diff --git a/src/SixLabors.Fonts/TextLayout.cs b/src/SixLabors.Fonts/TextLayout.cs index 4cae866e..8550cc8f 100644 --- a/src/SixLabors.Fonts/TextLayout.cs +++ b/src/SixLabors.Fonts/TextLayout.cs @@ -539,23 +539,11 @@ private static List LayoutLineVertical( } bool isFirstLine = index == 0; - float yExtraAdvance = 0; if (isFirstLine) { - // First vertical line: add extra ascent if the actual ink extends above - // the typographic ascender. This mirrors the horizontal logic but along - // the vertical flow direction of the column. - float requiredAscent = -textLine.ScaledMinY; - float extraAscent = requiredAscent - textLine.ScaledMaxAscender; - - if (extraAscent > 0) - { - // Move the column baseline down so that the tallest ink above the - // baseline fits inside the image, and increase the advance so the - // column height matches the new extent. - offsetY += extraAscent; - yExtraAdvance += extraAscent; - } + // In vertical layout, first-line Y ascent compensation introduces unwanted + // leading space before the first glyph. Keep first-line handling limited + // to X-origin block alignment only. // Set the X-Origin for horizontal alignment. switch (options.HorizontalAlignment) @@ -745,7 +733,7 @@ private static List LayoutLineVertical( penLocation + new Vector2((unscaledLineHeight - (data.ScaledLineHeight / options.LineSpacing)) * .5F, 0), offset, advanceW, - data.ScaledAdvance + yExtraAdvance, + data.ScaledAdvance, GlyphLayoutMode.Vertical, i == 0 && j == 0, data.GraphemeIndex, @@ -763,7 +751,7 @@ private static List LayoutLineVertical( if (data.IsLastInGrapheme) { - penLocation.Y += data.ScaledAdvance + yExtraAdvance; + penLocation.Y += data.ScaledAdvance; boxLocation.X = lineOriginX; penLocation.X = lineOriginX; } @@ -845,23 +833,11 @@ private static List LayoutLineVerticalMixed( } bool isFirstLine = index == 0; - float yExtraAdvance = 0; if (isFirstLine) { - // First mixed vertical line: compute any extra ascent required for this line. - // As with horizontal layout, ScaledMinY captures the true ink top in Y down, - // and ScaledMaxAscender is the typographic ascent used for line metrics. - float requiredAscent = -textLine.ScaledMinY; - float extraAscent = requiredAscent - textLine.ScaledMaxAscender; - - if (extraAscent > 0) - { - // Push the baseline for the first column down so that tall stacks are - // fully visible, and store the extra amount so we can also expand the - // advance along the flow direction for all glyphs in this column. - offsetY += extraAscent; - yExtraAdvance += extraAscent; - } + // In vertical-mixed layout, first-line Y ascent compensation introduces + // unwanted leading space before the first glyph. Keep first-line handling + // limited to X-origin block alignment only. // Set the X-Origin for horizontal alignment. switch (options.HorizontalAlignment) @@ -930,12 +906,7 @@ private static List LayoutLineVerticalMixed( float descenderAbs = Math.Abs(data.ScaledDescender); float descenderDelta = (Math.Abs(textLine.ScaledMaxDescender) - descenderAbs) * .5F; - // For rotated glyphs, yExtraAdvance represents additional "height" - // that we allocated to the column to fit tall stacks above the baseline. - // Adding half of that to the horizontal center offset keeps sideways - // glyphs visually centered within the now taller column. float centerOffsetX = baselineDelta + descenderAbs + descenderDelta; - centerOffsetX += yExtraAdvance * .5F; glyphs.Add(new GlyphLayout( new Glyph(metric, data.PointSize), @@ -943,7 +914,7 @@ private static List LayoutLineVerticalMixed( penLocation + new Vector2(centerOffsetX, 0), Vector2.Zero, advanceX, - data.ScaledAdvance + yExtraAdvance, + data.ScaledAdvance, GlyphLayoutMode.VerticalRotated, i == 0 && j == 0, data.GraphemeIndex, @@ -967,7 +938,7 @@ private static List LayoutLineVerticalMixed( penLocation + new Vector2((unscaledLineHeight - (data.ScaledLineHeight / options.LineSpacing)) * .5F, 0), offset, advanceX, - data.ScaledAdvance + yExtraAdvance, + data.ScaledAdvance, GlyphLayoutMode.Vertical, i == 0 && j == 0, data.GraphemeIndex, @@ -977,7 +948,7 @@ private static List LayoutLineVerticalMixed( } } - penLocation.Y += data.ScaledAdvance + yExtraAdvance; + penLocation.Y += data.ScaledAdvance; } boxLocation.Y = originY; diff --git "a/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\260\340\245\215\340\244\225\340\244\277-.png" "b/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\260\340\245\215\340\244\225\340\244\277-.png" index 802487a8..86c0bd25 100644 --- "a/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\260\340\245\215\340\244\225\340\244\277-.png" +++ "b/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\260\340\245\215\340\244\225\340\244\277-.png" @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bc0354e90fd121d079541e9c883213e3a5c2f3563d8616093cb744c996055d5b -size 1173 +oid sha256:e781fe4a3769c4495aa49f0d608df9a6ec2d0b21c06b6b74c6f7fca855d5965d +size 491 diff --git "a/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\260\340\245\215\340\244\225\340\244\277\340\244\260\340\245\215\340\244\225\340\244\277-.png" "b/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\260\340\245\215\340\244\225\340\244\277\340\244\260\340\245\215\340\244\225\340\244\277-.png" index b29cbbbc..2d87f895 100644 --- "a/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\260\340\245\215\340\244\225\340\244\277\340\244\260\340\245\215\340\244\225\340\244\277-.png" +++ "b/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\260\340\245\215\340\244\225\340\244\277\340\244\260\340\245\215\340\244\225\340\244\277-.png" @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3554e592c585e5c1055d5af650380c161b6fba51b833e4336f649fb7a6e6eca7 -size 2101 +oid sha256:bb6dbbea7934cfdd8c884e59946bc40b7050b6fddd3f36f9853d85d61614afb7 +size 833 diff --git "a/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\277-.png" "b/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\277-.png" index 6bbb238a..17a4bf61 100644 --- "a/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\277-.png" +++ "b/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\277-.png" @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:388c8f9144918a554df59eb46b7b847db0f4121da502000289a39d787cbf578a -size 869 +oid sha256:f062501be6e3c96a9aef1c4e1acb097c6890d26b2a8bc19d5f59d142026f41d5 +size 364 diff --git "a/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\277a-.png" "b/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\277a-.png" index b1b60b0a..d9ab8584 100644 --- "a/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\277a-.png" +++ "b/tests/Images/ReferenceOutput/FontTracking_CorrectlyAddSpacingForComposedCharacterVRef_-\340\244\277a-.png" @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b11a2c4b1a0bc30d897a8fa029d928bd58e7faa55af4a744134d7aa4ba2da022 -size 1029 +oid sha256:455676322c37b9afa7c6a96e7aa4f8e0187cc66b8d84a3cbd38a10f8e26bf523 +size 417