Skip to content

Commit 8d3c065

Browse files
Merge pull request #500 from SixLabors/js/linemetrics
Fix Vertical Layout with Custom LineSpacing
2 parents 80a0d61 + cf8b302 commit 8d3c065

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/SixLabors.Fonts/TextLayout.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ private static List<GlyphLayout> LayoutLineVertical(
580580
penLocation.Y += offsetY;
581581
penLocation.X += offsetX;
582582

583+
float lineOriginX = penLocation.X;
584+
583585
List<GlyphLayout> glyphs = new(textLine.Count);
584586

585587
// Grapheme-scoped state for transformed glyph alignment.
@@ -699,7 +701,7 @@ private static List<GlyphLayout> LayoutLineVertical(
699701
// Normalize ink minX to 0 and center within the column width.
700702
// This is grapheme-correct and avoids centering based only on the "first" entry,
701703
// which is not representative for marks like reph in Devanagari.
702-
currentGraphemeAlignX = -minX + ((scaledMaxLineHeight - inkWidth) * .5F);
704+
currentGraphemeAlignX = -minX + ((unscaledLineHeight - inkWidth) * .5F);
703705
}
704706
}
705707

@@ -740,7 +742,7 @@ private static List<GlyphLayout> LayoutLineVertical(
740742
glyphs.Add(new GlyphLayout(
741743
new Glyph(metric, data.PointSize),
742744
boxLocation,
743-
penLocation + new Vector2((scaledMaxLineHeight - data.ScaledLineHeight) * .5F, 0),
745+
penLocation + new Vector2((unscaledLineHeight - (data.ScaledLineHeight / options.LineSpacing)) * .5F, 0),
744746
offset,
745747
advanceW,
746748
data.ScaledAdvance + yExtraAdvance,
@@ -762,8 +764,8 @@ private static List<GlyphLayout> LayoutLineVertical(
762764
if (data.IsLastInGrapheme)
763765
{
764766
penLocation.Y += data.ScaledAdvance + yExtraAdvance;
765-
boxLocation.X = originX;
766-
penLocation.X = originX;
767+
boxLocation.X = lineOriginX;
768+
penLocation.X = lineOriginX;
767769
}
768770
}
769771

@@ -921,7 +923,7 @@ private static List<GlyphLayout> LayoutLineVerticalMixed(
921923
// - Take half the difference between the max line height (scaledMaxLineHeight)
922924
// and the current glyph's line height (data.ScaledLineHeight).
923925
// - The line height includes both ascender and descender metrics.
924-
float baselineDelta = (scaledMaxLineHeight - data.ScaledLineHeight) * .5F;
926+
float baselineDelta = (unscaledLineHeight - (data.ScaledLineHeight / options.LineSpacing)) * .5F;
925927

926928
// Adjust the horizontal offset further by considering the descender differences:
927929
// - Subtract the current glyph's descender (data.ScaledDescender) to align it properly.
@@ -962,7 +964,7 @@ private static List<GlyphLayout> LayoutLineVerticalMixed(
962964
glyphs.Add(new GlyphLayout(
963965
new Glyph(metric, data.PointSize),
964966
boxLocation,
965-
penLocation + new Vector2((scaledMaxLineHeight - data.ScaledLineHeight) * .5F, 0),
967+
penLocation + new Vector2((unscaledLineHeight - (data.ScaledLineHeight / options.LineSpacing)) * .5F, 0),
966968
offset,
967969
advanceX,
968970
data.ScaledAdvance + yExtraAdvance,

0 commit comments

Comments
 (0)