Skip to content

Commit 1f97711

Browse files
author
Dmitry Radchuk
committed
Add repeat, fit-content support
DEVSIX-8383
1 parent b6139dd commit 1f97711

32 files changed

+1599
-697
lines changed

layout/src/main/java/com/itextpdf/layout/exceptions/LayoutExceptionMessageConstant.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public final class LayoutExceptionMessageConstant {
5757
"Invalid grid-column/grid-row properties, cells overlapping";
5858
public static final String INVALID_FONT_PROPERTY_VALUE = "Invalid FONT property value type.";
5959
public static final String TAGGING_HINTKEY_SHOULD_HAVE_ACCES = "TaggingHintKey should have accessibility properties" ;
60+
public static final String GRID_AUTO_REPEAT_CAN_BE_USED_ONLY_ONCE
61+
= "Automatic repetitions in the grid template are allowed only once per template.";
62+
public static final String GRID_AUTO_REPEAT_CANNOT_BE_COMBINED_WITH_INDEFINITE_SIZES
63+
= "Automatic repetitions in the grid template cannot be combined with intrinsic or flexible sizes.";
6064

6165
private LayoutExceptionMessageConstant(){}
6266
}

layout/src/main/java/com/itextpdf/layout/properties/GridValue.java

Lines changed: 0 additions & 211 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.itextpdf.layout.properties.grid;
2+
3+
import java.util.List;
4+
5+
/**
6+
* This class represents an auto-repeat template value.
7+
* This value is preprocessed before grid sizing algorithm so its only exists at template level.
8+
*/
9+
public class AutoRepeatValue extends TemplateValue {
10+
private final List<GridValue> values;
11+
private final boolean autoFit;
12+
13+
/**
14+
* Create a new auto-repeat value
15+
*
16+
* @param autoFit determines whether to shrink flatten template values to match the grid size
17+
* @param values template values to repeat
18+
*/
19+
public AutoRepeatValue(boolean autoFit, List<GridValue> values) {
20+
super(ValueType.AUTO_REPEAT);
21+
this.values = values;
22+
this.autoFit = autoFit;
23+
}
24+
25+
/**
26+
* Get template values which should be repeated.
27+
*
28+
* @return template values list
29+
*/
30+
public List<GridValue> getValues() {
31+
return values;
32+
}
33+
34+
/**
35+
* Determines whether to shrink flatten template values to match the grid size.
36+
*
37+
* @return {@code true} if to shrink, {@code false} otherwise
38+
*/
39+
public boolean isAutoFit() {
40+
return autoFit;
41+
}
42+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.itextpdf.layout.properties.grid;
2+
3+
/**
4+
* Represents an auto template value.
5+
*/
6+
public final class AutoValue extends BreadthValue {
7+
/**
8+
* auto value constant.
9+
*/
10+
public static final AutoValue VALUE = new AutoValue();
11+
12+
private AutoValue() {
13+
super(ValueType.AUTO);
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.itextpdf.layout.properties.grid;
2+
3+
/**
4+
* Represents a breadth value on a grid.
5+
*/
6+
public abstract class BreadthValue extends GridValue {
7+
/**
8+
* Init a breadth value with a given type
9+
*
10+
* @param type value type
11+
*/
12+
protected BreadthValue(ValueType type) {
13+
super(type);
14+
}
15+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.itextpdf.layout.properties.grid;
2+
3+
import com.itextpdf.layout.properties.UnitValue;
4+
5+
/**
6+
* Represents fit content function template value.
7+
*/
8+
public class FitContentValue extends FunctionValue {
9+
private LengthValue length;
10+
11+
/**
12+
* Create fit content function value based on provided {@link LengthValue} instance.
13+
*
14+
* @param length max size value
15+
*/
16+
public FitContentValue(LengthValue length) {
17+
super(ValueType.FIT_CONTENT);
18+
this.length = length;
19+
}
20+
21+
/**
22+
* Create fit content function value based on provided {@link UnitValue} instance.
23+
*
24+
* @param length max size value
25+
*/
26+
public FitContentValue(UnitValue length) {
27+
super(ValueType.FIT_CONTENT);
28+
if (length != null) {
29+
if (length.isPointValue()) {
30+
this.length = new PointValue(length.getValue());
31+
} else if (length.isPercentValue()) {
32+
this.length = new PercentValue(length.getValue());
33+
}
34+
}
35+
}
36+
37+
/**
38+
* Get underlying {@link LengthValue} which represents max size on a grid for this value.
39+
*
40+
* @return underlying {@link LengthValue} value
41+
*/
42+
public LengthValue getLength() {
43+
return length;
44+
}
45+
46+
/**
47+
* Gets the maximum size which the value can take on passed space.
48+
*
49+
* @param space the space for which fit-content size will be calculated
50+
*
51+
* @return the maximum size of the value on passed space
52+
*/
53+
public float getMaxSizeForSpace(float space) {
54+
if (length.getType() == GridValue.ValueType.POINT) {
55+
return length.getValue();
56+
} else {
57+
return length.getValue() / 100 * space;
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)