Compare commits

..

33 Commits

Author SHA1 Message Date
MarcinZiabek 09e642295f Repeat content experiment 2022-10-28 23:22:11 +02:00
MarcinZiabek 65990ebf59 Added the WordWrappingStability test 2022-10-21 12:05:45 +02:00
MarcinZiabek 9d86e9efd3 DynamicImage: simplified implementation 2022-10-19 20:08:41 +02:00
Marcin Ziąbek 5cbacc7ea1 Update readme.md 2022-10-19 19:15:25 +02:00
MarcinZiabek 8214a8429d 2022.9.1 2022-10-15 23:03:25 +02:00
MarcinZiabek 389b8ce304 Inlined: improved behaviour predictability 2022-10-15 22:49:50 +02:00
MarcinZiabek e1f7cff4aa Fix: performance regression of the Table element #320 2022-10-11 23:19:13 +02:00
MarcinZiabek 6801425082 Fix: cells with RowSpan are not always displayed properly #320 2022-10-11 22:39:31 +02:00
MarcinZiabek ec31c9b063 Fix: CheckIfAllTextGlyphsAreAvailable and Fallback break hyperlinks 2022-10-11 10:31:31 +02:00
MarcinZiabek 6c8867e1b3 Added test: ReusingTheSameImageFileShouldBePossible 2022-10-06 23:20:17 +02:00
Marcin Ziąbek 20d86cbfde Update readme.md 2022-10-05 22:49:03 +02:00
MarcinZiabek 16a164e5b8 Example: achieve proportional height division 2022-10-05 01:15:36 +02:00
Marcin Ziąbek 261f087b46 Update readme.md 2022-10-04 12:30:36 +02:00
Marcin Ziąbek c876350b05 Merge pull request #354 from CollinAlpert/fix_broken_links
Fix links in README
2022-10-03 22:10:19 +02:00
Collin Alpert 58f3932241 Update readme.md 2022-10-03 15:28:48 +02:00
MarcinZiabek 9ce9ca85be Added GenerationBenchmark to test async performance 2022-09-22 22:37:15 +02:00
MarcinZiabek 553c8ab719 2022.9.1 2022-09-19 12:05:44 +02:00
Marcin Ziąbek e768e9b06d Update readme.md 2022-09-19 00:58:55 +02:00
Marcin Ziąbek fd913a777c Update readme.md 2022-09-19 00:57:32 +02:00
MarcinZiabek ed9e6daec5 2022.9.0 2022-09-19 00:45:14 +02:00
Marcin Ziąbek ee6249a658 Merge pull request #341 from QuestPDF/2022.9
2022.9 Release
2022-09-19 00:43:29 +02:00
MarcinZiabek b307304f46 Fixed typo 2022-09-18 20:15:41 +02:00
MarcinZiabek f028f82e11 Removed unsued file 2022-09-17 20:42:14 +02:00
MarcinZiabek 719a3385f6 Updated Previewer to 2022.9 2022-09-16 19:52:10 +02:00
MarcinZiabek 2adff11400 2022.9.0-alpha1 2022-09-16 19:46:32 +02:00
MarcinZiabek 34fed6d547 Settings.CheckIfAllTextGlyphsAreAvailable improvements 2022-09-16 16:08:02 +02:00
MarcinZiabek db2df75624 Text example: fixed visuals 2022-09-15 22:19:28 +02:00
MarcinZiabek 6b535752df Fixed formatting page numbers 2022-09-15 22:12:06 +02:00
MarcinZiabek 556f87ff25 Settings renaming 2022-09-15 21:20:25 +02:00
MarcinZiabek fbebbd85eb Fixed build, adapted fallback process for cached TextStyle 2022-09-15 15:09:30 +02:00
MarcinZiabek 4650c2a4ea Merge branch 'font-fallback' into 2022.9
# Conflicts:
#	QuestPDF/Elements/Text/Items/TextBlockSpan.cs
#	QuestPDF/Fluent/TextStyleExtensions.cs
#	QuestPDF/Infrastructure/TextStyle.cs
2022-09-14 23:28:50 +02:00
MarcinZiabek 5390fc3f1b Implemented font-fallback as required configuration 2022-09-10 23:27:27 +02:00
MarcinZiabek 0468dd5f02 Font-fallback implementation 2022-09-08 13:23:59 +02:00
51 changed files with 882 additions and 366 deletions
+2 -2
View File
@@ -65,9 +65,9 @@ namespace QuestPDF.Examples.Engine
return this; return this;
} }
public RenderingTest ShowResults(bool value = true) public RenderingTest ShowResults()
{ {
ShowResult = value; ShowResult = true;
return this; return this;
} }
+146
View File
@@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using QuestPDF.Elements;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
namespace QuestPDF.Examples
{
public class ProcessRunningTime
{
public TimeSpan FluentTime { get; set; }
public TimeSpan GenerationTime { get; set; }
public float Size { get; set; }
}
public class GenerationBenchmark
{
public const int TestSize = 4096;
[Test]
public void BenchmarkAsync()
{
RunTest(() => Enumerable
.Range(0, TestSize)
.AsParallel() // difference
.Select(GenerateAndCollect)
.ToList());
}
[Test]
public void BenchmarkSync()
{
RunTest(() => Enumerable
.Range(0, TestSize)
.Select(GenerateAndCollect)
.ToList());
}
public void RunTest(Func<IEnumerable<ProcessRunningTime>> handler)
{
var totalFluentTime = TimeSpan.Zero;
var totalGenerationTime = TimeSpan.Zero;
var stopWatch = new Stopwatch();
stopWatch.Start();
var results = handler();
stopWatch.Stop();
foreach (var result in results)
{
totalFluentTime += result.FluentTime;
totalGenerationTime += result.GenerationTime;
}
Console.WriteLine($"Fluent: {totalFluentTime:g}");
Console.WriteLine($"Generation: {totalGenerationTime:g}");
Console.WriteLine($"Total: {stopWatch.Elapsed:g}");
}
static ProcessRunningTime GenerateAndCollect(int attemptNumber)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var container = new Container();
container
.Padding(10)
.MinimalBox()
.Border(1)
.Column(column =>
{
column.Item().Text($"Attempts {attemptNumber}");
const int numberOfRows = 100;
const int numberOfColumns = 10;
for (var y = 0; y < numberOfRows; y++)
{
column.Item().Row(row =>
{
for (var x = 0; x < numberOfColumns; x++)
{
row.RelativeItem()
.Background(Colors.Red.Lighten5)
.Padding(3)
.Background(Colors.Red.Lighten4)
.Padding(3)
.Background(Colors.Red.Lighten3)
.Padding(3)
.Background(Colors.Red.Lighten2)
.Padding(3)
.Background(Colors.Red.Lighten1)
.Padding(3)
.Background(Colors.Red.Medium)
.Padding(3)
.Background(Colors.Red.Darken1)
.Padding(3)
.Background(Colors.Red.Darken2)
.Padding(3)
.Background(Colors.Red.Darken3)
.Padding(3)
.Background(Colors.Red.Darken4)
.Height(3);
}
});
}
});
var fluentTime = stopwatch.Elapsed;
stopwatch.Reset();
stopwatch.Start();
var size = Document
.Create(x => x.Page(page => page.Content().Element(container)))
.GeneratePdf()
.Length;
var generationTime = stopwatch.Elapsed;
return new ProcessRunningTime
{
FluentTime = fluentTime,
GenerationTime = generationTime,
Size = size
};
}
}
}
+55 -1
View File
@@ -1,4 +1,5 @@
using System.IO; using System;
using System.IO;
using NUnit.Framework; using NUnit.Framework;
using QuestPDF.Drawing.Exceptions; using QuestPDF.Drawing.Exceptions;
using QuestPDF.Examples.Engine; using QuestPDF.Examples.Engine;
@@ -34,6 +35,21 @@ namespace QuestPDF.Examples
}); });
} }
[Test]
public void DynamicImage()
{
RenderingTest
.Create()
.PageSize(450, 350)
.ProducePdf()
.ShowResults()
.Render(page =>
{
page.Padding(25)
.Image(Placeholders.Image);
});
}
[Test] [Test]
public void Exception() public void Exception()
{ {
@@ -47,5 +63,43 @@ namespace QuestPDF.Examples
.Render(page => page.Image("non_existent.png")); .Render(page => page.Image("non_existent.png"));
}); });
} }
[Test]
public void ReusingTheSameImageFileShouldBePossible()
{
var fileName = Path.GetTempFileName() + ".jpg";
try
{
var image = Placeholders.Image(300, 100);
using var file = File.Create(fileName);
file.Write(image);
file.Dispose();
RenderingTest
.Create()
.ProducePdf()
.PageSize(PageSizes.A4)
.ShowResults()
.Render(container =>
{
container
.Padding(20)
.Column(column =>
{
column.Spacing(20);
column.Item().Image(fileName);
column.Item().Image(fileName);
column.Item().Image(fileName);
});
});
}
finally
{
File.Delete(fileName);
}
}
} }
} }
@@ -0,0 +1,38 @@
using System.Linq;
using NUnit.Framework;
using QuestPDF.Examples.Engine;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
namespace QuestPDF.Examples
{
public class RepeatContentExamples
{
[Test]
public void ItemTypes()
{
RenderingTest
.Create()
.ProducePdf()
.PageSize(PageSizes.A4)
.ShowResults()
.Render(container =>
{
container
.Padding(25)
.Decoration(decoration =>
{
decoration.Before().Text("Test").FontSize(22);
decoration.Content().Column(column =>
{
column.Spacing(20);
foreach (var _ in Enumerable.Range(0, 10))
column.Item().Background(Colors.Grey.Medium).ExtendHorizontal().Height(80);
});
});
});
}
}
}
+36
View File
@@ -105,5 +105,41 @@ namespace QuestPDF.Examples
.Row(row => { }); .Row(row => { });
}); });
} }
[Test]
public void RowElementForRelativeHeightDivision()
{
RenderingTest
.Create()
.ProduceImages()
.ShowResults()
.MaxPages(100)
.PageSize(250, 400)
.Render(container =>
{
container
.Padding(25)
.AlignLeft()
.RotateRight()
.Row(row =>
{
row.Spacing(20);
row.RelativeItem(1).Element(Content);
row.RelativeItem(2).Element(Content);
row.RelativeItem(3).Element(Content);
void Content(IContainer container)
{
container
.RotateLeft()
.Border(1)
.Background(Placeholders.BackgroundColor())
.Padding(5)
.Text(Placeholders.Label());
}
});
});
}
} }
} }
+27 -73
View File
@@ -1,13 +1,8 @@
using System; using System.Linq;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using QuestPDF.Drawing;
using QuestPDF.Elements;
using QuestPDF.Examples.Engine; using QuestPDF.Examples.Engine;
using QuestPDF.Fluent; using QuestPDF.Fluent;
using QuestPDF.Helpers; using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
namespace QuestPDF.Examples namespace QuestPDF.Examples
{ {
@@ -16,77 +11,36 @@ namespace QuestPDF.Examples
[Test] [Test]
public void Benchmark() public void Benchmark()
{ {
GenerateAndCollect(); RenderingTest
.Create()
var stopwatch = new Stopwatch(); .ProducePdf()
stopwatch.Start(); .PageSize(PageSizes.A4)
.ShowResults()
foreach (var _ in Enumerable.Range(0, 10000)) .MaxPages(10_000)
{ .EnableCaching(true)
GenerateAndCollect(); .EnableDebugging(false)
} .Render(container =>
{
stopwatch.Stop(); container
.Padding(10)
Console.WriteLine($"Execution time: {stopwatch.Elapsed:g}"); .MinimalBox()
.Border(1)
void GenerateAndCollect() .Table(table =>
{
var container = new Container();
container
.Padding(10)
.MinimalBox()
.Border(1)
.Column(column =>
{
const int numberOfRows = 100;
const int numberOfColumns = 10;
for (var y = 0; y < numberOfRows; y++)
{ {
column.Item().Row(row => const int numberOfRows = 100_000;
const int numberOfColumns = 10;
table.ColumnsDefinition(columns =>
{ {
for (var x = 0; x < numberOfColumns; x++) foreach (var _ in Enumerable.Range(0, numberOfColumns))
{ columns.RelativeColumn();
row.RelativeItem()
.Background(Colors.Red.Lighten5)
.Padding(3)
.Background(Colors.Red.Lighten4)
.Padding(3)
.Background(Colors.Red.Lighten3)
.Padding(3)
.Background(Colors.Red.Lighten2)
.Padding(3)
.Background(Colors.Red.Lighten1)
.Padding(3)
.Background(Colors.Red.Medium)
.Padding(3)
.Background(Colors.Red.Darken1)
.Padding(3)
.Background(Colors.Red.Darken2)
.Padding(3)
.Background(Colors.Red.Darken3)
.Padding(3)
.Background(Colors.Red.Darken4)
.Height(3);
}
}); });
}
});
ElementCacheManager.Collect(container); foreach (var row in Enumerable.Range(0, numberOfRows))
} foreach (var column in Enumerable.Range(0, numberOfColumns))
table.Cell().Background(Placeholders.BackgroundColor()).Padding(5).Text($"{row}_{column}");
});
});
} }
} }
} }
+1 -1
View File
@@ -111,7 +111,7 @@ namespace QuestPDF.Examples
{ {
page.Margin(50); page.Margin(50);
page.Content().Column(column => page.Content().PaddingVertical(10).Column(column =>
{ {
column.Item().Element(Title); column.Item().Element(Title);
column.Item().PageBreak(); column.Item().PageBreak();
+71
View File
@@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using NUnit.Framework; using NUnit.Framework;
using QuestPDF.Elements.Text;
using QuestPDF.Examples.Engine; using QuestPDF.Examples.Engine;
using QuestPDF.Fluent; using QuestPDF.Fluent;
using QuestPDF.Helpers; using QuestPDF.Helpers;
@@ -618,5 +619,75 @@ namespace QuestPDF.Examples
.FontSize(20); .FontSize(20);
}); });
} }
[Test]
public void FontFallback()
{
RenderingTest
.Create()
.ProduceImages()
.ShowResults()
.RenderDocument(container =>
{
container.Page(page =>
{
page.Margin(50);
page.PageColor(Colors.White);
page.DefaultTextStyle(x => x
.Fallback(y => y.FontFamily("Segoe UI Emoji")
.Fallback(y => y.FontFamily("Microsoft YaHei"))));
page.Size(PageSizes.A4);
page.Content().Text(t =>
{
t.Line("This is normal text.");
t.EmptyLine();
t.Line("Following line should use font fallback:");
t.Line("中文文本");
t.EmptyLine();
t.Line("The following line contains a mix of known and unknown characters.");
t.Line("Mixed line: This 中文 is 文文 a mixed 本 本 line 本 中文文本!");
t.EmptyLine();
t.Line("Emojis work out of the box because of font fallback: 😊😅🥳👍❤😍👌");
});
});
});
}
[Test]
public void WordWrappingStability()
{
// instruction: check if any characters repeat when performing the word-wrapping algorithm
RenderingTest
.Create()
.PageSize(PageSizes.A4)
.ProducePdf()
.ShowResults()
.Render(container =>
{
var text = "Lorem ipsum dolor sit amet consectetuer";
container
.Padding(20)
.Column(column =>
{
column.Spacing(10);
foreach (var width in Enumerable.Range(25, 200))
{
column
.Item()
.MaxWidth(width)
.Background(Colors.Grey.Lighten3)
.Text(text);
}
});
});
}
} }
} }
+1 -1
View File
@@ -4,7 +4,7 @@
<Authors>MarcinZiabek</Authors> <Authors>MarcinZiabek</Authors>
<Company>CodeFlint</Company> <Company>CodeFlint</Company>
<PackageId>QuestPDF.Previewer</PackageId> <PackageId>QuestPDF.Previewer</PackageId>
<Version>2022.8.0</Version> <Version>2022.9.1</Version>
<PackAsTool>true</PackAsTool> <PackAsTool>true</PackAsTool>
<ToolCommandName>questpdf-previewer</ToolCommandName> <ToolCommandName>questpdf-previewer</ToolCommandName>
<PackageDescription>QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API.</PackageDescription> <PackageDescription>QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API.</PackageDescription>
+48 -3
View File
@@ -65,6 +65,7 @@ namespace QuestPDF.Drawing
document.Compose(container); document.Compose(container);
var content = container.Compose(); var content = container.Compose();
ApplyDefaultTextStyle(content, TextStyle.LibraryDefault); ApplyDefaultTextStyle(content, TextStyle.LibraryDefault);
ApplyContentRepeatState(content, false);
var debuggingState = Settings.EnableDebugging ? ApplyDebugging(content) : null; var debuggingState = Settings.EnableDebugging ? ApplyDebugging(content) : null;
@@ -74,8 +75,6 @@ namespace QuestPDF.Drawing
var pageContext = new PageContext(); var pageContext = new PageContext();
RenderPass(pageContext, new FreeCanvas(), content, debuggingState); RenderPass(pageContext, new FreeCanvas(), content, debuggingState);
RenderPass(pageContext, canvas, content, debuggingState); RenderPass(pageContext, canvas, content, debuggingState);
ElementCacheManager.Collect(content);
} }
internal static void RenderPass<TCanvas>(PageContext pageContext, TCanvas canvas, Container content, DebuggingState? debuggingState) internal static void RenderPass<TCanvas>(PageContext pageContext, TCanvas canvas, Container content, DebuggingState? debuggingState)
@@ -84,6 +83,8 @@ namespace QuestPDF.Drawing
content.VisitChildren(x => x?.Initialize(pageContext, canvas)); content.VisitChildren(x => x?.Initialize(pageContext, canvas));
content.VisitChildren(x => (x as IStateResettable)?.ResetState()); content.VisitChildren(x => (x as IStateResettable)?.ResetState());
ResetIsRenderedState(content);
canvas.BeginDocument(); canvas.BeginDocument();
var currentPage = 1; var currentPage = 1;
@@ -163,6 +164,50 @@ namespace QuestPDF.Drawing
return debuggingState; return debuggingState;
} }
private static void ApplyContentRepeatState(Element? content, bool repeatContent)
{
if (content == null)
return;
if (content is IVisual visual)
visual.RepeatContent = repeatContent;
if (content is TextBlock textBlock)
{
foreach (var textBlockItem in textBlock.Items)
{
if (textBlockItem is TextBlockElement textElement)
{
ApplyContentRepeatState(textElement.Element, true);
}
}
return;
}
// TODO: apply RepeatState in dynamic content
//if (content is DynamicHost dynamicHost)
// dynamicHost.TextStyle = dynamicHost.TextStyle.ApplyGlobalStyle(documentDefaultTextStyle);
if (content is RepeatContentSetter repeatContentSetter)
repeatContent = repeatContentSetter.RepeatContent;
foreach (var child in content.GetChildren())
ApplyContentRepeatState(child, repeatContent);
}
private static void ResetIsRenderedState(Element? content)
{
if (content == null)
return;
if (content is IVisual visual)
visual.IsRendered = false;
foreach (var child in content.GetChildren())
ResetIsRenderedState(child);
}
internal static void ApplyDefaultTextStyle(this Element? content, TextStyle documentDefaultTextStyle) internal static void ApplyDefaultTextStyle(this Element? content, TextStyle documentDefaultTextStyle)
{ {
if (content == null) if (content == null)
@@ -174,7 +219,7 @@ namespace QuestPDF.Drawing
{ {
if (textBlockItem is TextBlockSpan textSpan) if (textBlockItem is TextBlockSpan textSpan)
{ {
textSpan.Style = textSpan.Style.ApplyGlobalStyle(TextStyle.LibraryDefault); textSpan.Style = textSpan.Style.ApplyGlobalStyle(documentDefaultTextStyle);
} }
else if (textBlockItem is TextBlockElement textElement) else if (textBlockItem is TextBlockElement textElement)
{ {
-76
View File
@@ -1,76 +0,0 @@
using System;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using QuestPDF.Infrastructure;
namespace QuestPDF.Drawing
{
internal class CircularBuffer
{
private const int BufferSize = 11_000;
private object[] Buffer = new object[BufferSize];
private int WriteIndex { get; set; } = 0;
private int ReadIndex { get; set; } = 0;
public T Get<T>() where T : class, new()
{
lock (this)
{
if (ReadIndex == WriteIndex)
return new T();
var index = ReadIndex;
ReadIndex = (ReadIndex + 1) % BufferSize;
var result = Buffer[index] as T;
Buffer[index] = null;
return result;
}
}
public void Store(object value)
{
lock (this)
{
Buffer[WriteIndex] = value;
WriteIndex = (WriteIndex + 1) % BufferSize;
}
}
}
// performance analysis:
// without: 115s
// ConcurrentQueue: 28s
// ConcurrentBag: 38s
// CircularBuffer: 30s
internal static class ElementCacheManager
{
private static ConcurrentDictionary<Type, ConcurrentQueue<object>> Cache { get; } = new();
public static T Get<T>() where T : class, new()
{
var buffer = Cache.GetOrAdd(typeof(T), _=> new ConcurrentQueue<object>());
return buffer.TryDequeue(out var result) ? result as T : new T();
}
public static void Store<T>(T element)
{
var buffer = Cache.GetOrAdd(element.GetType(), _=> new ConcurrentQueue<object>());
buffer.Enqueue(element);
}
public static void Collect(Element element)
{
foreach (var child in element.GetChildren())
Collect(child);
if (element is ICollectable collectable)
{
collectable.Collect();
Store(element);
}
}
}
}
@@ -4,6 +4,11 @@ namespace QuestPDF.Drawing.Exceptions
{ {
public class DocumentDrawingException : Exception public class DocumentDrawingException : Exception
{ {
internal DocumentDrawingException(string message) : base(message)
{
}
internal DocumentDrawingException(string message, Exception inner) : base(message, inner) internal DocumentDrawingException(string message, Exception inner) : base(message, inner)
{ {
-8
View File
@@ -1,8 +0,0 @@
namespace QuestPDF.Drawing
{
internal struct TextMeasurement
{
public int LineIndex { get; set; }
public float FragmentWidth { get; set; }
}
}
-17
View File
@@ -56,9 +56,6 @@ namespace QuestPDF.Drawing
yOffset += glyphPositions[i].YAdvance * scaleY; yOffset += glyphPositions[i].YAdvance * scaleY;
} }
if (Settings.CheckIfAllTextGlyphsAreAvailableInSpecifiedFont)
CheckIfAllGlyphsAreAvailable(glyphs, text);
return new TextShapingResult(glyphs); return new TextShapingResult(glyphs);
} }
@@ -78,20 +75,6 @@ namespace QuestPDF.Drawing
else else
throw new NotSupportedException("TextEncoding of type GlyphId is not supported."); throw new NotSupportedException("TextEncoding of type GlyphId is not supported.");
} }
void CheckIfAllGlyphsAreAvailable(ShapedGlyph[] glyphs, string originalText)
{
var containsMissingGlyphs = glyphs.Any(x => x.Codepoint == default);
if (!containsMissingGlyphs)
return;
throw new ArgumentException(
$"Detected missing font glyphs while rendering text. " +
$"This means that the document contains text with characters not present in the assigned font. " +
$"Such characters are replaced by placeholders, usually visible as empty rectangles. " +
$"Font family used: {TextStyle.FontFamily}. Issue detected in text: '{originalText}'");
}
} }
internal struct ShapedGlyph internal struct ShapedGlyph
-10
View File
@@ -41,15 +41,5 @@ namespace QuestPDF.Elements
{ {
return $"Border: Top({Top}) Right({Right}) Bottom({Bottom}) Left({Left}) Color({Color})"; return $"Border: Top({Top}) Right({Right}) Bottom({Bottom}) Left({Left}) Color({Color})";
} }
public override void Collect()
{
base.Collect();
Left = 0;
Right = 0;
Bottom = 0;
Top = 0;
}
} }
} }
+13 -4
View File
@@ -7,19 +7,28 @@ namespace QuestPDF.Elements
{ {
public delegate void DrawOnCanvas(SKCanvas canvas, Size availableSpace); public delegate void DrawOnCanvas(SKCanvas canvas, Size availableSpace);
internal class Canvas : Element, ICacheable internal class Canvas : Element, IVisual, ICacheable
{ {
public bool IsRendered { get; set; }
public bool RepeatContent { get; set; }
public DrawOnCanvas Handler { get; set; } public DrawOnCanvas Handler { get; set; }
internal override SpacePlan Measure(Size availableSpace) internal override SpacePlan Measure(Size availableSpace)
{ {
return availableSpace.IsNegative() if (availableSpace.IsNegative())
? SpacePlan.Wrap() return SpacePlan.Wrap();
: SpacePlan.FullRender(availableSpace);
if (IsRendered && !RepeatContent)
return SpacePlan.FullRender(Size.Zero);
return SpacePlan.FullRender(availableSpace);
} }
internal override void Draw(Size availableSpace) internal override void Draw(Size availableSpace)
{ {
IsRendered = true;
var skiaCanvas = (Canvas as Drawing.SkiaCanvasBase)?.Canvas; var skiaCanvas = (Canvas as Drawing.SkiaCanvasBase)?.Canvas;
if (Handler == null || skiaCanvas == null) if (Handler == null || skiaCanvas == null)
+1 -6
View File
@@ -19,7 +19,7 @@ namespace QuestPDF.Elements
public Position Offset { get; set; } public Position Offset { get; set; }
} }
internal class Column : Element, ICacheable, IStateResettable, ICollectable internal class Column : Element, ICacheable, IStateResettable
{ {
internal List<ColumnItem> Items { get; } = new(); internal List<ColumnItem> Items { get; } = new();
internal float Spacing { get; set; } internal float Spacing { get; set; }
@@ -124,10 +124,5 @@ namespace QuestPDF.Elements
return commands; return commands;
} }
public void Collect()
{
Items.Clear();
}
} }
} }
+1 -1
View File
@@ -4,7 +4,7 @@ namespace QuestPDF.Elements
{ {
internal class Container : ContainerElement internal class Container : ContainerElement
{ {
public Container() internal Container()
{ {
} }
+18 -11
View File
@@ -6,31 +6,38 @@ using SkiaSharp;
namespace QuestPDF.Elements namespace QuestPDF.Elements
{ {
internal class DynamicImage : Element internal class DynamicImage : Element, IVisual
{ {
public bool IsRendered { get; set; }
public bool RepeatContent { get; set; }
public Func<Size, byte[]>? Source { get; set; } public Func<Size, byte[]>? Source { get; set; }
internal override SpacePlan Measure(Size availableSpace) internal override SpacePlan Measure(Size availableSpace)
{ {
return availableSpace.IsNegative() if (availableSpace.IsNegative())
? SpacePlan.Wrap() return SpacePlan.Wrap();
: SpacePlan.FullRender(availableSpace);
if (IsRendered && !RepeatContent)
return SpacePlan.FullRender(Size.Zero);
return SpacePlan.FullRender(availableSpace);
} }
internal override void Draw(Size availableSpace) internal override void Draw(Size availableSpace)
{ {
IsRendered = true;
if (availableSpace.Width < Size.Epsilon || availableSpace.Height < Size.Epsilon)
return;
var imageData = Source?.Invoke(availableSpace); var imageData = Source?.Invoke(availableSpace);
if (imageData == null) if (imageData == null)
return; return;
var imageElement = new Image using var image = SKImage.FromEncodedData(imageData);
{ Canvas.DrawImage(image, Position.Zero, availableSpace);
InternalImage = SKImage.FromEncodedData(imageData)
};
imageElement.Initialize(PageContext, Canvas);
imageElement.Draw(availableSpace);
} }
} }
} }
+12 -4
View File
@@ -5,8 +5,11 @@ using SkiaSharp;
namespace QuestPDF.Elements namespace QuestPDF.Elements
{ {
internal class Image : Element, ICacheable internal class Image : Element, IVisual, ICacheable
{ {
public bool IsRendered { get; set; }
public bool RepeatContent { get; set; }
public SKImage? InternalImage { get; set; } public SKImage? InternalImage { get; set; }
~Image() ~Image()
@@ -16,9 +19,13 @@ namespace QuestPDF.Elements
internal override SpacePlan Measure(Size availableSpace) internal override SpacePlan Measure(Size availableSpace)
{ {
return availableSpace.IsNegative() if (availableSpace.IsNegative())
? SpacePlan.Wrap() return SpacePlan.Wrap();
: SpacePlan.FullRender(availableSpace);
if (IsRendered && !RepeatContent)
return SpacePlan.FullRender(Size.Zero);
return SpacePlan.FullRender(availableSpace);
} }
internal override void Draw(Size availableSpace) internal override void Draw(Size availableSpace)
@@ -26,6 +33,7 @@ namespace QuestPDF.Elements
if (InternalImage == null) if (InternalImage == null)
return; return;
IsRendered = true;
Canvas.DrawImage(InternalImage, Position.Zero, availableSpace); Canvas.DrawImage(InternalImage, Position.Zero, availableSpace);
} }
} }
+1 -1
View File
@@ -212,7 +212,7 @@ namespace QuestPDF.Elements
break; break;
var element = queue.Peek(); var element = queue.Peek();
var size = element.Measure(Size.Max); var size = element.Measure(new Size(availableSize.Width, Size.Max.Height));
if (size.Type == SpacePlanType.Wrap) if (size.Type == SpacePlanType.Wrap)
break; break;
+14 -6
View File
@@ -15,34 +15,42 @@ namespace QuestPDF.Elements
Horizontal Horizontal
} }
internal class Line : Element, ILine, ICacheable internal class Line : Element, ILine, IVisual, ICacheable
{ {
public bool IsRendered { get; set; }
public bool RepeatContent { get; set; }
public LineType Type { get; set; } = LineType.Vertical; public LineType Type { get; set; } = LineType.Vertical;
public string Color { get; set; } = Colors.Black; public string Color { get; set; } = Colors.Black;
public float Size { get; set; } = 1; public float Thickness { get; set; } = 1;
internal override SpacePlan Measure(Size availableSpace) internal override SpacePlan Measure(Size availableSpace)
{ {
if (availableSpace.IsNegative()) if (availableSpace.IsNegative())
return SpacePlan.Wrap(); return SpacePlan.Wrap();
if (IsRendered && !RepeatContent)
return SpacePlan.FullRender(Size.Zero);
return Type switch return Type switch
{ {
LineType.Vertical when availableSpace.Width + Infrastructure.Size.Epsilon >= Size => SpacePlan.FullRender(Size, 0), LineType.Vertical when availableSpace.Width + Infrastructure.Size.Epsilon >= Thickness => SpacePlan.FullRender(Thickness, 0),
LineType.Horizontal when availableSpace.Height + Infrastructure.Size.Epsilon >= Size => SpacePlan.FullRender(0, Size), LineType.Horizontal when availableSpace.Height + Infrastructure.Size.Epsilon >= Thickness => SpacePlan.FullRender(0, Thickness),
_ => SpacePlan.Wrap() _ => SpacePlan.Wrap()
}; };
} }
internal override void Draw(Size availableSpace) internal override void Draw(Size availableSpace)
{ {
IsRendered = true;
if (Type == LineType.Vertical) if (Type == LineType.Vertical)
{ {
Canvas.DrawRectangle(new Position(-Size/2, 0), new Size(Size, availableSpace.Height), Color); Canvas.DrawRectangle(new Position(-Thickness/2, 0), new Size(Thickness, availableSpace.Height), Color);
} }
else if (Type == LineType.Horizontal) else if (Type == LineType.Horizontal)
{ {
Canvas.DrawRectangle(new Position(0, -Size/2), new Size(availableSpace.Width, Size), Color); Canvas.DrawRectangle(new Position(0, -Thickness/2), new Size(availableSpace.Width, Thickness), Color);
} }
} }
} }
+1 -11
View File
@@ -4,7 +4,7 @@ using QuestPDF.Infrastructure;
namespace QuestPDF.Elements namespace QuestPDF.Elements
{ {
internal class Padding : ContainerElement, ICacheable, ICollectable internal class Padding : ContainerElement, ICacheable
{ {
public float Top { get; set; } public float Top { get; set; }
public float Right { get; set; } public float Right { get; set; }
@@ -62,15 +62,5 @@ namespace QuestPDF.Elements
{ {
return $"Padding: Top({Top}) Right({Right}) Bottom({Bottom}) Left({Left})"; return $"Padding: Top({Top}) Right({Right}) Bottom({Bottom}) Left({Left})";
} }
public override void Collect()
{
base.Collect();
Left = 0;
Right = 0;
Bottom = 0;
Top = 0;
}
} }
} }
+9
View File
@@ -0,0 +1,9 @@
using QuestPDF.Infrastructure;
namespace QuestPDF.Elements
{
internal class RepeatContentSetter : ContainerElement
{
public bool RepeatContent { get; set; }
}
}
+1 -6
View File
@@ -31,7 +31,7 @@ namespace QuestPDF.Elements
public Position Offset { get; set; } public Position Offset { get; set; }
} }
internal class Row : Element, ICacheable, IStateResettable, ICollectable internal class Row : Element, ICacheable, IStateResettable
{ {
internal List<RowItem> Items { get; } = new(); internal List<RowItem> Items { get; } = new();
internal float Spacing { get; set; } internal float Spacing { get; set; }
@@ -156,10 +156,5 @@ namespace QuestPDF.Elements
return renderingCommands; return renderingCommands;
} }
public void Collect()
{
Items.Clear();
}
} }
} }
+4 -1
View File
@@ -24,6 +24,7 @@ namespace QuestPDF.Elements.Table
// inner table: list of all cells that ends at the corresponding row // inner table: list of all cells that ends at the corresponding row
private TableCell[][] CellsCache { get; set; } private TableCell[][] CellsCache { get; set; }
private int MaxRow { get; set; } private int MaxRow { get; set; }
private int MaxRowSpan { get; set; }
internal override void Initialize(IPageContext pageContext, ICanvas canvas) internal override void Initialize(IPageContext pageContext, ICanvas canvas)
{ {
@@ -56,6 +57,7 @@ namespace QuestPDF.Elements.Table
if (Cells.Count == 0) if (Cells.Count == 0)
{ {
MaxRow = 0; MaxRow = 0;
MaxRowSpan = 1;
CellsCache = Array.Empty<TableCell[]>(); CellsCache = Array.Empty<TableCell[]>();
return; return;
@@ -66,6 +68,7 @@ namespace QuestPDF.Elements.Table
.ToDictionary(x => x.Key, x => x.OrderBy(x => x.Column).ToArray()); .ToDictionary(x => x.Key, x => x.OrderBy(x => x.Column).ToArray());
MaxRow = groups.Max(x => x.Key); MaxRow = groups.Max(x => x.Key);
MaxRowSpan = Cells.Max(x => x.RowSpan);
CellsCache = Enumerable CellsCache = Enumerable
.Range(0, MaxRow + 1) .Range(0, MaxRow + 1)
@@ -201,7 +204,7 @@ namespace QuestPDF.Elements.Table
} }
// cell visibility optimizations // cell visibility optimizations
if (cell.Row > maxRenderingRow) if (cell.Row > maxRenderingRow + MaxRowSpan)
break; break;
// calculate cell position / size // calculate cell position / size
+160
View File
@@ -0,0 +1,160 @@
using System;
using System.Collections.Generic;
using System.Linq;
using QuestPDF.Drawing;
using QuestPDF.Drawing.Exceptions;
using QuestPDF.Elements.Text.Items;
using QuestPDF.Fluent;
using QuestPDF.Infrastructure;
using SkiaSharp;
namespace QuestPDF.Elements.Text
{
internal static class FontFallback
{
public struct TextRun
{
public string Content { get; set; }
public TextStyle Style { get; set; }
}
public class FallbackOption
{
public TextStyle Style { get; set; }
public SKFont Font { get; set; }
public SKTypeface Typeface { get; set; }
}
private static SKFontManager FontManager => SKFontManager.Default;
public static IEnumerable<TextRun> SplitWithFontFallback(this string text, TextStyle textStyle)
{
var fallbackOptions = GetFallbackOptions(textStyle).ToArray();
var spanStartIndex = 0;
var spanFallbackOption = fallbackOptions[0];
for (var i = 0; i < text.Length; i += char.IsSurrogatePair(text, i) ? 2 : 1)
{
var codepoint = char.ConvertToUtf32(text, i);
var newFallbackOption = MatchFallbackOption(fallbackOptions, codepoint);
if (newFallbackOption == spanFallbackOption)
continue;
yield return new TextRun
{
Content = text.Substring(spanStartIndex, i - spanStartIndex),
Style = spanFallbackOption.Style
};
spanStartIndex = i;
spanFallbackOption = newFallbackOption;
}
if (spanStartIndex > text.Length)
yield break;
yield return new TextRun
{
Content = text.Substring(spanStartIndex, text.Length - spanStartIndex),
Style = spanFallbackOption.Style
};
static IEnumerable<FallbackOption> GetFallbackOptions(TextStyle? textStyle)
{
while (textStyle != null)
{
var font = textStyle.ToFont();
yield return new FallbackOption
{
Style = textStyle,
Font = font,
Typeface = font.Typeface
};
textStyle = textStyle.Fallback;
}
}
static FallbackOption MatchFallbackOption(ICollection<FallbackOption> fallbackOptions, int codepoint)
{
foreach (var fallbackOption in fallbackOptions)
{
if (fallbackOption.Font.ContainsGlyph(codepoint))
return fallbackOption;
}
throw CreateNotMatchingFontException(codepoint);
}
static Exception CreateNotMatchingFontException(int codepoint)
{
var character = char.ConvertFromUtf32(codepoint);
var unicode = $"U-{codepoint:X4}";
var proposedFonts = FindFontsContainingGlyph(codepoint);
var proposedFontsFormatted = proposedFonts.Any() ? string.Join(", ", proposedFonts) : "no fonts available";
return new DocumentDrawingException(
$"Could not find an appropriate font fallback for glyph: {unicode} '{character}'. " +
$"Font families available on current environment that contain this glyph: {proposedFontsFormatted}. " +
$"Possible solutions: " +
$"1) Use one of the listed fonts as the primary font in your document. " +
$"2) Configure the fallback TextStyle using the 'TextStyle.Fallback' method with one of the listed fonts. ");
}
static IEnumerable<string> FindFontsContainingGlyph(int codepoint)
{
var fontManager = SKFontManager.Default;
return fontManager
.GetFontFamilies()
.Select(fontManager.MatchFamily)
.Where(x => x.ContainsGlyph(codepoint))
.Select(x => x.FamilyName);
}
}
public static IEnumerable<ITextBlockItem> ApplyFontFallback(this ICollection<ITextBlockItem> textBlockItems)
{
foreach (var textBlockItem in textBlockItems)
{
if (textBlockItem is TextBlockPageNumber or TextBlockElement)
{
yield return textBlockItem;
}
else if (textBlockItem is TextBlockSpan textBlockSpan)
{
if (!Settings.CheckIfAllTextGlyphsAreAvailable && textBlockSpan.Style.Fallback == null)
{
yield return textBlockSpan;
continue;
}
var textRuns = textBlockSpan.Text.SplitWithFontFallback(textBlockSpan.Style);
foreach (var textRun in textRuns)
{
var newElement = textBlockSpan switch
{
TextBlockHyperlink hyperlink => new TextBlockHyperlink { Url = hyperlink.Url },
TextBlockSectionLink sectionLink => new TextBlockSectionLink { SectionName = sectionLink.SectionName },
TextBlockSpan => new TextBlockSpan()
};
newElement.Text = textRun.Content;
newElement.Style = textRun.Style;
yield return newElement;
}
}
else
{
throw new NotSupportedException();
}
}
}
}
}
@@ -15,7 +15,7 @@ namespace QuestPDF.Elements.Text.Items
{ {
public string Text { get; set; } public string Text { get; set; }
public TextStyle Style { get; set; } = TextStyle.Default; public TextStyle Style { get; set; } = TextStyle.Default;
public TextShapingResult? TextShapingResult { get; set; } private TextShapingResult? TextShapingResult { get; set; }
private Dictionary<(int startIndex, float availableWidth), TextMeasurementResult?> MeasureCache = new (); private Dictionary<(int startIndex, float availableWidth), TextMeasurementResult?> MeasureCache = new ();
protected virtual bool EnableTextCache => true; protected virtual bool EnableTextCache => true;
+28 -5
View File
@@ -4,12 +4,16 @@ using System.Linq;
using QuestPDF.Drawing; using QuestPDF.Drawing;
using QuestPDF.Elements.Text.Calculation; using QuestPDF.Elements.Text.Calculation;
using QuestPDF.Elements.Text.Items; using QuestPDF.Elements.Text.Items;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure; using QuestPDF.Infrastructure;
namespace QuestPDF.Elements.Text namespace QuestPDF.Elements.Text
{ {
internal class TextBlock : Element, IStateResettable, ICollectable internal class TextBlock : Element, IVisual, IStateResettable
{ {
public bool IsRendered { get; set; }
public bool RepeatContent { get; set; }
public HorizontalAlignment Alignment { get; set; } = HorizontalAlignment.Left; public HorizontalAlignment Alignment { get; set; } = HorizontalAlignment.Left;
public List<ITextBlockItem> Items { get; set; } = new List<ITextBlockItem>(); public List<ITextBlockItem> Items { get; set; } = new List<ITextBlockItem>();
@@ -18,8 +22,11 @@ namespace QuestPDF.Elements.Text
private Queue<ITextBlockItem> RenderingQueue { get; set; } private Queue<ITextBlockItem> RenderingQueue { get; set; }
private int CurrentElementIndex { get; set; } private int CurrentElementIndex { get; set; }
private bool FontFallbackApplied { get; set; } = false;
public void ResetState() public void ResetState()
{ {
ApplyFontFallback();
InitializeQueue(); InitializeQueue();
CurrentElementIndex = 0; CurrentElementIndex = 0;
@@ -37,15 +44,25 @@ namespace QuestPDF.Elements.Text
foreach (var item in Items) foreach (var item in Items)
RenderingQueue.Enqueue(item); RenderingQueue.Enqueue(item);
} }
}
public void Collect() void ApplyFontFallback()
{ {
Items.Clear(); if (FontFallbackApplied)
return;
Items = Items.ApplyFontFallback().ToList();
FontFallbackApplied = true;
}
} }
internal override SpacePlan Measure(Size availableSpace) internal override SpacePlan Measure(Size availableSpace)
{ {
if (availableSpace.IsNegative())
return SpacePlan.Wrap();
if (IsRendered && !RepeatContent)
return SpacePlan.FullRender(Size.Zero);
if (!RenderingQueue.Any()) if (!RenderingQueue.Any())
return SpacePlan.FullRender(Size.Zero); return SpacePlan.FullRender(Size.Zero);
@@ -73,6 +90,9 @@ namespace QuestPDF.Elements.Text
internal override void Draw(Size availableSpace) internal override void Draw(Size availableSpace)
{ {
if (IsRendered && !RepeatContent)
return;
var lines = DivideTextItemsIntoLines(availableSpace.Width, availableSpace.Height).ToList(); var lines = DivideTextItemsIntoLines(availableSpace.Width, availableSpace.Height).ToList();
if (!lines.Any()) if (!lines.Any())
@@ -131,7 +151,10 @@ namespace QuestPDF.Elements.Text
CurrentElementIndex = lastElementMeasurement.IsLast ? 0 : lastElementMeasurement.NextIndex; CurrentElementIndex = lastElementMeasurement.IsLast ? 0 : lastElementMeasurement.NextIndex;
if (!RenderingQueue.Any()) if (!RenderingQueue.Any())
{
ResetState(); ResetState();
IsRendered = true;
}
float GetAlignmentOffset(float lineWidth) float GetAlignmentOffset(float lineWidth)
{ {
+1 -2
View File
@@ -1,5 +1,4 @@
using System; using System;
using QuestPDF.Drawing;
using QuestPDF.Elements; using QuestPDF.Elements;
using QuestPDF.Infrastructure; using QuestPDF.Infrastructure;
@@ -9,7 +8,7 @@ namespace QuestPDF.Fluent
{ {
private static IContainer Border(this IContainer element, Action<Border> handler) private static IContainer Border(this IContainer element, Action<Border> handler)
{ {
var border = element as Border ?? ElementCacheManager.Get<Border>(); var border = element as Border ?? new Border();
handler(border); handler(border);
return element.Element(border); return element.Element(border);
+10 -8
View File
@@ -1,14 +1,12 @@
using System; using System;
using QuestPDF.Drawing;
using QuestPDF.Elements; using QuestPDF.Elements;
using QuestPDF.Infrastructure; using QuestPDF.Infrastructure;
using Container = System.ComponentModel.Container;
namespace QuestPDF.Fluent namespace QuestPDF.Fluent
{ {
public class ColumnDescriptor public class ColumnDescriptor
{ {
internal Column Column { get; set; } internal Column Column { get; } = new();
public void Spacing(float value, Unit unit = Unit.Point) public void Spacing(float value, Unit unit = Unit.Point)
{ {
@@ -17,9 +15,14 @@ namespace QuestPDF.Fluent
public IContainer Item() public IContainer Item()
{ {
var columnItem = ElementCacheManager.Get<ColumnItem>(); var container = new Container();
Column.Items.Add(columnItem);
return columnItem; Column.Items.Add(new ColumnItem
{
Child = container
});
return container;
} }
} }
@@ -33,8 +36,7 @@ namespace QuestPDF.Fluent
public static void Column(this IContainer element, Action<ColumnDescriptor> handler) public static void Column(this IContainer element, Action<ColumnDescriptor> handler)
{ {
var descriptor = ElementCacheManager.Get<ColumnDescriptor>(); var descriptor = new ColumnDescriptor();
descriptor.Column = ElementCacheManager.Get<Column>();
handler(descriptor); handler(descriptor);
element.Element(descriptor.Column); element.Element(descriptor.Column);
} }
+4 -8
View File
@@ -12,7 +12,7 @@ namespace QuestPDF.Fluent
{ {
var container = new Container(); var container = new Container();
Decoration.Before = container; Decoration.Before = container;
return container; return container.RepeatContentWhenPaging();
} }
public void Before(Action<IContainer> handler) public void Before(Action<IContainer> handler)
@@ -36,7 +36,7 @@ namespace QuestPDF.Fluent
{ {
var container = new Container(); var container = new Container();
Decoration.After = container; Decoration.After = container;
return container; return container.RepeatContentWhenPaging();
} }
public void After(Action<IContainer> handler) public void After(Action<IContainer> handler)
@@ -49,9 +49,7 @@ namespace QuestPDF.Fluent
[Obsolete("This element has been renamed since version 2022.2. Please use the 'Before' method.")] [Obsolete("This element has been renamed since version 2022.2. Please use the 'Before' method.")]
public IContainer Header() public IContainer Header()
{ {
var container = new Container(); return Before();
Decoration.Before = container;
return container;
} }
[Obsolete("This element has been renamed since version 2022.2. Please use the 'Before' method.")] [Obsolete("This element has been renamed since version 2022.2. Please use the 'Before' method.")]
@@ -63,9 +61,7 @@ namespace QuestPDF.Fluent
[Obsolete("This element has been renamed since version 2022.2. Please use the 'After' method.")] [Obsolete("This element has been renamed since version 2022.2. Please use the 'After' method.")]
public IContainer Footer() public IContainer Footer()
{ {
var container = new Container(); return After();
Decoration.After = container;
return container;
} }
[Obsolete("This element has been renamed since version 2022.2. Please use the 'After' method.")] [Obsolete("This element has been renamed since version 2022.2. Please use the 'After' method.")]
+5 -6
View File
@@ -1,5 +1,4 @@
using System; using System;
using QuestPDF.Drawing;
using QuestPDF.Drawing.Exceptions; using QuestPDF.Drawing.Exceptions;
using QuestPDF.Elements; using QuestPDF.Elements;
using QuestPDF.Infrastructure; using QuestPDF.Infrastructure;
@@ -53,10 +52,10 @@ namespace QuestPDF.Fluent
public static IContainer Background(this IContainer element, string color) public static IContainer Background(this IContainer element, string color)
{ {
var background = ElementCacheManager.Get<Background>(); return element.Element(new Background
background.Color = color; {
Color = color
return element.Element(background); });
} }
public static void Placeholder(this IContainer element, string? text = null) public static void Placeholder(this IContainer element, string? text = null)
@@ -163,7 +162,7 @@ namespace QuestPDF.Fluent
public static IContainer MinimalBox(this IContainer element) public static IContainer MinimalBox(this IContainer element)
{ {
return element.Element(ElementCacheManager.Get<MinimalBox>()); return element.Element(new MinimalBox());
} }
public static IContainer Unconstrained(this IContainer element) public static IContainer Unconstrained(this IContainer element)
+1 -1
View File
@@ -24,7 +24,7 @@ namespace QuestPDF.Fluent
return container; return container;
} }
public IContainer Layer() => Layer(false); public IContainer Layer() => Layer(false).RepeatContentWhenPaging();
public IContainer PrimaryLayer() => Layer(true); public IContainer PrimaryLayer() => Layer(true);
internal void Validate() internal void Validate()
+6 -6
View File
@@ -6,11 +6,11 @@ namespace QuestPDF.Fluent
{ {
public static class LineExtensions public static class LineExtensions
{ {
private static ILine Line(this IContainer element, LineType type, float size) private static ILine Line(this IContainer element, LineType type, float thickness)
{ {
var line = new Line var line = new Line
{ {
Size = size, Thickness = thickness,
Type = type Type = type
}; };
@@ -18,14 +18,14 @@ namespace QuestPDF.Fluent
return line; return line;
} }
public static ILine LineVertical(this IContainer element, float size, Unit unit = Unit.Point) public static ILine LineVertical(this IContainer element, float thickness, Unit unit = Unit.Point)
{ {
return element.Line(LineType.Vertical, size.ToPoints(unit)); return element.Line(LineType.Vertical, thickness.ToPoints(unit));
} }
public static ILine LineHorizontal(this IContainer element, float size, Unit unit = Unit.Point) public static ILine LineHorizontal(this IContainer element, float thickness, Unit unit = Unit.Point)
{ {
return element.Line(LineType.Horizontal, size.ToPoints(unit)); return element.Line(LineType.Horizontal, thickness.ToPoints(unit));
} }
public static void LineColor(this ILine descriptor, string value) public static void LineColor(this ILine descriptor, string value)
+1 -2
View File
@@ -1,5 +1,4 @@
using System; using System;
using QuestPDF.Drawing;
using QuestPDF.Elements; using QuestPDF.Elements;
using QuestPDF.Infrastructure; using QuestPDF.Infrastructure;
@@ -9,7 +8,7 @@ namespace QuestPDF.Fluent
{ {
private static IContainer Padding(this IContainer element, Action<Padding> handler) private static IContainer Padding(this IContainer element, Action<Padding> handler)
{ {
var padding = element as Padding ?? ElementCacheManager.Get<Padding>(); var padding = element as Padding ?? new Padding();
handler(padding); handler(padding);
return element.Element(padding); return element.Element(padding);
@@ -0,0 +1,27 @@
using System;
using QuestPDF.Elements;
using QuestPDF.Infrastructure;
namespace QuestPDF.Fluent
{
public static class RepeatContentExtensions
{
private static IContainer RepeatContent(this IContainer element, Action<RepeatContentSetter> handler)
{
var repeatContentSetter = element as RepeatContentSetter ?? new RepeatContentSetter();
handler(repeatContentSetter);
return element.Element(repeatContentSetter);
}
public static IContainer RepeatContentWhenPaging(this IContainer element)
{
return element.RepeatContent(x => x.RepeatContent = true);
}
public static IContainer DoNotRepeatContentWhenPaging(this IContainer element)
{
return element.RepeatContent(x => x.RepeatContent = false);
}
}
}
+9 -11
View File
@@ -1,5 +1,4 @@
using System; using System;
using QuestPDF.Drawing;
using QuestPDF.Elements; using QuestPDF.Elements;
using QuestPDF.Infrastructure; using QuestPDF.Infrastructure;
@@ -7,7 +6,7 @@ namespace QuestPDF.Fluent
{ {
public class RowDescriptor public class RowDescriptor
{ {
internal Row Row { get; set; } internal Row Row { get; } = new();
public void Spacing(float value) public void Spacing(float value)
{ {
@@ -16,12 +15,14 @@ namespace QuestPDF.Fluent
private IContainer Item(RowItemType type, float size = 0) private IContainer Item(RowItemType type, float size = 0)
{ {
var rowItem = ElementCacheManager.Get<RowItem>(); var element = new RowItem
rowItem.Type = type; {
rowItem.Size = size; Type = type,
Size = size
};
Row.Items.Add(rowItem); Row.Items.Add(element);
return rowItem; return element;
} }
[Obsolete("This element has been renamed since version 2022.2. Please use the RelativeItem method.")] [Obsolete("This element has been renamed since version 2022.2. Please use the RelativeItem method.")]
@@ -56,12 +57,9 @@ namespace QuestPDF.Fluent
{ {
public static void Row(this IContainer element, Action<RowDescriptor> handler) public static void Row(this IContainer element, Action<RowDescriptor> handler)
{ {
var descriptor = ElementCacheManager.Get<RowDescriptor>(); var descriptor = new RowDescriptor();
descriptor.Row = ElementCacheManager.Get<Row>();
handler(descriptor); handler(descriptor);
element.Element(descriptor.Row); element.Element(descriptor.Row);
ElementCacheManager.Store(descriptor);
} }
} }
} }
+1
View File
@@ -36,6 +36,7 @@ namespace QuestPDF.Fluent
internal TextPageNumberDescriptor(Action<TextStyle> assignTextStyle, Action<PageNumberFormatter> assignFormatFunction) : base(assignTextStyle) internal TextPageNumberDescriptor(Action<TextStyle> assignTextStyle, Action<PageNumberFormatter> assignFormatFunction) : base(assignTextStyle)
{ {
AssignFormatFunction = assignFormatFunction; AssignFormatFunction = assignFormatFunction;
AssignFormatFunction(x => x?.ToString());
} }
public TextPageNumberDescriptor Format(PageNumberFormatter formatter) public TextPageNumberDescriptor Format(PageNumberFormatter formatter)
@@ -15,6 +15,17 @@ namespace QuestPDF.Fluent
return descriptor; return descriptor;
} }
public static T Fallback<T>(this T descriptor, TextStyle? value = null) where T : TextSpanDescriptor
{
descriptor.TextStyle.Fallback = value;
return descriptor;
}
public static T Fallback<T>(this T descriptor, Func<TextStyle, TextStyle> handler) where T : TextSpanDescriptor
{
return descriptor.Fallback(handler(TextStyle.Default));
}
public static T FontColor<T>(this T descriptor, string value) where T : TextSpanDescriptor public static T FontColor<T>(this T descriptor, string value) where T : TextSpanDescriptor
{ {
descriptor.MutateTextStyle(x => x.FontColor(value)); descriptor.MutateTextStyle(x => x.FontColor(value));
+16 -2
View File
@@ -4,8 +4,6 @@ using QuestPDF.Infrastructure;
namespace QuestPDF.Fluent namespace QuestPDF.Fluent
{ {
public static class TextStyleExtensions public static class TextStyleExtensions
{ {
[Obsolete("This element has been renamed since version 2022.3. Please use the FontColor method.")] [Obsolete("This element has been renamed since version 2022.3. Please use the FontColor method.")]
@@ -131,6 +129,7 @@ namespace QuestPDF.Fluent
#endregion #endregion
#region Position #region Position
public static TextStyle NormalPosition(this TextStyle style) public static TextStyle NormalPosition(this TextStyle style)
{ {
return style.Position(FontPosition.Normal); return style.Position(FontPosition.Normal);
@@ -150,6 +149,21 @@ namespace QuestPDF.Fluent
{ {
return style.Mutate(TextStyleProperty.FontPosition, fontPosition); return style.Mutate(TextStyleProperty.FontPosition, fontPosition);
} }
#endregion
#region Fallback
public static TextStyle Fallback(this TextStyle style, TextStyle? value = null)
{
return style.Mutate(TextStyleProperty.Fallback, value);
}
public static TextStyle Fallback(this TextStyle style, Func<TextStyle, TextStyle> handler)
{
return style.Fallback(handler(TextStyle.Default));
}
#endregion #endregion
} }
} }
+1 -6
View File
@@ -5,7 +5,7 @@ using QuestPDF.Elements;
namespace QuestPDF.Infrastructure namespace QuestPDF.Infrastructure
{ {
internal abstract class ContainerElement : Element, IContainer, ICollectable internal abstract class ContainerElement : Element, IContainer
{ {
internal Element? Child { get; set; } = Empty.Instance; internal Element? Child { get; set; } = Empty.Instance;
@@ -34,10 +34,5 @@ namespace QuestPDF.Infrastructure
{ {
Child?.Draw(availableSpace); Child?.Draw(availableSpace);
} }
public virtual void Collect()
{
Child = default;
}
} }
} }
-7
View File
@@ -1,7 +0,0 @@
namespace QuestPDF.Infrastructure
{
public interface ICollectable
{
void Collect();
}
}
+8
View File
@@ -0,0 +1,8 @@
namespace QuestPDF.Infrastructure
{
internal interface IVisual
{
public bool IsRendered { get; set; }
public bool RepeatContent { get; set; }
}
}
+4 -1
View File
@@ -17,6 +17,8 @@ namespace QuestPDF.Infrastructure
internal bool? HasUnderline { get; set; } internal bool? HasUnderline { get; set; }
internal bool? WrapAnywhere { get; set; } internal bool? WrapAnywhere { get; set; }
internal TextStyle? Fallback { get; set; }
internal static TextStyle LibraryDefault { get; } = new() internal static TextStyle LibraryDefault { get; } = new()
{ {
Color = Colors.Black, Color = Colors.Black,
@@ -29,7 +31,8 @@ namespace QuestPDF.Infrastructure
IsItalic = false, IsItalic = false,
HasStrikethrough = false, HasStrikethrough = false,
HasUnderline = false, HasUnderline = false,
WrapAnywhere = false WrapAnywhere = false,
Fallback = null
}; };
public static TextStyle Default { get; } = new(); public static TextStyle Default { get; } = new();
+53 -20
View File
@@ -16,13 +16,15 @@ namespace QuestPDF.Infrastructure
IsItalic, IsItalic,
HasStrikethrough, HasStrikethrough,
HasUnderline, HasUnderline,
WrapAnywhere WrapAnywhere,
Fallback
} }
internal static class TextStyleManager internal static class TextStyleManager
{ {
public static ConcurrentDictionary<(TextStyle origin, TextStyleProperty property, object value), TextStyle> TextStyleMutateCache = new(); private static readonly ConcurrentDictionary<(TextStyle origin, TextStyleProperty property, object value), TextStyle> TextStyleMutateCache = new();
public static ConcurrentDictionary<(TextStyle origin, TextStyle parent, bool overrideValue), TextStyle> TextStyleApplyCache = new(); private static readonly ConcurrentDictionary<(TextStyle origin, TextStyle parent), TextStyle> TextStyleApplyGlobalCache = new();
private static readonly ConcurrentDictionary<(TextStyle origin, TextStyle parent), TextStyle> TextStyleOverrideCache = new();
public static TextStyle Mutate(this TextStyle origin, TextStyleProperty property, object value) public static TextStyle Mutate(this TextStyle origin, TextStyleProperty property, object value)
{ {
@@ -30,7 +32,7 @@ namespace QuestPDF.Infrastructure
return TextStyleMutateCache.GetOrAdd(cacheKey, x => MutateStyle(x.origin, x.property, x.value)); return TextStyleMutateCache.GetOrAdd(cacheKey, x => MutateStyle(x.origin, x.property, x.value));
} }
private static TextStyle MutateStyle(TextStyle origin, TextStyleProperty property, object value, bool overrideValue = true) private static TextStyle MutateStyle(TextStyle origin, TextStyleProperty property, object? value, bool overrideValue = true)
{ {
if (overrideValue && value == null) if (overrideValue && value == null)
return origin; return origin;
@@ -178,36 +180,67 @@ namespace QuestPDF.Infrastructure
return origin with { WrapAnywhere = castedValue }; return origin with { WrapAnywhere = castedValue };
} }
if (property == TextStyleProperty.Fallback)
{
if (!overrideValue && origin.Fallback != null)
return origin;
var castedValue = (TextStyle?)value;
if (origin.Fallback == castedValue)
return origin;
return origin with { Fallback = castedValue };
}
throw new ArgumentOutOfRangeException(nameof(property), property, "Expected to mutate the TextStyle object. Provided property type is not supported."); throw new ArgumentOutOfRangeException(nameof(property), property, "Expected to mutate the TextStyle object. Provided property type is not supported.");
} }
internal static TextStyle ApplyGlobalStyle(this TextStyle style, TextStyle parent) internal static TextStyle ApplyGlobalStyle(this TextStyle style, TextStyle parent)
{ {
var cacheKey = (style, parent, false); var cacheKey = (style, parent);
return TextStyleApplyCache.GetOrAdd(cacheKey, key => ApplyStyle(key.origin, key.parent, key.overrideValue)); return TextStyleApplyGlobalCache.GetOrAdd(cacheKey, key => ApplyStyle(key.origin, key.parent, overrideStyle: false).ApplyFontFallback());
}
private static TextStyle ApplyFontFallback(this TextStyle style)
{
var targetFallbackStyle = style
?.Fallback
?.ApplyStyle(style, overrideStyle: false, applyFallback: false)
?.ApplyFontFallback();
return MutateStyle(style, TextStyleProperty.Fallback, targetFallbackStyle);
} }
internal static TextStyle OverrideStyle(this TextStyle style, TextStyle parent) internal static TextStyle OverrideStyle(this TextStyle style, TextStyle parent)
{ {
var cacheKey = (style, parent, true); var cacheKey = (style, parent);
return TextStyleApplyCache.GetOrAdd(cacheKey, key => ApplyStyle(key.origin, key.parent, key.overrideValue));
return TextStyleOverrideCache.GetOrAdd(cacheKey, key =>
{
var result = ApplyStyle(key.origin, key.parent);
return MutateStyle(result, TextStyleProperty.Fallback, key.parent.Fallback);
});
} }
private static TextStyle ApplyStyle(TextStyle style, TextStyle parent, bool overrideValue) private static TextStyle ApplyStyle(this TextStyle style, TextStyle parent, bool overrideStyle = true, bool applyFallback = true)
{ {
var result = style; var result = style;
result = MutateStyle(result, TextStyleProperty.Color, parent.Color, overrideValue); result = MutateStyle(result, TextStyleProperty.Color, parent.Color, overrideStyle);
result = MutateStyle(result, TextStyleProperty.BackgroundColor, parent.BackgroundColor, overrideValue); result = MutateStyle(result, TextStyleProperty.BackgroundColor, parent.BackgroundColor, overrideStyle);
result = MutateStyle(result, TextStyleProperty.FontFamily, parent.FontFamily, overrideValue); result = MutateStyle(result, TextStyleProperty.FontFamily, parent.FontFamily, overrideStyle);
result = MutateStyle(result, TextStyleProperty.Size, parent.Size, overrideValue); result = MutateStyle(result, TextStyleProperty.Size, parent.Size, overrideStyle);
result = MutateStyle(result, TextStyleProperty.LineHeight, parent.LineHeight, overrideValue); result = MutateStyle(result, TextStyleProperty.LineHeight, parent.LineHeight, overrideStyle);
result = MutateStyle(result, TextStyleProperty.FontWeight, parent.FontWeight, overrideValue); result = MutateStyle(result, TextStyleProperty.FontWeight, parent.FontWeight, overrideStyle);
result = MutateStyle(result, TextStyleProperty.FontPosition, parent.FontPosition, overrideValue); result = MutateStyle(result, TextStyleProperty.FontPosition, parent.FontPosition, overrideStyle);
result = MutateStyle(result, TextStyleProperty.IsItalic, parent.IsItalic, overrideValue); result = MutateStyle(result, TextStyleProperty.IsItalic, parent.IsItalic, overrideStyle);
result = MutateStyle(result, TextStyleProperty.HasStrikethrough, parent.HasStrikethrough, overrideValue); result = MutateStyle(result, TextStyleProperty.HasStrikethrough, parent.HasStrikethrough, overrideStyle);
result = MutateStyle(result, TextStyleProperty.HasUnderline, parent.HasUnderline, overrideValue); result = MutateStyle(result, TextStyleProperty.HasUnderline, parent.HasUnderline, overrideStyle);
result = MutateStyle(result, TextStyleProperty.WrapAnywhere, parent.WrapAnywhere, overrideValue); result = MutateStyle(result, TextStyleProperty.WrapAnywhere, parent.WrapAnywhere, overrideStyle);
if (applyFallback)
result = MutateStyle(result, TextStyleProperty.Fallback, parent.Fallback, overrideStyle);
return result; return result;
} }
+1 -1
View File
@@ -19,7 +19,7 @@ namespace QuestPDF.Previewer
public event Action? OnPreviewerStopped; public event Action? OnPreviewerStopped;
private const int RequiredPreviewerVersionMajor = 2022; private const int RequiredPreviewerVersionMajor = 2022;
private const int RequiredPreviewerVersionMinor = 8; private const int RequiredPreviewerVersionMinor = 9;
public PreviewerService(int port) public PreviewerService(int port)
{ {
+1 -1
View File
@@ -3,7 +3,7 @@
<Authors>MarcinZiabek</Authors> <Authors>MarcinZiabek</Authors>
<Company>CodeFlint</Company> <Company>CodeFlint</Company>
<PackageId>QuestPDF</PackageId> <PackageId>QuestPDF</PackageId>
<Version>2022.8.2</Version> <Version>2022.9.1</Version>
<PackageDescription>QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API.</PackageDescription> <PackageDescription>QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API.</PackageDescription>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/Resources/ReleaseNotes.txt"))</PackageReleaseNotes> <PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/Resources/ReleaseNotes.txt"))</PackageReleaseNotes>
<LangVersion>9</LangVersion> <LangVersion>9</LangVersion>
+10 -19
View File
@@ -1,20 +1,11 @@
2022.8.0: 2022.9.0
- Implemented font-fallback algorithm,
- Introduced new Settings API,
- Significantly reduced memory allocation cost for TextStyle objects,
- Implemented optional checking if all font glyphs are available,
- Minor text-rendering optimizations.
- Improved library performance, 2022.9.1
- Breaking change: changed default font from Calibri to an open-source Lato, - Fixed: text hyperlinks do not work when the CheckIfAllTextGlyphsAreAvailable option or text fallback are used,
- Default font files are included with the nuget package, making it safe to deploy on any environment, - Fixed: cells with RowSpan (greater than 1) are not always displayed properly,
- Default font files are significantly smaller, so output document files should be smaller too (up to 20x reduction in size), - Improved predictability of the Inlined element when measuring its children.
- When requested font is not available on the runtime environment, library provides list of available fonts,
- Fixed a rare layout overflow exception with the Inlined element,
- Fixed a memory leak connected to the HarfBuzz library.
2022.8.1:
- Fixed: default text style does not always work
- Fixed: page breaking rendering does not work in very specific corner cases
- Stability improvements for text wrapping
- Updated stability of rendering elements in negative space
- Optimization for the Column element: do not measure child when available height is negative
2022.8.2
- Fixed: the Column element incorrectly renders zero-height elements.
+2 -2
View File
@@ -3,7 +3,7 @@
public static class Settings public static class Settings
{ {
/// <summary> /// <summary>
/// This value represents the maximum lenght of the document that the library produces. /// This value represents the maximum length of the document that the library produces.
/// This is useful when layout constraints are too strong, e.g. one element does not fit in another. /// This is useful when layout constraints are too strong, e.g. one element does not fit in another.
/// In such cases, the library would produce document of infinite length, consuming all available resources. /// In such cases, the library would produce document of infinite length, consuming all available resources.
/// To break the algorithm and save the environment, the library breaks the rendering process after reaching specified length of document. /// To break the algorithm and save the environment, the library breaks the rendering process after reaching specified length of document.
@@ -35,6 +35,6 @@
/// However, it provides hints that used fonts are not sufficient to produce correct results. /// However, it provides hints that used fonts are not sufficient to produce correct results.
/// </summary> /// </summary>
/// <remarks>By default, this flag is enabled only when the debugger IS attached.</remarks> /// <remarks>By default, this flag is enabled only when the debugger IS attached.</remarks>
public static bool CheckIfAllTextGlyphsAreAvailableInSpecifiedFont { get; set; } = System.Diagnostics.Debugger.IsAttached; public static bool CheckIfAllTextGlyphsAreAvailable { get; set; } = System.Diagnostics.Debugger.IsAttached;
} }
} }
+8 -6
View File
@@ -17,13 +17,14 @@ It offers a layouting engine designed with a full paging support in mind. The do
Unlike other libraries, it does not rely on the HTML-to-PDF conversion which in many cases is not reliable. Instead, it implements its own layouting engine that is optimized to cover all paging-related requirements. Unlike other libraries, it does not rely on the HTML-to-PDF conversion which in many cases is not reliable. Instead, it implements its own layouting engine that is optimized to cover all paging-related requirements.
## Please show the value ## Please help by giving a star
Choosing a project dependency could be difficult. We need to ensure stability and maintainability of our projects. Surveys show that GitHub stars count play an important factor when assessing library quality. Choosing a project dependency could be difficult. We need to ensure stability and maintainability of our projects. Surveys show that GitHub stars count play an important factor when assessing library quality.
⭐ Please give this repository a star. It takes seconds and help thousands of developers! ⭐ ⭐ Please give this repository a star. It takes seconds and help thousands of developers! ⭐
<img src="https://user-images.githubusercontent.com/9263853/184642026-27dd7567-a46a-45d4-9594-e6a70a7193e9.png" width="700" /> <img src="https://user-images.githubusercontent.com/9263853/190931857-8ca52ec8-cc7d-4d12-9467-4442b3342fa1.png" width="700" />
## Please share with the community ## Please share with the community
@@ -46,6 +47,7 @@ Special thanks to all companies that decided to sponsor QuestPDF development. Th
| Company | Description | | Company | Description |
|--------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------| |--------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------|
| <img src="Resources/jetbrains-logo.svg" width="100px"> | [JetBrains](https://www.jetbrains.com/) supports this project as part of the OSS Power-Ups program. Thank you!<br/>100$ / month | | <img src="Resources/jetbrains-logo.svg" width="100px"> | [JetBrains](https://www.jetbrains.com/) supports this project as part of the OSS Power-Ups program. Thank you!<br/>100$ / month |
| <img src="https://avatars.githubusercontent.com/u/2712328?v=4" width="100px"> | [Mark Gould](https://github.com/markgould) supports this project. Thank you!<br/>100$ / month |
[![Sponsor project](https://img.shields.io/badge/%E2%9D%A4%EF%B8%8F%20sponsor-QuestPDF-red)](https://github.com/sponsors/QuestPDF) [![Sponsor project](https://img.shields.io/badge/%E2%9D%A4%EF%B8%8F%20sponsor-QuestPDF-red)](https://github.com/sponsors/QuestPDF)
@@ -61,14 +63,14 @@ Install-Package QuestPDF
dotnet add package QuestPDF dotnet add package QuestPDF
// Package reference in .csproj file // Package reference in .csproj file
<PackageReference Include="QuestPDF" Version="2022.6.0" /> <PackageReference Include="QuestPDF" Version="2022.9.0" />
``` ```
[![Nuget version](https://img.shields.io/badge/package%20details-QuestPDF-blue?logo=nuget)](https://www.nuget.org/packages/QuestPDF/) [![Nuget version](https://img.shields.io/badge/package%20details-QuestPDF-blue?logo=nuget)](https://www.nuget.org/packages/QuestPDF/)
## Documentation ## Documentation
[![Getting started tutorial]( https://img.shields.io/badge/%F0%9F%9A%80%20read-getting%20started-blue)](https://www.questpdf.com/getting-started.html) [![Getting started tutorial]( https://img.shields.io/badge/%F0%9F%9A%80%20read-getting%20started-blue)](https://www.questpdf.com/getting-started)
A short and easy to follow tutorial showing how to design an invoice document under 200 lines of code. A short and easy to follow tutorial showing how to design an invoice document under 200 lines of code.
@@ -76,14 +78,14 @@ A short and easy to follow tutorial showing how to design an invoice document un
A detailed description of behavior of all available components and how to use them with C# Fluent API. A detailed description of behavior of all available components and how to use them with C# Fluent API.
[![Patterns and Practices](https://img.shields.io/badge/%E2%9C%A8%20read-patterns%20and%20practices-blue)](https://www.questpdf.com/design-patterns.html) [![Patterns and Practices](https://img.shields.io/badge/%E2%9C%A8%20read-patterns%20and%20practices-blue)](https://www.questpdf.com/design-patterns)
Everything that may help you designing great reports and create reusable code that is easy to maintain. Everything that may help you designing great reports and create reusable code that is easy to maintain.
## QuestPDF Previewer ## QuestPDF Previewer
The QuestPDF Previewer is a tool designed to simplify and speed up your development lifecycle. First, it shows a preview of your document. But the real magic starts with the hot-reload capability! It observes your code and updates the preview every time you change the implementation. Get real-time results without the need of code recompilation. Save time and enjoy the task! The QuestPDF Previewer is a tool designed to simplify and speed up your development lifecycle. First, it shows a preview of your document. But the real magic starts with the hot-reload capability! It observes your code and updates the preview every time you change the implementation. Get real-time results without the need of code recompilation. Save time and enjoy the task!
[![Learn more](https://img.shields.io/badge/%F0%9F%93%96%20Previewer-learn%20more-blue)](https://www.questpdf.com/document-previewer.html) [![Learn more](https://img.shields.io/badge/%F0%9F%93%96%20Previewer-learn%20more-blue)](https://www.questpdf.com/document-previewer)
<img src="https://github.com/QuestPDF/QuestPDF-Documentation/blob/main/docs/public/previewer/animation.gif?raw=true" width="100%"> <img src="https://github.com/QuestPDF/QuestPDF-Documentation/blob/main/docs/public/previewer/animation.gif?raw=true" width="100%">