Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ nugets/
nul
*.trx
src/.claude/settings.local.json
/TestResults
/BenchmarkDotNet.Artifacts
/src/Tests/TestResults
1 change: 1 addition & 0 deletions claude.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The conversion pipeline is **Parse → Render**:
- No accessibility modifiers on internal members (`dotnet_style_require_accessibility_modifiers = never`)
- Private fields/constants use camelCase (no underscore prefix)
- Braces required for all control structures
- Always use underscores (`_`) for unused lambda parameters (e.g., `_ => _.Method()`)
- See `.editorconfig` for full rules

## Testing
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ https://nuget.org/packages/Morph/
<!-- snippet: BasicUsage -->
<a id='snippet-BasicUsage'></a>
```cs
var converter = new DocumentConverter();
var converter = new WordRender.Skia.DocumentConverter();

var result = converter.ConvertToImages(
"document.docx",
Expand All @@ -122,7 +122,7 @@ foreach (var path in result.ImagePaths)
<!-- snippet: InMemoryConversion -->
<a id='snippet-InMemoryConversion'></a>
```cs
var converter = new DocumentConverter();
var converter = new WordRender.Skia.DocumentConverter();

var imageData = converter.ConvertToImageData("document.docx");

Expand All @@ -140,7 +140,7 @@ foreach (var pngBytes in imageData)
<!-- snippet: StreamBasedConversion -->
<a id='snippet-StreamBasedConversion'></a>
```cs
var converter = new DocumentConverter();
var converter = new WordRender.Skia.DocumentConverter();

using var stream = File.OpenRead("document.docx");

Expand All @@ -159,7 +159,7 @@ var imageData = converter.ConvertToImageData(stream);
<!-- snippet: CustomOptions -->
<a id='snippet-CustomOptions'></a>
```cs
var converter = new DocumentConverter();
var converter = new WordRender.Skia.DocumentConverter();

var options = new ConversionOptions
{
Expand Down
18 changes: 18 additions & 0 deletions src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
<ProjectReference Include="..\Morph\Morph.csproj" />
<ProjectReference Include="..\Morph.Skia\Morph.Skia.csproj" />
<ProjectReference Include="..\Morph.ImageSharp\Morph.ImageSharp.csproj" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" />
</ItemGroup>

</Project>
59 changes: 59 additions & 0 deletions src/Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(ConversionBenchmarks).Assembly).Run(args);

