Improved text run calculation

This commit is contained in:
Marcin Ziąbek
2021-05-05 11:21:53 +02:00
parent 5010b61565
commit e18b5170e6
+19 -12
View File
@@ -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());