Code refactorization
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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}";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user