Author: tilman
Date: Sun Aug 16 18:52:02 2026
New Revision: 1937162
Log:
PDFBOX-6233: refactor to return origin only
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
==============================================================================
---
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Sun Aug 16 17:48:38 2026 (r1937161)
+++
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Sun Aug 16 18:52:02 2026 (r1937162)
@@ -651,9 +651,9 @@ public class PageDrawer extends PDFGraph
throw new IOException("Invalid soft mask subtype: " + subType);
}
gray = adjustImage(gray);
-
- Rectangle2D tpgBounds = transparencyGroup.getBounds();
- return new SoftMask(parentPaint, gray, tpgBounds, backdropColor,
softMask.getTransferFunction());
+ Point2D origin = transparencyGroup.getOrigin();
+ PDFunction transferFunction = softMask.getTransferFunction();
+ return new SoftMask(parentPaint, gray, origin, backdropColor,
transferFunction);
}
// returns the image adjusted for applySoftMaskToPaint().
@@ -1373,7 +1373,7 @@ public class PageDrawer extends PDFGraph
{
AffineTransform deviceTransform = graphics.getTransform();
Raster maskRaster = softMask.getMask().getRaster();
- Rectangle2D bboxDevice = softMask.getBBoxDevice();
+ Point2D origin = softMask.getOrigin();
int backdropColorValue = softMask.getBackdropColorValue();
PDFunction transferFunction = softMask.getTransferFunction();
Float[] map = transferFunction != null ? new Float[256] : null;
@@ -1391,8 +1391,8 @@ public class PageDrawer extends PDFGraph
{
point.setLocation(bounds.getMinX() + x, bounds.getMinY() + y);
deviceTransform.transform(point, point);
- int maskX = (int) Math.floor(point.getX() - bboxDevice.getX());
- int maskY = (int) Math.floor(point.getY() - bboxDevice.getY());
+ int maskX = (int) Math.floor(point.getX() - origin.getX());
+ int maskY = (int) Math.floor(point.getY() - origin.getY());
int alphaScale;
if (maskX >= 0 && maskY >= 0 && maskX < maskRaster.getWidth()
&& maskY < maskRaster.getHeight())
@@ -2168,7 +2168,7 @@ public class PageDrawer extends PDFGraph
return bbox;
}
- Rectangle2D getBounds()
+ Point2D getOrigin()
{
Rectangle2D r;
if (flipTG)
@@ -2189,12 +2189,12 @@ public class PageDrawer extends PDFGraph
// apply the underlying Graphics2D device's DPI transform
// this adjusts the rectangle to the rotated image to put the soft
mask at the correct position
//TODO
- // 1. change transparencyGroup.getBounds() to getOrigin(), because
size isn't used in SoftMask,
- // 2. Is it possible to create the softmask and transparency group
in the correct rotation?
- // (needs rendering identity testing before committing!)
+ // Is it possible to create the softmask and transparency group in
the correct rotation?
+ // (needs rendering identity testing before committing!)
AffineTransform adjustedTransform = new AffineTransform(xform);
adjustedTransform.scale(1.0 / xformScalingFactorX, 1.0 /
xformScalingFactorY);
- return adjustedTransform.createTransformedShape(r).getBounds2D();
+ Rectangle2D b2d =
adjustedTransform.createTransformedShape(r).getBounds2D();
+ return new Point2D.Double(b2d.getX(), b2d.getY());
}
}
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java
==============================================================================
---
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java
Sun Aug 16 17:48:38 2026 (r1937161)
+++
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/SoftMask.java
Sun Aug 16 18:52:02 2026 (r1937162)
@@ -23,6 +23,7 @@ import java.awt.PaintContext;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
@@ -55,7 +56,7 @@ class SoftMask implements Paint
private final Paint paint;
private final BufferedImage mask;
- private final Rectangle2D bboxDevice;
+ private final Point2D origin;
private int bc = 0;
private final PDFunction transferFunction;
@@ -64,16 +65,16 @@ class SoftMask implements Paint
*
* @param paint underlying paint.
* @param mask soft mask
- * @param bboxDevice bbox of the soft mask in the underlying Graphics2D
device space
+ * @param origin origin of the soft mask in the underlying Graphics2D
device space
* @param backdropColor the color to be used outside the transparency
group’s bounding box; if
* null, black will be used.
* @param transferFunction the transfer function, may be null.
*/
- SoftMask(Paint paint, BufferedImage mask, Rectangle2D bboxDevice, PDColor
backdropColor, PDFunction transferFunction)
+ SoftMask(Paint paint, BufferedImage mask, Point2D origin, PDColor
backdropColor, PDFunction transferFunction)
{
this.paint = paint;
this.mask = mask;
- this.bboxDevice = bboxDevice;
+ this.origin = origin;
if (transferFunction instanceof PDFunctionTypeIdentity)
{
this.transferFunction = null;
@@ -112,9 +113,9 @@ class SoftMask implements Paint
return mask;
}
- Rectangle2D getBBoxDevice()
+ Point2D getOrigin()
{
- return bboxDevice;
+ return origin;
}
int getBackdropColorValue()
@@ -175,8 +176,8 @@ class SoftMask implements Paint
WritableRaster outputRaster =
getColorModel().createCompatibleWritableRaster(w, h);
// the soft mask has its own bbox
- x1 = x1 - (int)bboxDevice.getX();
- y1 = y1 - (int)bboxDevice.getY();
+ x1 = x1 - (int) origin.getX();
+ y1 = y1 - (int) origin.getY();
int[] gray = new int[4];
Object pixelInput = null;