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
43 changes: 33 additions & 10 deletions src/SixLabors.Fonts/TextLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static IReadOnlyList<TextRun> BuildTextRuns(ReadOnlySpan<char> text, Text
int start = 0;
int end = text.GetGraphemeCount();
List<TextRun> textRuns = [];
foreach (TextRun textRun in options.TextRuns!.OrderBy(x => x.Start))
foreach (TextRun textRun in options.TextRuns.OrderBy(x => x.Start))
{
// Fill gaps within runs.
if (textRun.Start > start)
Expand Down Expand Up @@ -1490,14 +1490,14 @@ VerticalOrientationType.Rotate or
if (textLine.TrySplitAt(breakAt, keepAll, out remaining))
{
processed = breakAt.PositionWrap;
textLines.Add(textLine.Finalize(options));
textLines.Add(textLine.Finalize(true));
textLine = remaining;
}
}
else if (textLine.TrySplitAt(wrappingLength, out remaining))
{
processed += textLine.Count;
textLines.Add(textLine.Finalize(options));
textLines.Add(textLine.Finalize());
textLine = remaining;
}
else
Expand Down Expand Up @@ -1529,7 +1529,7 @@ VerticalOrientationType.Rotate or
}

// Add the split part to the list and continue processing.
textLines.Add(textLine.Finalize(options));
textLines.Add(textLine.Finalize(breakAt.Required));
textLine = remaining;
}
else
Expand All @@ -1551,16 +1551,26 @@ VerticalOrientationType.Rotate or
break;
}

textLines.Add(textLine.Finalize(options));
textLines.Add(textLine.Finalize());
textLine = overflow;
}
}

textLines.Add(textLine.Finalize(options));
textLines.Add(textLine.Finalize(true));
break;
}
}

// Finally we justify each line that does not end a paragraph.
for (int i = 0; i < textLines.Count; i++)
{
TextLine line = textLines[i];
if (!line.SkipJustification)
{
line.Justify(options);
}
}

return new TextBox(textLines);
}

Expand Down Expand Up @@ -1696,6 +1706,8 @@ internal sealed class TextLine

public int Count => this.data.Count;

public bool SkipJustification { get; private set; }

public float ScaledLineAdvance { get; private set; }

public float ScaledMaxLineHeight { get; private set; } = -1;
Expand Down Expand Up @@ -1933,14 +1945,12 @@ private void TrimTrailingWhitespace()
}
}

public TextLine Finalize(TextOptions options)
public TextLine Finalize(bool skipJustification = false)
{
this.SkipJustification = skipJustification;
this.TrimTrailingWhitespace();
this.BidiReOrder();
RecalculateLineMetrics(this);

this.Justify(options);
RecalculateLineMetrics(this);
return this;
}

Expand Down Expand Up @@ -1975,6 +1985,11 @@ public void Justify(TextOptions options)
}
}

if (nonZeroCount == 0)
{
return;
}

float padding = delta / nonZeroCount;
for (int i = 0; i < this.data.Count - 1; i++)
{
Expand All @@ -1986,6 +2001,7 @@ public void Justify(TextOptions options)
}
}

RecalculateLineMetrics(this);
return;
Comment thread
JimBobSquarePants marked this conversation as resolved.
}

Expand All @@ -2003,6 +2019,11 @@ public void Justify(TextOptions options)
}
}

if (whiteSpaceCount == 0)
{
return;
}

float padding = delta / whiteSpaceCount;
for (int i = 0; i < this.data.Count - 1; i++)
{
Expand All @@ -2014,6 +2035,8 @@ public void Justify(TextOptions options)
}
}
}

RecalculateLineMetrics(this);
}
Comment thread
JimBobSquarePants marked this conversation as resolved.

public void BidiReOrder()
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
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
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
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
Loading