diff --git a/QuestPDF.Examples/TextExample.cs b/QuestPDF.Examples/TextExample.cs index 1bb81fe..243062e 100644 --- a/QuestPDF.Examples/TextExample.cs +++ b/QuestPDF.Examples/TextExample.cs @@ -13,7 +13,52 @@ namespace QuestPDF.Examples public class TextExample : ExampleTestBase { [ShowResult] - [ImageSize(1600, 500)] + [ImageSize(1400, 600)] + public void OldText(IContainer container) + { + var fonts = new[] + { + Fonts.Arial, + Fonts.Calibri, + Fonts.Cambria, + Fonts.Candara, + Fonts.ComicSans, + Fonts.Consolas, + Fonts.Corbel, + Fonts.Courier, + Fonts.CourierNew, + Fonts.Georgia, + Fonts.Impact, + Fonts.LucidaConsole, + Fonts.SegoeSD, + Fonts.SegoeUI, + Fonts.Tahoma, + Fonts.TimesNewRoman, + Fonts.TimesRoman, + Fonts.Trebuchet, + Fonts.Verdana, + }; + + container + .Padding(50) + .Grid(stack => + { + stack.Spacing(10); + stack.Columns(2); + + foreach (var font in fonts) + { + stack + .Element() + .Box() + .Background(Placeholders.BackgroundColor()) + .Text($"Lorem ipsum dolor sit amet {font}", TextStyle.Default.Size(24).FontType(font)); + } + }); + } + + //[ShowResult] + [ImageSize(1400, 800)] public void Test(IContainer container) { List Lorem() diff --git a/QuestPDF/Elements/Text.cs b/QuestPDF/Elements/Text.cs index 6e611ca..0535639 100644 --- a/QuestPDF/Elements/Text.cs +++ b/QuestPDF/Elements/Text.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using QuestPDF.Drawing; using QuestPDF.Drawing.SpacePlan; +using QuestPDF.Fluent; using QuestPDF.Infrastructure; using Size = QuestPDF.Infrastructure.Size; @@ -24,7 +25,8 @@ namespace QuestPDF.Elements .DefaultIfEmpty(0) .Max(); - var realHeight = lines.Count * LineHeight; + var paint = Style.ToPaint().FontMetrics; + var realHeight = -paint.Ascent + paint.Descent; if (realHeight > availableSpace.Height + Size.Epsilon) return new Wrap(); @@ -34,12 +36,15 @@ namespace QuestPDF.Elements internal override void Draw(ICanvas canvas, Size availableSpace) { + var paint = Style.ToPaint().FontMetrics; + var offeset = -paint.Ascent; // paint.Ascent - Style.Size; + var lines = BreakLines(availableSpace.Width); var offsetTop = 0f; var offsetLeft = GetLeftOffset(); - canvas.Translate(new Position(0, Style.Size)); + canvas.Translate(new Position(0, offeset)); foreach (var line in lines) { @@ -47,7 +52,7 @@ namespace QuestPDF.Elements offsetTop += LineHeight; } - canvas.Translate(new Position(0, -Style.Size)); + canvas.Translate(new Position(0, -offeset)); float GetLeftOffset() {