Better new line handling

This commit is contained in:
Marcin Ziąbek
2021-08-27 20:25:20 +02:00
parent 899c138842
commit 3112ee10cf
3 changed files with 14 additions and 6 deletions
+3 -1
View File
@@ -29,11 +29,13 @@ namespace QuestPDF.Examples
{
text.Span("Let's start with bold text. ", TextStyle.Default.Bold().BackgroundColor(Colors.Grey.Lighten3).Size(16));
text.Span("Then something bigger. ", TextStyle.Default.Size(28).Color(Colors.DeepOrange.Darken2).BackgroundColor(Colors.Yellow.Lighten3).Underlined());
text.Span("And tiny teeny-tiny. ", TextStyle.Default.Size(6));
text.Span("And tiny \r\n teeny-tiny. ", TextStyle.Default.Size(6));
text.Span("Stroked text also works fine. ", TextStyle.Default.Size(14).Stroked().BackgroundColor(Colors.Grey.Lighten4));
text.Span("0123456789-0123456789-0123456789-0123456789-0123456789-0123456789-0123456789", TextStyle.Default.Size(18));
text.NewLine();
text.NewLine();
text.NewLine();
text.Span("Is it time for lorem ipsum? ", TextStyle.Default.Size(12).Underlined().BackgroundColor(Colors.Grey.Lighten3));
text.Span(Placeholders.LoremIpsum(), TextStyle.Default.Size(12));
@@ -28,9 +28,18 @@ namespace QuestPDF.Elements.Text.Items
{
var paint = Style.ToPaint();
var fontMetrics = Style.ToFontMetrics();
if (Text.Length == 0)
{
return new TextMeasurementResult
{
Width = request.AvailableWidth
};
}
// start breaking text from requested position
var text = Text.Substring(request.StartIndex);
var breakingIndex = (int)paint.BreakText(text, request.AvailableWidth);
if (breakingIndex <= 0)
+2 -5
View File
@@ -51,12 +51,9 @@ namespace QuestPDF.Fluent
public void Span(string text, TextStyle? style = null)
{
style ??= DefaultStyle;
if (string.IsNullOrWhiteSpace(text))
return;
var items = text
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
.Select(x => new TextBlockSpan
{
Text = x,