Forráskód Böngészése

Better new line handling

Marcin Ziąbek 4 éve
szülő
commit
3112ee10cf

+ 3 - 1
QuestPDF.Examples/TextExamples.cs

@@ -29,11 +29,13 @@ namespace QuestPDF.Examples
                         {
                             text.Span("Let's start with bold text. ", TextStyle.Default.Bold().BackgroundColor(Colors.Grey.Lighten3).Size(16));
                             text.Span("Then something bigger. ", TextStyle.Default.Size(28).Color(Colors.DeepOrange.Darken2).BackgroundColor(Colors.Yellow.Lighten3).Underlined());
-                            text.Span("And tiny teeny-tiny. ", TextStyle.Default.Size(6));
+                            text.Span("And tiny \r\n teeny-tiny. ", TextStyle.Default.Size(6));
                             text.Span("Stroked text also works fine. ", TextStyle.Default.Size(14).Stroked().BackgroundColor(Colors.Grey.Lighten4));
                                
                             text.Span("0123456789-0123456789-0123456789-0123456789-0123456789-0123456789-0123456789", TextStyle.Default.Size(18));
                             
+                            text.NewLine();
+                            text.NewLine();
                             text.NewLine();
                             text.Span("Is it time for lorem  ipsum? ", TextStyle.Default.Size(12).Underlined().BackgroundColor(Colors.Grey.Lighten3));
                             text.Span(Placeholders.LoremIpsum(), TextStyle.Default.Size(12));

+ 9 - 0
QuestPDF/Elements/Text/Items/TextBlockSpan.cs

@@ -28,9 +28,18 @@ namespace QuestPDF.Elements.Text.Items
         {
             var paint = Style.ToPaint();
             var fontMetrics = Style.ToFontMetrics();
+
+            if (Text.Length == 0)
+            {
+                return new TextMeasurementResult
+                {
+                    Width = request.AvailableWidth
+                };
+            }
             
             // start breaking text from requested position
             var text = Text.Substring(request.StartIndex);
+            
             var breakingIndex = (int)paint.BreakText(text, request.AvailableWidth);
 
             if (breakingIndex <= 0)

+ 2 - 5
QuestPDF/Fluent/TextExtensions.cs

@@ -51,12 +51,9 @@ namespace QuestPDF.Fluent
         public void Span(string text, TextStyle? style = null)
         {
             style ??= DefaultStyle;
-            
-            if (string.IsNullOrWhiteSpace(text))
-                return;
-            
+ 
             var items = text
-                .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
+                .Split(new[] { Environment.NewLine }, StringSplitOptions.None)
                 .Select(x => new TextBlockSpan
                 {
                     Text = x,