|
@@ -4,7 +4,6 @@ using System.Linq;
|
|
|
using QuestPDF.Drawing;
|
|
using QuestPDF.Drawing;
|
|
|
using QuestPDF.Drawing.Exceptions;
|
|
using QuestPDF.Drawing.Exceptions;
|
|
|
using QuestPDF.Elements.Text.Items;
|
|
using QuestPDF.Elements.Text.Items;
|
|
|
-using QuestPDF.Helpers;
|
|
|
|
|
using QuestPDF.Infrastructure;
|
|
using QuestPDF.Infrastructure;
|
|
|
using QuestPDF.Skia;
|
|
using QuestPDF.Skia;
|
|
|
using QuestPDF.Skia.Text;
|
|
using QuestPDF.Skia.Text;
|
|
@@ -37,6 +36,7 @@ namespace QuestPDF.Elements.Text
|
|
|
private float MaximumWidth { get; set; }
|
|
private float MaximumWidth { get; set; }
|
|
|
|
|
|
|
|
private bool IsRendered { get; set; }
|
|
private bool IsRendered { get; set; }
|
|
|
|
|
+ private bool? ContainsOnlyWhiteSpace { get; set; }
|
|
|
private int CurrentLineIndex { get; set; }
|
|
private int CurrentLineIndex { get; set; }
|
|
|
private float CurrentTopOffset { get; set; }
|
|
private float CurrentTopOffset { get; set; }
|
|
|
|
|
|
|
@@ -61,6 +61,13 @@ namespace QuestPDF.Elements.Text
|
|
|
|
|
|
|
|
if (IsRendered)
|
|
if (IsRendered)
|
|
|
return SpacePlan.Empty();
|
|
return SpacePlan.Empty();
|
|
|
|
|
+
|
|
|
|
|
+ // if the text block does not contain any items, or all items are null, return SpacePlan.Empty
|
|
|
|
|
+ // but if the text block contains only whitespace, return SpacePlan.FullRender with zero width and font-based height
|
|
|
|
|
+ ContainsOnlyWhiteSpace ??= Items.All(x => x is TextBlockSpan textBlockSpan && string.IsNullOrWhiteSpace(textBlockSpan.Text));
|
|
|
|
|
+
|
|
|
|
|
+ if (ContainsOnlyWhiteSpace == true)
|
|
|
|
|
+ return SpacePlan.FullRender(0, MeasureHeightOfParagraphContainingOnlyWhiteSpace());
|
|
|
|
|
|
|
|
Initialize();
|
|
Initialize();
|
|
|
|
|
|
|
@@ -108,6 +115,9 @@ namespace QuestPDF.Elements.Text
|
|
|
if (IsRendered)
|
|
if (IsRendered)
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
|
|
+ if (ContainsOnlyWhiteSpace == true)
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
CalculateParagraphMetrics(availableSpace);
|
|
CalculateParagraphMetrics(availableSpace);
|
|
|
|
|
|
|
|
if (MaximumWidth == 0)
|
|
if (MaximumWidth == 0)
|
|
@@ -501,5 +511,30 @@ namespace QuestPDF.Elements.Text
|
|
|
$"You can disable this check by setting the 'Settings.CheckIfAllTextGlyphsAreAvailable' option to 'false'. \n" +
|
|
$"You can disable this check by setting the 'Settings.CheckIfAllTextGlyphsAreAvailable' option to 'false'. \n" +
|
|
|
$"However, this may result with text glyphs being incorrectly rendered without any warning.");
|
|
$"However, this may result with text glyphs being incorrectly rendered without any warning.");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private float MeasureHeightOfParagraphContainingOnlyWhiteSpace()
|
|
|
|
|
+ {
|
|
|
|
|
+ var paragraphStyle = new ParagraphStyleConfiguration
|
|
|
|
|
+ {
|
|
|
|
|
+ Alignment = ParagraphStyleConfiguration.TextAlign.Start,
|
|
|
|
|
+ Direction = ParagraphStyleConfiguration.TextDirection.Ltr
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ var builder = SkParagraphBuilderPoolManager.Get(paragraphStyle);
|
|
|
|
|
+
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ foreach (var textBlockSpan in Items.OfType<TextBlockSpan>())
|
|
|
|
|
+ builder.AddText("\u00A0", textBlockSpan.Style.GetSkTextStyle()); // non-breaking space
|
|
|
|
|
+
|
|
|
|
|
+ var paragraph = builder.CreateParagraph();
|
|
|
|
|
+ paragraph.PlanLayout(1000);
|
|
|
|
|
+ return paragraph.GetLineMetrics().First().Height;
|
|
|
|
|
+ }
|
|
|
|
|
+ finally
|
|
|
|
|
+ {
|
|
|
|
|
+ SkParagraphBuilderPoolManager.Return(builder);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|