Author: vhennebert
Date: Fri Jul 17 16:21:23 2009
New Revision: 795131
URL: http://svn.apache.org/viewvc?rev=795131&view=rev
Log:
Added support for a change of IPD between two paragraphs (blocks)
Added:
xmlgraphics/fop/branches/Temp_ChangingIPDHack/test/layoutengine/standard-testcases/flow_changing-ipd_3.xml
(with props)
Modified:
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/PageBreaker.java
Modified:
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java?rev=795131&r1=795130&r2=795131&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
(original)
+++
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
Fri Jul 17 16:21:23 2009
@@ -19,6 +19,7 @@
package org.apache.fop.layoutmgr;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
@@ -216,7 +217,7 @@
protected abstract List getNextKnuthElements(LayoutContext context, int
alignment);
protected List getNextKnuthElements(LayoutContext context, int alignment,
- KnuthElement elementAtIPDChange) {
+ Position positionAtIPDChange, LayoutManager restartAtLM) {
throw new UnsupportedOperationException("TODO: implement acceptable
fallback");
}
@@ -338,6 +339,35 @@
if (alg.ipdChanged()) {
KnuthNode optimalBreak = alg.getBestNodeBeforeIPDChange();
KnuthElement elementAtBreak =
alg.getElement(optimalBreak.position);
+ Position positionAtBreak = elementAtBreak.getPosition();
+ if (!(positionAtBreak instanceof
SpaceResolver.SpaceHandlingBreakPosition)) {
+ throw new UnsupportedOperationException(
+ "Don't know how to restart at position" +
positionAtBreak);
+ }
+ /* Retrieve the original position wrapped into this space
position */
+ positionAtBreak = positionAtBreak.getPosition();
+ LayoutManager restartAtLM = null;
+ if (positionAtBreak.getIndex() == -1) {
+ /*
+ * This is an indication that we are between two blocks
+ * (possibly surrounded by another block), not inside a
+ * paragraph.
+ */
+ Position position;
+ Iterator iter =
alg.par.listIterator(optimalBreak.position + 1);
+ do {
+ KnuthElement nextElement = (KnuthElement)
iter.next();
+ position = nextElement.getPosition();
+ } while (position == null
+ || position instanceof
SpaceResolver.SpaceHandlingPosition
+ || position instanceof
SpaceResolver.SpaceHandlingBreakPosition
+ && position.getPosition().getIndex() ==
-1);
+ LayoutManager surroundingLM = positionAtBreak.getLM();
+ while (position.getLM() != surroundingLM) {
+ position = position.getPosition();
+ }
+ restartAtLM = position.getPosition().getLM();
+ }
log.trace("IPD changes after page " + optimalPageCount + "
at index "
+ optimalBreak.position);
doPhase3(alg, optimalPageCount, blockList, effectiveList);
@@ -345,7 +375,7 @@
blockLists.clear();
blockListIndex = -1;
nextSequenceStartsOn = getNextBlockList(childLC,
Constants.EN_COLUMN,
- elementAtBreak);
+ positionAtBreak, restartAtLM);
} else {
log.debug("PLM> iOptPageCount= " + optimalPageCount
+ " pageBreaks.size()= " +
alg.getPageBreaks().size());
@@ -555,28 +585,35 @@
*/
protected int getNextBlockList(LayoutContext childLC,
int nextSequenceStartsOn) {
- return getNextBlockList(childLC, nextSequenceStartsOn, null);
+ return getNextBlockList(childLC, nextSequenceStartsOn, null, null);
}
/**
- * Gets the next block list (sequence) and adds it to a list of block
lists if it's not empty.
+ * Gets the next block list (sequence) and adds it to a list of block lists
+ * if it's not empty.
+ *
* @param childLC LayoutContext to use
- * @param nextSequenceStartsOn indicates on what page the next sequence
should start
- * @param elementAtIPDChange last element on the part before an IPD change
- * @return the page on which the next content should appear after a hard
break
+ * @param nextSequenceStartsOn indicates on what page the next sequence
+ * should start
+ * @param positionAtIPDChange last element on the part before an IPD change
+ * @param restartAtLM the layout manager from which to restart, if IPD
+ * change occurs between two LMs
+ * @return the page on which the next content should appear after a hard
+ * break
*/
- protected int getNextBlockList(LayoutContext childLC,
- int nextSequenceStartsOn, KnuthElement elementAtIPDChange) {
+ protected int getNextBlockList(LayoutContext childLC, int
nextSequenceStartsOn,
+ Position positionAtIPDChange, LayoutManager restartAtLM) {
updateLayoutContext(childLC);
//Make sure the span change signal is reset
childLC.signalSpanChange(Constants.NOT_SET);
BlockSequence blockList;
List returnedList;
- if (elementAtIPDChange == null) {
+ if (positionAtIPDChange == null) {
returnedList = getNextKnuthElements(childLC, alignment);
} else {
- returnedList = getNextKnuthElements(childLC, alignment,
elementAtIPDChange);
+ returnedList = getNextKnuthElements(childLC, alignment,
positionAtIPDChange,
+ restartAtLM);
}
if (returnedList != null) {
if (returnedList.isEmpty()) {
Modified:
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java?rev=795131&r1=795130&r2=795131&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
(original)
+++
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
Fri Jul 17 16:21:23 2009
@@ -112,16 +112,18 @@
/** {...@inheritdoc} */
public List getNextKnuthElements(LayoutContext context, int alignment) {
- return getNextKnuthElements(context, alignment, null, null);
+ return getNextKnuthElements(context, alignment, null, null, null);
}
+ /** {...@inheritdoc} */
List getNextKnuthElements(LayoutContext context, int alignment, Stack
lmStack,
- LeafPosition restartPosition) {
+ Position restartPosition, LayoutManager restartAtLM) {
resetSpaces();
if (lmStack == null) {
return super.getNextKnuthElements(context, alignment);
} else {
- return super.getNextKnuthElements(context, alignment, lmStack,
restartPosition);
+ return super.getNextKnuthElements(context, alignment, lmStack,
restartPosition,
+ restartAtLM);
}
}
Modified:
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java?rev=795131&r1=795130&r2=795131&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
(original)
+++
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
Fri Jul 17 16:21:23 2009
@@ -358,7 +358,8 @@
}
/** {...@inheritdoc} */
- List getNextKnuthElements(LayoutContext context, int alignment, Stack
lmStack, LeafPosition position) {
+ List getNextKnuthElements(LayoutContext context, int alignment, Stack
lmStack,
+ Position restartPosition, LayoutManager restartAtLM) {
referenceIPD = context.getRefIPD();
updateContentAreaIPDwithOverconstrainedAdjust();
@@ -388,11 +389,22 @@
//Used to indicate a special break-after case when all content has
already been generated.
BreakElement forcedBreakAfterLast = null;
- LayoutManager currentChildLM = (BlockLevelLayoutManager) lmStack.pop();
- setCurrentChildLM(currentChildLM);
LayoutContext childLC = new LayoutContext(0);
- List childrenElements = getNextChildElements(currentChildLM, context,
childLC, alignment,
- lmStack, position);
+ List childrenElements;
+ LayoutManager currentChildLM;
+ if (lmStack.isEmpty()) {
+ assert restartAtLM != null && restartAtLM.getParent() == this;
+ currentChildLM = restartAtLM;
+ currentChildLM.reset();
+
+ childrenElements = getNextChildElements(currentChildLM, context,
childLC,
+ alignment);
+ } else {
+ currentChildLM = (BlockLevelLayoutManager) 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
@@ -534,11 +546,12 @@
private List getNextChildElements(LayoutManager childLM, LayoutContext
context,
LayoutContext childLC, int alignment) {
- return getNextChildElements(childLM, context, childLC, alignment,
null, null);
+ return getNextChildElements(childLM, context, childLC, alignment,
null, null, null);
}
private List getNextChildElements(LayoutManager childLM, LayoutContext
context,
- LayoutContext childLC, int alignment, Stack lmStack, LeafPosition
restartPosition) {
+ LayoutContext childLC, int alignment, Stack lmStack, Position
restartPosition,
+ LayoutManager restartAtLM) {
childLC.copyPendingMarksFrom(context);
childLC.setStackLimitBP(context.getStackLimitBP());
if (childLM instanceof LineLayoutManager) {
@@ -556,10 +569,10 @@
} else {
if (childLM instanceof LineLayoutManager) {
return ((LineLayoutManager)
childLM).getNextKnuthElements(childLC, alignment,
- restartPosition);
+ (LeafPosition) restartPosition);
} else if (childLM instanceof BlockLayoutManager) {
return ((BlockLayoutManager)
childLM).getNextKnuthElements(childLC, alignment,
- lmStack, restartPosition);
+ lmStack, restartPosition, restartAtLM);
} else {
throw new UnsupportedOperationException("TODO: layout manager
not restartable");
}
Modified:
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java?rev=795131&r1=795130&r2=795131&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
(original)
+++
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
Fri Jul 17 16:21:23 2009
@@ -81,33 +81,37 @@
/** {...@inheritdoc} */
public List getNextKnuthElements(LayoutContext context, int alignment,
- KnuthElement elementAtIPDChange) {
+ Position positionAtIPDChange, LayoutManager restartAtLM) {
List elements = new LinkedList();
- LayoutManager currentChildLM = null;
-
- Position position = elementAtIPDChange.getPosition();
- while (position != null && (currentChildLM = position.getLM()) ==
null) {
- position = position.getPosition();
- }
+ LayoutManager currentChildLM = positionAtIPDChange.getLM();
if (currentChildLM == null) {
throw new IllegalStateException(
"Cannot find layout manager from where to re-start layout
after IPD change");
}
- Stack lmStack = new Stack();
- while (currentChildLM.getParent() != this) {
- lmStack.push(currentChildLM);
- currentChildLM = currentChildLM.getParent();
- }
- setCurrentChildLM(currentChildLM);
- if (!(currentChildLM instanceof BlockLayoutManager)) {
- throw new UnsupportedOperationException("TODO: layout manager not
restartable");
- } else {
- if (addChildElements(elements, currentChildLM, context, alignment,
lmStack,
- (LeafPosition) position) != null) {
+ if (restartAtLM != null && restartAtLM.getParent() == this) {
+ currentChildLM = restartAtLM;
+ setCurrentChildLM(currentChildLM);
+ currentChildLM.reset();
+ if (addChildElements(elements, currentChildLM, context, alignment)
!= null) {
return elements;
}
+ } else {
+ Stack lmStack = new Stack();
+ while (currentChildLM.getParent() != this) {
+ lmStack.push(currentChildLM);
+ currentChildLM = currentChildLM.getParent();
+ }
+ setCurrentChildLM(currentChildLM);
+ if (!(currentChildLM instanceof BlockLayoutManager)) {
+ throw new UnsupportedOperationException("TODO: layout manager
not restartable");
+ } else {
+ if (addChildElements(elements, currentChildLM, context,
alignment, lmStack,
+ positionAtIPDChange, restartAtLM) != null) {
+ return elements;
+ }
+ }
}
while ((currentChildLM = getChildLM()) != null) {
@@ -126,19 +130,19 @@
private List addChildElements(List elements, LayoutManager childLM,
LayoutContext context,
int alignment) {
- return addChildElements(elements, childLM, context, alignment, null,
null);
+ return addChildElements(elements, childLM, context, alignment, null,
null, null);
}
private List addChildElements(List elements, LayoutManager childLM,
LayoutContext context,
- int alignment, Stack lmStack, LeafPosition position) {
+ int alignment, Stack lmStack, Position position, LayoutManager
restartAtLM) {
if (handleSpanChange(childLM, elements, context)) {
SpaceResolver.resolveElementList(elements);
return elements;
}
LayoutContext childLC = new LayoutContext(0);
- List childrenElements = getNextChildElements(childLM, context, childLC,
- alignment, lmStack, position);
+ List childrenElements = getNextChildElements(childLM, context,
childLC, alignment, lmStack,
+ position, restartAtLM);
if (elements.isEmpty()) {
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
}
@@ -188,7 +192,7 @@
}
private List getNextChildElements(LayoutManager childLM, LayoutContext
context,
- LayoutContext childLC, int alignment, Stack lmStack, LeafPosition
restartPosition) {
+ LayoutContext childLC, int alignment, Stack lmStack, Position
restartPosition, LayoutManager restartLM) {
childLC.setStackLimitBP(context.getStackLimitBP());
childLC.setRefIPD(context.getRefIPD());
childLC.setWritingMode(getCurrentPage().getSimplePageMaster().getWritingMode());
@@ -198,7 +202,7 @@
childrenElements = childLM.getNextKnuthElements(childLC,
alignment);
} else {
childrenElements = ((BlockLayoutManager)
childLM).getNextKnuthElements(childLC,
- alignment, lmStack, restartPosition);
+ alignment, lmStack, restartPosition, restartLM);
}
assert !childrenElements.isEmpty();
Modified:
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/PageBreaker.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/PageBreaker.java?rev=795131&r1=795130&r2=795131&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/PageBreaker.java
(original)
+++
xmlgraphics/fop/branches/Temp_ChangingIPDHack/src/java/org/apache/fop/layoutmgr/PageBreaker.java
Fri Jul 17 16:21:23 2009
@@ -129,12 +129,12 @@
/** {...@inheritdoc} */
protected int getNextBlockList(LayoutContext childLC,
int nextSequenceStartsOn) {
- return getNextBlockList(childLC, nextSequenceStartsOn, null);
+ return getNextBlockList(childLC, nextSequenceStartsOn, null, null);
}
/** {...@inheritdoc} */
protected int getNextBlockList(LayoutContext childLC, int
nextSequenceStartsOn,
- KnuthElement elementAtIPDChange) {
+ Position positionAtIPDChange, LayoutManager restartLM) {
if (!firstPart) {
// if this is the first page that will be created by
// the current BlockSequence, it could have a break
@@ -146,7 +146,7 @@
pageBreakHandled = true;
pageProvider.setStartOfNextElementList(pslm.getCurrentPageNum(),
pslm.getCurrentPV().getCurrentSpan().getCurrentFlowIndex());
- return super.getNextBlockList(childLC, nextSequenceStartsOn,
elementAtIPDChange);
+ return super.getNextBlockList(childLC, nextSequenceStartsOn,
positionAtIPDChange, restartLM);
}
private boolean containsFootnotes(List contentList, LayoutContext context)
{
@@ -223,12 +223,14 @@
return contentList;
}
+ /** {...@inheritdoc} */
protected List getNextKnuthElements(LayoutContext context, int alignment,
- KnuthElement elementAtIPDChange) {
+ Position positionAtIPDChange, LayoutManager restartAtLM) {
List contentList = null;
do {
- contentList = childFLM.getNextKnuthElements(context, alignment,
elementAtIPDChange);
+ contentList = childFLM.getNextKnuthElements(context, alignment,
positionAtIPDChange,
+ restartAtLM);
} while (!childFLM.isFinished() && contentList == null);
// scan contentList, searching for footnotes
Added:
xmlgraphics/fop/branches/Temp_ChangingIPDHack/test/layoutengine/standard-testcases/flow_changing-ipd_3.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ChangingIPDHack/test/layoutengine/standard-testcases/flow_changing-ipd_3.xml?rev=795131&view=auto
==============================================================================
---
xmlgraphics/fop/branches/Temp_ChangingIPDHack/test/layoutengine/standard-testcases/flow_changing-ipd_3.xml
(added)
+++
xmlgraphics/fop/branches/Temp_ChangingIPDHack/test/layoutengine/standard-testcases/flow_changing-ipd_3.xml
Fri Jul 17 16:21:23 2009
@@ -0,0 +1,82 @@
+<?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 that a change of IPD between two blocks is correctly
handled.
+ </p>
+ </info>
+ <fo>
+ <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="narrow"
+ page-height="300pt" page-width="400pt" margin="50pt">
+ <fo:region-body background-color="#F0F0F0"/>
+ </fo:simple-page-master>
+ <fo:simple-page-master master-name="wide"
+ page-height="300pt" page-width="600pt" margin="50pt">
+ <fo:region-body background-color="#F0F0F0"/>
+ </fo:simple-page-master>
+ <fo:page-sequence-master master-name="pages">
+ <fo:single-page-master-reference master-reference="narrow"/>
+ <fo:repeatable-page-master-reference master-reference="wide"/>
+ </fo:page-sequence-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="pages">
+ <fo:flow flow-name="xsl-region-body">
+ <fo:block text-align="justify" id="surrounding"
+ space-before.minimum="10pt"
+ space-before.optimum="12pt"
+ space-before.maximum="50pt">
+ <fo:block space-before="inherit" id="b1">In olden times when
wishing still helped one,
+ there lived a king whose daughters were all beautiful, but the
youngest was so
+ beautiful that the sun itself, which has seen so much, was
astonished whenever it
+ shone in her face.</fo:block>
+ <fo:block space-before="inherit" id="b2">In olden times when
wishing still helped one,
+ there lived a king whose daughters were all beautiful, but the
youngest was so
+ beautiful that the sun itself, which has seen so much, was
astonished whenever it
+ shone in her face.</fo:block>
+ <fo:block space-before="inherit" id="b3">In olden times when
wishing still helped one,
+ there lived a king whose daughters were all beautiful, but the
youngest was so
+ beautiful that the sun itself, which has seen so much, was
astonished whenever it
+ shone in her face.</fo:block>
+ <fo:block border-top="1pt solid black" space-before.minimum="10pt"
+ space-before.optimum="12pt" space-before.maximum="50pt"
+ space-before.conditionality="retain" id="b4">In olden times when
wishing still helped
+ one, there lived a king whose daughters were all beautiful, but
the youngest was so
+ beautiful that the sun itself, which has seen so much, was
astonished whenever it
+ shone in her face.</fo:block>
+ <fo:block space-before="inherit" id="b5">In olden times when
wishing still helped one,
+ there lived a king whose daughters were all beautiful, but the
youngest was so
+ beautiful that the sun itself, which has seen so much, was
astonished whenever it
+ shone in her face.</fo:block>
+ </fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+ </fo:root>
+ </fo>
+ <checks>
+ <eval expected="face."
xpath="//pageViewport[1]//flow/block/block[3]/lineArea[4]/text/word[position()=last()]"/>
+ <eval expected="12000"
xpath="//pageViewport[2]//flow/block/block[1]/@space-before"/>
+ <eval expected="(solid,#000000,1000)"
+
xpath="//pageViewport[2]//flow/block/block[1]/@border-before"/>
+ <eval expected="In"
xpath="//pageViewport[1]//flow/block/block[1]/lineArea[1]/text/word[1]"/>
+ <eval expected="olden"
xpath="//pageViewport[1]//flow/block/block[1]/lineArea[1]/text/word[2]"/>
+ </checks>
+</testcase>
Propchange:
xmlgraphics/fop/branches/Temp_ChangingIPDHack/test/layoutengine/standard-testcases/flow_changing-ipd_3.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xmlgraphics/fop/branches/Temp_ChangingIPDHack/test/layoutengine/standard-testcases/flow_changing-ipd_3.xml
------------------------------------------------------------------------------
svn:keywords = Revision Id
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]