[MemoryDiagnoser]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
public class ConversionBenchmarks
{
static string GetSourceDir([System.Runtime.CompilerServices.CallerFilePath] string path = "") => Path.GetDirectoryName(path)!;
static readonly string inputsDir = Path.GetFullPath(Path.Combine(GetSourceDir(), "..", "Tests", "Inputs"));

// Small (~33KB) - simple resume
static readonly string smallDoc = Path.Combine(inputsDir, "resumes", "01", "input.docx");
// Medium (~92KB) - letter with images
static readonly string mediumDoc = Path.Combine(inputsDir, "letters", "01", "input.docx");
// Large (~5.5MB) - newsletter with many images
static readonly string largeDoc = Path.Combine(inputsDir, "newsletters", "03", "input.docx");

readonly WordRender.Skia.DocumentConverter skia = new();
readonly WordRender.ImageSharp.DocumentConverter imageSharp = new();

byte[] smallBytes = [];
byte[] mediumBytes = [];
byte[] largeBytes = [];

[GlobalSetup]
public void Setup()
{
smallBytes = File.ReadAllBytes(smallDoc);
mediumBytes = File.ReadAllBytes(mediumDoc);
largeBytes = File.ReadAllBytes(largeDoc);
}

[Benchmark(Baseline = true)]
[BenchmarkCategory("Small")]
public IReadOnlyList<byte[]> Skia_Small() => skia.ConvertToImageData(new MemoryStream(smallBytes));

[Benchmark]
[BenchmarkCategory("Small")]
public IReadOnlyList<byte[]> ImageSharp_Small() => imageSharp.ConvertToImageData(new MemoryStream(smallBytes));

[Benchmark(Baseline = true)]
[BenchmarkCategory("Medium")]
public IReadOnlyList<byte[]> Skia_Medium() => skia.ConvertToImageData(new MemoryStream(mediumBytes));

[Benchmark]
[BenchmarkCategory("Medium")]
public IReadOnlyList<byte[]> ImageSharp_Medium() => imageSharp.ConvertToImageData(new MemoryStream(mediumBytes));

[Benchmark(Baseline = true)]
[BenchmarkCategory("Large")]
public IReadOnlyList<byte[]> Skia_Large() => skia.ConvertToImageData(new MemoryStream(largeBytes));

[Benchmark]
[BenchmarkCategory("Large")]
public IReadOnlyList<byte[]> ImageSharp_Large() => imageSharp.ConvertToImageData(new MemoryStream(largeBytes));
}
14 changes: 9 additions & 5 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AngleSharp" Version="1.4.0" />
<PackageVersion Include="DocumentFormat.OpenXml" Version="3.4.1" />
<PackageVersion Include="Magick.NET-Q16-AnyCPU" Version="14.10.4" />
<PackageVersion Include="BenchmarkDotNet" Version="0.15.8" />
<PackageVersion Include="DocumentFormat.OpenXml" Version="3.5.1" />
<PackageVersion Include="Magick.NET-Q16-AnyCPU" Version="14.11.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageVersion Include="Microsoft.Office.Interop.Word" Version="15.0.4797.1004" />
<PackageVersion Include="NUnit" Version="4.5.1" />
Expand All @@ -18,9 +19,12 @@
<PackageVersion Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.119.2" />
<PackageVersion Include="SkiaSharp.NativeAssets.macOS" Version="3.119.2" />
<PackageVersion Include="SkiaSharp.NativeAssets.Win32" Version="3.119.2" />
<PackageVersion Include="SixLabors.Fonts" Version="2.1.3" />
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.12" />
<PackageVersion Include="SixLabors.ImageSharp.Drawing" Version="2.1.7" />
<PackageVersion Include="Svg.Skia" Version="3.6.0" />
<PackageVersion Include="TUnit" Version="1.19.22" />
<PackageVersion Include="Verify.ImageMagick" Version="3.8.5" />
<PackageVersion Include="Verify.TUnit" Version="31.13.2" />
<PackageVersion Include="TUnit" Version="1.19.74" />
<PackageVersion Include="Verify.ImageMagick" Version="3.8.6" />
<PackageVersion Include="Verify.TUnit" Version="31.13.5" />
</ItemGroup>
</Project>
Binary file added src/Fonts/CAVOLINI.TTF
Binary file not shown.
Binary file added src/Fonts/CAVOLINIBOLD.TTF
Binary file not shown.
Binary file added src/Fonts/CAVOLINIBOLDITALIC.TTF
Binary file not shown.
Binary file added src/Fonts/CAVOLINIITALIC.TTF
Binary file not shown.
Binary file added src/Fonts/Century_Gothic_400.ttf
Binary file not shown.
Binary file added src/Fonts/Century_Gothic_700.ttf
Binary file not shown.
Binary file added src/Fonts/Euphemia Regular.ttf
Binary file not shown.
Binary file added src/Fonts/Grandview.ttf
Binary file not shown.
Binary file added src/Fonts/GrandviewBold.ttf
Binary file not shown.
Binary file added src/Fonts/GrandviewBoldItalic.ttf
Binary file not shown.
Binary file added src/Fonts/GrandviewItalic.ttf
Binary file not shown.
Binary file added src/Fonts/GrandviewLight.ttf
Binary file not shown.
Binary file added src/Fonts/GrandviewLightItalic.ttf
Binary file not shown.
Binary file added src/Fonts/Thehandregular-lgDld.otf
Binary file not shown.
15 changes: 15 additions & 0 deletions src/Morph.ImageSharp/DocumentConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace WordRender.ImageSharp;

/// <summary>
/// Converts DOCX documents to PNG images using SixLabors.ImageSharp.
/// </summary>
public sealed class DocumentConverter : WordRender.DocumentConverter
{
private protected override int RenderPages(ParsedDocument document, ConversionOptions options, Action<Action<Stream>> pageCallback)
{
using var context = new RenderContext(document.PageSettings, options.Dpi, document.Compatibility, options.FontWidthScale, options.FontFallback);
using var renderer = new PageRenderer(context);

return renderer.RenderDocument(document, pageCallback);
}
}
12 changes: 12 additions & 0 deletions src/Morph.ImageSharp/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Global using directives

global using System.Globalization;
global using System.Numerics;
global using System.Text;
global using System.Text.RegularExpressions;
global using SixLabors.Fonts;
global using SixLabors.ImageSharp;
global using SixLabors.ImageSharp.Drawing;
global using SixLabors.ImageSharp.Drawing.Processing;
global using SixLabors.ImageSharp.PixelFormats;
global using SixLabors.ImageSharp.Processing;
17 changes: 17 additions & 0 deletions src/Morph.ImageSharp/Morph.ImageSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<NoWarn>CS0618;CS1591;CS1572;NU1902</NoWarn>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010005AA7D6703369C6701F8527FC7536EE1F43584266AA043F7B5F58E6BF0CC55BEAD30F5D2F06DEBED488B221DBFA987C08B8178960C10E06002AB1ADC7D89AE62B78E6794ED60BA0561022EA6593F4AB3F1F1523826CBE43B6B6039B4B15291B3B83943E3A8FC1E7E35FFA862E82429410920B20B51128A53E3FB502065D56EB3" />
<ProjectReference Include="..\Morph\Morph.csproj" />
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
<PackageReference Include="SixLabors.ImageSharp" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" />
<PackageReference Include="SixLabors.Fonts" />
</ItemGroup>

</Project>
Loading
Loading