Browse Source

Fixed space removal

Marcin Ziąbek 4 years ago
parent
commit
3dfe7a59e0
2 changed files with 34 additions and 6 deletions
  1. 27 2
      QuestPDF.Examples/TextExamples.cs
  2. 7 4
      QuestPDF/Elements/Text/Items/TextBlockSpan.cs

+ 27 - 2
QuestPDF.Examples/TextExamples.cs

@@ -89,9 +89,34 @@ namespace QuestPDF.Examples
                 });
                 });
         }
         }
 
 
-        T MyFunc<T>(T arg)
+        [Test]
+        public void PageNumber()
         {
         {
-            return arg;
+            RenderingTest
+                .Create()
+                .PageSize(500, 400)
+                .FileName()
+                .ProduceImages()
+                .ShowResults()
+                .Render(container =>
+                {
+                    container
+                        .Padding(10)
+                        .Box()
+                        .Border(1)
+                        .Padding(10)
+                        .Text(text =>
+                        {
+                            text.DefaultTextStyle(TextStyle.Default);
+                            text.AlignLeft();
+                            text.ParagraphSpacing(10);
+
+                            text.Span("This is page number ");
+                            text.CurrentPageNumber();
+                            text.Span(" out of ");
+                            text.TotalPages();
+                        });
+                });
         }
         }
     }
     }
 }
 }

+ 7 - 4
QuestPDF/Elements/Text/Items/TextBlockSpan.cs

@@ -32,10 +32,13 @@ namespace QuestPDF.Elements.Text.Items
             var fontMetrics = Style.ToFontMetrics();
             var fontMetrics = Style.ToFontMetrics();
 
 
             var startIndex = request.StartIndex;
             var startIndex = request.StartIndex;
-            
-            while (startIndex + 1 < Text.Length && Text[startIndex] == space)
-                startIndex++;
-            
+
+            if (request.IsFirstLineElement)
+            {
+                while (startIndex + 1 < Text.Length && Text[startIndex] == space)
+                    startIndex++;
+            }
+
             if (Text.Length == 0)
             if (Text.Length == 0)
             {
             {
                 return new TextMeasurementResult
                 return new TextMeasurementResult