Skip to content

Commit b23b1c4

Browse files
committed
Implement basic version of grid track sizing algroithm
DEVSIX-8324
1 parent 67c625b commit b23b1c4

File tree

154 files changed

+1685
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+1685
-49
lines changed

src/main/java/com/itextpdf/html2pdf/css/apply/util/GridApplierUtil.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ This file is part of the iText (R) project.
2929
import com.itextpdf.layout.properties.GridFlow;
3030
import com.itextpdf.layout.properties.GridValue;
3131
import com.itextpdf.layout.properties.Property;
32-
import com.itextpdf.layout.properties.SizingValue;
3332
import com.itextpdf.layout.properties.UnitValue;
3433
import com.itextpdf.styledxmlparser.css.CommonCssConstants;
3534
import com.itextpdf.styledxmlparser.css.util.CssDimensionParsingUtils;
@@ -187,9 +186,7 @@ public static void applyGridContainerProperties(Map<String, String> cssProps, IP
187186
private static void applyAuto(String autoStr, IPropertyContainer container, int property, float emValue, float remValue) {
188187
if (autoStr != null) {
189188
GridValue value = getGridValue(autoStr, emValue, remValue);
190-
// TODO DEVSIX-8324 - we support only absolute values for now
191-
// If some relative values are not supported after DEVSIX-8324, add the corresponding warning message
192-
if (value != null && value.isAbsoluteValue()) {
189+
if (value != null) {
193190
container.setProperty(property, value);
194191
}
195192
}
@@ -217,9 +214,7 @@ private static void applyTemplate(String templateStr, IPropertyContainer contain
217214
final List<GridValue> templateResult = new ArrayList<>();
218215
for (String str : templateStrArray) {
219216
GridValue value = getGridValue(str, emValue, remValue);
220-
// TODO DEVSIX-8324 - we support only absolute values for now
221-
// If some relative values are not supported after DEVSIX-8324, add the corresponding warning message
222-
if (value != null && value.isAbsoluteValue()) {
217+
if (value != null) {
223218
templateResult.add(value);
224219
}
225220
}
@@ -232,20 +227,23 @@ private static void applyTemplate(String templateStr, IPropertyContainer contain
232227
private static GridValue getGridValue(String str, float emValue, float remValue) {
233228
final UnitValue unit = CssDimensionParsingUtils.parseLengthValueToPt(str, emValue, remValue);
234229
if (unit != null) {
235-
return GridValue.createUnitValue(unit);
230+
if (unit.isPointValue()) {
231+
return GridValue.createPointValue(unit.getValue());
232+
} else {
233+
return GridValue.createPercentValue(unit.getValue());
234+
}
236235
} else if (CommonCssConstants.MIN_CONTENT.equals(str)) {
237-
return GridValue.createSizeValue(SizingValue.createMinContentValue());
236+
return GridValue.createMinContentValue();
238237
} else if (CommonCssConstants.MAX_CONTENT.equals(str)) {
239-
return GridValue.createSizeValue(SizingValue.createMaxContentValue());
238+
return GridValue.createMaxContentValue();
240239
} else if (CommonCssConstants.AUTO.equals(str)) {
241-
return GridValue.createSizeValue(SizingValue.createAutoValue());
240+
return GridValue.createAutoValue();
242241
}
243242
final Float fr = CssDimensionParsingUtils.parseFlex(str);
244243
if (fr != null) {
245244
return GridValue.createFlexValue((float) fr);
246245
}
247246

248-
// TODO DEVSIX-8324 - add a warning for the values we do not support yet
249247
return null;
250248
}
251249

src/test/java/com/itextpdf/html2pdf/css/apply/util/GridApplierUtilTest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ public void containerAutoValuesTest() {
323323
cssProps.put(CssConstants.GRID_AUTO_ROWS, "30%");
324324
IElement element = new Div();
325325
GridApplierUtil.applyGridContainerProperties(cssProps, element, new ProcessorContext(new ConverterProperties()));
326-
Assertions.assertEquals(8.25, element.<GridValue>getProperty(Property.GRID_AUTO_COLUMNS).getAbsoluteValue(), 0.00001);
327-
Assertions.assertNull(element.<GridValue>getProperty(Property.GRID_AUTO_ROWS));
326+
Assertions.assertEquals(8.25, element.<GridValue>getProperty(Property.GRID_AUTO_COLUMNS).getValue(), 0.00001);
327+
Assertions.assertEquals(30, element.<GridValue>getProperty(Property.GRID_AUTO_ROWS).getValue());
328328
}
329329

330330
@Test
@@ -335,14 +335,19 @@ public void containerTemplateValuesTest() {
335335
IElement element = new Div();
336336
GridApplierUtil.applyGridContainerProperties(cssProps, element, new ProcessorContext(new ConverterProperties()));
337337
List<GridValue> actualColValues = element.<List<GridValue>>getProperty(Property.GRID_TEMPLATE_COLUMNS);
338-
Assertions.assertEquals(1, actualColValues.size());
339-
Assertions.assertEquals(75, actualColValues.get(0).getAbsoluteValue());
338+
Assertions.assertEquals(6, actualColValues.size());
339+
Assertions.assertTrue(actualColValues.get(0).isMinContentValue());
340+
Assertions.assertTrue(actualColValues.get(1).isFlexibleValue());
341+
Assertions.assertTrue(actualColValues.get(2).isAutoValue());
342+
Assertions.assertTrue(actualColValues.get(3).isFlexibleValue());
343+
Assertions.assertEquals(75, actualColValues.get(4).getValue());
344+
Assertions.assertEquals(20, actualColValues.get(5).getValue());
340345
List<GridValue> actualRowValues = element.<List<GridValue>>getProperty(Property.GRID_TEMPLATE_ROWS);
341346
Assertions.assertEquals(4, actualRowValues.size());
342-
Assertions.assertEquals(7.5f, actualRowValues.get(0).getAbsoluteValue());
343-
Assertions.assertEquals(20, actualRowValues.get(1).getAbsoluteValue());
344-
Assertions.assertEquals(0, actualRowValues.get(2).getAbsoluteValue());
345-
Assertions.assertEquals(60, actualRowValues.get(3).getAbsoluteValue());
347+
Assertions.assertEquals(7.5f, actualRowValues.get(0).getValue());
348+
Assertions.assertEquals(20, actualRowValues.get(1).getValue());
349+
Assertions.assertEquals(0, actualRowValues.get(2).getValue());
350+
Assertions.assertEquals(60, actualRowValues.get(3).getValue());
346351
}
347352

348353
@Test

src/test/java/com/itextpdf/html2pdf/css/grid/GridRelativeValuesTest.java

Lines changed: 222 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,228 @@ public static void beforeClass() {
4141
}
4242

4343
@Test
44-
public void allRelativeSingleValuesTest() throws IOException, InterruptedException {
45-
runTest("allRelativeSingleValues");
44+
public void bothAxis1Test() throws IOException, InterruptedException {
45+
runTest("bothAxis1");
46+
}
47+
48+
@Test
49+
public void bothAxis2Test() throws IOException, InterruptedException {
50+
runTest("bothAxis2");
51+
}
52+
53+
@Test
54+
public void bothAxis3Test() throws IOException, InterruptedException {
55+
runTest("bothAxis3");
56+
}
57+
58+
@Test
59+
public void bothAxis4Test() throws IOException, InterruptedException {
60+
runTest("bothAxis4");
61+
}
62+
63+
@Test
64+
public void bothAxis5Test() throws IOException, InterruptedException {
65+
runTest("bothAxis5");
66+
}
67+
68+
@Test
69+
public void bothAxis6Test() throws IOException, InterruptedException {
70+
runTest("bothAxis6");
71+
}
72+
73+
@Test
74+
public void bothAxis7Test() throws IOException, InterruptedException {
75+
runTest("bothAxis7");
76+
}
77+
78+
@Test
79+
public void bothAxis8Test() throws IOException, InterruptedException {
80+
runTest("bothAxis8");
81+
}
82+
83+
@Test
84+
public void bothAxis9Test() throws IOException, InterruptedException {
85+
runTest("bothAxis9");
86+
}
87+
88+
@Test
89+
public void bothAxis10Test() throws IOException, InterruptedException {
90+
runTest("bothAxis10");
91+
}
92+
93+
@Test
94+
public void bothAxis11Test() throws IOException, InterruptedException {
95+
runTest("bothAxis11");
96+
}
97+
98+
@Test
99+
public void bothAxis12Test() throws IOException, InterruptedException {
100+
runTest("bothAxis12");
101+
}
102+
103+
@Test
104+
public void bothAxis13Test() throws IOException, InterruptedException {
105+
runTest("bothAxis13");
106+
}
107+
108+
@Test
109+
public void bothAxis14Test() throws IOException, InterruptedException {
110+
runTest("bothAxis14");
111+
}
112+
113+
@Test
114+
public void bothAxis15Test() throws IOException, InterruptedException {
115+
runTest("bothAxis15");
116+
}
117+
118+
@Test
119+
public void bothAxis16Test() throws IOException, InterruptedException {
120+
runTest("bothAxis16");
121+
}
122+
123+
@Test
124+
public void bothAxis17Test() throws IOException, InterruptedException {
125+
runTest("bothAxis17");
126+
}
127+
128+
@Test
129+
public void bothAxis18Test() throws IOException, InterruptedException {
130+
runTest("bothAxis18");
131+
}
132+
133+
@Test
134+
public void bothAxis19Test() throws IOException, InterruptedException {
135+
runTest("bothAxis19");
136+
}
137+
138+
@Test
139+
public void bothAxis20Test() throws IOException, InterruptedException {
140+
runTest("bothAxis20");
141+
}
142+
143+
@Test
144+
public void bothAxis21Test() throws IOException, InterruptedException {
145+
runTest("bothAxis21");
146+
}
147+
148+
@Test
149+
public void bothAxisOnlyFr1Test() throws IOException, InterruptedException {
150+
runTest("bothAxisOnlyFr1");
151+
}
152+
153+
@Test
154+
public void bothAxisOnlyFr2Test() throws IOException, InterruptedException {
155+
runTest("bothAxisOnlyFr2");
156+
}
157+
158+
@Test
159+
public void bothAxisOnlyFr3Test() throws IOException, InterruptedException {
160+
runTest("bothAxisOnlyFr3");
161+
}
162+
163+
@Test
164+
public void bothAxisOnlyFr4Test() throws IOException, InterruptedException {
165+
runTest("bothAxisOnlyFr4");
166+
}
167+
168+
@Test
169+
public void bothAxisOnlyFr5Test() throws IOException, InterruptedException {
170+
runTest("bothAxisOnlyFr5");
171+
}
172+
173+
@Test
174+
public void bothAxisOnlyFr6Test() throws IOException, InterruptedException {
175+
runTest("bothAxisOnlyFr6");
176+
}
177+
178+
@Test
179+
public void colAxis1Test() throws IOException, InterruptedException {
180+
runTest("colAxis1");
181+
}
182+
183+
@Test
184+
public void colAxis2Test() throws IOException, InterruptedException {
185+
runTest("colAxis2");
186+
}
187+
188+
@Test
189+
public void colAxis3Test() throws IOException, InterruptedException {
190+
runTest("colAxis3");
191+
}
192+
193+
@Test
194+
public void colAxis4Test() throws IOException, InterruptedException {
195+
runTest("colAxis4");
196+
}
197+
198+
@Test
199+
public void colAxis5Test() throws IOException, InterruptedException {
200+
runTest("colAxis5");
201+
}
202+
203+
@Test
204+
public void colAxis6Test() throws IOException, InterruptedException {
205+
runTest("colAxis6");
206+
}
207+
208+
@Test
209+
public void colAxis7Test() throws IOException, InterruptedException {
210+
runTest("colAxis7");
211+
}
212+
213+
@Test
214+
public void colAxis8Test() throws IOException, InterruptedException {
215+
runTest("colAxis8");
216+
}
217+
218+
@Test
219+
public void colAxis9Test() throws IOException, InterruptedException {
220+
runTest("colAxis9");
221+
}
222+
223+
@Test
224+
public void colAxis10Test() throws IOException, InterruptedException {
225+
runTest("colAxis10");
226+
}
227+
228+
@Test
229+
public void colAxis11Test() throws IOException, InterruptedException {
230+
runTest("colAxis11");
231+
}
232+
233+
@Test
234+
public void rowAxis1Test() throws IOException, InterruptedException {
235+
runTest("rowAxis1");
236+
}
237+
238+
@Test
239+
public void rowAxis2Test() throws IOException, InterruptedException {
240+
runTest("rowAxis2");
241+
}
242+
243+
@Test
244+
public void rowAxis3Test() throws IOException, InterruptedException {
245+
runTest("rowAxis3");
246+
}
247+
248+
@Test
249+
public void rowAxis4Test() throws IOException, InterruptedException {
250+
runTest("rowAxis4");
251+
}
252+
253+
@Test
254+
public void rowAxis5Test() throws IOException, InterruptedException {
255+
runTest("rowAxis5");
256+
}
257+
258+
@Test
259+
public void rowAxis6Test() throws IOException, InterruptedException {
260+
runTest("rowAxis6");
261+
}
262+
263+
@Test
264+
public void rowAxis7Test() throws IOException, InterruptedException {
265+
runTest("rowAxis7");
46266
}
47267

48268
private void runTest(String testName) throws IOException, InterruptedException {

0 commit comments

Comments
 (0)