Skip to content

Commit

Permalink
Merge pull request #175 from SixLabors/js/fix-171
Browse files Browse the repository at this point in the history
Properly Fix #171
  • Loading branch information
JimBobSquarePants authored May 20, 2021
2 parents 1aab62a + e112ed9 commit 1ce1aff
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/SixLabors.Fonts/TextLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public IReadOnlyList<GlyphLayout> GenerateLayout(ReadOnlySpan<char> text, Render
// Remember where the top of the layouted text is for accurate vertical alignment.
// This is important because there is considerable space between the lineHeight at the glyph's ascender.
float top = 0;

float scale = 0;
bool firstLine = true;
GlyphInstance? previousGlyph = null;
int lastWrappableLocation = -1;
Expand Down Expand Up @@ -108,24 +108,31 @@ public IReadOnlyList<GlyphLayout> GenerateLayout(ReadOnlySpan<char> text, Render
}

GlyphInstance? glyph = glyphs[0];
float scale = glyph.Font.EmSize * 72;
if (previousGlyph != null && glyph.Font != previousGlyph.Font)
{
scale = glyph.Font.EmSize * 72;
}

float fontHeight = glyph.Font.LineHeight * options.LineSpacing;
if (fontHeight > unscaledLineHeight)
{
// get the larget lineheight thus far
unscaledLineHeight = fontHeight;
scale = glyph.Font.EmSize * 72;
lineHeight = unscaledLineHeight * spanStyle.PointSize / scale;
}

if (glyph.Font.Ascender > unscaledLineMaxAscender)
{
unscaledLineMaxAscender = glyph.Font.Ascender;
scale = glyph.Font.EmSize * 72;
lineMaxAscender = unscaledLineMaxAscender * spanStyle.PointSize / scale;
}

if (Math.Abs(glyph.Font.Descender) > unscaledLineMaxDescender)
{
unscaledLineMaxDescender = Math.Abs(glyph.Font.Descender);
scale = glyph.Font.EmSize * 72;
lineMaxDescender = unscaledLineMaxDescender * spanStyle.PointSize / scale;
}

Expand Down

0 comments on commit 1ce1aff

Please sign in to comment.