From 056e3f244c3e4e70ad76d1bbd7639bcfea4c6828 Mon Sep 17 00:00:00 2001 From: MarcinZiabek Date: Sat, 30 Jul 2022 21:30:04 +0200 Subject: [PATCH] Minor code adjustments --- QuestPDF.Examples/TextExamples.cs | 3 ++- QuestPDF/Drawing/FontManager.cs | 7 ++++++- QuestPDF/Elements/Text/TextBlock.cs | 22 ++++++++++++---------- QuestPDF/Helpers/Helpers.cs | 12 +++++------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/QuestPDF.Examples/TextExamples.cs b/QuestPDF.Examples/TextExamples.cs index 77c7b14..c68252a 100644 --- a/QuestPDF.Examples/TextExamples.cs +++ b/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); }); } diff --git a/QuestPDF/Drawing/FontManager.cs b/QuestPDF/Drawing/FontManager.cs index 7192205..280cca8 100644 --- a/QuestPDF/Drawing/FontManager.cs +++ b/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); diff --git a/QuestPDF/Elements/Text/TextBlock.cs b/QuestPDF/Elements/Text/TextBlock.cs index 5ba462e..6420a7d 100644 --- a/QuestPDF/Elements/Text/TextBlock.cs +++ b/QuestPDF/Elements/Text/TextBlock.cs @@ -14,27 +14,29 @@ namespace QuestPDF.Elements.Text public List Items { get; set; } = new List(); public string Text => string.Join(" ", Items.Where(x => x is TextBlockSpan).Cast().Select(x => x.Text)); - + private Queue 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(Items); - } - else + InitializeQueue(); + CurrentElementIndex = 0; + + void InitializeQueue() { + // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract + if (RenderingQueue == null) + { + RenderingQueue = new Queue(Items); + return; + } + RenderingQueue.Clear(); foreach (var item in Items) RenderingQueue.Enqueue(item); } - - CurrentElementIndex = 0; } internal override SpacePlan Measure(Size availableSpace) diff --git a/QuestPDF/Helpers/Helpers.cs b/QuestPDF/Helpers/Helpers.cs index 23e3f1d..799ad82 100644 --- a/QuestPDF/Helpers/Helpers.cs +++ b/QuestPDF/Helpers/Helpers.cs @@ -46,13 +46,11 @@ namespace QuestPDF.Helpers internal static void VisitChildren(this Element? element, Action 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); }