Improved default text style
This commit is contained in:
@@ -25,9 +25,10 @@ namespace QuestPDF.ReportSample.Layouts
|
||||
public void Compose(IDocumentContainer container)
|
||||
{
|
||||
container
|
||||
.DefaultTextStyle(Typography.Normal)
|
||||
.Page(page =>
|
||||
{
|
||||
page.DefaultTextStyle(Typography.Normal);
|
||||
|
||||
page.MarginVertical(40);
|
||||
page.MarginHorizontal(50);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ namespace QuestPDF.Drawing
|
||||
{
|
||||
internal class DocumentContainer : IDocumentContainer
|
||||
{
|
||||
internal TextStyle DefaultTextStyle { get; set; } = TextStyle.Default;
|
||||
internal List<IComponent> Pages { get; set; } = new List<IComponent>();
|
||||
|
||||
internal Container Compose()
|
||||
|
||||
@@ -39,7 +39,6 @@ namespace QuestPDF.Drawing
|
||||
var metadata = document.GetMetadata();
|
||||
var pageContext = new PageContext();
|
||||
|
||||
ApplyDefaultTextStyle(content, container.DefaultTextStyle);
|
||||
RenderPass(pageContext, new FreeCanvas(), content, metadata);
|
||||
RenderPass(pageContext, canvas, content, metadata);
|
||||
}
|
||||
@@ -103,7 +102,7 @@ namespace QuestPDF.Drawing
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyDefaultTextStyle(Element content, TextStyle documentDefaultTextStyle)
|
||||
internal static void ApplyDefaultTextStyle(this Element content, TextStyle documentDefaultTextStyle)
|
||||
{
|
||||
documentDefaultTextStyle.ApplyGlobalStyle(TextStyle.LibraryDefault);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using QuestPDF.Drawing;
|
||||
using QuestPDF.Fluent;
|
||||
using QuestPDF.Helpers;
|
||||
using QuestPDF.Infrastructure;
|
||||
@@ -7,6 +8,8 @@ namespace QuestPDF.Elements
|
||||
{
|
||||
internal class Page : IComponent
|
||||
{
|
||||
public TextStyle DefaultTextStyle { get; set; } = new TextStyle();
|
||||
|
||||
public Size MinSize { get; set; } = PageSizes.A4;
|
||||
public Size MaxSize { get; set; } = PageSizes.A4;
|
||||
|
||||
@@ -15,6 +18,8 @@ namespace QuestPDF.Elements
|
||||
public float MarginTop { get; set; }
|
||||
public float MarginBottom { get; set; }
|
||||
|
||||
public string BackgroundColor { get; set; } = Colors.Transparent;
|
||||
|
||||
public Element Header { get; set; } = Empty.Instance;
|
||||
public Element Content { get; set; } = Empty.Instance;
|
||||
public Element Footer { get; set; } = Empty.Instance;
|
||||
@@ -22,12 +27,13 @@ namespace QuestPDF.Elements
|
||||
public void Compose(IContainer container)
|
||||
{
|
||||
container
|
||||
|
||||
.MinWidth(MinSize.Width)
|
||||
.MinHeight(MinSize.Height)
|
||||
|
||||
.MaxWidth(MaxSize.Width)
|
||||
.MaxHeight(MaxSize.Height)
|
||||
|
||||
.Background(BackgroundColor)
|
||||
|
||||
.PaddingLeft(MarginLeft)
|
||||
.PaddingRight(MarginRight)
|
||||
@@ -47,6 +53,8 @@ namespace QuestPDF.Elements
|
||||
decoration.Footer().Element(Footer);
|
||||
});
|
||||
|
||||
(container as Element).ApplyDefaultTextStyle(DefaultTextStyle);
|
||||
|
||||
bool IsClose(float x, float y)
|
||||
{
|
||||
return Math.Abs(x - y) < Size.Epsilon;
|
||||
|
||||
@@ -70,6 +70,16 @@ namespace QuestPDF.Fluent
|
||||
MarginHorizontal(value);
|
||||
}
|
||||
|
||||
public void DefaultTextStyle(TextStyle textStyle)
|
||||
{
|
||||
Page.DefaultTextStyle = textStyle;
|
||||
}
|
||||
|
||||
public void Background(string color)
|
||||
{
|
||||
Page.BackgroundColor = color;
|
||||
}
|
||||
|
||||
public IContainer Header()
|
||||
{
|
||||
var container = new Container();
|
||||
@@ -94,12 +104,6 @@ namespace QuestPDF.Fluent
|
||||
|
||||
public static class PageExtensions
|
||||
{
|
||||
public static IDocumentContainer DefaultTextStyle(this IDocumentContainer document, TextStyle textStyle)
|
||||
{
|
||||
(document as DocumentContainer).DefaultTextStyle = textStyle;
|
||||
return document;
|
||||
}
|
||||
|
||||
public static IDocumentContainer Page(this IDocumentContainer document, Action<PageDescriptor> handler)
|
||||
{
|
||||
var descriptor = new PageDescriptor();
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace QuestPDF.Helpers
|
||||
{
|
||||
public static class Placeholders
|
||||
{
|
||||
private static Random Random = new Random();
|
||||
public static readonly Random Random = new Random();
|
||||
|
||||
#region Word Cache
|
||||
|
||||
|
||||
Reference in New Issue
Block a user