Browse Source

Fix: CheckIfAllTextGlyphsAreAvailable and Fallback break hyperlinks

MarcinZiabek 3 years ago
parent
commit
ec31c9b063

+ 16 - 6
QuestPDF/Elements/Text/FontFallback.cs

@@ -121,7 +121,11 @@ namespace QuestPDF.Elements.Text
         {
         {
             foreach (var textBlockItem in textBlockItems)
             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)
                     if (!Settings.CheckIfAllTextGlyphsAreAvailable && textBlockSpan.Style.Fallback == null)
                     {
                     {
@@ -130,19 +134,25 @@ namespace QuestPDF.Elements.Text
                     }
                     }
                     
                     
                     var textRuns = textBlockSpan.Text.SplitWithFontFallback(textBlockSpan.Style);
                     var textRuns = textBlockSpan.Text.SplitWithFontFallback(textBlockSpan.Style);
-
+                    
                     foreach (var textRun in textRuns)
                     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
                 else
                 {
                 {
-                    yield return textBlockItem;
+                    throw new NotSupportedException();
                 }
                 }
             }
             }
         }
         }

+ 1 - 1
QuestPDF/Elements/Text/Items/TextBlockSpan.cs

@@ -15,7 +15,7 @@ namespace QuestPDF.Elements.Text.Items
     {
     {
         public string Text { get; set; }
         public string Text { get; set; }
         public TextStyle Style { get; set; } = TextStyle.Default;
         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 ();
         private Dictionary<(int startIndex, float availableWidth), TextMeasurementResult?> MeasureCache = new ();
         protected virtual bool EnableTextCache => true; 
         protected virtual bool EnableTextCache => true;