Skip to content

Commit

Permalink
Fix 367
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Feb 9, 2024
1 parent 476c5f3 commit 7c23ae8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/SixLabors.Fonts/TextLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,12 @@ private static TextBox BreakLines(
textLine = split;
lineAdvance = split.ScaledLineAdvance;
}
else if (textLine.Count > 0)
{
textLines.Add(textLine.Finalize());
textLine = new();
lineAdvance = 0;
}
}
else if (lastLineBreak.PositionWrap < codePointIndex && !CodePoint.IsWhiteSpace(codePoint))
{
Expand Down
Binary file not shown.
29 changes: 29 additions & 0 deletions tests/SixLabors.Fonts.Tests/Issues/Issues_367.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

namespace SixLabors.Fonts.Tests.Issues;
public class Issues_367
{
[Fact]
public void ShouldMatchBrowserBreak()
{
Font font = new FontCollection().Add(TestFonts.CourierPrimeFile).CreateFont(12);

TextOptions options = new(font)
{
Dpi = 96f // 1in = 96px
};

const float wrappingLengthInInches = 3.875f;
options.WrappingLength = wrappingLengthInInches * options.Dpi;

const string text = "Leer, but lonesome has fussin' change a faith. Themself seen and four trample.";
int lineCount = TextMeasurer.CountLines(text, options);

Assert.Equal(3, lineCount);

FontRectangle advance = TextMeasurer.MeasureAdvance(text, options);
Assert.Equal(365, advance.Width);
Assert.Equal(48, advance.Height);
}
}
2 changes: 2 additions & 0 deletions tests/SixLabors.Fonts.Tests/TestFonts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ public static class TestFonts

public static string PermanentMarkerRegularWoff2File => GetFullPath("PermanentMarker-Regular.woff2");

public static string CourierPrimeFile => GetFullPath("courier-prime.woff2");

public static Stream TwemojiMozillaData() => OpenStream(TwemojiMozillaFile);

public static Stream SegoeuiEmojiData() => OpenStream(SegoeuiEmojiFile);
Expand Down
2 changes: 1 addition & 1 deletion tests/SixLabors.Fonts.Tests/TextLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public void CountLinesWithSpan()
[Theory]
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 25, 7)]
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 50, 7)]
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 100, 6)]
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 100, 7)]
[InlineData("This is a long and Honorificabilitudinitatibus califragilisticexpialidocious", 200, 6)]
public void CountLinesWrappingLength(string text, int wrappingLength, int usedLines)
{
Expand Down

0 comments on commit 7c23ae8

Please sign in to comment.