Skip to content
Merged
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
16 changes: 11 additions & 5 deletions PdfSharpCore/Drawing.Layout/XTextSegmentFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public void DrawString(IEnumerable<TextSegment> textSegments, XRect layoutRectan
textSegments,
layoutRectangle,
format,
(block, dx, dy) => _gfx.DrawString(block.Text, block.Environment.Font, block.Environment.Brush, dx + block.Location.X, dy + block.Location.Y)
(block, dx, dy) => _gfx.DrawString(block.Text, block.Environment.Font, block.Environment.Brush, dx + block.Location.X, dy + block.Location.Y),
false
);
}

Expand Down Expand Up @@ -144,9 +145,11 @@ public XSize CalculateTextSize(IEnumerable<TextSegment> textSegments, double wid
var layoutRectangle = new XRect(0, 0, width, 100000000);
var blocks = new List<Block>();

ProcessTextSegments(textSegments, layoutRectangle, format, (block, dx, dy) => blocks.Add(block));
ProcessTextSegments(textSegments, layoutRectangle, format, (block, dx, dy) => blocks.Add(block), true);

var height = blocks.Max(b => b.Location.Y);
var height = blocks.Any()
? blocks.Max(b => b.Location.Y)
: 0;
var maxLineHeight = 0.0;
for (int i = blocks.Count - 1; i >= 0; i--)
{
Expand All @@ -170,7 +173,7 @@ public XSize CalculateTextSize(IEnumerable<TextSegment> textSegments, double wid
return new XSize(calculatedWith, height + maxLineHeight);
}

private void ProcessTextSegments(IEnumerable<TextSegment> textSegments, XRect layoutRectangle, XStringFormat format, Action<Block, double, double> applyBlock)
private void ProcessTextSegments(IEnumerable<TextSegment> textSegments, XRect layoutRectangle, XStringFormat format, Action<Block, double, double> applyBlock, bool applyBlockIfLineBreak)
{
if (textSegments.All(ts => string.IsNullOrEmpty(ts.Text)))
{
Expand Down Expand Up @@ -242,7 +245,7 @@ private void ProcessTextSegments(IEnumerable<TextSegment> textSegments, XRect la
break;
}

if (block.Type == BlockType.LineBreak)
if (block.Type == BlockType.LineBreak && !applyBlockIfLineBreak)
{
continue;
}
Expand Down Expand Up @@ -397,6 +400,9 @@ private void CreateLayout(List<List<Block>> blockUnits, XRect layoutRectangle)

break;
}

// necessary to correctly calculate closing line breaks
block.Location = new XPoint(0, y);
}
else
{
Expand Down