aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGlenn Adams <gadams@apache.org>2014-09-08 10:04:22 +0000
committerGlenn Adams <gadams@apache.org>2014-09-08 10:04:22 +0000
commit812ae2c1bcacdcb702b0ff8b9dd8ae171e865959 (patch)
tree7eba9358f23fdb1d27459c2f646a4fc4f7357fec /src
parentaa1367a401b7bad197fe3e6f4870bf4ef0c478da (diff)
downloadxmlgraphics-fop-812ae2c1bcacdcb702b0ff8b9dd8ae171e865959.tar.gz
xmlgraphics-fop-812ae2c1bcacdcb702b0ff8b9dd8ae171e865959.zip
FOP-2410: fix fo:page-number in bidi context
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1623347 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/area/inline/InlineArea.java6
-rw-r--r--src/java/org/apache/fop/area/inline/ResolvedPageNumber.java37
-rw-r--r--src/java/org/apache/fop/complexscripts/bidi/TextInterval.java5
-rw-r--r--src/java/org/apache/fop/complexscripts/bidi/UnflattenProcessor.java5
-rw-r--r--src/java/org/apache/fop/fo/StringCharIterator.java64
-rw-r--r--src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java3
-rw-r--r--src/java/org/apache/fop/fo/flow/PageNumber.java24
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java68
8 files changed, 174 insertions, 38 deletions
diff --git a/src/java/org/apache/fop/area/inline/InlineArea.java b/src/java/org/apache/fop/area/inline/InlineArea.java
index 945d1ff4e..e85d779fe 100644
--- a/src/java/org/apache/fop/area/inline/InlineArea.java
+++ b/src/java/org/apache/fop/area/inline/InlineArea.java
@@ -260,8 +260,10 @@ public class InlineArea extends Area {
+ ": increase by " + ipdVariation + " mpt.");
}
- increaseIPD(ipdVariation);
- notifyIPDVariation(ipdVariation);
+ if (ipdVariation != 0) {
+ increaseIPD(ipdVariation);
+ notifyIPDVariation(ipdVariation);
+ }
}
/**
diff --git a/src/java/org/apache/fop/area/inline/ResolvedPageNumber.java b/src/java/org/apache/fop/area/inline/ResolvedPageNumber.java
new file mode 100644
index 000000000..cbef88b7e
--- /dev/null
+++ b/src/java/org/apache/fop/area/inline/ResolvedPageNumber.java
@@ -0,0 +1,37 @@
+/*
+ * 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.area.inline;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+/**
+ * Always (pre-) resolved page number area. Needed by BIDI code to distinguish
+ * from UnresolvedPageNumber.
+ */
+public class ResolvedPageNumber extends TextArea {
+
+ private static final long serialVersionUID = -1758369835371647979L;
+
+ private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+ }
+
+}
diff --git a/src/java/org/apache/fop/complexscripts/bidi/TextInterval.java b/src/java/org/apache/fop/complexscripts/bidi/TextInterval.java
index e1a42a473..8a1cbe8bd 100644
--- a/src/java/org/apache/fop/complexscripts/bidi/TextInterval.java
+++ b/src/java/org/apache/fop/complexscripts/bidi/TextInterval.java
@@ -26,6 +26,7 @@ import org.apache.fop.fo.flow.AbstractPageNumberCitation;
import org.apache.fop.fo.flow.BidiOverride;
import org.apache.fop.fo.flow.Character;
import org.apache.fop.fo.flow.Leader;
+import org.apache.fop.fo.flow.PageNumber;
// CSOFF: LineLengthCheck
@@ -92,6 +93,8 @@ class TextInterval {
((AbstractGraphics) fn) .setBidiLevel(level);
} else if (fn instanceof Leader) {
((Leader) fn) .setBidiLevel(level);
+ } else if (fn instanceof PageNumber) {
+ ((PageNumber) fn) .setBidiLevel(level);
}
}
public boolean equals(Object o) {
@@ -129,6 +132,8 @@ class TextInterval {
c = 'G';
} else if (fn instanceof Leader) {
c = 'L';
+ } else if (fn instanceof PageNumber) {
+ c = '#';
} else {
c = '?';
}
diff --git a/src/java/org/apache/fop/complexscripts/bidi/UnflattenProcessor.java b/src/java/org/apache/fop/complexscripts/bidi/UnflattenProcessor.java
index c511dbd70..456aa52ad 100644
--- a/src/java/org/apache/fop/complexscripts/bidi/UnflattenProcessor.java
+++ b/src/java/org/apache/fop/complexscripts/bidi/UnflattenProcessor.java
@@ -31,6 +31,7 @@ import org.apache.fop.area.inline.BasicLinkArea;
import org.apache.fop.area.inline.FilledArea;
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.inline.ResolvedPageNumber;
import org.apache.fop.area.inline.SpaceArea;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.UnresolvedPageNumber;
@@ -214,7 +215,9 @@ class UnflattenProcessor {
}
}
private void pushTextContainer(TextArea tc, InlineArea ia) {
- if (tc instanceof UnresolvedPageNumber) {
+ if (tc instanceof ResolvedPageNumber) {
+ tcNew = tc;
+ } else if (tc instanceof UnresolvedPageNumber) {
tcNew = tc;
} else {
if (tcNew == null) {
diff --git a/src/java/org/apache/fop/fo/StringCharIterator.java b/src/java/org/apache/fop/fo/StringCharIterator.java
new file mode 100644
index 000000000..f3490052b
--- /dev/null
+++ b/src/java/org/apache/fop/fo/StringCharIterator.java
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Class providing an (FO flavored) char iterator for a string.
+ */
+public class StringCharIterator extends CharIterator {
+
+ private int index;
+ private String str;
+
+ /**
+ * Constructor
+ * @param c the character that this iterator should iterate.
+ */
+ public StringCharIterator(String s) {
+ this.index = -1;
+ this.str = s;
+ }
+
+ /**
+ * @return true if there is another element in the collection over which to
+ * iterate (since this iterator only handles one character, this will return
+ * false if it is past that character).
+ */
+ public boolean hasNext() {
+ return (index + 1) < str.length();
+ }
+
+ /**
+ * @return the next character, if there is one (since there is only one
+ * character over which to iterate, it must be the first character).
+ * @throws NoSuchElementException if past the first character
+ */
+ public char nextChar() throws NoSuchElementException {
+ if ((index + 1) < str.length()) {
+ return str.charAt(++index);
+ } else {
+ throw new NoSuchElementException();
+ }
+ }
+
+}
+
diff --git a/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java b/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java
index f32ca5abd..60deaebec 100644
--- a/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java
+++ b/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java
@@ -41,7 +41,6 @@ import org.apache.fop.fo.properties.CommonFont;
import org.apache.fop.fo.properties.CommonTextDecoration;
import org.apache.fop.fo.properties.SpaceProperty;
import org.apache.fop.fo.properties.StructureTreeElementHolder;
-import org.apache.fop.util.CharUtilities;
/**
* Common base class for the <a href="http://www.w3.org/TR/xsl/#fo_page-number-citation">
@@ -209,7 +208,7 @@ public abstract class AbstractPageNumberCitation extends FObj
protected Stack<DelimitedTextRange> collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges,
DelimitedTextRange currentRange) {
if (currentRange != null) {
- currentRange.append(CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this);
+ currentRange.append('1', this);
}
return ranges;
}
diff --git a/src/java/org/apache/fop/fo/flow/PageNumber.java b/src/java/org/apache/fop/fo/flow/PageNumber.java
index 8fac84bca..42a4bd8ed 100644
--- a/src/java/org/apache/fop/fo/flow/PageNumber.java
+++ b/src/java/org/apache/fop/fo/flow/PageNumber.java
@@ -20,17 +20,21 @@
package org.apache.fop.fo.flow;
import java.awt.Color;
+import java.util.Stack;
import org.xml.sax.Locator;
import org.apache.fop.accessibility.StructureTreeElement;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.complexscripts.bidi.DelimitedTextRange;
import org.apache.fop.datatypes.Length;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.StringCharIterator;
import org.apache.fop.fo.ValidationException;
+import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.properties.CommonAccessibility;
import org.apache.fop.fo.properties.CommonAccessibilityHolder;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
@@ -205,4 +209,24 @@ public class PageNumber extends FObj
return false;
}
+ @Override
+ protected Stack<DelimitedTextRange> collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges,
+ DelimitedTextRange currentRange) {
+ if (currentRange != null) {
+ currentRange.append(new StringCharIterator(defaultPageNumberString()), this);
+ }
+ return ranges;
+ }
+
+ private String defaultPageNumberString() {
+ if (findAncestor(FO_PAGE_SEQUENCE) > 0) {
+ for (FONode p = getParent(); p != null; p = p.getParent()) {
+ if (p instanceof PageSequence) {
+ return ((PageSequence)p).makeFormattedPageNumber(1);
+ }
+ }
+ }
+ return "1";
+ }
+
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java
index 82e53666c..7881283c0 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java
@@ -21,7 +21,7 @@ package org.apache.fop.layoutmgr.inline;
import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.InlineArea;
-import org.apache.fop.area.inline.TextArea;
+import org.apache.fop.area.inline.ResolvedPageNumber;
import org.apache.fop.fo.flow.PageNumber;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
@@ -57,10 +57,7 @@ public class PageNumberLayoutManager extends LeafNodeLayoutManager {
setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground());
}
- /**
- * {@inheritDoc}
- * #makeAlignmentContext(LayoutContext)
- */
+ /** {@inheritDoc} */
protected AlignmentContext makeAlignmentContext(LayoutContext context) {
return new AlignmentContext(
font
@@ -76,49 +73,50 @@ public class PageNumberLayoutManager extends LeafNodeLayoutManager {
/** {@inheritDoc} */
public InlineArea get(LayoutContext context) {
// get page string from parent, build area
- TextArea text = new TextArea();
+ ResolvedPageNumber pn = new ResolvedPageNumber();
String str = getCurrentPV().getPageNumberString();
int width = getStringWidth(str);
- text.addWord(str, 0);
- text.setIPD(width);
- text.setBPD(font.getAscender() - font.getDescender());
- text.setBaselineOffset(font.getAscender());
- TraitSetter.addFontTraits(text, font);
- text.addTrait(Trait.COLOR, fobj.getColor());
- TraitSetter.addTextDecoration(text, fobj.getTextDecoration());
-
- return text;
+ int level = getBidiLevel();
+ pn.addWord(str, 0, level);
+ pn.setBidiLevel(level);
+ pn.setIPD(width);
+ pn.setBPD(font.getAscender() - font.getDescender());
+ pn.setBaselineOffset(font.getAscender());
+ TraitSetter.addFontTraits(pn, font);
+ pn.addTrait(Trait.COLOR, fobj.getColor());
+ TraitSetter.addTextDecoration(pn, fobj.getTextDecoration());
+ return pn;
}
/** {@inheritDoc} */
protected InlineArea getEffectiveArea(LayoutContext layoutContext) {
- TextArea baseArea = (TextArea)curArea;
+ ResolvedPageNumber baseArea = (ResolvedPageNumber)curArea;
//TODO Maybe replace that with a clone() call or better, a copy constructor
//TODO or even better: delay area creation until addAreas() stage
- //TextArea is cloned because the LM is reused in static areas and the area can't be.
- TextArea ta = new TextArea();
- TraitSetter.setProducerID(ta, fobj.getId());
- ta.setIPD(baseArea.getIPD());
- ta.setBPD(baseArea.getBPD());
- ta.setBlockProgressionOffset(baseArea.getBlockProgressionOffset());
- ta.setBaselineOffset(baseArea.getBaselineOffset());
- ta.addTrait(Trait.COLOR, fobj.getColor()); //only to initialize the trait map
- ta.getTraits().putAll(baseArea.getTraits());
+ //ResolvedPageNumber is cloned because the LM is reused in static areas and the area can't be.
+ ResolvedPageNumber pn = new ResolvedPageNumber();
+ TraitSetter.setProducerID(pn, fobj.getId());
+ pn.setIPD(baseArea.getIPD());
+ pn.setBPD(baseArea.getBPD());
+ pn.setBlockProgressionOffset(baseArea.getBlockProgressionOffset());
+ pn.setBaselineOffset(baseArea.getBaselineOffset());
+ pn.addTrait(Trait.COLOR, fobj.getColor()); //only to initialize the trait map
+ pn.getTraits().putAll(baseArea.getTraits());
if (!layoutContext.treatAsArtifact()) {
- TraitSetter.addStructureTreeElement(ta, fobj.getStructureTreeElement());
+ TraitSetter.addStructureTreeElement(pn, fobj.getStructureTreeElement());
}
- updateContent(ta);
- return ta;
+ updateContent(pn);
+ return pn;
}
- private void updateContent(TextArea area) {
+ private void updateContent(ResolvedPageNumber pn) {
// get the page number of the page actually being built
- area.removeText();
- area.addWord(getCurrentPV().getPageNumberString(), 0);
+ pn.removeText();
+ pn.addWord(getCurrentPV().getPageNumberString(), 0, getBidiLevel());
// update the ipd of the area
- area.handleIPDVariation(getStringWidth(area.getText()) - area.getIPD());
+ pn.handleIPDVariation(getStringWidth(pn.getText()) - pn.getIPD());
// update the width stored in the AreaInfo object
- areaInfo.ipdArea = MinOptMax.getInstance(area.getIPD());
+ areaInfo.ipdArea = MinOptMax.getInstance(pn.getIPD());
}
/**
@@ -133,5 +131,9 @@ public class PageNumberLayoutManager extends LeafNodeLayoutManager {
return width;
}
+ protected int getBidiLevel() {
+ return fobj.getBidiLevel();
+ }
+
}