Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 11 additions & 40 deletions src/SixLabors.Fonts/TextLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,23 +539,11 @@ private static List<GlyphLayout> 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)
Expand Down Expand Up @@ -745,7 +733,7 @@ private static List<GlyphLayout> 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,
Expand All @@ -763,7 +751,7 @@ private static List<GlyphLayout> LayoutLineVertical(

if (data.IsLastInGrapheme)
{
penLocation.Y += data.ScaledAdvance + yExtraAdvance;
penLocation.Y += data.ScaledAdvance;
boxLocation.X = lineOriginX;
penLocation.X = lineOriginX;
}
Expand Down Expand Up @@ -845,23 +833,11 @@ private static List<GlyphLayout> 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)
Expand Down Expand Up @@ -930,20 +906,15 @@ private static List<GlyphLayout> 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),
boxLocation,
penLocation + new Vector2(centerOffsetX, 0),
Vector2.Zero,
advanceX,
data.ScaledAdvance + yExtraAdvance,
data.ScaledAdvance,
GlyphLayoutMode.VerticalRotated,
i == 0 && j == 0,
data.GraphemeIndex,
Expand All @@ -967,7 +938,7 @@ private static List<GlyphLayout> 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,
Expand All @@ -977,7 +948,7 @@ private static List<GlyphLayout> LayoutLineVerticalMixed(
}
}

penLocation.Y += data.ScaledAdvance + yExtraAdvance;
penLocation.Y += data.ScaledAdvance;
}

boxLocation.Y = originY;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading