Skip to content

Commit b054d68

Browse files
Merge pull request #177 from SixLabors/js/text-options
Update Fonts Reference and Introduce Shared TextOptions
2 parents e987bd8 + 7012259 commit b054d68

50 files changed

Lines changed: 471 additions & 1055 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: 3 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
@@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_root", "_root", "{C317F1B1
1212
ci-build.ps1 = ci-build.ps1
1313
ci-pack.ps1 = ci-pack.ps1
1414
ci-test.ps1 = ci-test.ps1
15+
codecov.yml = codecov.yml
1516
Directory.Build.props = Directory.Build.props
1617
Directory.Build.targets = Directory.Build.targets
1718
LICENSE = LICENSE

codecov.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,14 @@ codecov:
99
# Avoid Report Expired
1010
# https://docs.codecov.io/docs/codecov-yaml#section-expired-reports
1111
max_report_age: off
12+
13+
coverage:
14+
# Use integer precision
15+
# https://docs.codecov.com/docs/codecovyml-reference#coverageprecision
16+
precision: 0
17+
18+
# Explicitly control coverage status checks
19+
# https://docs.codecov.com/docs/commit-status#disabling-a-status
20+
status:
21+
project: on
22+
patch: off

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
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.20" />
2424
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
2525
</ItemGroup>
2626

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)