ソースを参照

Fixed space removal

Marcin Ziąbek 4 年 前
コミット
3dfe7a59e0

+ 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 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)
             {
                 return new TextMeasurementResult