Skip to content

Commit a3ecc76

Browse files
Refactor to use Fonts TextOptions (non-compiling)
1 parent e987bd8 commit a3ecc76

48 files changed

Lines changed: 470 additions & 1051 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ImageSharp.Drawing.sln

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.28902.138
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_root", "_root", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}"
77
ProjectSection(SolutionItems) = preProject
@@ -333,9 +333,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{5286
333333
EndProject
334334
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawShapesWithImageSharp", "samples\DrawShapesWithImageSharp\DrawShapesWithImageSharp.csproj", "{5493F024-0A3F-420C-AC2D-05B77A36025B}"
335335
EndProject
336+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SixLabors.Fonts", "..\Fonts\src\SixLabors.Fonts\SixLabors.Fonts.csproj", "{36EAD456-7859-4C52-A745-E8BFBA0BC239}"
337+
EndProject
336338
Global
337339
GlobalSection(SharedMSBuildProjectFiles) = preSolution
338340
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{2e33181e-6e28-4662-a801-e2e7dc206029}*SharedItemsImports = 5
341+
..\Fonts\shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{36ead456-7859-4c52-a745-e8bfba0bc239}*SharedItemsImports = 5
339342
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{68a8cc40-6aed-4e96-b524-31b1158fdeea}*SharedItemsImports = 13
340343
EndGlobalSection
341344
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -359,6 +362,10 @@ Global
359362
{5493F024-0A3F-420C-AC2D-05B77A36025B}.Debug|Any CPU.Build.0 = Debug|Any CPU
360363
{5493F024-0A3F-420C-AC2D-05B77A36025B}.Release|Any CPU.ActiveCfg = Release|Any CPU
361364
{5493F024-0A3F-420C-AC2D-05B77A36025B}.Release|Any CPU.Build.0 = Release|Any CPU
365+
{36EAD456-7859-4C52-A745-E8BFBA0BC239}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
366+
{36EAD456-7859-4C52-A745-E8BFBA0BC239}.Debug|Any CPU.Build.0 = Debug|Any CPU
367+
{36EAD456-7859-4C52-A745-E8BFBA0BC239}.Release|Any CPU.ActiveCfg = Release|Any CPU
368+
{36EAD456-7859-4C52-A745-E8BFBA0BC239}.Release|Any CPU.Build.0 = Release|Any CPU
362369
EndGlobalSection
363370
GlobalSection(SolutionProperties) = preSolution
364371
HideSolutionNode = FALSE

samples/DrawShapesWithImageSharp/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ private static void DrawText(string text)
6565
{
6666
FontFamily fam = SystemFonts.Get("Arial");
6767
var font = new Font(fam, 30);
68-
var style = new RendererOptions(font, 72);
69-
IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, style);
68+
TextOptions textOptions = new(font);
69+
IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, textOptions);
7070

7171
glyphs.SaveImage("Text", text + ".png");
7272
}
@@ -75,13 +75,13 @@ private static void DrawText(string text, IPath path)
7575
{
7676
FontFamily fam = SystemFonts.Get("Arial");
7777
var font = new Font(fam, 30);
78-
var style = new RendererOptions(font, 72)
78+
TextOptions textOptions = new(font)
7979
{
80-
WrappingWidth = path.ComputeLength(),
80+
WrappingLength = path.ComputeLength(),
8181
VerticalAlignment = VerticalAlignment.Top,
8282
HorizontalAlignment = HorizontalAlignment.Center,
8383
};
84-
IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, path, style);
84+
IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, path, textOptions);
8585

8686
glyphs.SaveImage("Text-Path", text + ".png");
8787
}

src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta15.15" />
23+
<!--<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta15.15" />-->
2424
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
2525
</ItemGroup>
2626

27+
<ItemGroup>
28+
<ProjectReference Include="..\..\..\Fonts\src\SixLabors.Fonts\SixLabors.Fonts.csproj" />
29+
</ItemGroup>
30+
2731
<Import Project="..\..\shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems" Label="Shared" />
2832

2933
</Project>

