Skip to content

Commit 34f2897

Browse files
committed
Do not perform redundant mathematical operations that can cause the precission loss. Introduce some new handy UV methods.
DEVSIX-1810
1 parent 662fbe9 commit 34f2897

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

layout/src/main/java/com/itextpdf/layout/renderer/AbstractRenderer.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,9 @@ protected Float retrieveUnitValue(float baseValue, int property, boolean pointOn
14121412
}
14131413
if (value != null) {
14141414
if (value.getUnitType() == UnitValue.PERCENT) {
1415-
return baseValue * value.getValue() / 100;
1415+
// during mathematical operations the precision can be lost, so avoiding them if possible (100 / 100 == 1) is a good practice
1416+
// TODO Maybe decrease the result value by AbstractRenderer.EPS ?
1417+
return value.getValue() != 100 ? baseValue * value.getValue() / 100 : baseValue;
14161418
} else {
14171419
assert value.getUnitType() == UnitValue.POINT;
14181420
return value.getValue();
@@ -2046,6 +2048,17 @@ protected boolean hasAbsoluteUnitValue(int property) {
20462048
return value != null && value.isPointValue();
20472049
}
20482050

2051+
/**
2052+
* Check if corresponding property has relative value.
2053+
*
2054+
* @param property {@link Property}
2055+
* @return false if property value either null, or point, otherwise true.
2056+
*/
2057+
protected boolean hasRelativeUnitValue(int property) {
2058+
UnitValue value = this.<UnitValue>getProperty(property);
2059+
return value != null && value.isPercentValue();
2060+
}
2061+
20492062
boolean isFirstOnRootArea(boolean checkRootAreaOnly) {
20502063
boolean isFirstOnRootArea = true;
20512064
IRenderer ancestor = this;

0 commit comments

Comments
 (0)