Skip to content

Commit badd958

Browse files
Samuel HuylebroeckiText-CI
authored andcommitted
Normalize PdfArray#toRectangle
Will now return the rectangle defined by lower-left and upper-right corners instead of raw extractraction DEVSIX-2530
1 parent 0e5b707 commit badd958

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfArray.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,14 @@ public Rectangle toRectangle() {
485485
float y1 = getAsNumber(1).floatValue();
486486
float x2 = getAsNumber(2).floatValue();
487487
float y2 = getAsNumber(3).floatValue();
488-
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
488+
float llx, lly, urx, ury;
489+
//Find the lower-left and upper-right of these 4 points
490+
llx = Math.min(x1,x2);
491+
lly = Math.min(y1,y2);
492+
urx = Math.max(x1,x2);
493+
ury = Math.max(y1,y2);
494+
495+
return new Rectangle(llx, lly, urx - llx, ury - lly);
489496
} catch (Exception e) {
490497
throw new PdfException(PdfException.CannotConvertPdfArrayToRectanle, e, this);
491498
}

0 commit comments

Comments
 (0)