Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/OpenQuestPDF.Examples/ContentDirectionExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}

Expand Down
2 changes: 1 addition & 1 deletion Source/OpenQuestPDF.Examples/DefaultTextStyleExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(" / ");
Expand Down
5 changes: 3 additions & 2 deletions Source/OpenQuestPDF.Examples/DynamicSimpleTableExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -137,7 +138,7 @@ public static void Dynamic()
.Decoration(decoration =>
{
decoration
.Header()
.Before()
.PaddingBottom(5)
.Text(text =>
{
Expand Down
8 changes: 4 additions & 4 deletions Source/OpenQuestPDF.Examples/ElementExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion Source/OpenQuestPDF.Examples/Engine/RenderingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public void Render(Action<IContainer> content)
public void RenderDocument(Action<IDocumentContainer> 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);
}
Expand Down
14 changes: 3 additions & 11 deletions Source/OpenQuestPDF.Examples/Engine/SimpleDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,18 @@ public class SimpleDocument : IDocument
public const int ImageScalingFactor = 2;

private Action<IDocumentContainer> Content { get; }
private int MaxPages { get; }
private bool ApplyCaching { get; }
private bool ApplyDebugging { get; }

public SimpleDocument(Action<IDocumentContainer> content, int maxPages, bool applyCaching, bool applyDebugging)
public SimpleDocument(Action<IDocumentContainer> 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
};
}

Expand Down
2 changes: 1 addition & 1 deletion Source/OpenQuestPDF.Examples/ExecutionOrderExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Example()
.Render(container =>
{
container
.DefaultTextStyle(TextStyle.Default.Size(18))
.DefaultTextStyle(TextStyle.Default.FontSize(18))
.Padding(25)
.Row(row =>
{
Expand Down
2 changes: 1 addition & 1 deletion Source/OpenQuestPDF.Examples/InlinedExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(" / ");
Expand Down
4 changes: 2 additions & 2 deletions Source/OpenQuestPDF.Examples/LineExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down
19 changes: 10 additions & 9 deletions Source/OpenQuestPDF.Examples/LoremPicsumExample.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Net;
using System.Net.Http;
using NUnit.Framework;
using OpenQuestPDF.Examples.Engine;
using OpenQuestPDF.Fluent;
Expand All @@ -14,22 +14,23 @@ public LoremPicsum(bool greyscale)
{
Greyscale = greyscale;
}

public void Compose(IContainer container)
{
var url = "https://picsum.photos/300/200";

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]
Expand All @@ -52,7 +53,7 @@ public void LoremPicsum()
column
.Item()
.Component(new LoremPicsum(true));

column
.Item()
.AlignRight()
Expand Down
4 changes: 2 additions & 2 deletions Source/OpenQuestPDF.Examples/StopPaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Source/OpenQuestPDF.Examples/TableExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
8 changes: 4 additions & 4 deletions Source/OpenQuestPDF.Examples/TextBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ private static IEnumerable<BookChapter> GetBookChapters()

private void ComposeBook(IDocumentContainer container, ICollection<BookChapter> 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 =>
{
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
}

Expand Down
12 changes: 8 additions & 4 deletions Source/OpenQuestPDF.Examples/TextExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 14 additions & 11 deletions Source/OpenQuestPDF.Previewer/InteractiveCanvas.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia;
using Avalonia.Media;
using Avalonia.Platform;
using Avalonia.Rendering.SceneGraph;
using Avalonia.Skia;
Expand All @@ -9,7 +10,7 @@ namespace OpenQuestPDF.Previewer;
class InteractiveCanvas : ICustomDrawOperation
{
public Rect Bounds { get; set; }
public ICollection<PreviewPage> Pages { get; set; }
public ICollection<PreviewPage>? Pages { get; set; }

private float Width => (float)Bounds.Width;
private float Height => (float)Bounds.Height;
Expand All @@ -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;

Expand Down Expand Up @@ -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<ISkiaSharpApiLeaseFeature>();
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;

Expand Down
5 changes: 3 additions & 2 deletions Source/OpenQuestPDF.Previewer/OpenQuestPDF.Previewer.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Authors>LM Development</Authors>
Expand All @@ -8,7 +8,7 @@
<ToolCommandName>questpdf-previewer</ToolCommandName>
<PackageDescription>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.</PackageDescription>
<PackageReleaseNotes>Initial release.</PackageReleaseNotes>
<RepositoryUrl>https://github.com/LMDevelopment/OpenQuestPDF.git</RepositoryUrl>
<RepositoryUrl>https://github.com/LM-Development/OpenQuestPDF.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Copyright>LM IT Services AG, OpenQuestPDF contributors</Copyright>
<PackageTags>pdf report file export generate generation tool create creation render portable document format quest html library converter open source free standard core previewer</PackageTags>
Expand Down Expand Up @@ -38,6 +38,7 @@
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.6" />
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="11.3.6" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.3.6" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.6" />
<PackageReference Include="ReactiveUI" Version="21.0.1" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.119.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="3.119.0" />
Expand Down
7 changes: 4 additions & 3 deletions Source/OpenQuestPDF.Previewer/PreviewerApp.axaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Application x:Class="QuestPDF.Previewer.PreviewerApp"
<Application x:Class="OpenQuestPDF.Previewer.PreviewerApp"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="QuestPDF Document Preview">
Name="OpenQuestPDF Document Preview"
RequestedThemeVariant="Dark">
<Application.Styles>
<FluentTheme Mode="Dark" />
<FluentTheme />
</Application.Styles>
</Application>
Loading