Fix(#499): inconsistent text height when using multiple lines

This commit is contained in:
MarcinZiabek
2023-04-16 11:42:38 +02:00
parent e6c7befac4
commit 6ad465b9fa
2 changed files with 43 additions and 1 deletions
+30
View File
@@ -974,5 +974,35 @@ namespace QuestPDF.Examples
});
});
}
[Test]
public void InconsistentLineHeightWhenUsingNewLineTest()
{
RenderingTest
.Create()
.PageSize(PageSizes.A4)
.ProduceImages()
.ShowResults()
.Render(container =>
{
container
.Padding(20)
.Background(Colors.Grey.Lighten4)
.Text(text =>
{
text.DefaultTextStyle(x => x.FontSize(16));
text.Line(Placeholders.Paragraph());
text.Line("");
text.Line(Placeholders.Paragraph());
text.Line(Placeholders.Label()).FontSize(48);
text.Line(Placeholders.Paragraph());
text.Line("");
text.Line(Placeholders.Paragraph());
});
});
}
}
}
+13 -1
View File
@@ -88,7 +88,19 @@ namespace QuestPDF.Fluent
if (!TextBlocks.Any())
TextBlocks.Add(new TextBlock());
TextBlocks.Last().Items.Add(item);
var lastTextBlock = TextBlocks.Last();
// TextBlock with only one Span with empty text is a special case.
// It represents an empty line with a given text style (e.g. text height).
// When more content is put to text block, the first items should be ignored (removed in this case).
// This change fixes inconsistent line height problem.
if (lastTextBlock.Items.Count == 1 && lastTextBlock.Items[0] is TextBlockSpan { Text: "" })
{
lastTextBlock.Items[0] = item;
return;
}
lastTextBlock.Items.Add(item);
}
[Obsolete("This element has been renamed since version 2022.3. Please use the overload that returns a TextSpanDescriptor object which allows to specify text style.")]