diff --git a/QuestPDF/Elements/TextRun.cs b/QuestPDF/Elements/TextRun.cs index 6bba5dc..b27abf9 100644 --- a/QuestPDF/Elements/TextRun.cs +++ b/QuestPDF/Elements/TextRun.cs @@ -17,26 +17,33 @@ namespace QuestPDF.Elements { var measurements = Elements.Select(x => x.Measure()).ToList(); + var metrics = Elements + .Select(x => x.Style.ToPaint()) + .Select(x => x.FontMetrics) + .ToList(); + + var lineHeight = metrics.Max(x => -x.Ascent) + metrics.Max(x => x.Descent); + var width = measurements.Sum(x => x.Width); - //var height = measurements.Max(x => x.Height); - //var height = measurements.Max(x => x.Position.Bottom) + measurements.Max(x => x.Position.Height); - var height = Elements.Max(x => x.Style.Size * x.Style.LineHeight); - - return new FullRender(width, height); + + return new FullRender(width, lineHeight); } internal override void Draw(ICanvas canvas, Size availableSpace) { - var measurements = Elements.Select(x => x.Measure()).ToList(); - - var lineHeight = Elements.Max(x => x.Style.Size * x.Style.LineHeight); - var textHeight = Elements.Max(x => x.Style.Size); + var measurements = Elements + .Select(x => x.Measure()) + .ToList(); - var lineHeightOffset = (lineHeight - textHeight) / 2; - var baselineOffset = measurements.Max(x => -x.Position.Top); - var offset = lineHeightOffset + baselineOffset; + var metrics = Elements + .Select(x => x.Style.ToPaint()) + .Select(x => x.FontMetrics) + .ToList(); + var offset = metrics.Max(x => -x.Ascent); + var lineHeight = metrics.Max(x => -x.Ascent) + metrics.Max(x => x.Descent); + using var typeface = SKTypeface.FromFamilyName("Helvetica"); using var shaper = new SKShaper(typeface); var shaped = shaper.Shape("Podstawowy łaciński — ✔️ ❤️ ☆ Tabela znaków Unicode", Elements.First().Style.ToPaint());