|
@@ -1,6 +1,7 @@
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
|
+using QuestPDF.Drawing;
|
|
|
using QuestPDF.Elements;
|
|
using QuestPDF.Elements;
|
|
|
using QuestPDF.Elements.Text;
|
|
using QuestPDF.Elements.Text;
|
|
|
using QuestPDF.Elements.Text.Items;
|
|
using QuestPDF.Elements.Text.Items;
|
|
@@ -13,7 +14,7 @@ namespace QuestPDF.Fluent
|
|
|
{
|
|
{
|
|
|
private ICollection<TextBlock> TextBlocks { get; } = new List<TextBlock>();
|
|
private ICollection<TextBlock> TextBlocks { get; } = new List<TextBlock>();
|
|
|
private TextStyle DefaultStyle { get; set; } = TextStyle.Default;
|
|
private TextStyle DefaultStyle { get; set; } = TextStyle.Default;
|
|
|
- private HorizontalAlignment Alignment { get; set; } = HorizontalAlignment.Left;
|
|
|
|
|
|
|
+ internal HorizontalAlignment Alignment { get; set; } = HorizontalAlignment.Left;
|
|
|
private float Spacing { get; set; } = 0f;
|
|
private float Spacing { get; set; } = 0f;
|
|
|
|
|
|
|
|
public void DefaultTextStyle(TextStyle style)
|
|
public void DefaultTextStyle(TextStyle style)
|
|
@@ -49,9 +50,12 @@ namespace QuestPDF.Fluent
|
|
|
TextBlocks.Last().Children.Add(item);
|
|
TextBlocks.Last().Children.Add(item);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void Span(string text, TextStyle? style = null)
|
|
|
|
|
|
|
+ public void Span(string? text, TextStyle? style = null)
|
|
|
{
|
|
{
|
|
|
- style ??= DefaultStyle;
|
|
|
|
|
|
|
+ if (IsNullOrEmpty(text))
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ style ??= TextStyle.Default;
|
|
|
|
|
|
|
|
var items = text
|
|
var items = text
|
|
|
.Replace("\r", string.Empty)
|
|
.Replace("\r", string.Empty)
|
|
@@ -75,16 +79,12 @@ namespace QuestPDF.Fluent
|
|
|
.ForEach(TextBlocks.Add);
|
|
.ForEach(TextBlocks.Add);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void Line(string text, TextStyle? style = null)
|
|
|
|
|
|
|
+ public void Line(string? text, TextStyle? style = null)
|
|
|
{
|
|
{
|
|
|
|
|
+ text ??= string.Empty;
|
|
|
Span(text + Environment.NewLine, style);
|
|
Span(text + Environment.NewLine, style);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public void Line(string text)
|
|
|
|
|
- {
|
|
|
|
|
- Span(text + Environment.NewLine);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
public void EmptyLine()
|
|
public void EmptyLine()
|
|
|
{
|
|
{
|
|
|
Span(Environment.NewLine);
|
|
Span(Environment.NewLine);
|
|
@@ -92,7 +92,10 @@ namespace QuestPDF.Fluent
|
|
|
|
|
|
|
|
private void PageNumber(string slotName, TextStyle? style = null)
|
|
private void PageNumber(string slotName, TextStyle? style = null)
|
|
|
{
|
|
{
|
|
|
- style ??= DefaultStyle;
|
|
|
|
|
|
|
+ if (IsNullOrEmpty(slotName))
|
|
|
|
|
+ throw new ArgumentException(nameof(slotName));
|
|
|
|
|
+
|
|
|
|
|
+ style ??= TextStyle.Default;
|
|
|
|
|
|
|
|
AddItemToLastTextBlock(new TextBlockPageNumber()
|
|
AddItemToLastTextBlock(new TextBlockPageNumber()
|
|
|
{
|
|
{
|
|
@@ -113,12 +116,21 @@ namespace QuestPDF.Fluent
|
|
|
|
|
|
|
|
public void PageNumberOfLocation(string locationName, TextStyle? style = null)
|
|
public void PageNumberOfLocation(string locationName, TextStyle? style = null)
|
|
|
{
|
|
{
|
|
|
|
|
+ if (IsNullOrEmpty(locationName))
|
|
|
|
|
+ throw new ArgumentException(nameof(locationName));
|
|
|
|
|
+
|
|
|
PageNumber(locationName, style);
|
|
PageNumber(locationName, style);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void InternalLocation(string text, string locationName, TextStyle? style = null)
|
|
|
|
|
|
|
+ public void InternalLocation(string? text, string locationName, TextStyle? style = null)
|
|
|
{
|
|
{
|
|
|
- style ??= DefaultStyle;
|
|
|
|
|
|
|
+ if (IsNullOrEmpty(text))
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ if (IsNullOrEmpty(locationName))
|
|
|
|
|
+ throw new ArgumentException(nameof(locationName));
|
|
|
|
|
+
|
|
|
|
|
+ style ??= TextStyle.Default;
|
|
|
|
|
|
|
|
AddItemToLastTextBlock(new TextBlockInternalLink
|
|
AddItemToLastTextBlock(new TextBlockInternalLink
|
|
|
{
|
|
{
|
|
@@ -128,9 +140,15 @@ namespace QuestPDF.Fluent
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void ExternalLocation(string text, string url, TextStyle? style = null)
|
|
|
|
|
|
|
+ public void ExternalLocation(string? text, string url, TextStyle? style = null)
|
|
|
{
|
|
{
|
|
|
- style ??= DefaultStyle;
|
|
|
|
|
|
|
+ if (IsNullOrEmpty(text))
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ if (IsNullOrEmpty(url))
|
|
|
|
|
+ throw new ArgumentException(nameof(url));
|
|
|
|
|
+
|
|
|
|
|
+ style ??= TextStyle.Default;
|
|
|
|
|
|
|
|
AddItemToLastTextBlock(new TextBlockExternalLink
|
|
AddItemToLastTextBlock(new TextBlockExternalLink
|
|
|
{
|
|
{
|
|
@@ -156,6 +174,9 @@ namespace QuestPDF.Fluent
|
|
|
{
|
|
{
|
|
|
TextBlocks.ToList().ForEach(x => x.Alignment = Alignment);
|
|
TextBlocks.ToList().ForEach(x => x.Alignment = Alignment);
|
|
|
|
|
|
|
|
|
|
+ foreach (var textBlockSpan in TextBlocks.SelectMany(x => x.Children).Where(x => x is TextBlockSpan).Cast<TextBlockSpan>())
|
|
|
|
|
+ textBlockSpan.Style.ApplyParentStyle(DefaultStyle);
|
|
|
|
|
+
|
|
|
container.Stack(stack =>
|
|
container.Stack(stack =>
|
|
|
{
|
|
{
|
|
|
stack.Spacing(Spacing);
|
|
stack.Spacing(Spacing);
|
|
@@ -170,19 +191,18 @@ namespace QuestPDF.Fluent
|
|
|
{
|
|
{
|
|
|
public static void Text(this IContainer element, Action<TextDescriptor> content)
|
|
public static void Text(this IContainer element, Action<TextDescriptor> content)
|
|
|
{
|
|
{
|
|
|
- var textBlock = new TextBlock();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ var descriptor = new TextDescriptor();
|
|
|
|
|
+
|
|
|
if (element is Alignment alignment)
|
|
if (element is Alignment alignment)
|
|
|
- textBlock.Alignment = alignment.Horizontal;
|
|
|
|
|
|
|
+ descriptor.Alignment = alignment.Horizontal;
|
|
|
|
|
|
|
|
- var descriptor = new TextDescriptor();
|
|
|
|
|
content?.Invoke(descriptor);
|
|
content?.Invoke(descriptor);
|
|
|
descriptor.Compose(element);
|
|
descriptor.Compose(element);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static void Text(this IContainer element, object text, TextStyle? style = null)
|
|
|
|
|
|
|
+ public static void Text(this IContainer element, object? text, TextStyle? style = null)
|
|
|
{
|
|
{
|
|
|
- element.Text(x => x.Span(text.ToString(), style));
|
|
|
|
|
|
|
+ element.Text(x => x.Span(text?.ToString(), style));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|