Browse Source

Minor code adjustments

MarcinZiabek 3 years ago
parent
commit
056e3f244c

+ 2 - 1
QuestPDF.Examples/TextExamples.cs

@@ -590,7 +590,7 @@ namespace QuestPDF.Examples
                             text.Span("Complex Unicode structure: ");
                             
                             
-                            text.Span("T̶̖̔͆͆̽̔ḩ̷̼̫̐̈́̀͜͝͝ì̶͇̤͓̱̣͇͓͉̎s̵̡̟̹͍̜͉̗̾͛̈̐́͋͂͝͠ͅ ̴̨͙͍͇̭̒͗̀́͝ì̷̡̺͉̼̏̏̉̌͝s̷͍͙̗̰̖͙̈̑̂̔͑͊̌̓̊̇͜ ̶̛̼͚͊̅͘ṭ̷̨̘̣̙̖͉͌̏̂̅͑̄̽̕͝ȅ̶̲̲̙̭͈̬̣͔̝͔̈́͝s̸̢̯̪̫͓̭̮̓̀͆͜ț̸̢͉̞̥̤̏̌̓͝").FontColor(Colors.Red.Medium);
+                            text.Span("T̶̖̔͆͆̽̔ḩ̷̼̫̐̈́̀͜͝͝ì̶͇̤͓̱̣͇͓͉̎s̵̡̟̹͍̜͉̗̾͛̈̐́͋͂͝͠ͅ ̴̨͙͍͇̭̒͗̀́͝ì̷̡̺͉̼̏̏̉̌͝s̷͍͙̗̰̖͙̈̑̂̔͑͊̌̓̊̇͜ ̶̛̼͚͊̅͘ṭ̷̨̘̣̙̖͉͌̏̂̅͑̄̽̕͝ȅ̶̲̲̙̭͈̬̣͔̝͔̈́͝s̸̢̯̪̫͓̭̮̓̀͆͜ț̸̢͉̞̥̤̏̌̓͝").FontFamily(Fonts.Calibri).FontColor(Colors.Red.Medium);
                             
                             
                             text.Span(".");
@@ -614,6 +614,7 @@ namespace QuestPDF.Examples
                         .MinimalBox()
                         .Background(Colors.Grey.Lighten2)
                         .Text("ينا الألم. في بعض الأحيان ونظراً للالتزامات التي يفرضها علينا")
+                        .FontFamily(Fonts.Calibri)
                         .FontSize(20);
                 });
         }

+ 6 - 1
QuestPDF/Drawing/FontManager.cs

@@ -43,8 +43,13 @@ namespace QuestPDF.Drawing
             }
         }
 
-        [Obsolete("Since version 2022.3, the FontManager class offers better font type matching support. Please use the RegisterFont(Stream stream) method.")]
+        [Obsolete("Since version 2022.8 this method has been renamed. Please use the RegisterFontWithCustomName method.")]
         public static void RegisterFontType(string fontName, Stream stream)
+        {
+            RegisterFontWithCustomName(fontName, stream);
+        }
+        
+        public static void RegisterFontWithCustomName(string fontName, Stream stream)
         {
             using var fontData = SKData.Create(stream);
             RegisterFontType(fontData);

+ 12 - 10
QuestPDF/Elements/Text/TextBlock.cs

@@ -14,27 +14,29 @@ namespace QuestPDF.Elements.Text
         public List<ITextBlockItem> Items { get; set; } = new List<ITextBlockItem>();
 
         public string Text => string.Join(" ", Items.Where(x => x is TextBlockSpan).Cast<TextBlockSpan>().Select(x => x.Text));
-        
+
         private Queue<ITextBlockItem> RenderingQueue { get; set; }
         private int CurrentElementIndex { get; set; }
 
         public void ResetState()
         {
-            // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
-            // Create queue when we don't have one yet, otherwise clear the existing one so it re-uses the internal array under the hood.
-            if (RenderingQueue == null)
-            {
-                RenderingQueue = new Queue<ITextBlockItem>(Items);
-            }
-            else
+            InitializeQueue();
+            CurrentElementIndex = 0;
+
+            void InitializeQueue()
             {
+                // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
+                if (RenderingQueue == null)
+                {
+                    RenderingQueue = new Queue<ITextBlockItem>(Items);
+                    return;
+                }
+                
                 RenderingQueue.Clear();
             
                 foreach (var item in Items)
                     RenderingQueue.Enqueue(item);
             }
-            
-            CurrentElementIndex = 0;
         }
 
         internal override SpacePlan Measure(Size availableSpace)

+ 5 - 7
QuestPDF/Helpers/Helpers.cs

@@ -46,13 +46,11 @@ namespace QuestPDF.Helpers
 
         internal static void VisitChildren(this Element? element, Action<Element?> handler)
         {
-            if (element != null)
-            {
-                foreach (var child in element.GetChildren())
-                {
-                    if (child != null) VisitChildren(child, handler);
-                }
-            }
+            if (element == null)
+                return;
+            
+            foreach (var child in element.GetChildren())
+                VisitChildren(child, handler);
 
             handler(element);
         }