src/ImageSharp.Drawing/Processing/DrawingOptions.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class DrawingOptions
1212
{
1313
private GraphicsOptions graphicsOptions;
1414
private ShapeOptions shapeOptions;
15-
private TextOptions textOptions;
1615

1716
/// <summary>
1817
/// Initializes a new instance of the <see cref="DrawingOptions"/> class.
@@ -21,23 +20,19 @@ public DrawingOptions()
2120
{
2221
this.graphicsOptions = new GraphicsOptions();
2322
this.shapeOptions = new ShapeOptions();
24-
this.textOptions = new TextOptions();
2523
this.Transform = Matrix3x2.Identity;
2624
}
2725

2826
internal DrawingOptions(
2927
GraphicsOptions graphicsOptions,
3028
ShapeOptions shapeOptions,
31-
TextOptions textOptions,
3229
Matrix3x2 transform)
3330
{
3431
DebugGuard.NotNull(graphicsOptions, nameof(graphicsOptions));
3532
DebugGuard.NotNull(shapeOptions, nameof(shapeOptions));
36-
DebugGuard.NotNull(textOptions, nameof(textOptions));
3733

3834
this.graphicsOptions = graphicsOptions;
3935
this.shapeOptions = shapeOptions;
40-
this.textOptions = textOptions;
4136
this.Transform = transform;
4237
}
4338

@@ -67,19 +62,6 @@ public ShapeOptions ShapeOptions
6762
}
6863
}
6964

70-
/// <summary>
71-
/// Gets or sets the Text Options.
72-
/// </summary>
73-
public TextOptions TextOptions
74-
{
75-
get => this.textOptions;
76-
set
77-
{
78-
Guard.NotNull(value, nameof(this.TextOptions));
79-
this.textOptions = value;
80-
}
81-
}
82-
8365
/// <summary>
8466
/// Gets or sets the Transform to apply during rasterization.
8567
/// </summary>

src/ImageSharp.Drawing/Processing/DrawingOptionsDefaultsExtensions.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class DrawingOptionsDefaultsExtensions
1919
/// <param name="context">The image processing context to retrieve defaults from.</param>
2020
/// <returns>The globally configured default options.</returns>
2121
public static DrawingOptions GetDrawingOptions(this IImageProcessingContext context)
22-
=> new DrawingOptions(context.GetGraphicsOptions(), context.GetShapeOptions(), context.GetTextOptions(), context.GetDrawingTransform());
22+
=> new(context.GetGraphicsOptions(), context.GetShapeOptions(), context.GetDrawingTransform());
2323

2424
/// <summary>
2525
/// Sets the 2D transformation matrix to be used during rasterization when drawing shapes or text.
@@ -39,9 +39,7 @@ public static IImageProcessingContext SetDrawingTransform(this IImageProcessingC
3939
/// <param name="configuration">The configuration to store default against.</param>
4040
/// <param name="matrix">The default matrix to use.</param>
4141
public static void SetDrawingTransform(this Configuration configuration, Matrix3x2 matrix)
42-
{
43-
configuration.Properties[DrawingTransformMatrixKey] = matrix;
44-
}
42+
=> configuration.Properties[DrawingTransformMatrixKey] = matrix;
4543

4644
/// <summary>
4745
/// Gets the default 2D transformation matrix to be used during rasterization when drawing shapes or text.
@@ -50,16 +48,14 @@ public static void SetDrawingTransform(this Configuration configuration, Matrix3
5048
/// <returns>The matrix.</returns>
5149
public static Matrix3x2 GetDrawingTransform(this IImageProcessingContext context)
5250
{
53-
if (context.Properties.TryGetValue(DrawingTransformMatrixKey, out var options) && options is Matrix3x2 go)
51+
if (context.Properties.TryGetValue(DrawingTransformMatrixKey, out object options) && options is Matrix3x2 go)
5452
{
5553
return go;
5654
}
5755

58-
Matrix3x2 matrix = context.Configuration.GetDrawingTransform();
59-
6056
// do not cache the fall back to config into the processing context
6157
// in case someone want to change the value on the config and expects it re-flow thru.
62-
return matrix;
58+
return context.Configuration.GetDrawingTransform();
6359
}
6460

6561
/// <summary>
@@ -69,7 +65,7 @@ public static Matrix3x2 GetDrawingTransform(this IImageProcessingContext context
6965
/// <returns>The globally configured default matrix.</returns>
7066
public static Matrix3x2 GetDrawingTransform(this Configuration configuration)
7167
{
72-
if (configuration.Properties.TryGetValue(DrawingTransformMatrixKey, out var options) && options is Matrix3x2 go)
68+
if (configuration.Properties.TryGetValue(DrawingTransformMatrixKey, out object options) && options is Matrix3x2 go)
7369
{
7470
return go;
7571
}

src/ImageSharp.Drawing/Processing/Extensions/ClearExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal static DrawingOptions CloneForClearOperation(this DrawingOptions drawin
6060
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
6161
options.BlendPercentage = 1F;
6262

63-
return new DrawingOptions(options, drawingOptions.ShapeOptions, drawingOptions.TextOptions, drawingOptions.Transform);
63+
return new DrawingOptions(options, drawingOptions.ShapeOptions, drawingOptions.Transform);
6464
}
6565
}
6666
}

0 commit comments

Comments
 (0)