Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactoring - moved rectangle normalization into PdfRectangle constructor to avoid issues with using this constructor in the future #1117

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfRectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,7 @@ public PdfRectangle(Rectangle rectangle) {
* @param rectangle as a PdfArray
*/
public PdfRectangle(PdfArray rectangle) {
this(convertToFloat(rectangle.getPdfObject(0)), convertToFloat(rectangle.getPdfObject(1)),
convertToFloat(rectangle.getPdfObject(2)), convertToFloat(rectangle.getPdfObject(3)));
}

private static float convertToFloat(PdfObject object) {
if (!(object instanceof PdfNumber)) {
throw new IllegalArgumentException(
"Invalid argument. Float value (coordinate) expected! But was " + object);
}
return ((PdfNumber) object).floatValue();
this(PdfReader.getNormalizedRectangle(rectangle));
}

// methods
Expand Down
7 changes: 3 additions & 4 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfStamperImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,8 @@ void flatFields() {

if (bboxRaw != null && rectRaw != null) {
transformNeeded = true;
PdfRectangle bbox = new PdfRectangle(PdfReader.getNormalizedRectangle(bboxRaw));
PdfRectangle rect = new PdfRectangle(PdfReader.getNormalizedRectangle(rectRaw));
PdfRectangle bbox = new PdfRectangle(bboxRaw);
PdfRectangle rect = new PdfRectangle(rectRaw);

float rectWidth = rect.width();
float rectHeight = rect.height();
Expand Down Expand Up @@ -1060,8 +1060,7 @@ void flatFields() {
if (!(objReal instanceof PdfIndirectReference)) {

// Lonzak: npe bugfix
PdfRectangle bBoxCoordinates = new PdfRectangle(
((PdfDictionary) objReal).getAsArray(PdfName.BBOX));
PdfArray bBoxCoordinates = ((PdfDictionary) objReal).getAsArray(PdfName.BBOX);
if (bBoxCoordinates != null && bBoxCoordinates.size() >= 4) {
// DEVSIX-1741 - Bugfix backported as Jonthan of iText suggested
Rectangle bBox = PdfReader.getNormalizedRectangle(bBoxCoordinates);
Expand Down
Loading