aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/area
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-01-28 15:04:39 +0000
committerJeremias Maerki <jeremias@apache.org>2008-01-28 15:04:39 +0000
commit1ea8b13df56f773fc3d28a9a4b69ed1ed8b97cf4 (patch)
treeaa175e32ee1cee808287fee13ff980747cfcc262 /src/java/org/apache/fop/area
parent74b2adc7ebb1c898d17bc5778de412522512d4c8 (diff)
downloadxmlgraphics-fop-1ea8b13df56f773fc3d28a9a4b69ed1ed8b97cf4.tar.gz
xmlgraphics-fop-1ea8b13df56f773fc3d28a9a4b69ed1ed8b97cf4.zip
Added support for the natural language indentifier ("Lang" in the document catalog) for PDF documents based on the language/country values on fo:page-sequence. This required a few changes in the AreaTreeModel and the Renderer interface because it didn't support passing through the PageSequence object, only its title. Now, we can put other values on the PageSequence and transport them to the renderers.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@615906 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/area')
-rw-r--r--src/java/org/apache/fop/area/AreaTreeModel.java19
-rw-r--r--src/java/org/apache/fop/area/AreaTreeParser.java21
-rw-r--r--src/java/org/apache/fop/area/PageSequence.java53
-rw-r--r--src/java/org/apache/fop/area/RenderPagesModel.java17
4 files changed, 84 insertions, 26 deletions
diff --git a/src/java/org/apache/fop/area/AreaTreeModel.java b/src/java/org/apache/fop/area/AreaTreeModel.java
index bdbb88f2a..c43db31bb 100644
--- a/src/java/org/apache/fop/area/AreaTreeModel.java
+++ b/src/java/org/apache/fop/area/AreaTreeModel.java
@@ -22,10 +22,8 @@ package org.apache.fop.area;
// Java
import java.util.List;
-// XML
import org.xml.sax.SAXException;
-// Apache
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -55,10 +53,13 @@ public class AreaTreeModel {
/**
* Start a page sequence on this model.
- * @param title the title of the new page sequence
+ * @param pageSequence the page sequence about to start
*/
- public void startPageSequence(LineArea title) {
- currentPageSequence = new PageSequence(title);
+ public void startPageSequence(PageSequence pageSequence) {
+ if (pageSequence == null) {
+ throw new NullPointerException("pageSequence must not be null");
+ }
+ this.currentPageSequence = pageSequence;
pageSequenceList.add(currentPageSequence);
currentPageSequenceIndex = pageSequenceList.size() - 1;
}
@@ -91,6 +92,14 @@ public class AreaTreeModel {
public void endDocument() throws SAXException {};
/**
+ * Returns the currently active page-sequence.
+ * @return the currently active page-sequence
+ */
+ public PageSequence getCurrentPageSequence() {
+ return this.currentPageSequence;
+ }
+
+ /**
* Get the page sequence count.
* @return the number of page sequences in the document.
*/
diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java
index d4cdf5239..fafb99ed6 100644
--- a/src/java/org/apache/fop/area/AreaTreeParser.java
+++ b/src/java/org/apache/fop/area/AreaTreeParser.java
@@ -141,7 +141,6 @@ public class AreaTreeParser {
private Stack areaStack = new Stack();
private boolean firstFlow;
- private boolean pendingStartPageSequence;
private Stack delegateStack = new Stack();
private ContentHandler delegate;
@@ -349,8 +348,12 @@ public class AreaTreeParser {
private class PageSequenceMaker extends AbstractMaker {
public void startElement(Attributes attributes) {
- pendingStartPageSequence = true;
- //treeModel.startPageSequence(null); Done after title or on the first viewport
+ PageSequence pageSequence = new PageSequence(null);
+ String lang = attributes.getValue("language");
+ pageSequence.setLanguage(lang);
+ String country = attributes.getValue("country");
+ pageSequence.setCountry(country);
+ areaStack.push(pageSequence);
}
}
@@ -364,19 +367,19 @@ public class AreaTreeParser {
public void endElement() {
LineArea line = (LineArea)areaStack.pop();
- treeModel.startPageSequence(line);
- pendingStartPageSequence = false;
+ PageSequence pageSequence = (PageSequence)areaStack.peek();
+ pageSequence.setTitle(line);
}
-
}
private class PageViewportMaker extends AbstractMaker {
public void startElement(Attributes attributes) {
- if (pendingStartPageSequence) {
- treeModel.startPageSequence(null);
- pendingStartPageSequence = false;
+ if (!areaStack.isEmpty()) {
+ PageSequence pageSequence = (PageSequence)areaStack.peek();
+ treeModel.startPageSequence(pageSequence);
+ areaStack.pop();
}
if (currentPageViewport != null) {
throw new IllegalStateException("currentPageViewport must be null");
diff --git a/src/java/org/apache/fop/area/PageSequence.java b/src/java/org/apache/fop/area/PageSequence.java
index d39ec7cf2..3b65f7701 100644
--- a/src/java/org/apache/fop/area/PageSequence.java
+++ b/src/java/org/apache/fop/area/PageSequence.java
@@ -28,13 +28,15 @@ public class PageSequence {
private List pages = new java.util.ArrayList();
private LineArea title;
+ private String language;
+ private String country;
/**
* Main constructor
* @param title the title for the page-sequence, may be null
*/
public PageSequence(LineArea title) {
- this.title = title;
+ setTitle(title);
}
/**
@@ -45,6 +47,14 @@ public class PageSequence {
}
/**
+ * Sets the page sequence's title.
+ * @param title the title
+ */
+ public void setTitle(LineArea title) {
+ this.title = title;
+ }
+
+ /**
* Adds a new page to the page sequence
* @param page the page to be added
*/
@@ -76,4 +86,45 @@ public class PageSequence {
public boolean isFirstPage(PageViewport page) {
return page.equals(getPage(0));
}
+
+ /**
+ * Returns the language of the page-sequence.
+ * @return the language (the value of the language property, "none" is mapped to null)
+ */
+ public String getLanguage() {
+ return this.language;
+ }
+
+ /**
+ * Sets the language that applies to this page-sequence.
+ * @param language the language to set ("none" is mapped to null)
+ */
+ public void setLanguage(String language) {
+ if ("none".equals(language)) {
+ this.language = null;
+ } else {
+ this.language = language;
+ }
+ }
+
+ /**
+ * Returns the country of the page-sequence.
+ * @return the country (the value of the country property, "none" is mapped to null)
+ */
+ public String getCountry() {
+ return this.country;
+ }
+
+ /**
+ * Sets the country that applies to this page-sequence.
+ * @param country the country to set ("none" is mapped to null)
+ */
+ public void setCountry(String country) {
+ if ("none".equals(country)) {
+ this.country = null;
+ } else {
+ this.country = country;
+ }
+ }
+
}
diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java
index 1b3a22706..e080e9cbe 100644
--- a/src/java/org/apache/fop/area/RenderPagesModel.java
+++ b/src/java/org/apache/fop/area/RenderPagesModel.java
@@ -81,16 +81,11 @@ public class RenderPagesModel extends AreaTreeModel {
}
}
- /**
- * Start a new page sequence.
- * This tells the renderer that a new page sequence has
- * started with the given title.
- * @param title the title of the new page sequence
- */
- public void startPageSequence(LineArea title) {
- super.startPageSequence(title);
+ /** {@inheritDoc} */
+ public void startPageSequence(PageSequence pageSequence) {
+ super.startPageSequence(pageSequence);
if (renderer.supportsOutOfOrder()) {
- renderer.startPageSequence(title);
+ renderer.startPageSequence(getCurrentPageSequence());
}
}
@@ -112,7 +107,7 @@ public class RenderPagesModel extends AreaTreeModel {
boolean ready = renderer.supportsOutOfOrder() && page.isResolved();
if (ready) {
if (!renderer.supportsOutOfOrder() && page.getPageSequence().isFirstPage(page)) {
- renderer.startPageSequence(this.currentPageSequence.getTitle());
+ renderer.startPageSequence(getCurrentPageSequence());
}
try {
renderer.renderPage(page);
@@ -159,7 +154,7 @@ public class RenderPagesModel extends AreaTreeModel {
if (pageViewport.isResolved() || renderUnresolved) {
if (!renderer.supportsOutOfOrder()
&& pageViewport.getPageSequence().isFirstPage(pageViewport)) {
- renderer.startPageSequence(this.currentPageSequence.getTitle());
+ renderer.startPageSequence(getCurrentPageSequence());
}
try {
renderer.renderPage(pageViewport);