From 4d444be7c1175608f9a0f6207744459a41e00780 Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Wed, 11 Oct 2006 14:19:28 +0000 Subject: [PATCH] FilledArea now properly applies the variation factor, when a page number citation is resolved. It (and each InlineArea) may have an adjustingInfo object for that purpose. Adapted leader_toc testcase to the new, correct, results; removed page-number-citation_forward-ref testcase because it duplicates the leader_toc testcase. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@462812 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/area/inline/AbstractTextArea.java | 22 ++++----- .../apache/fop/area/inline/FilledArea.java | 15 +++++- .../apache/fop/area/inline/InlineArea.java | 49 ++++++++++++++++++- .../layoutmgr/inline/LeaderLayoutManager.java | 1 + .../inline/LeafNodeLayoutManager.java | 1 + test/layoutengine/disabled-testcases.xml | 5 -- .../standard-testcases/leader_toc.xml | 17 ++++--- .../page-number-citation_forward-ref.xml | 47 ------------------ 8 files changed, 84 insertions(+), 73 deletions(-) delete mode 100644 test/layoutengine/standard-testcases/page-number-citation_forward-ref.xml diff --git a/src/java/org/apache/fop/area/inline/AbstractTextArea.java b/src/java/org/apache/fop/area/inline/AbstractTextArea.java index 6f56a955b..3f0376310 100644 --- a/src/java/org/apache/fop/area/inline/AbstractTextArea.java +++ b/src/java/org/apache/fop/area/inline/AbstractTextArea.java @@ -51,7 +51,7 @@ public abstract class AbstractTextArea extends InlineParent { private int textWordSpaceAdjust = 0; private int textLetterSpaceAdjust = 0; - private TextAdjustingInfo adjustingInfo = null; + private TextAdjustingInfo textAdjustingInfo = null; private int baselineOffset = 0; /** @@ -68,7 +68,7 @@ public abstract class AbstractTextArea extends InlineParent { * @param adj the current adjustment of the area */ public AbstractTextArea(int stretch, int shrink, int adj) { - adjustingInfo = new TextAdjustingInfo(stretch, shrink, adj); + textAdjustingInfo = new TextAdjustingInfo(stretch, shrink, adj); } /** @@ -115,7 +115,7 @@ public abstract class AbstractTextArea extends InlineParent { * @param spaceDiff the space difference */ public void setSpaceDifference(int spaceDiff) { - adjustingInfo.spaceDifference = spaceDiff; + textAdjustingInfo.spaceDifference = spaceDiff; } /** @@ -127,7 +127,7 @@ public abstract class AbstractTextArea extends InlineParent { */ public boolean applyVariationFactor(double variationFactor, int lineStretch, int lineShrink) { - if (adjustingInfo != null) { + if (textAdjustingInfo != null) { // compute the new adjustments: // if the variation factor is negative, it means that before // the ipd variation the line had to stretch and now it has @@ -140,23 +140,23 @@ public abstract class AbstractTextArea extends InlineParent { if (textWordSpaceAdjust < 0) { // from a negative adjustment to a positive one balancingFactor - = ((double) adjustingInfo.availableStretch / adjustingInfo.availableShrink) + = ((double) textAdjustingInfo.availableStretch / textAdjustingInfo.availableShrink) * ((double) lineShrink / lineStretch); } else { // from a positive adjustment to a negative one balancingFactor - = ((double) adjustingInfo.availableShrink / adjustingInfo.availableStretch) + = ((double) textAdjustingInfo.availableShrink / textAdjustingInfo.availableStretch) * ((double) lineStretch / lineShrink); } } - textWordSpaceAdjust = (int) ((textWordSpaceAdjust - adjustingInfo.spaceDifference) + textWordSpaceAdjust = (int) ((textWordSpaceAdjust - textAdjustingInfo.spaceDifference) * variationFactor * balancingFactor) - + adjustingInfo.spaceDifference; + + textAdjustingInfo.spaceDifference; textLetterSpaceAdjust *= variationFactor; // update the ipd of the area - int oldAdjustment = adjustingInfo.adjustment; - adjustingInfo.adjustment *= balancingFactor * variationFactor; - ipd += adjustingInfo.adjustment - oldAdjustment; + int oldAdjustment = textAdjustingInfo.adjustment; + textAdjustingInfo.adjustment *= balancingFactor * variationFactor; + ipd += textAdjustingInfo.adjustment - oldAdjustment; } return false; } diff --git a/src/java/org/apache/fop/area/inline/FilledArea.java b/src/java/org/apache/fop/area/inline/FilledArea.java index 6b84c660d..a111e7f89 100644 --- a/src/java/org/apache/fop/area/inline/FilledArea.java +++ b/src/java/org/apache/fop/area/inline/FilledArea.java @@ -35,7 +35,7 @@ import java.util.Iterator; */ public class FilledArea extends InlineParent { private int unitWidth; - + /** * Create a new filled area. */ @@ -115,5 +115,18 @@ public class FilledArea extends InlineParent { } return newList; } + + /** + * recursively apply the variation factor to all descendant areas + * @param variationFactor the variation factor that must be applied to adjustments + * @param lineStretch the total stretch of the line + * @param lineShrink the total shrink of the line + * @return true if there is an UnresolvedArea descendant + */ + public boolean applyVariationFactor(double variationFactor, + int lineStretch, int lineShrink) { + setIPD(getIPD() + adjustingInfo.applyVariationFactor(variationFactor)); + return false; + } } diff --git a/src/java/org/apache/fop/area/inline/InlineArea.java b/src/java/org/apache/fop/area/inline/InlineArea.java index 5e31adf22..d4f834441 100644 --- a/src/java/org/apache/fop/area/inline/InlineArea.java +++ b/src/java/org/apache/fop/area/inline/InlineArea.java @@ -55,6 +55,18 @@ public class InlineArea extends Area { availableShrink = shrink; adjustment = adj; } + + /** + * Apply the variation factor + * + * @param variationFactor the factor by which the adjustment is to be changed + * @return the IPD increase + */ + protected int applyVariationFactor(double variationFactor) { + int oldAdjustment = adjustment; + adjustment *= variationFactor; + return adjustment - oldAdjustment; + } } /** @@ -76,6 +88,38 @@ public class InlineArea extends Area { */ private int storedIPDVariation = 0; + /** + * The adjustment information object + */ + protected InlineAdjustingInfo adjustingInfo = null; + + /** + * @return the adjustment information object + */ + public InlineAdjustingInfo getAdjustingInfo() { + return adjustingInfo; + } + + /** + * Create a new adjustment information object + * @param stretch the available space for stretching + * @param shrink the available space for shrinking + * @param adj space adjustment type + */ + public void setAdjustingInfo(int stretch, int shrink, int adjustment) { + adjustingInfo = new InlineAdjustingInfo(stretch, shrink, adjustment); + } + + /** + * Modify the adjustment value in the adjustment information object + * @param adjustment the new adjustment value + */ + public void setAdjustment(int adjustment) { + if (adjustingInfo != null) { + adjustingInfo.adjustment = adjustment; + } + } + /** * Increase the inline progression dimensions of this area. * This is used for inline parent areas that contain mulitple child areas. @@ -165,7 +209,10 @@ public class InlineArea extends Area { */ public boolean applyVariationFactor(double variationFactor, int lineStretch, int lineShrink) { - // default behaviour: simply return false + // default behaviour: update the IPD and return false + if (adjustingInfo != null) { + setIPD(getIPD() + adjustingInfo.applyVariationFactor(variationFactor)); + } return false; } diff --git a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java index 1f47e7c39..9e64ea534 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java @@ -253,6 +253,7 @@ public class LeaderLayoutManager extends LeafNodeLayoutManager { // create the AreaInfo object to store the computed values areaInfo = new AreaInfo((short) 0, ipd, false, context.getAlignmentContext()); + curArea.setAdjustingInfo(ipd.max - ipd.opt, ipd.opt - ipd.min, 0); addKnuthElementsForBorderPaddingStart(seq); diff --git a/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java index 20f8a0571..b730ab0cf 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java @@ -255,6 +255,7 @@ public abstract class LeafNodeLayoutManager extends AbstractLayoutManager - areaInfo.ipdArea.opt)); } area.setIPD(width); + area.setAdjustment(width - areaInfo.ipdArea.opt); } /** @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(LayoutContext, int) */ diff --git a/test/layoutengine/disabled-testcases.xml b/test/layoutengine/disabled-testcases.xml index a17668934..d4b94361f 100644 --- a/test/layoutengine/disabled-testcases.xml +++ b/test/layoutengine/disabled-testcases.xml @@ -218,11 +218,6 @@ Background-images on page-number-citations are not placed correctly. - - page-number-citation: Forward references not adjusted properly - page-number-citation_forward-ref.xml - Forward references are not properly adjusted when they are resolved. - page-number-citation-last: FOs spanning multiple pages are not properly handled. page-number-citation-last_basic.xml diff --git a/test/layoutengine/standard-testcases/leader_toc.xml b/test/layoutengine/standard-testcases/leader_toc.xml index acd0daa90..b970bfedf 100644 --- a/test/layoutengine/standard-testcases/leader_toc.xml +++ b/test/layoutengine/standard-testcases/leader_toc.xml @@ -30,7 +30,8 @@ - + 1. Chapter @@ -99,7 +100,7 @@ Text - 2. Chapter + 2. Chapter Text @@ -123,32 +124,32 @@ - + - + - + - + - + - + diff --git a/test/layoutengine/standard-testcases/page-number-citation_forward-ref.xml b/test/layoutengine/standard-testcases/page-number-citation_forward-ref.xml deleted file mode 100644 index 49fe3e19a..000000000 --- a/test/layoutengine/standard-testcases/page-number-citation_forward-ref.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - -

- This test checks fo:page-number-citation, especially the width adjustment after a forward reference is resolved. -

-
- - - - - - - - - - This block has id="first". - Note: The interesting part is on the second page! - Backward reference "first" - Forward reference "second" - This block has id="second". - - - - - - - - -
-- 2.39.5