aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/intermediate
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/render/intermediate')
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFContext.java18
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFPainter.java9
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFParser.java18
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFRenderer.java64
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFSerializer.java11
5 files changed, 81 insertions, 39 deletions
diff --git a/src/java/org/apache/fop/render/intermediate/IFContext.java b/src/java/org/apache/fop/render/intermediate/IFContext.java
index b05db1369..30989d04f 100644
--- a/src/java/org/apache/fop/render/intermediate/IFContext.java
+++ b/src/java/org/apache/fop/render/intermediate/IFContext.java
@@ -43,6 +43,8 @@ public class IFContext {
/** foreign attributes: Map<QName, Object> */
private Map foreignAttributes = Collections.EMPTY_MAP;
+ private String structurePointer;
+
/**
* Main constructor.
* @param ua the user agent
@@ -108,4 +110,20 @@ public class IFContext {
setForeignAttributes(null);
}
+ public void setStructurePointer(String ptr) {
+ this.structurePointer = ptr;
+ }
+
+ public void resetStructurePointer() {
+ setStructurePointer(null);
+ }
+
+ public String getStructurePointer() {
+ return this.structurePointer;
+ }
+
+ public boolean hasStructurePointer() {
+ return (this.structurePointer != null) && (structurePointer.length() > 0);
+ }
+
}
diff --git a/src/java/org/apache/fop/render/intermediate/IFPainter.java b/src/java/org/apache/fop/render/intermediate/IFPainter.java
index 163fe16a1..6369b0251 100644
--- a/src/java/org/apache/fop/render/intermediate/IFPainter.java
+++ b/src/java/org/apache/fop/render/intermediate/IFPainter.java
@@ -153,11 +153,10 @@ public interface IFPainter {
* @param wordSpacing additional spacing between words (may be 0)
* @param dx an array of adjustment values for each character in X-direction (may be null)
* @param text the text
- * @param ptr used for accessibility
* @throws IFException if an error occurs while handling this event
*/
void drawText(int x, int y, int letterSpacing, int wordSpacing,
- int[] dx, String text, String ptr) throws IFException;
+ int[] dx, String text) throws IFException;
/**
* Restricts the current clipping region with the given rectangle.
@@ -206,20 +205,18 @@ public interface IFPainter {
* an fo:external-graphic in XSL-FO.
* @param uri the image's URI
* @param rect the rectangle in which the image shall be painted
- * @param ptr used for accessibility
* @throws IFException if an error occurs while handling this event
*/
- void drawImage(String uri, Rectangle rect, String ptr) throws IFException;
+ void drawImage(String uri, Rectangle rect) throws IFException;
/**
* Draws an image (represented by a DOM document) inside a given rectangle. This is the
* equivalent to an fo:instream-foreign-object in XSL-FO.
* @param doc the DOM document containing the foreign object
* @param rect the rectangle in which the image shall be painted
- * @param ptr used for accessibility
* @throws IFException if an error occurs while handling this event
*/
- void drawImage(Document doc, Rectangle rect, String ptr) throws IFException;
+ void drawImage(Document doc, Rectangle rect) throws IFException;
//Note: For now, all foreign objects are handled as DOM documents. At the moment, all known
//implementations use a DOM anyway, so optimizing this to work with SAX wouldn't result in
//any performance benefits. The IFRenderer itself has a DOM anyway. Only the IFParser could
diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java
index 47e24445c..5dbe6e46c 100644
--- a/src/java/org/apache/fop/render/intermediate/IFParser.java
+++ b/src/java/org/apache/fop/render/intermediate/IFParser.java
@@ -173,6 +173,14 @@ public class IFParser implements IFConstants {
documentHandler.getContext().resetForeignAttributes();
}
+ private void establishStructurePointer(String ptr) {
+ documentHandler.getContext().setStructurePointer(ptr);
+ }
+
+ private void resetStructurePointer() {
+ documentHandler.getContext().resetStructurePointer();
+ }
+
/** {@inheritDoc} */
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
@@ -482,7 +490,9 @@ public class IFParser implements IFConstants {
int wordSpacing = (s != null ? Integer.parseInt(s) : 0);
int[] dx = XMLUtil.getAttributeAsIntArray(lastAttributes, "dx");
String ptr = lastAttributes.getValue("ptr"); // used for accessibility
- painter.drawText(x, y, letterSpacing, wordSpacing, dx, content.toString(), ptr);
+ establishStructurePointer(ptr);
+ painter.drawText(x, y, letterSpacing, wordSpacing, dx, content.toString());
+ resetStructurePointer();
}
public boolean ignoreCharacters() {
@@ -578,9 +588,10 @@ public class IFParser implements IFConstants {
Map foreignAttributes = getForeignAttributes(lastAttributes);
establishForeignAttributes(foreignAttributes);
String ptr = lastAttributes.getValue("ptr"); // used for accessibility
+ establishStructurePointer(ptr);
if (foreignObject != null) {
painter.drawImage(foreignObject,
- new Rectangle(x, y, width, height), ptr);
+ new Rectangle(x, y, width, height));
foreignObject = null;
} else {
String uri = lastAttributes.getValue(
@@ -588,9 +599,10 @@ public class IFParser implements IFConstants {
if (uri == null) {
throw new IFException("xlink:href is missing on image", null);
}
- painter.drawImage(uri, new Rectangle(x, y, width, height), ptr);
+ painter.drawImage(uri, new Rectangle(x, y, width, height));
}
resetForeignAttributes();
+ resetStructurePointer();
inForeignObject = false;
}
diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
index 664f1324a..905277f1b 100644
--- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java
+++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
@@ -53,6 +53,7 @@ import org.apache.fop.Version;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.Area;
+import org.apache.fop.area.AreaTreeObject;
import org.apache.fop.area.Block;
import org.apache.fop.area.BlockViewport;
import org.apache.fop.area.BookmarkData;
@@ -500,7 +501,10 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
documentHandler.endDocumentHeader();
this.inPageSequence = true;
}
+ establishForeignAttributes(pageSequence.getForeignAttributes());
documentHandler.startPageSequence(null);
+ resetForeignAttributes();
+ processExtensionAttachments(pageSequence);
} catch (IFException e) {
handleIFException(e);
}
@@ -557,13 +561,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
documentHandler.startPageHeader();
//Add page attachments to page header
- if (page.hasExtensionAttachments()) {
- for (Iterator iter = page.getExtensionAttachments().iterator();
- iter.hasNext();) {
- ExtensionAttachment attachment = (ExtensionAttachment) iter.next();
- this.documentHandler.handleExtensionObject(attachment);
- }
- }
+ processExtensionAttachments(page);
documentHandler.endPageHeader();
this.painter = documentHandler.startPageContent();
@@ -590,6 +588,16 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
}
}
+ private void processExtensionAttachments(AreaTreeObject area) throws IFException {
+ if (area.hasExtensionAttachments()) {
+ for (Iterator iter = area.getExtensionAttachments().iterator();
+ iter.hasNext();) {
+ ExtensionAttachment attachment = (ExtensionAttachment) iter.next();
+ this.documentHandler.handleExtensionObject(attachment);
+ }
+ }
+ }
+
private void establishForeignAttributes(Map foreignAttributes) {
documentHandler.getContext().setForeignAttributes(foreignAttributes);
}
@@ -598,6 +606,14 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
documentHandler.getContext().resetForeignAttributes();
}
+ private void establishStructurePointer(String ptr) {
+ documentHandler.getContext().setStructurePointer(ptr);
+ }
+
+ private void resetStructurePointer() {
+ documentHandler.getContext().resetStructurePointer();
+ }
+
/** {@inheritDoc} */
protected void saveGraphicsState() {
graphicContextStack.push(graphicContext);
@@ -818,17 +834,20 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
currentIPPosition = saveIP;
currentBPPosition = saveBP;
- currentBPPosition += (bv.getAllocBPD());
+ currentBPPosition += bv.getAllocBPD();
}
viewportDimensionStack.pop();
}
/** {@inheritDoc} */
public void renderViewport(Viewport viewport) {
+ String ptr = (String) viewport.getTrait(Trait.PTR);
+ establishStructurePointer(ptr);
Dimension dim = new Dimension(viewport.getIPD(), viewport.getBPD());
viewportDimensionStack.push(dim);
super.renderViewport(viewport);
viewportDimensionStack.pop();
+ resetStructurePointer();
}
/** {@inheritDoc} */
@@ -966,6 +985,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
String fontName = getInternalFontNameForArea(text);
int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
String ptr = (String)text.getTrait(Trait.PTR); // used for accessibility
+ establishStructurePointer(ptr);
// This assumes that *all* CIDFonts use a /ToUnicode mapping
Typeface tf = getTypeface(fontName);
@@ -984,9 +1004,10 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
textUtil.setStartPosition(rx, bl);
textUtil.setSpacing(text.getTextLetterSpaceAdjust(), text.getTextWordSpaceAdjust());
super.renderText(text);
- textUtil.setPtr(ptr); // used for accessibility
+
textUtil.flush();
renderTextDecoration(tf, size, text, bl, rx);
+ resetStructurePointer();
}
/** {@inheritDoc} */
@@ -1061,20 +1082,11 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
private int startx, starty;
private int tls, tws;
private final boolean combined = false;
- private String ptr = null; // used for accessibility
void addChar(char ch) {
text.append(ch);
}
- /**
- * used for accessibility
- * @param inPtr to be stored
- */
- public void setPtr(String inPtr) {
- ptr = inPtr;
- }
-
void adjust(int adjust) {
if (adjust != 0) {
int idx = text.length();
@@ -1117,9 +1129,9 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
System.arraycopy(dx, 0, effDX, 0, size);
}
if (combined) {
- painter.drawText(startx, starty, 0, 0, effDX, text.toString(), ptr);
+ painter.drawText(startx, starty, 0, 0, effDX, text.toString());
} else {
- painter.drawText(startx, starty, tls, tws, effDX, text.toString(), ptr);
+ painter.drawText(startx, starty, tls, tws, effDX, text.toString());
}
} catch (IFException e) {
handleIFException(e);
@@ -1130,12 +1142,12 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
}
/** {@inheritDoc} */
- public void renderImage(Image image, Rectangle2D pos, String ptr) {
- drawImage(image.getURL(), pos, image.getForeignAttributes(), ptr);
+ public void renderImage(Image image, Rectangle2D pos) {
+ drawImage(image.getURL(), pos, image.getForeignAttributes());
}
/** {@inheritDoc} */
- protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes, String ptr) {
+ protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
Rectangle posInt = new Rectangle(
currentIPPosition + (int)pos.getX(),
currentBPPosition + (int)pos.getY(),
@@ -1144,7 +1156,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
uri = URISpecification.getURL(uri);
try {
establishForeignAttributes(foreignAttributes);
- painter.drawImage(uri, posInt, ptr);
+ painter.drawImage(uri, posInt);
resetForeignAttributes();
} catch (IFException ife) {
handleIFException(ife);
@@ -1152,7 +1164,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
}
/** {@inheritDoc} */
- public void renderForeignObject(ForeignObject fo, Rectangle2D pos, String ptr) {
+ public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
endTextObject();
Rectangle posInt = new Rectangle(
currentIPPosition + (int)pos.getX(),
@@ -1162,7 +1174,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
Document doc = fo.getDocument();
try {
establishForeignAttributes(fo.getForeignAttributes());
- painter.drawImage(doc, posInt, ptr);
+ painter.drawImage(doc, posInt);
resetForeignAttributes();
} catch (IFException ife) {
handleIFException(ife);
diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializer.java b/src/java/org/apache/fop/render/intermediate/IFSerializer.java
index 248492a96..2f5524c2c 100644
--- a/src/java/org/apache/fop/render/intermediate/IFSerializer.java
+++ b/src/java/org/apache/fop/render/intermediate/IFSerializer.java
@@ -267,7 +267,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler
if (id != null) {
atts.addAttribute(XML_NAMESPACE, "id", "xml:id", XMLUtil.CDATA, id);
}
-
+ addForeignAttributes(atts);
handler.startElement(EL_PAGE_SEQUENCE, atts);
if (this.getUserAgent().isAccessibilityEnabled()) {
if (doc == null) {
@@ -463,7 +463,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler
}
/** {@inheritDoc} */
- public void drawImage(String uri, Rectangle rect, String ptr) throws IFException {
+ public void drawImage(String uri, Rectangle rect) throws IFException {
try {
AttributesImpl atts = new AttributesImpl();
addAttribute(atts, XLINK_HREF, uri);
@@ -472,6 +472,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler
addAttribute(atts, "width", Integer.toString(rect.width));
addAttribute(atts, "height", Integer.toString(rect.height));
addForeignAttributes(atts);
+ String ptr = getContext().getStructurePointer();
if (ptr != null) {
addAttribute(atts, "ptr", ptr); // used for accessibility
}
@@ -493,7 +494,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler
}
/** {@inheritDoc} */
- public void drawImage(Document doc, Rectangle rect, String ptr) throws IFException {
+ public void drawImage(Document doc, Rectangle rect) throws IFException {
try {
AttributesImpl atts = new AttributesImpl();
addAttribute(atts, "x", Integer.toString(rect.x));
@@ -501,6 +502,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler
addAttribute(atts, "width", Integer.toString(rect.width));
addAttribute(atts, "height", Integer.toString(rect.height));
addForeignAttributes(atts);
+ String ptr = getContext().getStructurePointer();
if (ptr != null) {
addAttribute(atts, "ptr", ptr); // used for accessibility
}
@@ -602,7 +604,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler
/** {@inheritDoc} */
public void drawText(int x, int y, int letterSpacing, int wordSpacing,
- int[] dx, String text, String ptr) throws IFException {
+ int[] dx, String text) throws IFException {
try {
AttributesImpl atts = new AttributesImpl();
XMLUtil.addAttribute(atts, XMLConstants.XML_SPACE, "preserve");
@@ -617,6 +619,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler
if (dx != null) {
addAttribute(atts, "dx", IFUtil.toString(dx));
}
+ String ptr = getContext().getStructurePointer();
if (ptr != null) {
addAttribute(atts, "ptr", ptr); // used for accessibility
}