Return-Path: X-Original-To: apmail-xmlgraphics-fop-commits-archive@www.apache.org Delivered-To: apmail-xmlgraphics-fop-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AF52D113B4 for ; Mon, 8 Sep 2014 10:04:45 +0000 (UTC) Received: (qmail 16720 invoked by uid 500); 8 Sep 2014 10:04:45 -0000 Delivered-To: apmail-xmlgraphics-fop-commits-archive@xmlgraphics.apache.org Received: (qmail 16679 invoked by uid 500); 8 Sep 2014 10:04:45 -0000 Mailing-List: contact fop-commits-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: fop-dev@xmlgraphics.apache.org Delivered-To: mailing list fop-commits@xmlgraphics.apache.org Received: (qmail 16669 invoked by uid 99); 8 Sep 2014 10:04:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Sep 2014 10:04:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Sep 2014 10:04:43 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8053D23888E2; Mon, 8 Sep 2014 10:04:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1623347 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop: area/inline/ complexscripts/bidi/ fo/ fo/flow/ layoutmgr/inline/ Date: Mon, 08 Sep 2014 10:04:23 -0000 To: fop-commits@xmlgraphics.apache.org From: gadams@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140908100423.8053D23888E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gadams Date: Mon Sep 8 10:04:22 2014 New Revision: 1623347 URL: http://svn.apache.org/r1623347 Log: FOP-2410: fix fo:page-number in bidi context Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/ResolvedPageNumber.java (with props) xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/StringCharIterator.java (with props) Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/bidi/TextInterval.java xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/bidi/UnflattenProcessor.java xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/PageNumber.java xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java?rev=1623347&r1=1623346&r2=1623347&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java Mon Sep 8 10:04:22 2014 @@ -260,8 +260,10 @@ public class InlineArea extends Area { + ": increase by " + ipdVariation + " mpt."); } - increaseIPD(ipdVariation); - notifyIPDVariation(ipdVariation); + if (ipdVariation != 0) { + increaseIPD(ipdVariation); + notifyIPDVariation(ipdVariation); + } } /** Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/ResolvedPageNumber.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/ResolvedPageNumber.java?rev=1623347&view=auto ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/ResolvedPageNumber.java (added) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/ResolvedPageNumber.java Mon Sep 8 10:04:22 2014 @@ -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(); + } + +} Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/ResolvedPageNumber.java ------------------------------------------------------------------------------ svn:eol-style = LF Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/bidi/TextInterval.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/bidi/TextInterval.java?rev=1623347&r1=1623346&r2=1623347&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/bidi/TextInterval.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/bidi/TextInterval.java Mon Sep 8 10:04:22 2014 @@ -26,6 +26,7 @@ import org.apache.fop.fo.flow.AbstractPa 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 = '?'; } Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/bidi/UnflattenProcessor.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/bidi/UnflattenProcessor.java?rev=1623347&r1=1623346&r2=1623347&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/bidi/UnflattenProcessor.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/bidi/UnflattenProcessor.java Mon Sep 8 10:04:22 2014 @@ -31,6 +31,7 @@ import org.apache.fop.area.inline.BasicL 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) { Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/StringCharIterator.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/StringCharIterator.java?rev=1623347&view=auto ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/StringCharIterator.java (added) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/StringCharIterator.java Mon Sep 8 10:04:22 2014 @@ -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(); + } + } + +} + Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/StringCharIterator.java ------------------------------------------------------------------------------ svn:eol-style = LF Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java?rev=1623347&r1=1623346&r2=1623347&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java Mon Sep 8 10:04:22 2014 @@ -41,7 +41,6 @@ import org.apache.fop.fo.properties.Comm 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 @@ -209,7 +208,7 @@ public abstract class AbstractPageNumber protected Stack collectDelimitedTextRanges(Stack ranges, DelimitedTextRange currentRange) { if (currentRange != null) { - currentRange.append(CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this); + currentRange.append('1', this); } return ranges; } Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/PageNumber.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/PageNumber.java?rev=1623347&r1=1623346&r2=1623347&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/PageNumber.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/PageNumber.java Mon Sep 8 10:04:22 2014 @@ -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 collectDelimitedTextRanges(Stack 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"; + } + } Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java?rev=1623347&r1=1623346&r2=1623347&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java Mon Sep 8 10:04:22 2014 @@ -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 ext setCommonBorderPaddingBackground(fobj.getCommonBorderPaddingBackground()); } - /** - * {@inheritDoc} - * #makeAlignmentContext(LayoutContext) - */ + /** {@inheritDoc} */ protected AlignmentContext makeAlignmentContext(LayoutContext context) { return new AlignmentContext( font @@ -76,49 +73,50 @@ public class PageNumberLayoutManager ext /** {@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 ext return width; } + protected int getBidiLevel() { + return fobj.getBidiLevel(); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org