From c7e17515ef3e7b09b5a822fe81ffbb1e21da6ff9 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Fri, 16 Oct 2009 14:12:06 +0000 Subject: [PATCH] Made PDFImageHandlerGraphics2D accessible git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@825902 13f79535-47bb-0310-9956-ffa450edef68 --- .../render/pdf/PDFImageHandlerGraphics2D.java | 18 ++++++++++++++++-- .../org/apache/fop/render/pdf/PDFRenderer.java | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java index 18717809d..c3242827a 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java @@ -35,6 +35,7 @@ import org.apache.fop.pdf.PDFXObject; import org.apache.fop.render.AbstractImageHandlerGraphics2D; import org.apache.fop.render.RendererContext; import org.apache.fop.render.RenderingContext; +import org.apache.fop.render.pdf.PDFLogicalStructureHandler.MarkedContentInfo; import org.apache.fop.svg.PDFGraphics2D; /** @@ -63,6 +64,9 @@ public class PDFImageHandlerGraphics2D extends AbstractImageHandlerGraphics2D renderer.currentPage, renderer.getFontInfo()); Rectangle effPos = new Rectangle(origin.x + pos.x, origin.y + pos.y, pos.width, pos.height); + if (context.getUserAgent().isAccessibilityEnabled()) { + pdfContext.setMarkedContentInfo(renderer.addCurrentImageToStructureTree()); + } handleImage(pdfContext, image, effPos); return null; } @@ -87,7 +91,13 @@ public class PDFImageHandlerGraphics2D extends AbstractImageHandlerGraphics2D float sy = fheight / (float)imh; generator.comment("G2D start"); - generator.saveGraphicsState(); + boolean accessibilityEnabled = context.getUserAgent().isAccessibilityEnabled(); + if (accessibilityEnabled) { + MarkedContentInfo mci = pdfContext.getMarkedContentInfo(); + generator.saveGraphicsState(mci.tag, mci.mcid); + } else { + generator.saveGraphicsState(); + } generator.updateColor(Color.black, false, null); generator.updateColor(Color.black, true, null); @@ -115,7 +125,11 @@ public class PDFImageHandlerGraphics2D extends AbstractImageHandlerGraphics2D imageG2D.getGraphics2DImagePainter().paint(graphics, area); generator.add(graphics.getString()); - generator.restoreGraphicsState(); + if (accessibilityEnabled) { + generator.restoreGraphicsStateAccess(); + } else { + generator.restoreGraphicsState(); + } generator.comment("G2D end"); } diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index 380241ba0..6188433c6 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -1347,5 +1347,9 @@ public class PDFRenderer extends AbstractPathOrientedRenderer implements PDFConf public void setEncryptionParams(PDFEncryptionParams encryptionParams) { this.pdfUtil.setEncryptionParams(encryptionParams); } + + MarkedContentInfo addCurrentImageToStructureTree() { + return logicalStructureHandler.addImageContentItem(imageReference); + } } -- 2.39.5