From 03f05c5dc588e40037ce77f742e39fe1eb45cb1e Mon Sep 17 00:00:00 2001
From: Simon Pepping
Date: Thu, 20 Jan 2011 16:05:42 +0000
Subject: Avoid deconstructing and reconstructing the base URI of the
configuration; the location string is obtained from a sax.Locator with system
ID, line number and optionally column number
(avalon.framework.configuration.SAXConfigurationHandler.getLocationString),
and can be used as a URI string directly.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1061362 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/apps/FopFactoryConfigurator.java | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/src/java/org/apache/fop/apps/FopFactoryConfigurator.java b/src/java/org/apache/fop/apps/FopFactoryConfigurator.java
index 9de00cd85..9097f23e3 100644
--- a/src/java/org/apache/fop/apps/FopFactoryConfigurator.java
+++ b/src/java/org/apache/fop/apps/FopFactoryConfigurator.java
@@ -378,15 +378,9 @@ public class FopFactoryConfigurator {
private void setBaseURI() throws FOPException {
String loc = cfg.getLocation();
- String[] locationParts = (loc != null ? cfg.getLocation().split(":") : null);
try {
- if (locationParts != null && locationParts.length >= 2
- && "file".equals(locationParts[0])) {
- StringBuilder sb = new StringBuilder(locationParts[1]);
- for (int idx = 2; idx < locationParts.length; idx++) {
- sb.append(":").append(locationParts[idx]);
- }
- baseURI = new URI(locationParts[0], sb.toString(), null);
+ if (loc != null && loc.startsWith("file:")) {
+ baseURI = new URI(loc);
baseURI = baseURI.resolve(".").normalize();
}
if (baseURI == null) {
--
cgit v1.2.3
From 93e2a5192a5163ceac8f400ced467add3ae87fec Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Fri, 21 Jan 2011 06:54:39 +0000
Subject: Fix for paths with spaces. Submitted by: Carl Hoffman/Glenn Adams
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1061652 13f79535-47bb-0310-9956-ffa450edef68
---
fop.cmd | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fop.cmd b/fop.cmd
index b8bfb2096..3a0538d5e 100644
--- a/fop.cmd
+++ b/fop.cmd
@@ -19,7 +19,7 @@ SETLOCAL ENABLEDELAYEDEXPANSION
rem %~dp0 is the expanded pathname of the current script under NT
set LOCAL_FOP_HOME=
-if "%OS%"=="Windows_NT" set LOCAL_FOP_HOME=%~dp0
+if "%OS%"=="Windows_NT" set LOCAL_FOP_HOME="%~dp0"
rem Code from Apache Ant project
rem Slurp the command line arguments. This loop allows for an unlimited number
--
cgit v1.2.3
From a712bc8cdc1bbbcc3e7ee1ac79c0e887b79e8b9d Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Fri, 21 Jan 2011 08:21:12 +0000
Subject: Reduced task attribute redundancy by using . Added
maxmemory="256m" on junit instead of a JVM argument to overcome
OutOfMemoryErrors that I have since moving to Windows 7 64bit.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1061678 13f79535-47bb-0310-9956-ffa450edef68
---
build.xml | 48 ++++++++++++++++++++++++++++++------------------
1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/build.xml b/build.xml
index bc515dff0..c63de4004 100644
--- a/build.xml
+++ b/build.xml
@@ -205,8 +205,21 @@ list of possible build targets.
- -->
-
+-->
+
+
+
+
+
+
+
+
+
+
@@ -332,7 +345,7 @@ list of possible build targets.
-
+
@@ -341,7 +354,7 @@ list of possible build targets.
-
+
@@ -353,7 +366,7 @@ list of possible build targets.
-
+
@@ -417,7 +430,7 @@ list of possible build targets.
-
+
@@ -697,7 +710,7 @@ list of possible build targets.
-
+
@@ -733,7 +746,7 @@ list of possible build targets.
-
+
@@ -755,7 +768,7 @@ list of possible build targets.
previous test block succeeded it indicates that the packaging of the allinone
JAR needs to be updated.
-->
-
+
@@ -778,8 +791,7 @@ list of possible build targets.
-
-
+
@@ -796,7 +808,7 @@ list of possible build targets.
-
+
@@ -832,7 +844,7 @@ list of possible build targets.
-
+
@@ -849,7 +861,7 @@ list of possible build targets.
-
+
@@ -867,7 +879,7 @@ list of possible build targets.
-
+
@@ -891,7 +903,7 @@ list of possible build targets.
-
+
@@ -928,7 +940,7 @@ list of possible build targets.
-
+
@@ -1417,7 +1429,7 @@ NOTE:
-
+
--
cgit v1.2.3
From 57d30ce11144107318c7620941dac47c5bb7540d Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sat, 22 Jan 2011 18:28:57 +0000
Subject: Bugzilla 50626: Fix potential performance issue when adding nodes.
Thanks to mkoegler.AT.auto.tuwien.ac.at.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1062225 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/fo/FObj.java | 45 ++++++++++++++++++++++++++++--------
1 file changed, 35 insertions(+), 10 deletions(-)
diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java
index 34e29a58a..66bf1a15d 100644
--- a/src/java/org/apache/fop/fo/FObj.java
+++ b/src/java/org/apache/fop/fo/FObj.java
@@ -51,12 +51,13 @@ public abstract class FObj extends FONode implements Constants {
* pointer to the descendant subtree
*/
protected FONode firstChild;
+ protected FONode lastChild;
/** The list of extension attachments, null if none */
- private List/**/ extensionAttachments = null;
+ private List extensionAttachments = null;
/** The map of foreign attributes, null if none */
- private Map/**/ foreignAttributes = null;
+ private Map foreignAttributes = null;
/** Used to indicate if this FO is either an Out Of Line FO (see rec)
* or a descendant of one. Used during FO validation.
@@ -197,13 +198,19 @@ public abstract class FObj extends FONode implements Constants {
} else {
if (firstChild == null) {
firstChild = child;
+ lastChild = child;
} else {
- FONode prevChild = firstChild;
- while (prevChild.siblings != null
- && prevChild.siblings[1] != null) {
- prevChild = prevChild.siblings[1];
+ if (lastChild == null) {
+ FONode prevChild = firstChild;
+ while (prevChild.siblings != null
+ && prevChild.siblings[1] != null) {
+ prevChild = prevChild.siblings[1];
+ }
+ FONode.attachSiblings(prevChild, child);
+ } else {
+ FONode.attachSiblings(lastChild, child);
+ lastChild = child;
}
- FONode.attachSiblings(prevChild, child);
}
}
}
@@ -238,6 +245,13 @@ public abstract class FObj extends FONode implements Constants {
nextChild.siblings[0] = prevChild;
}
}
+ if (child == lastChild) {
+ if (child.siblings != null) {
+ lastChild = siblings[0];
+ } else {
+ lastChild = null;
+ }
+ }
}
/**
@@ -421,6 +435,7 @@ public abstract class FObj extends FONode implements Constants {
* Convenience method for validity checking. Checks if the
* incoming node is a member of the "%block;" parameter entity
* as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
+ *
* @param nsURI namespace URI of incoming node
* @param lName local name (i.e., no prefix) of incoming node
* @return true if a member, false if not
@@ -440,6 +455,7 @@ public abstract class FObj extends FONode implements Constants {
* Convenience method for validity checking. Checks if the
* incoming node is a member of the "%inline;" parameter entity
* as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
+ *
* @param nsURI namespace URI of incoming node
* @param lName local name (i.e., no prefix) of incoming node
* @return true if a member, false if not
@@ -529,7 +545,7 @@ public abstract class FObj extends FONode implements Constants {
/** @return whether this object has an id set */
public boolean hasId() {
- return id != null && id.length() > 0;
+ return (id != null && id.length() > 0);
}
/** {@inheritDoc} */
@@ -554,7 +570,7 @@ public abstract class FObj extends FONode implements Constants {
"Parameter attachment must not be null");
}
if (extensionAttachments == null) {
- extensionAttachments = new java.util.ArrayList/**/();
+ extensionAttachments = new java.util.ArrayList();
}
if (log.isDebugEnabled()) {
log.debug("ExtensionAttachment of category "
@@ -591,7 +607,7 @@ public abstract class FObj extends FONode implements Constants {
throw new NullPointerException("Parameter attributeName must not be null");
}
if (foreignAttributes == null) {
- foreignAttributes = new java.util.HashMap/**/();
+ foreignAttributes = new java.util.HashMap();
}
foreignAttributes.put(attributeName, value);
}
@@ -679,6 +695,9 @@ public abstract class FObj extends FONode implements Constants {
&& currentNode.siblings[1] != null) {
FONode.attachSiblings(newNode, currentNode.siblings[1]);
}
+ if (currentNode == parentNode.lastChild) {
+ parentNode.lastChild = newNode;
+ }
} else {
throw new IllegalStateException();
}
@@ -694,12 +713,18 @@ public abstract class FObj extends FONode implements Constants {
parentNode.firstChild = newNode;
currentIndex = 0;
currentNode = newNode;
+ if (parentNode.lastChild == null) {
+ parentNode.lastChild = newNode;
+ }
} else {
if (currentNode.siblings != null
&& currentNode.siblings[1] != null) {
FONode.attachSiblings((FONode) o, currentNode.siblings[1]);
}
FONode.attachSiblings(currentNode, (FONode) o);
+ if (currentNode == parentNode.lastChild) {
+ parentNode.lastChild = newNode;
+ }
}
flags &= F_NONE_ALLOWED;
}
--
cgit v1.2.3
From b970c338ba74b78e16b10c0b38b71b33df49fb36 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sat, 22 Jan 2011 19:09:00 +0000
Subject: Minor fixups: extract addAttributeToList() + no reason to first check
the attributeValue to ignore namespace declarations
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1062236 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/fo/PropertyList.java | 48 +++++++++++++---------------
1 file changed, 22 insertions(+), 26 deletions(-)
diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java
index 709c4303b..8d5a4311f 100644
--- a/src/java/org/apache/fop/fo/PropertyList.java
+++ b/src/java/org/apache/fop/fo/PropertyList.java
@@ -264,6 +264,13 @@ public abstract class PropertyList {
return -1;
}
+ private String addAttributeToList(Attributes attributes,
+ String attributeName) throws ValidationException {
+ String attributeValue = attributes.getValue(attributeName);
+ convertAttributeToProperty(attributes, attributeName, attributeValue);
+ return attributeValue;
+ }
+
/**
* Adds the attributes, passed in by the parser to the PropertyList
*
@@ -278,39 +285,29 @@ public abstract class PropertyList {
* need them before all others (possible from-table-column() on any
* other property further in the list...
*/
- String attributeName = "column-number";
- String attributeValue = attributes.getValue(attributeName);
- convertAttributeToProperty(attributes, attributeName,
- attributeValue);
- attributeName = "number-columns-spanned";
- attributeValue = attributes.getValue(attributeName);
- convertAttributeToProperty(attributes, attributeName,
- attributeValue);
+ addAttributeToList(attributes, "column-number");
+ addAttributeToList(attributes, "number-columns-spanned");
/*
* If font-size is set on this FO, must set it first, since
* other attributes specified in terms of "ems" depend on it.
*/
- attributeName = "font";
- attributeValue = attributes.getValue(attributeName);
- convertAttributeToProperty(attributes, attributeName,
- attributeValue);
- if (attributeValue == null) {
+ String checkValue = addAttributeToList(attributes, "font");
+ if (checkValue == null || "".equals(checkValue)) {
/*
* font shorthand wasn't specified, so still need to process
* explicit font-size
*/
- attributeName = "font-size";
- attributeValue = attributes.getValue(attributeName);
- convertAttributeToProperty(attributes, attributeName,
- attributeValue);
+ addAttributeToList(attributes, "font-size");
}
+ String attributeName;
+ String attributeValue;
String attributeNS;
FopFactory factory = getFObj().getUserAgent().getFactory();
for (int i = 0; i < attributes.getLength(); i++) {
/* convert all attributes with the same namespace as the fo element
- * the "xml:lang" property is a special case */
+ * the "xml:lang" and "xml:base" properties are special cases */
attributeNS = attributes.getURI(i);
attributeName = attributes.getQName(i);
attributeValue = attributes.getValue(i);
@@ -368,15 +365,14 @@ public abstract class PropertyList {
String attributeValue)
throws ValidationException {
- if (attributeValue != null) {
-
- if (attributeName.startsWith("xmlns:")
- || "xmlns".equals(attributeName)) {
- //Ignore namespace declarations if the XML parser/XSLT processor
- //reports them as 'regular' attributes
- return;
- }
+ if (attributeName.startsWith("xmlns:")
+ || "xmlns".equals(attributeName)) {
+ /* Ignore namespace declarations if the XML parser/XSLT processor
+ * reports them as 'regular' attributes */
+ return;
+ }
+ if (attributeValue != null) {
/* Handle "compound" properties, ex. space-before.minimum */
String basePropertyName = findBasePropertyName(attributeName);
String subPropertyName = findSubPropertyName(attributeName);
--
cgit v1.2.3
From 881ef26a95f595c6606bb73a5853b81885b13cd1 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sat, 22 Jan 2011 19:15:11 +0000
Subject: Make HashMaps type safe + remove corresponding redundant casts and
unnecessary (un)boxing
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1062241 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/fo/FOPropertyMapping.java | 31 +++++++++++++----------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java
index c711a76c0..1aaa23bd6 100644
--- a/src/java/org/apache/fop/fo/FOPropertyMapping.java
+++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java
@@ -79,9 +79,12 @@ public final class FOPropertyMapping implements Constants {
private FOPropertyMapping() {
}
- private static Map propNames = new HashMap(); // CSOK: VisibilityModifier
- private static Map subPropNames = new HashMap(); // CSOK: VisibilityModifier
- private static Map propIds = new HashMap(); // CSOK: VisibilityModifier
+ private static Map propNames
+ = new HashMap(); // CSOK: VisibilityModifier
+ private static Map subPropNames
+ = new HashMap(); // CSOK: VisibilityModifier
+ private static Map propIds
+ = new HashMap(); // CSOK: VisibilityModifier
private static PropertyMaker[] generics = null; // CSOK: VisibilityModifier
@@ -246,8 +249,8 @@ public final class FOPropertyMapping implements Constants {
*/
private static void addPropertyMaker(String name, PropertyMaker maker) {
generics[maker.getPropId()] = maker;
- propNames.put(name, new Integer(maker.getPropId()));
- propIds.put(new Integer(maker.getPropId()), name);
+ propNames.put(name, maker.getPropId());
+ propIds.put(maker.getPropId(), name);
}
/**
@@ -256,8 +259,8 @@ public final class FOPropertyMapping implements Constants {
* @param id Id for the subproperty from CP_* in Constants.java.
*/
private static void addSubpropMakerName(String name, int id) {
- subPropNames.put(name, new Integer(id));
- propIds.put(new Integer(id), name);
+ subPropNames.put(name, id);
+ propIds.put(id, name);
}
/**
@@ -342,9 +345,9 @@ public final class FOPropertyMapping implements Constants {
*/
public static int getPropertyId(String name) {
if (name != null) {
- Integer i = (Integer) propNames.get(name);
+ Integer i = propNames.get(name);
if (i != null) {
- return i.intValue();
+ return i;
}
}
return -1;
@@ -357,9 +360,9 @@ public final class FOPropertyMapping implements Constants {
*/
public static int getSubPropertyId(String name) {
if (name != null) {
- Integer i = (Integer) subPropNames.get(name);
+ Integer i = subPropNames.get(name);
if (i != null) {
- return i.intValue();
+ return i;
}
}
return -1;
@@ -373,10 +376,10 @@ public final class FOPropertyMapping implements Constants {
public static String getPropertyName(int id) {
if (((id & Constants.COMPOUND_MASK) == 0)
|| ((id & Constants.PROPERTY_MASK) == 0)) {
- return (String) propIds.get(new Integer(id));
+ return propIds.get(id);
} else {
- return propIds.get(new Integer(id & Constants.PROPERTY_MASK))
- + "." + propIds.get(new Integer(id & Constants.COMPOUND_MASK));
+ return propIds.get(id & Constants.PROPERTY_MASK)
+ + "." + propIds.get(id & Constants.COMPOUND_MASK);
}
}
--
cgit v1.2.3
From a136c6faa5991fbfc60c64998da50e26a8f6660c Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Mon, 24 Jan 2011 09:55:52 +0000
Subject: FAQ entry for anti-aliasing artifacts in Adobe Acrobat.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1062710 13f79535-47bb-0310-9956-ffa450edef68
---
src/documentation/content/xdocs/faq.xml | 40 +++++++++++++++
.../images/acrobat-anti-aliasing-artifacts.png | Bin 0 -> 8128 bytes
.../images/anti-aliasing-artifacts-demo.fo | 57 +++++++++++++++++++++
3 files changed, 97 insertions(+)
create mode 100644 src/documentation/resources/images/acrobat-anti-aliasing-artifacts.png
create mode 100644 src/documentation/resources/images/anti-aliasing-artifacts-demo.fo
diff --git a/src/documentation/content/xdocs/faq.xml b/src/documentation/content/xdocs/faq.xml
index c2f6cb7ca..2fd6e16ca 100644
--- a/src/documentation/content/xdocs/faq.xml
+++ b/src/documentation/content/xdocs/faq.xml
@@ -1016,6 +1016,46 @@ Can I control this?
+
+ How can I get rid of strange single-pixel lines inside table borders or between table cells in Adobe Acrobat?
+
+
+ Since Apache FOP supports the collapsed border model, every border segment consists
+ of two separate shapes. This is due to the fact that each side of the border
+ segment can have a different color. Now, Adobe Acrobat may display thin (1 pixel wide)
+ lines inside the border segment or sometimes even between to adjacent
+ colored rectangles making up the background of a block or table cell.
+ This effect is due to the way Adobe Acrobat does anti-aliasing. Adobe's algorithm
+ seems to cause these artifacts. Other PDF viewers don't have that problem. Or at least
+ we haven't had any reports in that direction.
+
+
+ First of all, these artifacts do not appear in print since no anti-aliasing is done
+ by Adobe Acrobat in this case (except maybe if you tell Acrobat to print the page
+ as a bitmap in which case Adobe fully composes the page itself). So, if the artifacts appear
+ on screen, it doesn't mean they have to appear in print, too.
+
+
+ To get rid of the artifacts, you can call up the "Preferences" dialog of
+ Adobe Acrobat and select the tab "Page display". Enabling "Enhance thin lines"
+ may help in some situations. Otherwise, you can disable "Smooth line art".
+ You may have to disable "Use 2D graphics acceleration", too, so you can disable
+ "Smooth line art" in the first place.
+
+
+ Here an example of how the effect can look like (left: anti-aliasing on, right: anti-aliasing off):
+
+
+
+ Unfortunately, it is not possible to control the above settings from within the PDF file.
+ The user has to change these settings himself. Improving FOP to avoid this kind of problem
+ would be possible although rather hard to achieve because we'd need to add a considerable
+ amount of code to combine the various line segments. Something like that has been tried already
+ years ago showing that this is a tricky task. Also, the improvement may not justify the amount
+ of effort required.
+
+
+
IEx specific stuff
diff --git a/src/documentation/resources/images/acrobat-anti-aliasing-artifacts.png b/src/documentation/resources/images/acrobat-anti-aliasing-artifacts.png
new file mode 100644
index 000000000..db9c23a2a
Binary files /dev/null and b/src/documentation/resources/images/acrobat-anti-aliasing-artifacts.png differ
diff --git a/src/documentation/resources/images/anti-aliasing-artifacts-demo.fo b/src/documentation/resources/images/anti-aliasing-artifacts-demo.fo
new file mode 100644
index 000000000..5917e80e0
--- /dev/null
+++ b/src/documentation/resources/images/anti-aliasing-artifacts-demo.fo
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Cell 1/1
+
+
+ Cell 2/1
+
+
+
+
+ Cell 1/2
+
+
+ Cell 2/2
+
+
+
+
+
+
+
+
+
+
+
+ Cell 1/1
+
+
+ Cell 2/1
+
+
+
+
+ Cell 1/2
+
+
+ Cell 2/2
+
+
+
+
+
+
+
--
cgit v1.2.3
From 9e0c21610df3f37956acef6b6042cdaa34aefea2 Mon Sep 17 00:00:00 2001
From: Vincent Hennebert
Date: Mon, 24 Jan 2011 11:46:53 +0000
Subject: Removed unnecessary Checkstyle CSOK comments
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1062741 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/fo/FOPropertyMapping.java | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java
index 1aaa23bd6..b1e851ea4 100644
--- a/src/java/org/apache/fop/fo/FOPropertyMapping.java
+++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java
@@ -79,14 +79,11 @@ public final class FOPropertyMapping implements Constants {
private FOPropertyMapping() {
}
- private static Map propNames
- = new HashMap(); // CSOK: VisibilityModifier
- private static Map subPropNames
- = new HashMap(); // CSOK: VisibilityModifier
- private static Map propIds
- = new HashMap(); // CSOK: VisibilityModifier
-
- private static PropertyMaker[] generics = null; // CSOK: VisibilityModifier
+ private static Map propNames = new HashMap();
+ private static Map subPropNames = new HashMap();
+ private static Map propIds = new HashMap();
+
+ private static PropertyMaker[] generics = null;
// The rest is only used during the building of the generics array.
private Property[] enums = null;
--
cgit v1.2.3
From 59933c342db81b1409d1c9d3cfdb466e194e4649 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Mon, 24 Jan 2011 18:06:25 +0000
Subject: Bugzilla 50593: Mostly add type safety to various collections in the
fop.area package. Additionally, added @Override annotations and used static
import for Constants.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1062901 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/area/Area.java | 55 +++++-----
src/java/org/apache/fop/area/AreaTreeHandler.java | 31 +++---
src/java/org/apache/fop/area/AreaTreeModel.java | 12 +--
src/java/org/apache/fop/area/AreaTreeObject.java | 35 +++----
src/java/org/apache/fop/area/AreaTreeParser.java | 52 ++++-----
src/java/org/apache/fop/area/BeforeFloat.java | 2 +
src/java/org/apache/fop/area/BlockParent.java | 8 +-
src/java/org/apache/fop/area/BookmarkData.java | 54 +++++-----
src/java/org/apache/fop/area/CTM.java | 17 +--
.../apache/fop/area/CachedRenderPagesModel.java | 12 ++-
src/java/org/apache/fop/area/DestinationData.java | 10 +-
src/java/org/apache/fop/area/Footnote.java | 1 +
src/java/org/apache/fop/area/IDTracker.java | 98 +++++++++++------
src/java/org/apache/fop/area/LineArea.java | 29 +++---
src/java/org/apache/fop/area/LinkResolver.java | 10 +-
src/java/org/apache/fop/area/MainReference.java | 23 ++--
src/java/org/apache/fop/area/Page.java | 53 +++++-----
src/java/org/apache/fop/area/PageSequence.java | 4 +-
src/java/org/apache/fop/area/PageViewport.java | 116 ++++++++++-----------
src/java/org/apache/fop/area/RegionReference.java | 8 +-
src/java/org/apache/fop/area/RenderPagesModel.java | 24 +++--
src/java/org/apache/fop/area/Resolvable.java | 2 +-
src/java/org/apache/fop/area/Span.java | 7 +-
src/java/org/apache/fop/area/Trait.java | 27 +++--
src/java/org/apache/fop/area/inline/Container.java | 2 +-
.../org/apache/fop/area/inline/FilledArea.java | 20 ++--
.../org/apache/fop/area/inline/InlineArea.java | 5 +-
.../apache/fop/area/inline/InlineBlockParent.java | 1 +
src/java/org/apache/fop/area/inline/SpaceArea.java | 4 +-
src/java/org/apache/fop/area/inline/TextArea.java | 11 +-
.../fop/area/inline/UnresolvedPageNumber.java | 11 +-
src/java/org/apache/fop/area/inline/WordArea.java | 14 +--
32 files changed, 398 insertions(+), 360 deletions(-)
diff --git a/src/java/org/apache/fop/area/Area.java b/src/java/org/apache/fop/area/Area.java
index f94c68454..b1e27a1eb 100644
--- a/src/java/org/apache/fop/area/Area.java
+++ b/src/java/org/apache/fop/area/Area.java
@@ -132,7 +132,7 @@ public class Area extends AreaTreeObject implements Serializable {
/**
* Traits for this area stored in a HashMap
*/
- protected Map props = null;
+ protected Map props = null;
/**
* logging instance
@@ -239,7 +239,7 @@ public class Area extends AreaTreeObject implements Serializable {
Integer padWidth = (Integer) getTrait(Trait.PADDING_BEFORE);
if (padWidth != null) {
- margin += padWidth.intValue();
+ margin += padWidth;
}
return margin;
@@ -260,7 +260,7 @@ public class Area extends AreaTreeObject implements Serializable {
Integer padWidth = (Integer) getTrait(Trait.PADDING_AFTER);
if (padWidth != null) {
- margin += padWidth.intValue();
+ margin += padWidth;
}
return margin;
@@ -280,7 +280,7 @@ public class Area extends AreaTreeObject implements Serializable {
Integer padWidth = (Integer) getTrait(Trait.PADDING_START);
if (padWidth != null) {
- margin += padWidth.intValue();
+ margin += padWidth;
}
return margin;
@@ -300,7 +300,7 @@ public class Area extends AreaTreeObject implements Serializable {
Integer padWidth = (Integer) getTrait(Trait.PADDING_END);
if (padWidth != null) {
- margin += padWidth.intValue();
+ margin += padWidth;
}
return margin;
@@ -315,7 +315,7 @@ public class Area extends AreaTreeObject implements Serializable {
int margin = 0;
Integer space = (Integer) getTrait(Trait.SPACE_BEFORE);
if (space != null) {
- margin = space.intValue();
+ margin = space;
}
return margin;
}
@@ -329,7 +329,7 @@ public class Area extends AreaTreeObject implements Serializable {
int margin = 0;
Integer space = (Integer) getTrait(Trait.SPACE_AFTER);
if (space != null) {
- margin = space.intValue();
+ margin = space;
}
return margin;
}
@@ -343,7 +343,7 @@ public class Area extends AreaTreeObject implements Serializable {
int margin = 0;
Integer space = (Integer) getTrait(Trait.SPACE_START);
if (space != null) {
- margin = space.intValue();
+ margin = space;
}
return margin;
}
@@ -357,7 +357,7 @@ public class Area extends AreaTreeObject implements Serializable {
int margin = 0;
Integer space = (Integer) getTrait(Trait.SPACE_END);
if (space != null) {
- margin = space.intValue();
+ margin = space;
}
return margin;
}
@@ -380,9 +380,9 @@ public class Area extends AreaTreeObject implements Serializable {
*/
public void addTrait(Object traitCode, Object prop) {
if (props == null) {
- props = new java.util.HashMap(20);
+ props = new java.util.HashMap(20);
}
- props.put(traitCode, prop);
+ props.put((Integer)traitCode, prop);
}
/**
@@ -390,7 +390,7 @@ public class Area extends AreaTreeObject implements Serializable {
*
* @return the map of traits
*/
- public Map getTraits() {
+ public Map getTraits() {
return this.props;
}
@@ -402,44 +402,44 @@ public class Area extends AreaTreeObject implements Serializable {
/**
* Get a trait from this area.
*
- * @param oTraitCode the trait key
+ * @param traitCode the trait key
* @return the trait value
*/
- public Object getTrait(Object oTraitCode) {
- return (props != null ? props.get(oTraitCode) : null);
+ public Object getTrait(Integer traitCode) {
+ return (props != null ? props.get(traitCode) : null);
}
/**
* Checks whether a certain trait is set on this area.
- * @param oTraitCode the trait key
+ * @param traitCode the trait key
* @return true if the trait is set
*/
- public boolean hasTrait(Object oTraitCode) {
- return (getTrait(oTraitCode) != null);
+ public boolean hasTrait(Integer traitCode) {
+ return (getTrait(traitCode) != null);
}
/**
* Get a boolean trait from this area.
- * @param oTraitCode the trait key
+ * @param traitCode the trait key
* @return the trait value
*/
- public boolean getTraitAsBoolean(Object oTraitCode) {
- return Boolean.TRUE.equals(getTrait(oTraitCode));
+ public boolean getTraitAsBoolean(Integer traitCode) {
+ return Boolean.TRUE.equals(getTrait(traitCode));
}
/**
* Get a trait from this area as an integer.
*
- * @param oTraitCode the trait key
+ * @param traitCode the trait key
* @return the trait value
*/
- public int getTraitAsInteger(Object oTraitCode) {
- final Object obj = getTrait(oTraitCode);
+ public int getTraitAsInteger(Integer traitCode) {
+ final Object obj = getTrait(traitCode);
if (obj instanceof Integer) {
- return ((Integer)obj).intValue();
+ return (Integer) obj;
} else {
throw new IllegalArgumentException("Trait "
- + oTraitCode.getClass().getName()
+ + traitCode.getClass().getName()
+ " could not be converted to an integer");
}
}
@@ -447,7 +447,8 @@ public class Area extends AreaTreeObject implements Serializable {
/**
* {@inheritDoc}
* @return ipd and bpd of area
- * */
+ */
+ @Override
public String toString() {
StringBuffer sb = new StringBuffer(super.toString());
sb.append(" {ipd=").append(Integer.toString(getIPD()));
diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java
index 87c681ed6..2729a5a0a 100644
--- a/src/java/org/apache/fop/area/AreaTreeHandler.java
+++ b/src/java/org/apache/fop/area/AreaTreeHandler.java
@@ -21,7 +21,6 @@ package org.apache.fop.area;
// Java
import java.io.OutputStream;
-import java.util.Iterator;
import java.util.List;
import org.xml.sax.SAXException;
@@ -175,6 +174,7 @@ public class AreaTreeHandler extends FOEventHandler {
* @throws SAXException
* if there is an error
*/
+ @Override
public void startDocument() throws SAXException {
// Initialize statistics
if (statistics != null) {
@@ -194,6 +194,7 @@ public class AreaTreeHandler extends FOEventHandler {
}
/** {@inheritDoc} */
+ @Override
public void startPageSequence(PageSequence pageSequence) {
startAbstractPageSequence(pageSequence);
}
@@ -210,10 +211,8 @@ public class AreaTreeHandler extends FOEventHandler {
}
}
- private void wrapAndAddExtensionAttachments(List list) {
- Iterator it = list.iterator();
- while (it.hasNext()) {
- ExtensionAttachment attachment = (ExtensionAttachment) it.next();
+ private void wrapAndAddExtensionAttachments(List list) {
+ for (ExtensionAttachment attachment : list) {
addOffDocumentItem(new OffDocumentExtensionAttachment(attachment));
}
}
@@ -224,6 +223,7 @@ public class AreaTreeHandler extends FOEventHandler {
*
* @param pageSequence the page sequence ending
*/
+ @Override
public void endPageSequence(PageSequence pageSequence) {
if (statistics != null) {
@@ -243,11 +243,13 @@ public class AreaTreeHandler extends FOEventHandler {
}
/** {@inheritDoc} */
+ @Override
public void startExternalDocument(ExternalDocument document) {
startAbstractPageSequence(document);
}
/** {@inheritDoc} */
+ @Override
public void endExternalDocument(ExternalDocument document) {
if (statistics != null) {
statistics.end();
@@ -282,15 +284,16 @@ public class AreaTreeHandler extends FOEventHandler {
*
* @throws SAXException if there is some error
*/
+ @Override
public void endDocument() throws SAXException {
finishPrevPageSequence(null);
// process fox:destination elements
if (rootFObj != null) {
- List destinationList = rootFObj.getDestinationList();
+ List destinationList = rootFObj.getDestinationList();
if (destinationList != null) {
while (destinationList.size() > 0) {
- Destination destination = (Destination) destinationList.remove(0);
+ Destination destination = destinationList.remove(0);
DestinationData destinationData = new DestinationData(destination);
addOffDocumentItem(destinationData);
}
@@ -325,15 +328,15 @@ public class AreaTreeHandler extends FOEventHandler {
if (odi instanceof Resolvable) {
Resolvable res = (Resolvable) odi;
String[] ids = res.getIDRefs();
- for (int count = 0; count < ids.length; count++) {
- List pageVPList = idTracker.getPageViewportsContainingID(ids[count]);
+ for (String id : ids) {
+ List pageVPList = idTracker.getPageViewportsContainingID(id);
if (pageVPList != null) {
- res.resolveIDRef(ids[count], pageVPList);
+ res.resolveIDRef(id, pageVPList);
} else {
AreaEventProducer eventProducer = AreaEventProducer.Provider.get(
getUserAgent().getEventBroadcaster());
- eventProducer.unresolvedIDReference(this, odi.getName(), ids[count]);
- idTracker.addUnresolvedIDRef(ids[count], res);
+ eventProducer.unresolvedIDReference(this, odi.getName(), id);
+ idTracker.addUnresolvedIDRef(id, res);
}
}
// check to see if ODI is now fully resolved, if so process it
@@ -414,13 +417,13 @@ public class AreaTreeHandler extends FOEventHandler {
}
/**
- * Get the list of page viewports that have an area with a given id.
+ * Get the set of page viewports that have an area with a given id.
*
* @param id the id to lookup
* @return the list of PageViewports
* @deprecated use getIDTracker().getPageViewportsContainingID(id) instead
*/
- public List getPageViewportsContainingID(String id) {
+ public List getPageViewportsContainingID(String id) {
return idTracker.getPageViewportsContainingID(id);
}
diff --git a/src/java/org/apache/fop/area/AreaTreeModel.java b/src/java/org/apache/fop/area/AreaTreeModel.java
index 8659b4cca..b829d89a2 100644
--- a/src/java/org/apache/fop/area/AreaTreeModel.java
+++ b/src/java/org/apache/fop/area/AreaTreeModel.java
@@ -36,7 +36,7 @@ import org.apache.commons.logging.LogFactory;
* the life of the area tree model.
*/
public class AreaTreeModel {
- private List/**/ pageSequenceList = null;
+ private List pageSequenceList = null;
private int currentPageSequenceIndex = -1;
/** the current page sequence */
protected PageSequence currentPageSequence;
@@ -48,7 +48,7 @@ public class AreaTreeModel {
* Create a new store pages model
*/
public AreaTreeModel() {
- pageSequenceList = new java.util.ArrayList/**/();
+ pageSequenceList = new java.util.ArrayList();
}
/**
@@ -72,7 +72,7 @@ public class AreaTreeModel {
currentPageSequence.addPage(page);
int pageIndex = 0;
for (int i = 0; i < currentPageSequenceIndex; i++) {
- pageIndex += ((PageSequence)pageSequenceList.get(i)).getPageCount();
+ pageIndex += pageSequenceList.get(i).getPageCount();
}
pageIndex += currentPageSequence.getPageCount() - 1;
page.setPageIndex(pageIndex);
@@ -113,8 +113,7 @@ public class AreaTreeModel {
* @return returns the number of pages in a page sequence
*/
public int getPageCount(int seq) {
- PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1);
- return sequence.getPageCount();
+ return pageSequenceList.get(seq - 1).getPageCount();
}
/**
@@ -124,7 +123,6 @@ public class AreaTreeModel {
* @return the PageViewport for the particular page
*/
public PageViewport getPage(int seq, int count) {
- PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1);
- return sequence.getPage(count);
+ return pageSequenceList.get(seq - 1).getPage(count);
}
}
diff --git a/src/java/org/apache/fop/area/AreaTreeObject.java b/src/java/org/apache/fop/area/AreaTreeObject.java
index bab27f411..dbbfc5744 100644
--- a/src/java/org/apache/fop/area/AreaTreeObject.java
+++ b/src/java/org/apache/fop/area/AreaTreeObject.java
@@ -34,10 +34,10 @@ import org.apache.fop.fo.extensions.ExtensionAttachment;
public abstract class AreaTreeObject {
/** Foreign attributes */
- protected Map foreignAttributes = null;
+ protected Map foreignAttributes = null;
/** Extension attachments */
- protected List/**/ extensionAttachments = null;
+ protected List extensionAttachments = null;
/**
* Sets a foreign attribute.
@@ -46,25 +46,22 @@ public abstract class AreaTreeObject {
*/
public void setForeignAttribute(QName name, String value) {
if (this.foreignAttributes == null) {
- this.foreignAttributes = new java.util.HashMap();
+ this.foreignAttributes = new java.util.HashMap();
}
this.foreignAttributes.put(name, value);
}
/**
- * Set foreign attributes from a Map.
+ * Add foreign attributes from a Map.
+ *
* @param atts a Map with attributes (keys: QName, values: String)
*/
- public void setForeignAttributes(Map atts) {
- if (atts.size() == 0) {
+ public void setForeignAttributes(Map atts) {
+ if (atts == null || atts.size() == 0) {
return;
}
- Iterator iter = atts.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry)iter.next();
- String value = (String)entry.getValue();
- //The casting is only to ensure type safety (too bad we can't use generics, yet)
- setForeignAttribute((QName)entry.getKey(), value);
+ for (Map.Entry e : atts.entrySet()) {
+ setForeignAttribute(e.getKey(), e.getValue());
}
}
@@ -75,24 +72,24 @@ public abstract class AreaTreeObject {
*/
public String getForeignAttributeValue(QName name) {
if (this.foreignAttributes != null) {
- return (String)this.foreignAttributes.get(name);
+ return this.foreignAttributes.get(name);
} else {
return null;
}
}
/** @return the foreign attributes associated with this area */
- public Map getForeignAttributes() {
+ public Map getForeignAttributes() {
if (this.foreignAttributes != null) {
return Collections.unmodifiableMap(this.foreignAttributes);
} else {
- return Collections.EMPTY_MAP;
+ return Collections.emptyMap();
}
}
private void prepareExtensionAttachmentContainer() {
if (this.extensionAttachments == null) {
- this.extensionAttachments = new java.util.ArrayList/**/();
+ this.extensionAttachments = new java.util.ArrayList();
}
}
@@ -109,17 +106,17 @@ public abstract class AreaTreeObject {
* Set extension attachments from a List
* @param extensionAttachments a List with extension attachments
*/
- public void setExtensionAttachments(List extensionAttachments) {
+ public void setExtensionAttachments(List extensionAttachments) {
prepareExtensionAttachmentContainer();
this.extensionAttachments.addAll(extensionAttachments);
}
/** @return the extension attachments associated with this area */
- public List getExtensionAttachments() {
+ public List getExtensionAttachments() {
if (this.extensionAttachments != null) {
return Collections.unmodifiableList(this.extensionAttachments);
} else {
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
}
diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java
index ae7c0a7c3..6c82257f3 100644
--- a/src/java/org/apache/fop/area/AreaTreeParser.java
+++ b/src/java/org/apache/fop/area/AreaTreeParser.java
@@ -75,7 +75,6 @@ import org.apache.fop.area.inline.SpaceArea;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.Viewport;
import org.apache.fop.area.inline.WordArea;
-import org.apache.fop.fo.Constants;
import org.apache.fop.fo.ElementMappingRegistry;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.fo.extensions.ExtensionAttachment;
@@ -91,6 +90,12 @@ import org.apache.fop.util.DelegatingContentHandler;
import org.apache.fop.util.XMLConstants;
import org.apache.fop.util.XMLUtil;
+import static org.apache.fop.fo.Constants.FO_REGION_AFTER;
+import static org.apache.fop.fo.Constants.FO_REGION_BEFORE;
+import static org.apache.fop.fo.Constants.FO_REGION_BODY;
+import static org.apache.fop.fo.Constants.FO_REGION_END;
+import static org.apache.fop.fo.Constants.FO_REGION_START;
+
/**
* This is a parser for the area tree XML (intermediate format) which is used to reread an area
* tree (or part of it) into memory again for rendering to the final output format.
@@ -136,7 +141,7 @@ public class AreaTreeParser {
private static class Handler extends DefaultHandler {
- private Map makers = new java.util.HashMap();
+ private Map makers = new java.util.HashMap();
private AreaTreeModel treeModel;
private FOUserAgent userAgent;
@@ -148,14 +153,15 @@ public class AreaTreeParser {
private boolean ignoreCharacters = true;
private PageViewport currentPageViewport;
- private Map pageViewportsByKey = new java.util.HashMap();
+ private Map pageViewportsByKey
+ = new java.util.HashMap();
// set of "ID firsts" that have already been assigned to a PV:
- private Set idFirstsAssigned = new java.util.HashSet();
+ private Set idFirstsAssigned = new java.util.HashSet();
- private Stack areaStack = new Stack();
+ private Stack areaStack = new Stack();
private boolean firstFlow;
- private Stack delegateStack = new Stack();
+ private Stack delegateStack = new Stack();
private ContentHandler delegate;
private DOMImplementation domImplementation;
private Locator locator;
@@ -228,9 +234,9 @@ public class AreaTreeParser {
if (areaStack.size() > 0) {
int pos = areaStack.size() - 1;
Object obj = null;
- while ( pos >= 0 ) {
+ while (pos >= 0) {
obj = areaStack.get(pos);
- if ( clazz.isInstance ( obj ) ) {
+ if (clazz.isInstance(obj)) {
break;
} else {
pos--;
@@ -358,7 +364,7 @@ public class AreaTreeParser {
private boolean startAreaTreeElement(String localName, Attributes attributes)
throws SAXException {
lastAttributes = new AttributesImpl(attributes);
- Maker maker = (Maker)makers.get(localName);
+ Maker maker = makers.get(localName);
content.clear();
ignoreCharacters = true;
if (maker != null) {
@@ -387,7 +393,7 @@ public class AreaTreeParser {
}
} else {
if ("".equals(uri)) {
- Maker maker = (Maker)makers.get(localName);
+ Maker maker = makers.get(localName);
if (maker != null) {
maker.endElement();
content.clear();
@@ -525,7 +531,7 @@ public class AreaTreeParser {
private class RegionBeforeMaker extends AbstractMaker {
public void startElement(Attributes attributes) {
- pushNewRegionReference(attributes, Constants.FO_REGION_BEFORE);
+ pushNewRegionReference(attributes, FO_REGION_BEFORE);
}
public void endElement() {
@@ -536,7 +542,7 @@ public class AreaTreeParser {
private class RegionAfterMaker extends AbstractMaker {
public void startElement(Attributes attributes) {
- pushNewRegionReference(attributes, Constants.FO_REGION_AFTER);
+ pushNewRegionReference(attributes, FO_REGION_AFTER);
}
public void endElement() {
@@ -547,7 +553,7 @@ public class AreaTreeParser {
private class RegionStartMaker extends AbstractMaker {
public void startElement(Attributes attributes) {
- pushNewRegionReference(attributes, Constants.FO_REGION_START);
+ pushNewRegionReference(attributes, FO_REGION_START);
}
public void endElement() {
@@ -558,7 +564,7 @@ public class AreaTreeParser {
private class RegionEndMaker extends AbstractMaker {
public void startElement(Attributes attributes) {
- pushNewRegionReference(attributes, Constants.FO_REGION_END);
+ pushNewRegionReference(attributes, FO_REGION_END);
}
public void endElement() {
@@ -577,15 +583,13 @@ public class AreaTreeParser {
int columnCount = XMLUtil.getAttributeAsInt(attributes, "columnCount", 1);
int columnGap = XMLUtil.getAttributeAsInt(attributes, "columnGap", 0);
RegionViewport rv = getCurrentRegionViewport();
- body = new BodyRegion(Constants.FO_REGION_BODY,
- regionName, rv, columnCount, columnGap);
+ body = new BodyRegion(FO_REGION_BODY, regionName, rv, columnCount, columnGap);
transferForeignObjects(attributes, body);
body.setCTM(getAttributeAsCTM(attributes, "ctm"));
setAreaAttributes(attributes, body);
setTraits(attributes, body, SUBSET_BORDER_PADDING);
rv.setRegionReference(body);
- currentPageViewport.getPage().setRegionViewport(
- Constants.FO_REGION_BODY, rv);
+ currentPageViewport.getPage().setRegionViewport(FO_REGION_BODY, rv);
areaStack.push(body);
}
@@ -982,7 +986,7 @@ public class AreaTreeParser {
attributes, "show-children", false);
String[] linkdata
= InternalLink.parseXMLAttribute(attributes.getValue("internal-link"));
- PageViewport pv = (PageViewport) pageViewportsByKey.get(linkdata[0]);
+ PageViewport pv = pageViewportsByKey.get(linkdata[0]);
BookmarkData bm = new BookmarkData(title, showChildren, pv, linkdata[1]);
Object tos = areaStack.peek();
if (tos instanceof BookmarkData) {
@@ -1002,9 +1006,9 @@ public class AreaTreeParser {
public void startElement(Attributes attributes) {
String[] linkdata
= InternalLink.parseXMLAttribute(lastAttributes.getValue("internal-link"));
- PageViewport pv = (PageViewport) pageViewportsByKey.get(linkdata[0]);
+ PageViewport pv = pageViewportsByKey.get(linkdata[0]);
DestinationData dest = new DestinationData(linkdata[1]);
- List pages = new java.util.ArrayList();
+ List pages = new java.util.ArrayList();
pages.add(pv);
dest.resolveIDRef(linkdata[1], pages);
areaStack.push(dest);
@@ -1096,7 +1100,7 @@ public class AreaTreeParser {
private void setTraits(Attributes attributes, Area area, Object[] traitSubset) {
for (int i = traitSubset.length; --i >= 0;) {
- Object trait = traitSubset[i];
+ Integer trait = (Integer) traitSubset[i];
String traitName = Trait.getTraitName(trait);
String value = attributes.getValue(traitName);
if (value != null) {
@@ -1107,7 +1111,7 @@ public class AreaTreeParser {
area.addTrait(trait, Boolean.valueOf(value));
} else if (cl == String.class) {
area.addTrait(trait, value);
- if (trait == Trait.PROD_ID
+ if (Trait.PROD_ID.equals(trait)
&& !idFirstsAssigned.contains(value)
&& currentPageViewport != null) {
currentPageViewport.setFirstWithID(value);
@@ -1173,7 +1177,7 @@ public class AreaTreeParser {
area.addTrait(trait, BorderProps.valueOf(this.userAgent, value));
}
} else {
- if (trait == Trait.FONT) {
+ if (Trait.FONT.equals(trait)) {
String fontName = attributes.getValue("font-name");
if (fontName != null) {
String fontStyle = attributes.getValue("font-style");
diff --git a/src/java/org/apache/fop/area/BeforeFloat.java b/src/java/org/apache/fop/area/BeforeFloat.java
index b64eff556..c4d7e21d6 100644
--- a/src/java/org/apache/fop/area/BeforeFloat.java
+++ b/src/java/org/apache/fop/area/BeforeFloat.java
@@ -57,6 +57,7 @@ public class BeforeFloat extends BlockParent {
*
* @return the height of the before float including separator
*/
+ @Override
public int getBPD() {
int h = super.getBPD();
if (separator != null) {
@@ -66,6 +67,7 @@ public class BeforeFloat extends BlockParent {
}
/** {@inheritDoc} */
+ @Override
public boolean isEmpty() {
return true; // before floats are not yet implemented
}
diff --git a/src/java/org/apache/fop/area/BlockParent.java b/src/java/org/apache/fop/area/BlockParent.java
index 18f9056da..5a64d52cf 100644
--- a/src/java/org/apache/fop/area/BlockParent.java
+++ b/src/java/org/apache/fop/area/BlockParent.java
@@ -50,15 +50,13 @@ public class BlockParent extends Area {
/**
* The children of this block parent area.
*/
- protected List children = null;
-
- // orientation if reference area
-// private int orientation = ORIENT_0;
+ protected List children = null;
/** {@inheritDoc} */
+ @Override
public void addChildArea(Area childArea) {
if (children == null) {
- children = new ArrayList();
+ children = new ArrayList ();
}
children.add(childArea);
}
diff --git a/src/java/org/apache/fop/area/BookmarkData.java b/src/java/org/apache/fop/area/BookmarkData.java
index 28ee2c23e..727040a3c 100644
--- a/src/java/org/apache/fop/area/BookmarkData.java
+++ b/src/java/org/apache/fop/area/BookmarkData.java
@@ -19,8 +19,6 @@
package org.apache.fop.area;
-import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -34,13 +32,13 @@ import org.apache.fop.fo.pagination.bookmarks.BookmarkTree;
*/
public class BookmarkData extends AbstractOffDocumentItem implements Resolvable {
- private List subData = new java.util.ArrayList();
+ private List subData = new java.util.ArrayList();
// bookmark-title for this fo:bookmark
private String bookmarkTitle = null;
// indicator of whether to initially display/hide child bookmarks of this object
- private boolean bShow = true;
+ private boolean showChildren = true;
// ID Reference for this bookmark
private String idRef;
@@ -49,7 +47,8 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable
private PageViewport pageRef = null;
// unresolved idrefs by this bookmark and child bookmarks below it
- private Map unresolvedIDRefs = new java.util.HashMap();
+ private Map> unresolvedIDRefs
+ = new java.util.HashMap>();
/**
* Create a new bookmark data object.
@@ -59,10 +58,10 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable
* @param bookmarkTree fo:bookmark-tree for this document
*/
public BookmarkData(BookmarkTree bookmarkTree) {
- idRef = null;
- whenToProcess = END_OF_DOC;
+ this.idRef = null;
+ this.whenToProcess = END_OF_DOC;
// top level defined in Rec to show all child bookmarks
- bShow = true;
+ this.showChildren = true;
for (int count = 0; count < bookmarkTree.getBookmarks().size(); count++) {
Bookmark bkmk = (Bookmark)(bookmarkTree.getBookmarks()).get(count);
@@ -79,15 +78,15 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable
* @param bookmark the fo:bookmark object
*/
public BookmarkData(Bookmark bookmark) {
- bookmarkTitle = bookmark.getBookmarkTitle();
- bShow = bookmark.showChildItems();
+ this.bookmarkTitle = bookmark.getBookmarkTitle();
+ this.showChildren = bookmark.showChildItems();
this.idRef = bookmark.getInternalDestination();
}
private void putUnresolved(String id, BookmarkData bd) {
- List refs = (List)unresolvedIDRefs.get(id);
+ List refs = unresolvedIDRefs.get(id);
if (refs == null) {
- refs = new java.util.ArrayList();
+ refs = new java.util.ArrayList();
unresolvedIDRefs.put(id, refs);
}
refs.add(bd);
@@ -101,7 +100,7 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable
public BookmarkData() {
idRef = null;
whenToProcess = END_OF_DOC;
- bShow = true;
+ showChildren = true;
}
/**
@@ -116,7 +115,7 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable
*/
public BookmarkData(String title, boolean showChildren, PageViewport pv, String idRef) {
bookmarkTitle = title;
- bShow = showChildren;
+ this.showChildren = showChildren;
pageRef = pv;
this.idRef = idRef;
}
@@ -138,11 +137,11 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable
*/
public void addSubData(BookmarkData sub) {
subData.add(sub);
- if (sub.pageRef == null || sub.pageRef.equals("")) {
+ if (sub.pageRef == null) {
putUnresolved(sub.getIDRef(), sub);
String[] ids = sub.getIDRefs();
- for (int count = 0; count < ids.length; count++) {
- putUnresolved(ids[count], sub);
+ for (String id : ids) {
+ putUnresolved(id, sub);
}
}
}
@@ -162,7 +161,7 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable
* @return true to initially display child bookmarks, false otherwise
*/
public boolean showChildItems() {
- return bShow;
+ return showChildren;
}
/**
@@ -181,7 +180,7 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable
* @return the child bookmark data
*/
public BookmarkData getSubData(int count) {
- return (BookmarkData) subData.get(count);
+ return subData.get(count);
}
/**
@@ -208,7 +207,8 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable
* {@inheritDoc}
*/
public String[] getIDRefs() {
- return (String[])unresolvedIDRefs.keySet().toArray(new String[] {});
+ return unresolvedIDRefs.keySet().toArray(
+ new String[unresolvedIDRefs.keySet().size()]);
}
/**
@@ -217,22 +217,20 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable
* resolves id references of child elements that have the same
* id reference.
*
- * {@inheritDoc} List)
+ * {@inheritDoc}
*/
- public void resolveIDRef(String id, List pages) {
+ public void resolveIDRef(String id, List pages) {
if (id.equals(idRef)) {
//Own ID has been resolved, so note the page
- pageRef = (PageViewport) pages.get(0);
+ pageRef = pages.get(0);
//Note: Determining the placement inside the page is the renderer's job.
}
//Notify all child bookmarks
- Collection refs = (Collection)unresolvedIDRefs.get(id);
+ List refs = unresolvedIDRefs.get(id);
if (refs != null) {
- Iterator iter = refs.iterator();
- while (iter.hasNext()) {
- BookmarkData bd = (BookmarkData)iter.next();
- bd.resolveIDRef(id, pages);
+ for (Resolvable res : refs) {
+ res.resolveIDRef(id, pages);
}
}
unresolvedIDRefs.remove(id);
diff --git a/src/java/org/apache/fop/area/CTM.java b/src/java/org/apache/fop/area/CTM.java
index eb6207c42..07c3bbc02 100644
--- a/src/java/org/apache/fop/area/CTM.java
+++ b/src/java/org/apache/fop/area/CTM.java
@@ -25,7 +25,10 @@ import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import org.apache.fop.datatypes.FODimension;
-import org.apache.fop.fo.Constants;
+
+import static org.apache.fop.fo.Constants.EN_LR_TB;
+import static org.apache.fop.fo.Constants.EN_RL_TB;
+import static org.apache.fop.fo.Constants.EN_TB_RL;
/**
* Describe a PDF or PostScript style coordinate transformation matrix (CTM).
@@ -133,14 +136,14 @@ public class CTM implements Serializable {
public static CTM getWMctm(int wm, int ipd, int bpd) {
CTM wmctm;
switch (wm) {
- case Constants.EN_LR_TB:
+ case EN_LR_TB:
return new CTM(CTM_LRTB);
- case Constants.EN_RL_TB:
+ case EN_RL_TB:
wmctm = new CTM(CTM_RLTB);
wmctm.e = ipd;
return wmctm;
//return CTM_RLTB.translate(ipd, 0);
- case Constants.EN_TB_RL: // CJK
+ case EN_TB_RL: // CJK
wmctm = new CTM(CTM_TBRL);
wmctm.e = bpd;
return wmctm;
@@ -157,13 +160,12 @@ public class CTM implements Serializable {
* @return CTM The result of multiplying premult * this.
*/
public CTM multiply(CTM premult) {
- CTM result = new CTM ((premult.a * a) + (premult.b * c),
+ return new CTM ((premult.a * a) + (premult.b * c),
(premult.a * b) + (premult.b * d),
(premult.c * a) + (premult.d * c),
(premult.c * b) + (premult.d * d),
(premult.e * a) + (premult.f * c) + e,
(premult.e * b) + (premult.f * d) + f);
- return result;
}
/**
@@ -249,6 +251,7 @@ public class CTM implements Serializable {
*
* @return a string with the transform values
*/
+ @Override
public String toString() {
return "[" + a + " " + b + " " + c + " " + d + " " + e + " "
+ f + "]";
@@ -332,7 +335,7 @@ public class CTM implements Serializable {
* can set ipd and bpd appropriately based on the writing mode.
*/
- if (writingMode == Constants.EN_LR_TB || writingMode == Constants.EN_RL_TB) {
+ if (writingMode == EN_LR_TB || writingMode == EN_RL_TB) {
reldims.ipd = width;
reldims.bpd = height;
} else {
diff --git a/src/java/org/apache/fop/area/CachedRenderPagesModel.java b/src/java/org/apache/fop/area/CachedRenderPagesModel.java
index 729ca0c65..288884a55 100644
--- a/src/java/org/apache/fop/area/CachedRenderPagesModel.java
+++ b/src/java/org/apache/fop/area/CachedRenderPagesModel.java
@@ -48,7 +48,8 @@ import org.apache.fop.fonts.FontInfo;
* the contents are reloaded.
*/
public class CachedRenderPagesModel extends RenderPagesModel {
- private Map pageMap = new HashMap();
+
+ private Map pageMap = new HashMap();
/** Base directory to save temporary file in, typically points to the user's temp dir. */
protected File baseDir;
@@ -64,12 +65,12 @@ public class CachedRenderPagesModel extends RenderPagesModel {
public CachedRenderPagesModel (FOUserAgent userAgent, String outputFormat,
FontInfo fontInfo, OutputStream stream) throws FOPException {
super(userAgent, outputFormat, fontInfo, stream);
+ //TODO: Avoid System.getProperty()?
this.baseDir = new File(System.getProperty("java.io.tmpdir"));
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
protected boolean checkPreparedPages(PageViewport newpage, boolean renderUnresolved) {
for (Iterator iter = prepared.iterator(); iter.hasNext();) {
PageViewport pageViewport = (PageViewport)iter.next();
@@ -77,7 +78,7 @@ public class CachedRenderPagesModel extends RenderPagesModel {
if (pageViewport != newpage) {
try {
// load page from cache
- String name = (String)pageMap.get(pageViewport);
+ String name = pageMap.get(pageViewport);
File tempFile = new File(baseDir, name);
log.debug("Loading page from: " + tempFile);
ObjectInputStream in = new ObjectInputStream(
@@ -152,6 +153,7 @@ public class CachedRenderPagesModel extends RenderPagesModel {
}
/** {@inheritDoc} */
+ @Override
public void endDocument() throws SAXException {
super.endDocument();
}
diff --git a/src/java/org/apache/fop/area/DestinationData.java b/src/java/org/apache/fop/area/DestinationData.java
index f8d906b91..5797e41df 100644
--- a/src/java/org/apache/fop/area/DestinationData.java
+++ b/src/java/org/apache/fop/area/DestinationData.java
@@ -66,9 +66,7 @@ public class DestinationData extends AbstractOffDocumentItem implements Resolvab
return idRef;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public String[] getIDRefs() {
return idRefs;
}
@@ -97,12 +95,12 @@ public class DestinationData extends AbstractOffDocumentItem implements Resolvab
* Resolves the idref of this object by getting the PageViewport
* object that corresponds to the IDRef
*
- * {@inheritDoc} List)
+ * {@inheritDoc}
* TODO check to make sure it works if multiple bookmark-items
* have the same idref
*/
- public void resolveIDRef(String id, List pages) {
- pageRef = (PageViewport) pages.get(0);
+ public void resolveIDRef(String id, List pages) {
+ pageRef = pages.get(0);
// TODO get rect area of id on page
}
diff --git a/src/java/org/apache/fop/area/Footnote.java b/src/java/org/apache/fop/area/Footnote.java
index 72b9f2ed0..bc9f27b24 100644
--- a/src/java/org/apache/fop/area/Footnote.java
+++ b/src/java/org/apache/fop/area/Footnote.java
@@ -80,6 +80,7 @@ public class Footnote extends BlockParent {
*
* @param child the block area.
*/
+ @Override
public void addBlock(Block child) {
addChildArea(child);
this.setBPD(this.getBPD() + child.getBPD());
diff --git a/src/java/org/apache/fop/area/IDTracker.java b/src/java/org/apache/fop/area/IDTracker.java
index 829c8c58d..0986891f8 100644
--- a/src/java/org/apache/fop/area/IDTracker.java
+++ b/src/java/org/apache/fop/area/IDTracker.java
@@ -19,8 +19,7 @@
package org.apache.fop.area;
-import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -36,18 +35,20 @@ public class IDTracker {
private static final Log LOG = LogFactory.getLog(IDTracker.class);
- // HashMap of ID's whose area is located on one or more consecutive
- // PageViewports. Each ID has an arraylist of PageViewports that
+ // Map of ID's whose area is located on one or more consecutive
+ // PageViewports. Each ID has a list of PageViewports that
// form the defined area of this ID
- private Map idLocations = new java.util.HashMap();
+ private Map> idLocations
+ = new java.util.HashMap>();
// idref's whose target PageViewports have yet to be identified
// Each idref has a HashSet of Resolvable objects containing that idref
- private Map unresolvedIDRefs = new java.util.HashMap();
+ private Map> unresolvedIDRefs
+ = new java.util.HashMap>();
- private Set unfinishedIDs = new java.util.HashSet();
+ private Set unfinishedIDs = new java.util.HashSet();
- private Set alreadyResolvedIDs = new java.util.HashSet();
+ private Set alreadyResolvedIDs = new java.util.HashSet();
/**
* Tie a PageViewport with an ID found on a child area of the PV. Note that
@@ -61,9 +62,9 @@ public class IDTracker {
if (LOG.isDebugEnabled()) {
LOG.debug("associateIDWithPageViewport(" + id + ", " + pv + ")");
}
- List pvList = (List) idLocations.get(id);
+ List pvList = idLocations.get(id);
if (pvList == null) { // first time ID located
- pvList = new ArrayList();
+ pvList = new java.util.ArrayList();
idLocations.put(id, pvList);
pvList.add(pv);
// signal the PageViewport that it is the first PV to contain this id:
@@ -73,7 +74,7 @@ public class IDTracker {
* Resolvable objects tied to it.
*/
if (!unfinishedIDs.contains(id)) {
- tryIDResolution(id, pv, pvList);
+ tryIDResolution(id, pvList);
}
} else {
/* TODO: The check is a quick-fix to avoid a waste
@@ -116,12 +117,11 @@ public class IDTracker {
}
unfinishedIDs.remove(id);
- List pvList = (List) idLocations.get(id);
- Set todo = (Set) unresolvedIDRefs.get(id);
+ List idLocs = idLocations.get(id);
+ Set todo = unresolvedIDRefs.get(id);
if (todo != null) {
- for (Iterator iter = todo.iterator(); iter.hasNext();) {
- Resolvable res = (Resolvable) iter.next();
- res.resolveIDRef(id, pvList);
+ for (Resolvable res : todo) {
+ res.resolveIDRef(id, idLocs);
}
unresolvedIDRefs.remove(id);
}
@@ -138,17 +138,15 @@ public class IDTracker {
}
/**
- * Tries to resolve all unresolved ID references on the given page.
+ * Tries to resolve all unresolved ID references on the given set of pages.
*
* @param id ID to resolve
- * @param pv page viewport whose ID refs to resolve
- * @param pvList of PageViewports
+ * @param pvList list of PageViewports
*/
- private void tryIDResolution(String id, PageViewport pv, List pvList) {
- Set todo = (Set) unresolvedIDRefs.get(id);
+ private void tryIDResolution(String id, List pvList) {
+ Set todo = unresolvedIDRefs.get(id);
if (todo != null) {
- for (Iterator iter = todo.iterator(); iter.hasNext();) {
- Resolvable res = (Resolvable) iter.next();
+ for (Resolvable res : todo) {
if (!unfinishedIDs.contains(id)) {
res.resolveIDRef(id, pvList);
} else {
@@ -168,10 +166,10 @@ public class IDTracker {
public void tryIDResolution(PageViewport pv) {
String[] ids = pv.getIDRefs();
if (ids != null) {
- for (int i = 0; i < ids.length; i++) {
- List pvList = (List) idLocations.get(ids[i]);
- if (pvList != null) {
- tryIDResolution(ids[i], pv, pvList);
+ for (String id : ids) {
+ List pvList = idLocations.get(id);
+ if (!(pvList == null || pvList.isEmpty())) {
+ tryIDResolution(id, pvList);
}
}
}
@@ -183,8 +181,46 @@ public class IDTracker {
* @param id the id to lookup
* @return the list of PageViewports
*/
- public List getPageViewportsContainingID(String id) {
- return (List) idLocations.get(id);
+ public List getPageViewportsContainingID(String id) {
+ if (!(idLocations == null || idLocations.isEmpty())) {
+ List idLocs = idLocations.get(id);
+ if (idLocs != null) {
+ return idLocs;
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * Get the first {@link PageViewport} containing content generated
+ * by the FO with the given {@code id}.
+ *
+ * @param id the id
+ * @return the first {@link PageViewport} for the id; {@code null} if
+ * no matching {@link PageViewport} was found
+ */
+ public PageViewport getFirstPageViewportContaining(String id) {
+ List list = getPageViewportsContainingID(id);
+ if (!(list == null || list.isEmpty())) {
+ return list.get(0);
+ }
+ return null;
+ }
+
+ /**
+ * Get the last {@link PageViewport} containing content generated
+ * by the FO with the given {@code id}.
+ *
+ * @param id the id
+ * @return the last {@link PageViewport} for the id; {@code null} if
+ * no matching {@link PageViewport} was found
+ */
+ public PageViewport getLastPageViewportContaining(String id) {
+ List list = getPageViewportsContainingID(id);
+ if (!(list == null || list.isEmpty())) {
+ return list.get(list.size() - 1);
+ }
+ return null;
}
/**
@@ -194,9 +230,9 @@ public class IDTracker {
* @param res the Resolvable object needing the idref to be resolved
*/
public void addUnresolvedIDRef(String idref, Resolvable res) {
- Set todo = (Set) unresolvedIDRefs.get(idref);
+ Set todo = unresolvedIDRefs.get(idref);
if (todo == null) {
- todo = new java.util.HashSet();
+ todo = new java.util.HashSet();
unresolvedIDRefs.put(idref, todo);
}
// add Resolvable object to this HashSet
diff --git a/src/java/org/apache/fop/area/LineArea.java b/src/java/org/apache/fop/area/LineArea.java
index b33b5da14..edf60578a 100644
--- a/src/java/org/apache/fop/area/LineArea.java
+++ b/src/java/org/apache/fop/area/LineArea.java
@@ -24,7 +24,11 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.fop.area.inline.InlineArea;
-import org.apache.fop.fo.Constants;
+
+import static org.apache.fop.fo.Constants.EN_START;
+import static org.apache.fop.fo.Constants.EN_CENTER;
+import static org.apache.fop.fo.Constants.EN_END;
+import static org.apache.fop.fo.Constants.EN_JUSTIFY;
/**
* The line area.
@@ -75,7 +79,7 @@ public class LineArea extends Area {
// this class can contain the dominant char styling info
// this means that many renderers can optimise a bit
- private List inlineAreas = new ArrayList();
+ private List inlineAreas = new ArrayList();
/**
* default constructor:
@@ -102,11 +106,12 @@ public class LineArea extends Area {
*
* @param childArea the inline child area to add
*/
+ @Override
public void addChildArea(Area childArea) {
if (childArea instanceof InlineArea) {
addInlineArea((InlineArea)childArea);
// set the parent area for the child area
- ((InlineArea) childArea).setParentArea(this);
+ ((InlineArea)childArea).setParentArea(this);
}
}
@@ -150,8 +155,8 @@ public class LineArea extends Area {
int ipd = 0;
int bpd = 0;
for (int i = 0, len = inlineAreas.size(); i < len; i++) {
- ipd = Math.max(ipd, ((InlineArea)inlineAreas.get(i)).getAllocIPD());
- bpd += ((InlineArea)inlineAreas.get(i)).getAllocBPD();
+ ipd = Math.max(ipd, inlineAreas.get(i).getAllocIPD());
+ bpd += inlineAreas.get(i).getAllocBPD();
}
setIPD(ipd);
setBPD(bpd);
@@ -174,18 +179,18 @@ public class LineArea extends Area {
*/
public void handleIPDVariation(int ipdVariation) {
switch (adjustingInfo.lineAlignment) {
- case Constants.EN_START:
+ case EN_START:
// nothing to do in this case
break;
- case Constants.EN_CENTER:
+ case EN_CENTER:
// re-compute indent
- addTrait(Trait.START_INDENT, new Integer(getStartIndent() - ipdVariation / 2));
+ addTrait(Trait.START_INDENT, getStartIndent() - ipdVariation / 2);
break;
- case Constants.EN_END:
+ case EN_END:
// re-compute indent
- addTrait(Trait.START_INDENT, new Integer(getStartIndent() - ipdVariation));
+ addTrait(Trait.START_INDENT, getStartIndent() - ipdVariation);
break;
- case Constants.EN_JUSTIFY:
+ case EN_JUSTIFY:
// compute variation factor
adjustingInfo.variationFactor *= (float) (adjustingInfo.difference - ipdVariation)
/ adjustingInfo.difference;
@@ -207,7 +212,7 @@ public class LineArea extends Area {
* no UnresolvedAreas left
*/
public void finalise() {
- if (adjustingInfo.lineAlignment == Constants.EN_JUSTIFY) {
+ if (adjustingInfo.lineAlignment == EN_JUSTIFY) {
if (log.isTraceEnabled()) {
log.trace("Applying variation factor to justified line: " + adjustingInfo);
}
diff --git a/src/java/org/apache/fop/area/LinkResolver.java b/src/java/org/apache/fop/area/LinkResolver.java
index 70bdfdf91..1e135701f 100644
--- a/src/java/org/apache/fop/area/LinkResolver.java
+++ b/src/java/org/apache/fop/area/LinkResolver.java
@@ -23,12 +23,6 @@ package org.apache.fop.area;
import java.util.List;
import java.io.Serializable;
-// FOP
-import org.apache.fop.area.Trait;
-import org.apache.fop.area.Resolvable;
-import org.apache.fop.area.PageViewport;
-import org.apache.fop.area.Area;
-
/**
* Link resolving for resolving internal links.
*/
@@ -72,8 +66,8 @@ public class LinkResolver implements Resolvable, Serializable {
*
* {@inheritDoc}
*/
- public void resolveIDRef(String id, List pages) {
- resolveIDRef(id, (PageViewport)pages.get(0));
+ public void resolveIDRef(String id, List pages) {
+ resolveIDRef(id, pages.get(0));
}
/**
diff --git a/src/java/org/apache/fop/area/MainReference.java b/src/java/org/apache/fop/area/MainReference.java
index 87e594169..a6112011d 100644
--- a/src/java/org/apache/fop/area/MainReference.java
+++ b/src/java/org/apache/fop/area/MainReference.java
@@ -34,7 +34,7 @@ public class MainReference extends Area {
private static final long serialVersionUID = 7635126485620012448L;
private BodyRegion parent;
- private List spanAreas = new java.util.ArrayList();
+ private List spanAreas = new java.util.ArrayList();
private boolean isEmpty = true;
/**
@@ -59,7 +59,7 @@ public class MainReference extends Area {
spanAreas.remove(spanAreas.size() - 1);
}
RegionViewport rv = parent.getRegionViewport();
- int ipdWidth = (int) parent.getIPD()
+ int ipdWidth = parent.getIPD()
- rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd();
Span newSpan = new Span(((spanAll) ? 1 : getColumnCount()),
@@ -84,8 +84,8 @@ public class MainReference extends Area {
*
* @param spans content already laid out
*/
- public void setSpans(List spans) {
- spanAreas = new ArrayList(spans);
+ public void setSpans(List spans) {
+ spanAreas = new ArrayList(spans);
}
/**
@@ -93,7 +93,7 @@ public class MainReference extends Area {
* @return the active span.
*/
public Span getCurrentSpan() {
- return (Span) spanAreas.get(spanAreas.size() - 1);
+ return spanAreas.get(spanAreas.size() - 1);
}
/**
@@ -103,16 +103,13 @@ public class MainReference extends Area {
* @return true if no child areas have been added yet.
*/
public boolean isEmpty() {
- if (isEmpty) {
- boolean nonEmptyFound = false;
- if (spanAreas != null) {
- for (Iterator spaniter = spanAreas.iterator(); spaniter.hasNext();) {
- Span spanArea = (Span) spaniter.next();
- nonEmptyFound |= !spanArea.isEmpty();
+ if (isEmpty && spanAreas != null) {
+ for (Span spanArea : spanAreas) {
+ if (!spanArea.isEmpty()) {
+ isEmpty = false;
+ break;
}
}
-
- isEmpty = !nonEmptyFound;
}
return isEmpty;
}
diff --git a/src/java/org/apache/fop/area/Page.java b/src/java/org/apache/fop/area/Page.java
index 715bcfe85..a1d9e389f 100644
--- a/src/java/org/apache/fop/area/Page.java
+++ b/src/java/org/apache/fop/area/Page.java
@@ -22,19 +22,26 @@ package org.apache.fop.area;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
-import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.datatypes.LengthBase;
import org.apache.fop.datatypes.SimplePercentBaseContext;
-import org.apache.fop.fo.Constants;
import org.apache.fop.fo.pagination.Region;
import org.apache.fop.fo.pagination.RegionBody;
import org.apache.fop.fo.pagination.SimplePageMaster;
import org.apache.fop.fo.properties.CommonMarginBlock;
import org.apache.fop.layoutmgr.TraitSetter;
+import static org.apache.fop.fo.Constants.FO_REGION_AFTER;
+import static org.apache.fop.fo.Constants.FO_REGION_BEFORE;
+import static org.apache.fop.fo.Constants.FO_REGION_BODY;
+import static org.apache.fop.fo.Constants.FO_REGION_END;
+import static org.apache.fop.fo.Constants.FO_REGION_START;
+import static org.apache.fop.fo.Constants.EN_ERROR_IF_OVERFLOW;
+import static org.apache.fop.fo.Constants.EN_HIDDEN;
+
/**
* The page.
* This holds the contents of the page. Each region is added.
@@ -58,7 +65,7 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
private RegionViewport regionAfter = null;
// temporary map of unresolved objects used when serializing the page
- private Map unresolved = null;
+ private Map> unresolved = null;
/** Set to true to make this page behave as if it were not empty. */
private boolean fakeNonEmpty = false;
@@ -119,12 +126,10 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
spm.getWritingMode(), pageRefRect, reldims);
// Create a RegionViewport/ reference area pair for each page region
- RegionReference rr = null;
- for (Iterator regenum = spm.getRegions().values().iterator();
- regenum.hasNext();) {
- Region r = (Region)regenum.next();
+ RegionReference rr;
+ for (Region r : spm.getRegions().values()) {
RegionViewport rvp = makeRegionViewport(r, reldims, pageCTM);
- if (r.getNameId() == Constants.FO_REGION_BODY) {
+ if (r.getNameId() == FO_REGION_BODY) {
rr = new BodyRegion((RegionBody) r, rvp);
} else {
rr = new RegionReference(r, rvp);
@@ -155,7 +160,7 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
* @param pageCTM page coordinate transformation matrix
* @return the new region viewport
*/
- private RegionViewport makeRegionViewport(Region r, FODimension reldims, CTM pageCTM) {
+ private static RegionViewport makeRegionViewport(Region r, FODimension reldims, CTM pageCTM) {
Rectangle2D relRegionRect = r.getViewportRectangle(reldims);
Rectangle2D absRegionRect = pageCTM.transform(relRegionRect);
// Get the region viewport rectangle in absolute coords by
@@ -164,8 +169,8 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
rv.setBPD((int)relRegionRect.getHeight());
rv.setIPD((int)relRegionRect.getWidth());
TraitSetter.addBackground(rv, r.getCommonBorderPaddingBackground(), null);
- rv.setClip(r.getOverflow() == Constants.EN_HIDDEN
- || r.getOverflow() == Constants.EN_ERROR_IF_OVERFLOW);
+ rv.setClip(r.getOverflow() == EN_HIDDEN
+ || r.getOverflow() == EN_ERROR_IF_OVERFLOW);
return rv;
}
@@ -180,7 +185,7 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
* where x=distance from left, y=distance from bottom, width=right-left
* height=top-bottom
*/
- private void setRegionReferencePosition(RegionReference rr, Region r,
+ private static void setRegionReferencePosition(RegionReference rr, Region r,
Rectangle2D absRegVPRect) {
FODimension reldims = new FODimension(0, 0);
rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(),
@@ -200,15 +205,15 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
* @param port the region viewport to set
*/
public void setRegionViewport(int areaclass, RegionViewport port) {
- if (areaclass == Constants.FO_REGION_BEFORE) {
+ if (areaclass == FO_REGION_BEFORE) {
regionBefore = port;
- } else if (areaclass == Constants.FO_REGION_START) {
+ } else if (areaclass == FO_REGION_START) {
regionStart = port;
- } else if (areaclass == Constants.FO_REGION_BODY) {
+ } else if (areaclass == FO_REGION_BODY) {
regionBody = port;
- } else if (areaclass == Constants.FO_REGION_END) {
+ } else if (areaclass == FO_REGION_END) {
regionEnd = port;
- } else if (areaclass == Constants.FO_REGION_AFTER) {
+ } else if (areaclass == FO_REGION_AFTER) {
regionAfter = port;
}
}
@@ -221,15 +226,15 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
*/
public RegionViewport getRegionViewport(int areaClass) {
switch (areaClass) {
- case Constants.FO_REGION_BEFORE:
+ case FO_REGION_BEFORE:
return regionBefore;
- case Constants.FO_REGION_START:
+ case FO_REGION_START:
return regionStart;
- case Constants.FO_REGION_BODY:
+ case FO_REGION_BODY:
return regionBody;
- case Constants.FO_REGION_END:
+ case FO_REGION_END:
return regionEnd;
- case Constants.FO_REGION_AFTER:
+ case FO_REGION_AFTER:
return regionAfter;
default:
throw new IllegalArgumentException("No such area class with ID = " + areaClass);
@@ -284,7 +289,7 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
*
* @param unres the Map of unresolved objects
*/
- public void setUnresolvedReferences(Map unres) {
+ public void setUnresolvedReferences(Map> unres) {
unresolved = unres;
}
@@ -295,7 +300,7 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
*
* @return the de-serialized HashMap of unresolved objects
*/
- public Map getUnresolvedReferences() {
+ public Map> getUnresolvedReferences() {
return unresolved;
}
diff --git a/src/java/org/apache/fop/area/PageSequence.java b/src/java/org/apache/fop/area/PageSequence.java
index 8fd3cd571..1f0411b00 100644
--- a/src/java/org/apache/fop/area/PageSequence.java
+++ b/src/java/org/apache/fop/area/PageSequence.java
@@ -26,7 +26,7 @@ import java.util.List;
*/
public class PageSequence extends AreaTreeObject {
- private List pages = new java.util.ArrayList();
+ private List pages = new java.util.ArrayList();
private LineArea title;
private String language;
private String country;
@@ -75,7 +75,7 @@ public class PageSequence extends AreaTreeObject {
* @return the requested page or null if it was not found
*/
public PageViewport getPage(int idx) {
- return (PageViewport)this.pages.get(idx);
+ return this.pages.get(idx);
}
/**
diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java
index a4fcb61a8..ff4b2fdaa 100644
--- a/src/java/org/apache/fop/area/PageViewport.java
+++ b/src/java/org/apache/fop/area/PageViewport.java
@@ -25,7 +25,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -33,9 +32,15 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.flow.Marker;
import org.apache.fop.fo.pagination.SimplePageMaster;
+import static org.apache.fop.fo.Constants.FO_REGION_BODY;
+import static org.apache.fop.fo.Constants.EN_FSWP;
+import static org.apache.fop.fo.Constants.EN_FIC;
+import static org.apache.fop.fo.Constants.EN_LSWP;
+import static org.apache.fop.fo.Constants.EN_LEWP;
+
/**
* Page viewport that specifies the viewport area and holds the page contents.
* This is the top level object for a page and remains valid for the life
@@ -63,26 +68,24 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
private transient PageSequence pageSequence;
- // list of id references and the rectangle on the page
- //private Map idReferences = null;
-
// set of IDs that appear first (or exclusively) on this page:
- private Set idFirsts = new java.util.HashSet();
+ private Set idFirsts = new java.util.HashSet();
// this keeps a list of currently unresolved areas or extensions
// once an idref is resolved it is removed
// when this is empty the page can be rendered
- private Map unresolvedIDRefs = new java.util.HashMap();
+ private Map> unresolvedIDRefs
+ = new java.util.HashMap>();
- private Map pendingResolved = null;
+ private Map> pendingResolved = null;
// hashmap of markers for this page
// start and end are added by the fo that contains the markers
- private Map markerFirstStart = null;
- private Map markerLastStart = null;
- private Map markerFirstAny = null;
- private Map markerLastEnd = null;
- private Map markerLastAny = null;
+ private Map markerFirstStart = null;
+ private Map markerLastStart = null;
+ private Map markerFirstAny = null;
+ private Map markerLastEnd = null;
+ private Map markerLastAny = null;
/**
* logging instance
@@ -254,8 +257,8 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
/**
* Add an "ID-first" to this page.
- * This is typically called by the AreaTreeHandler when associating
- * an ID with a PageViewport.
+ * This is typically called by the {@link AreaTreeHandler} when associating
+ * an ID with a {@link PageViewport}.
*
* @param id the id to be registered as first appearing on this page
*/
@@ -277,9 +280,9 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
/**
* Add an idref to this page.
- * All idrefs found for child areas of this PageViewport are added
- * to unresolvedIDRefs, for subsequent resolution by AreaTreeHandler
- * calls to this object's resolveIDRef().
+ * All idrefs found for child areas of this {@link PageViewport} are added
+ * to unresolvedIDRefs, for subsequent resolution by {@link AreaTreeHandler}
+ * calls to this object's {@code resolveIDRef()}.
*
* @param idref the idref
* @param res the child element of this page that needs this
@@ -287,14 +290,14 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
*/
public void addUnresolvedIDRef(String idref, Resolvable res) {
if (unresolvedIDRefs == null) {
- unresolvedIDRefs = new HashMap();
+ unresolvedIDRefs = new HashMap>();
}
- List list = (List)unresolvedIDRefs.get(idref);
- if (list == null) {
- list = new ArrayList();
- unresolvedIDRefs.put(idref, list);
+ List pageViewports = unresolvedIDRefs.get(idref);
+ if (pageViewports == null) {
+ pageViewports = new ArrayList();
+ unresolvedIDRefs.put(idref, pageViewports);
}
- list.add(res);
+ pageViewports.add(res);
}
/**
@@ -312,24 +315,22 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
*/
public String[] getIDRefs() {
return (unresolvedIDRefs == null) ? null
- : (String[]) unresolvedIDRefs.keySet().toArray(new String[] {});
+ : unresolvedIDRefs.keySet().toArray(
+ new String[unresolvedIDRefs.keySet().size()]);
}
- /**
- * {@inheritDoc}
- */
- public void resolveIDRef(String id, List pages) {
+ /** {@inheritDoc} */
+ public void resolveIDRef(String id, List pages) {
if (page == null) {
if (pendingResolved == null) {
- pendingResolved = new HashMap();
+ pendingResolved = new HashMap>();
}
pendingResolved.put(id, pages);
} else {
if (unresolvedIDRefs != null) {
- List todo = (List)unresolvedIDRefs.get(id);
+ List todo = unresolvedIDRefs.get(id);
if (todo != null) {
- for (int count = 0; count < todo.size(); count++) {
- Resolvable res = (Resolvable)todo.get(count);
+ for (Resolvable res : todo) {
res.resolveIDRef(id, pages);
}
}
@@ -363,7 +364,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
* @param isfirst if the area being added has is-first trait
* @param islast if the area being added has is-last trait
*/
- public void addMarkers(Map marks, boolean starting,
+ public void addMarkers(Map marks, boolean starting,
boolean isfirst, boolean islast) {
if (marks == null) {
@@ -380,14 +381,13 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
if (starting) {
if (isfirst) {
if (markerFirstStart == null) {
- markerFirstStart = new HashMap();
+ markerFirstStart = new HashMap();
}
if (markerFirstAny == null) {
- markerFirstAny = new HashMap();
+ markerFirstAny = new HashMap();
}
// first on page: only put in new values, leave current
- for (Iterator iter = marks.keySet().iterator(); iter.hasNext();) {
- Object key = iter.next();
+ for (String key : marks.keySet()) {
if (!markerFirstStart.containsKey(key)) {
markerFirstStart.put(key, marks.get(key));
if (log.isTraceEnabled()) {
@@ -404,7 +404,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
}
}
if (markerLastStart == null) {
- markerLastStart = new HashMap();
+ markerLastStart = new HashMap();
}
// last on page: replace all
markerLastStart.putAll(marks);
@@ -414,11 +414,10 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
}
} else {
if (markerFirstAny == null) {
- markerFirstAny = new HashMap();
+ markerFirstAny = new HashMap();
}
// first on page: only put in new values, leave current
- for (Iterator iter = marks.keySet().iterator(); iter.hasNext();) {
- Object key = iter.next();
+ for (String key : marks.keySet()) {
if (!markerFirstAny.containsKey(key)) {
markerFirstAny.put(key, marks.get(key));
if (log.isTraceEnabled()) {
@@ -432,7 +431,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
// at the end of the area, register is-last and any areas
if (islast) {
if (markerLastEnd == null) {
- markerLastEnd = new HashMap();
+ markerLastEnd = new HashMap();
}
// last on page: replace all
markerLastEnd.putAll(marks);
@@ -442,7 +441,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
}
}
if (markerLastAny == null) {
- markerLastAny = new HashMap();
+ markerLastAny = new HashMap();
}
// last on page: replace all
markerLastAny.putAll(marks);
@@ -462,11 +461,11 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
* @param pos the position to retrieve
* @return Object the marker found or null
*/
- public Object getMarker(String name, int pos) {
- Object mark = null;
+ public Marker getMarker(String name, int pos) {
+ Marker mark = null;
String posName = null;
switch (pos) {
- case Constants.EN_FSWP:
+ case EN_FSWP:
if (markerFirstStart != null) {
mark = markerFirstStart.get(name);
posName = "FSWP";
@@ -476,13 +475,13 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
posName = "FirstAny after " + posName;
}
break;
- case Constants.EN_FIC:
+ case EN_FIC:
if (markerFirstAny != null) {
mark = markerFirstAny.get(name);
posName = "FIC";
}
break;
- case Constants.EN_LSWP:
+ case EN_LSWP:
if (markerLastStart != null) {
mark = markerLastStart.get(name);
posName = "LSWP";
@@ -492,7 +491,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
posName = "LastAny after " + posName;
}
break;
- case Constants.EN_LEWP:
+ case EN_LEWP:
if (markerLastEnd != null) {
mark = markerLastEnd.get(name);
posName = "LEWP";
@@ -503,7 +502,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
}
break;
default:
- throw new RuntimeException();
+ assert false;
}
if (log.isTraceEnabled()) {
log.trace("page " + pageNumberString + ": " + "Retrieving marker " + name
@@ -550,10 +549,8 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
page = (Page) in.readObject();
unresolvedIDRefs = page.getUnresolvedReferences();
if (unresolvedIDRefs != null && pendingResolved != null) {
- for (Iterator iter = pendingResolved.keySet().iterator();
- iter.hasNext();) {
- String id = (String) iter.next();
- resolveIDRef(id, (List)pendingResolved.get(id));
+ for (String id : pendingResolved.keySet()) {
+ resolveIDRef(id, pendingResolved.get(id));
}
pendingResolved = null;
}
@@ -577,9 +574,8 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
page = null;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append("PageViewport: page=");
@@ -602,8 +598,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
* @return BodyRegion object
*/
public BodyRegion getBodyRegion() {
- return (BodyRegion) getPage().getRegionViewport(
- Constants.FO_REGION_BODY).getRegionReference();
+ return (BodyRegion) getPage().getRegionViewport(FO_REGION_BODY).getRegionReference();
}
/**
@@ -659,5 +654,4 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
public RegionReference getRegionReference(int id) {
return getPage().getRegionViewport(id).getRegionReference();
}
-
}
diff --git a/src/java/org/apache/fop/area/RegionReference.java b/src/java/org/apache/fop/area/RegionReference.java
index a727f9029..4158f924a 100644
--- a/src/java/org/apache/fop/area/RegionReference.java
+++ b/src/java/org/apache/fop/area/RegionReference.java
@@ -38,7 +38,7 @@ public class RegionReference extends Area implements Cloneable {
private CTM ctm;
// the list of block areas from the static flow
- private ArrayList blocks = new ArrayList();
+ private ArrayList blocks = new ArrayList ();
/** the parent {@link RegionViewport} for this object */
protected RegionViewport regionViewport;
@@ -68,6 +68,7 @@ public class RegionReference extends Area implements Cloneable {
}
/** {@inheritDoc} */
+ @Override
public void addChildArea(Area child) {
blocks.add(child);
}
@@ -106,7 +107,7 @@ public class RegionReference extends Area implements Cloneable {
*
* @return the list of blocks in this region
*/
- public List getBlocks() {
+ public List getBlocks() {
return blocks;
}
@@ -143,11 +144,12 @@ public class RegionReference extends Area implements Cloneable {
RegionReference rr = new RegionReference(regionClass, regionName, regionViewport);
rr.ctm = ctm;
rr.setIPD(getIPD());
- rr.blocks = (ArrayList)blocks.clone();
+ rr.blocks = (ArrayList )blocks.clone();
return rr;
}
/** {@inheritDoc} */
+ @Override
public String toString() {
StringBuffer sb = new StringBuffer(super.toString());
sb.append(" {regionName=").append(regionName);
diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java
index 13995b099..592e49f1e 100644
--- a/src/java/org/apache/fop/area/RenderPagesModel.java
+++ b/src/java/org/apache/fop/area/RenderPagesModel.java
@@ -50,9 +50,10 @@ public class RenderPagesModel extends AreaTreeModel {
/**
* Pages that have been prepared but not rendered yet.
*/
- protected List/**/ prepared = new java.util.ArrayList/**/();
- private List/**/ pendingODI = new java.util.ArrayList/**/();
- private List/**/ endDocODI = new java.util.ArrayList/**/();
+ protected List prepared = new java.util.ArrayList();
+
+ private List pendingODI = new java.util.ArrayList();
+ private List endDocODI = new java.util.ArrayList();
/**
* Create a new render pages model with the given renderer.
@@ -83,6 +84,7 @@ public class RenderPagesModel extends AreaTreeModel {
}
/** {@inheritDoc} */
+ @Override
public void startPageSequence(PageSequence pageSequence) {
super.startPageSequence(pageSequence);
if (renderer.supportsOutOfOrder()) {
@@ -98,6 +100,7 @@ public class RenderPagesModel extends AreaTreeModel {
* the page is added to a queue.
* @param page the page to add to the model
*/
+ @Override
public void addPage(PageViewport page) {
super.addPage(page);
@@ -183,11 +186,11 @@ public class RenderPagesModel extends AreaTreeModel {
renderer.renderPage(pageViewport);
if (!pageViewport.isResolved()) {
String[] idrefs = pageViewport.getIDRefs();
- for (int count = 0; count < idrefs.length; count++) {
+ for (String idref : idrefs) {
AreaEventProducer eventProducer = AreaEventProducer.Provider.get(
renderer.getUserAgent().getEventBroadcaster());
eventProducer.unresolvedIDReferenceOnPage(this,
- pageViewport.getPageNumberString(), idrefs[count]);
+ pageViewport.getPageNumberString(), idref);
}
}
} catch (Exception e) {
@@ -214,9 +217,8 @@ public class RenderPagesModel extends AreaTreeModel {
prepared.add(page);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public void handleOffDocumentItem(OffDocumentItem oDI) {
switch(oDI.getWhenToProcess()) {
case OffDocumentItem.IMMEDIATELY:
@@ -233,9 +235,8 @@ public class RenderPagesModel extends AreaTreeModel {
}
}
- private void processOffDocumentItems(List list) {
- for (int count = 0; count < list.size(); count++) {
- OffDocumentItem oDI = (OffDocumentItem)list.get(count);
+ private void processOffDocumentItems(List list) {
+ for (OffDocumentItem oDI : list) {
renderer.processOffDocumentItem(oDI);
}
}
@@ -244,6 +245,7 @@ public class RenderPagesModel extends AreaTreeModel {
* End the document. Render any end document OffDocumentItems
* {@inheritDoc}
*/
+ @Override
public void endDocument() throws SAXException {
// render any pages that had unresolved ids
checkPreparedPages(null, true);
diff --git a/src/java/org/apache/fop/area/Resolvable.java b/src/java/org/apache/fop/area/Resolvable.java
index cc2569e8a..3ab3ef309 100644
--- a/src/java/org/apache/fop/area/Resolvable.java
+++ b/src/java/org/apache/fop/area/Resolvable.java
@@ -59,5 +59,5 @@ public interface Resolvable {
* @param pages the list of PageViewports with the given ID
*
*/
- void resolveIDRef(String id, List pages);
+ void resolveIDRef(String id, List pages);
}
diff --git a/src/java/org/apache/fop/area/Span.java b/src/java/org/apache/fop/area/Span.java
index e2ef90432..c2fd4679c 100644
--- a/src/java/org/apache/fop/area/Span.java
+++ b/src/java/org/apache/fop/area/Span.java
@@ -34,7 +34,7 @@ public class Span extends Area {
private static final long serialVersionUID = -5551430053660081549L;
// the list of flow reference areas in this span area
- private List flowAreas;
+ private List flowAreas;
private int colCount;
private int colGap;
private int colWidth; // width for each normal flow, calculated value
@@ -60,7 +60,7 @@ public class Span extends Area {
* Create the normal flows for this Span
*/
private void createNormalFlows() {
- flowAreas = new java.util.ArrayList(colCount);
+ flowAreas = new java.util.ArrayList(colCount);
colWidth = (ipd - ((colCount - 1) * colGap)) / colCount;
for (int i = 0; i < colCount; i++) {
@@ -105,7 +105,7 @@ public class Span extends Area {
*/
public NormalFlow getNormalFlow(int colRequested) {
if (colRequested >= 0 && colRequested < colCount) {
- return (NormalFlow) flowAreas.get(colRequested);
+ return flowAreas.get(colRequested);
} else { // internal error
throw new IllegalArgumentException("Invalid column number "
+ colRequested + " requested; only 0-" + (colCount - 1)
@@ -184,6 +184,7 @@ public class Span extends Area {
}
/** {@inheritDoc} */
+ @Override
public String toString() {
StringBuffer sb = new StringBuffer(super.toString());
if (colCount > 1) {
diff --git a/src/java/org/apache/fop/area/Trait.java b/src/java/org/apache/fop/area/Trait.java
index a8e1db186..042b65337 100644
--- a/src/java/org/apache/fop/area/Trait.java
+++ b/src/java/org/apache/fop/area/Trait.java
@@ -24,11 +24,15 @@ import java.io.Serializable;
import org.apache.xmlgraphics.image.loader.ImageInfo;
-import org.apache.fop.fo.Constants;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.traits.BorderProps;
import org.apache.fop.util.ColorUtil;
+import static org.apache.fop.fo.Constants.EN_REPEAT;
+import static org.apache.fop.fo.Constants.EN_REPEATX;
+import static org.apache.fop.fo.Constants.EN_REPEATY;
+import static org.apache.fop.fo.Constants.EN_NOREPEAT;
+
// properties should be serialized by the holder
/**
* Area traits used for rendering.
@@ -142,8 +146,10 @@ public final class Trait implements Serializable {
/** Trait for color of underline decorations when rendering inline parent. */
public static final Integer UNDERLINE_COLOR = 34;
+
/** Trait for color of overline decorations when rendering inline parent. */
public static final Integer OVERLINE_COLOR = 35;
+
/** Trait for color of linethrough decorations when rendering inline parent. */
public static final Integer LINETHROUGH_COLOR = 36;
@@ -367,6 +373,7 @@ public final class Trait implements Serializable {
* Return the human-friendly string for debugging.
* {@inheritDoc}
*/
+ @Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("pvKey=").append(pvKey);
@@ -441,6 +448,7 @@ public final class Trait implements Serializable {
* @return a String
of the form
* "org.apache.fop.area.Trait.ExternalLink[dest=someURL,newWindow=false]"
*/
+ @Override
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append("newWindow=").append(newWindow);
@@ -581,23 +589,23 @@ public final class Trait implements Serializable {
private String getRepeatString() {
switch (getRepeat()) {
- case Constants.EN_REPEAT: return "repeat";
- case Constants.EN_REPEATX: return "repeat-x";
- case Constants.EN_REPEATY: return "repeat-y";
- case Constants.EN_NOREPEAT: return "no-repeat";
+ case EN_REPEAT: return "repeat";
+ case EN_REPEATX: return "repeat-x";
+ case EN_REPEATY: return "repeat-y";
+ case EN_NOREPEAT: return "no-repeat";
default: throw new IllegalStateException("Illegal repeat style: " + getRepeat());
}
}
private static int getConstantForRepeat(String repeat) {
if ("repeat".equalsIgnoreCase(repeat)) {
- return Constants.EN_REPEAT;
+ return EN_REPEAT;
} else if ("repeat-x".equalsIgnoreCase(repeat)) {
- return Constants.EN_REPEATX;
+ return EN_REPEATX;
} else if ("repeat-y".equalsIgnoreCase(repeat)) {
- return Constants.EN_REPEATY;
+ return EN_REPEATY;
} else if ("no-repeat".equalsIgnoreCase(repeat)) {
- return Constants.EN_NOREPEAT;
+ return EN_NOREPEAT;
} else {
throw new IllegalStateException("Illegal repeat style: " + repeat);
}
@@ -607,6 +615,7 @@ public final class Trait implements Serializable {
* Return the string for debugging.
* {@inheritDoc}
*/
+ @Override
public String toString() {
StringBuffer sb = new StringBuffer();
if (color != null) {
diff --git a/src/java/org/apache/fop/area/inline/Container.java b/src/java/org/apache/fop/area/inline/Container.java
index f6dbf3a15..9267b92d0 100644
--- a/src/java/org/apache/fop/area/inline/Container.java
+++ b/src/java/org/apache/fop/area/inline/Container.java
@@ -38,7 +38,7 @@ public class Container extends Area {
/**
* The list of block areas stacked inside this container
*/
- protected List blocks = new ArrayList();
+ protected List blocks = new ArrayList();
/**
* The width of this container
diff --git a/src/java/org/apache/fop/area/inline/FilledArea.java b/src/java/org/apache/fop/area/inline/FilledArea.java
index 06d0d3aa3..858951f75 100644
--- a/src/java/org/apache/fop/area/inline/FilledArea.java
+++ b/src/java/org/apache/fop/area/inline/FilledArea.java
@@ -39,9 +39,7 @@ public class FilledArea extends InlineParent {
private int unitWidth;
- /**
- * Create a new filled area.
- */
+ /** Create a new filled area. */
public FilledArea() {
}
@@ -88,13 +86,11 @@ public class FilledArea extends InlineParent {
return this.unitWidth;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public int getBPD() {
int bpd = 0;
- for (Iterator childAreaIt = getChildAreas().iterator(); childAreaIt.hasNext();) {
- InlineArea area = (InlineArea)childAreaIt.next();
+ for (InlineArea area : getChildAreas()) {
if (bpd < area.getBPD()) {
bpd = area.getBPD();
}
@@ -110,9 +106,10 @@ public class FilledArea extends InlineParent {
*
* @return the list of child areas copied to fill the width
*/
- public List getChildAreas() {
- int units = (int)(getIPD() / unitWidth);
- List newList = new ArrayList();
+ @Override
+ public List getChildAreas() {
+ int units = getIPD() / unitWidth;
+ List newList = new ArrayList();
for (int count = 0; count < units; count++) {
newList.addAll(inlines);
}
@@ -126,6 +123,7 @@ public class FilledArea extends InlineParent {
* @param lineShrink the total shrink of the line
* @return true if there is an UnresolvedArea descendant
*/
+ @Override
public boolean applyVariationFactor(double variationFactor,
int lineStretch, int lineShrink) {
setIPD(getIPD() + adjustingInfo.applyVariationFactor(variationFactor));
diff --git a/src/java/org/apache/fop/area/inline/InlineArea.java b/src/java/org/apache/fop/area/inline/InlineArea.java
index 3450b99be..515f45b68 100644
--- a/src/java/org/apache/fop/area/inline/InlineArea.java
+++ b/src/java/org/apache/fop/area/inline/InlineArea.java
@@ -178,6 +178,7 @@ public class InlineArea extends Area {
*
* {@inheritDoc}
*/
+ @Override
public void addChildArea(Area childArea) {
super.addChildArea(childArea);
if (childArea instanceof InlineArea) {
@@ -185,9 +186,7 @@ public class InlineArea extends Area {
}
}
- /**
- *@return true if the inline area is underlined.
- */
+ /** @return true if the inline area is underlined. */
public boolean hasUnderline() {
return getTraitAsBoolean(Trait.UNDERLINE);
}
diff --git a/src/java/org/apache/fop/area/inline/InlineBlockParent.java b/src/java/org/apache/fop/area/inline/InlineBlockParent.java
index fe024ac0f..982e8848f 100644
--- a/src/java/org/apache/fop/area/inline/InlineBlockParent.java
+++ b/src/java/org/apache/fop/area/inline/InlineBlockParent.java
@@ -48,6 +48,7 @@ public class InlineBlockParent extends InlineArea {
*
* @param childArea the child area to add
*/
+ @Override
public void addChildArea(Area childArea) {
if (child != null) {
throw new IllegalStateException("InlineBlockParent may have only one child area.");
diff --git a/src/java/org/apache/fop/area/inline/SpaceArea.java b/src/java/org/apache/fop/area/inline/SpaceArea.java
index 9c698b305..ebfcc5ec8 100644
--- a/src/java/org/apache/fop/area/inline/SpaceArea.java
+++ b/src/java/org/apache/fop/area/inline/SpaceArea.java
@@ -48,9 +48,7 @@ public class SpaceArea extends InlineArea {
isAdjustable = a;
}
- /**
- * @return Returns the space.
- */
+ /** @return Returns the space. */
public String getSpace() {
return String.valueOf(space);
}
diff --git a/src/java/org/apache/fop/area/inline/TextArea.java b/src/java/org/apache/fop/area/inline/TextArea.java
index 8fb9455ad..15d005025 100644
--- a/src/java/org/apache/fop/area/inline/TextArea.java
+++ b/src/java/org/apache/fop/area/inline/TextArea.java
@@ -99,20 +99,19 @@ public class TextArea extends AbstractTextArea {
*/
public String getText() {
StringBuffer text = new StringBuffer();
- InlineArea child;
// assemble the text
- for (int i = 0; i < inlines.size(); i++) {
- child = (InlineArea) inlines.get(i);
- if (child instanceof WordArea) {
- text.append(((WordArea) child).getWord());
+ for (InlineArea inline : inlines) {
+ if (inline instanceof WordArea) {
+ text.append(((WordArea) inline).getWord());
} else {
- text.append(((SpaceArea) child).getSpace());
+ text.append(((SpaceArea) inline).getSpace());
}
}
return text.toString();
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return "TextArea{text=" + getText() + "}";
}
diff --git a/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java b/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
index 3457ad698..d3bb91045 100644
--- a/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
+++ b/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
@@ -92,18 +92,14 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable {
* @param id an id whose PageViewports have been determined
* @param pages the list of PageViewports associated with this ID
*/
- public void resolveIDRef(String id, List pages) {
+ public void resolveIDRef(String id, List pages) {
if (!resolved && pageIDRef.equals(id) && pages != null) {
if (log.isDebugEnabled()) {
log.debug("Resolving pageNumber: " + id);
}
resolved = true;
- PageViewport page;
- if (pageType == FIRST) {
- page = (PageViewport)pages.get(0);
- } else {
- page = (PageViewport)pages.get(pages.size() - 1);
- }
+ int pageIndex = pageType ? 0 : pages.size() - 1;
+ PageViewport page = pages.get(pageIndex);
// replace the text
removeText();
text = page.getPageNumberString();
@@ -136,6 +132,7 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable {
* @param lineShrink the total shrink of the line
* @return true if there is an UnresolvedArea descendant
*/
+ @Override
public boolean applyVariationFactor(double variationFactor,
int lineStretch, int lineShrink) {
return true;
diff --git a/src/java/org/apache/fop/area/inline/WordArea.java b/src/java/org/apache/fop/area/inline/WordArea.java
index 8bb6888ce..7f62fe8d7 100644
--- a/src/java/org/apache/fop/area/inline/WordArea.java
+++ b/src/java/org/apache/fop/area/inline/WordArea.java
@@ -47,22 +47,18 @@ public class WordArea extends InlineArea {
this.letterAdjust = la;
}
- /**
- * @return Returns the word.
- */
+ /** @return Returns the word. */
public String getWord() {
return word;
}
- /**
- * @return Returns the offset.
- */
+ /** @return Returns the offset. */
+ @Override
public int getOffset() {
return offset;
}
- /**
- * @param o The offset to set.
- */
+ /** @param o The offset to set. */
+ @Override
public void setOffset(int o) {
offset = o;
}
--
cgit v1.2.3
From 5d677308df2545985dcf053f99703c506314a6e8 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Mon, 24 Jan 2011 18:35:15 +0000
Subject: Bugzilla 50636: fix performance issue when adding pages in very large
documents
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1062913 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/area/AreaTreeModel.java | 16 +++++++---------
status.xml | 8 ++++++++
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/java/org/apache/fop/area/AreaTreeModel.java b/src/java/org/apache/fop/area/AreaTreeModel.java
index b829d89a2..2a1f14ab5 100644
--- a/src/java/org/apache/fop/area/AreaTreeModel.java
+++ b/src/java/org/apache/fop/area/AreaTreeModel.java
@@ -37,10 +37,10 @@ import org.apache.commons.logging.LogFactory;
*/
public class AreaTreeModel {
private List pageSequenceList = null;
- private int currentPageSequenceIndex = -1;
+ private int currentPageIndex = 0;
+
/** the current page sequence */
protected PageSequence currentPageSequence;
-// private List offDocumentItems = new java.util.ArrayList();
/** logger instance */
protected static final Log log = LogFactory.getLog(AreaTreeModel.class);
@@ -59,9 +59,11 @@ public class AreaTreeModel {
if (pageSequence == null) {
throw new NullPointerException("pageSequence must not be null");
}
+ if (currentPageSequence != null) {
+ currentPageIndex += currentPageSequence.getPageCount();
+ }
this.currentPageSequence = pageSequence;
pageSequenceList.add(currentPageSequence);
- currentPageSequenceIndex = pageSequenceList.size() - 1;
}
/**
@@ -70,12 +72,8 @@ public class AreaTreeModel {
*/
public void addPage(PageViewport page) {
currentPageSequence.addPage(page);
- int pageIndex = 0;
- for (int i = 0; i < currentPageSequenceIndex; i++) {
- pageIndex += pageSequenceList.get(i).getPageCount();
- }
- pageIndex += currentPageSequence.getPageCount() - 1;
- page.setPageIndex(pageIndex);
+ page.setPageIndex(currentPageIndex
+ + currentPageSequence.getPageCount() - 1);
page.setPageSequence(currentPageSequence);
}
diff --git a/status.xml b/status.xml
index c80ba0668..b604971e5 100644
--- a/status.xml
+++ b/status.xml
@@ -59,6 +59,14 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
+
+ Bugfix: fix performance issue when adding pages, if the total number of pages
+ is significantly large.
+
+
+ Bugfix: fix performance issue when adding nodes, if the number of children
+ is significantly large.
+
Bugfix: relative URIs in the configuration file (base, font-base, hyphenation-base) are evaluated relative to the base URI of the configuration file.
--
cgit v1.2.3
From 6de2d9fab226f7da81f5c803100990f71f7e44e1 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Mon, 24 Jan 2011 18:36:56 +0000
Subject: Credit where credit is due...
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1062914 13f79535-47bb-0310-9956-ffa450edef68
---
status.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/status.xml b/status.xml
index b604971e5..bb51ab16f 100644
--- a/status.xml
+++ b/status.xml
@@ -59,11 +59,11 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
-
+
Bugfix: fix performance issue when adding pages, if the total number of pages
is significantly large.
-
+
Bugfix: fix performance issue when adding nodes, if the number of children
is significantly large.
--
cgit v1.2.3
From 1c8f05b0a02f3238ec6d508ed6e942b6104d7f1c Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Mon, 24 Jan 2011 22:18:42 +0000
Subject: Bugzilla 50635: fix issue in checkPreparedPages() where the same
page-sequence is potentially started multiple times
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1063022 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/area/RenderPagesModel.java | 7 ++++---
status.xml | 4 ++++
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java
index 592e49f1e..afec850f8 100644
--- a/src/java/org/apache/fop/area/RenderPagesModel.java
+++ b/src/java/org/apache/fop/area/RenderPagesModel.java
@@ -155,14 +155,15 @@ public class RenderPagesModel extends AreaTreeModel {
* false if the renderer doesn't support out of order
* rendering and there are pending pages
*/
- protected boolean checkPreparedPages(PageViewport newPageViewport, boolean
- renderUnresolved) {
+ protected boolean checkPreparedPages(PageViewport newPageViewport,
+ boolean renderUnresolved) {
+
for (Iterator iter = prepared.iterator(); iter.hasNext();) {
PageViewport pageViewport = (PageViewport)iter.next();
if (pageViewport.isResolved() || renderUnresolved) {
if (!renderer.supportsOutOfOrder()
&& pageViewport.getPageSequence().isFirstPage(pageViewport)) {
- renderer.startPageSequence(getCurrentPageSequence());
+ renderer.startPageSequence(pageViewport.getPageSequence());
}
renderPage(pageViewport);
pageViewport.clear();
diff --git a/status.xml b/status.xml
index bb51ab16f..dd131de73 100644
--- a/status.xml
+++ b/status.xml
@@ -59,6 +59,10 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
+
+ Bugfix: fix issue in RenderPagesModel.checkPreparedPages() where the same page-sequence
+ is potentially started multiple times.
+
Bugfix: fix performance issue when adding pages, if the total number of pages
is significantly large.
--
cgit v1.2.3
From f540b00cf2c8cf1126f6d45e3a9062b2bccd7a58 Mon Sep 17 00:00:00 2001
From: Simon Pepping
Date: Thu, 27 Jan 2011 15:34:12 +0000
Subject: Fix an forgotten change of type in class Area and a checkstyle error
in class FObj
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1064159 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/area/Area.java | 4 ++--
src/java/org/apache/fop/fo/FObj.java | 6 +++---
src/java/org/apache/fop/layoutmgr/TraitSetter.java | 4 ++--
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/java/org/apache/fop/area/Area.java b/src/java/org/apache/fop/area/Area.java
index b1e27a1eb..1f14ed740 100644
--- a/src/java/org/apache/fop/area/Area.java
+++ b/src/java/org/apache/fop/area/Area.java
@@ -378,11 +378,11 @@ public class Area extends AreaTreeObject implements Serializable {
* @param traitCode the trait key
* @param prop the value of the trait
*/
- public void addTrait(Object traitCode, Object prop) {
+ public void addTrait(Integer traitCode, Object prop) {
if (props == null) {
props = new java.util.HashMap(20);
}
- props.put((Integer)traitCode, prop);
+ props.put(traitCode, prop);
}
/**
diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java
index 66bf1a15d..98661b8b6 100644
--- a/src/java/org/apache/fop/fo/FObj.java
+++ b/src/java/org/apache/fop/fo/FObj.java
@@ -47,10 +47,10 @@ public abstract class FObj extends FONode implements Constants {
private static final PropertyMaker[] PROPERTY_LIST_TABLE
= FOPropertyMapping.getGenericMappings();
- /**
- * pointer to the descendant subtree
- */
+ /** pointer to the descendant subtree */
protected FONode firstChild;
+
+ /** pointer to the end of the descendant subtree */
protected FONode lastChild;
/** The list of extension attachments, null if none */
diff --git a/src/java/org/apache/fop/layoutmgr/TraitSetter.java b/src/java/org/apache/fop/layoutmgr/TraitSetter.java
index 6039ad941..ff0e70811 100644
--- a/src/java/org/apache/fop/layoutmgr/TraitSetter.java
+++ b/src/java/org/apache/fop/layoutmgr/TraitSetter.java
@@ -104,10 +104,10 @@ public final class TraitSetter {
private static void addBorderTrait(Area area,
CommonBorderPaddingBackground bpProps,
boolean bDiscard, int iSide, int mode,
- Object oTrait) {
+ Integer trait) {
int iBP = bpProps.getBorderWidth(iSide, bDiscard);
if (iBP > 0) {
- area.addTrait(oTrait,
+ area.addTrait(trait,
new BorderProps(bpProps.getBorderStyle(iSide),
iBP, bpProps.getBorderColor(iSide),
mode));
--
cgit v1.2.3
From 941181b8e3bf0369f1803e9af89bff52c0c93c8f Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Tue, 1 Feb 2011 16:04:41 +0000
Subject: Allow afp:no-operation to be added to fo:page-sequence (page group in
AFP) and fo:declarations (document in AFP). Includes a test case. Update QDox
to avoid a bug with class private enums. Connect some older test cases into
the standard test suite.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066078 13f79535-47bb-0310-9956-ffa450edef68
---
build.xml | 1 +
lib/build/qdox-1.12.jar | Bin 0 -> 179721 bytes
lib/build/qdox-1.6.3.jar | Bin 104078 -> 0 bytes
.../apache/fop/tools/EventProducerCollector.java | 15 ++-
src/documentation/content/xdocs/trunk/output.xml | 12 +-
src/java/org/apache/fop/afp/DataStream.java | 10 +-
.../afp/modca/AbstractResourceGroupContainer.java | 4 +-
src/java/org/apache/fop/afp/modca/NoOperation.java | 21 +++-
.../apache/fop/fo/FOValidationEventProducer.xml | 1 +
.../apache/fop/render/afp/AFPDocumentHandler.java | 80 +++++++++-----
.../render/afp/extensions/AFPPageSetupElement.java | 10 +-
status.xml | 3 +
test/java/org/apache/fop/StandardTestSuite.java | 4 +
.../fop/render/AbstractRenderingTestCase.java | 106 ++++++++++++++++++
.../org/apache/fop/render/afp/AFPTestSuite.java | 42 +++++++
.../apache/fop/render/afp/AbstractAFPTestCase.java | 47 ++++++++
.../apache/fop/render/afp/NoOperationTestCase.java | 123 +++++++++++++++++++++
test/java/org/apache/fop/render/afp/nops.fo | 41 +++++++
.../fop/render/ps/AbstractPostScriptTestCase.java | 54 +--------
.../fop/render/ps/ImageHandlingTestCase.java | 1 +
.../java/org/apache/fop/render/ps/PSTestSuite.java | 43 +++++++
.../render/ps/ResourceOptimizationTestCase.java | 2 +-
22 files changed, 525 insertions(+), 95 deletions(-)
create mode 100644 lib/build/qdox-1.12.jar
delete mode 100644 lib/build/qdox-1.6.3.jar
create mode 100644 test/java/org/apache/fop/render/AbstractRenderingTestCase.java
create mode 100644 test/java/org/apache/fop/render/afp/AFPTestSuite.java
create mode 100644 test/java/org/apache/fop/render/afp/AbstractAFPTestCase.java
create mode 100644 test/java/org/apache/fop/render/afp/NoOperationTestCase.java
create mode 100644 test/java/org/apache/fop/render/afp/nops.fo
create mode 100644 test/java/org/apache/fop/render/ps/PSTestSuite.java
diff --git a/build.xml b/build.xml
index c63de4004..b93a0176f 100644
--- a/build.xml
+++ b/build.xml
@@ -737,6 +737,7 @@ list of possible build targets.
+
diff --git a/lib/build/qdox-1.12.jar b/lib/build/qdox-1.12.jar
new file mode 100644
index 000000000..3d850e5f5
Binary files /dev/null and b/lib/build/qdox-1.12.jar differ
diff --git a/lib/build/qdox-1.6.3.jar b/lib/build/qdox-1.6.3.jar
deleted file mode 100644
index 3e99cb064..000000000
Binary files a/lib/build/qdox-1.6.3.jar and /dev/null differ
diff --git a/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java b/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java
index 4721f41df..7b103e0cd 100644
--- a/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java
+++ b/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java
@@ -21,7 +21,6 @@ package org.apache.fop.tools;
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -47,10 +46,10 @@ import com.thoughtworks.qdox.model.Type;
class EventProducerCollector {
private static final String CLASSNAME_EVENT_PRODUCER = EventProducer.class.getName();
- private static final Map PRIMITIVE_MAP;
+ private static final Map> PRIMITIVE_MAP;
static {
- Map m = new java.util.HashMap();
+ Map > m = new java.util.HashMap>();
m.put("boolean", Boolean.class);
m.put("byte", Byte.class);
m.put("char", Character.class);
@@ -63,7 +62,7 @@ class EventProducerCollector {
}
private DocletTagFactory tagFactory;
- private List models = new ArrayList();
+ private List models = new java.util.ArrayList();
/**
* Creates a new EventProducerCollector.
@@ -139,7 +138,7 @@ class EventProducerCollector {
throws EventConventionException, ClassNotFoundException {
JavaClass clazz = method.getParentClass();
//Check EventProducer conventions
- if (!method.getReturns().isVoid()) {
+ if (!method.getReturnType().isVoid()) {
throw new EventConventionException("All methods of interface "
+ clazz.getFullyQualifiedName() + " must have return type 'void'!");
}
@@ -168,10 +167,10 @@ class EventProducerCollector {
if (params.length > 1) {
for (int j = 1, cj = params.length; j < cj; j++) {
JavaParameter p = params[j];
- Class type;
+ Class> type;
JavaClass pClass = p.getType().getJavaClass();
if (p.getType().isPrimitive()) {
- type = (Class)PRIMITIVE_MAP.get(pClass.getName());
+ type = PRIMITIVE_MAP.get(pClass.getName());
if (type == null) {
throw new UnsupportedOperationException(
"Primitive datatype not supported: " + pClass.getName());
@@ -197,7 +196,7 @@ class EventProducerCollector {
* Returns the event model that has been accumulated.
* @return the event model.
*/
- public List getModels() {
+ public List getModels() {
return this.models;
}
diff --git a/src/documentation/content/xdocs/trunk/output.xml b/src/documentation/content/xdocs/trunk/output.xml
index 226a2d96c..ea994b521 100644
--- a/src/documentation/content/xdocs/trunk/output.xml
+++ b/src/documentation/content/xdocs/trunk/output.xml
@@ -931,9 +931,15 @@ Note that the value of the encoding attribute in the example is the double-byte
]]>
- The no-operation extension element can only occur within a simple-page-master.
- Multiple no-operation extension elements within a simple-page-master are allowed.
- The name attribute is mandatory.
+
The no-operation extension element can appear as child of
+ simple-page-master (appears after "Begin Page" BPG),
+ page-sequence (appears after "Begin Named Page Group" BNG
+ and declarations (appears after "Begin Document" BDT).
+ Multiple no-operation extension elements inside the same formatting object are allowed.
+ Each NOP will appear right after the respective "Begin" field indicated above even if it
+ is specified as the last child under its parent. However, the order inside the parent
+ will be maintained.
+ The name attribute is mandatory but will not appear inside the AFP stream.
diff --git a/src/java/org/apache/fop/afp/DataStream.java b/src/java/org/apache/fop/afp/DataStream.java
index a437c3004..2794ae932 100644
--- a/src/java/org/apache/fop/afp/DataStream.java
+++ b/src/java/org/apache/fop/afp/DataStream.java
@@ -595,7 +595,13 @@ public class DataStream {
* byte data
*/
public void createNoOperation(String content) {
- currentPage.createNoOperation(content);
+ if (currentPage != null) {
+ currentPage.createNoOperation(content);
+ } else if (currentPageGroup != null) {
+ currentPageGroup.createNoOperation(content);
+ } else {
+ document.createNoOperation(content);
+ }
}
/**
@@ -639,9 +645,9 @@ public class DataStream {
currentPageGroup.endPageGroup();
tleSequence = currentPageGroup.getTleSequence();
document.addPageGroup(currentPageGroup);
- document.writeToStream(outputStream);
currentPageGroup = null;
}
+ document.writeToStream(outputStream); //Flush objects
}
/**
diff --git a/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java b/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java
index 2c5e02328..f8c5a38d3 100644
--- a/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java
+++ b/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java
@@ -126,6 +126,7 @@ implements Streamable {
// }
/** {@inheritDoc} */
+ @Override
public void writeToStream(OutputStream os) throws IOException {
if (!started) {
writeStart(os);
@@ -140,6 +141,7 @@ implements Streamable {
}
/** {@inheritDoc} */
+ @Override
protected void writeObjects(Collection/**/ objects, OutputStream os)
throws IOException {
writeObjects(objects, os, false);
@@ -176,7 +178,7 @@ implements Streamable {
* @return true if this object can be written
*/
protected boolean canWrite(AbstractAFPObject obj) {
- if (obj instanceof AbstractPageObject) {
+ if (obj instanceof Completable) {
return ((Completable)obj).isComplete();
}
else {
diff --git a/src/java/org/apache/fop/afp/modca/NoOperation.java b/src/java/org/apache/fop/afp/modca/NoOperation.java
index cb5841346..cb6f4d60b 100644
--- a/src/java/org/apache/fop/afp/modca/NoOperation.java
+++ b/src/java/org/apache/fop/afp/modca/NoOperation.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.OutputStream;
import org.apache.fop.afp.AFPConstants;
+import org.apache.fop.afp.Completable;
import org.apache.fop.afp.util.BinaryUtils;
/**
@@ -35,7 +36,7 @@ import org.apache.fop.afp.util.BinaryUtils;
* No Operation structured fields, no semantics should be attached to
* the data carried by the No Operation structured field in interchange
*/
-public class NoOperation extends AbstractAFPObject {
+public class NoOperation extends AbstractAFPObject implements Completable {
/** Up to 32759 bytes of data with no architectural definition */
private static final int MAX_DATA_LEN = 32759;
@@ -81,7 +82,7 @@ public class NoOperation extends AbstractAFPObject {
data[1] = rl1[0];
data[2] = rl1[1];
- // Structured field ID for a TLE
+ // Structured field ID for a NOP
data[3] = (byte) 0xD3;
data[4] = (byte) 0xEE;
data[5] = (byte) 0xEE;
@@ -97,4 +98,20 @@ public class NoOperation extends AbstractAFPObject {
os.write(data);
}
+ /** {@inheritDoc} */
+ public boolean isComplete() {
+ return true; //always complete
+ }
+
+ /** {@inheritDoc} */
+ public void setComplete(boolean complete) {
+ //ignore
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return "NOP: " + content.substring(0, Math.min(64, content.length()));
+ }
+
}
\ No newline at end of file
diff --git a/src/java/org/apache/fop/fo/FOValidationEventProducer.xml b/src/java/org/apache/fop/fo/FOValidationEventProducer.xml
index c3e4b6b61..509f7c1d3 100644
--- a/src/java/org/apache/fop/fo/FOValidationEventProducer.xml
+++ b/src/java/org/apache/fop/fo/FOValidationEventProducer.xml
@@ -9,6 +9,7 @@
The element must be a child of fo:simple-page-master.
The element must be a child of fo:declarations.
The element must be a child of fo:declarations or fo:simple-page-master.
+ The element must be a child of fo:declarations, fo:simple-page-master or fo:page-sequence.
The element must be a child of fo:instream-foreign-object or fo:external-graphic.
The element must be a child of fo:page-sequence.
The element must be a child of fo:page-sequence or fo:simple-page-master.
diff --git a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
index c37e0c37c..87651defd 100644
--- a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
+++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
@@ -77,17 +77,17 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
private DataStream dataStream;
/** the map of page segments */
- private Map/**/pageSegmentMap
- = new java.util.HashMap/**/();
+ private Map pageSegmentMap
+ = new java.util.HashMap();
/** Medium Map referenced on previous page **/
private String lastMediumMap;
- private static final int LOC_ELSEWHERE = 0;
- private static final int LOC_FOLLOWING_PAGE_SEQUENCE = 1;
- private static final int LOC_IN_PAGE_HEADER = 2;
+ private static enum Location {
+ ELSEWHERE, IN_DOCUMENT_HEADER, FOLLOWING_PAGE_SEQUENCE, IN_PAGE_HEADER
+ }
- private int location = LOC_ELSEWHERE;
+ private Location location = Location.ELSEWHERE;
/** the shading mode for filled rectangles */
private AFPShadingMode shadingMode = AFPShadingMode.COLOR;
@@ -117,6 +117,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
}
/** {@inheritDoc} */
+ @Override
public void setDefaultFontInfo(FontInfo fontInfo) {
FontManager fontManager = getUserAgent().getFactory().getFontManager();
FontCollection[] fontCollections = new FontCollection[] {
@@ -152,6 +153,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
}
/** {@inheritDoc} */
+ @Override
public void startDocument() throws IFException {
super.startDocument();
try {
@@ -165,11 +167,23 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
}
}
+
+ /** {@inheritDoc} */
+ @Override
+ public void startDocumentHeader() throws IFException {
+ super.startDocumentHeader();
+ this.location = Location.IN_DOCUMENT_HEADER;
+ }
+
/** {@inheritDoc} */
+ @Override
public void endDocumentHeader() throws IFException {
+ super.endDocumentHeader();
+ this.location = Location.ELSEWHERE;
}
/** {@inheritDoc} */
+ @Override
public void endDocument() throws IFException {
try {
this.dataStream.endDocument();
@@ -189,7 +203,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
} catch (IOException ioe) {
throw new IFException("I/O error in startPageSequence()", ioe);
}
- this.location = LOC_FOLLOWING_PAGE_SEQUENCE;
+ this.location = Location.FOLLOWING_PAGE_SEQUENCE;
}
/** {@inheritDoc} */
@@ -212,7 +226,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
/** {@inheritDoc} */
public void startPage(int index, String name, String pageMasterName, Dimension size)
throws IFException {
- this.location = LOC_ELSEWHERE;
+ this.location = Location.ELSEWHERE;
paintingState.clear();
AffineTransform baseTransform = getBaseTransform();
@@ -232,14 +246,16 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
}
/** {@inheritDoc} */
+ @Override
public void startPageHeader() throws IFException {
super.startPageHeader();
- this.location = LOC_IN_PAGE_HEADER;
+ this.location = Location.IN_PAGE_HEADER;
}
/** {@inheritDoc} */
+ @Override
public void endPageHeader() throws IFException {
- this.location = LOC_ELSEWHERE;
+ this.location = Location.ELSEWHERE;
super.endPageHeader();
}
@@ -272,17 +288,36 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
AFPPageSetup aps = (AFPPageSetup)extension;
String element = aps.getElementName();
if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(element)) {
- if (this.location != LOC_IN_PAGE_HEADER
- && this.location != LOC_FOLLOWING_PAGE_SEQUENCE) {
+ switch (this.location) {
+ case FOLLOWING_PAGE_SEQUENCE:
+ case IN_PAGE_HEADER:
+ String name = aps.getName();
+ String value = aps.getValue();
+ dataStream.createTagLogicalElement(name, value);
+ break;
+ default:
throw new IFException(
"TLE extension must be in the page header or between page-sequence"
+ " and the first page: " + aps, null);
}
- String name = aps.getName();
- String value = aps.getValue();
- dataStream.createTagLogicalElement(name, value);
+ } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
+ switch (this.location) {
+ case IN_DOCUMENT_HEADER:
+ case FOLLOWING_PAGE_SEQUENCE:
+ case IN_PAGE_HEADER:
+ String content = aps.getContent();
+ if (content != null) {
+ dataStream.createNoOperation(content);
+ }
+ break;
+ default:
+ throw new IFException(
+ "NOP extension must be in the document header, the page header"
+ + " or between page-sequence"
+ + " and the first page: " + aps, null);
+ }
} else {
- if (this.location != LOC_IN_PAGE_HEADER) {
+ if (this.location != Location.IN_PAGE_HEADER) {
throw new IFException(
"AFP page setup extension encountered outside the page header: " + aps,
null);
@@ -294,16 +329,11 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
String source = apse.getValue();
String uri = apse.getResourceSrc();
pageSegmentMap.put(source, new PageSegmentDescriptor(name, uri));
- } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
- String content = aps.getContent();
- if (content != null) {
- dataStream.createNoOperation(content);
- }
}
}
} else if (extension instanceof AFPPageOverlay) {
AFPPageOverlay ipo = (AFPPageOverlay)extension;
- if (this.location != LOC_IN_PAGE_HEADER) {
+ if (this.location != Location.IN_PAGE_HEADER) {
throw new IFException(
"AFP page overlay extension encountered outside the page header: " + ipo,
null);
@@ -313,8 +343,8 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
dataStream.createIncludePageOverlay(overlay, ipo.getX(), ipo.getY());
}
} else if (extension instanceof AFPInvokeMediumMap) {
- if (this.location != LOC_FOLLOWING_PAGE_SEQUENCE
- && this.location != LOC_IN_PAGE_HEADER) {
+ if (this.location != Location.FOLLOWING_PAGE_SEQUENCE
+ && this.location != Location.IN_PAGE_HEADER) {
throw new IFException(
"AFP IMM extension must be between page-sequence"
@@ -401,7 +431,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
* @return the page segment descriptor or null if there's no page segment for the given URI
*/
PageSegmentDescriptor getPageSegmentNameFor(String uri) {
- return (PageSegmentDescriptor)pageSegmentMap.get(uri);
+ return pageSegmentMap.get(uri);
}
}
diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java
index 19f98f32a..b5b05191a 100644
--- a/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java
+++ b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java
@@ -54,6 +54,7 @@ public class AFPPageSetupElement extends AbstractAFPExtensionObject {
}
/** {@inheritDoc} */
+ @Override
protected void startOfNode() throws FOPException {
super.startOfNode();
if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(getLocalName())) {
@@ -63,14 +64,17 @@ public class AFPPageSetupElement extends AbstractAFPExtensionObject {
"rule.childOfPageSequenceOrSPM");
}
} else {
- if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) {
+ if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER
+ && parent.getNameId() != Constants.FO_PAGE_SEQUENCE
+ && parent.getNameId() != Constants.FO_DECLARATIONS) {
invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(),
- "rule.childOfSPM");
+ "rule.childOfSPMorPSorDeclarations");
}
}
}
/** {@inheritDoc} */
+ @Override
protected void characters(char[] data, int start, int length,
PropertyList pList, Locator locator) throws FOPException {
StringBuffer sb = new StringBuffer();
@@ -83,6 +87,7 @@ public class AFPPageSetupElement extends AbstractAFPExtensionObject {
}
/** {@inheritDoc} */
+ @Override
public void processNode(String elementName, Locator locator,
Attributes attlist, PropertyList propertyList)
throws FOPException {
@@ -106,6 +111,7 @@ public class AFPPageSetupElement extends AbstractAFPExtensionObject {
}
/** {@inheritDoc} */
+ @Override
protected ExtensionAttachment instantiateExtensionAttachment() {
return new AFPPageSetup(getLocalName());
}
diff --git a/status.xml b/status.xml
index dd131de73..8afa69af4 100644
--- a/status.xml
+++ b/status.xml
@@ -59,6 +59,9 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
+
+ Allow afp:no-operation to also appear under fo:page-sequence and fo:declarations.
+
Bugfix: fix issue in RenderPagesModel.checkPreparedPages() where the same page-sequence
is potentially started multiple times.
diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java
index caf75b4b4..61a9bdc5e 100644
--- a/test/java/org/apache/fop/StandardTestSuite.java
+++ b/test/java/org/apache/fop/StandardTestSuite.java
@@ -26,12 +26,14 @@ import org.apache.fop.fonts.DejaVuLGCSerifTest;
import org.apache.fop.image.loader.batik.ImageLoaderTestCase;
import org.apache.fop.image.loader.batik.ImagePreloaderTestCase;
import org.apache.fop.intermediate.IFMimickingTestCase;
+import org.apache.fop.render.afp.AFPTestSuite;
import org.apache.fop.render.extensions.prepress.PageBoundariesTest;
import org.apache.fop.render.extensions.prepress.PageScaleTest;
import org.apache.fop.render.pdf.PDFAConformanceTestCase;
import org.apache.fop.render.pdf.PDFCMapTestCase;
import org.apache.fop.render.pdf.PDFEncodingTestCase;
import org.apache.fop.render.pdf.PDFsRGBSettingsTestCase;
+import org.apache.fop.render.ps.PSTestSuite;
import org.apache.fop.render.rtf.RichTextFormatTestSuite;
import org.apache.fop.traits.MinOptMaxTest;
@@ -54,6 +56,8 @@ public class StandardTestSuite {
suite.addTest(new TestSuite(PDFCMapTestCase.class));
suite.addTest(new TestSuite(PDFsRGBSettingsTestCase.class));
suite.addTest(new TestSuite(DejaVuLGCSerifTest.class));
+ suite.addTest(AFPTestSuite.suite());
+ suite.addTest(PSTestSuite.suite());
suite.addTest(RichTextFormatTestSuite.suite());
suite.addTest(new TestSuite(ImageLoaderTestCase.class));
suite.addTest(new TestSuite(ImagePreloaderTestCase.class));
diff --git a/test/java/org/apache/fop/render/AbstractRenderingTestCase.java b/test/java/org/apache/fop/render/AbstractRenderingTestCase.java
new file mode 100644
index 000000000..daaa94e41
--- /dev/null
+++ b/test/java/org/apache/fop/render/AbstractRenderingTestCase.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Map;
+import java.util.MissingResourceException;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.MimeConstants;
+
+/**
+ * Abstract base class for rendering (output) verification tests.
+ */
+public abstract class AbstractRenderingTestCase extends TestCase {
+
+ private static final Map MIME_MAP = new java.util.HashMap();
+
+ static {
+ MIME_MAP.put(MimeConstants.MIME_PDF, ".pdf");
+ MIME_MAP.put(MimeConstants.MIME_POSTSCRIPT, ".ps");
+ MIME_MAP.put(MimeConstants.MIME_AFP, ".afp");
+ }
+
+ /** the JAXP TransformerFactory */
+ protected TransformerFactory tFactory = TransformerFactory.newInstance();
+ /** the FopFactory */
+ protected FopFactory fopFactory = FopFactory.newInstance();
+
+ /**
+ * Renders a test file.
+ * @param ua the user agent (with override set!)
+ * @param resourceName the resource name for the FO file
+ * @param suffix a suffix for the output filename
+ * @param outputFormat MIME type of the requested output format
+ * @return the output file
+ * @throws Exception if an error occurs
+ */
+ protected File renderFile(FOUserAgent ua, String resourceName, String suffix,
+ String outputFormat) throws Exception {
+ String extension = MIME_MAP.get(outputFormat);
+ assert extension != null;
+ File outputFile = new File("build/test-results/" + resourceName + suffix + extension);
+ File outputDir = outputFile.getParentFile();
+ FileUtils.forceMkdir(outputDir);
+
+ // Prepare input file
+ InputStream in = getClass().getResourceAsStream(resourceName);
+ if (in == null) {
+ throw new MissingResourceException(resourceName + " not found in resources",
+ getClass().getName(), null);
+ }
+ try {
+ Source src = new StreamSource(in);
+
+ // Create output file
+ OutputStream out = new java.io.FileOutputStream(outputFile);
+ out = new java.io.BufferedOutputStream(out);
+ try {
+ Fop fop = fopFactory.newFop(outputFormat, ua, out);
+ SAXResult res = new SAXResult(fop.getDefaultHandler());
+
+ Transformer transformer = tFactory.newTransformer();
+ transformer.transform(src, res);
+ } finally {
+ IOUtils.closeQuietly(out);
+ }
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ return outputFile;
+ }
+
+}
diff --git a/test/java/org/apache/fop/render/afp/AFPTestSuite.java b/test/java/org/apache/fop/render/afp/AFPTestSuite.java
new file mode 100644
index 000000000..3f12746bf
--- /dev/null
+++ b/test/java/org/apache/fop/render/afp/AFPTestSuite.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for FOP's AFP output.
+ */
+public class AFPTestSuite {
+
+ /**
+ * Builds the test suite
+ * @return the test suite
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test suite for AFP output");
+ //$JUnit-BEGIN$
+ suite.addTest(new TestSuite(NoOperationTestCase.class));
+ //$JUnit-END$
+ return suite;
+ }
+}
diff --git a/test/java/org/apache/fop/render/afp/AbstractAFPTestCase.java b/test/java/org/apache/fop/render/afp/AbstractAFPTestCase.java
new file mode 100644
index 000000000..7f081a4d0
--- /dev/null
+++ b/test/java/org/apache/fop/render/afp/AbstractAFPTestCase.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp;
+
+import java.io.File;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRenderingTestCase;
+
+/**
+ * Abstract base class for AFP verification tests.
+ */
+abstract class AbstractAFPTestCase extends AbstractRenderingTestCase {
+
+ /**
+ * Renders a test file.
+ * @param ua the user agent (with override set!)
+ * @param resourceName the resource name for the FO file
+ * @param suffix a suffix for the output filename
+ * @return the output file
+ * @throws Exception if an error occurs
+ */
+ protected File renderFile(FOUserAgent ua, String resourceName, String suffix)
+ throws Exception {
+ return renderFile(ua, resourceName, suffix, MimeConstants.MIME_AFP);
+ }
+
+
+}
diff --git a/test/java/org/apache/fop/render/afp/NoOperationTestCase.java b/test/java/org/apache/fop/render/afp/NoOperationTestCase.java
new file mode 100644
index 000000000..56e4551d1
--- /dev/null
+++ b/test/java/org/apache/fop/render/afp/NoOperationTestCase.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.Assert;
+
+import org.apache.commons.io.IOUtils;
+
+import org.apache.fop.afp.AFPConstants;
+import org.apache.fop.afp.parser.MODCAParser;
+import org.apache.fop.afp.parser.UnparsedStructuredField;
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * Tests generation of afp:no-operation (NOPs).
+ */
+public class NoOperationTestCase extends AbstractAFPTestCase {
+
+ /**
+ * Tests afp:no-operation.
+ * @throws Exception if an error occurs
+ */
+ public void testNoOperation() throws Exception {
+ FOUserAgent ua = fopFactory.newFOUserAgent();
+ File outputFile = renderFile(ua, "nops.fo", "");
+
+ InputStream in = new java.io.FileInputStream(outputFile);
+ try {
+ MODCAParser parser = new MODCAParser(in);
+ UnparsedStructuredField field = skipTo(parser, 0xD3A8A8); //Begin Document
+
+ //NOP in fo:declarations
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3EEEE, field.getSfTypeID());
+ assertEquals("fo:declarations", getNopText(field));
+
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3A8AD, field.getSfTypeID()); //Begin Named Page Group
+
+ //NOPs in fo:page-sequence
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3EEEE, field.getSfTypeID());
+ assertEquals("fo:page-sequence: start", getNopText(field));
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3EEEE, field.getSfTypeID());
+ assertEquals("fo:page-sequence: end", getNopText(field));
+
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3A8AF, field.getSfTypeID()); //Begin Page
+
+ field = skipTo(parser, 0xD3A9C9); //End Active Environment Group
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3EEEE, field.getSfTypeID());
+ assertEquals("fo:simple-page-master: first", getNopText(field));
+
+ field = skipTo(parser, 0xD3A9C9); //End Active Environment Group
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3EEEE, field.getSfTypeID());
+ assertEquals("fo:simple-page-master: rest", getNopText(field));
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+
+ int counter = 0;
+ in = new java.io.FileInputStream(outputFile);
+ try {
+ MODCAParser parser = new MODCAParser(in);
+ while (true) {
+ UnparsedStructuredField field = parser.readNextStructuredField();
+ if (field == null) {
+ break;
+ }
+ if (field.getSfTypeID() == 0xD3EEEE) {
+ counter++;
+ }
+ }
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ assertEquals(6, counter); //decl, 2 * ps, 3 * page/spm
+ }
+
+ private String getNopText(UnparsedStructuredField field) throws UnsupportedEncodingException {
+ byte[] data = field.getData();
+ String text = new String(data, AFPConstants.EBCIDIC_ENCODING);
+ return text;
+ }
+
+ private UnparsedStructuredField skipTo(MODCAParser parser, int typeID) throws IOException {
+ UnparsedStructuredField field = null;
+ do {
+ field = parser.readNextStructuredField();
+ if (field.getSfTypeID() == typeID) {
+ return field;
+ }
+ } while (field != null);
+ Assert.fail("Structured field not found: " + Integer.toHexString(typeID));
+ return null;
+ }
+
+}
diff --git a/test/java/org/apache/fop/render/afp/nops.fo b/test/java/org/apache/fop/render/afp/nops.fo
new file mode 100644
index 000000000..96c6e0d24
--- /dev/null
+++ b/test/java/org/apache/fop/render/afp/nops.fo
@@ -0,0 +1,41 @@
+
+
+
+
+ fo:simple-page-master: first
+
+
+
+
+ fo:simple-page-master: rest
+
+
+
+
+
+
+
+
+
+
+
+
+ fo:declarations
+
+
+
+ fo:page-sequence: start
+
+ Page 1
+ Page 1
+
+ Page 2
+ Page 2
+
+ Page 3
+ Page 3
+
+ fo:page-sequence: end
+
+
diff --git a/test/java/org/apache/fop/render/ps/AbstractPostScriptTestCase.java b/test/java/org/apache/fop/render/ps/AbstractPostScriptTestCase.java
index 522d193ed..30e499846 100644
--- a/test/java/org/apache/fop/render/ps/AbstractPostScriptTestCase.java
+++ b/test/java/org/apache/fop/render/ps/AbstractPostScriptTestCase.java
@@ -21,20 +21,6 @@ package org.apache.fop.render.ps;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.MissingResourceException;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.stream.StreamSource;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
import org.apache.xmlgraphics.ps.PSResource;
import org.apache.xmlgraphics.ps.dsc.DSCException;
@@ -44,19 +30,13 @@ import org.apache.xmlgraphics.ps.dsc.events.DSCComment;
import org.apache.xmlgraphics.ps.dsc.events.DSCEvent;
import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.Fop;
-import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRenderingTestCase;
/**
* Abstract base class for PostScript verification tests.
*/
-public abstract class AbstractPostScriptTestCase extends TestCase {
-
- /** the JAXP TransformerFactory */
- protected TransformerFactory tFactory = TransformerFactory.newInstance();
- /** the FopFactory */
- protected FopFactory fopFactory = FopFactory.newInstance();
+public abstract class AbstractPostScriptTestCase extends AbstractRenderingTestCase {
/**
* Renders a test file.
@@ -68,35 +48,7 @@ public abstract class AbstractPostScriptTestCase extends TestCase {
*/
protected File renderFile(FOUserAgent ua, String resourceName, String suffix)
throws Exception {
- File outputFile = new File("build/test-results/" + resourceName + suffix + ".ps");
- File outputDir = outputFile.getParentFile();
- FileUtils.forceMkdir(outputDir);
-
- // Prepare input file
- InputStream in = getClass().getResourceAsStream(resourceName);
- if (in == null) {
- throw new MissingResourceException(resourceName + " not found in resources",
- getClass().getName(), null);
- }
- try {
- Source src = new StreamSource(in);
-
- // Create PostScript
- OutputStream out = new java.io.FileOutputStream(outputFile);
- out = new java.io.BufferedOutputStream(out);
- try {
- Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, ua, out);
- SAXResult res = new SAXResult(fop.getDefaultHandler());
-
- Transformer transformer = tFactory.newTransformer();
- transformer.transform(src, res);
- } finally {
- IOUtils.closeQuietly(out);
- }
- } finally {
- IOUtils.closeQuietly(in);
- }
- return outputFile;
+ return renderFile(ua, resourceName, suffix, MimeConstants.MIME_POSTSCRIPT);
}
/**
diff --git a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java
index 72c677a0c..c127d82a5 100644
--- a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java
+++ b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java
@@ -86,6 +86,7 @@ public class ImageHandlingTestCase extends AbstractPostScriptTestCase {
gotoDSCComment(parser, DSCConstants.BEGIN_RESOURCE);
gotoDSCComment(parser, DSCConstants.BEGIN_RESOURCE);
gotoDSCComment(parser, DSCConstants.BEGIN_RESOURCE);
+ gotoDSCComment(parser, DSCConstants.BEGIN_RESOURCE);
PSResource form2 = new PSResource(PSResource.TYPE_FORM, "FOPForm:2");
checkResourceComment(parser, DSCConstants.BEGIN_RESOURCE, form2);
diff --git a/test/java/org/apache/fop/render/ps/PSTestSuite.java b/test/java/org/apache/fop/render/ps/PSTestSuite.java
new file mode 100644
index 000000000..05ba2dac7
--- /dev/null
+++ b/test/java/org/apache/fop/render/ps/PSTestSuite.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for FOP's PostScript output.
+ */
+public class PSTestSuite {
+
+ /**
+ * Builds the test suite
+ * @return the test suite
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test suite for PostScript output");
+ //$JUnit-BEGIN$
+ suite.addTest(new TestSuite(ImageHandlingTestCase.class));
+ suite.addTest(new TestSuite(ResourceOptimizationTestCase.class));
+ //$JUnit-END$
+ return suite;
+ }
+}
diff --git a/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java b/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java
index 862ad5205..327c86548 100644
--- a/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java
+++ b/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java
@@ -90,7 +90,7 @@ public class ResourceOptimizationTestCase extends AbstractPostScriptTestCase {
= (DSCCommentDocumentSuppliedResources)gotoDSCComment(parser,
DSCConstants.DOCUMENT_SUPPLIED_RESOURCES);
Set resources = supplied.getResources();
- assertEquals(4, resources.size());
+ assertEquals(5, resources.size());
assertTrue(resources.contains(form1));
assertTrue("Expected barcode.eps as supplied resource",
resources.contains(new PSResource(PSResource.TYPE_FILE,
--
cgit v1.2.3
From 723fa887a6e6c0dd7ebc18dcc0d63185c8dcb7bd Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Tue, 1 Feb 2011 20:02:08 +0000
Subject: Updated XGC JAR after migrating ColorProfileUtil
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066181 13f79535-47bb-0310-9956-ffa450edef68
---
lib/xmlgraphics-commons-1.5svn.jar | Bin 765844 -> 580694 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
diff --git a/lib/xmlgraphics-commons-1.5svn.jar b/lib/xmlgraphics-commons-1.5svn.jar
index b11bfd2d2..353b5d26e 100644
Binary files a/lib/xmlgraphics-commons-1.5svn.jar and b/lib/xmlgraphics-commons-1.5svn.jar differ
--
cgit v1.2.3
From 3c839549f3deefeba13214cf950aee3b5b832523 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Tue, 1 Feb 2011 20:03:46 +0000
Subject: Bugzilla 50698: Changes after updating XGC JAR
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066182 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/fop/pdf/PDFICCBasedColorSpace.java | 27 ++++++++++---------
src/java/org/apache/fop/pdf/PDFResources.java | 2 +-
.../fop/render/pdf/AbstractImageAdapter.java | 2 +-
.../apache/fop/render/pdf/PDFRenderingUtil.java | 4 +--
src/java/org/apache/fop/util/ColorProfileUtil.java | 30 +++++-----------------
src/java/org/apache/fop/util/ColorSpaceCache.java | 9 ++++---
6 files changed, 29 insertions(+), 45 deletions(-)
diff --git a/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java b/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
index 7511bc20d..4d473bb7c 100644
--- a/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
+++ b/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
@@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
/**
* Represents an ICCBased color space in PDF.
@@ -134,21 +135,19 @@ public class PDFICCBasedColorSpace extends PDFObject implements PDFColorSpace {
public static PDFICCStream setupsRGBColorProfile(PDFDocument pdfDoc) {
ICC_Profile profile;
PDFICCStream sRGBProfile = pdfDoc.getFactory().makePDFICCStream();
- synchronized (PDFICCBasedColorSpace.class) {
- InputStream in = PDFDocument.class.getResourceAsStream("sRGB Color Space Profile.icm");
- if (in != null) {
- try {
- profile = ICC_Profile.getInstance(in);
- } catch (IOException ioe) {
- throw new RuntimeException(
- "Unexpected IOException loading the sRGB profile: " + ioe.getMessage());
- } finally {
- IOUtils.closeQuietly(in);
- }
- } else {
- // Fallback: Use the sRGB profile from the JRE (about 140KB)
- profile = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
+ InputStream in = PDFDocument.class.getResourceAsStream("sRGB Color Space Profile.icm");
+ if (in != null) {
+ try {
+ profile = ColorProfileUtil.getICC_Profile(in);
+ } catch (IOException ioe) {
+ throw new RuntimeException(
+ "Unexpected IOException loading the sRGB profile: " + ioe.getMessage());
+ } finally {
+ IOUtils.closeQuietly(in);
}
+ } else {
+ // Fallback: Use the sRGB profile from the JRE (about 140KB)
+ profile = ColorProfileUtil.getICC_Profile(ColorSpace.CS_sRGB);
}
sRGBProfile.setColorSpace(profile, null);
return sRGBProfile;
diff --git a/src/java/org/apache/fop/pdf/PDFResources.java b/src/java/org/apache/fop/pdf/PDFResources.java
index 12eca75e4..99a42433c 100644
--- a/src/java/org/apache/fop/pdf/PDFResources.java
+++ b/src/java/org/apache/fop/pdf/PDFResources.java
@@ -25,12 +25,12 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
import org.apache.fop.fonts.FontDescriptor;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.Typeface;
import org.apache.fop.fonts.base14.Symbol;
import org.apache.fop.fonts.base14.ZapfDingbats;
-import org.apache.fop.util.ColorProfileUtil;
/**
* class representing a /Resources object.
diff --git a/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java b/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
index 2130ef685..9e20886e0 100644
--- a/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
+++ b/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
@@ -25,6 +25,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
import org.apache.fop.pdf.PDFColor;
import org.apache.fop.pdf.PDFConformanceException;
@@ -35,7 +36,6 @@ import org.apache.fop.pdf.PDFICCBasedColorSpace;
import org.apache.fop.pdf.PDFICCStream;
import org.apache.fop.pdf.PDFImage;
import org.apache.fop.pdf.PDFReference;
-import org.apache.fop.util.ColorProfileUtil;
/**
* Abstract PDFImage implementation for the PDF renderer.
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java b/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
index ae205a1e5..e63059472 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
@@ -35,6 +35,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xmlgraphics.image.loader.util.ImageUtil;
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
import org.apache.xmlgraphics.xmp.Metadata;
import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
@@ -64,7 +65,6 @@ import org.apache.fop.pdf.PDFReference;
import org.apache.fop.pdf.PDFText;
import org.apache.fop.pdf.PDFXMode;
import org.apache.fop.render.pdf.extensions.PDFEmbeddedFileExtensionAttachment;
-import org.apache.fop.util.ColorProfileUtil;
/**
* Utility class which enables all sorts of features that are not directly connected to the
@@ -294,7 +294,7 @@ class PDFRenderingUtil implements PDFConfigurationConstants {
in = new URL(src.getSystemId()).openStream();
}
try {
- profile = ICC_Profile.getInstance(in);
+ profile = ColorProfileUtil.getICC_Profile(in);
} finally {
IOUtils.closeQuietly(in);
}
diff --git a/src/java/org/apache/fop/util/ColorProfileUtil.java b/src/java/org/apache/fop/util/ColorProfileUtil.java
index 35b6660dc..9ee34d2b6 100644
--- a/src/java/org/apache/fop/util/ColorProfileUtil.java
+++ b/src/java/org/apache/fop/util/ColorProfileUtil.java
@@ -19,13 +19,11 @@
package org.apache.fop.util;
-import java.awt.color.ColorSpace;
-import java.awt.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
-import java.io.UnsupportedEncodingException;
/**
* Helper methods for handling color profiles.
+ * @deprecated use org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil directly
*/
public final class ColorProfileUtil {
@@ -36,21 +34,11 @@ public final class ColorProfileUtil {
* Returns the profile description of an ICC profile
* @param profile the profile
* @return the description
+ * @deprecated use org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil directly
*/
public static String getICCProfileDescription(ICC_Profile profile) {
- byte[] data = profile.getData(ICC_Profile.icSigProfileDescriptionTag);
- if (data == null) {
- return null;
- } else {
- //Info on the data format: http://www.color.org/ICC-1_1998-09.PDF
- int length = (data[8] << 3 * 8) | (data[9] << 2 * 8) | (data[10] << 8) | data[11];
- length--; //Remove trailing NUL character
- try {
- return new String(data, 12, length, "US-ASCII");
- } catch (UnsupportedEncodingException e) {
- throw new UnsupportedOperationException("Incompatible VM");
- }
- }
+ return org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil
+ .getICCProfileDescription(profile);
}
/**
@@ -58,14 +46,10 @@ public final class ColorProfileUtil {
* provided by the Java class library.
* @param profile the color profile to check
* @return true if it is the default sRGB profile
+ * @deprecated use org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil directly
*/
public static boolean isDefaultsRGB(ICC_Profile profile) {
- ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
- ICC_Profile sRGBProfile = null;
- if (sRGB instanceof ICC_ColorSpace) {
- sRGBProfile = ((ICC_ColorSpace)sRGB).getProfile();
- }
- return profile == sRGBProfile;
+ return org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil
+ .isDefaultsRGB(profile);
}
-
}
diff --git a/src/java/org/apache/fop/util/ColorSpaceCache.java b/src/java/org/apache/fop/util/ColorSpaceCache.java
index 7b3f409e0..63d8746f7 100644
--- a/src/java/org/apache/fop/util/ColorSpaceCache.java
+++ b/src/java/org/apache/fop/util/ColorSpaceCache.java
@@ -31,6 +31,7 @@ import javax.xml.transform.stream.StreamSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
/**
* Map with cached ICC based ColorSpace objects.
@@ -40,7 +41,8 @@ public class ColorSpaceCache {
private static Log log = LogFactory.getLog(ColorSpaceCache.class);
private URIResolver resolver;
- private Map colorSpaceMap = Collections.synchronizedMap(new java.util.HashMap());
+ private Map colorSpaceMap
+ = Collections.synchronizedMap(new java.util.HashMap());
/**
* Default constructor
@@ -74,7 +76,7 @@ public class ColorSpaceCache {
if (src != null && src instanceof StreamSource) {
// FOP URI resolver found ICC profile - create ICC profile
// from the Source
- iccProfile = ICC_Profile.getInstance(((StreamSource) src)
+ iccProfile = ColorProfileUtil.getICC_Profile(((StreamSource) src)
.getInputStream());
} else {
// TODO - Would it make sense to fall back on VM ICC
@@ -102,8 +104,7 @@ public class ColorSpaceCache {
log.warn("Color profile '" + iccProfileSrc + "' not found.");
}
} else {
- colorSpace = (ColorSpace)colorSpaceMap.get(base
- + iccProfileSrc);
+ colorSpace = colorSpaceMap.get(base + iccProfileSrc);
}
return colorSpace;
}
--
cgit v1.2.3
From d8261a197b2d8cd10c3f171f2a3ca7e9f04f1302 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Tue, 1 Feb 2011 20:20:02 +0000
Subject: Bugzilla 48334: Added implementation for xml:base
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066190 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/fo/Constants.java | 4 +-
src/java/org/apache/fop/fo/FOPropertyMapping.java | 9 +-
src/java/org/apache/fop/fo/PropertyList.java | 3 +-
.../org/apache/fop/fo/properties/URIProperty.java | 148 +++++++++++++++++++++
status.xml | 4 +
test/fotree/testcases/xml_base.fo | 82 ++++++++++++
6 files changed, 247 insertions(+), 3 deletions(-)
create mode 100644 src/java/org/apache/fop/fo/properties/URIProperty.java
create mode 100644 test/fotree/testcases/xml_base.fo
diff --git a/src/java/org/apache/fop/fo/Constants.java b/src/java/org/apache/fop/fo/Constants.java
index 5f23502f3..726d4d89e 100644
--- a/src/java/org/apache/fop/fo/Constants.java
+++ b/src/java/org/apache/fop/fo/Constants.java
@@ -778,9 +778,11 @@ public interface Constants {
* Used for accessibility.
*/
int PR_X_ALT_TEXT = 275;
+ /** Property constant - FOP proprietary prototype (in XSL-FO 2.0 Requirements) */
+ int PR_X_XML_BASE = 276;
/** Number of property constants defined */
- int PROPERTY_COUNT = 275;
+ int PROPERTY_COUNT = 276;
// compound property constants
diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java
index b1e851ea4..c32aca0f0 100644
--- a/src/java/org/apache/fop/fo/FOPropertyMapping.java
+++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java
@@ -64,6 +64,7 @@ import org.apache.fop.fo.properties.StringProperty;
import org.apache.fop.fo.properties.TableBorderPrecedence;
import org.apache.fop.fo.properties.TextDecorationProperty;
import org.apache.fop.fo.properties.ToBeImplementedProperty;
+import org.apache.fop.fo.properties.URIProperty;
import org.apache.fop.fo.properties.VerticalAlignShorthandParser;
import org.apache.fop.fo.properties.WhiteSpaceShorthandParser;
import org.apache.fop.fo.properties.XMLLangShorthandParser;
@@ -2572,7 +2573,7 @@ public final class FOPropertyMapping implements Constants {
addPropertyMaker("score-spaces", m);
// src
- m = new StringProperty.Maker(PR_SRC);
+ m = new URIProperty.Maker(PR_SRC);
m.setInherited(false);
m.setDefault("");
addPropertyMaker("src", m);
@@ -2819,6 +2820,12 @@ public final class FOPropertyMapping implements Constants {
m.setDatatypeParser(new XMLLangShorthandParser());
addPropertyMaker("xml:lang", m);
+ // xml:base
+ m = new URIProperty.Maker(PR_X_XML_BASE);
+ m.setInherited(true);
+ m.setDefault("");
+ addPropertyMaker("xml:base", m);
+
}
}
diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java
index 8d5a4311f..a1634e868 100644
--- a/src/java/org/apache/fop/fo/PropertyList.java
+++ b/src/java/org/apache/fop/fo/PropertyList.java
@@ -312,7 +312,8 @@ public abstract class PropertyList {
attributeName = attributes.getQName(i);
attributeValue = attributes.getValue(i);
if (attributeNS == null || attributeNS.length() == 0
- || "xml:lang".equals(attributeName)) {
+ || "xml:lang".equals(attributeName)
+ || "xml:base".equals(attributeName)) {
convertAttributeToProperty(attributes, attributeName, attributeValue);
} else if (!factory.isNamespaceIgnored(attributeNS)) {
ElementMapping mapping = factory.getElementMappingRegistry().getElementMapping(
diff --git a/src/java/org/apache/fop/fo/properties/URIProperty.java b/src/java/org/apache/fop/fo/properties/URIProperty.java
new file mode 100644
index 000000000..6465fafdb
--- /dev/null
+++ b/src/java/org/apache/fop/fo/properties/URIProperty.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.properties;
+
+import org.apache.fop.datatypes.URISpecification;
+import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.expr.PropertyException;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import static org.apache.fop.fo.Constants.PR_X_XML_BASE;
+
+/**
+ * Class modeling a property that has a value of type <uri-specification>.
+ * The purpose is mainly to support resolution of a specified
+ * relative URI against a specified or inherited xml:base
+ * during the property refinement stage.
+ * If no xml:base
has been specified, only the original URI, as
+ * it appears in the source document, is stored as the property's specified
+ * value.
+ */
+public class URIProperty extends Property {
+
+ /** will be null if the URI is not resolved against an xml:base */
+ private URI resolvedURI;
+
+ /**
+ * Default constructor, to create a {@link URIProperty} from a
+ * {@code java.net.URI} directly.
+ * @param uri a resolved {@code java.net.URI}
+ */
+ protected URIProperty(URI uri) {
+ this.resolvedURI = uri;
+ }
+
+ /**
+ * Alternate constructor, to create a {@link URIProperty} from a
+ * string representation.
+ * @param uri a {@code java.lang.String} representing the URI
+ * @param resolve flag indicating whether this URI was the result of resolution
+ * @throws IllegalArgumentException if the URI should be resolved, but is not valid.
+ */
+ private URIProperty(String uri, boolean resolve) {
+ if (resolve && !(uri == null || "".equals(uri))) {
+ this.resolvedURI = URI.create(uri);
+ } else {
+ setSpecifiedValue(uri);
+ }
+ }
+
+ /**
+ * Return a string representing the resolved URI, or the
+ * specified value if the URI is not resolved against
+ * an xml:base
+ * @return a string representing the URI
+ */
+ @Override
+ public String getString() {
+ if (resolvedURI == null) {
+ return getSpecifiedValue();
+ } else {
+ return resolvedURI.toString();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return this.getString();
+ }
+
+ /**
+ * Inner {@link PropertyMaker} subclass responsible
+ * for making instances of this type.
+ */
+ public static class Maker extends PropertyMaker {
+
+ /**
+ * Create a maker for the given property id
+ *
+ * @param propId the id of the property for which a Maker should be created
+ */
+ public Maker(int propId) {
+ super(propId);
+ }
+
+ /**
+ * {@inheritDoc}
+ * Check if {@code xml:base} has been specified and whether the
+ * given {@code value} represents a relative URI. If so, create
+ * a property representing the resolved URI.
+ */
+ @Override
+ public Property make(PropertyList propertyList, String value,
+ FObj fo) throws PropertyException {
+
+ Property p = null;
+ //special treament for data: URIs
+ if (value.matches("(?s)^(url\\(('|\")?)?data:.*$")) {
+ p = new URIProperty(value, false);
+ } else {
+ try {
+ URI specifiedURI = new URI(URISpecification.escapeURI(value));
+ URIProperty xmlBase = (URIProperty)propertyList.get(PR_X_XML_BASE, true, false);
+ if (xmlBase == null) {
+ //xml:base undefined
+ if (this.propId == PR_X_XML_BASE) {
+ //if current property is xml:base, define a new one
+ p = new URIProperty(specifiedURI);
+ p.setSpecifiedValue(value);
+ } else {
+ //otherwise, just store the specified value (for backward compatibility)
+ p = new URIProperty(value, false);
+ }
+ } else {
+ //xml:base defined, so resolve
+ p = new URIProperty(xmlBase.resolvedURI.resolve(specifiedURI));
+ p.setSpecifiedValue(value);
+ }
+ } catch (URISyntaxException use) {
+ // Let PropertyList propagate the exception
+ throw new PropertyException("Invalid URI specified");
+ }
+ }
+ return p;
+ }
+ }
+
+}
diff --git a/status.xml b/status.xml
index 8afa69af4..c0c759763 100644
--- a/status.xml
+++ b/status.xml
@@ -59,6 +59,10 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
+
+ Added support for resolution of relative URIs against a specified xml:base during
+ property refinement.
+
Allow afp:no-operation to also appear under fo:page-sequence and fo:declarations.
diff --git a/test/fotree/testcases/xml_base.fo b/test/fotree/testcases/xml_base.fo
new file mode 100644
index 000000000..fa4858d7c
--- /dev/null
+++ b/test/fotree/testcases/xml_base.fo
@@ -0,0 +1,82 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--
cgit v1.2.3
From 0bf6f2900d0198f0af1974fd2bc6d4310093b21a Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Tue, 1 Feb 2011 20:47:54 +0000
Subject: Small cleanup: extract TextDecorationMaker, move validation into
convertProperty() and eliminate unnecessary TextDecorationProperty
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066198 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/fo/FOPropertyMapping.java | 4 +-
.../fop/fo/properties/TextDecorationMaker.java | 123 +++++++++++++++
.../fop/fo/properties/TextDecorationProperty.java | 167 ---------------------
3 files changed, 125 insertions(+), 169 deletions(-)
create mode 100644 src/java/org/apache/fop/fo/properties/TextDecorationMaker.java
delete mode 100644 src/java/org/apache/fop/fo/properties/TextDecorationProperty.java
diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java
index c32aca0f0..cf4eef3a5 100644
--- a/src/java/org/apache/fop/fo/FOPropertyMapping.java
+++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java
@@ -62,7 +62,7 @@ import org.apache.fop.fo.properties.SpacePropertyMaker;
import org.apache.fop.fo.properties.SpacingPropertyMaker;
import org.apache.fop.fo.properties.StringProperty;
import org.apache.fop.fo.properties.TableBorderPrecedence;
-import org.apache.fop.fo.properties.TextDecorationProperty;
+import org.apache.fop.fo.properties.TextDecorationMaker;
import org.apache.fop.fo.properties.ToBeImplementedProperty;
import org.apache.fop.fo.properties.URIProperty;
import org.apache.fop.fo.properties.VerticalAlignShorthandParser;
@@ -1695,7 +1695,7 @@ public final class FOPropertyMapping implements Constants {
// text-decoration
//m = new EnumProperty.Maker(PR_TEXT_DECORATION);
- m = new TextDecorationProperty.Maker(PR_TEXT_DECORATION);
+ m = new TextDecorationMaker(PR_TEXT_DECORATION);
m.setInherited(false);
m.addEnum("none", getEnumProperty(EN_NONE, "NONE"));
m.addEnum("underline", getEnumProperty(EN_UNDERLINE, "UNDERLINE"));
diff --git a/src/java/org/apache/fop/fo/properties/TextDecorationMaker.java b/src/java/org/apache/fop/fo/properties/TextDecorationMaker.java
new file mode 100644
index 000000000..de26934a0
--- /dev/null
+++ b/src/java/org/apache/fop/fo/properties/TextDecorationMaker.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.properties;
+
+import java.util.List;
+
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.expr.NCnameProperty;
+import org.apache.fop.fo.expr.PropertyException;
+
+/**
+ * Dedicated {@link org.apache.fop.fo.properties.PropertyMaker} for handling the
+ * text-decoration
+ * property.
+ */
+public class TextDecorationMaker extends ListProperty.Maker {
+
+ /**
+ * Create a maker for the given property id.
+ * @param propId id of the property for which a maker should be created
+ */
+ public TextDecorationMaker(int propId) {
+ super(propId);
+ }
+
+ /**
+ * {@inheritDoc}
+ * Add validation rules for the text-decoration
property.
+ */
+ @Override
+ public Property convertProperty(Property p,
+ PropertyList propertyList,
+ FObj fo)
+ throws PropertyException {
+
+ ListProperty listProp = (ListProperty) super.convertProperty(p, propertyList, fo);
+ List lst = listProp.getList();
+ boolean none = false;
+ boolean under = false;
+ boolean over = false;
+ boolean through = false;
+ boolean blink = false;
+ int enumValue;
+ for (int i = lst.size(); --i >= 0;) {
+ Property prop = (Property)lst.get(i);
+ if (prop instanceof NCnameProperty) {
+ prop = checkEnumValues(prop.getString());
+ lst.set(i, prop);
+ }
+ enumValue = prop.getEnum();
+ switch (enumValue) {
+ case Constants.EN_NONE:
+ if (under | over | through | blink) {
+ throw new PropertyException("Invalid combination of values");
+ }
+ none = true;
+ break;
+ case Constants.EN_UNDERLINE:
+ case Constants.EN_NO_UNDERLINE:
+ case Constants.EN_OVERLINE:
+ case Constants.EN_NO_OVERLINE:
+ case Constants.EN_LINE_THROUGH:
+ case Constants.EN_NO_LINE_THROUGH:
+ case Constants.EN_BLINK:
+ case Constants.EN_NO_BLINK:
+ if (none) {
+ throw new PropertyException
+ ("'none' specified, no additional values allowed");
+ }
+ switch (enumValue) {
+ case Constants.EN_UNDERLINE:
+ case Constants.EN_NO_UNDERLINE:
+ if (!under) {
+ under = true;
+ continue;
+ }
+ case Constants.EN_OVERLINE:
+ case Constants.EN_NO_OVERLINE:
+ if (!over) {
+ over = true;
+ continue;
+ }
+ case Constants.EN_LINE_THROUGH:
+ case Constants.EN_NO_LINE_THROUGH:
+ if (!through) {
+ through = true;
+ continue;
+ }
+ case Constants.EN_BLINK:
+ case Constants.EN_NO_BLINK:
+ if (!blink) {
+ blink = true;
+ continue;
+ }
+ default:
+ throw new PropertyException("Invalid combination of values");
+ }
+ default:
+ throw new PropertyException("Invalid value specified: " + prop);
+ }
+ }
+ return listProp;
+ }
+}
diff --git a/src/java/org/apache/fop/fo/properties/TextDecorationProperty.java b/src/java/org/apache/fop/fo/properties/TextDecorationProperty.java
deleted file mode 100644
index bcd41fb20..000000000
--- a/src/java/org/apache/fop/fo/properties/TextDecorationProperty.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.fo.properties;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.fop.fo.Constants;
-import org.apache.fop.fo.FObj;
-import org.apache.fop.fo.PropertyList;
-import org.apache.fop.fo.expr.NCnameProperty;
-import org.apache.fop.fo.expr.PropertyException;
-
-/**
- * Special list property for text-decoration.
- */
-public class TextDecorationProperty extends ListProperty {
-
- /**
- * Inner class for creating instances of ListProperty
- */
- public static class Maker extends PropertyMaker {
-
- /**
- * @param propId ID of the property for which Maker should be created
- */
- public Maker(int propId) {
- super(propId);
- }
-
- /**
- * {@inheritDoc}
- */
- public Property convertProperty(Property p,
- PropertyList propertyList, FObj fo)
- throws PropertyException {
- if (p instanceof TextDecorationProperty) {
- return p;
- } else {
- if (p instanceof ListProperty) {
- ListProperty lst = (ListProperty)p;
- lst = checkEnums(lst);
- return new TextDecorationProperty((ListProperty)p);
- } else if (p instanceof EnumProperty) {
- ListProperty lst = new ListProperty(p);
- return new TextDecorationProperty(lst);
- } else {
- throw new PropertyException("Cannot convert anything other "
- + "than a list property, got a " + p.getClass().getName());
- }
- }
- }
-
- private ListProperty checkEnums(ListProperty lst) throws PropertyException {
- List l = lst.getList();
- for (int i = 0; i < l.size(); i++) {
- Property prop = (Property)l.get(i);
- if (prop instanceof EnumProperty) {
- //skip
- } else if (prop instanceof NCnameProperty) {
- Property propEnum = checkEnumValues(((NCnameProperty)prop).getString());
- if (propEnum == null) {
- throw new PropertyException("Illegal enum value: " + prop.getString());
- }
- l.set(i, propEnum);
- } else {
- throw new PropertyException("Invalid content for text-decoration "
- + "property: " + prop);
- }
- }
- return lst;
- }
-
- }
-
- /**
- * Constructs a new instance by converting a ListProperty.
- * @param listProp the ListProperty to be converted
- * @throws PropertyException in case the conversion fails
- */
- public TextDecorationProperty(ListProperty listProp) throws PropertyException {
- List lst = listProp.getList();
- boolean none = false;
- boolean under = false;
- boolean over = false;
- boolean through = false;
- boolean blink = false;
- Iterator i = lst.iterator();
- while (i.hasNext()) {
- Property prop = (Property)i.next();
- switch (prop.getEnum()) {
- case Constants.EN_NONE:
- if (under | over | through | blink) {
- throw new PropertyException(
- "Invalid combination of values");
- }
- none = true;
- break;
- case Constants.EN_UNDERLINE:
- case Constants.EN_NO_UNDERLINE:
- if (none) {
- throw new PropertyException
- ("'none' specified, no additional values allowed");
- }
- if (under) {
- throw new PropertyException("Invalid combination of values");
- }
- under = true;
- break;
- case Constants.EN_OVERLINE:
- case Constants.EN_NO_OVERLINE:
- if (none) {
- throw new PropertyException
- ("'none' specified, no additional values allowed");
- }
- if (over) {
- throw new PropertyException("Invalid combination of values");
- }
- over = true;
- break;
- case Constants.EN_LINE_THROUGH:
- case Constants.EN_NO_LINE_THROUGH:
- if (none) {
- throw new PropertyException
- ("'none' specified, no additional values allowed");
- }
- if (through) {
- throw new PropertyException("Invalid combination of values");
- }
- through = true;
- break;
- case Constants.EN_BLINK:
- case Constants.EN_NO_BLINK:
- if (none) {
- throw new PropertyException
- ("'none' specified, no additional values allowed");
- }
- if (blink) {
- throw new PropertyException("Invalid combination of values");
- }
- blink = true;
- break;
- default:
- throw new PropertyException("Invalid value specified: " + prop);
- }
- addProperty(prop);
- }
- }
-
-}
--
cgit v1.2.3
From 587a85e03571738a93cbd69458725bf276dcc541 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Tue, 1 Feb 2011 23:46:38 +0000
Subject: Add type safety to PositionIterator + attempt at javadoc improvement
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066275 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/fop/layoutmgr/KnuthPossPosIter.java | 5 +--
.../org/apache/fop/layoutmgr/PositionIterator.java | 41 +++++++++++++---------
2 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java b/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
index e69b991b3..c4c4a466c 100644
--- a/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
+++ b/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
@@ -22,7 +22,8 @@ package org.apache.fop.layoutmgr;
import java.util.List;
/**
- * A Knuth element position iterator.
+ * A dedicated {@link PositionIterator} that is backed by an iterator
+ * over a list of {@link KnuthElement}s.
*/
public class KnuthPossPosIter extends PositionIterator {
@@ -60,7 +61,7 @@ public class KnuthPossPosIter extends PositionIterator {
}
/** {@inheritDoc} */
- public Object next() {
+ public Position next() {
--iterCount;
return super.next();
}
diff --git a/src/java/org/apache/fop/layoutmgr/PositionIterator.java b/src/java/org/apache/fop/layoutmgr/PositionIterator.java
index 63ff8461a..f88142613 100644
--- a/src/java/org/apache/fop/layoutmgr/PositionIterator.java
+++ b/src/java/org/apache/fop/layoutmgr/PositionIterator.java
@@ -22,20 +22,30 @@ package org.apache.fop.layoutmgr;
import java.util.Iterator;
import java.util.NoSuchElementException;
-/** A position iterator. */
-public abstract class PositionIterator implements Iterator {
+/**
+ * An iterator over {@link Position} instances, that is wrapped around
+ * another 'parent' {@link Iterator}. The parent can be either another
+ * {@code PositionIterator}, or an iterator over {@link KnuthElement}s,
+ * for example.
+ * The {@link #next()} method always returns a {@link Position}. The
+ * protected {@link #getLM(Object)} and {@link #getPos(Object)} methods
+ * must be overridden in subclasses to take care of obtaining the
+ * {@link LayoutManager} or {@link Position} from the object returned
+ * by the parent iterator's {@code next()} method.
+ */
+public abstract class PositionIterator implements Iterator {
private Iterator parentIter;
private Object nextObj;
private LayoutManager childLM;
- private boolean bHasNext;
+ private boolean hasNext;
/**
* Construct position iterator.
- * @param pIter an iterator to use as parent
+ * @param parentIter an iterator to use as parent
*/
- protected PositionIterator(Iterator pIter) {
- parentIter = pIter;
+ protected PositionIterator(Iterator parentIter) {
+ this.parentIter = parentIter;
lookAhead();
//checkNext();
}
@@ -45,7 +55,7 @@ public abstract class PositionIterator implements Iterator {
// Move to next "segment" of iterator, ie: new childLM
if (childLM == null && nextObj != null) {
childLM = getLM(nextObj);
- bHasNext = true;
+ hasNext = true;
}
return childLM;
}
@@ -64,7 +74,7 @@ public abstract class PositionIterator implements Iterator {
private void lookAhead() {
if (parentIter.hasNext()) {
- bHasNext = true;
+ hasNext = true;
nextObj = parentIter.next();
} else {
endIter();
@@ -78,7 +88,7 @@ public abstract class PositionIterator implements Iterator {
childLM = lm;
} else if (childLM != lm && lm != null) {
// End of this sub-sequence with same child LM
- bHasNext = false;
+ hasNext = false;
childLM = null;
return false;
}
@@ -87,23 +97,23 @@ public abstract class PositionIterator implements Iterator {
/** end (reset) iterator */
protected void endIter() {
- bHasNext = false;
+ hasNext = false;
nextObj = null;
childLM = null;
}
/** {@inheritDoc} */
public boolean hasNext() {
- return (bHasNext && checkNext());
+ return (hasNext && checkNext());
}
/** {@inheritDoc} */
- public Object next() throws NoSuchElementException {
- if (bHasNext) {
- Object retObj = getPos(nextObj);
+ public Position next() throws NoSuchElementException {
+ if (hasNext) {
+ Position retPos = getPos(nextObj);
lookAhead();
- return retObj;
+ return retPos;
} else {
throw new NoSuchElementException("PosIter");
}
@@ -119,4 +129,3 @@ public abstract class PositionIterator implements Iterator {
throw new UnsupportedOperationException("PositionIterator doesn't support remove");
}
}
-
--
cgit v1.2.3
From e1d2e4628bf358cfe74681722013292668517779 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Tue, 1 Feb 2011 23:51:21 +0000
Subject: Commit file necessary to avoid compile error after r1066198
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066277 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/fop/fo/properties/ListProperty.java | 28 +++++++++++++++-------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/src/java/org/apache/fop/fo/properties/ListProperty.java b/src/java/org/apache/fop/fo/properties/ListProperty.java
index 4c5208505..6b1ffcea0 100644
--- a/src/java/org/apache/fop/fo/properties/ListProperty.java
+++ b/src/java/org/apache/fop/fo/properties/ListProperty.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.expr.PropertyException;
/**
* Superclass for properties that are lists of other properties
@@ -30,22 +31,23 @@ import org.apache.fop.fo.PropertyList;
public class ListProperty extends Property {
/**
- * Inner class for creating instances of ListProperty
+ * Inner class for creating instances of {@code ListProperty}
*/
public static class Maker extends PropertyMaker {
/**
+ * Create a maker for the given property id.
* @param propId ID of the property for which Maker should be created
*/
public Maker(int propId) {
super(propId);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public Property convertProperty(Property p,
- PropertyList propertyList, FObj fo) {
+ PropertyList propertyList, FObj fo)
+ throws PropertyException {
if (p instanceof ListProperty) {
return p;
} else {
@@ -56,7 +58,7 @@ public class ListProperty extends Property {
}
/** Vector containing the list of sub-properties */
- protected List list = new java.util.Vector();
+ protected final List list = new java.util.Vector();
/**
* Simple constructor used by subclasses to do some special processing.
@@ -66,7 +68,9 @@ public class ListProperty extends Property {
}
/**
- * @param prop the first Property to be added to the list
+ * Create a new instance, using the given {@link Property} as the first
+ * element in the list.
+ * @param prop the first property to be added to the list
*/
public ListProperty(Property prop) {
this();
@@ -82,15 +86,21 @@ public class ListProperty extends Property {
}
/**
- * @return this.list
+ * Return the {@code java.util.List} of {@link Property} instances
+ * contained in this property.
+ * @return the list of properties contained in this instance
*/
- public List getList() {
+ @Override
+ public List getList() {
return list;
}
/**
+ * Return the {@code java.util.List} of {@link Property} instances,
+ * cast as a {@code java.lang.Object}.
* @return this.list cast as an Object
*/
+ @Override
public Object getObject() {
return list;
}
--
cgit v1.2.3
From d42674784ff6bda51cf4b28b377414b059cbcfd7 Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Wed, 2 Feb 2011 10:19:18 +0000
Subject: Bugzilla #50699: Added support for lookup of alternative glyphs when
additional single-byte encodings are used, ex. replacing "Omegagreek" by
"Omega" and vice versa. Submitted by: Alexandros Papadakis
Changes to patch:
- fixed a couple of typos
- code formatting
- a little code optimization
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066400 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/fonts/SingleByteFont.java | 68 +++++++++++++++++++++--
status.xml | 4 ++
2 files changed, 67 insertions(+), 5 deletions(-)
diff --git a/src/java/org/apache/fop/fonts/SingleByteFont.java b/src/java/org/apache/fop/fonts/SingleByteFont.java
index d798db1bb..b832eec2b 100644
--- a/src/java/org/apache/fop/fonts/SingleByteFont.java
+++ b/src/java/org/apache/fop/fonts/SingleByteFont.java
@@ -29,6 +29,8 @@ import java.util.TreeSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xmlgraphics.fonts.Glyphs;
+
/**
* Generic SingleByte font
*/
@@ -44,6 +46,7 @@ public class SingleByteFont extends CustomFont {
private Map unencodedCharacters;
private List additionalEncodings;
+ private Map alternativeCodes;
/**
@@ -99,19 +102,69 @@ public class SingleByteFont extends CustomFont {
return arr;
}
- /** {@inheritDoc} */
- @Override
- public char mapChar(char c) {
- notifyMapOperation();
+ /**
+ * Lookup a character using its alternative names. If found, cache it so we
+ * can speed up lookups.
+ * @param c the character
+ * @return the suggested alternative character present in the font
+ */
+ private char findAlternative(char c) {
+ char d;
+ if (alternativeCodes == null) {
+ alternativeCodes = new java.util.HashMap();
+ } else {
+ Character alternative = alternativeCodes.get(c);
+ if (alternative != null) {
+ return alternative;
+ }
+ }
+ String charName = Glyphs.charToGlyphName(c);
+ String[] charNameAlternatives = Glyphs.getCharNameAlternativesFor(charName);
+ if (charNameAlternatives != null && charNameAlternatives.length > 0) {
+ for (int i = 0; i < charNameAlternatives.length; i++) {
+ if (log.isDebugEnabled()) {
+ log.debug("Checking alternative for char " + c + " (charname="
+ + charName + "): " + charNameAlternatives[i]);
+ }
+ String s = Glyphs.getUnicodeSequenceForGlyphName(charNameAlternatives[i]);
+ if (s != null) {
+ d = lookupChar(s.charAt(0));
+ if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
+ alternativeCodes.put(c, d);
+ return d;
+ }
+ }
+ }
+ }
+
+ return SingleByteEncoding.NOT_FOUND_CODE_POINT;
+ }
+
+ private char lookupChar(char c) {
char d = mapping.mapChar(c);
if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
return d;
}
- //Check unencoded characters which are available in the font by character name
+ // Check unencoded characters which are available in the font by
+ // character name
d = mapUnencodedChar(c);
+ return d;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public char mapChar(char c) {
+ notifyMapOperation();
+ char d = lookupChar(c);
if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
return d;
+ } else {
+ // Check for alternative
+ d = findAlternative(c);
+ if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
+ return d;
+ }
}
this.warnMissingGlyph(c);
return Typeface.NOT_FOUND;
@@ -162,6 +215,11 @@ public class SingleByteFont extends CustomFont {
if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
return true;
}
+ // Check if an alternative exists
+ d = findAlternative(c);
+ if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
+ return true;
+ }
return false;
}
diff --git a/status.xml b/status.xml
index c0c759763..2ba48dc80 100644
--- a/status.xml
+++ b/status.xml
@@ -59,6 +59,10 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
+
+ Added support for lookup of alternative glyphs when additional single-byte encodings are
+ used, ex. replacing "Omegagreek" by "Omega" and vice versa.
+
Added support for resolution of relative URIs against a specified xml:base during
property refinement.
--
cgit v1.2.3
From 9490404b65fcd1c763280fcad3ab8e1b6ecd2589 Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Wed, 2 Feb 2011 17:28:58 +0000
Subject: Adding information about the font cache file.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066543 13f79535-47bb-0310-9956-ffa450edef68
---
src/documentation/content/xdocs/trunk/fonts.xml | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/documentation/content/xdocs/trunk/fonts.xml b/src/documentation/content/xdocs/trunk/fonts.xml
index dcd03e548..57b9b98f9 100644
--- a/src/documentation/content/xdocs/trunk/fonts.xml
+++ b/src/documentation/content/xdocs/trunk/fonts.xml
@@ -426,6 +426,21 @@
Name: font/myfont.ttf
Content-Type: application/x-font
This feature allows you to create JAR files containing fonts. The JAR files can be added to fop by providem them in the classpath, e.g. copying them into the lib/ directory.
+
+ The font cache
+
+ Apache FOP maintains a cache file that is used to speed up auto-detection. This file
+ is usually found in the ".fop" directory under the user's home directory. It's called
+ "fop-fonts.cache". When the user's home directory is not writable, the font cache file
+ is put in the directory for temporary files.
+
+
+ If there was a problem loading a particular font, it is flagged in the cache file so
+ it is not loaded anymore. So, if a font is actually around but is still not found
+ by Apache FOP, it's worth a try to delete the font cache file which forces Apache FOP
+ to reparse all fonts.
+
+
Embedding
--
cgit v1.2.3
From 99958ef6253a233b4ffeabf5711ba65ac4b71061 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Wed, 2 Feb 2011 20:57:06 +0000
Subject: Generify ListUtil methods
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066626 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/util/ListUtil.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/java/org/apache/fop/util/ListUtil.java b/src/java/org/apache/fop/util/ListUtil.java
index d97457510..8e88e4cbf 100644
--- a/src/java/org/apache/fop/util/ListUtil.java
+++ b/src/java/org/apache/fop/util/ListUtil.java
@@ -34,22 +34,22 @@ public final class ListUtil {
/**
* Retrieve the last element from a list.
*
- * @param list
- * The list to work on
+ * @param the type of objects stored in the list
+ * @param list the list to work on
* @return last element
*/
- public static Object getLast(List list) {
+ public static T getLast(List list) {
return list.get(list.size() - 1);
}
/**
* Retrieve and remove the last element from a list.
*
- * @param list
- * The list to work on
+ * @param the type of objects stored in the list
+ * @param list the list to work on
* @return previous last element
*/
- public static Object removeLast(List list) {
+ public static T removeLast(List list) {
return list.remove(list.size() - 1);
}
}
--
cgit v1.2.3
From 2068719a604acf7eaccadf185c7112bd2e6e2565 Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Fri, 4 Feb 2011 08:14:41 +0000
Subject: Bugzilla #50705: Fix to preserve the order of AFP TLEs and NOPs as
given in the XSL-FO document. Submitted by: Mehdi Houshmand
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067109 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/afp/modca/AbstractPageObject.java | 11 ++++-------
src/java/org/apache/fop/afp/modca/Overlay.java | 1 -
src/java/org/apache/fop/afp/modca/PageGroup.java | 6 ------
src/java/org/apache/fop/afp/modca/PageObject.java | 1 -
status.xml | 3 +++
5 files changed, 7 insertions(+), 15 deletions(-)
diff --git a/src/java/org/apache/fop/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/afp/modca/AbstractPageObject.java
index 1454cf96d..99afd322a 100644
--- a/src/java/org/apache/fop/afp/modca/AbstractPageObject.java
+++ b/src/java/org/apache/fop/afp/modca/AbstractPageObject.java
@@ -57,11 +57,8 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject implemen
/** The current presentation text object */
private PresentationTextObject currentPresentationTextObject = null;
- /** The list of tag logical elements */
- protected List/**/ tagLogicalElements = null;
-
/** The list of objects within this resource container */
- protected List/**/ objects = new java.util.ArrayList();
+ protected List/**/ objects = new java.util.ArrayList();
/** The page width */
private int width;
@@ -217,10 +214,10 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject implemen
* @return the TLEs
*/
protected List getTagLogicalElements() {
- if (tagLogicalElements == null) {
- this.tagLogicalElements = new java.util.ArrayList/**/();
+ if (objects == null) {
+ this.objects = new java.util.ArrayList/**/();
}
- return this.tagLogicalElements;
+ return this.objects;
}
/**
diff --git a/src/java/org/apache/fop/afp/modca/Overlay.java b/src/java/org/apache/fop/afp/modca/Overlay.java
index 0179c94a7..2793e93f5 100644
--- a/src/java/org/apache/fop/afp/modca/Overlay.java
+++ b/src/java/org/apache/fop/afp/modca/Overlay.java
@@ -72,7 +72,6 @@ public class Overlay extends PageObject {
getActiveEnvironmentGroup().writeToStream(os);
- writeObjects(tagLogicalElements, os);
writeObjects(objects, os);
}
diff --git a/src/java/org/apache/fop/afp/modca/PageGroup.java b/src/java/org/apache/fop/afp/modca/PageGroup.java
index 895ec1259..aceb0ff80 100644
--- a/src/java/org/apache/fop/afp/modca/PageGroup.java
+++ b/src/java/org/apache/fop/afp/modca/PageGroup.java
@@ -75,12 +75,6 @@ public class PageGroup extends AbstractResourceEnvironmentGroupContainer {
complete = true;
}
- /** {@inheritDoc} */
- protected void writeContent(OutputStream os) throws IOException {
- writeObjects(tagLogicalElements, os, true);
- super.writeContent(os);
- }
-
/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
byte[] data = new byte[17];
diff --git a/src/java/org/apache/fop/afp/modca/PageObject.java b/src/java/org/apache/fop/afp/modca/PageObject.java
index 6c2547f0b..33bfe0997 100644
--- a/src/java/org/apache/fop/afp/modca/PageObject.java
+++ b/src/java/org/apache/fop/afp/modca/PageObject.java
@@ -185,7 +185,6 @@ public class PageObject extends AbstractResourceGroupContainer {
getActiveEnvironmentGroup().writeToStream(os);
- writeObjects(tagLogicalElements, os);
writeObjects(objects, os);
}
diff --git a/status.xml b/status.xml
index 2ba48dc80..2a7fe4f12 100644
--- a/status.xml
+++ b/status.xml
@@ -59,6 +59,9 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
+
+ Fix to preserve the order of AFP TLEs and NOPs as given in the XSL-FO document.
+
Added support for lookup of alternative glyphs when additional single-byte encodings are
used, ex. replacing "Omegagreek" by "Omega" and vice versa.
--
cgit v1.2.3
From 629e1e66b37ff2e85b1d2907cef4c9b18e3c709c Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Fri, 4 Feb 2011 09:56:33 +0000
Subject: Some tests for bitmap conversions.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067123 13f79535-47bb-0310-9956-ffa450edef68
---
test/java/org/apache/fop/UtilityCodeTestSuite.java | 2 +
.../apache/fop/util/BitmapImageUtilTestCase.java | 167 +++++++++++++++++++++
2 files changed, 169 insertions(+)
create mode 100644 test/java/org/apache/fop/util/BitmapImageUtilTestCase.java
diff --git a/test/java/org/apache/fop/UtilityCodeTestSuite.java b/test/java/org/apache/fop/UtilityCodeTestSuite.java
index fed9f0f71..004b8f3c3 100644
--- a/test/java/org/apache/fop/UtilityCodeTestSuite.java
+++ b/test/java/org/apache/fop/UtilityCodeTestSuite.java
@@ -25,6 +25,7 @@ import junit.framework.TestSuite;
import org.apache.fop.events.BasicEventTestCase;
import org.apache.fop.pdf.PDFObjectTestCase;
import org.apache.fop.traits.BorderPropsTestCase;
+import org.apache.fop.util.BitmapImageUtilTestCase;
import org.apache.fop.util.ColorUtilTestCase;
import org.apache.fop.util.ElementListUtilsTestCase;
import org.apache.fop.util.PDFNumberTestCase;
@@ -51,6 +52,7 @@ public class UtilityCodeTestSuite {
suite.addTest(new TestSuite(BasicEventTestCase.class));
suite.addTest(new TestSuite(XMLResourceBundleTestCase.class));
suite.addTest(new TestSuite(URIResolutionTestCase.class));
+ suite.addTest(new TestSuite(BitmapImageUtilTestCase.class));
//$JUnit-END$
return suite;
}
diff --git a/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java b/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java
new file mode 100644
index 000000000..cf8fdce24
--- /dev/null
+++ b/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.util;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.RenderedImage;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.io.IOUtils;
+
+import org.apache.xmlgraphics.image.writer.ImageWriterUtil;
+import org.apache.xmlgraphics.util.WriterOutputStream;
+import org.apache.xmlgraphics.util.io.ASCIIHexOutputStream;
+
+import org.apache.fop.util.bitmap.BitmapImageUtil;
+import org.apache.fop.util.bitmap.JAIMonochromeBitmapConverter;
+import org.apache.fop.util.bitmap.MonochromeBitmapConverter;
+
+/**
+ * Tests {@link BitmapImageUtil}.
+ */
+public class BitmapImageUtilTestCase extends TestCase {
+
+ private static final boolean DEBUG = true;
+ private static final boolean TEST_PIXELS = true;
+
+ /**
+ * Tests the convertTo* methods.
+ * @throws Exception if an error occurs
+ */
+ public void testConvertToMono() throws Exception {
+ BufferedImage testImage = createTestImage();
+ saveAsPNG(testImage, "test-image");
+
+ RenderedImage img;
+ Dimension scaled = new Dimension(320, 240);
+
+ img = BitmapImageUtil.convertToGrayscale(testImage, null);
+ saveAsPNG(img, "out-gray");
+ assertEquals(1, img.getColorModel().getNumComponents());
+ assertEquals(8, img.getColorModel().getPixelSize());
+ assertEquals(640, img.getWidth());
+ assertEquals(480, img.getHeight());
+ assertPixels("5757575757575757575757FFFFFFFFFF", img, 220, 34, 16);
+
+ img = BitmapImageUtil.convertToGrayscale(testImage, scaled);
+ saveAsPNG(img, "out-gray-scaled");
+ assertEquals(1, img.getColorModel().getNumComponents());
+ assertEquals(8, img.getColorModel().getPixelSize());
+ assertEquals(320, img.getWidth());
+ assertEquals(240, img.getHeight());
+
+ img = BitmapImageUtil.convertToMonochrome(testImage, null);
+ saveAsPNG(img, "out-mono");
+ assertEquals(1, img.getColorModel().getPixelSize());
+ assertEquals(640, img.getWidth());
+ assertEquals(480, img.getHeight());
+ assertPixels("00000000000000000000000101010101", img, 220, 34, 16);
+
+ if (isJAIAvailable()) {
+ img = BitmapImageUtil.convertToMonochrome(testImage, null, 0.5f);
+ saveAsPNG(img, "out-mono-jai-0.5");
+ assertEquals(1, img.getColorModel().getPixelSize());
+ assertEquals(640, img.getWidth());
+ assertEquals(480, img.getHeight());
+ assertPixels("00010000000100000001000101010101", img, 220, 34, 16);
+
+ img = BitmapImageUtil.convertToMonochrome(testImage, null, 1.0f);
+ saveAsPNG(img, "out-mono-jai-1.0");
+ assertEquals(1, img.getColorModel().getPixelSize());
+ assertEquals(640, img.getWidth());
+ assertEquals(480, img.getHeight());
+ assertPixels("01000001000001000001000101010101", img, 220, 34, 16);
+ }
+ }
+
+ private void assertPixels(String expected, RenderedImage img, int x, int y, int w)
+ throws IOException {
+ if (TEST_PIXELS) {
+ byte[] byteArray = (byte[])img.getData().getDataElements(x, y, w, 1, new byte[w]);
+ assertEquals(expected, toHex(byteArray));
+ }
+ }
+
+ private boolean isJAIAvailable() {
+ MonochromeBitmapConverter converter
+ = BitmapImageUtil.createDefaultMonochromeBitmapConverter();
+ return (converter instanceof JAIMonochromeBitmapConverter);
+ }
+
+ private void saveAsPNG(RenderedImage img, String name) throws IOException {
+ if (DEBUG) {
+ File baseDir = new File("./build/test-results/bitmap-conversion");
+ baseDir.mkdirs();
+ ImageWriterUtil.saveAsPNG(img, new File(baseDir, name + ".png"));
+ }
+ }
+
+ private String toHex(byte[] byteArray) throws IOException {
+ InputStream in = new java.io.ByteArrayInputStream(byteArray);
+ StringWriter writer = new StringWriter();
+ WriterOutputStream wo = new WriterOutputStream(writer, "US-ASCII");
+ ASCIIHexOutputStream hex = new ASCIIHexOutputStream(wo);
+ IOUtils.copyLarge(in, hex);
+ return writer.toString();
+ }
+
+ private BufferedImage createTestImage() {
+ BufferedImage buf = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);
+ Graphics2D g2d = buf.createGraphics();
+ g2d.setBackground(Color.WHITE);
+ g2d.clearRect(0, 0, buf.getWidth(), buf.getHeight());
+
+ //A few rectangles rotated and with different color
+ Graphics2D copy = (Graphics2D)g2d.create();
+ copy.translate(170, 170);
+ int c = 12;
+ for (int i = 0; i < c; i++) {
+ float f = ((i + 1) / (float)c);
+ Color col = new Color(0.0f, 1 - f, 0.0f);
+ copy.setColor(col);
+ copy.fillRect(0, 0, 120, 120);
+ copy.rotate(-2 * Math.PI / c);
+ }
+ copy.dispose();
+
+ //the same in gray scales
+ copy = (Graphics2D)g2d.create();
+ copy.translate(470, 310);
+ c = 12;
+ for (int i = 0; i < c; i++) {
+ float f = ((i + 1) / (float)c);
+ Color col = new Color(f, f, f);
+ copy.setColor(col);
+ copy.fillRect(0, 0, 120, 120);
+ copy.rotate(-2 * Math.PI / c);
+ }
+ copy.dispose();
+ return buf;
+ }
+
+}
--
cgit v1.2.3
From 9adfae3eb6782ce8b240045f4a0f2702b09c30b6 Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Fri, 4 Feb 2011 10:02:01 +0000
Subject: Fix compile error when JAI is not around.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067126 13f79535-47bb-0310-9956-ffa450edef68
---
test/java/org/apache/fop/util/BitmapImageUtilTestCase.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java b/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java
index cf8fdce24..92a3a15bd 100644
--- a/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java
+++ b/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java
@@ -38,7 +38,6 @@ import org.apache.xmlgraphics.util.WriterOutputStream;
import org.apache.xmlgraphics.util.io.ASCIIHexOutputStream;
import org.apache.fop.util.bitmap.BitmapImageUtil;
-import org.apache.fop.util.bitmap.JAIMonochromeBitmapConverter;
import org.apache.fop.util.bitmap.MonochromeBitmapConverter;
/**
@@ -110,7 +109,7 @@ public class BitmapImageUtilTestCase extends TestCase {
private boolean isJAIAvailable() {
MonochromeBitmapConverter converter
= BitmapImageUtil.createDefaultMonochromeBitmapConverter();
- return (converter instanceof JAIMonochromeBitmapConverter);
+ return converter.getClass().getName().contains("JAI");
}
private void saveAsPNG(RenderedImage img, String name) throws IOException {
--
cgit v1.2.3
From 8312fbff3f5f45d205449be19af94203014e658c Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Fri, 4 Feb 2011 15:11:29 +0000
Subject: Bugfix: Suppress generating duplicate fo:root and fo:declarations
extension attachments.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067190 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/area/AreaTreeHandler.java | 24 +++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java
index 2729a5a0a..dd9db89a3 100644
--- a/src/java/org/apache/fop/area/AreaTreeHandler.java
+++ b/src/java/org/apache/fop/area/AreaTreeHandler.java
@@ -201,14 +201,19 @@ public class AreaTreeHandler extends FOEventHandler {
private void startAbstractPageSequence(AbstractPageSequence pageSequence) {
rootFObj = pageSequence.getRoot();
+
+ //Before the first page-sequence...
+ if (this.prevPageSeqLM == null) {
+ // extension attachments from fo:root
+ wrapAndAddExtensionAttachments(rootFObj.getExtensionAttachments());
+ // extension attachments from fo:declarations
+ if (rootFObj.getDeclarations() != null) {
+ wrapAndAddExtensionAttachments(rootFObj.getDeclarations().getExtensionAttachments());
+ }
+ }
+
finishPrevPageSequence(pageSequence.getInitialPageNumber());
pageSequence.initPageNumber();
- // extension attachments from fo:root
- wrapAndAddExtensionAttachments(rootFObj.getExtensionAttachments());
- // extension attachments from fo:declarations
- if (rootFObj.getDeclarations() != null) {
- wrapAndAddExtensionAttachments(rootFObj.getDeclarations().getExtensionAttachments());
- }
}
private void wrapAndAddExtensionAttachments(List list) {
@@ -367,6 +372,7 @@ public class AreaTreeHandler extends FOEventHandler {
* @param pv a page viewport that contains the area with this ID
* @deprecated use getIDTracker().associateIDWithPageViewport(id, pv) instead
*/
+ @Deprecated
public void associateIDWithPageViewport(String id, PageViewport pv) {
idTracker.associateIDWithPageViewport(id, pv);
}
@@ -379,6 +385,7 @@ public class AreaTreeHandler extends FOEventHandler {
* @param id the id of the object being processed
* @deprecated use getIDTracker().signalPendingID(id) instead
*/
+ @Deprecated
public void signalPendingID(String id) {
idTracker.signalPendingID(id);
}
@@ -391,6 +398,7 @@ public class AreaTreeHandler extends FOEventHandler {
* @param id the id of the formatting object which was just finished
* @deprecated use getIDTracker().signalIDProcessed(id) instead
*/
+ @Deprecated
public void signalIDProcessed(String id) {
idTracker.signalIDProcessed(id);
}
@@ -402,6 +410,7 @@ public class AreaTreeHandler extends FOEventHandler {
* @return true if the ID has been resolved
* @deprecated use getIDTracker().alreadyResolvedID(id) instead
*/
+ @Deprecated
public boolean alreadyResolvedID(String id) {
return idTracker.alreadyResolvedID(id);
}
@@ -412,6 +421,7 @@ public class AreaTreeHandler extends FOEventHandler {
* @param pv page viewport whose ID refs to resolve
* @deprecated use getIDTracker().tryIDResolution(pv) instead
*/
+ @Deprecated
public void tryIDResolution(PageViewport pv) {
idTracker.tryIDResolution(pv);
}
@@ -423,6 +433,7 @@ public class AreaTreeHandler extends FOEventHandler {
* @return the list of PageViewports
* @deprecated use getIDTracker().getPageViewportsContainingID(id) instead
*/
+ @Deprecated
public List getPageViewportsContainingID(String id) {
return idTracker.getPageViewportsContainingID(id);
}
@@ -434,6 +445,7 @@ public class AreaTreeHandler extends FOEventHandler {
* @param res the Resolvable object needing the idref to be resolved
* @deprecated use getIDTracker().addUnresolvedIDRef(idref, res) instead
*/
+ @Deprecated
public void addUnresolvedIDRef(String idref, Resolvable res) {
idTracker.addUnresolvedIDRef(idref, res);
}
--
cgit v1.2.3
From 0d5b2a69b9ef87ebd2c383172214673667f2a23c Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Fri, 4 Feb 2011 15:13:07 +0000
Subject: Disable pixel tests due to differences between JVMs.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067193 13f79535-47bb-0310-9956-ffa450edef68
---
test/java/org/apache/fop/util/BitmapImageUtilTestCase.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java b/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java
index 92a3a15bd..55a9fe4e4 100644
--- a/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java
+++ b/test/java/org/apache/fop/util/BitmapImageUtilTestCase.java
@@ -46,7 +46,7 @@ import org.apache.fop.util.bitmap.MonochromeBitmapConverter;
public class BitmapImageUtilTestCase extends TestCase {
private static final boolean DEBUG = true;
- private static final boolean TEST_PIXELS = true;
+ private static final boolean TEST_PIXELS = false;
/**
* Tests the convertTo* methods.
--
cgit v1.2.3
From 186dd12cec2194d3187146919c09246cf410844e Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sat, 5 Feb 2011 00:13:18 +0000
Subject: Refactoring PositionIterator Step 1: make the class instantiable,
provide default implementations for getLM() and getPos(), and make the
constructor public
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067353 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/fop/layoutmgr/KnuthPossPosIter.java | 4 +++
.../org/apache/fop/layoutmgr/PositionIterator.java | 29 +++++++++++++++-------
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java b/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
index c4c4a466c..71790ec82 100644
--- a/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
+++ b/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
@@ -51,6 +51,7 @@ public class KnuthPossPosIter extends PositionIterator {
// Check position < endPos
/** {@inheritDoc} */
+ @Override
protected boolean checkNext() {
if (iterCount > 0) {
return super.checkNext();
@@ -61,6 +62,7 @@ public class KnuthPossPosIter extends PositionIterator {
}
/** {@inheritDoc} */
+ @Override
public Position next() {
--iterCount;
return super.next();
@@ -75,11 +77,13 @@ public class KnuthPossPosIter extends PositionIterator {
}
/** {@inheritDoc} */
+ @Override
protected LayoutManager getLM(Object nextObj) {
return ((ListElement) nextObj).getLayoutManager();
}
/** {@inheritDoc} */
+ @Override
protected Position getPos(Object nextObj) {
return ((ListElement) nextObj).getPosition();
}
diff --git a/src/java/org/apache/fop/layoutmgr/PositionIterator.java b/src/java/org/apache/fop/layoutmgr/PositionIterator.java
index f88142613..b2bf404ff 100644
--- a/src/java/org/apache/fop/layoutmgr/PositionIterator.java
+++ b/src/java/org/apache/fop/layoutmgr/PositionIterator.java
@@ -28,12 +28,11 @@ import java.util.NoSuchElementException;
* {@code PositionIterator}, or an iterator over {@link KnuthElement}s,
* for example.
* The {@link #next()} method always returns a {@link Position}. The
- * protected {@link #getLM(Object)} and {@link #getPos(Object)} methods
- * must be overridden in subclasses to take care of obtaining the
- * {@link LayoutManager} or {@link Position} from the object returned
- * by the parent iterator's {@code next()} method.
+ * {@link #getPos(Object)} method can be overridden in subclasses
+ * to take care of obtaining the {@link LayoutManager} or {@link Position}
+ * from the object returned by the parent iterator's {@code next()} method.
*/
-public abstract class PositionIterator implements Iterator {
+public class PositionIterator implements Iterator {
private Iterator parentIter;
private Object nextObj;
@@ -44,7 +43,7 @@ public abstract class PositionIterator implements Iterator {
* Construct position iterator.
* @param parentIter an iterator to use as parent
*/
- protected PositionIterator(Iterator parentIter) {
+ public PositionIterator(Iterator parentIter) {
this.parentIter = parentIter;
lookAhead();
//checkNext();
@@ -64,13 +63,25 @@ public abstract class PositionIterator implements Iterator {
* @param nextObj next object from which to obtain position
* @return layout manager
*/
- protected abstract LayoutManager getLM(Object nextObj);
+ protected LayoutManager getLM(Object nextObj) {
+ return getPos(nextObj).getLM();
+ }
/**
+ * Default implementation assumes that the passed
+ * {@code nextObj} is itself a {@link Position}, and just returns it.
+ * Subclasses for which this is not the case, must provide a
+ * suitable override this method.
* @param nextObj next object from which to obtain position
- * @return position of next object
+ * @return position of next object.
*/
- protected abstract Position getPos(Object nextObj);
+ protected Position getPos(Object nextObj) {
+ if (nextObj instanceof Position) {
+ return (Position)nextObj;
+ }
+ throw new IllegalArgumentException(
+ "Cannot obtain Position from the given object.");
+ }
private void lookAhead() {
if (parentIter.hasNext()) {
--
cgit v1.2.3
From 8addb610e119ae5192f697dc19ddcc55612a83e6 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sat, 5 Feb 2011 00:40:35 +0000
Subject: Decommission AreaAdditionUtil.StackingIter + minor fixups
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067360 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/fop/layoutmgr/AreaAdditionUtil.java | 32 ++++++++--------------
1 file changed, 11 insertions(+), 21 deletions(-)
diff --git a/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java b/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java
index 755be91d1..1bacbd29b 100644
--- a/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java
+++ b/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java
@@ -19,7 +19,6 @@
package org.apache.fop.layoutmgr;
-import java.util.Iterator;
import java.util.LinkedList;
import org.apache.fop.layoutmgr.SpaceResolver.SpaceHandlingBreakPosition;
@@ -32,20 +31,6 @@ public final class AreaAdditionUtil {
private AreaAdditionUtil() {
}
- private static class StackingIter extends PositionIterator {
- StackingIter(Iterator parentIter) {
- super(parentIter);
- }
-
- protected LayoutManager getLM(Object nextObj) {
- return ((Position) nextObj).getLM();
- }
-
- protected Position getPos(Object nextObj) {
- return ((Position) nextObj);
- }
- }
-
/**
* Creates the child areas for the given layout manager.
* @param bslm the BlockStackingLayoutManager instance for which "addAreas" is performed.
@@ -54,19 +39,23 @@ public final class AreaAdditionUtil {
*/
public static void addAreas(BlockStackingLayoutManager bslm,
PositionIterator parentIter, LayoutContext layoutContext) {
- LayoutManager childLM = null;
+ LayoutManager childLM;
LayoutContext lc = new LayoutContext(0);
LayoutManager firstLM = null;
LayoutManager lastLM = null;
Position firstPos = null;
Position lastPos = null;
+ if (bslm != null) {
+ bslm.addId();
+ }
+
// "unwrap" the NonLeafPositions stored in parentIter
// and put them in a new list;
- LinkedList positionList = new LinkedList();
+ LinkedList positionList = new LinkedList();
Position pos;
while (parentIter.hasNext()) {
- pos = (Position)parentIter.next();
+ pos = parentIter.next();
if (pos == null) {
continue;
}
@@ -78,8 +67,8 @@ public final class AreaAdditionUtil {
}
if (pos instanceof NonLeafPosition) {
// pos was created by a child of this FlowLM
- positionList.add(((NonLeafPosition) pos).getPosition());
- lastLM = ((NonLeafPosition) pos).getPosition().getLM();
+ positionList.add(pos.getPosition());
+ lastLM = (pos.getPosition().getLM());
if (firstLM == null) {
firstLM = lastLM;
}
@@ -104,7 +93,7 @@ public final class AreaAdditionUtil {
bslm.isLast(lastPos));
}
- StackingIter childPosIter = new StackingIter(positionList.listIterator());
+ PositionIterator childPosIter = new PositionIterator(positionList.listIterator());
while ((childLM = childPosIter.getNextChildLM()) != null) {
// TODO vh: the test above might be problematic in some cases. See comment in
@@ -129,6 +118,7 @@ public final class AreaAdditionUtil {
false,
bslm.isFirst(firstPos),
bslm.isLast(lastPos));
+ bslm.checkEndOfLayout(lastPos);
}
--
cgit v1.2.3
From 9e56df1048a109dcd04d77779335aa7d7431dd01 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sat, 5 Feb 2011 00:59:17 +0000
Subject: Decommission private PositionIterator subclasses in list package (+
minor fixups)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067365 13f79535-47bb-0310-9956-ffa450edef68
---
.../fop/layoutmgr/list/ListBlockLayoutManager.java | 25 +++++++---------------
.../list/ListItemContentLayoutManager.java | 25 ++++++----------------
2 files changed, 15 insertions(+), 35 deletions(-)
diff --git a/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java
index 8ab79d2c4..9ffe015d3 100644
--- a/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java
@@ -65,20 +65,6 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager
private MinOptMax effSpaceBefore;
private MinOptMax effSpaceAfter;
- private static class StackingIter extends PositionIterator {
- StackingIter(Iterator parentIter) {
- super(parentIter);
- }
-
- protected LayoutManager getLM(Object nextObj) {
- return ((Position) nextObj).getLM();
- }
-
- protected Position getPos(Object nextObj) {
- return ((Position) nextObj);
- }
- }
-
/**
* Create a new list block layout manager.
* @param node list-block to create the layout manager for
@@ -96,6 +82,7 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager
}
/** {@inheritDoc} */
+ @Override
public void initialize() {
foSpaceBefore = new SpaceVal(
getListBlockFO().getCommonMarginBlock().spaceBefore, this).getSpace();
@@ -115,6 +102,7 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager
}
/** {@inheritDoc} */
+ @Override
public List getNextKnuthElements(LayoutContext context, int alignment) {
resetSpaces();
List returnList = super.getNextKnuthElements(context, alignment);
@@ -135,6 +123,7 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager
}
/** {@inheritDoc} */
+ @Override
public List getChangedKnuthElements(List oldList, int alignment) {
//log.debug("LBLM.getChangedKnuthElements>");
return super.getChangedKnuthElements(oldList, alignment);
@@ -147,6 +136,7 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager
* @param parentIter the position iterator
* @param layoutContext the layout context for adding areas
*/
+ @Override
public void addAreas(PositionIterator parentIter,
LayoutContext layoutContext) {
getParentArea(null);
@@ -170,10 +160,10 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager
// "unwrap" the NonLeafPositions stored in parentIter
// and put them in a new list;
- LinkedList positionList = new LinkedList();
+ LinkedList positionList = new LinkedList();
Position pos;
while (parentIter.hasNext()) {
- pos = (Position)parentIter.next();
+ pos = parentIter.next();
if (pos.getIndex() >= 0) {
if (firstPos == null) {
firstPos = pos;
@@ -194,7 +184,7 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager
addMarkersToPage(true, isFirst(firstPos), isLast(lastPos));
- StackingIter childPosIter = new StackingIter(positionList.listIterator());
+ PositionIterator childPosIter = new PositionIterator(positionList.listIterator());
while ((childLM = childPosIter.getNextChildLM()) != null) {
// Add the block areas to Area
// set the space adjustment ratio
@@ -235,6 +225,7 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager
* @param childArea the child area
* @return the parent area of the child
*/
+ @Override
public Area getParentArea(Area childArea) {
if (curBlockArea == null) {
curBlockArea = new Block();
diff --git a/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java
index 246c57094..f2e3b7d95 100644
--- a/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java
@@ -19,7 +19,6 @@
package org.apache.fop.layoutmgr.list;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -49,20 +48,6 @@ public class ListItemContentLayoutManager extends BlockStackingLayoutManager {
private int xoffset;
private int itemIPD;
- private static class StackingIter extends PositionIterator {
- StackingIter(Iterator parentIter) {
- super(parentIter);
- }
-
- protected LayoutManager getLM(Object nextObj) {
- return ((Position) nextObj).getLM();
- }
-
- protected Position getPos(Object nextObj) {
- return ((Position) nextObj);
- }
- }
-
/**
* Create a new Cell layout manager.
* @param node list-item-label node
@@ -99,6 +84,7 @@ public class ListItemContentLayoutManager extends BlockStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
public List getChangedKnuthElements(List oldList, int alignment) {
//log.debug(" ListItemContentLayoutManager.getChanged>");
return super.getChangedKnuthElements(oldList, alignment);
@@ -112,6 +98,7 @@ public class ListItemContentLayoutManager extends BlockStackingLayoutManager {
* @param parentIter the iterator of the break positions
* @param layoutContext the layout context for adding the areas
*/
+ @Override
public void addAreas(PositionIterator parentIter,
LayoutContext layoutContext) {
getParentArea(null);
@@ -127,10 +114,10 @@ public class ListItemContentLayoutManager extends BlockStackingLayoutManager {
// "unwrap" the NonLeafPositions stored in parentIter
// and put them in a new list;
- LinkedList positionList = new LinkedList();
+ LinkedList positionList = new LinkedList();
Position pos;
while (parentIter.hasNext()) {
- pos = (Position)parentIter.next();
+ pos = parentIter.next();
if (pos == null) {
continue;
}
@@ -156,7 +143,7 @@ public class ListItemContentLayoutManager extends BlockStackingLayoutManager {
addMarkersToPage(true, isFirst(firstPos), isLast(lastPos));
- StackingIter childPosIter = new StackingIter(positionList.listIterator());
+ PositionIterator childPosIter = new PositionIterator(positionList.listIterator());
while ((childLM = childPosIter.getNextChildLM()) != null) {
// Add the block areas to Area
lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM);
@@ -189,6 +176,7 @@ public class ListItemContentLayoutManager extends BlockStackingLayoutManager {
* @param childArea the child area to get the parent for
* @return the parent area
*/
+ @Override
public Area getParentArea(Area childArea) {
if (curBlockArea == null) {
curBlockArea = new Block();
@@ -215,6 +203,7 @@ public class ListItemContentLayoutManager extends BlockStackingLayoutManager {
*
* @param childArea the child to add to the cell
*/
+ @Override
public void addChildArea(Area childArea) {
if (curBlockArea != null) {
curBlockArea.addBlock((Block) childArea);
--
cgit v1.2.3
From 58d1c60f1071ff57459baecf060925d5f2dba0b6 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sat, 5 Feb 2011 01:25:37 +0000
Subject: Decommission InlineStackingLM.StackingIter (+ minor fixups)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067371 13f79535-47bb-0310-9956-ffa450edef68
---
.../layoutmgr/inline/FootnoteLayoutManager.java | 21 +++++----
.../fop/layoutmgr/inline/InlineLayoutManager.java | 53 +++++++++++-----------
.../inline/InlineStackingLayoutManager.java | 31 +------------
.../fop/layoutmgr/inline/LineLayoutManager.java | 2 +-
4 files changed, 40 insertions(+), 67 deletions(-)
diff --git a/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java
index efa6f880a..d5d62dd4b 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java
@@ -34,6 +34,7 @@ import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.LayoutManager;
import org.apache.fop.layoutmgr.ListElement;
import org.apache.fop.layoutmgr.NonLeafPosition;
+import org.apache.fop.layoutmgr.Position;
import org.apache.fop.layoutmgr.PositionIterator;
/**
@@ -62,6 +63,7 @@ public class FootnoteLayoutManager extends InlineStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
public void initialize() {
// create an InlineStackingLM handling the fo:inline child of fo:footnote
citationLM = new InlineLayoutManager(footnote.getFootnoteCitation());
@@ -71,6 +73,7 @@ public class FootnoteLayoutManager extends InlineStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
public List getNextKnuthElements(LayoutContext context,
int alignment) {
// for the moment, this LM is set as the citationLM's parent
@@ -119,9 +122,8 @@ public class FootnoteLayoutManager extends InlineStackingLayoutManager {
return returnedList;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public List getChangedKnuthElements(List oldList, int alignment, int depth) {
List returnedList = super.getChangedKnuthElements(oldList, alignment, depth);
addAnchor(returnedList);
@@ -129,16 +131,15 @@ public class FootnoteLayoutManager extends InlineStackingLayoutManager {
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public void addAreas(PositionIterator posIter, LayoutContext context) {
// "Unwrap" the NonLeafPositions stored in posIter and put
// them in a new list, that will be given to the citationLM
- LinkedList positionList = new LinkedList();
- NonLeafPosition pos = null;
+ LinkedList positionList = new LinkedList();
+ Position pos;
while (posIter.hasNext()) {
- pos = (NonLeafPosition) posIter.next();
+ pos = posIter.next();
if (pos != null && pos.getPosition() != null) {
positionList.add(pos.getPosition());
}
@@ -150,7 +151,7 @@ public class FootnoteLayoutManager extends InlineStackingLayoutManager {
// make the citationLM add its areas
LayoutContext childContext = new LayoutContext(context);
- StackingIter childPosIter = new StackingIter(positionList.listIterator());
+ PositionIterator childPosIter = new PositionIterator(positionList.listIterator());
LayoutManager childLM;
while ((childLM = childPosIter.getNextChildLM()) != null) {
childLM.addAreas(childPosIter, childContext);
diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java
index 1d3233112..c28cfc608 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java
@@ -77,8 +77,6 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
private boolean areaCreated = false;
private LayoutManager lastChildLM = null; // Set when return last breakposs;
- private Position auxiliaryPosition;
-
private Font font;
/** The alignment adjust property */
@@ -113,6 +111,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
public void initialize() {
InlineLevel fobj = (InlineLevel) this.fobj;
@@ -150,6 +149,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
protected MinOptMax getExtraIPD(boolean isNotFirst, boolean isNotLast) {
int borderAndPadding = 0;
if (borderProps != null) {
@@ -167,6 +167,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
/** {@inheritDoc} */
+ @Override
protected boolean hasLeadingFence(boolean isNotFirst) {
return borderProps != null
&& (borderProps.getPadding(CommonBorderPaddingBackground.START, isNotFirst, this) > 0
@@ -175,6 +176,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
protected boolean hasTrailingFence(boolean isNotLast) {
return borderProps != null
&& (borderProps.getPadding(CommonBorderPaddingBackground.END, isNotLast, this) > 0
@@ -183,10 +185,12 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
protected SpaceProperty getSpaceStart() {
return inlineProps != null ? inlineProps.spaceStart : null;
}
/** {@inheritDoc} */
+ @Override
protected SpaceProperty getSpaceEnd() {
return inlineProps != null ? inlineProps.spaceEnd : null;
}
@@ -212,6 +216,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
protected void setTraits(boolean isNotFirst, boolean isNotLast) {
if (borderProps != null) {
// Add border and padding to current area and set flags (FIRST, LAST ...)
@@ -239,15 +244,16 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
public List getNextKnuthElements // CSOK: MethodLength
(LayoutContext context, int alignment) {
LayoutManager curLM;
// the list returned by child LM
- List returnedList;
+ List returnedList;
// the list which will be returned to the parent LM
- List returnList = new LinkedList();
+ List returnList = new LinkedList();
KnuthSequence lastSequence = null;
if (fobj instanceof Title) {
@@ -328,16 +334,16 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
sequence.wrapPositions(this);
}
int insertionStartIndex = 0;
- if (lastSequence != null && lastSequence.appendSequenceOrClose
- ((KnuthSequence) returnedList.get(0))) {
+ if (lastSequence != null
+ && lastSequence.appendSequenceOrClose(returnedList.get(0))) {
insertionStartIndex = 1;
}
// add border and padding to the first complete sequence of this LM
if (!borderAdded && !returnedList.isEmpty()) {
- addKnuthElementsForBorderPaddingStart((KnuthSequence) returnedList.get(0));
+ addKnuthElementsForBorderPaddingStart(returnedList.get(0));
borderAdded = true;
}
- for (Iterator iter = returnedList.listIterator(insertionStartIndex);
+ for (Iterator iter = returnedList.listIterator(insertionStartIndex);
iter.hasNext();) {
returnList.add(iter.next());
}
@@ -368,7 +374,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
childLC.clearKeepsPending();
}
- lastSequence = (KnuthSequence) ListUtil.getLast(returnList);
+ lastSequence = ListUtil.getLast(returnList);
lastChildLM = curLM;
}
@@ -408,6 +414,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
* by this LayoutManager.
* @param context layout context.
*/
+ @Override
public void addAreas(PositionIterator parentIter,
LayoutContext context) {
@@ -433,21 +440,18 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
// set in the layout context, it must be also set in the
// layout context given to lastLM, but must be cleared in the
// layout context given to the other LMs.
- List positionList = new LinkedList();
- NonLeafPosition pos;
+ List positionList = new LinkedList();
+ Position pos;
LayoutManager lastLM = null; // last child LM in this iterator
Position lastPos = null;
while (parentIter.hasNext()) {
- pos = (NonLeafPosition) parentIter.next();
+ pos = parentIter.next();
if (pos != null && pos.getPosition() != null) {
positionList.add(pos.getPosition());
lastLM = pos.getPosition().getLM();
lastPos = pos;
}
}
- /*if (pos != null) {
- lastLM = pos.getPosition().getLM();
- }*/
addMarkersToPage(
true,
@@ -469,8 +473,8 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
setCurrentArea(parent);
- StackingIter childPosIter
- = new StackingIter(positionList.listIterator());
+ PositionIterator childPosIter
+ = new PositionIterator(positionList.listIterator());
LayoutManager prevLM = null;
LayoutManager childLM;
@@ -522,6 +526,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
public void addChildArea(Area childArea) {
Area parent = getCurrentArea();
if (getContext().resolveLeadingSpace()) {
@@ -532,6 +537,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
public List getChangedKnuthElements(List oldList, int alignment, int depth) {
List returnedList = new LinkedList();
addKnuthElementsForBorderPaddingStart(returnedList);
@@ -546,7 +552,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
*/
protected void addKnuthElementsForBorderPaddingStart(List returnList) {
//Border and Padding (start)
- /**
+ /*
* If the returnlist is a BlockKnuthSequence, the border and padding should be added
* to the first paragraph inside it, but it is too late to do that now.
* At least, avoid adding it to the bpd sequence.
@@ -571,7 +577,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
*/
protected void addKnuthElementsForBorderPaddingEnd(List returnList) {
//Border and Padding (after)
- /**
+ /*
* If the returnlist is a BlockKnuthSequence, the border and padding should be added
* to the last paragraph inside it, but it is too late to do that now.
* At least, avoid adding it to the bpd sequence.
@@ -590,13 +596,8 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
}
- /** @return a cached auxiliary Position instance used for things like spaces. */
+ /** @return an auxiliary {@link Position} instance used for things like spaces. */
protected Position getAuxiliaryPosition() {
- //if (this.auxiliaryPosition == null) {
- //this.auxiliaryPosition = new NonLeafPosition(this, new LeafPosition(this, -1));
- this.auxiliaryPosition = new NonLeafPosition(this, null);
- //}
- return this.auxiliaryPosition;
+ return new NonLeafPosition(this, null);
}
-
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java
index d8c4966d0..b15f0f8db 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java
@@ -19,7 +19,6 @@
package org.apache.fop.layoutmgr.inline;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
@@ -31,10 +30,8 @@ import org.apache.fop.fo.properties.SpaceProperty;
import org.apache.fop.layoutmgr.AbstractLayoutManager;
import org.apache.fop.layoutmgr.KnuthElement;
import org.apache.fop.layoutmgr.LayoutContext;
-import org.apache.fop.layoutmgr.LayoutManager;
import org.apache.fop.layoutmgr.NonLeafPosition;
import org.apache.fop.layoutmgr.Position;
-import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.traits.MinOptMax;
/**
@@ -45,33 +42,6 @@ import org.apache.fop.traits.MinOptMax;
public abstract class InlineStackingLayoutManager extends AbstractLayoutManager
implements InlineLevelLayoutManager {
-
- /**
- * A stacking iterator.
- */
- protected static class StackingIter extends PositionIterator {
-
- StackingIter(Iterator parentIter) {
- super(parentIter);
- }
-
- /**
- * @param nextObj the next object
- * @return layout manager of next object
- */
- protected LayoutManager getLM(Object nextObj) {
- return ((Position) nextObj).getLM();
- }
-
- /**
- * @param nextObj the next object
- * @return position of next object
- */
- protected Position getPos(Object nextObj) {
- return ((Position) nextObj);
- }
- }
-
/**
* Size of border and padding in BPD (ie, before and after).
*/
@@ -296,6 +266,7 @@ public abstract class InlineStackingLayoutManager extends AbstractLayoutManager
} else {
currLM = (InlineLevelLayoutManager) pos.getLM(depth);
}
+
// initialize prevLM
if (prevLM == null) {
prevLM = currLM;
diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
index 2611a8cd5..5437c90af 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
@@ -1562,7 +1562,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
lc.setAlignmentContext(alignmentContext);
setChildContext(lc);
- PositionIterator childPosIter = new StackingIter(positionList.listIterator());
+ PositionIterator childPosIter = new PositionIterator(positionList.listIterator());
LayoutContext blocklc = new LayoutContext(0);
blocklc.setLeadingSpace(new SpaceSpecifier(true));
blocklc.setTrailingSpace(new SpaceSpecifier(false));
--
cgit v1.2.3
From 4941b30967c894d294f5a0f3aa84c659e165d969 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sat, 5 Feb 2011 21:49:58 +0000
Subject: Code cleanup
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067533 13f79535-47bb-0310-9956-ffa450edef68
---
.../fop/layoutmgr/BlockStackingLayoutManager.java | 695 ++++-----------------
1 file changed, 109 insertions(+), 586 deletions(-)
diff --git a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
index fd9f2a822..4f0ab9ddb 100644
--- a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
@@ -50,9 +50,7 @@ import org.apache.fop.util.ListUtil;
public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
implements BlockLevelLayoutManager {
- /**
- * logging instance
- */
+ /** logging instance */
private static Log log = LogFactory.getLog(BlockStackingLayoutManager.class);
/** parent area */
@@ -65,7 +63,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
/** space-after value adjusted for block-progression-unit handling */
protected int adjustedSpaceAfter;
/** Only used to store the original list when createUnitElements is called */
- protected List storedList;
+ protected List storedList;
/** Indicates whether break before has been served or not */
protected boolean breakBeforeServed;
/** Indicates whether the first visible mark has been returned by this LM, yet */
@@ -162,17 +160,11 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
* If so, add it. Otherwise initiate breaking.
* @param childArea the area to add: will be some block-stacked Area.
*/
+ @Override
public void addChildArea(Area childArea) {
addChildToArea(childArea, getCurrentArea());
}
- /** {@inheritDoc} */
- protected void notifyEndOfLayout() {
- super.notifyEndOfLayout();
- // Free memory of the area tree
- //this.parentArea = null;
- }
-
/**
* Force current area to be added to parent area.
*/
@@ -244,12 +236,13 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
}
/** {@inheritDoc} */
+ @Override
public List getNextKnuthElements(LayoutContext context, int alignment) {
referenceIPD = context.getRefIPD();
updateContentAreaIPDwithOverconstrainedAdjust();
- List contentList = new LinkedList();
- List elements = new LinkedList();
+ List contentList = new LinkedList();
+ List elements = new LinkedList();
if (!breakBeforeServed) {
breakBeforeServed = true;
@@ -275,11 +268,11 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
BreakElement forcedBreakAfterLast = null;
LayoutManager currentChildLM;
- while ((currentChildLM = (LayoutManager) getChildLM()) != null) {
+ while ((currentChildLM = getChildLM()) != null) {
LayoutContext childLC = new LayoutContext(0);
- List childrenElements = getNextChildElements(currentChildLM, context, childLC,
- alignment);
+ List childrenElements
+ = getNextChildElements(currentChildLM, context, childLC, alignment);
if (contentList.isEmpty()) {
//Propagate keep-with-previous up from the first child
@@ -306,7 +299,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
if (contentList.isEmpty()) {
// Empty fo:block, zero-length box makes sure the IDs and/or markers
// are registered and borders/padding are painted.
- elements.add(new KnuthBox(0, notifyPos(new Position(this)), false));
+ elements.add(makeAuxiliaryZeroWidthBox());
}
// a descendant of this block has break-before
contentList.addAll(childrenElements);
@@ -338,7 +331,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
} else if (forcedBreakAfterLast == null) {
// Empty fo:block, zero-length box makes sure the IDs and/or markers
// are registered.
- elements.add(new KnuthBox(0, notifyPos(new Position(this)), true));
+ elements.add(makeAuxiliaryZeroWidthBox());
}
addKnuthElementsForBorderPaddingAfter(elements, true);
@@ -361,14 +354,15 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
}
/** {@inheritDoc} */
+ @Override
public List getNextKnuthElements // CSOK: MethodLength
(LayoutContext context, int alignment, Stack lmStack,
Position restartPosition, LayoutManager restartAtLM) {
referenceIPD = context.getRefIPD();
updateContentAreaIPDwithOverconstrainedAdjust();
- List contentList = new LinkedList();
- List elements = new LinkedList();
+ List contentList = new LinkedList();
+ List elements = new LinkedList();
if (!breakBeforeServed) {
breakBeforeServed = true;
@@ -394,7 +388,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
BreakElement forcedBreakAfterLast = null;
LayoutContext childLC = new LayoutContext(0);
- List childrenElements;
+ List childrenElements;
LayoutManager currentChildLM;
if (lmStack.isEmpty()) {
assert restartAtLM != null && restartAtLM.getParent() == this;
@@ -405,7 +399,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
childrenElements = getNextChildElements(currentChildLM, context, childLC,
alignment);
} else {
- currentChildLM = (BlockLevelLayoutManager) lmStack.pop();
+ currentChildLM = (LayoutManager) lmStack.pop();
setCurrentChildLM(currentChildLM);
childrenElements = getNextChildElements(currentChildLM, context, childLC, alignment,
lmStack, restartPosition, restartAtLM);
@@ -430,13 +424,12 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
// a descendant of this block has break-before
forcedBreakAfterLast = (BreakElement) childrenElements.get(0);
context.clearPendingMarks();
-// break; TODO
}
if (contentList.isEmpty()) {
// Empty fo:block, zero-length box makes sure the IDs and/or markers
// are registered and borders/padding are painted.
- elements.add(new KnuthBox(0, notifyPos(new Position(this)), false));
+ elements.add(makeAuxiliaryZeroWidthBox());
}
// a descendant of this block has break-before
contentList.addAll(childrenElements);
@@ -451,7 +444,6 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
if (currentChildLM.isFinished() && !hasNextChildLM()) {
forcedBreakAfterLast = (BreakElement) ListUtil.removeLast(contentList);
context.clearPendingMarks();
-// break; TODO
}
wrapPositionElements(contentList, elements);
@@ -462,7 +454,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
}
- while ((currentChildLM = (LayoutManager) getChildLM()) != null) {
+ while ((currentChildLM = getChildLM()) != null) {
currentChildLM.reset(); // TODO won't work with forced breaks
childLC = new LayoutContext(0);
@@ -495,7 +487,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
if (contentList.isEmpty()) {
// Empty fo:block, zero-length box makes sure the IDs and/or markers
// are registered and borders/padding are painted.
- elements.add(new KnuthBox(0, notifyPos(new Position(this)), false));
+ elements.add(makeAuxiliaryZeroWidthBox());
}
// a descendant of this block has break-before
contentList.addAll(childrenElements);
@@ -527,7 +519,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
} else if (forcedBreakAfterLast == null) {
// Empty fo:block, zero-length box makes sure the IDs and/or markers
// are registered.
- elements.add(new KnuthBox(0, notifyPos(new Position(this)), true));
+ elements.add(makeAuxiliaryZeroWidthBox());
}
addKnuthElementsForBorderPaddingAfter(elements, true);
@@ -549,12 +541,32 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
return elements;
}
- private List getNextChildElements(LayoutManager childLM, LayoutContext context,
+ private KnuthBox makeZeroWidthBox() {
+ return new KnuthBox(0, new NonLeafPosition(this, null), false);
+ }
+
+ private KnuthBox makeAuxiliaryZeroWidthBox() {
+ return new KnuthBox(0, notifyPos(new Position(this)), true);
+ }
+
+ private KnuthPenalty makeZeroWidthPenalty(int penaltyValue) {
+ return new KnuthPenalty(0, penaltyValue, false, new NonLeafPosition(this, null), false);
+ }
+
+ private KnuthGlue makeSpaceAdjustmentGlue(int width, Adjustment adjustmentClass,
+ boolean isAuxiliary) {
+ return new KnuthGlue(width, 0, 0,
+ adjustmentClass,
+ new NonLeafPosition(this, null),
+ isAuxiliary);
+ }
+
+ private List getNextChildElements(LayoutManager childLM, LayoutContext context,
LayoutContext childLC, int alignment) {
return getNextChildElements(childLM, context, childLC, alignment, null, null, null);
}
- private List getNextChildElements(LayoutManager childLM, LayoutContext context,
+ private List getNextChildElements(LayoutManager childLM, LayoutContext context,
LayoutContext childLC, int alignment, Stack lmStack, Position restartPosition,
LayoutManager restartAtLM) {
childLC.copyPendingMarksFrom(context);
@@ -588,7 +600,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
* @param parentLC the parent layout context
* @param childLC the currently active child layout context
*/
- protected void addInBetweenBreak(List contentList, LayoutContext parentLC,
+ protected void addInBetweenBreak(List contentList, LayoutContext parentLC,
LayoutContext childLC) {
if (mustKeepTogether()
@@ -612,7 +624,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
return;
}
- ListElement last = (ListElement) ListUtil.getLast(contentList);
+ ListElement last = ListUtil.getLast(contentList);
if (last.isGlue()) {
// the last element in contentList is a glue;
// it is a feasible breakpoint, there is no need to add
@@ -643,15 +655,9 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
-/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> " + adj);
-/*LF*/ //log.debug(" lastElement e' " + (lastElement.isPenalty()
- // ? "penalty" : (lastElement.isGlue() ? "glue" : "box" )));
-/*LF*/ //log.debug(" position e' " + lastElement.getPosition().getClass().getName());
-/*LF*/ //log.debug(" " + (bpUnit > 0 ? "unit" : ""));
+ assert (lastElement != null && lastElement.getPosition() != null);
Position innerPosition = lastElement.getPosition().getPosition();
if (innerPosition == null && lastElement.isGlue()) {
@@ -660,11 +666,9 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
== Adjustment.SPACE_BEFORE_ADJUSTMENT) {
// this adjustment applies to space-before
adjustedSpaceBefore += adj;
-/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> spazio prima: " + adj);
} else {
// this adjustment applies to space-after
adjustedSpaceAfter += adj;
-/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> spazio dopo: " + adj);
}
return adj;
} else if (innerPosition instanceof MappingPosition) {
@@ -674,7 +678,6 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
MappingPosition mappingPos = (MappingPosition)innerPosition;
if (lastElement.isGlue()) {
// lastElement is a glue
-/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> bpunit con glue");
ListIterator storedListIterator = storedList.listIterator(
mappingPos.getFirstIndex());
int newAdjustment = 0;
@@ -684,8 +687,6 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
newAdjustment += ((BlockLevelLayoutManager)storedElement
.getLayoutManager()).negotiateBPDAdjustment(
adj - newAdjustment, storedElement);
-/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> (progressivo) righe: "
- // + newAdjustment);
}
}
newAdjustment = (newAdjustment > 0 ? bpUnit * neededUnits(newAdjustment)
@@ -695,19 +696,16 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
// lastElement is a penalty: this means that the paragraph
// has been split between consecutive pages:
// this may involve a change in the number of lines
-/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> bpunit con penalty");
KnuthPenalty storedPenalty = (KnuthPenalty)
storedList.get(mappingPos.getLastIndex());
if (storedPenalty.getWidth() > 0) {
// the original penalty has width > 0
-/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> chiamata passata");
return ((BlockLevelLayoutManager)storedPenalty.getLayoutManager())
.negotiateBPDAdjustment(storedPenalty.getWidth(),
storedPenalty);
} else {
// the original penalty has width = 0
// the adjustment involves only the spaces before and after
-/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> chiamata gestita");
return adj;
}
}
@@ -718,7 +716,6 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
int returnValue = ((BlockLevelLayoutManager)lastElement.getLayoutManager())
.negotiateBPDAdjustment(adj, lastElement);
lastElement.setPosition(savedPos);
-/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> righe: " + returnValue);
return returnValue;
} else {
// this should never happen
@@ -727,12 +724,10 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void discardSpace(KnuthGlue spaceGlue) {
- //log.debug(" BLM.discardSpace> " + spaceGlue.getPosition().getClass().getName());
- Position innerPosition = ((NonLeafPosition) spaceGlue.getPosition()).getPosition();
+ assert (spaceGlue != null && spaceGlue.getPosition() != null);
+ Position innerPosition = spaceGlue.getPosition().getPosition();
if (innerPosition == null || innerPosition.getLM() == this) {
// if this block has block-progression-unit > 0, innerPosition can be
@@ -757,36 +752,27 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
}
}
- /**
- * {@inheritDoc}
- */
- public List getChangedKnuthElements(List oldList, int alignment) { // CSOK: MethodLength
-/*LF*/ //log.debug("");
-/*LF*/ //log.debug(" BLM.getChangedKnuthElements> inizio: oldList.size() = "
- // + oldList.size());
- ListIterator oldListIterator = oldList.listIterator();
- KnuthElement returnedElement;
+ /** {@inheritDoc} */
+ @Override
+ public List getChangedKnuthElements(List oldList, int alignment) {
+ ListIterator oldListIterator = oldList.listIterator();
KnuthElement currElement = null;
KnuthElement prevElement = null;
- List returnedList = new LinkedList();
- List returnList = new LinkedList();
+ List returnedList = new LinkedList();
+ List returnList = new LinkedList();
int fromIndex = 0;
// "unwrap" the Positions stored in the elements
- KnuthElement oldElement = null;
+ KnuthElement oldElement;
while (oldListIterator.hasNext()) {
- oldElement = (KnuthElement)oldListIterator.next();
- Position innerPosition = ((NonLeafPosition) oldElement.getPosition()).getPosition();
- //log.debug(" BLM> unwrapping: "
- // + (oldElement.isBox() ? "box " : (oldElement.isGlue() ? "glue " : "penalty"))
- // + " creato da " + oldElement.getLayoutManager().getClass().getName());
- //log.debug(" BLM> unwrapping: "
- // + oldElement.getPosition().getClass().getName());
+ oldElement = oldListIterator.next();
+ assert oldElement.getPosition() != null;
+ Position innerPosition = oldElement.getPosition().getPosition();
if (innerPosition != null) {
- // oldElement was created by a descendant of this BlockLM
+ // oldElement was created by a descendant
oldElement.setPosition(innerPosition);
} else {
- // thisElement was created by this BlockLM
+ // oldElement was created by this LM:
// modify its position in order to recognize it was not created
// by a child
oldElement.setPosition(new Position(this));
@@ -794,63 +780,24 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
}
// create the iterator
- List workList;
- if (bpUnit == 0) {
- workList = oldList;
- } else {
- // the storedList must be used instead of oldList;
- // find the index of the first element of returnedList
- // corresponding to the first element of oldList
- oldListIterator = oldList.listIterator();
- KnuthElement el = (KnuthElement) oldListIterator.next();
- while (!(el.getPosition() instanceof MappingPosition)) {
- el = (KnuthElement) oldListIterator.next();
- }
- int iFirst = ((MappingPosition) el.getPosition()).getFirstIndex();
-
- // find the index of the last element of returnedList
- // corresponding to the last element of oldList
- oldListIterator = oldList.listIterator(oldList.size());
- el = (KnuthElement) oldListIterator.previous();
- while (!(el.getPosition() instanceof MappingPosition)) {
- el = (KnuthElement) oldListIterator.previous();
- }
- int iLast = ((MappingPosition) el.getPosition()).getLastIndex();
-
- //log-debug(" si usa storedList da " + iFirst + " a " + iLast
- // + " compresi su " + storedList.size() + " elementi totali");
- workList = storedList.subList(iFirst, iLast + 1);
- }
- ListIterator workListIterator = workList.listIterator();
-
- //log.debug(" BLM.getChangedKnuthElements> workList.size() = "
- // + workList.size() + " da 0 a " + (workList.size() - 1));
-
+ List workList = oldList;
+ ListIterator workListIterator = workList.listIterator();
while (workListIterator.hasNext()) {
- currElement = (KnuthElement) workListIterator.next();
- //log.debug("elemento n. " + workListIterator.previousIndex()
- // + " nella workList");
+ currElement = workListIterator.next();
if (prevElement != null
&& prevElement.getLayoutManager() != currElement.getLayoutManager()) {
// prevElement is the last element generated by the same LM
- BlockLevelLayoutManager prevLM = (BlockLevelLayoutManager)
- prevElement.getLayoutManager();
- BlockLevelLayoutManager currLM = (BlockLevelLayoutManager)
- currElement.getLayoutManager();
- boolean bSomethingAdded = false;
+ BlockLevelLayoutManager prevLM
+ = (BlockLevelLayoutManager)prevElement.getLayoutManager();
+ BlockLevelLayoutManager currLM
+ = (BlockLevelLayoutManager)currElement.getLayoutManager();
+ boolean somethingAdded = false;
if (prevLM != this) {
- //log.debug(" BLM.getChangedKnuthElements> chiamata da "
- // + fromIndex + " a " + workListIterator.previousIndex() + " su "
- // + prevLM.getClass().getName());
returnedList.addAll(prevLM.getChangedKnuthElements(workList.subList(
fromIndex, workListIterator.previousIndex()), alignment));
- bSomethingAdded = true;
+ somethingAdded = true;
} else {
- // prevLM == this
// do nothing
- //log.debug(" BLM.getChangedKnuthElements> elementi propri, "
- // + "ignorati, da " + fromIndex + " a " + workListIterator.previousIndex()
- // + " su " + prevLM.getClass().getName());
}
fromIndex = workListIterator.previousIndex();
@@ -859,116 +806,77 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
* while in getNextKE they were changed to BreakElements?
*/
// there is another block after this one
- if (bSomethingAdded
+ if (somethingAdded
&& (this.mustKeepTogether()
|| prevLM.mustKeepWithNext()
|| currLM.mustKeepWithPrevious())) {
// add an infinite penalty to forbid a break between blocks
- returnedList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false,
- new Position(this), false));
- } else if (bSomethingAdded
- && !((KnuthElement) ListUtil.getLast(returnedList))
- .isGlue()) {
+ returnedList.add(makeZeroWidthPenalty(KnuthPenalty.INFINITE));
+ } else if (somethingAdded
+ && !ListUtil.getLast(returnedList).isGlue()) {
// add a null penalty to allow a break between blocks
- returnedList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
+ returnedList.add(makeZeroWidthPenalty(KnuthPenalty.INFINITE));
}
}
prevElement = currElement;
}
if (currElement != null) {
- BlockLevelLayoutManager currLM = (BlockLevelLayoutManager)
- currElement.getLayoutManager();
+ LayoutManager currLM = currElement.getLayoutManager();
if (currLM != this) {
- //log.debug(" BLM.getChangedKnuthElements> chiamata da " + fromIndex
- // + " a " + oldList.size() + " su " + currLM.getClass().getName());
returnedList.addAll(currLM.getChangedKnuthElements(
workList.subList(fromIndex, workList.size()), alignment));
} else {
- // currLM == this
// there are no more elements to add
// remove the last penalty added to returnedList
if (!returnedList.isEmpty()) {
ListUtil.removeLast(returnedList);
}
- //log.debug(" BLM.getChangedKnuthElements> elementi propri, ignorati, da "
- // + fromIndex + " a " + workList.size());
}
}
// append elements representing space-before
boolean spaceBeforeIsConditional = true;
if (fobj instanceof org.apache.fop.fo.flow.Block) {
- spaceBeforeIsConditional = ((org.apache.fop.fo.flow.Block)fobj)
- .getCommonMarginBlock().spaceBefore.getSpace().isDiscard();
+ spaceBeforeIsConditional = getSpaceBeforeProperty().isDiscard();
}
- if (bpUnit > 0
- || adjustedSpaceBefore != 0) {
+ if (adjustedSpaceBefore != 0) {
if (!spaceBeforeIsConditional) {
// add elements to prevent the glue to be discarded
- returnList.add(new KnuthBox(0,
- new NonLeafPosition(this, null), false));
- returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false,
- new NonLeafPosition(this, null), false));
- }
- if (bpUnit > 0) {
- returnList.add(new KnuthGlue(0, 0, 0,
- Adjustment.SPACE_BEFORE_ADJUSTMENT, new NonLeafPosition(this, null), true));
- } else {
- returnList.add(new KnuthGlue(adjustedSpaceBefore, 0, 0,
- Adjustment.SPACE_BEFORE_ADJUSTMENT, new NonLeafPosition(this, null), true));
+ returnList.add(makeZeroWidthBox());
+ returnList.add(makeZeroWidthPenalty(KnuthPenalty.INFINITE));
}
- }
-
- //log.debug(" BLM.getChangedKnuthElements> intermedio: returnedList.size() = "
- // + returnedList.size());
-/* estensione: conversione complessiva */
-/*LF*/ if (bpUnit > 0) {
-/*LF*/ storedList = returnedList;
-/*LF*/ returnedList = createUnitElements(returnedList);
-/*LF*/ }
-/* estensione */
+ returnList.add(makeSpaceAdjustmentGlue(adjustedSpaceBefore,
+ Adjustment.SPACE_BEFORE_ADJUSTMENT,
+ false));
+ }
// "wrap" the Position stored in each element of returnedList
// and add elements to returnList
- ListIterator listIter = returnedList.listIterator();
- while (listIter.hasNext()) {
- returnedElement = (KnuthElement)listIter.next();
- returnedElement.setPosition(new NonLeafPosition(this, returnedElement.getPosition()));
- returnList.add(returnedElement);
+ for (KnuthElement el : returnedList) {
+ el.setPosition(new NonLeafPosition(this, el.getPosition()));
+ returnList.add(el);
}
// append elements representing space-after
boolean spaceAfterIsConditional = true;
if (fobj instanceof org.apache.fop.fo.flow.Block) {
- spaceAfterIsConditional = ((org.apache.fop.fo.flow.Block)fobj)
- .getCommonMarginBlock().spaceAfter.getSpace().isDiscard();
+ spaceAfterIsConditional = getSpaceAfterProperty().isDiscard();
}
- if (bpUnit > 0 || adjustedSpaceAfter != 0) {
+ if (adjustedSpaceAfter != 0) {
if (!spaceAfterIsConditional) {
- returnList.add(new KnuthPenalty(0,
- KnuthElement.INFINITE, false,
- new NonLeafPosition(this, null), false));
- }
- if (bpUnit > 0) {
- returnList.add(new KnuthGlue(0, 0, 0,
- Adjustment.SPACE_AFTER_ADJUSTMENT,
- new NonLeafPosition(this, null),
- spaceAfterIsConditional));
- } else {
- returnList.add(new KnuthGlue(adjustedSpaceAfter, 0, 0,
- Adjustment.SPACE_AFTER_ADJUSTMENT,
- new NonLeafPosition(this, null),
- spaceAfterIsConditional));
+ returnList.add(makeZeroWidthPenalty(KnuthPenalty.INFINITE));
}
+
+ returnList.add(makeSpaceAdjustmentGlue(adjustedSpaceAfter,
+ Adjustment.SPACE_AFTER_ADJUSTMENT,
+ spaceAfterIsConditional));
+
if (!spaceAfterIsConditional) {
- returnList.add(new KnuthBox(0,
- new NonLeafPosition(this, null), true));
+ returnList.add(makeZeroWidthBox());
}
}
- //log.debug(" BLM.getChangedKnuthElements> finished: returnList.size() = "
- // + returnList.size());
return returnList;
}
@@ -1218,8 +1126,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
* @param context the layout context
* @return true if an element has been added due to a break-before.
*/
- protected boolean addKnuthElementsForBreakBefore(List returnList,
- LayoutContext context) {
+ protected boolean addKnuthElementsForBreakBefore(List returnList, LayoutContext context) {
int breakBefore = getBreakBefore();
if (breakBefore == EN_PAGE
|| breakBefore == EN_COLUMN
@@ -1261,8 +1168,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
* @param context the layout context
* @return true if an element has been added due to a break-after.
*/
- protected boolean addKnuthElementsForBreakAfter(List returnList,
- LayoutContext context) {
+ protected boolean addKnuthElementsForBreakAfter(List returnList, LayoutContext context) {
int breakAfter = -1;
if (fobj instanceof BreakPropertySet) {
breakAfter = ((BreakPropertySet)fobj).getBreakAfter();
@@ -1285,8 +1191,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
* @param returnList return list to add the additional elements to
* @param alignment vertical alignment
*/
- protected void addKnuthElementsForSpaceBefore(List returnList/*,
- Position returnPosition*/, int alignment) {
+ protected void addKnuthElementsForSpaceBefore(List returnList, int alignment) {
SpaceProperty spaceBefore = getSpaceBeforeProperty();
// append elements representing space-before
if (spaceBefore != null
@@ -1296,37 +1201,6 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
RelSide.BEFORE,
true, false, this));
}
- /*
- if (bpUnit > 0
- || spaceBefore != null
- && !(spaceBefore.getMinimum(this).getLength().getValue(this) == 0
- && spaceBefore.getMaximum(this).getLength().getValue(this) == 0)) {
- if (spaceBefore != null && !spaceBefore.getSpace().isDiscard()) {
- // add elements to prevent the glue to be discarded
- returnList.add(new KnuthBox(0, getAuxiliaryPosition(), false));
- returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE,
- false, getAuxiliaryPosition(), false));
- }
- if (bpUnit > 0) {
- returnList.add(new KnuthGlue(0, 0, 0,
- BlockLevelLayoutManager.SPACE_BEFORE_ADJUSTMENT,
- getAuxiliaryPosition(), true));
- } else { //if (alignment == EN_JUSTIFY) {
- returnList.add(new KnuthGlue(
- spaceBefore.getOptimum(this).getLength().getValue(this),
- spaceBefore.getMaximum(this).getLength().getValue(this)
- - spaceBefore.getOptimum(this).getLength().getValue(this),
- spaceBefore.getOptimum(this).getLength().getValue(this)
- - spaceBefore.getMinimum(this).getLength().getValue(this),
- BlockLevelLayoutManager.SPACE_BEFORE_ADJUSTMENT,
- getAuxiliaryPosition(), true));
-// } else {
-// returnList.add(new KnuthGlue(
-// spaceBefore.getOptimum().getLength().getValue(this),
-// 0, 0, BlockLevelLayoutManager.SPACE_BEFORE_ADJUSTMENT,
-// returnPosition, true));
- }
- }*/
}
/**
@@ -1334,8 +1208,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
* @param returnList return list to add the additional elements to
* @param alignment vertical alignment
*/
- protected void addKnuthElementsForSpaceAfter(List returnList/*, Position returnPosition*/,
- int alignment) {
+ protected void addKnuthElementsForSpaceAfter(List returnList, int alignment) {
SpaceProperty spaceAfter = getSpaceAfterProperty();
// append elements representing space-after
if (spaceAfter != null
@@ -1345,359 +1218,6 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
RelSide.AFTER,
false, true, this));
}
- /*
- if (bpUnit > 0
- || spaceAfter != null
- && !(spaceAfter.getMinimum(this).getLength().getValue(this) == 0
- && spaceAfter.getMaximum(this).getLength().getValue(this) == 0)) {
- if (spaceAfter != null && !spaceAfter.getSpace().isDiscard()) {
- returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE,
- false, getAuxiliaryPosition(), false));
- }
- if (bpUnit > 0) {
- returnList.add(new KnuthGlue(0, 0, 0,
- BlockLevelLayoutManager.SPACE_AFTER_ADJUSTMENT,
- getAuxiliaryPosition(), true));
- } else { //if (alignment == EN_JUSTIFY) {
- returnList.add(new KnuthGlue(
- spaceAfter.getOptimum(this).getLength().getValue(this),
- spaceAfter.getMaximum(this).getLength().getValue(this)
- - spaceAfter.getOptimum(this).getLength().getValue(this),
- spaceAfter.getOptimum(this).getLength().getValue(this)
- - spaceAfter.getMinimum(this).getLength().getValue(this),
- BlockLevelLayoutManager.SPACE_AFTER_ADJUSTMENT, getAuxiliaryPosition(),
- (!spaceAfter.getSpace().isDiscard()) ? false : true));
-// } else {
-// returnList.add(new KnuthGlue(
-// spaceAfter.getOptimum().getLength().getValue(this), 0, 0,
-// BlockLevelLayoutManager.SPACE_AFTER_ADJUSTMENT, returnPosition,
-// (!spaceAfter.getSpace().isDiscard()) ? false : true));
- }
- if (spaceAfter != null && !spaceAfter.getSpace().isDiscard()) {
- returnList.add(new KnuthBox(0, getAuxiliaryPosition(), true));
- }
- }*/
- }
-
- /**
- * Create unit elements.
- * @param oldList the old list
- * @return the new list
- */
- protected List createUnitElements(List oldList) { // CSOK: MethodLength
- //log.debug("Start conversion: " + oldList.size()
- // + " elements, space-before.min=" + layoutProps.spaceBefore.getSpace().min
- // + " space-after.min=" + layoutProps.spaceAfter.getSpace().min);
- // add elements at the beginning and at the end of oldList
- // representing minimum spaces
- LayoutManager lm = ((KnuthElement)oldList.get(0)).getLayoutManager();
- boolean bAddedBoxBefore = false;
- boolean bAddedBoxAfter = false;
- if (adjustedSpaceBefore > 0) {
- oldList.add(0, new KnuthBox(adjustedSpaceBefore,
- new Position(lm), true));
- bAddedBoxBefore = true;
- }
- if (adjustedSpaceAfter > 0) {
- oldList.add(new KnuthBox(adjustedSpaceAfter,
- new Position(lm), true));
- bAddedBoxAfter = true;
- }
-
- MinOptMax totalLength = MinOptMax.ZERO;
- LinkedList newList = new LinkedList();
-
- //log.debug(" Prima scansione");
- // scan the list once to compute total min, opt and max length
- ListIterator oldListIterator = oldList.listIterator();
- while (oldListIterator.hasNext()) {
- KnuthElement element = (KnuthElement) oldListIterator.next();
- if (element.isBox()) {
- totalLength = totalLength.plus(element.getWidth());
- //log.debug("box " + element.getWidth());
- } else if (element.isGlue()) {
- totalLength = totalLength.minusMin(element.getShrink());
- totalLength = totalLength.plusMax(element.getStretch());
- //leafValue = ((LeafPosition) element.getPosition()).getLeafPos();
- //log.debug("glue " + element.getWidth() + " + "
- // + ((KnuthGlue) element).getStretch() + " - "
- // + ((KnuthGlue) element).getShrink());
- } else {
- //log.debug((((KnuthPenalty)element).getPenalty() == KnuthElement.INFINITE
- // ? "PENALTY " : "penalty ") + element.getWidth());
- }
- }
- // compute the total amount of "units"
- MinOptMax totalUnits = MinOptMax.getInstance(neededUnits(totalLength.getMin()),
- neededUnits(totalLength.getOpt()),
- neededUnits(totalLength.getMax()));
- //log.debug(" totalLength= " + totalLength);
- //log.debug(" unita'= " + totalUnits);
-
- //log.debug(" Seconda scansione");
- // scan the list once more, stopping at every breaking point
- // in order to compute partial min, opt and max length
- // and create the new elements
- oldListIterator = oldList.listIterator();
- boolean prevIsBox;
- MinOptMax lengthBeforeBreak = MinOptMax.ZERO;
- MinOptMax lengthAfterBreak = totalLength;
- MinOptMax unitsBeforeBreak;
- MinOptMax unitsAfterBreak;
- MinOptMax unsuppressibleUnits = MinOptMax.ZERO;
- int firstIndex = 0;
- int lastIndex = -1;
- while (oldListIterator.hasNext()) {
- KnuthElement element = (KnuthElement) oldListIterator.next();
- lastIndex++;
- if (element.isBox()) {
- lengthBeforeBreak = lengthBeforeBreak.plus(element.getWidth());
- lengthAfterBreak = lengthAfterBreak.minus(element.getWidth());
- prevIsBox = true;
- } else if (element.isGlue()) {
- lengthBeforeBreak = lengthBeforeBreak.minusMin(element.getShrink());
- lengthAfterBreak = lengthAfterBreak.plusMin(element.getShrink());
- lengthBeforeBreak = lengthBeforeBreak.plusMax(element.getStretch());
- lengthAfterBreak = lengthAfterBreak.minusMax(element.getStretch());
- prevIsBox = false;
- } else {
- lengthBeforeBreak = lengthBeforeBreak.plus(element.getWidth());
- prevIsBox = false;
- }
-
- // create the new elements
- if (element.isPenalty() && element.getPenalty() < KnuthElement.INFINITE
- || element.isGlue() && prevIsBox
- || !oldListIterator.hasNext()) {
- // suppress elements after the breaking point
- int iStepsForward = 0;
- while (oldListIterator.hasNext()) {
- KnuthElement el = (KnuthElement) oldListIterator.next();
- iStepsForward++;
- if (el.isGlue()) {
- // suppressed glue
- lengthAfterBreak = lengthAfterBreak.plusMin(el.getShrink());
- lengthAfterBreak = lengthAfterBreak.minusMax(el.getStretch());
- } else if (el.isPenalty()) {
- // suppressed penalty, do nothing
- } else {
- // box, end of suppressions
- break;
- }
- }
- // compute the partial amount of "units" before and after the break
- unitsBeforeBreak = MinOptMax.getInstance(neededUnits(lengthBeforeBreak.getMin()),
- neededUnits(lengthBeforeBreak.getOpt()),
- neededUnits(lengthBeforeBreak.getMax()));
- unitsAfterBreak = MinOptMax.getInstance(neededUnits(lengthAfterBreak.getMin()),
- neededUnits(lengthAfterBreak.getOpt()),
- neededUnits(lengthAfterBreak.getMax()));
-
- // rewind the iterator and lengthAfterBreak
- for (int i = 0; i < iStepsForward; i++) {
- KnuthElement el = (KnuthElement) oldListIterator.previous();
- if (el.isGlue()) {
- lengthAfterBreak = lengthAfterBreak.minusMin(el.getShrink());
- lengthAfterBreak = lengthAfterBreak.plusMax(el.getStretch());
- }
- }
-
- // compute changes in length, stretch and shrink
- int uLengthChange = unitsBeforeBreak.getOpt() + unitsAfterBreak.getOpt()
- - totalUnits.getOpt();
- int uStretchChange = unitsBeforeBreak.getStretch()
- + unitsAfterBreak.getStretch() - totalUnits.getStretch();
- int uShrinkChange = unitsBeforeBreak.getShrink()
- + unitsAfterBreak.getShrink() - totalUnits.getShrink();
-
- // compute the number of normal, stretch and shrink unit
- // that must be added to the new sequence
- int uNewNormal = unitsBeforeBreak.getOpt() - unsuppressibleUnits.getOpt();
- int uNewStretch = unitsBeforeBreak.getStretch()
- - unsuppressibleUnits.getStretch();
- int uNewShrink = unitsBeforeBreak.getShrink()
- - unsuppressibleUnits.getShrink();
-
- //log.debug("("
- // + unsuppressibleUnits.min + "-" + unsuppressibleUnits.opt + "-"
- // + unsuppressibleUnits.max + ") "
- // + " -> " + unitsBeforeBreak.min + "-" + unitsBeforeBreak.opt + "-"
- // + unitsBeforeBreak.max
- // + " + " + unitsAfterBreak.min + "-" + unitsAfterBreak.opt + "-"
- // + unitsAfterBreak.max
- // + (uLengthChange != 0 ? " [length " + uLengthChange + "] " : "")
- // + (uStretchChange != 0 ? " [stretch " + uStretchChange + "] " : "")
- // + (uShrinkChange != 0 ? " [shrink " + uShrinkChange + "]" : ""));
-
- // create the MappingPosition which will be stored in the new elements
- // correct firstIndex and lastIndex
- int firstIndexCorrection = 0;
- int lastIndexCorrection = 0;
- if (bAddedBoxBefore) {
- if (firstIndex != 0) {
- firstIndexCorrection++;
- }
- lastIndexCorrection++;
- }
- if (bAddedBoxAfter && lastIndex == (oldList.size() - 1)) {
- lastIndexCorrection++;
- }
- MappingPosition mappingPos = new MappingPosition(this,
- firstIndex - firstIndexCorrection,
- lastIndex - lastIndexCorrection);
-
- // new box
- newList.add(new KnuthBox((uNewNormal - uLengthChange) * bpUnit, mappingPos, false));
- unsuppressibleUnits = unsuppressibleUnits.plus(uNewNormal - uLengthChange);
- //log.debug(" box " + (uNewNormal - uLengthChange));
-
- // new infinite penalty, glue and box, if necessary
- if (uNewStretch - uStretchChange > 0
- || uNewShrink - uShrinkChange > 0) {
- int iStretchUnits = (uNewStretch - uStretchChange > 0
- ? (uNewStretch - uStretchChange) : 0);
- int iShrinkUnits = (uNewShrink - uShrinkChange > 0
- ? (uNewShrink - uShrinkChange) : 0);
- newList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false,
- mappingPos,
- false));
- newList.add(new KnuthGlue(0,
- iStretchUnits * bpUnit,
- iShrinkUnits * bpUnit,
- Adjustment.LINE_NUMBER_ADJUSTMENT,
- mappingPos,
- false));
- //log.debug(" PENALTY");
- //log.debug(" glue 0 " + iStretchUnits + " " + iShrinkUnits);
- unsuppressibleUnits = unsuppressibleUnits.plusMax(iStretchUnits);
- unsuppressibleUnits = unsuppressibleUnits.minusMin(iShrinkUnits);
- if (!oldListIterator.hasNext()) {
- newList.add(new KnuthBox(0, mappingPos, false));
- //log.debug(" box 0");
- }
- }
-
- // new breaking sequence
- if (uStretchChange != 0
- || uShrinkChange != 0) {
- // new infinite penalty, glue, penalty and glue
- newList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false,
- mappingPos,
- false));
- newList.add(new KnuthGlue(0,
- uStretchChange * bpUnit,
- uShrinkChange * bpUnit,
- Adjustment.LINE_NUMBER_ADJUSTMENT,
- mappingPos,
- false));
- newList.add(new KnuthPenalty(uLengthChange * bpUnit,
- 0, false, element.getPosition(), false));
- newList.add(new KnuthGlue(0,
- -uStretchChange * bpUnit,
- -uShrinkChange * bpUnit,
- Adjustment.LINE_NUMBER_ADJUSTMENT,
- mappingPos,
- false));
- //log.debug(" PENALTY");
- //log.debug(" glue 0 " + uStretchChange + " " + uShrinkChange);
- //log.debug(" penalty " + uLengthChange + " * unit");
- //log.debug(" glue 0 " + (- uStretchChange) + " "
- // + (- uShrinkChange));
- } else if (oldListIterator.hasNext()) {
- // new penalty
- newList.add(new KnuthPenalty(uLengthChange * bpUnit,
- 0, false,
- mappingPos,
- false));
- //log.debug(" penalty " + uLengthChange + " * unit");
- }
- // update firstIndex
- firstIndex = lastIndex + 1;
- }
-
- if (element.isPenalty()) {
- lengthBeforeBreak = lengthBeforeBreak.minus(element.getWidth());
- }
-
- }
-
- // remove elements at the beginning and at the end of oldList
- // representing minimum spaces
- if (adjustedSpaceBefore > 0) {
- oldList.remove(0);
- }
- if (adjustedSpaceAfter > 0) {
- ListUtil.removeLast(oldList);
- }
-
- // if space-before.conditionality is "discard", correct newList
- boolean correctFirstElement = false;
- if (fobj instanceof org.apache.fop.fo.flow.Block) {
- correctFirstElement = ((org.apache.fop.fo.flow.Block)fobj)
- .getCommonMarginBlock().spaceBefore.getSpace().isDiscard();
- }
- if (correctFirstElement) {
- // remove the wrong element
- KnuthBox wrongBox = (KnuthBox) newList.removeFirst();
- // if this paragraph is at the top of a page, the space before
- // must be ignored; compute the length change
- int decreasedLength = (neededUnits(totalLength.getOpt())
- - neededUnits(totalLength.getOpt() - adjustedSpaceBefore))
- * bpUnit;
- // insert the correct elements
- newList.addFirst(new KnuthBox(wrongBox.getWidth() - decreasedLength,
- wrongBox.getPosition(), false));
- newList.addFirst(new KnuthGlue(decreasedLength, 0, 0,
- Adjustment.SPACE_BEFORE_ADJUSTMENT,
- wrongBox.getPosition(), false));
- //log.debug(" rimosso box " + neededUnits(wrongBox.getWidth()));
- //log.debug(" aggiunto glue " + neededUnits(decreasedLength) + " 0 0");
- //log.debug(" aggiunto box " + neededUnits(
- // wrongBox.getWidth() - decreasedLength));
- }
-
- // if space-after.conditionality is "discard", correct newList
- boolean correctLastElement = false;
- if (fobj instanceof org.apache.fop.fo.flow.Block) {
- correctLastElement = ((org.apache.fop.fo.flow.Block)fobj)
- .getCommonMarginBlock().spaceAfter.getSpace().isDiscard();
- }
- if (correctLastElement) {
- // remove the wrong element
- KnuthBox wrongBox = (KnuthBox) newList.removeLast();
- // if the old sequence is box(h) penalty(inf) glue(x,y,z) box(0)
- // (it cannot be parted and has some stretch or shrink)
- // the wrong box is the first one, not the last one
- LinkedList preserveList = new LinkedList();
- if (wrongBox.getWidth() == 0) {
- preserveList.add(wrongBox);
- preserveList.addFirst((KnuthGlue) newList.removeLast());
- preserveList.addFirst((KnuthPenalty) newList.removeLast());
- wrongBox = (KnuthBox) newList.removeLast();
- }
-
- // if this paragraph is at the bottom of a page, the space after
- // must be ignored; compute the length change
- int decreasedLength = (neededUnits(totalLength.getOpt())
- - neededUnits(totalLength.getOpt() - adjustedSpaceAfter))
- * bpUnit;
- // insert the correct box
- newList.addLast(new KnuthBox(wrongBox.getWidth() - decreasedLength,
- wrongBox.getPosition(), false));
- // add preserved elements
- if (!preserveList.isEmpty()) {
- newList.addAll(preserveList);
- }
- // insert the correct glue
- newList.addLast(new KnuthGlue(decreasedLength, 0, 0, Adjustment.SPACE_AFTER_ADJUSTMENT,
- wrongBox.getPosition(), false));
- //log.debug(" rimosso box " + neededUnits(wrongBox.getWidth()));
- //log.debug(" aggiunto box " + neededUnits(
- // wrongBox.getWidth() - decreasedLength));
- //log.debug(" aggiunto glue " + neededUnits(decreasedLength) + " 0 0");
- }
-
- return newList;
}
/** A stack iterator. */
@@ -1731,8 +1251,8 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
/** A mapping position. */
protected static class MappingPosition extends Position {
- private int iFirstIndex;
- private int iLastIndex;
+ private int firstIndex;
+ private int lastIndex;
/**
* Construct mapping position.
@@ -1742,18 +1262,18 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
*/
public MappingPosition(LayoutManager lm, int first, int last) {
super(lm);
- iFirstIndex = first;
- iLastIndex = last;
+ firstIndex = first;
+ lastIndex = last;
}
/** @return first index */
public int getFirstIndex() {
- return iFirstIndex;
+ return firstIndex;
}
/** @return last index */
public int getLastIndex() {
- return iLastIndex;
+ return lastIndex;
}
}
@@ -1817,6 +1337,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
* Returns the IPD of the content area
* @return the IPD of the content area
*/
+ @Override
public int getContentAreaIPD() {
return contentAreaIPD;
}
@@ -1833,11 +1354,13 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
* Returns the BPD of the content area
* @return the BPD of the content area
*/
+ @Override
public int getContentAreaBPD() {
return -1;
}
/** {@inheritDoc} */
+ @Override
public void reset() {
super.reset();
breakBeforeServed = false;
--
cgit v1.2.3
From e8279d632fdf524b7e098113de93fce005bf65b2 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sun, 6 Feb 2011 00:56:28 +0000
Subject: Add type safety to LMiter
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067558 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/layoutmgr/LMiter.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/java/org/apache/fop/layoutmgr/LMiter.java b/src/java/org/apache/fop/layoutmgr/LMiter.java
index 9f437df6a..d3ad30485 100644
--- a/src/java/org/apache/fop/layoutmgr/LMiter.java
+++ b/src/java/org/apache/fop/layoutmgr/LMiter.java
@@ -24,10 +24,10 @@ import java.util.ListIterator;
import java.util.NoSuchElementException;
/** An iterator for layout managers. */
-public class LMiter implements ListIterator {
+public class LMiter implements ListIterator {
/** list of layout managers */
- protected List listLMs;
+ protected List listLMs;
/** current position in iteration */
protected int curPos = 0;
/** The LayoutManager to which this LMiter is attached **/
@@ -44,7 +44,7 @@ public class LMiter implements ListIterator {
/** {@inheritDoc} */
public boolean hasNext() {
- return (curPos < listLMs.size()) ? true : lp.createNextChildLMs(curPos);
+ return (curPos < listLMs.size()) || lp.createNextChildLMs(curPos);
}
/** {@inheritDoc} */
@@ -53,7 +53,7 @@ public class LMiter implements ListIterator {
}
/** {@inheritDoc} */
- public Object previous() throws NoSuchElementException {
+ public LayoutManager previous() throws NoSuchElementException {
if (curPos > 0) {
return listLMs.get(--curPos);
} else {
@@ -62,7 +62,7 @@ public class LMiter implements ListIterator {
}
/** {@inheritDoc} */
- public Object next() throws NoSuchElementException {
+ public LayoutManager next() throws NoSuchElementException {
if (curPos < listLMs.size()) {
return listLMs.get(curPos++);
} else {
@@ -82,12 +82,12 @@ public class LMiter implements ListIterator {
/** {@inheritDoc} */
- public void add(Object o) throws UnsupportedOperationException {
+ public void add(LayoutManager lm) throws UnsupportedOperationException {
throw new UnsupportedOperationException("LMiter doesn't support add");
}
/** {@inheritDoc} */
- public void set(Object o) throws UnsupportedOperationException {
+ public void set(LayoutManager lm) throws UnsupportedOperationException {
throw new UnsupportedOperationException("LMiter doesn't support set");
}
--
cgit v1.2.3
From 70dcfa240017129c7a296ceb653fd2074d25ee64 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sun, 6 Feb 2011 01:00:28 +0000
Subject: Code cleanup
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067559 13f79535-47bb-0310-9956-ffa450edef68
---
.../apache/fop/layoutmgr/BlockLayoutManager.java | 186 +++++----------------
1 file changed, 46 insertions(+), 140 deletions(-)
diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
index 62e89bdb0..fdb0e5347 100644
--- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
@@ -46,15 +46,13 @@ import org.apache.fop.traits.SpaceVal;
public class BlockLayoutManager extends BlockStackingLayoutManager
implements ConditionalElementListener {
- /**
- * logging instance
- */
+ /** logging instance */
private static Log log = LogFactory.getLog(BlockLayoutManager.class);
private Block curBlockArea;
/** Iterator over the child layout managers. */
- protected ListIterator proxyLMiter;
+ protected ListIterator proxyLMiter;
private int lead = 12000;
private Length lineHeight;
@@ -78,44 +76,37 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
}
/** {@inheritDoc} */
+ @Override
public void initialize() {
super.initialize();
- FontInfo fi = getBlockFO().getFOEventHandler().getFontInfo();
- FontTriplet[] fontkeys = getBlockFO().getCommonFont().getFontState(fi);
+ org.apache.fop.fo.flow.Block fo = getBlockFO();
+ FontInfo fi = fo.getFOEventHandler().getFontInfo();
+ FontTriplet[] fontkeys = fo.getCommonFont().getFontState(fi);
Font initFont = fi.getFontInstance(fontkeys[0],
getBlockFO().getCommonFont().fontSize.getValue(this));
lead = initFont.getAscender();
follow = -initFont.getDescender();
//middleShift = -fs.getXHeight() / 2;
- lineHeight = getBlockFO().getLineHeight().getOptimum(this).getLength();
- startIndent = getBlockFO().getCommonMarginBlock().startIndent.getValue(this);
- endIndent = getBlockFO().getCommonMarginBlock().endIndent.getValue(this);
- foSpaceBefore = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceBefore, this)
- .getSpace();
- foSpaceAfter = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceAfter, this)
- .getSpace();
- bpUnit = 0; // non-standard extension
- if (bpUnit == 0) {
- // use optimum space values
- adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace()
- .getOptimum(this).getLength().getValue(this);
- adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace()
- .getOptimum(this).getLength().getValue(this);
- } else {
- // use minimum space values
- adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace()
- .getMinimum(this).getLength().getValue(this);
- adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace()
- .getMinimum(this).getLength().getValue(this);
- }
+ lineHeight = fo.getLineHeight().getOptimum(this).getLength();
+ startIndent = fo.getCommonMarginBlock().startIndent.getValue(this);
+ endIndent = fo.getCommonMarginBlock().endIndent.getValue(this);
+ foSpaceBefore = new SpaceVal(fo.getCommonMarginBlock().spaceBefore, this).getSpace();
+ foSpaceAfter = new SpaceVal(fo.getCommonMarginBlock().spaceAfter, this).getSpace();
+ // use optimum space values
+ adjustedSpaceBefore = fo.getCommonMarginBlock().spaceBefore.getSpace()
+ .getOptimum(this).getLength().getValue(this);
+ adjustedSpaceAfter = fo.getCommonMarginBlock().spaceAfter.getSpace()
+ .getOptimum(this).getLength().getValue(this);
}
/** {@inheritDoc} */
+ @Override
public List getNextKnuthElements(LayoutContext context, int alignment) {
return getNextKnuthElements(context, alignment, null, null, null);
}
/** {@inheritDoc} */
+ @Override
public List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack,
Position restartPosition, LayoutManager restartAtLM) {
resetSpaces();
@@ -151,7 +142,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
*/
public ProxyLMiter() {
super(BlockLayoutManager.this);
- listLMs = new java.util.ArrayList(10);
+ listLMs = new java.util.ArrayList(10);
}
/**
@@ -166,7 +157,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
* @return true if new child lms were added
*/
protected boolean createNextChildLMs(int pos) {
- List newLMs = createChildLMs(pos + 1 - listLMs.size());
+ List newLMs = createChildLMs(pos + 1 - listLMs.size());
if (newLMs != null) {
listLMs.addAll(newLMs);
}
@@ -174,13 +165,12 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public boolean createNextChildLMs(int pos) {
while (proxyLMiter.hasNext()) {
- LayoutManager lm = (LayoutManager) proxyLMiter.next();
+ LayoutManager lm = proxyLMiter.next();
if (lm instanceof InlineLevelLayoutManager) {
LineLayoutManager lineLM = createLineManager(lm);
addChildLM(lineLM);
@@ -203,10 +193,10 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
private LineLayoutManager createLineManager(LayoutManager firstlm) {
LineLayoutManager llm;
llm = new LineLayoutManager(getBlockFO(), lineHeight, lead, follow);
- List inlines = new java.util.ArrayList();
+ List inlines = new java.util.ArrayList();
inlines.add(firstlm);
while (proxyLMiter.hasNext()) {
- LayoutManager lm = (LayoutManager) proxyLMiter.next();
+ LayoutManager lm = proxyLMiter.next();
if (lm instanceof InlineLevelLayoutManager) {
inlines.add(lm);
} else {
@@ -219,23 +209,26 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepTogetherProperty() {
return getBlockFO().getKeepTogether();
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepWithPreviousProperty() {
return getBlockFO().getKeepWithPrevious();
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepWithNextProperty() {
return getBlockFO().getKeepWithNext();
}
/** {@inheritDoc} */
- public void addAreas // CSOK: MethodLength
- (PositionIterator parentIter, LayoutContext layoutContext) {
+ @Override
+ public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
getParentArea(null);
// if this will create the first block area in a page
@@ -256,14 +249,12 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
// "unwrap" the NonLeafPositions stored in parentIter
// and put them in a new list;
- LinkedList positionList = new LinkedList();
+ LinkedList positionList = new LinkedList();
Position pos;
- boolean spaceBefore = false;
- boolean spaceAfter = false;
Position firstPos = null;
Position lastPos = null;
while (parentIter.hasNext()) {
- pos = (Position) parentIter.next();
+ pos = parentIter.next();
//log.trace("pos = " + pos.getClass().getName() + "; " + pos);
if (pos.getIndex() >= 0) {
if (firstPos == null) {
@@ -276,30 +267,11 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
//Not all elements are wrapped
innerPosition = pos.getPosition();
}
- if (innerPosition == null) {
- // pos was created by this BlockLM and was inside an element
- // representing space before or after
- // this means the space was not discarded
- if (positionList.size() == 0) {
- // pos was in the element representing space-before
- spaceBefore = true;
- //log.trace(" space before");
- } else {
- // pos was in the element representing space-after
- spaceAfter = true;
- //log.trace(" space-after");
- }
- } else if (innerPosition.getLM() == this
- && !(innerPosition instanceof MappingPosition)) {
- // pos was created by this BlockLM and was inside a penalty
- // allowing or forbidding a page break
- // nothing to do
- //log.trace(" penalty");
- } else {
+
+ if (innerPosition != null) {
// innerPosition was created by another LM
positionList.add(innerPosition);
lastLM = innerPosition.getLM();
- //log.trace(" " + innerPosition.getClass().getName());
}
}
@@ -307,78 +279,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
addMarkersToPage(true, isFirst(firstPos), isLast(lastPos));
- if (bpUnit == 0) {
- // the Positions in positionList were inside the elements
- // created by the LineLM
- childPosIter = new StackingIter(positionList.listIterator());
- } else {
- // the Positions in positionList were inside the elements
- // created by the BlockLM in the createUnitElements() method
- //if (((Position) positionList.getLast()) instanceof
- // LeafPosition) {
- // // the last item inside positionList is a LeafPosition
- // // (a LineBreakPosition, more precisely); this means that
- // // the whole paragraph is on the same page
- // childPosIter = new KnuthPossPosIter(storedList, 0,
- // storedList.size());
- //} else {
- // // the last item inside positionList is a Position;
- // // this means that the paragraph has been split
- // // between consecutive pages
- LinkedList splitList = new LinkedList();
- int splitLength = 0;
- int iFirst = ((MappingPosition) positionList.getFirst()).getFirstIndex();
- int iLast = ((MappingPosition) positionList.getLast()).getLastIndex();
- // copy from storedList to splitList all the elements from
- // iFirst to iLast
- ListIterator storedListIterator = storedList.listIterator(iFirst);
- while (storedListIterator.nextIndex() <= iLast) {
- KnuthElement element = (KnuthElement) storedListIterator
- .next();
- // some elements in storedList (i.e. penalty items) were created
- // by this BlockLM, and must be ignored
- if (element.getLayoutManager() != this) {
- splitList.add(element);
- splitLength += element.getWidth();
- lastLM = element.getLayoutManager();
- }
- }
- //log.debug("Adding areas from " + iFirst + " to " + iLast);
- //log.debug("splitLength= " + splitLength
- // + " (" + neededUnits(splitLength) + " units') "
- // + (neededUnits(splitLength) * bpUnit - splitLength)
- // + " spacing");
- // add space before and / or after the paragraph
- // to reach a multiple of bpUnit
- if (spaceBefore && spaceAfter) {
- foSpaceBefore = new SpaceVal(getBlockFO()
- .getCommonMarginBlock().spaceBefore, this).getSpace();
- foSpaceAfter = new SpaceVal(getBlockFO()
- .getCommonMarginBlock().spaceAfter, this).getSpace();
- adjustedSpaceBefore = (neededUnits(splitLength
- + foSpaceBefore.getMin()
- + foSpaceAfter.getMin())
- * bpUnit - splitLength) / 2;
- adjustedSpaceAfter = neededUnits(splitLength
- + foSpaceBefore.getMin()
- + foSpaceAfter.getMin())
- * bpUnit - splitLength - adjustedSpaceBefore;
- } else if (spaceBefore) {
- adjustedSpaceBefore = neededUnits(splitLength
- + foSpaceBefore.getMin())
- * bpUnit - splitLength;
- } else {
- adjustedSpaceAfter = neededUnits(splitLength
- + foSpaceAfter.getMin())
- * bpUnit - splitLength;
- }
- //log.debug("spazio prima = " + adjustedSpaceBefore
- // + " spazio dopo = " + adjustedSpaceAfter + " totale = " +
- // (adjustedSpaceBefore + adjustedSpaceAfter + splitLength));
- childPosIter = new KnuthPossPosIter(splitList, 0, splitList
- .size());
- //}
- }
+ // the Positions in positionList were inside the elements
+ // created by the LineLM
+ childPosIter = new StackingIter(positionList.listIterator());
while ((childLM = childPosIter.getNextChildLM()) != null) {
// set last area flag
@@ -415,6 +318,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
* @param childArea area to get the parent area for
* @return the parent area
*/
+ @Override
public Area getParentArea(Area childArea) {
if (curBlockArea == null) {
curBlockArea = new Block();
@@ -446,9 +350,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
return curBlockArea;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public void addChildArea(Area childArea) {
if (curBlockArea != null) {
if (childArea instanceof LineArea) {
@@ -463,6 +366,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
* Force current area to be added to parent area.
* {@inheritDoc}
*/
+ @Override
protected void flush() {
if (curBlockArea != null) {
TraitSetter.addBackground(curBlockArea,
@@ -486,6 +390,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
* Returns the IPD of the content area
* @return the IPD of the content area
*/
+ @Override
public int getContentAreaIPD() {
if (curBlockArea != null) {
return curBlockArea.getIPD();
@@ -498,6 +403,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
* Returns the BPD of the content area
* @return the BPD of the content area
*/
+ @Override
public int getContentAreaBPD() {
if (curBlockArea != null) {
return curBlockArea.getBPD();
@@ -505,9 +411,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
return -1;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public boolean getGeneratesBlockArea() {
return true;
}
@@ -558,6 +463,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
}
/** {@inheritDoc} */
+ @Override
public boolean isRestartable() {
return true;
}
--
cgit v1.2.3
From 8dd910c9acc446dc2560ab66e80f7f8c67347577 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sun, 6 Feb 2011 01:15:39 +0000
Subject: Restored part that would otherwise cause a StackOverflowError...
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067565 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
index fdb0e5347..bfcc44b3c 100644
--- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
@@ -268,7 +268,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
innerPosition = pos.getPosition();
}
- if (innerPosition != null) {
+ if (innerPosition != null
+ && (innerPosition.getLM() != this
+ || innerPosition instanceof MappingPosition)) {
// innerPosition was created by another LM
positionList.add(innerPosition);
lastLM = innerPosition.getLM();
--
cgit v1.2.3
From d2d04b82a13aa73cd13c06ddc8f16b00de2b7c18 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sun, 6 Feb 2011 01:17:57 +0000
Subject: Further cleanup: reduce some code duplication in BlockStackingLM's
getNextKnuthElements() variants
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067567 13f79535-47bb-0310-9956-ffa450edef68
---
.../apache/fop/layoutmgr/BlockLayoutManager.java | 8 +-
.../fop/layoutmgr/BlockStackingLayoutManager.java | 208 +++++----------------
2 files changed, 51 insertions(+), 165 deletions(-)
diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
index bfcc44b3c..a7361ae31 100644
--- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
@@ -110,12 +110,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
public List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack,
Position restartPosition, LayoutManager restartAtLM) {
resetSpaces();
- if (lmStack == null) {
- return super.getNextKnuthElements(context, alignment);
- } else {
- return super.getNextKnuthElements(context, alignment, lmStack, restartPosition,
- restartAtLM);
- }
+ return super.getNextKnuthElements(
+ context, alignment, lmStack, restartPosition, restartAtLM);
}
private void resetSpaces() {
diff --git a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
index 4f0ab9ddb..ee43be6fa 100644
--- a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
@@ -238,6 +238,14 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
/** {@inheritDoc} */
@Override
public List getNextKnuthElements(LayoutContext context, int alignment) {
+ return getNextKnuthElements(context, alignment, null, null, null);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public List getNextKnuthElements // CSOK: MethodLength
+ (LayoutContext context, int alignment, Stack lmStack,
+ Position restartPosition, LayoutManager restartAtLM) {
referenceIPD = context.getRefIPD();
updateContentAreaIPDwithOverconstrainedAdjust();
@@ -267,33 +275,41 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
//Used to indicate a special break-after case when all content has already been generated.
BreakElement forcedBreakAfterLast = null;
+ LayoutContext childLC = new LayoutContext(0);
+ List childElements;
LayoutManager currentChildLM;
- while ((currentChildLM = getChildLM()) != null) {
- LayoutContext childLC = new LayoutContext(0);
-
- List childrenElements
- = getNextChildElements(currentChildLM, context, childLC, alignment);
-
+ if (lmStack != null) {
+ if (lmStack.isEmpty()) {
+ assert restartAtLM != null && restartAtLM.getParent() == this;
+ currentChildLM = restartAtLM;
+ currentChildLM.reset();
+ setCurrentChildLM(currentChildLM);
+ childElements = getNextChildElements(currentChildLM, context, childLC, alignment);
+ } else {
+ currentChildLM = (LayoutManager) lmStack.pop();
+ setCurrentChildLM(currentChildLM);
+ childElements = getNextChildElements(currentChildLM, context, childLC, alignment,
+ lmStack, restartPosition, restartAtLM);
+ }
if (contentList.isEmpty()) {
//Propagate keep-with-previous up from the first child
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
}
- if (childrenElements != null && !childrenElements.isEmpty()) {
+ if (childElements != null && !childElements.isEmpty()) {
if (!contentList.isEmpty()
- && !ElementListUtils.startsWithForcedBreak(childrenElements)) {
+ && !ElementListUtils.startsWithForcedBreak(childElements)) {
// there is a block handled by prevLM before the one
// handled by curLM, and the one handled
// by the current LM does not begin with a break
addInBetweenBreak(contentList, context, childLC);
}
- if (childrenElements.size() == 1
- && ElementListUtils.startsWithForcedBreak(childrenElements)) {
+ if (childElements.size() == 1
+ && ElementListUtils.startsWithForcedBreak(childElements)) {
if (currentChildLM.isFinished() && !hasNextChildLM()) {
// a descendant of this block has break-before
- forcedBreakAfterLast = (BreakElement) childrenElements.get(0);
+ forcedBreakAfterLast = (BreakElement) childElements.get(0);
context.clearPendingMarks();
- break;
}
if (contentList.isEmpty()) {
@@ -302,19 +318,18 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
elements.add(makeAuxiliaryZeroWidthBox());
}
// a descendant of this block has break-before
- contentList.addAll(childrenElements);
+ contentList.addAll(childElements);
wrapPositionElements(contentList, elements);
return elements;
} else {
- contentList.addAll(childrenElements);
- if (ElementListUtils.endsWithForcedBreak(childrenElements)) {
+ contentList.addAll(childElements);
+ if (ElementListUtils.endsWithForcedBreak(childElements)) {
// a descendant of this block has break-after
if (currentChildLM.isFinished() && !hasNextChildLM()) {
forcedBreakAfterLast = (BreakElement) ListUtil.removeLast(contentList);
context.clearPendingMarks();
- break;
}
wrapPositionElements(contentList, elements);
@@ -326,160 +341,34 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
}
}
- if (!contentList.isEmpty()) {
- wrapPositionElements(contentList, elements);
- } else if (forcedBreakAfterLast == null) {
- // Empty fo:block, zero-length box makes sure the IDs and/or markers
- // are registered.
- elements.add(makeAuxiliaryZeroWidthBox());
- }
-
- addKnuthElementsForBorderPaddingAfter(elements, true);
- addKnuthElementsForSpaceAfter(elements, alignment);
-
- //All child content is processed. Only break-after can occur now, so...
- context.clearPendingMarks();
- if (forcedBreakAfterLast == null) {
- addKnuthElementsForBreakAfter(elements, context);
- } else {
- forcedBreakAfterLast.clearPendingMarks();
- elements.add(forcedBreakAfterLast);
- }
-
- context.updateKeepWithNextPending(getKeepWithNext());
-
- setFinished(true);
-
- return elements;
- }
-
- /** {@inheritDoc} */
- @Override
- public List getNextKnuthElements // CSOK: MethodLength
- (LayoutContext context, int alignment, Stack lmStack,
- Position restartPosition, LayoutManager restartAtLM) {
- referenceIPD = context.getRefIPD();
- updateContentAreaIPDwithOverconstrainedAdjust();
-
- List contentList = new LinkedList();
- List elements = new LinkedList();
-
- if (!breakBeforeServed) {
- breakBeforeServed = true;
- if (!context.suppressBreakBefore()) {
- if (addKnuthElementsForBreakBefore(elements, context)) {
- return elements;
- }
- }
- }
-
- if (!firstVisibleMarkServed) {
- addKnuthElementsForSpaceBefore(elements, alignment);
- context.updateKeepWithPreviousPending(getKeepWithPrevious());
- }
-
- addKnuthElementsForBorderPaddingBefore(elements, !firstVisibleMarkServed);
- firstVisibleMarkServed = true;
-
- //Spaces, border and padding to be repeated at each break
- addPendingMarks(context);
-
- //Used to indicate a special break-after case when all content has already been generated.
- BreakElement forcedBreakAfterLast = null;
-
- LayoutContext childLC = new LayoutContext(0);
- List childrenElements;
- LayoutManager currentChildLM;
- if (lmStack.isEmpty()) {
- assert restartAtLM != null && restartAtLM.getParent() == this;
- currentChildLM = restartAtLM;
- currentChildLM.reset();
- setCurrentChildLM(currentChildLM);
-
- childrenElements = getNextChildElements(currentChildLM, context, childLC,
- alignment);
- } else {
- currentChildLM = (LayoutManager) lmStack.pop();
- setCurrentChildLM(currentChildLM);
- childrenElements = getNextChildElements(currentChildLM, context, childLC, alignment,
- lmStack, restartPosition, restartAtLM);
- }
-
- if (contentList.isEmpty()) {
- //Propagate keep-with-previous up from the first child
- context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
- }
- if (childrenElements != null && !childrenElements.isEmpty()) {
- if (!contentList.isEmpty()
- && !ElementListUtils.startsWithForcedBreak(childrenElements)) {
- // there is a block handled by prevLM before the one
- // handled by curLM, and the one handled
- // by the current LM does not begin with a break
- addInBetweenBreak(contentList, context, childLC);
- }
- if (childrenElements.size() == 1
- && ElementListUtils.startsWithForcedBreak(childrenElements)) {
-
- if (currentChildLM.isFinished() && !hasNextChildLM()) {
- // a descendant of this block has break-before
- forcedBreakAfterLast = (BreakElement) childrenElements.get(0);
- context.clearPendingMarks();
- }
-
- if (contentList.isEmpty()) {
- // Empty fo:block, zero-length box makes sure the IDs and/or markers
- // are registered and borders/padding are painted.
- elements.add(makeAuxiliaryZeroWidthBox());
- }
- // a descendant of this block has break-before
- contentList.addAll(childrenElements);
-
- wrapPositionElements(contentList, elements);
-
- return elements;
- } else {
- contentList.addAll(childrenElements);
- if (ElementListUtils.endsWithForcedBreak(childrenElements)) {
- // a descendant of this block has break-after
- if (currentChildLM.isFinished() && !hasNextChildLM()) {
- forcedBreakAfterLast = (BreakElement) ListUtil.removeLast(contentList);
- context.clearPendingMarks();
- }
-
- wrapPositionElements(contentList, elements);
-
- return elements;
- }
- }
- context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
- }
-
while ((currentChildLM = getChildLM()) != null) {
- currentChildLM.reset(); // TODO won't work with forced breaks
+ if (lmStack != null) {
+ currentChildLM.reset(); // TODO won't work with forced breaks
+ }
childLC = new LayoutContext(0);
- childrenElements = getNextChildElements(currentChildLM, context, childLC,
+ childElements = getNextChildElements(currentChildLM, context, childLC,
alignment);
if (contentList.isEmpty()) {
//Propagate keep-with-previous up from the first child
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
}
- if (childrenElements != null && !childrenElements.isEmpty()) {
+ if (childElements != null && !childElements.isEmpty()) {
if (!contentList.isEmpty()
- && !ElementListUtils.startsWithForcedBreak(childrenElements)) {
+ && !ElementListUtils.startsWithForcedBreak(childElements)) {
// there is a block handled by prevLM before the one
// handled by curLM, and the one handled
// by the current LM does not begin with a break
addInBetweenBreak(contentList, context, childLC);
}
- if (childrenElements.size() == 1
- && ElementListUtils.startsWithForcedBreak(childrenElements)) {
+ if (childElements.size() == 1
+ && ElementListUtils.startsWithForcedBreak(childElements)) {
if (currentChildLM.isFinished() && !hasNextChildLM()) {
// a descendant of this block has break-before
- forcedBreakAfterLast = (BreakElement) childrenElements.get(0);
+ forcedBreakAfterLast = (BreakElement) childElements.get(0);
context.clearPendingMarks();
break;
}
@@ -490,14 +379,14 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
elements.add(makeAuxiliaryZeroWidthBox());
}
// a descendant of this block has break-before
- contentList.addAll(childrenElements);
+ contentList.addAll(childElements);
wrapPositionElements(contentList, elements);
return elements;
} else {
- contentList.addAll(childrenElements);
- if (ElementListUtils.endsWithForcedBreak(childrenElements)) {
+ contentList.addAll(childElements);
+ if (ElementListUtils.endsWithForcedBreak(childElements)) {
// a descendant of this block has break-after
if (currentChildLM.isFinished() && !hasNextChildLM()) {
forcedBreakAfterLast = (BreakElement) ListUtil.removeLast(contentList);
@@ -780,8 +669,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
}
// create the iterator
- List workList = oldList;
- ListIterator workListIterator = workList.listIterator();
+ ListIterator workListIterator = oldList.listIterator();
while (workListIterator.hasNext()) {
currElement = workListIterator.next();
if (prevElement != null
@@ -793,8 +681,10 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
= (BlockLevelLayoutManager)currElement.getLayoutManager();
boolean somethingAdded = false;
if (prevLM != this) {
- returnedList.addAll(prevLM.getChangedKnuthElements(workList.subList(
- fromIndex, workListIterator.previousIndex()), alignment));
+ returnedList.addAll(
+ prevLM.getChangedKnuthElements(
+ oldList.subList(fromIndex, workListIterator.previousIndex()),
+ alignment));
somethingAdded = true;
} else {
// do nothing
@@ -824,7 +714,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
LayoutManager currLM = currElement.getLayoutManager();
if (currLM != this) {
returnedList.addAll(currLM.getChangedKnuthElements(
- workList.subList(fromIndex, workList.size()), alignment));
+ oldList.subList(fromIndex, oldList.size()), alignment));
} else {
// there are no more elements to add
// remove the last penalty added to returnedList
--
cgit v1.2.3
From db0fea16dea5465d25e1e45ecdc276166f9d9c45 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sun, 6 Feb 2011 01:23:08 +0000
Subject: Code cleanup (minor)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067569 13f79535-47bb-0310-9956-ffa450edef68
---
.../fop/layoutmgr/FootnoteBodyLayoutManager.java | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java b/src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java
index 4f6cfa9d5..6c6462a3f 100644
--- a/src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java
@@ -38,31 +38,29 @@ public class FootnoteBodyLayoutManager extends BlockStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
- LayoutManager childLM = null;
+ LayoutManager childLM;
LayoutManager lastLM = null;
LayoutContext lc = new LayoutContext(0);
// "unwrap" the NonLeafPositions stored in parentIter
// and put them in a new list;
- LinkedList positionList = new LinkedList();
+ LinkedList positionList = new LinkedList();
Position pos;
while (parentIter.hasNext()) {
- pos = (Position) parentIter.next();
- //log.trace("pos = " + pos.getClass().getName() + "; " + pos);
- Position innerPosition = pos;
+ pos = parentIter.next();
+ Position innerPosition;
if (pos instanceof NonLeafPosition) {
- innerPosition = ((NonLeafPosition) pos).getPosition();
+ innerPosition = pos.getPosition();
if (innerPosition.getLM() == this) {
// pos was created by this LM and was inside a penalty
// allowing or forbidding a page break
// nothing to do
- //log.trace(" penalty");
} else {
// innerPosition was created by another LM
positionList.add(innerPosition);
lastLM = innerPosition.getLM();
- //log.trace(" " + innerPosition.getClass().getName());
}
}
}
@@ -81,6 +79,7 @@ public class FootnoteBodyLayoutManager extends BlockStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
public void addChildArea(Area childArea) {
childArea.setAreaClass(Area.CLASS_FOOTNOTE);
parentLayoutManager.addChildArea(childArea);
@@ -92,16 +91,19 @@ public class FootnoteBodyLayoutManager extends BlockStackingLayoutManager {
}
/** {@inheritDoc} */
+ @Override
public Keep getKeepTogether() {
return getParentKeepTogether();
}
/** {@inheritDoc} */
+ @Override
public Keep getKeepWithNext() {
return Keep.KEEP_AUTO;
}
/** {@inheritDoc} */
+ @Override
public Keep getKeepWithPrevious() {
return Keep.KEEP_AUTO;
}
--
cgit v1.2.3
From 2bbfc6dd682aa336d377b4ac7a8f3817093d6031 Mon Sep 17 00:00:00 2001
From: "Andreas L. Delmelle"
Date: Sun, 6 Feb 2011 12:14:27 +0000
Subject: Preceding cleanups 'fixed' behavior in test case
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067644 13f79535-47bb-0310-9956-ffa450edef68
---
.../standard-testcases/fox_disable-column-balancing.xml | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/test/layoutengine/standard-testcases/fox_disable-column-balancing.xml b/test/layoutengine/standard-testcases/fox_disable-column-balancing.xml
index ad9743ab6..c25223a47 100644
--- a/test/layoutengine/standard-testcases/fox_disable-column-balancing.xml
+++ b/test/layoutengine/standard-testcases/fox_disable-column-balancing.xml
@@ -216,11 +216,7 @@