aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-04-16 09:10:37 +0000
committerJeremias Maerki <jeremias@apache.org>2009-04-16 09:10:37 +0000
commit5a0c020ad1330df3b6c94cef63698344dfbada00 (patch)
treeeea1c037e7c2921ea7da3e95c95b859b94ad7f26 /src/java/org
parent721ef295c32495df02023a22d3c3de13ebb6697f (diff)
downloadxmlgraphics-fop-5a0c020ad1330df3b6c94cef63698344dfbada00.tar.gz
xmlgraphics-fop-5a0c020ad1330df3b6c94cef63698344dfbada00.zip
Fixed some bugs concerning marked content generation inside leaders (use-content case).
Removed marked content logic from PDFTextUtil and concentrated it in PDFContentGenerator to make Artifact generation more uniform. Not only text generates Artifacts but inside leaders images can also be Artifacts. Some code simplifications. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@765525 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/fop/pdf/PDFTextUtil.java52
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFContentGenerator.java46
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java18
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java2
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFPainter.java66
5 files changed, 72 insertions, 112 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFTextUtil.java b/src/java/org/apache/fop/pdf/PDFTextUtil.java
index bb8816995..6640f9b80 100644
--- a/src/java/org/apache/fop/pdf/PDFTextUtil.java
+++ b/src/java/org/apache/fop/pdf/PDFTextUtil.java
@@ -48,7 +48,6 @@ public abstract class PDFTextUtil {
public static final int TR_CLIP = 7;
private boolean inTextObject = false;
- private boolean artifactMode = false;
private String startText;
private String endText;
private boolean useMultiByte;
@@ -117,15 +116,6 @@ public abstract class PDFTextUtil {
}
/**
- * Indicates whether we are in a text object and if that text object represents
- * an artifact.
- * @return true if in artifact-mode text object
- */
- public boolean inArtifactMode() {
- return this.artifactMode;
- }
-
- /**
* Called when a new text object should be started. Be sure to call setFont() before
* issuing any text painting commands.
*/
@@ -138,51 +128,11 @@ public abstract class PDFTextUtil {
}
/**
- * Begin of a regular text object, used for accessibility
- * @param mcid of text object
- * @param structElemType of parent
- */
- public void beginTextObjectAccess(int mcid, String structElemType) {
- if (inTextObject) {
- throw new IllegalStateException("Already in text object");
- }
- write(structElemType + " <</MCID "
- + String.valueOf(mcid) + ">>\nBDC\nBT\n");
- this.inTextObject = true;
- }
-
- /**
- * Begin of a text object marked as artifact (fo:leader in XSL-FO) text object.
- * Used for accessibility.
- */
- public void beginArtifactTextObject() {
- if (inTextObject) {
- throw new IllegalStateException("Already in text object");
- }
- write("/Artifact\nBMC\nBT\n");
- this.inTextObject = true;
- this.artifactMode = true;
- }
-
- /**
* Called when a text object should be ended.
*/
public void endTextObject() {
- endTextObject(false);
- }
-
- /**
- * Called when a text object should be ended.
- * @param accessEnabled indicating if accessibility is turned on or not
- */
- public void endTextObject(boolean accessEnabled) {
checkInTextObject();
- if (accessEnabled) {
- write("ET\nEMC\n");
- } else {
- write("ET\n");
- }
- this.artifactMode = false;
+ write("ET\n");
this.inTextObject = false;
initValues();
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java b/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
index 750f9a3cf..5f9256e9e 100644
--- a/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
+++ b/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
@@ -57,6 +57,7 @@ public class PDFContentGenerator {
/** Text generation utility holding the current font status */
protected PDFTextUtil textutil;
+ private boolean inArtifactMode;
/**
* Main constructor. Creates a new PDF stream and additional helper classes for text painting
@@ -160,17 +161,31 @@ public class PDFContentGenerator {
protected void saveGraphicsState(String structElemType, int sequenceNum) {
endTextObject();
currentState.save();
- startAccessSequence(structElemType, sequenceNum);
+ beginMarkedContentSequence(structElemType, sequenceNum);
currentStream.add("q\n");
}
/**
- * Used for accessibility
+ * Begins a new marked content sequence (BDC or BMC). If the parameter structElemType is null,
+ * the sequenceNum is ignored and instead of a BDC with the MCID as parameter, an "Artifact"
+ * and a BMC command is generated.
* @param structElemType Structure Element Type
* @param sequenceNum Sequence number
*/
- protected void startAccessSequence(String structElemType, int sequenceNum) {
- currentStream.add(structElemType + " <</MCID " + String.valueOf(sequenceNum) + ">>\nBDC\n");
+ protected void beginMarkedContentSequence(String structElemType, int sequenceNum) {
+ assert !this.inArtifactMode;
+ if (structElemType != null) {
+ currentStream.add(structElemType + " <</MCID " + String.valueOf(sequenceNum) + ">>\n"
+ + "BDC\n");
+ } else {
+ currentStream.add("/Artifact\nBMC\n");
+ this.inArtifactMode = true;
+ }
+ }
+
+ private void endMarkedContentSequence() {
+ currentStream.add("EMC\n");
+ this.inArtifactMode = false;
}
/**
@@ -195,7 +210,7 @@ public class PDFContentGenerator {
protected void restoreGraphicsStateAccess() {
endTextObject();
currentStream.add("Q\n");
- currentStream.add("EMC\n");
+ endMarkedContentSequence();
currentState.restore();
}
@@ -205,8 +220,10 @@ public class PDFContentGenerator {
* @param structElemType of parent of new text element
*/
protected void separateTextElements(int mcid, String structElemType) {
- textutil.endTextObject(true);
- textutil.beginTextObjectAccess(mcid, structElemType);
+ textutil.endTextObject();
+ endMarkedContentSequence();
+ beginMarkedContentSequence(structElemType, mcid);
+ textutil.beginTextObject();
}
/**
@@ -214,9 +231,8 @@ public class PDFContentGenerator {
* separates a text element from fo:leader text element
*/
public void separateTextElementFromLeader() {
- if (!textutil.inArtifactMode()) {
- textutil.endTextObject(true);
- textutil.beginArtifactTextObject();
+ if (!inArtifactMode) {
+ separateTextElements(0, null);
}
}
@@ -234,7 +250,8 @@ public class PDFContentGenerator {
*/
protected void beginTextObjectAccess(int mcid, String structElemType) {
if (!textutil.isInTextObject()) {
- textutil.beginTextObjectAccess(mcid, structElemType);
+ beginMarkedContentSequence(structElemType, mcid);
+ textutil.beginTextObject();
}
}
@@ -242,15 +259,14 @@ public class PDFContentGenerator {
* Accessibility begin of LeaderTextObject
*/
public void beginLeaderTextObject() {
- if (!textutil.isInTextObject()) {
- textutil.beginArtifactTextObject();
- }
+ beginTextObjectAccess(0, null);
}
/** Indicates the end of a text object. */
protected void endTextObject() {
if (textutil.isInTextObject()) {
- textutil.endTextObject(accessEnabled);
+ endMarkedContentSequence();
+ textutil.endTextObject();
}
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java b/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
index 7df6c9fee..0a975efc3 100644
--- a/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
+++ b/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
@@ -520,15 +520,19 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
* @param mcid sequence number within page
*/
void addChildToStructElemText(String ptr, int mcid) {
- PDFDictionary dict = new PDFDictionary();
- dict.put("Type", new PDFName("MCR"));
- dict.put("Pg", this.currentPage);
- dict.put("MCID", mcid);
PDFStructElem tempStructElem = (PDFStructElem) structTreeMap.get(ptr);
- tempStructElem.addKid(dict);
- if (!tempStructElem.getLevel1()) {
- addMeToParent(tempStructElem);
+ if (tempStructElem != null) {
+ PDFDictionary dict = new PDFDictionary();
+ dict.put("Type", new PDFName("MCR"));
+ dict.put("Pg", this.currentPage);
+ dict.put("MCID", mcid);
+ tempStructElem.addKid(dict);
+ if (!tempStructElem.getLevel1()) {
+ addMeToParent(tempStructElem);
+ }
}
+ //tempStructElem is null, for example inside fo:leaders in which case
+ //the text shall be marked as artifact
}
/**
diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java
index c405a2f2a..fde9e0696 100644
--- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java
+++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java
@@ -124,7 +124,7 @@ public class PDFImageHandlerSVG implements ImageHandler {
if (context.getUserAgent().isAccessibilityEnabled()) {
String structElemType = pdfContext.getStructElemType();
int sequenceNum = pdfContext.getSequenceNum();
- generator.startAccessSequence(structElemType, sequenceNum);
+ generator.beginMarkedContentSequence(structElemType, sequenceNum);
}
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 3ab32114c..4c9baf0f6 100644
--- a/src/java/org/apache/fop/render/pdf/PDFPainter.java
+++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java
@@ -135,19 +135,9 @@ public class PDFPainter extends AbstractIFPainter {
if (xobject != null) {
if (accessEnabled && getContext().hasStructurePointer()) {
String ptr = getContext().getStructurePointer();
- mcid = this.documentHandler.getMCID();
- mcid++; // fix for Acro Checker
- this.documentHandler.incMCID(); // simulating a parent text element
- structElemType = this.documentHandler.getStructElemType(ptr);
- this.documentHandler.addToTempList(
- this.documentHandler.getCurrentParentTreeKey(),
- this.documentHandler.getParentTrailerObject(ptr));
- this.documentHandler.addToTempList(
- this.documentHandler.getCurrentParentTreeKey(),
- this.documentHandler.getTrailerObject(ptr));
+ prepareImageMCID(ptr);
placeImageAccess(rect, xobject);
- this.documentHandler.addChildToStructElemImage(ptr, mcid);
- this.documentHandler.incMCID();
+ addImageMCID(ptr);
} else {
placeImage(rect, xobject);
}
@@ -155,27 +145,36 @@ public class PDFPainter extends AbstractIFPainter {
}
if (accessEnabled && getContext().hasStructurePointer()) {
String ptr = getContext().getStructurePointer();
- mcid = this.documentHandler.getMCID();
- mcid++; // fix for Acro Checker
- this.documentHandler.incMCID(); // simulating a parent text element
- structElemType = this.documentHandler.getStructElemType(ptr);
+ prepareImageMCID(ptr);
+ drawImageUsingURI(uri, rect);
+ addImageMCID(ptr);
+ } else {
+ drawImageUsingURI(uri, rect);
+ }
+ flushPDFDoc();
+ }
+
+ private void prepareImageMCID(String ptr) {
+ mcid = this.documentHandler.getMCID();
+ mcid++; // fix for Acro Checker
+ this.documentHandler.incMCID(); // simulating a parent text element
+ structElemType = this.documentHandler.getStructElemType(ptr);
+ if (structElemType != null) {
this.documentHandler.addToTempList(
this.documentHandler.getCurrentParentTreeKey(),
this.documentHandler.getParentTrailerObject(ptr));
this.documentHandler.addToTempList(
this.documentHandler.getCurrentParentTreeKey(),
this.documentHandler.getTrailerObject(ptr));
- //PDFRenderingContext pdfContext = new PDFRenderingContext(
- // getUserAgent(), generator, this.documentHandler.currentPage, getFontInfo());
- //pdfContext.setMCID(mcid);
- //pdfContext.setStructElemType(structElemType);
- drawImageUsingURI(uri, rect);
+ }
+ }
+
+ private void addImageMCID(String ptr) {
+ if (this.structElemType != null) {
this.documentHandler.addChildToStructElemImage(ptr, mcid);
this.documentHandler.incMCID();
- } else {
- drawImageUsingURI(uri, rect);
}
- flushPDFDoc();
+ //If structElemType is null, it means "Artifact" mode (ex. leader with use-content).
}
/** {@inheritDoc} */
@@ -226,19 +225,9 @@ public class PDFPainter extends AbstractIFPainter {
public void drawImage(Document doc, Rectangle rect) throws IFException {
if (accessEnabled && getContext().hasStructurePointer()) {
String ptr = getContext().getStructurePointer();
- mcid = this.documentHandler.getMCID();
- mcid++; // fix for Acro Checker
- this.documentHandler.incMCID(); // simulating a parent text element
- structElemType = this.documentHandler.getStructElemType(ptr);
- this.documentHandler.addToTempList(
- this.documentHandler.getCurrentParentTreeKey(),
- this.documentHandler.getParentTrailerObject(ptr));
- this.documentHandler.addToTempList(
- this.documentHandler.getCurrentParentTreeKey(),
- this.documentHandler.getTrailerObject(ptr));
+ prepareImageMCID(ptr);
drawImageUsingDocument(doc, rect);
- this.documentHandler.addChildToStructElemImage(ptr, mcid);
- this.documentHandler.incMCID();
+ addImageMCID(ptr);
} else {
drawImageUsingDocument(doc, rect);
}
@@ -338,13 +327,13 @@ public class PDFPainter extends AbstractIFPainter {
if (accessEnabled) {
String ptr = getContext().getStructurePointer();
int mcId;
- String structElType = "";
+ String structElType = null;
if (ptr != null && ptr.length() > 0) {
mcId = this.documentHandler.getMCID();
+ structElType = this.documentHandler.getStructElemType(ptr);
this.documentHandler.addToTempList(
this.documentHandler.getCurrentParentTreeKey(),
this.documentHandler.getTrailerObject(ptr));
- structElType = this.documentHandler.getStructElemType(ptr);
if (generator.getTextUtil().isInTextObject()) {
generator.separateTextElements(mcId, structElType);
}
@@ -354,6 +343,7 @@ public class PDFPainter extends AbstractIFPainter {
this.documentHandler.incMCID();
} else {
// <fo:leader leader-pattern="use-content">
+ // Leader content is marked as "/Artifact"
if (generator.getTextUtil().isInTextObject()) {
generator.separateTextElementFromLeader();
}