From ec31c9b063593a07fccd9690faceaccd2b8dceba Mon Sep 17 00:00:00 2001 From: MarcinZiabek Date: Tue, 11 Oct 2022 10:31:31 +0200 Subject: [PATCH] Fix: CheckIfAllTextGlyphsAreAvailable and Fallback break hyperlinks --- QuestPDF/Elements/Text/FontFallback.cs | 22 ++++++++++++++----- QuestPDF/Elements/Text/Items/TextBlockSpan.cs | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/QuestPDF/Elements/Text/FontFallback.cs b/QuestPDF/Elements/Text/FontFallback.cs index 5eabe9c..cb215d4 100644 --- a/QuestPDF/Elements/Text/FontFallback.cs +++ b/QuestPDF/Elements/Text/FontFallback.cs @@ -121,7 +121,11 @@ namespace QuestPDF.Elements.Text { foreach (var textBlockItem in textBlockItems) { - if (textBlockItem is TextBlockSpan textBlockSpan and not TextBlockPageNumber) + if (textBlockItem is TextBlockPageNumber or TextBlockElement) + { + yield return textBlockItem; + } + else if (textBlockItem is TextBlockSpan textBlockSpan) { if (!Settings.CheckIfAllTextGlyphsAreAvailable && textBlockSpan.Style.Fallback == null) { @@ -130,19 +134,25 @@ namespace QuestPDF.Elements.Text } var textRuns = textBlockSpan.Text.SplitWithFontFallback(textBlockSpan.Style); - + foreach (var textRun in textRuns) { - yield return new TextBlockSpan + var newElement = textBlockSpan switch { - Text = textRun.Content, - Style = textRun.Style + TextBlockHyperlink hyperlink => new TextBlockHyperlink { Url = hyperlink.Url }, + TextBlockSectionLink sectionLink => new TextBlockSectionLink { SectionName = sectionLink.SectionName }, + TextBlockSpan => new TextBlockSpan() }; + + newElement.Text = textRun.Content; + newElement.Style = textRun.Style; + + yield return newElement; } } else { - yield return textBlockItem; + throw new NotSupportedException(); } } } diff --git a/QuestPDF/Elements/Text/Items/TextBlockSpan.cs b/QuestPDF/Elements/Text/Items/TextBlockSpan.cs index 4dfad0f..459acc3 100644 --- a/QuestPDF/Elements/Text/Items/TextBlockSpan.cs +++ b/QuestPDF/Elements/Text/Items/TextBlockSpan.cs @@ -15,7 +15,7 @@ namespace QuestPDF.Elements.Text.Items { public string Text { get; set; } public TextStyle Style { get; set; } = TextStyle.Default; - public TextShapingResult? TextShapingResult { get; set; } + private TextShapingResult? TextShapingResult { get; set; } private Dictionary<(int startIndex, float availableWidth), TextMeasurementResult?> MeasureCache = new (); protected virtual bool EnableTextCache => true;