Skip to content

Commit fda3fa2

Browse files
Samuel Huylebroeckpavel-alay
authored andcommitted
Move inner classes out
DEVSIX-1050 Autoported commit. Original commit hash: [63adb0d1]
1 parent 26c8479 commit fda3fa2

File tree

6 files changed

+199
-190
lines changed

6 files changed

+199
-190
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using iText.Html2pdf.Css;
3+
using iText.Html2pdf.Css.Apply.Util;
4+
using iText.Layout.Properties;
5+
using iText.StyledXmlParser.Css;
6+
using iText.StyledXmlParser.Css.Util;
7+
8+
namespace iText.Html2pdf.Attach.Impl.Layout {
9+
/// <summary>Container class for grouping necessary values used in dimension calculation</summary>
10+
public abstract class DimensionContainer {
11+
internal float dimension;
12+
13+
internal float minDimension;
14+
15+
internal float maxDimension;
16+
17+
internal float minContentDimension;
18+
19+
internal float maxContentDimension;
20+
21+
internal DimensionContainer() {
22+
dimension = -1;
23+
minDimension = 0;
24+
minContentDimension = 0;
25+
maxDimension = float.MaxValue;
26+
maxContentDimension = float.MaxValue;
27+
}
28+
29+
/// <summary>Check if this dimension is auto</summary>
30+
/// <returns>True if the dimension is to be automatically calculated, false if it was set via a property</returns>
31+
internal virtual bool IsAutoDimension() {
32+
return dimension == -1;
33+
}
34+
35+
internal virtual float ParseDimension(CssContextNode node, String content, float maxAvailableDimension) {
36+
float fontsize = FontStyleApplierUtil.ParseAbsoluteFontSize(node.GetStyles().Get(CssConstants.FONT_SIZE));
37+
UnitValue unitValue = CssUtils.ParseLengthValueToPt(content, fontsize, 0);
38+
if (unitValue == null) {
39+
return 0;
40+
}
41+
if (unitValue.IsPointValue()) {
42+
return unitValue.GetValue();
43+
}
44+
return maxAvailableDimension * unitValue.GetValue() / 100f;
45+
}
46+
}
47+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using iText.Html2pdf.Attach;
3+
using iText.Html2pdf.Css;
4+
using iText.StyledXmlParser.Css;
5+
using iText.StyledXmlParser.Css.Page;
6+
7+
namespace iText.Html2pdf.Attach.Impl.Layout {
8+
public class HeightDimensionContainer : DimensionContainer {
9+
internal HeightDimensionContainer(CssContextNode pmbcNode, float width, float maxHeight, ProcessorContext
10+
context) {
11+
String height = pmbcNode.GetStyles().Get(CssConstants.HEIGHT);
12+
if (height != null && !height.Equals("auto")) {
13+
dimension = ParseDimension(pmbcNode, height, maxHeight);
14+
}
15+
minDimension = GetMinHeight(pmbcNode, maxHeight);
16+
maxDimension = GetMaxHeight(pmbcNode, maxHeight);
17+
minContentDimension = PageContextProcessor.GetMinContentHeight((PageMarginBoxContextNode)pmbcNode, width,
18+
maxHeight, context);
19+
maxContentDimension = PageContextProcessor.GetMaxContentHeight((PageMarginBoxContextNode)pmbcNode, width,
20+
maxHeight, context);
21+
}
22+
23+
internal virtual float GetMinHeight(CssContextNode node, float maxAvailableHeight) {
24+
String content = node.GetStyles().Get(CssConstants.MIN_HEIGHT);
25+
if (content == null) {
26+
return 0;
27+
}
28+
content = content.ToLowerInvariant().Trim();
29+
if (content.Equals("inherit")) {
30+
if (node.ParentNode() is CssContextNode) {
31+
return GetMinHeight((CssContextNode)node.ParentNode(), maxAvailableHeight);
32+
}
33+
return 0;
34+
}
35+
return ParseDimension(node, content, maxAvailableHeight);
36+
}
37+
38+
internal virtual float GetMaxHeight(CssContextNode node, float maxAvailableHeight) {
39+
String content = node.GetStyles().Get(CssConstants.MAX_HEIGHT);
40+
if (content == null) {
41+
return float.MaxValue;
42+
}
43+
content = content.ToLowerInvariant().Trim();
44+
if (content.Equals("inherit")) {
45+
if (node.ParentNode() is CssContextNode) {
46+
return GetMaxHeight((CssContextNode)node.ParentNode(), maxAvailableHeight);
47+
}
48+
return float.MaxValue;
49+
}
50+
float dim = ParseDimension(node, content, maxAvailableHeight);
51+
if (dim == 0) {
52+
return float.MaxValue;
53+
}
54+
return dim;
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)