Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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/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
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
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
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
4 changes: 2 additions & 2 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
57 changes: 29 additions & 28 deletions Source/OpenQuestPDF.UnitTests/TestEngine/TestPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text.Json;
using FluentAssertions;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using OpenQuestPDF.Drawing;
using OpenQuestPDF.Elements;
using OpenQuestPDF.Helpers;
Expand Down Expand Up @@ -42,7 +43,7 @@ private T GetExpected<T>() where T : OperationBase
return result;

var gotType = value?.GetType()?.Name ?? "null";
Assert.Fail($"Expected: {typeof(T).Name}, got {gotType}: {JsonSerializer.Serialize(value)}");
ClassicAssert.Fail($"Expected: {typeof(T).Name}, got {gotType}: {JsonSerializer.Serialize(value)}");
return null;
}

Expand All @@ -54,43 +55,43 @@ private ICanvas CreateCanvas()
{
var expected = GetExpected<CanvasTranslateOperation>();

Assert.AreEqual(expected.Position.X, position.X, "Translate X");
Assert.AreEqual(expected.Position.Y, position.Y, "Translate Y");
ClassicAssert.AreEqual(expected.Position.X, position.X, "Translate X");
ClassicAssert.AreEqual(expected.Position.Y, position.Y, "Translate Y");
},
RotateFunc = angle =>
{
var expected = GetExpected<CanvasRotateOperation>();

Assert.AreEqual(expected.Angle, angle, "Rotate angle");
ClassicAssert.AreEqual(expected.Angle, angle, "Rotate angle");
},
ScaleFunc = (scaleX, scaleY) =>
{
var expected = GetExpected<CanvasScaleOperation>();

Assert.AreEqual(expected.ScaleX, scaleX, "Scale X");
Assert.AreEqual(expected.ScaleY, scaleY, "Scale Y");
ClassicAssert.AreEqual(expected.ScaleX, scaleX, "Scale X");
ClassicAssert.AreEqual(expected.ScaleY, scaleY, "Scale Y");
},
DrawRectFunc = (position, size, color) =>
{
var expected = GetExpected<CanvasDrawRectangleOperation>();

Assert.AreEqual(expected.Position.X, position.X, "Draw rectangle: X");
Assert.AreEqual(expected.Position.Y, position.Y, "Draw rectangle: Y");
ClassicAssert.AreEqual(expected.Position.X, position.X, "Draw rectangle: X");
ClassicAssert.AreEqual(expected.Position.Y, position.Y, "Draw rectangle: Y");

Assert.AreEqual(expected.Size.Width, size.Width, "Draw rectangle: width");
Assert.AreEqual(expected.Size.Height, size.Height, "Draw rectangle: height");
ClassicAssert.AreEqual(expected.Size.Width, size.Width, "Draw rectangle: width");
ClassicAssert.AreEqual(expected.Size.Height, size.Height, "Draw rectangle: height");

Assert.AreEqual(expected.Color, color, "Draw rectangle: color");
ClassicAssert.AreEqual(expected.Color, color, "Draw rectangle: color");
},
DrawImageFunc = (image, position, size) =>
{
var expected = GetExpected<CanvasDrawImageOperation>();

Assert.AreEqual(expected.Position.X, position.X, "Draw image: X");
Assert.AreEqual(expected.Position.Y, position.Y, "Draw image: Y");
ClassicAssert.AreEqual(expected.Position.X, position.X, "Draw image: X");
ClassicAssert.AreEqual(expected.Position.Y, position.Y, "Draw image: Y");

Assert.AreEqual(expected.Size.Width, size.Width, "Draw image: width");
Assert.AreEqual(expected.Size.Height, size.Height, "Draw image: height");
ClassicAssert.AreEqual(expected.Size.Width, size.Width, "Draw image: width");
ClassicAssert.AreEqual(expected.Size.Height, size.Height, "Draw image: height");
}
};
}
Expand All @@ -106,21 +107,21 @@ public Element CreateChild(string id)
{
var expected = GetExpected<ChildMeasureOperation>();

Assert.AreEqual(expected.ChildId, id);
ClassicAssert.AreEqual(expected.ChildId, id);

Assert.AreEqual(expected.Input.Width, availableSpace.Width, $"Measure: width of child '{expected.ChildId}'");
Assert.AreEqual(expected.Input.Height, availableSpace.Height, $"Measure: height of child '{expected.ChildId}'");
ClassicAssert.AreEqual(expected.Input.Width, availableSpace.Width, $"Measure: width of child '{expected.ChildId}'");
ClassicAssert.AreEqual(expected.Input.Height, availableSpace.Height, $"Measure: height of child '{expected.ChildId}'");

return expected.Output;
},
DrawFunc = availableSpace =>
{
var expected = GetExpected<ChildDrawOperation>();

Assert.AreEqual(expected.ChildId, id);
ClassicAssert.AreEqual(expected.ChildId, id);

Assert.AreEqual(expected.Input.Width, availableSpace.Width, $"Draw: width of child '{expected.ChildId}'");
Assert.AreEqual(expected.Input.Height, availableSpace.Height, $"Draw: width of child '{expected.ChildId}'");
ClassicAssert.AreEqual(expected.Input.Width, availableSpace.Width, $"Draw: width of child '{expected.ChildId}'");
ClassicAssert.AreEqual(expected.Input.Height, availableSpace.Height, $"Draw: width of child '{expected.ChildId}'");
}
};
}
Expand Down Expand Up @@ -199,11 +200,11 @@ public TestPlan CheckMeasureResult(SpacePlan expected)

var actual = Element.Measure(OperationInput);

