diff --git a/Source/OpenQuestPDF.Examples/ContentDirectionExamples.cs b/Source/OpenQuestPDF.Examples/ContentDirectionExamples.cs index 80b0626fd..857110275 100644 --- a/Source/OpenQuestPDF.Examples/ContentDirectionExamples.cs +++ b/Source/OpenQuestPDF.Examples/ContentDirectionExamples.cs @@ -111,7 +111,7 @@ public void Page() var price = Placeholders.Random.NextDouble() * 100; table.Cell().Text(item); - table.Cell().Text(Placeholders.Random.Next(1, 10)); + table.Cell().Text(Placeholders.Random.Next(1, 10).ToString()); table.Cell().Text($"USD${price:F2}"); } diff --git a/Source/OpenQuestPDF.Examples/DefaultTextStyleExample.cs b/Source/OpenQuestPDF.Examples/DefaultTextStyleExample.cs index 07fe7c6b5..386d7b8a8 100644 --- a/Source/OpenQuestPDF.Examples/DefaultTextStyleExample.cs +++ b/Source/OpenQuestPDF.Examples/DefaultTextStyleExample.cs @@ -20,7 +20,7 @@ public void DefaultTextStyle() container.Page(page => { // all text in this set of pages has size 20 - page.DefaultTextStyle(TextStyle.Default.Size(20)); + page.DefaultTextStyle(TextStyle.Default.FontSize(20)); page.Margin(20); page.Size(PageSizes.A4); diff --git a/Source/OpenQuestPDF.Examples/DifferentHeaderOnFirstPageExample.cs b/Source/OpenQuestPDF.Examples/DifferentHeaderOnFirstPageExample.cs index aec742447..ed6f994dc 100644 --- a/Source/OpenQuestPDF.Examples/DifferentHeaderOnFirstPageExample.cs +++ b/Source/OpenQuestPDF.Examples/DifferentHeaderOnFirstPageExample.cs @@ -42,7 +42,7 @@ public void Placeholder() page.Footer().AlignCenter().Text(text => { - text.DefaultTextStyle(TextStyle.Default.Size(16)); + text.DefaultTextStyle(TextStyle.Default.FontSize(16)); text.CurrentPageNumber(); text.Span(" / "); diff --git a/Source/OpenQuestPDF.Examples/DynamicSimpleTableExample.cs b/Source/OpenQuestPDF.Examples/DynamicSimpleTableExample.cs index b2cfe0409..c025c0c91 100644 --- a/Source/OpenQuestPDF.Examples/DynamicSimpleTableExample.cs +++ b/Source/OpenQuestPDF.Examples/DynamicSimpleTableExample.cs @@ -90,7 +90,8 @@ IContainer Style(IContainer container) .Cell().ColumnSpan(5) .AlignRight() .PaddingTop(10) - .Text($"Subtotal: {total}$", TextStyle.Default.Bold()); + .Text($"Subtotal: {total}$") + .Style(TextStyle.Default.Bold()); }); foreach (var index in Enumerable.Range(State.ShownItemsCount, itemsToDisplay)) @@ -137,7 +138,7 @@ public static void Dynamic() .Decoration(decoration => { decoration - .Header() + .Before() .PaddingBottom(5) .Text(text => { diff --git a/Source/OpenQuestPDF.Examples/ElementExamples.cs b/Source/OpenQuestPDF.Examples/ElementExamples.cs index 4654b21de..4de7b7107 100644 --- a/Source/OpenQuestPDF.Examples/ElementExamples.cs +++ b/Source/OpenQuestPDF.Examples/ElementExamples.cs @@ -192,7 +192,7 @@ public void GridExample() .PageSize(400, 230) .Render(container => { - var textStyle = TextStyle.Default.Size(14); + var textStyle = TextStyle.Default.FontSize(14); container .Padding(15) @@ -503,8 +503,8 @@ public void Scale() { var headerFontStyle = TextStyle .Default - .Size(20) - .Color(Colors.Blue.Darken2) + .FontSize(20) + .FontColor(Colors.Blue.Darken2) .SemiBold(); decoration @@ -525,7 +525,7 @@ public void Scale() ? Colors.Red.Lighten4 : Colors.Green.Lighten4; - var fontStyle = TextStyle.Default.Size(16); + var fontStyle = TextStyle.Default.FontSize(16); column .Item() diff --git a/Source/OpenQuestPDF.Examples/Engine/RenderingTest.cs b/Source/OpenQuestPDF.Examples/Engine/RenderingTest.cs index 2953ede05..70ae718fb 100644 --- a/Source/OpenQuestPDF.Examples/Engine/RenderingTest.cs +++ b/Source/OpenQuestPDF.Examples/Engine/RenderingTest.cs @@ -104,7 +104,10 @@ public void Render(Action content) public void RenderDocument(Action content) { MaxPagesThreshold ??= ResultType == RenderingTestResult.Pdf ? 1000 : 10; - var document = new SimpleDocument(content, MaxPagesThreshold.Value, ApplyCaching, ApplyDebugging); + Settings.DocumentLayoutExceptionThreshold = MaxPagesThreshold.Value; + Settings.EnableCaching = ApplyCaching; + Settings.EnableDebugging = ApplyDebugging; + var document = new SimpleDocument(content); Render(document); } diff --git a/Source/OpenQuestPDF.Examples/Engine/SimpleDocument.cs b/Source/OpenQuestPDF.Examples/Engine/SimpleDocument.cs index 243032dc6..6f2933a8f 100644 --- a/Source/OpenQuestPDF.Examples/Engine/SimpleDocument.cs +++ b/Source/OpenQuestPDF.Examples/Engine/SimpleDocument.cs @@ -12,26 +12,18 @@ public class SimpleDocument : IDocument public const int ImageScalingFactor = 2; private Action Content { get; } - private int MaxPages { get; } - private bool ApplyCaching { get; } - private bool ApplyDebugging { get; } - public SimpleDocument(Action content, int maxPages, bool applyCaching, bool applyDebugging) + public SimpleDocument(Action content) { - Content = content; - MaxPages = maxPages; - ApplyCaching = applyCaching; - ApplyDebugging = applyDebugging; + Content = content; } public DocumentMetadata GetMetadata() { + return new DocumentMetadata() { RasterDpi = PageSizes.PointsPerInch * ImageScalingFactor, - DocumentLayoutExceptionThreshold = MaxPages, - ApplyCaching = ApplyCaching, - ApplyDebugging = ApplyDebugging }; } diff --git a/Source/OpenQuestPDF.Examples/ExecutionOrderExamples.cs b/Source/OpenQuestPDF.Examples/ExecutionOrderExamples.cs index 06447cad2..7aca6c18b 100644 --- a/Source/OpenQuestPDF.Examples/ExecutionOrderExamples.cs +++ b/Source/OpenQuestPDF.Examples/ExecutionOrderExamples.cs @@ -20,7 +20,7 @@ public void Example() .Render(container => { container - .DefaultTextStyle(TextStyle.Default.Size(18)) + .DefaultTextStyle(TextStyle.Default.FontSize(18)) .Padding(25) .Row(row => { diff --git a/Source/OpenQuestPDF.Examples/InlinedExamples.cs b/Source/OpenQuestPDF.Examples/InlinedExamples.cs index 01e8913c8..c25b73171 100644 --- a/Source/OpenQuestPDF.Examples/InlinedExamples.cs +++ b/Source/OpenQuestPDF.Examples/InlinedExamples.cs @@ -27,7 +27,7 @@ public void Inlined() { decoration.Before().Text(text => { - text.DefaultTextStyle(TextStyle.Default.Size(20)); + text.DefaultTextStyle(TextStyle.Default.FontSize(20)); text.CurrentPageNumber(); text.Span(" / "); diff --git a/Source/OpenQuestPDF.Examples/LineExamples.cs b/Source/OpenQuestPDF.Examples/LineExamples.cs index 63bef11db..706b2ee47 100644 --- a/Source/OpenQuestPDF.Examples/LineExamples.cs +++ b/Source/OpenQuestPDF.Examples/LineExamples.cs @@ -22,7 +22,7 @@ public void LineHorizontal() container .Padding(15) .MinimalBox() - .DefaultTextStyle(TextStyle.Default.Size(16)) + .DefaultTextStyle(TextStyle.Default.FontSize(16)) .Column(column => { column.Item().Text("Above text"); @@ -44,7 +44,7 @@ public void LineVertical() { container .Padding(15) - .DefaultTextStyle(TextStyle.Default.Size(16)) + .DefaultTextStyle(TextStyle.Default.FontSize(16)) .Row(row => { row.AutoItem().Text("Left text"); diff --git a/Source/OpenQuestPDF.Examples/LoremPicsumExample.cs b/Source/OpenQuestPDF.Examples/LoremPicsumExample.cs index 406125f51..86e365c9c 100644 --- a/Source/OpenQuestPDF.Examples/LoremPicsumExample.cs +++ b/Source/OpenQuestPDF.Examples/LoremPicsumExample.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net.Http; using NUnit.Framework; using OpenQuestPDF.Examples.Engine; using OpenQuestPDF.Fluent; @@ -14,7 +14,7 @@ public LoremPicsum(bool greyscale) { Greyscale = greyscale; } - + public void Compose(IContainer container) { var url = "https://picsum.photos/300/200"; @@ -22,14 +22,15 @@ public void Compose(IContainer container) if (Greyscale) url += "?grayscale"; - using var client = new WebClient(); - client.Headers.Add("user-agent", "QuestPDF/1.0 Unit Testing"); - - var response = client.DownloadData(url); - container.Image(response); + using var client = new HttpClient(); + client.DefaultRequestHeaders.Add("user-agent", "OpenQuestPDF/1.0 Unit Testing"); + + var response = client.GetByteArrayAsync(url); + response.Wait(); + container.Image(response.Result); } } - + public class LoremPicsumExample { [Test] @@ -52,7 +53,7 @@ public void LoremPicsum() column .Item() .Component(new LoremPicsum(true)); - + column .Item() .AlignRight() diff --git a/Source/OpenQuestPDF.Examples/StopPaging.cs b/Source/OpenQuestPDF.Examples/StopPaging.cs index 374400b52..17ca8cc3c 100644 --- a/Source/OpenQuestPDF.Examples/StopPaging.cs +++ b/Source/OpenQuestPDF.Examples/StopPaging.cs @@ -20,14 +20,14 @@ public void Example() { container .Padding(25) - .DefaultTextStyle(TextStyle.Default.Size(14)) + .DefaultTextStyle(TextStyle.Default.FontSize(14)) .Decoration(decoration => { decoration .Before() .Text(text => { - text.DefaultTextStyle(TextStyle.Default.SemiBold().Color(Colors.Blue.Medium)); + text.DefaultTextStyle(TextStyle.Default.SemiBold().FontColor(Colors.Blue.Medium)); text.Span("Page "); text.CurrentPageNumber(); diff --git a/Source/OpenQuestPDF.Examples/TableExamples.cs b/Source/OpenQuestPDF.Examples/TableExamples.cs index b7e118dcb..83de3974c 100644 --- a/Source/OpenQuestPDF.Examples/TableExamples.cs +++ b/Source/OpenQuestPDF.Examples/TableExamples.cs @@ -97,7 +97,7 @@ public void DefaultCellStyle() .Padding(10) .MinimalBox() .Border(1) - .DefaultTextStyle(TextStyle.Default.Size(16)) + .DefaultTextStyle(TextStyle.Default.FontSize(16)) .Table(table => { table.ColumnsDefinition(columns => diff --git a/Source/OpenQuestPDF.Examples/TextBenchmark.cs b/Source/OpenQuestPDF.Examples/TextBenchmark.cs index 88314db32..c8a3f9bc8 100644 --- a/Source/OpenQuestPDF.Examples/TextBenchmark.cs +++ b/Source/OpenQuestPDF.Examples/TextBenchmark.cs @@ -104,8 +104,8 @@ private static IEnumerable GetBookChapters() private void ComposeBook(IDocumentContainer container, ICollection chapters) { - var subtitleStyle = TextStyle.Default.Size(24).SemiBold().Color(Colors.Blue.Medium); - var normalStyle = TextStyle.Default.Size(14); + var subtitleStyle = TextStyle.Default.FontSize(24).SemiBold().FontColor(Colors.Blue.Medium); + var normalStyle = TextStyle.Default.FontSize(14); container.Page(page => { @@ -147,7 +147,7 @@ void TableOfContents(IContainer container) foreach (var chapter in chapters) { - column.Item().InternalLink(chapter.Title).Row(row => + column.Item().SectionLink(chapter.Title).Row(row => { row.RelativeItem().Text(chapter.Title).Style(normalStyle); row.ConstantItem(100).AlignRight().Text(text => text.BeginPageNumberOfSection(chapter.Title).Style(normalStyle)); @@ -199,7 +199,7 @@ void Acknowledgements(IContainer container) void SectionTitle(ColumnDescriptor column, string text) { - column.Item().Location(text).Text(text).Style(subtitleStyle); + column.Item().Section(text).Text(text).Style(subtitleStyle); column.Item().PaddingTop(10).PaddingBottom(50).BorderBottom(1).BorderColor(Colors.Grey.Lighten2).ExtendHorizontal(); } diff --git a/Source/OpenQuestPDF.Examples/TextExamples.cs b/Source/OpenQuestPDF.Examples/TextExamples.cs index 722b62af4..47d95568f 100644 --- a/Source/OpenQuestPDF.Examples/TextExamples.cs +++ b/Source/OpenQuestPDF.Examples/TextExamples.cs @@ -495,7 +495,7 @@ public void SpaceIssue() text.EmptyLine(); - text.Hyperlink("Please visit QuestPDF website", "https://www.questpdf.com"); + text.Hyperlink("Please visit OpenQuestPDF GitHub repository", "https://www.github.com/LM-Development/OpenQuestPDF"); text.EmptyLine(); @@ -549,7 +549,7 @@ public void HugeList() { text.Line($"{i}: {Placeholders.Paragraph()}"); - text.Hyperlink("Please visit QuestPDF website. ", "https://www.questpdf.com"); + text.Hyperlink("Please visit OpenQuestPDF project page. ", "https://www.github.com/LM-Development/OpenQuestPDF"); text.Span("This is page number "); text.CurrentPageNumber(); @@ -928,10 +928,14 @@ public void DetectSpanPositionExample() var paint = new SKPaint { Color = SKColors.Red, - TextSize = fontSize + }; + + var font = new SKFont + { + Size = fontSize, }; - var fontMetrics = paint.FontMetrics; + var fontMetrics = font.Metrics; var start = 0f; var end = 0f; diff --git a/Source/OpenQuestPDF.Previewer/InteractiveCanvas.cs b/Source/OpenQuestPDF.Previewer/InteractiveCanvas.cs index bd579ef03..666f29310 100644 --- a/Source/OpenQuestPDF.Previewer/InteractiveCanvas.cs +++ b/Source/OpenQuestPDF.Previewer/InteractiveCanvas.cs @@ -1,4 +1,5 @@ using Avalonia; +using Avalonia.Media; using Avalonia.Platform; using Avalonia.Rendering.SceneGraph; using Avalonia.Skia; @@ -9,7 +10,7 @@ namespace OpenQuestPDF.Previewer; class InteractiveCanvas : ICustomDrawOperation { public Rect Bounds { get; set; } - public ICollection Pages { get; set; } + public ICollection? Pages { get; set; } private float Width => (float)Bounds.Width; private float Height => (float)Bounds.Height; @@ -24,9 +25,9 @@ class InteractiveCanvas : ICustomDrawOperation private const float PageSpacing = 25f; private const float SafeZone = 25f; - public float TotalPagesHeight => Pages.Sum(x => x.Height) + (Pages.Count - 1) * PageSpacing; + public float TotalPagesHeight => Pages != null ? Pages.Sum(x => x.Height) + (Pages.Count - 1) * PageSpacing : 0; public float TotalHeight => TotalPagesHeight + SafeZone * 2 / Scale; - public float MaxWidth => Pages.Any() ? Pages.Max(x => x.Width) : 0; + public float MaxWidth => Pages != null && Pages.Any() ? Pages.Max(x => x.Width) : 0; public float MaxTranslateY => TotalHeight - Height / Scale; @@ -109,18 +110,20 @@ public void ZoomToPoint(float x, float y, float factor) #region rendering - public void Render(IDrawingContextImpl context) + public void Render(ImmediateDrawingContext context) { - if (Pages.Count <= 0) + var leaseFeature = context.TryGetFeature(); + if (leaseFeature == null) + throw new InvalidOperationException($"Context needs to support {nameof(ISkiaSharpApiLeaseFeature)}"); + using var lease = leaseFeature.Lease(); + + var canvas = lease.SkCanvas; + + if (Pages == null || Pages.Count <= 0) return; LimitScale(); - LimitTranslate(); - - var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas; - - if (canvas == null) - throw new InvalidOperationException($"Context needs to be ISkiaDrawingContextImpl but got {nameof(context)}"); + LimitTranslate(); var originalMatrix = canvas.TotalMatrix; diff --git a/Source/OpenQuestPDF.Previewer/OpenQuestPDF.Previewer.csproj b/Source/OpenQuestPDF.Previewer/OpenQuestPDF.Previewer.csproj index e8cbf12fe..2577e6ca3 100644 --- a/Source/OpenQuestPDF.Previewer/OpenQuestPDF.Previewer.csproj +++ b/Source/OpenQuestPDF.Previewer/OpenQuestPDF.Previewer.csproj @@ -1,4 +1,4 @@ - + LM Development @@ -8,7 +8,7 @@ questpdf-previewer OpenQuestPDF 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. Initial release. - https://github.com/LMDevelopment/OpenQuestPDF.git + https://github.com/LM-Development/OpenQuestPDF.git git LM IT Services AG, OpenQuestPDF contributors pdf report file export generate generation tool create creation render portable document format quest html library converter open source free standard core previewer @@ -38,6 +38,7 @@ + diff --git a/Source/OpenQuestPDF.Previewer/PreviewerApp.axaml b/Source/OpenQuestPDF.Previewer/PreviewerApp.axaml index 4c3e4f584..4b0a4d577 100644 --- a/Source/OpenQuestPDF.Previewer/PreviewerApp.axaml +++ b/Source/OpenQuestPDF.Previewer/PreviewerApp.axaml @@ -1,8 +1,9 @@ - + Name="OpenQuestPDF Document Preview" + RequestedThemeVariant="Dark"> - + \ No newline at end of file diff --git a/Source/OpenQuestPDF.Previewer/PreviewerWindow.axaml b/Source/OpenQuestPDF.Previewer/PreviewerWindow.axaml index ee81f66bc..cc4a2dfcf 100644 --- a/Source/OpenQuestPDF.Previewer/PreviewerWindow.axaml +++ b/Source/OpenQuestPDF.Previewer/PreviewerWindow.axaml @@ -2,9 +2,9 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:previewer="clr-namespace:QuestPDF.Previewer" + xmlns:previewer="clr-namespace:OpenQuestPDF.Previewer" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="QuestPDF.Previewer.PreviewerWindow" + x:Class="OpenQuestPDF.Previewer.PreviewerWindow" x:DataType="previewer:PreviewerWindowViewModel" x:CompileBindings="True" WindowStartupLocation="CenterScreen" @@ -13,7 +13,7 @@ Background="#666" Icon="/Resources/Logo.png" UseLayoutRounding="True" - Title="QuestPDF Document Preview"> + Title="OpenQuestPDF Document Preview">