Better new line handling
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user