Skip to content

Commit 1bbb270

Browse files
author
Relorer
committed
remove useless properties
1 parent 54ea564 commit 1bbb270

File tree

5 files changed

+5
-45
lines changed

5 files changed

+5
-45
lines changed

HTMLToQPDF.Example/Utilities/PDFCreator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using QuestPDF.Fluent;
33
using QuestPDF.Helpers;
44
using QuestPDF.Infrastructure;
5-
using SkiaSharp;
65

76
namespace HTMLToQPDF.Example.Utilities
87
{
@@ -29,9 +28,9 @@ public static void Create(string html, string path, bool customStyles)
2928
{
3029
handler.SetTextStyleForHtmlElement("h1", TextStyle.Default.FontColor(Colors.DeepOrange.Accent4).FontSize(32).Bold());
3130
handler.SetContainerStyleForHtmlElement("div", c => c.Background(Colors.Teal.Lighten5));
31+
handler.SetContainerStyleForHtmlElement("img", c => c.MaxHeight(7, Unit.Centimetre));
3232
handler.SetContainerStyleForHtmlElement("table", c => c.Background(Colors.Pink.Lighten5));
3333
handler.SetListVerticalPadding(40);
34-
handler.SetMaxImgHeight(7, Unit.Centimetre);
3534
}
3635
handler.SetHtml(html);
3736
});

HTMLToQPDF/Components/HTMLComponent.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ namespace HTMLToQPDF.Components
1414

1515
internal class HTMLComponent : IComponent
1616
{
17-
public float MinImgWidth { get; set; } = 0;
18-
public float MaxImgHeight { get; set; } = 0;
1917
public GetImgBySrc GetImgBySrc { get; set; } = ImgUtils.GetImgBySrc;
2018

2119
public Dictionary<string, TextStyle> TextStyles { get; } = new Dictionary<string, TextStyle>()
@@ -54,7 +52,7 @@ public void Compose(IContainer container)
5452

5553
CreateSeparateBranchesForTextNodes(node);
5654

57-
container.Component(node.GetComponent(new HTMLComponentsArgs(TextStyles, ContainerStyles, ListVerticalPadding, GetImgBySrc, MaxImgHeight, MinImgWidth)));
55+
container.Component(node.GetComponent(new HTMLComponentsArgs(TextStyles, ContainerStyles, ListVerticalPadding, GetImgBySrc)));
5856
}
5957

6058
/// <summary>

HTMLToQPDF/Components/HTMLComponentsArgs.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ internal class HTMLComponentsArgs
1010
public Dictionary<string, Func<IContainer, IContainer>> ContainerStyles { get; }
1111
public float ListVerticalPadding { get; }
1212
public GetImgBySrc GetImgBySrc { get; }
13-
public float MaxImgHeight { get; }
14-
public float MinImgWidth { get; }
1513

16-
public HTMLComponentsArgs(Dictionary<string, TextStyle> textStyles, Dictionary<string, Func<IContainer, IContainer>> containerStyles, float listVerticalPadding, GetImgBySrc getImgBySrc, float maxImgHeight, float minImgWidth)
14+
public HTMLComponentsArgs(Dictionary<string, TextStyle> textStyles, Dictionary<string, Func<IContainer, IContainer>> containerStyles, float listVerticalPadding, GetImgBySrc getImgBySrc)
1715
{
1816
TextStyles = textStyles;
1917
ContainerStyles = containerStyles;
2018
ListVerticalPadding = listVerticalPadding;
2119
GetImgBySrc = getImgBySrc;
22-
MaxImgHeight = maxImgHeight;
23-
MinImgWidth = minImgWidth;
2420
}
2521
}
2622
}

HTMLToQPDF/Components/Tags/ImgComponent.cs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,23 @@
33
using QuestPDF.Fluent;
44
using QuestPDF.Helpers;
55
using QuestPDF.Infrastructure;
6-
using SkiaSharp;
76

87
namespace HTMLQuestPDF.Components.Tags
98
{
109
internal class ImgComponent : BaseHTMLComponent
1110
{
1211
private readonly GetImgBySrc getImgBySrc;
13-
private readonly float minImgWidth;
14-
private readonly float maxImgHeight;
1512

1613
public ImgComponent(HtmlNode node, HTMLComponentsArgs args) : base(node, args)
1714
{
1815
this.getImgBySrc = args.GetImgBySrc;
19-
this.minImgWidth = args.MinImgWidth;
20-
this.maxImgHeight = args.MaxImgHeight;
2116
}
2217

2318
protected override void ComposeSingle(IContainer container)
2419
{
2520
var src = node.GetAttributeValue("src", "");
26-
var img = getImgBySrc(src);
27-
28-
var item = container.AlignCenter();
29-
if (img?.Any() ?? false)
30-
{
31-
item.Element(e =>
32-
{
33-
var image = SKImage.FromEncodedData(img);
34-
35-
if (minImgWidth == 0 && maxImgHeight != 0) return e.MaxHeight(maxImgHeight);
36-
if (minImgWidth == 0 || maxImgHeight == 0) return e;
37-
38-
var requiredHeight = image.Height * (minImgWidth / image.Width);
39-
return requiredHeight > maxImgHeight ? e.MinHeight(maxImgHeight) : e;
40-
}).Image(img, ImageScaling.FitArea);
41-
}
42-
else
43-
{
44-
item.Image(Placeholders.Image(200, 100), ImageScaling.FitArea);
45-
}
21+
var img = getImgBySrc(src) ?? Placeholders.Image(200, 100);
22+
container.AlignCenter().Image(img, ImageScaling.FitArea);
4623
}
4724
}
4825
}

HTMLToQPDF/HTMLDescriptor.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ public void OverloadImgReceivingFunc(GetImgBySrc getImg)
1818
PDFPage.GetImgBySrc = getImg;
1919
}
2020

21-
public void SetMinImgWidth(float value, Unit unit = Unit.Point)
22-
{
23-
PDFPage.MinImgWidth = UnitUtils.ToPoints(value, unit);
24-
}
25-
26-
public void SetMaxImgHeight(float value, Unit unit = Unit.Point)
27-
{
28-
PDFPage.MaxImgHeight = UnitUtils.ToPoints(value, unit);
29-
}
30-
3121
public void SetTextStyleForHtmlElement(string tagName, TextStyle style)
3222
{
3323
PDFPage.TextStyles[tagName.ToLower()] = style;

0 commit comments

Comments
 (0)