ASF Bugzilla – Attachment 26800 Details for
Bug 44328
[PATCH] orphans/widows not respected in some cases
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch fixing some of the issues with widows/orphans
b44328.patch (text/plain), 13.22 KB, created by
Andreas L. Delmelle
on 2011-03-27 02:36:03 UTC
(
hide
)
Description:
patch fixing some of the issues with widows/orphans
Filename:
MIME Type:
Creator:
Andreas L. Delmelle
Created:
2011-03-27 02:36:03 UTC
Size:
13.22 KB
patch
obsolete
>Index: test/layoutengine/standard-testcases/inline_block_nested_4.xml >=================================================================== >--- test/layoutengine/standard-testcases/inline_block_nested_4.xml (revision 627324) >+++ test/layoutengine/standard-testcases/inline_block_nested_4.xml (revision ) >@@ -52,19 +52,13 @@ > <checks> > <element-list category="breaker"> > <box w="12000"/> >- <penalty w="0" p="0"/> > <box w="12000"/> >- <penalty w="0" p="0"/> > <box w="12000"/> > <penalty w="0" p="0"/> > <box w="12000"/> >- <penalty w="0" p="0"/> > <box w="12000"/> >- <penalty w="0" p="0"/> > <box w="12000"/> >- <penalty w="0" p="1000"/> >- <glue w="0"/> >- <penalty w="0" p="-1000"/> >+ <skip>3</skip> > </element-list> > > <!-- first block --> >Index: test/layoutengine/standard-testcases/inline_block_nested_1.xml >=================================================================== >--- test/layoutengine/standard-testcases/inline_block_nested_1.xml (revision 627324) >+++ test/layoutengine/standard-testcases/inline_block_nested_1.xml (revision ) >@@ -39,9 +39,7 @@ > <checks> > <element-list category="breaker"> > <box w="14400"/> >- <penalty w="0" p="0"/> > <box w="0" aux="true"/> <!-- this is from the empty block --> >- <penalty w="0" p="0"/> > <box w="14400"/> > <skip>3</skip> > </element-list> >Index: test/layoutengine/standard-testcases/inline_block_nested_6.xml >=================================================================== >--- test/layoutengine/standard-testcases/inline_block_nested_6.xml (revision 807014) >+++ test/layoutengine/standard-testcases/inline_block_nested_6.xml (revision ) >@@ -49,14 +49,14 @@ > </fo> > <checks> > <element-list category="breaker"> >- <skip>5</skip> >+ <skip>3</skip> > <!-- penalty between blocks b11 and b12, set by InlineLM in b1 --> > <penalty w="0" p="0"/> > <skip>5</skip> > <!-- penalty between blocks b21 and b22, set by InlineLM in b2 --> > <!-- keep-together.within-page="always" --> > <penalty w="0" p="1000"/> >- <skip>3</skip> >+ <skip>5</skip> > <!-- penalty between blocks b31 and b32, set by InlineLM in b3 --> > <!-- keep-with-next.within-page="always" --> > <penalty w="0" p="1000"/> >Index: test/layoutengine/standard-testcases/inline_block-level_nested_1.xml >=================================================================== >--- test/layoutengine/standard-testcases/inline_block-level_nested_1.xml (revision 815383) >+++ test/layoutengine/standard-testcases/inline_block-level_nested_1.xml (revision ) >@@ -77,23 +77,17 @@ > <checks> > <element-list category="breaker"> > <box w="14400"/> >- <penalty w="0" p="0"/> > <box w="14400"/> >- <penalty w="0" p="0"/> > <box w="14400"/> > <penalty w="0" p="0"/> > <glue w="6000" aux="true"/> > <box w="14400"/> >- <penalty w="0" p="0"/> > <box w="14400"/> >- <penalty w="0" p="0"/> > <box w="14400"/> > <penalty w="0" p="0"/> > <glue w="6000" aux="true"/> > <box w="14400"/> >- <penalty w="0" p="0"/> > <box w="14400"/> >- <penalty w="0" p="0"/> > <box w="14400"/> > <skip>3</skip> > </element-list> >Index: src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java >=================================================================== >--- src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (revision 1067698) >+++ src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (revision ) >@@ -155,7 +155,7 @@ > private final int follow; > private AlignmentContext alignmentContext; > >- private List knuthParagraphs; >+ private List<KnuthSequence> knuthParagraphs; > > private LineLayoutPossibilities lineLayouts; > private LineLayoutPossibilities[] lineLayoutsList; >@@ -400,7 +400,7 @@ > // true if this line contains only zero-height, auxiliary boxes > // and the actual line width is 0; in this case, the line "collapses" > // i.e. the line area will have bpd = 0 >- boolean bZeroHeightLine = (difference == ipd); >+ boolean isZeroHeightLine = (difference == ipd); > > // if line-stacking-strategy is "font-height", the line height > // is not affected by its content >@@ -436,9 +436,9 @@ > } > lastAC = ac; > } >- if (bZeroHeightLine >+ if (isZeroHeightLine > && (!element.isAuxiliary() || ac != null && ac.getHeight() > 0)) { >- bZeroHeightLine = false; >+ isZeroHeightLine = false; > } > } > } >@@ -450,7 +450,7 @@ > > constantLineHeight = lineLead + lineFollow; > >- if (bZeroHeightLine) { >+ if (isZeroHeightLine) { > return new LineBreakPosition(thisLLM, > knuthParagraphs.indexOf(par), > firstElementIndex, lastElementIndex, >@@ -580,7 +580,7 @@ > //PHASE 1: Create Knuth elements > if (knuthParagraphs == null) { > // it's the first time this method is called >- knuthParagraphs = new ArrayList(); >+ knuthParagraphs = new ArrayList<KnuthSequence>(); > > // here starts Knuth's algorithm > collectInlineKnuthElements(context); >@@ -612,12 +612,10 @@ > LeafPosition restartPosition) { > log.trace("Restarting line breaking from index " + restartPosition.getIndex()); > int parIndex = restartPosition.getLeafPos(); >- Paragraph paragraph = (Paragraph) knuthParagraphs.get(parIndex); >- for (int i = 0; i <= restartPosition.getIndex(); i++) { >- paragraph.remove(0); >- } >- Iterator iter = paragraph.iterator(); >- while (iter.hasNext() && !((KnuthElement) iter.next()).isBox()) { >+ KnuthSequence paragraph = knuthParagraphs.get(parIndex); >+ paragraph.subList(0, restartPosition.getIndex()).clear(); >+ Iterator<KnuthElement> iter = paragraph.iterator(); >+ while (iter.hasNext() && !iter.next().isBox()) { > iter.remove(); > } > if (!iter.hasNext()) { >@@ -650,8 +648,8 @@ > > Paragraph lastPar = null; > >- InlineLevelLayoutManager curLM; >- while ((curLM = (InlineLevelLayoutManager) getChildLM()) != null) { >+ InlineLevelLayoutManager curLM = (InlineLevelLayoutManager) getChildLM(); >+ while (curLM != null) { > List inlineElements = curLM.getNextKnuthElements(inlineLC, effectiveAlignment); > if (inlineElements == null || inlineElements.size() == 0) { > /* curLM.getNextKnuthElements() returned null or an empty list; >@@ -748,7 +746,9 @@ > } > } > } // end of loop over returnedList >+ curLM = (InlineLevelLayoutManager) getChildLM(); > } >+ > if (lastPar != null) { > lastPar.endParagraph(); > ElementListObserver.observe(lastPar, "line", fobj.getId()); >@@ -765,13 +765,13 @@ > * @param context the layout context > * @return a list of Knuth elements representing broken lines > */ >- private List createLineBreaks(int alignment, LayoutContext context) { >+ private List<ListElement> createLineBreaks(int alignment, LayoutContext context) { > // find the optimal line breaking points for each paragraph >- Iterator paragraphsIterator = knuthParagraphs.iterator(); >+ Iterator<KnuthSequence> paragraphsIterator = knuthParagraphs.iterator(); > lineLayoutsList = new LineLayoutPossibilities[knuthParagraphs.size()]; > LineLayoutPossibilities llPoss; > for (int i = 0; paragraphsIterator.hasNext(); i++) { >- KnuthSequence seq = (KnuthSequence) paragraphsIterator.next(); >+ KnuthSequence seq = paragraphsIterator.next(); > if (!seq.isInlineSequence()) { > // This set of line layout possibilities does not matter; > // we only need an entry in lineLayoutsList. >@@ -807,7 +807,7 @@ > lineHeight.getValue(this), lead, follow, > (knuthParagraphs.indexOf(currPar) == 0), > hyphenationLadderCount.getEnum() == EN_NO_LIMIT >- ? 0 : hyphenationLadderCount.getValue(), >+ ? 0 : hyphenationLadderCount.getValue(), > this); > alg.setConstantLineWidth(ipd); > boolean canWrap = (wrapOption != EN_NO_WRAP); >@@ -873,14 +873,20 @@ > * @param context the layout context > * @return the newly built element list > */ >- private List postProcessLineBreaks(int alignment, LayoutContext context) { >+ private List<ListElement> postProcessLineBreaks(int alignment, LayoutContext context) { > > List<ListElement> returnList = new LinkedList<ListElement>(); > > int endIndex = -1; >+ int lineCount = 0; > for (int p = 0; p < knuthParagraphs.size(); p++) { >+ >+ KnuthSequence seq = knuthParagraphs.get(p); >+ LineLayoutPossibilities llPoss = lineLayoutsList[p]; > // penalty between paragraphs >- if (p > 0) { >+ if (p > 0 && lineCount >= fobj.getOrphans() >+ && (p != knuthParagraphs.size() - 1 >+ || llPoss.getChosenLineCount() >= fobj.getWidows())) { > Keep keep = getKeepTogether(); > returnList.add(new BreakElement( > new Position(this), >@@ -889,9 +895,6 @@ > context)); > } > >- LineLayoutPossibilities llPoss = lineLayoutsList[p]; >- KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(p); >- > if (!seq.isInlineSequence()) { > List<ListElement> targetList = new LinkedList<ListElement>(); > ListIterator listIter = seq.listIterator(); >@@ -903,7 +906,11 @@ > tempElement.getPosition()))); > } > targetList.add(tempElement); >+ if (tempElement.isBox() >+ && !((KnuthBox) tempElement).isAuxiliary()) { >+ lineCount++; >- } >+ } >+ } > returnList.addAll(targetList); > } else if (seq.isInlineSequence() && alignment == EN_JUSTIFY) { > /* justified vertical alignment (not in the XSL FO recommendation): >@@ -917,11 +924,11 @@ > int startIndex = 0; > for (int i = 0; > i < llPoss.getChosenLineCount(); >- i++) { >+ i++, lineCount++) { > if (returnList.size() > 0 > && i > 0 //if i==0 break generated above already >- && i >= fobj.getOrphans() >- && i <= llPoss.getChosenLineCount() - fobj.getWidows()) { >+ && lineCount >= fobj.getOrphans() >+ && lineCount <= llPoss.getChosenLineCount() - fobj.getWidows()) { > // penalty allowing a page break between lines > Keep keep = getKeepTogether(); > returnList.add(new BreakElement( >@@ -1149,7 +1156,7 @@ > > /** {@inheritDoc} */ > public List getChangedKnuthElements(List oldList, int alignment) { >- List returnList = new LinkedList(); >+ List<KnuthElement> returnList = new LinkedList<KnuthElement>(); > for (int p = 0; p < knuthParagraphs.size(); p++) { > LineLayoutPossibilities llPoss = lineLayoutsList[p]; > //log.debug("demerits of the chosen layout: " + llPoss.getChosenDemerits()); >@@ -1392,7 +1399,7 @@ > public void addAreas(PositionIterator parentIter, > LayoutContext context) { > while (parentIter.hasNext()) { >- Position pos = (Position) parentIter.next(); >+ Position pos = parentIter.next(); > boolean isLastPosition = !parentIter.hasNext(); > if (pos instanceof LineBreakPosition) { > addInlineArea(context, (LineBreakPosition) pos, isLastPosition); >@@ -1426,12 +1433,12 @@ > (lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast), > lbp.difference, lbp.availableStretch, lbp.availableShrink); > if (lbp.startIndent != 0) { >- lineArea.addTrait(Trait.START_INDENT, new Integer(lbp.startIndent)); >+ lineArea.addTrait(Trait.START_INDENT, lbp.startIndent); > } > lineArea.setBPD(lbp.lineHeight); > lineArea.setIPD(lbp.lineWidth); >- lineArea.addTrait(Trait.SPACE_BEFORE, new Integer(lbp.spaceBefore)); >- lineArea.addTrait(Trait.SPACE_AFTER, new Integer(lbp.spaceAfter)); >+ lineArea.addTrait(Trait.SPACE_BEFORE, lbp.spaceBefore); >+ lineArea.addTrait(Trait.SPACE_AFTER, lbp.spaceAfter); > alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline); > > if (seq instanceof Paragraph) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 44328
:
21452
|
26800
|
26801
|
26807
|
26813
|
26820
|
26842
|
26843
|
26845
|
26846
|
26851
|
26852
|
27055
|
27066