Skip to content

Commit 0e586c3

Browse files
Merge pull request #181 from SixLabors/js/fix-textbuilder
Remove double origin assignment from TextBuilder
2 parents b054d68 + 2abbe4f commit 0e586c3

4 files changed

Lines changed: 38 additions & 4 deletions

File tree

src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta15.20" />
24-
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
23+
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta15.23" />
24+
<PackageReference Include="SixLabors.ImageSharp" Version="2.0.0-alpha.0.123" />
2525
</ItemGroup>
2626

2727
<Import Project="..\..\shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems" Label="Shared" />

src/ImageSharp.Drawing/Shapes/Text/TextBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class TextBuilder
1919
/// <returns>The <see cref="IPathCollection"/></returns>
2020
public static IPathCollection GenerateGlyphs(string text, TextOptions textOptions)
2121
{
22-
GlyphBuilder glyphBuilder = new(textOptions.Origin);
22+
GlyphBuilder glyphBuilder = new();
2323
TextRenderer renderer = new(glyphBuilder);
2424

2525
renderer.RenderText(text, textOptions);

tests/ImageSharp.Drawing.Tests/ConfigurationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ConfigurationTests
2020

2121
public Configuration DefaultConfiguration { get; }
2222

23-
private readonly int expectedDefaultConfigurationCount = 5;
23+
private readonly int expectedDefaultConfigurationCount = 7;
2424

2525
public ConfigurationTests()
2626
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System.Numerics;
5+
using SixLabors.Fonts;
6+
using Xunit;
7+
8+
namespace SixLabors.ImageSharp.Drawing.Tests.Shapes
9+
{
10+
public class TextBuilderTests
11+
{
12+
[Fact]
13+
public void TextBuilder_Bounds_AreCorrect()
14+
{
15+
Vector2 position = new(5, 5);
16+
var options = new TextOptions(TestFontUtilities.GetFont(TestFonts.OpenSans, 16))
17+
{
18+
Origin = position
19+
};
20+
21+
string text = "Hello World";
22+
23+
IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, options);
24+
25+
RectangleF builderBounds = glyphs.Bounds;
26+
FontRectangle measuredBounds = TextMeasurer.MeasureBounds(text, options);
27+
28+
Assert.Equal(measuredBounds.X, builderBounds.X);
29+
Assert.Equal(measuredBounds.Y, builderBounds.Y);
30+
Assert.Equal(measuredBounds.Width, builderBounds.Width);
31+
Assert.Equal(measuredBounds.Height, builderBounds.Height);
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)