Optimized the TextLine object
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using QuestPDF.Examples.Engine;
|
||||
using QuestPDF.Fluent;
|
||||
@@ -35,7 +36,7 @@ namespace QuestPDF.Examples
|
||||
|
||||
text.Span(Placeholders.LoremIpsum());
|
||||
|
||||
text.Line("This is target text that does not show up. > This is a short sentence that will be wrapped into second line hopefully, right? <");
|
||||
text.Line($"This is target text that does not show up. {DateTime.UtcNow:T} > This is a short sentence that will be wrapped into second line hopefully, right? <");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuestPDF.Elements.Text.Items;
|
||||
|
||||
@@ -6,14 +7,33 @@ namespace QuestPDF.Elements.Text.Calculation
|
||||
{
|
||||
internal class TextLine
|
||||
{
|
||||
public ICollection<TextLineElement> Elements { get; set; }
|
||||
public ICollection<TextLineElement> Elements { get; private set; }
|
||||
|
||||
public float TextHeight => Elements.Max(x => x.Measurement.Height);
|
||||
public float LineHeight => Elements.Max(x => x.Measurement.LineHeight * x.Measurement.Height);
|
||||
public float TextHeight { get; private set; }
|
||||
public float LineHeight { get; private set; }
|
||||
|
||||
public float Ascent => Elements.Min(x => x.Measurement.Ascent) - (LineHeight - TextHeight) / 2;
|
||||
public float Descent => Elements.Max(x => x.Measurement.Descent) + (LineHeight - TextHeight) / 2;
|
||||
public float Ascent { get; private set; }
|
||||
public float Descent { get; private set; }
|
||||
|
||||
public float Width => Elements.Sum(x => x.Measurement.Width);
|
||||
public float Width { get; private set; }
|
||||
|
||||
public static TextLine From(ICollection<TextLineElement> elements)
|
||||
{
|
||||
var textHeight = elements.Max(x => x.Measurement.Height);
|
||||
var lineHeight = elements.Max(x => x.Measurement.LineHeight * x.Measurement.Height);
|
||||
|
||||
return new TextLine
|
||||
{
|
||||
Elements = elements,
|
||||
|
||||
TextHeight = textHeight,
|
||||
LineHeight = lineHeight,
|
||||
|
||||
Ascent = elements.Min(x => x.Measurement.Ascent) - (lineHeight - textHeight) / 2,
|
||||
Descent = elements.Max(x => x.Measurement.Descent) + (lineHeight - textHeight) / 2,
|
||||
|
||||
Width = elements.Sum(x => x.Measurement.Width)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using QuestPDF.Elements.Text.Calculation;
|
||||
using QuestPDF.Elements.Text.Items;
|
||||
|
||||
namespace QuestPDF.Elements.Text.Items
|
||||
namespace QuestPDF.Elements.Text.Calculation
|
||||
{
|
||||
internal class TextLineElement
|
||||
{
|
||||
|
||||
@@ -192,10 +192,7 @@ namespace QuestPDF.Elements.Text
|
||||
queue.Dequeue();
|
||||
}
|
||||
|
||||
return new TextLine
|
||||
{
|
||||
Elements = currentLineElements
|
||||
};
|
||||
return TextLine.From(currentLineElements);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user