Browse Source

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
pull/25/head
Simon Pepping 17 years ago
parent
commit
7a7a0b1427

+ 11
- 11
src/java/org/apache/fop/area/inline/AbstractTextArea.java View File

@@ -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;
}

+ 14
- 1
src/java/org/apache/fop/area/inline/FilledArea.java View File

@@ -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;
}
}


+ 48
- 1
src/java/org/apache/fop/area/inline/InlineArea.java View File

@@ -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;
}

+ 1
- 0
src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java View File

@@ -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);

+ 1
- 0
src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java View File

@@ -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) */

+ 0
- 5
test/layoutengine/disabled-testcases.xml View File

@@ -218,11 +218,6 @@
<description>Background-images on page-number-citations are not
placed correctly.</description>
</testcase>
<testcase>
<name>page-number-citation: Forward references not adjusted properly</name>
<file>page-number-citation_forward-ref.xml</file>
<description>Forward references are not properly adjusted when they are resolved.</description>
</testcase>
<testcase>
<name>page-number-citation-last: FOs spanning multiple pages are not properly handled.</name>
<file>page-number-citation-last_basic.xml</file>

+ 9
- 8
test/layoutengine/standard-testcases/leader_toc.xml View File

@@ -30,7 +30,8 @@
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="normal" white-space-collapse="true">
<fo:page-sequence master-reference="normal" white-space-collapse="true"
initial-page-number="9">
<fo:flow flow-name="xsl-region-body">
<fo:block text-align-last="justify">
<fo:basic-link internal-destination="N4">1. Chapter</fo:basic-link>
@@ -99,7 +100,7 @@
<fo:block>Text
</fo:block>
<fo:block id="N28">2. Chapter
<fo:block id="N28" break-before="page">2. Chapter
</fo:block>
<fo:block>Text
@@ -123,32 +124,32 @@
<checks>
<eval expected="11100" xpath="//flow/block[1]/lineArea/@bpd"/>
<eval expected="360000" xpath="//flow/block[1]/lineArea/@ipd"/>
<eval expected="263812" xpath="//flow/block[1]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="286768" xpath="//flow/block[1]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="5280" xpath="//flow/block[1]/lineArea/inlineparent[2]/@offset"/>
<eval expected="11100" xpath="//flow/block[2]/lineArea/@bpd"/>
<eval expected="331654" xpath="//flow/block[2]/lineArea/@ipd"/>
<eval expected="231669" xpath="//flow/block[2]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="254591" xpath="//flow/block[2]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="5280" xpath="//flow/block[2]/lineArea/inlineparent[2]/@offset"/>
<eval expected="11100" xpath="//flow/block[3]/lineArea/@bpd"/>
<eval expected="331654" xpath="//flow/block[3]/lineArea/@ipd"/>
<eval expected="231669" xpath="//flow/block[3]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="254591" xpath="//flow/block[3]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="5280" xpath="//flow/block[3]/lineArea/inlineparent[2]/@offset"/>
<eval expected="11100" xpath="//flow/block[4]/lineArea/@bpd"/>
<eval expected="360000" xpath="//flow/block[4]/lineArea/@ipd"/>
<eval expected="263812" xpath="//flow/block[4]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="280199" xpath="//flow/block[4]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="5280" xpath="//flow/block[4]/lineArea/inlineparent[2]/@offset"/>
<eval expected="11100" xpath="//flow/block[5]/lineArea/@bpd"/>
<eval expected="331654" xpath="//flow/block[5]/lineArea/@ipd"/>
<eval expected="231669" xpath="//flow/block[5]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="248032" xpath="//flow/block[5]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="5280" xpath="//flow/block[5]/lineArea/inlineparent[2]/@offset"/>
<eval expected="11100" xpath="//flow/block[6]/lineArea/@bpd"/>
<eval expected="331654" xpath="//flow/block[6]/lineArea/@ipd"/>
<eval expected="231669" xpath="//flow/block[6]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="248032" xpath="//flow/block[6]/lineArea/inlineparent[2]/@ipd"/>
<eval expected="5280" xpath="//flow/block[6]/lineArea/inlineparent[2]/@offset"/>
</checks>
</testcase>

+ 0
- 47
test/layoutengine/standard-testcases/page-number-citation_forward-ref.xml View File

@@ -1,47 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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$ -->
<testcase>
<info>
<p>
This test checks fo:page-number-citation, especially the width adjustment after a forward reference is resolved.
</p>
</info>
<fo>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg">
<fo:layout-master-set>
<fo:simple-page-master master-name="master1" page-width="5in" page-height="1in">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="master1" white-space-collapse="true">
<fo:flow flow-name="xsl-region-body">
<fo:block id="first">This block has id="first".</fo:block>
<fo:block font-style="italic" font-size="smaller" break-after="page">Note: The interesting part is on the second page!</fo:block>
<fo:block text-align="justify" text-align-last="justify" id="refbl1">Backward reference "first"<fo:leader leader-pattern="dots" leader-pattern-width="8pt"/><fo:page-number-citation id="first-ref" ref-id="first"/></fo:block>
<fo:block text-align="justify" text-align-last="justify" id="refbl2">Forward reference "second"<fo:leader leader-pattern="dots" leader-pattern-width="8pt"/><fo:page-number-citation id="second-ref" ref-id="second"/></fo:block>
<fo:block break-before="page" id="second">This block has id="second".</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</fo>
<checks>
<true xpath="(//block[@prod-id='refbl1']/@ipd - sum(//block[@prod-id='refbl1']/lineArea/child::*/@ipd)) &lt; 3"/>
<true xpath="(//block[@prod-id='refbl2']/@ipd - sum(//block[@prod-id='refbl2']/lineArea/child::*/@ipd)) &lt; 3"/>
</checks>
</testcase>

Loading…
Cancel
Save