Skip to content

Commit

Permalink
GH-314 make sure we adjust for xObject matrix when processing Do images.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Corless committed Dec 2, 2023
1 parent fdf1275 commit 65b3c2b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
11 changes: 9 additions & 2 deletions core/core-awt/src/main/java/org/icepdf/core/pobjects/Form.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.icepdf.core.pobjects.graphics.Shapes;
import org.icepdf.core.util.Library;
import org.icepdf.core.util.parser.content.ContentParser;
import org.icepdf.core.util.updater.callbacks.ContentStreamRedactorCallback;

import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
Expand Down Expand Up @@ -148,10 +149,16 @@ public void setParentResources(Resources parentResource) {
this.parentResource = parentResource;
}


public synchronized void init() throws InterruptedException {
init(null);
}

/**
*
*/
public synchronized void init() throws InterruptedException {
public synchronized void init(ContentStreamRedactorCallback contentStreamRedactorCallback)
throws InterruptedException {
if (inited) {
return;
}
Expand All @@ -171,7 +178,7 @@ public synchronized void init() throws InterruptedException {
}
// Build a new content parser for the content streams and apply the
// content stream of the calling content stream.
ContentParser cp = new ContentParser(library, leafResources);
ContentParser cp = new ContentParser(library, leafResources, contentStreamRedactorCallback);
cp.setGraphicsState(graphicsState);
byte[] in = getDecodedStreamBytes();
if (in != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,7 @@ public boolean configurePermissions() {
Permissions permissions = catalog.getPermissions();
if (permissions != null) {
this.permissions = permissions;
if (logger.isLoggable(Level.FINER)) {
logger.finer("Document perms dictionary found and configured. ");
}
logger.finer(() -> "Document perms dictionary found and configured. ");
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ protected static GraphicsState consume_Do(GraphicsState graphicState, Stack<Obje
// resources reference as a result we pass in the current
// one in the hope that any resources can be found.
formXObject.setParentResources(resources);
formXObject.init();
formXObject.init(contentStreamRedactorCallback);
// 2. concatenate matrix entry with the current CTM
AffineTransform af = new AffineTransform(graphicState.getCTM());
af.concatenate(formXObject.getMatrix());
Expand Down Expand Up @@ -600,6 +600,21 @@ protected static GraphicsState consume_Do(GraphicsState graphicState, Stack<Obje
pageText.getPageLines());
}
}
// Some Do object will have images, and we need to make sure we account for localized space.
if (contentStreamRedactorCallback != null &&
formXObject.getShapes() != null) {
Shapes pageShapes = formXObject.getShapes();
ArrayList<DrawCmd> xObjectShapes = pageShapes.getShapes();
for (DrawCmd object : xObjectShapes) {
if (object instanceof ImageDrawCmd) {
ImageDrawCmd imageDrawCmd = (ImageDrawCmd) object;
ImageStream imageStream = imageDrawCmd.getImageStream();
AffineTransform pageSpace = new AffineTransform(graphicState.getCTM());
pageSpace.concatenate(formXObject.getMatrix());
imageStream.setGraphicsTransformMatrix(af);
}
}
}
shapes.add(new NoClipDrawCmd());
// 5. Restore the saved graphics state
graphicState = graphicState.restore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,15 @@ private boolean isTextLayoutToken(int token) {

/**
* Marks any glyphText that intersect a redaction bound.
*
* @param glyphText text to test for intersection with redact annotations
*/
public void checkAndRedactText(GlyphText glyphText) {
for (RedactionAnnotation annotation : redactionAnnotations) {
GeneralPath reactionPaths = annotation.getMarkupPath();
Rectangle2D glyphBounds = glyphText.getBounds();
if (reactionPaths.contains(glyphBounds)) {
if (logger.isLoggable(Level.FINER)) {
logger.finer("Redacting Text: " + glyphText.getCid() + " " + glyphText.getUnicode());
}
logger.finer(() -> "Redacting Text: " + glyphText.getCid() + " " + glyphText.getUnicode());
glyphText.redact();
}
}
Expand All @@ -148,9 +147,7 @@ public void checkAndRedactInlineImage(ImageReference imageReference, int pos) th
ImageStream imageStream = imageReference.getImageStream();
Rectangle2D imageBounds = imageStream.getNormalizedBounds();
if (redactionPath.intersects(imageBounds)) {
if (logger.isLoggable(Level.FINER)) {
logger.finer("Redacting inline image: " + imageStream.getWidth() + "x" + imageStream.getHeight());
}
logger.finer(() -> "Redacting inline image: " + imageStream.getWidth() + "x" + imageStream.getHeight());
ImageStream burnedImageStream = ImageBurner.burn(imageReference, redactionPath);
CountingOutputStream countingOutputStream = new CountingOutputStream(burnedContentOutputStream);
InlineImageWriter.write(countingOutputStream, burnedImageStream);
Expand All @@ -170,10 +167,8 @@ public void checkAndRedactImageXObject(ImageReference imageReference) throws Int
ImageStream imageStream = imageReference.getImageStream();
Rectangle2D imageBounds = imageStream.getNormalizedBounds();
if (redactionPath.intersects(imageBounds)) {
if (logger.isLoggable(Level.FINER)) {
logger.finer("Redacting Image: " + imageStream.getPObjectReference() + " " +
imageStream.getWidth() + "x" + imageStream.getHeight());
}
logger.finer(() -> "Redacting Image: " + imageStream.getPObjectReference() + " " +
imageStream.getWidth() + "x" + imageStream.getHeight());
ImageBurner.burn(imageReference, redactionPath);
}
}
Expand Down

0 comments on commit 65b3c2b

Please sign in to comment.