-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix calculation of wrapping advance #440
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
using System.Globalization; | ||
using System.Numerics; | ||
using System.Text; | ||
using SixLabors.Fonts.Tests.Fakes; | ||
using SixLabors.Fonts.Unicode; | ||
using SixLabors.ImageSharp.Drawing.Processing; | ||
|
@@ -289,11 +290,11 @@ | |
LayoutMode = LayoutMode.HorizontalTopBottom | ||
}; | ||
|
||
FontRectangle size = TextMeasurer.MeasureBounds(text, options); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { height, width }); | ||
|
||
FontRectangle size = TextMeasurer.MeasureBounds(text, options); | ||
Assert.Equal(width, size.Width, 4F); | ||
Assert.Equal(height, size.Height, 4F); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { height, width }); | ||
} | ||
} | ||
|
||
|
@@ -315,11 +316,12 @@ | |
LayoutMode = LayoutMode.HorizontalBottomTop | ||
}; | ||
|
||
FontRectangle size = TextMeasurer.MeasureBounds(text, options); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { height, width }); | ||
|
||
|
||
FontRectangle size = TextMeasurer.MeasureBounds(text, options); | ||
Assert.Equal(width, size.Width, 4F); | ||
Assert.Equal(height, size.Height, 4F); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { height, width }); | ||
} | ||
} | ||
|
||
|
@@ -338,11 +340,11 @@ | |
LayoutMode = LayoutMode.VerticalLeftRight | ||
}; | ||
|
||
FontRectangle size = TextMeasurer.MeasureBounds(text, options); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { height, width }); | ||
|
||
FontRectangle size = TextMeasurer.MeasureBounds(text, options); | ||
Assert.Equal(width, size.Width, 4F); | ||
Assert.Equal(height, size.Height, 4F); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { height, width }); | ||
} | ||
} | ||
|
||
|
@@ -361,11 +363,11 @@ | |
LayoutMode = LayoutMode.VerticalRightLeft | ||
}; | ||
|
||
FontRectangle size = TextMeasurer.MeasureBounds(text, options); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { height, width }); | ||
|
||
FontRectangle size = TextMeasurer.MeasureBounds(text, options); | ||
Assert.Equal(width, size.Width, 4F); | ||
Assert.Equal(height, size.Height, 4F); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { height, width }); | ||
} | ||
} | ||
|
||
|
@@ -384,11 +386,11 @@ | |
LayoutMode = LayoutMode.VerticalMixedLeftRight | ||
}; | ||
|
||
FontRectangle size = TextMeasurer.MeasureBounds(text, options); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { height, width }); | ||
|
||
FontRectangle size = TextMeasurer.MeasureBounds(text, options); | ||
Assert.Equal(width, size.Width, 4F); | ||
Assert.Equal(height, size.Height, 4F); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { height, width }); | ||
} | ||
} | ||
|
||
|
@@ -416,14 +418,11 @@ | |
FallbackFontFamilies = new[] { jhengHei } | ||
}; | ||
|
||
FontRectangle size = TextMeasurer.MeasureAdvance( | ||
text, | ||
options); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { layoutMode, wordBreaking }); | ||
|
||
FontRectangle size = TextMeasurer.MeasureAdvance(text, options); | ||
Assert.Equal(width, size.Width, 4F); | ||
Assert.Equal(height, size.Height, 4F); | ||
|
||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { layoutMode, wordBreaking }); | ||
} | ||
} | ||
|
||
|
@@ -455,10 +454,10 @@ | |
text, | ||
options); | ||
|
||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { layoutMode, wordBreaking }); | ||
|
||
Assert.Equal(width, size.Width, 4F); | ||
Assert.Equal(height, size.Height, 4F); | ||
|
||
TextLayoutTestUtilities.TestLayout(text, options, properties: new { layoutMode, wordBreaking }); | ||
} | ||
} | ||
|
||
|
@@ -550,8 +549,8 @@ | |
|
||
[Theory] | ||
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 25, 6)] | ||
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 50, 5)] | ||
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 100, 4)] | ||
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 50, 4)] | ||
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 100, 3)] | ||
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 200, 3)] | ||
public void CountLinesWrappingLength(string text, int wrappingLength, int usedLines) | ||
{ | ||
|
@@ -561,9 +560,10 @@ | |
WrappingLength = wrappingLength | ||
}; | ||
|
||
TextLayoutTestUtilities.TestLayout(text, options, properties: usedLines); | ||
|
||
int count = TextMeasurer.CountLines(text, options); | ||
Assert.Equal(usedLines, count); | ||
TextLayoutTestUtilities.TestLayout(text, options, properties: usedLines); | ||
} | ||
|
||
[Fact] | ||
|
@@ -849,7 +849,7 @@ | |
} | ||
} | ||
|
||
public static TheoryData<char, FontRectangle> OpenSans_Data | ||
Check warning on line 852 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, macos-latest, net6.0, 6.0.x, -x64, false)
Check warning on line 852 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, true)
|
||
= new() | ||
{ | ||
{ '!', new(0F, 0F, 1.1621094F, 7.2753906F) }, | ||
|
@@ -1217,10 +1217,11 @@ | |
}; | ||
|
||
const string text = "Hello World!"; | ||
int lineCount = TextMeasurer.CountLines(text, options); | ||
Assert.Equal(text.Length - 1, lineCount); | ||
|
||
TextLayoutTestUtilities.TestLayout(text, options); | ||
|
||
int lineCount = TextMeasurer.CountLines(text, options); | ||
Assert.Equal(text.Length - 1, lineCount); | ||
} | ||
|
||
private class CaptureGlyphBoundBuilder : IGlyphRenderer | ||
|
@@ -1232,15 +1233,15 @@ | |
renderer.RenderText(text, options); | ||
return glyphBuilder.GlyphBounds; | ||
} | ||
public readonly List<FontRectangle> GlyphBounds = new(); | ||
Check warning on line 1236 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, macos-latest, net6.0, 6.0.x, -x64, false)
Check warning on line 1236 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, true)
|
||
public CaptureGlyphBoundBuilder() { } | ||
Check warning on line 1237 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, macos-latest, net6.0, 6.0.x, -x64, false)
Check warning on line 1237 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, true)
|
||
bool IGlyphRenderer.BeginGlyph(in FontRectangle bounds, in GlyphRendererParameters parameters) | ||
Check warning on line 1238 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, macos-latest, net6.0, 6.0.x, -x64, false)
Check warning on line 1238 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, true)
|
||
{ | ||
this.GlyphBounds.Add(bounds); | ||
return true; | ||
} | ||
public void BeginFigure() { } | ||
Check warning on line 1243 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, macos-latest, net6.0, 6.0.x, -x64, false)
Check warning on line 1243 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, true)
|
||
public void MoveTo(Vector2 point) { } | ||
Check warning on line 1244 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, macos-latest, net6.0, 6.0.x, -x64, false)
Check warning on line 1244 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, true)
|
||
public void QuadraticBezierTo(Vector2 secondControlPoint, Vector2 point) { } | ||
public void CubicBezierTo(Vector2 secondControlPoint, Vector2 thirdControlPoint, Vector2 point) { } | ||
public void LineTo(Vector2 point) { } | ||
|
@@ -1256,7 +1257,7 @@ | |
private static readonly Font OpenSansWoff = new FontCollection().Add(TestFonts.OpenSansFile).CreateFont(10); | ||
|
||
#if OS_WINDOWS | ||
public static TheoryData<char, FontRectangle> SegoeUi_Data | ||
Check warning on line 1260 in tests/SixLabors.Fonts.Tests/TextLayoutTests.cs GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, true)
|
||
= new() | ||
{ | ||
{ '!', new(0F, 0F, 1.0839844F, 7.0898438F) }, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This took me a few hours to figure out! Setting
i = 0
was incorrect as the loop was incrementing the value before we read the collection again.