Skip to content

Commit 145e9ca

Browse files
authored
Merge pull request #201 from tinokrueger/features/text-segment-formatter-text-width-issue
Fixed text width calculation in XTextSegementFormater
2 parents 0d1c4c6 + 7970b12 commit 145e9ca

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

PdfSharpCore/Drawing.Layout/XTextSegmentFormatter.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,16 @@ public XSize CalculateTextSize(IEnumerable<TextSegment> textSegments, double wid
158158
maxLineHeight = Math.Max(maxLineHeight, blocks[i].Environment.LineSpace);
159159
}
160160

161-
return new XSize(width, height + maxLineHeight);
161+
var calculatedWith = blocks.Any()
162+
? blocks.Max(b => b.Location.X + b.Width)
163+
: width;
164+
165+
if (width < calculatedWith)
166+
{
167+
calculatedWith = width;
168+
}
169+
170+
return new XSize(calculatedWith, height + maxLineHeight);
162171
}
163172

164173
private void ProcessTextSegments(IEnumerable<TextSegment> textSegments, XRect layoutRectangle, XStringFormat format, Action<Block, double, double> applyBlock)

0 commit comments

Comments
 (0)