Assert.AreEqual(expected.GetType(), actual.GetType());
ClassicAssert.AreEqual(expected.GetType(), actual.GetType());

Assert.AreEqual(expected.Width, actual.Width, "Measure: width");
Assert.AreEqual(expected.Height, actual.Height, "Measure: height");
Assert.AreEqual(expected.Type, actual.Type, "Measure: height");
ClassicAssert.AreEqual(expected.Width, actual.Width, "Measure: width");
ClassicAssert.AreEqual(expected.Height, actual.Height, "Measure: height");
ClassicAssert.AreEqual(expected.Type, actual.Type, "Measure: height");

return this;
}
Expand All @@ -217,14 +218,14 @@ public TestPlan CheckDrawResult()

public TestPlan CheckState(Func<Element, bool> condition)
{
Assert.IsTrue(condition(Element), "Checking condition");
ClassicAssert.IsTrue(condition(Element), "Checking condition");
return this;
}

public TestPlan CheckState<T>(Func<T, bool> condition) where T : Element
{
Assert.IsTrue(Element is T);
Assert.IsTrue(condition(Element as T), "Checking condition");
ClassicAssert.IsTrue(Element is T);
ClassicAssert.IsTrue(condition(Element as T), "Checking condition");
return this;
}

Expand Down
11 changes: 3 additions & 8 deletions Source/OpenQuestPDF.UnitTests/TestsBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions;
using FluentAssertions.Equivalency;
using NUnit.Framework;

namespace OpenQuestPDF.UnitTests
Expand All @@ -9,14 +10,8 @@ public class TestsBase
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
AssertionOptions.AssertEquivalencyUsing(options => options
.IncludingNestedObjects()
.IncludingInternalProperties()
.IncludingInternalFields()
.AllowingInfiniteRecursion()
.RespectingRuntimeTypes()
.WithTracing()
.WithStrictOrdering());
// FluentAssertions configuration removed as the API has changed in newer versions
// The default configuration should be sufficient for our test needs
}
}
}
7 changes: 6 additions & 1 deletion Source/OpenQuestPDF.UnitTests/TextStyleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public void ApplyInheritedAndGlobalStyle()
}
};

targetStyle.Should().BeEquivalentTo(expectedStyle);
targetStyle.Should().BeEquivalentTo(expectedStyle, options => options
.IncludingNestedObjects()
.IncludingInternalProperties()
.IncludingInternalFields()
.AllowingInfiniteRecursion()
.WithStrictOrdering());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace OpenQuestPDF.Elements.Text.Calculation
{
internal class TextDrawingRequest
{
public ICanvas Canvas { get; set; }
public IPageContext PageContext { get; set; }
public ICanvas Canvas { get; set; } = null!;
public IPageContext PageContext { get; set; } = null!;

public int StartIndex { get; set; }
public int EndIndex { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace OpenQuestPDF.Elements.Text.Calculation
{
internal class TextMeasurementRequest
{
public ICanvas Canvas { get; set; }
public IPageContext PageContext { get; set; }
public ICanvas Canvas { get; set; } = null!;
public IPageContext PageContext { get; set; } = null!;

public int StartIndex { get; set; }
public float AvailableWidth { get; set; }
Expand Down
24 changes: 5 additions & 19 deletions Source/OpenQuestPDF/Fluent/TextStyleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ namespace OpenQuestPDF.Fluent
{
public static class TextStyleExtensions
{
[Obsolete("This element has been renamed since version 2022.3. Please use the FontColor method.")]
public static TextStyle Color(this TextStyle style, string value)
{
return style.FontColor(value);
}

public static TextStyle FontColor(this TextStyle style, string value)
{
ColorValidator.Validate(value);
Expand All @@ -25,25 +19,17 @@ public static TextStyle BackgroundColor(this TextStyle style, string value)
return style.Mutate(TextStyleProperty.BackgroundColor, value);
}

[Obsolete("This element has been renamed since version 2022.3. Please use the FontFamily method.")]
public static TextStyle FontType(this TextStyle style, string value)
{
return style.FontFamily(value);
}

public static TextStyle FontFamily(this TextStyle style, string value)
{
return style.Mutate(TextStyleProperty.FontFamily, value);
}

[Obsolete("This element has been renamed since version 2022.3. Please use the FontSize method.")]
public static TextStyle Size(this TextStyle style, float value)
{
return style.FontSize(value);
}

/// <include file='../Resources/Documentation.xml' path='documentation/doc[@for=\"text.fontSize\"]/*' />
public static TextStyle FontSize(this TextStyle style, float value)
{
if (value <= 0)
throw new ArgumentException("Font size must be greater than 0.");

return style.Mutate(TextStyleProperty.Size, value);
}

Expand Down Expand Up @@ -169,7 +155,7 @@ private static TextStyle Position(this TextStyle style, FontPosition fontPositio

public static TextStyle Fallback(this TextStyle style, TextStyle? value = null)
{
return style.Mutate(TextStyleProperty.Fallback, value);
return style.Mutate(TextStyleProperty.Fallback, value ?? TextStyle.Default);
}

public static TextStyle Fallback(this TextStyle style, Func<TextStyle, TextStyle> handler)
Expand Down
4 changes: 2 additions & 2 deletions Source/OpenQuestPDF/Infrastructure/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace OpenQuestPDF.Infrastructure
{
internal abstract class Element : IElement
{
internal IPageContext PageContext { get; set; }
internal ICanvas Canvas { get; set; }
internal IPageContext PageContext { get; set; } = null!;
internal ICanvas Canvas { get; set; } = null!;

internal virtual IEnumerable<Element?> GetChildren()
{
Expand Down
Loading