Skip to content

Commit cb284bd

Browse files
committed
Add unit tests for SvgCoordinateUtils
DEVSIX-4867
1 parent b1a36b1 commit cb284bd

File tree

3 files changed

+521
-17
lines changed

3 files changed

+521
-17
lines changed

svg/src/main/java/com/itextpdf/svg/exceptions/SvgExceptionMessageConstant.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ public class SvgExceptionMessageConstant {
5757

5858
public static final String COULD_NOT_DETERMINE_MIDDLE_POINT_OF_ELLIPTICAL_ARC = "Could not determine the middle point of the ellipse traced by this elliptical arc";
5959

60-
public static final String VIEWBOX_APPLYING_COULD_NOT_BE_PROCESSED =
61-
"The viewBox or the current viewport is null. The viewBox applying could not be processed.";
62-
60+
public static final String CURRENT_VIEWPORT_IS_NULL =
61+
"The current viewport is null. The viewBox applying could not be processed.";
6362

63+
public static final String VIEWBOX_IS_INCORRECT =
64+
"The viewBox is incorrect. The viewBox applying could not be processed.";
6465
}

svg/src/main/java/com/itextpdf/svg/utils/SvgCoordinateUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public static double calculateAngleBetweenTwoVectors(Vector vectorA, Vector vect
106106
*/
107107
public static double getCoordinateForUserSpaceOnUse(String attributeValue, double defaultValue,
108108
double start, double length, float em, float rem) {
109-
// TODO DEVSIX-4867 add tests for this method
110109
double absoluteValue;
111110
final UnitValue unitValue = CssUtils.parseLengthValueToPt(attributeValue, em, rem);
112111
if (unitValue == null) {
@@ -129,7 +128,6 @@ public static double getCoordinateForUserSpaceOnUse(String attributeValue, doubl
129128
* And if it's a valid value with a number, the number will be extracted from that value.
130129
*/
131130
public static double getCoordinateForObjectBoundingBox(String attributeValue, double defaultValue) {
132-
// TODO DEVSIX-4867 add tests for this method
133131
if (CssTypesValidationUtils.isPercentageValue(attributeValue)) {
134132
return CssDimensionParsingUtils.parseRelativeValue(attributeValue, 1);
135133
} else if (CssTypesValidationUtils.isNumericValue(attributeValue)
@@ -168,10 +166,12 @@ public static double getCoordinateForObjectBoundingBox(String attributeValue, do
168166
*/
169167
public static Rectangle applyViewBox(Rectangle viewBox, Rectangle currentViewPort, String align,
170168
String meetOrSlice) {
171-
// TODO DEVSIX-4867 add tests for this method
169+
if (currentViewPort == null) {
170+
throw new IllegalArgumentException(SvgExceptionMessageConstant.CURRENT_VIEWPORT_IS_NULL);
171+
}
172172

173-
if (viewBox == null || currentViewPort == null) {
174-
throw new IllegalArgumentException(SvgExceptionMessageConstant.VIEWBOX_APPLYING_COULD_NOT_BE_PROCESSED);
173+
if (viewBox == null || viewBox.getWidth() <= 0 || viewBox.getHeight() <= 0) {
174+
throw new IllegalArgumentException(SvgExceptionMessageConstant.VIEWBOX_IS_INCORRECT);
175175
}
176176

177177
if (align == null || (

0 commit comments

Comments
 (0)