diff --git a/QuestPDF.ReportSample/DataSource.cs b/QuestPDF.ReportSample/DataSource.cs index 1b278c2..062cea3 100644 --- a/QuestPDF.ReportSample/DataSource.cs +++ b/QuestPDF.ReportSample/DataSource.cs @@ -7,9 +7,6 @@ namespace QuestPDF.ReportSample { public static class DataSource { - public static int SectionCounter { get; set; } - public static int FieldCounter { get; set; } - public static ReportModel GetReport() { return new ReportModel diff --git a/QuestPDF.ReportSample/Tests.cs b/QuestPDF.ReportSample/Tests.cs index 08b9995..089ad2e 100644 --- a/QuestPDF.ReportSample/Tests.cs +++ b/QuestPDF.ReportSample/Tests.cs @@ -57,8 +57,8 @@ namespace QuestPDF.ReportSample Console.WriteLine($"Time per document: {performance:N} ms"); Console.WriteLine($"Documents per second: {speed:N} d/s"); - //if (speed < performanceTarget) - // throw new Exception("Rendering algorithm is too slow."); + if (speed < performanceTarget) + throw new Exception("Rendering algorithm is too slow."); } } } \ No newline at end of file diff --git a/QuestPDF/Elements/Constrained.cs b/QuestPDF/Elements/Constrained.cs index d18def5..8a58ff2 100644 --- a/QuestPDF/Elements/Constrained.cs +++ b/QuestPDF/Elements/Constrained.cs @@ -22,8 +22,8 @@ namespace QuestPDF.Elements return new Wrap(); var available = new Size( - MathHelpers.Min(MaxWidth, availableSpace.Width), - MathHelpers.Min(MaxHeight, availableSpace.Height)); + Min(MaxWidth, availableSpace.Width), + Min(MaxHeight, availableSpace.Height)); var measurement = Child?.Measure(available) ?? new FullRender(Size.Zero); var size = measurement as Size; @@ -32,8 +32,8 @@ namespace QuestPDF.Elements return new Wrap(); var actualSize = new Size( - MathHelpers.Max(MinWidth, size.Width), - MathHelpers.Max(MinHeight, size.Height)); + Max(MinWidth, size.Width), + Max(MinHeight, size.Height)); if (size is FullRender) return new FullRender(actualSize); @@ -47,23 +47,20 @@ namespace QuestPDF.Elements internal override void Draw(Size availableSpace) { var available = new Size( - MathHelpers.Min(MaxWidth, availableSpace.Width), - MathHelpers.Min(MaxHeight, availableSpace.Height)); + Min(MaxWidth, availableSpace.Width), + Min(MaxHeight, availableSpace.Height)); Child?.Draw(available); } - } - - static class MathHelpers - { - public static float Min(params float?[] values) + + private static float Min(float? x, float y) { - return values.Where(x => x.HasValue).Min().Value; + return x.HasValue ? Math.Min(x.Value, y) : y; } - public static float Max(params float?[] values) + private static float Max(float? x, float y) { - return values.Where(x => x.HasValue).Max().Value; + return x.HasValue ? Math.Max(x.Value, y) : y; } } } \ No newline at end of file diff --git a/QuestPDF/Infrastructure/Position.cs b/QuestPDF/Infrastructure/Position.cs index f71dd38..358c602 100644 --- a/QuestPDF/Infrastructure/Position.cs +++ b/QuestPDF/Infrastructure/Position.cs @@ -2,10 +2,10 @@ { internal class Position { - public float X { get; set; } - public float Y { get; set; } + public float X { get; } + public float Y { get; } - public static Position Zero => new Position(0, 0); + public static Position Zero { get; } = new Position(0, 0); public Position(float x, float y) { diff --git a/QuestPDF/Infrastructure/Size.cs b/QuestPDF/Infrastructure/Size.cs index 196d58e..5ccceac 100644 --- a/QuestPDF/Infrastructure/Size.cs +++ b/QuestPDF/Infrastructure/Size.cs @@ -7,8 +7,8 @@ public float Width { get; } public float Height { get; } - public static Size Zero => new Size(0, 0); - public static Size Max => new Size(14_400, 14_400); + public static Size Zero { get; } = new Size(0, 0); + public static Size Max { get; } = new Size(14_400, 14_400); public Size(float width, float height) { @@ -17,26 +17,5 @@ } public override string ToString() => $"(W: {Width}, H: {Height})"; - - protected bool Equals(Size other) - { - return Width.Equals(other.Width) && Height.Equals(other.Height); - } - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; - return Equals((Size) obj); - } - - public override int GetHashCode() - { - unchecked - { - return (Width.GetHashCode() * 397) ^ Height.GetHashCode(); - } - } } } \ No newline at end of file diff --git a/QuestPDF/Infrastructure/TextStyle.cs b/QuestPDF/Infrastructure/TextStyle.cs index 545d7db..640d9d2 100644 --- a/QuestPDF/Infrastructure/TextStyle.cs +++ b/QuestPDF/Infrastructure/TextStyle.cs @@ -32,9 +32,8 @@ namespace QuestPDF.Infrastructure HasUnderline = false }; - private static TextStyle DefaultTextStyleCache = new TextStyle(); - public static TextStyle Default => DefaultTextStyleCache; - + public static TextStyle Default => new TextStyle(); + internal void ApplyGlobalStyle(TextStyle globalStyle) { if (HasGlobalStyleApplied) @@ -43,7 +42,6 @@ namespace QuestPDF.Infrastructure HasGlobalStyleApplied = true; ApplyParentStyle(globalStyle); - Key ??= $"{Color}|{BackgroundColor}|{FontType}|{Size}|{LineHeight}|{FontWeight}|{IsItalic}|{HasStrikethrough}|{HasUnderline}"; }