From e3e19e881a5cd78c2d4612bb01310cc3500cc2ca Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Tue, 13 Oct 2009 15:34:29 +0000 Subject: [PATCH] Bugfix: render all background images as artifacts git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@824808 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/intermediate/IFContext.java | 9 ----- .../fop/render/pdf/PDFContentGenerator.java | 10 ----- .../render/pdf/PDFImageHandlerRawJPEG.java | 10 ++--- .../pdf/PDFImageHandlerRenderedImage.java | 6 +-- .../fop/render/pdf/PDFImageHandlerSVG.java | 6 +-- .../org/apache/fop/render/pdf/PDFPainter.java | 29 +++++--------- .../fop/render/pdf/PDFRenderingContext.java | 39 +++---------------- 7 files changed, 24 insertions(+), 85 deletions(-) diff --git a/src/java/org/apache/fop/render/intermediate/IFContext.java b/src/java/org/apache/fop/render/intermediate/IFContext.java index f052846d3..804b353c1 100644 --- a/src/java/org/apache/fop/render/intermediate/IFContext.java +++ b/src/java/org/apache/fop/render/intermediate/IFContext.java @@ -155,13 +155,4 @@ public class IFContext { return this.structurePointer; } - /** - * Indicates whether a structure pointer is available. - * @return true if there's a structure pointer - * @see #setStructurePointer(String) - */ - public boolean hasStructurePointer() { - return (this.structurePointer != null) && (structurePointer.length() > 0); - } - } diff --git a/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java b/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java index 942d5c72c..51a74bd2b 100644 --- a/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java +++ b/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java @@ -229,16 +229,6 @@ public class PDFContentGenerator { textutil.beginTextObject(); } - /** - * used for accessibility - * separates a text element from fo:leader text element - */ - public void separateTextElementFromLeader() { - if (!inArtifactMode) { - separateTextElements(null, 0); - } - } - /** Indicates the beginning of a text object. */ protected void beginTextObject() { if (!textutil.isInTextObject()) { diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java index fe3a00aa8..02dd98ecf 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java @@ -34,6 +34,7 @@ import org.apache.fop.pdf.PDFXObject; import org.apache.fop.render.ImageHandler; import org.apache.fop.render.RendererContext; import org.apache.fop.render.RenderingContext; +import org.apache.fop.render.pdf.PDFLogicalStructureHandler.MarkedContentInfo; /** * Image handler implementation which handles raw JPEG images for PDF output. @@ -83,13 +84,8 @@ public class PDFImageHandlerRawJPEG implements PDFImageHandler, ImageHandler { float w = (float)pos.getWidth() / 1000f; float h = (float)pos.getHeight() / 1000f; if (context.getUserAgent().isAccessibilityEnabled()) { - String structElemType = pdfContext.getStructElemType(); - if (structElemType != null && structElemType.length() > 0) { - int sequenceNum = pdfContext.getSequenceNum(); - generator.placeImage(x, y, w, h, xobj, structElemType, sequenceNum); - } else { - generator.placeImage(x, y, w, h, xobj); - } + MarkedContentInfo mci = pdfContext.getMarkedContentInfo(); + generator.placeImage(x, y, w, h, xobj, mci.tag, mci.mcid); } else { generator.placeImage(x, y, w, h, xobj); } diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java index 24d17a2b1..3c02cb6f3 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java @@ -34,6 +34,7 @@ import org.apache.fop.pdf.PDFXObject; import org.apache.fop.render.ImageHandler; import org.apache.fop.render.RendererContext; import org.apache.fop.render.RenderingContext; +import org.apache.fop.render.pdf.PDFLogicalStructureHandler.MarkedContentInfo; /** * Image handler implementation which handles RenderedImage instances for PDF output. @@ -84,9 +85,8 @@ public class PDFImageHandlerRenderedImage implements PDFImageHandler, ImageHandl float w = (float)pos.getWidth() / 1000f; float h = (float)pos.getHeight() / 1000f; if (context.getUserAgent().isAccessibilityEnabled()) { - String structElemType = pdfContext.getStructElemType(); - int sequenceNum = pdfContext.getSequenceNum(); - generator.placeImage(x, y, w, h, xobj, structElemType, sequenceNum); + MarkedContentInfo mci = pdfContext.getMarkedContentInfo(); + generator.placeImage(x, y, w, h, xobj, mci.tag, mci.mcid); } else { generator.placeImage(x, y, w, h, xobj); } diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java index fde9e0696..e6d2c8a71 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java @@ -40,6 +40,7 @@ import org.apache.fop.apps.FOUserAgent; import org.apache.fop.image.loader.batik.BatikImageFlavors; import org.apache.fop.render.ImageHandler; import org.apache.fop.render.RenderingContext; +import org.apache.fop.render.pdf.PDFLogicalStructureHandler.MarkedContentInfo; import org.apache.fop.svg.PDFAElementBridge; import org.apache.fop.svg.PDFBridgeContext; import org.apache.fop.svg.PDFGraphics2D; @@ -122,9 +123,8 @@ public class PDFImageHandlerSVG implements ImageHandler { generator.comment("SVG setup"); generator.saveGraphicsState(); if (context.getUserAgent().isAccessibilityEnabled()) { - String structElemType = pdfContext.getStructElemType(); - int sequenceNum = pdfContext.getSequenceNum(); - generator.beginMarkedContentSequence(structElemType, sequenceNum); + MarkedContentInfo mci = pdfContext.getMarkedContentInfo(); + generator.beginMarkedContentSequence(mci.tag, mci.mcid); } generator.setColor(Color.black, false); generator.setColor(Color.black, true); diff --git a/src/java/org/apache/fop/render/pdf/PDFPainter.java b/src/java/org/apache/fop/render/pdf/PDFPainter.java index 25e169ab0..2ae28b6db 100644 --- a/src/java/org/apache/fop/render/pdf/PDFPainter.java +++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java @@ -131,7 +131,7 @@ public class PDFPainter extends AbstractIFPainter { throws IFException { PDFXObject xobject = getPDFDoc().getXObject(uri); if (xobject != null) { - if (accessEnabled && getContext().hasStructurePointer()) { + if (accessEnabled) { String ptr = getContext().getStructurePointer(); prepareImageMCID(ptr); placeImageAccess(rect, xobject); @@ -139,7 +139,7 @@ public class PDFPainter extends AbstractIFPainter { placeImage(rect, xobject); } } else { - if (accessEnabled && getContext().hasStructurePointer()) { + if (accessEnabled) { String ptr = getContext().getStructurePointer(); prepareImageMCID(ptr); } @@ -156,8 +156,7 @@ public class PDFPainter extends AbstractIFPainter { protected RenderingContext createRenderingContext() { PDFRenderingContext pdfContext = new PDFRenderingContext( getUserAgent(), generator, this.documentHandler.currentPage, getFontInfo()); - pdfContext.setMCID(imageMCI.mcid); - pdfContext.setStructElemType(imageMCI.tag); + pdfContext.setMarkedContentInfo(imageMCI); return pdfContext; } @@ -198,7 +197,7 @@ public class PDFPainter extends AbstractIFPainter { /** {@inheritDoc} */ public void drawImage(Document doc, Rectangle rect) throws IFException { - if (accessEnabled && getContext().hasStructurePointer()) { + if (accessEnabled) { String ptr = getContext().getStructurePointer(); prepareImageMCID(ptr); } @@ -298,22 +297,12 @@ public class PDFPainter extends AbstractIFPainter { throws IFException { if (accessEnabled) { String ptr = getContext().getStructurePointer(); - if (ptr != null && ptr.length() > 0) { - MarkedContentInfo mci = logicalStructureHandler.addTextContentItem(ptr); - if (generator.getTextUtil().isInTextObject()) { - generator.separateTextElements(mci.tag, mci.mcid); - } - generator.updateColor(state.getTextColor(), true, null); - generator.beginTextObjectAccess(mci.tag, mci.mcid); - } else { - // - // Leader content is marked as "/Artifact" - if (generator.getTextUtil().isInTextObject()) { - generator.separateTextElementFromLeader(); - } - generator.updateColor(state.getTextColor(), true, null); - generator.beginLeaderTextObject(); + MarkedContentInfo mci = logicalStructureHandler.addTextContentItem(ptr); + if (generator.getTextUtil().isInTextObject()) { + generator.separateTextElements(mci.tag, mci.mcid); } + generator.updateColor(state.getTextColor(), true, null); + generator.beginTextObjectAccess(mci.tag, mci.mcid); } else { generator.updateColor(state.getTextColor(), true, null); generator.beginTextObject(); diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderingContext.java b/src/java/org/apache/fop/render/pdf/PDFRenderingContext.java index f82019b4a..80adfa5c8 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderingContext.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderingContext.java @@ -25,6 +25,7 @@ import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fonts.FontInfo; import org.apache.fop.pdf.PDFPage; import org.apache.fop.render.AbstractRenderingContext; +import org.apache.fop.render.pdf.PDFLogicalStructureHandler.MarkedContentInfo; /** * Rendering context for PDF production. @@ -34,11 +35,7 @@ public class PDFRenderingContext extends AbstractRenderingContext { private PDFContentGenerator generator; private FontInfo fontInfo; private PDFPage page; - /** Temp. val. for accessibility, used in PDFImageHandlerRenderedImage */ - private String structElemType = ""; - - /** Temp. val. for accessibility, used in PDFImageHandlerRenderedImage */ - private int mcid = -1; + private MarkedContentInfo mci; /** * Main constructor. @@ -84,35 +81,11 @@ public class PDFRenderingContext extends AbstractRenderingContext { return this.fontInfo; } - /** - * Used for accessibility, used in PDFPainter.drawImage - * @param value to be stored - */ - public void setMCID(int value) { - mcid = value; - } - - /** - * Used for accessibility - * @return mcid - */ - public int getSequenceNum() { - return mcid; + void setMarkedContentInfo(MarkedContentInfo mci) { + this.mci = mci; } - /** - * Used for accessibility - * @param s the type of the structure element - */ - public void setStructElemType(String s) { - structElemType = s; - } - - /** - * Used for accessibility - * @return the type of the structure element - */ - public String getStructElemType() { - return structElemType; + MarkedContentInfo getMarkedContentInfo() { + return mci; } } -- 2.39.5