View | Details | Raw Unified | Return to bug 44328
Collapse All | Expand All

(-)test/layoutengine/standard-testcases/inline_block_nested_4.xml (-7 / +1 lines)
Lines 52-70 Link Here
52
  <checks>
52
  <checks>
53
    <element-list category="breaker">
53
    <element-list category="breaker">
54
      <box w="12000"/>
54
      <box w="12000"/>
55
      <penalty w="0" p="0"/>
56
      <box w="12000"/>
55
      <box w="12000"/>
57
      <penalty w="0" p="0"/>
58
      <box w="12000"/>
56
      <box w="12000"/>
59
      <penalty w="0" p="0"/>
57
      <penalty w="0" p="0"/>
60
      <box w="12000"/>
58
      <box w="12000"/>
61
      <penalty w="0" p="0"/>
62
      <box w="12000"/>
59
      <box w="12000"/>
63
      <penalty w="0" p="0"/>
64
      <box w="12000"/>
60
      <box w="12000"/>
65
      <penalty w="0" p="1000"/>
61
      <skip>3</skip>
66
      <glue w="0"/>
67
      <penalty w="0" p="-1000"/>
68
    </element-list>
62
    </element-list>
69
    
63
    
70
    <!-- first block -->
64
    <!-- first block -->
(-)test/layoutengine/standard-testcases/inline_block_nested_1.xml (-2 lines)
Lines 39-47 Link Here
39
  <checks>
39
  <checks>
40
    <element-list category="breaker">
40
    <element-list category="breaker">
41
      <box w="14400"/>
41
      <box w="14400"/>
42
      <penalty w="0" p="0"/>
43
      <box w="0" aux="true"/> <!-- this is from the empty block -->
42
      <box w="0" aux="true"/> <!-- this is from the empty block -->
44
      <penalty w="0" p="0"/>
45
      <box w="14400"/>
43
      <box w="14400"/>
46
      <skip>3</skip>
44
      <skip>3</skip>
47
    </element-list>
45
    </element-list>
(-)test/layoutengine/standard-testcases/inline_block_nested_6.xml (-2 / +2 lines)
Lines 49-62 Link Here
49
  </fo>
49
  </fo>
50
  <checks>
50
  <checks>
51
    <element-list category="breaker">
51
    <element-list category="breaker">
52
      <skip>5</skip>
52
      <skip>3</skip>
53
      <!-- penalty between blocks b11 and b12, set by InlineLM in b1 -->
53
      <!-- penalty between blocks b11 and b12, set by InlineLM in b1 -->
54
      <penalty w="0" p="0"/>
54
      <penalty w="0" p="0"/>
55
      <skip>5</skip>
55
      <skip>5</skip>
56
      <!-- penalty between blocks b21 and b22, set by InlineLM in b2 -->
56
      <!-- penalty between blocks b21 and b22, set by InlineLM in b2 -->
57
      <!-- keep-together.within-page="always" -->
57
      <!-- keep-together.within-page="always" -->
58
      <penalty w="0" p="1000"/>
58
      <penalty w="0" p="1000"/>
59
      <skip>3</skip>
59
      <skip>5</skip>
60
      <!-- penalty between blocks b31 and b32, set by InlineLM in b3 -->
60
      <!-- penalty between blocks b31 and b32, set by InlineLM in b3 -->
61
      <!-- keep-with-next.within-page="always" -->
61
      <!-- keep-with-next.within-page="always" -->
62
      <penalty w="0" p="1000"/>
62
      <penalty w="0" p="1000"/>
(-)test/layoutengine/standard-testcases/inline_block-level_nested_1.xml (-6 lines)
Lines 77-99 Link Here
77
  <checks>
77
  <checks>
78
    <element-list category="breaker">
78
    <element-list category="breaker">
79
      <box w="14400"/>
79
      <box w="14400"/>
80
      <penalty w="0" p="0"/>
81
      <box w="14400"/>
80
      <box w="14400"/>
82
      <penalty w="0" p="0"/>
83
      <box w="14400"/>
81
      <box w="14400"/>
84
      <penalty w="0" p="0"/>
82
      <penalty w="0" p="0"/>
85
      <glue w="6000" aux="true"/>
83
      <glue w="6000" aux="true"/>
86
      <box w="14400"/>
84
      <box w="14400"/>
87
      <penalty w="0" p="0"/>
88
      <box w="14400"/>
85
      <box w="14400"/>
89
      <penalty w="0" p="0"/>
90
      <box w="14400"/>
86
      <box w="14400"/>
91
      <penalty w="0" p="0"/>
87
      <penalty w="0" p="0"/>
92
      <glue w="6000" aux="true"/>
88
      <glue w="6000" aux="true"/>
93
      <box w="14400"/>
89
      <box w="14400"/>
94
      <penalty w="0" p="0"/>
95
      <box w="14400"/>
90
      <box w="14400"/>
96
      <penalty w="0" p="0"/>
97
      <box w="14400"/>
91
      <box w="14400"/>
98
      <skip>3</skip>
92
      <skip>3</skip>
99
    </element-list>
93
    </element-list>
(-)src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (-32 / +39 lines)
Lines 155-161 Link Here
155
    private final int follow;
155
    private final int follow;
156
    private AlignmentContext alignmentContext;
156
    private AlignmentContext alignmentContext;
157
157
158
    private List knuthParagraphs;
158
    private List<KnuthSequence> knuthParagraphs;
159
159
160
    private LineLayoutPossibilities lineLayouts;
160
    private LineLayoutPossibilities lineLayouts;
161
    private LineLayoutPossibilities[] lineLayoutsList;
161
    private LineLayoutPossibilities[] lineLayoutsList;
Lines 400-406 Link Here
400
            // true if this line contains only zero-height, auxiliary boxes
400
            // true if this line contains only zero-height, auxiliary boxes
401
            // and the actual line width is 0; in this case, the line "collapses"
401
            // and the actual line width is 0; in this case, the line "collapses"
402
            // i.e. the line area will have bpd = 0
402
            // i.e. the line area will have bpd = 0
403
            boolean bZeroHeightLine = (difference == ipd);
403
            boolean isZeroHeightLine = (difference == ipd);
404
404
405
            // if line-stacking-strategy is "font-height", the line height
405
            // if line-stacking-strategy is "font-height", the line height
406
            // is not affected by its content
406
            // is not affected by its content
Lines 436-444 Link Here
436
                            }
436
                            }
437
                            lastAC = ac;
437
                            lastAC = ac;
438
                        }
438
                        }
439
                        if (bZeroHeightLine
439
                        if (isZeroHeightLine
440
                            && (!element.isAuxiliary() || ac != null && ac.getHeight() > 0)) {
440
                            && (!element.isAuxiliary() || ac != null && ac.getHeight() > 0)) {
441
                            bZeroHeightLine = false;
441
                            isZeroHeightLine = false;
442
                        }
442
                        }
443
                    }
443
                    }
444
                }
444
                }
Lines 450-456 Link Here
450
450
451
            constantLineHeight = lineLead + lineFollow;
451
            constantLineHeight = lineLead + lineFollow;
452
452
453
            if (bZeroHeightLine) {
453
            if (isZeroHeightLine) {
454
                return new LineBreakPosition(thisLLM,
454
                return new LineBreakPosition(thisLLM,
455
                                             knuthParagraphs.indexOf(par),
455
                                             knuthParagraphs.indexOf(par),
456
                                             firstElementIndex, lastElementIndex,
456
                                             firstElementIndex, lastElementIndex,
Lines 580-586 Link Here
580
        //PHASE 1: Create Knuth elements
580
        //PHASE 1: Create Knuth elements
581
        if (knuthParagraphs == null) {
581
        if (knuthParagraphs == null) {
582
            // it's the first time this method is called
582
            // it's the first time this method is called
583
            knuthParagraphs = new ArrayList();
583
            knuthParagraphs = new ArrayList<KnuthSequence>();
584
584
585
            // here starts Knuth's algorithm
585
            // here starts Knuth's algorithm
586
            collectInlineKnuthElements(context);
586
            collectInlineKnuthElements(context);
Lines 612-623 Link Here
612
            LeafPosition restartPosition) {
612
            LeafPosition restartPosition) {
613
        log.trace("Restarting line breaking from index " + restartPosition.getIndex());
613
        log.trace("Restarting line breaking from index " + restartPosition.getIndex());
614
        int parIndex = restartPosition.getLeafPos();
614
        int parIndex = restartPosition.getLeafPos();
615
        Paragraph paragraph = (Paragraph) knuthParagraphs.get(parIndex);
615
        KnuthSequence paragraph = knuthParagraphs.get(parIndex);
616
        for (int i = 0; i <= restartPosition.getIndex(); i++) {
616
        paragraph.subList(0, restartPosition.getIndex()).clear();
617
            paragraph.remove(0);
617
        Iterator<KnuthElement> iter = paragraph.iterator();
618
        }
618
        while (iter.hasNext() && !iter.next().isBox()) {
619
        Iterator iter = paragraph.iterator();
620
        while (iter.hasNext() && !((KnuthElement) iter.next()).isBox()) {
621
            iter.remove();
619
            iter.remove();
622
        }
620
        }
623
        if (!iter.hasNext()) {
621
        if (!iter.hasNext()) {
Lines 650-657 Link Here
650
648
651
        Paragraph lastPar = null;
649
        Paragraph lastPar = null;
652
650
653
        InlineLevelLayoutManager curLM;
651
        InlineLevelLayoutManager curLM = (InlineLevelLayoutManager) getChildLM();
654
        while ((curLM = (InlineLevelLayoutManager) getChildLM()) != null) {
652
        while (curLM != null) {
655
            List inlineElements = curLM.getNextKnuthElements(inlineLC, effectiveAlignment);
653
            List inlineElements = curLM.getNextKnuthElements(inlineLC, effectiveAlignment);
656
            if (inlineElements == null || inlineElements.size() == 0) {
654
            if (inlineElements == null || inlineElements.size() == 0) {
657
                /* curLM.getNextKnuthElements() returned null or an empty list;
655
                /* curLM.getNextKnuthElements() returned null or an empty list;
Lines 748-754 Link Here
748
                    }
746
                    }
749
                }
747
                }
750
            } // end of loop over returnedList
748
            } // end of loop over returnedList
749
            curLM = (InlineLevelLayoutManager) getChildLM();
751
        }
750
        }
751
752
        if (lastPar != null) {
752
        if (lastPar != null) {
753
            lastPar.endParagraph();
753
            lastPar.endParagraph();
754
            ElementListObserver.observe(lastPar, "line", fobj.getId());
754
            ElementListObserver.observe(lastPar, "line", fobj.getId());
Lines 765-777 Link Here
765
     * @param context the layout context
765
     * @param context the layout context
766
     * @return a list of Knuth elements representing broken lines
766
     * @return a list of Knuth elements representing broken lines
767
     */
767
     */
768
    private List createLineBreaks(int alignment, LayoutContext context) {
768
    private List<ListElement> createLineBreaks(int alignment, LayoutContext context) {
769
        // find the optimal line breaking points for each paragraph
769
        // find the optimal line breaking points for each paragraph
770
        Iterator paragraphsIterator = knuthParagraphs.iterator();
770
        Iterator<KnuthSequence> paragraphsIterator = knuthParagraphs.iterator();
771
        lineLayoutsList = new LineLayoutPossibilities[knuthParagraphs.size()];
771
        lineLayoutsList = new LineLayoutPossibilities[knuthParagraphs.size()];
772
        LineLayoutPossibilities llPoss;
772
        LineLayoutPossibilities llPoss;
773
        for (int i = 0; paragraphsIterator.hasNext(); i++) {
773
        for (int i = 0; paragraphsIterator.hasNext(); i++) {
774
            KnuthSequence seq = (KnuthSequence) paragraphsIterator.next();
774
            KnuthSequence seq = paragraphsIterator.next();
775
            if (!seq.isInlineSequence()) {
775
            if (!seq.isInlineSequence()) {
776
                // This set of line layout possibilities does not matter;
776
                // This set of line layout possibilities does not matter;
777
                // we only need an entry in lineLayoutsList.
777
                // we only need an entry in lineLayoutsList.
Lines 807-813 Link Here
807
                                        lineHeight.getValue(this), lead, follow,
807
                                        lineHeight.getValue(this), lead, follow,
808
                                        (knuthParagraphs.indexOf(currPar) == 0),
808
                                        (knuthParagraphs.indexOf(currPar) == 0),
809
                                        hyphenationLadderCount.getEnum() == EN_NO_LIMIT
809
                                        hyphenationLadderCount.getEnum() == EN_NO_LIMIT
810
                                        ? 0 : hyphenationLadderCount.getValue(),
810
                                            ? 0 : hyphenationLadderCount.getValue(),
811
                                        this);
811
                                        this);
812
        alg.setConstantLineWidth(ipd);
812
        alg.setConstantLineWidth(ipd);
813
        boolean canWrap = (wrapOption != EN_NO_WRAP);
813
        boolean canWrap = (wrapOption != EN_NO_WRAP);
Lines 873-886 Link Here
873
     * @param context the layout context
873
     * @param context the layout context
874
     * @return the newly built element list
874
     * @return the newly built element list
875
     */
875
     */
876
    private List postProcessLineBreaks(int alignment, LayoutContext context) {
876
    private List<ListElement> postProcessLineBreaks(int alignment, LayoutContext context) {
877
877
878
        List<ListElement> returnList = new LinkedList<ListElement>();
878
        List<ListElement> returnList = new LinkedList<ListElement>();
879
879
880
        int endIndex = -1;
880
        int endIndex = -1;
881
        int lineCount = 0;
881
        for (int p = 0; p < knuthParagraphs.size(); p++) {
882
        for (int p = 0; p < knuthParagraphs.size(); p++) {
883
884
            KnuthSequence seq = knuthParagraphs.get(p);
885
            LineLayoutPossibilities llPoss = lineLayoutsList[p];
882
            // penalty between paragraphs
886
            // penalty between paragraphs
883
            if (p > 0) {
887
            if (p > 0 && lineCount >= fobj.getOrphans()
888
                    && (p != knuthParagraphs.size() - 1
889
                        || llPoss.getChosenLineCount() >= fobj.getWidows())) {
884
                Keep keep = getKeepTogether();
890
                Keep keep = getKeepTogether();
885
                returnList.add(new BreakElement(
891
                returnList.add(new BreakElement(
886
                            new Position(this),
892
                            new Position(this),
Lines 889-897 Link Here
889
                            context));
895
                            context));
890
            }
896
            }
891
897
892
            LineLayoutPossibilities llPoss = lineLayoutsList[p];
893
            KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(p);
894
895
            if (!seq.isInlineSequence()) {
898
            if (!seq.isInlineSequence()) {
896
                List<ListElement> targetList = new LinkedList<ListElement>();
899
                List<ListElement> targetList = new LinkedList<ListElement>();
897
                ListIterator listIter = seq.listIterator();
900
                ListIterator listIter = seq.listIterator();
Lines 903-909 Link Here
903
                                tempElement.getPosition())));
906
                                tempElement.getPosition())));
904
                    }
907
                    }
905
                    targetList.add(tempElement);
908
                    targetList.add(tempElement);
906
                }
909
                    if (tempElement.isBox()
910
                            && !((KnuthBox) tempElement).isAuxiliary()) {
911
                        lineCount++;
912
                    }
913
                }
907
                returnList.addAll(targetList);
914
                returnList.addAll(targetList);
908
            } else if (seq.isInlineSequence() && alignment == EN_JUSTIFY) {
915
            } else if (seq.isInlineSequence() && alignment == EN_JUSTIFY) {
909
                /* justified vertical alignment (not in the XSL FO recommendation):
916
                /* justified vertical alignment (not in the XSL FO recommendation):
Lines 917-927 Link Here
917
                int startIndex = 0;
924
                int startIndex = 0;
918
                for (int i = 0;
925
                for (int i = 0;
919
                        i < llPoss.getChosenLineCount();
926
                        i < llPoss.getChosenLineCount();
920
                        i++) {
927
                        i++, lineCount++) {
921
                    if (returnList.size() > 0
928
                    if (returnList.size() > 0
922
                            && i > 0 //if i==0 break generated above already
929
                            && i > 0 //if i==0 break generated above already
923
                            && i >= fobj.getOrphans()
930
                            && lineCount >= fobj.getOrphans()
924
                            && i <= llPoss.getChosenLineCount() - fobj.getWidows()) {
931
                            && lineCount <= llPoss.getChosenLineCount() - fobj.getWidows()) {
925
                        // penalty allowing a page break between lines
932
                        // penalty allowing a page break between lines
926
                        Keep keep = getKeepTogether();
933
                        Keep keep = getKeepTogether();
927
                        returnList.add(new BreakElement(
934
                        returnList.add(new BreakElement(
Lines 1149-1155 Link Here
1149
1156
1150
    /** {@inheritDoc} */
1157
    /** {@inheritDoc} */
1151
    public List getChangedKnuthElements(List oldList, int alignment) {
1158
    public List getChangedKnuthElements(List oldList, int alignment) {
1152
        List returnList = new LinkedList();
1159
        List<KnuthElement> returnList = new LinkedList<KnuthElement>();
1153
        for (int p = 0; p < knuthParagraphs.size(); p++) {
1160
        for (int p = 0; p < knuthParagraphs.size(); p++) {
1154
            LineLayoutPossibilities llPoss = lineLayoutsList[p];
1161
            LineLayoutPossibilities llPoss = lineLayoutsList[p];
1155
            //log.debug("demerits of the chosen layout: " + llPoss.getChosenDemerits());
1162
            //log.debug("demerits of the chosen layout: " + llPoss.getChosenDemerits());
Lines 1392-1398 Link Here
1392
    public void addAreas(PositionIterator parentIter,
1399
    public void addAreas(PositionIterator parentIter,
1393
                         LayoutContext context) {
1400
                         LayoutContext context) {
1394
        while (parentIter.hasNext()) {
1401
        while (parentIter.hasNext()) {
1395
            Position pos = (Position) parentIter.next();
1402
            Position pos = parentIter.next();
1396
            boolean isLastPosition = !parentIter.hasNext();
1403
            boolean isLastPosition = !parentIter.hasNext();
1397
            if (pos instanceof LineBreakPosition) {
1404
            if (pos instanceof LineBreakPosition) {
1398
                addInlineArea(context, (LineBreakPosition) pos, isLastPosition);
1405
                addInlineArea(context, (LineBreakPosition) pos, isLastPosition);
Lines 1426-1437 Link Here
1426
                (lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast),
1433
                (lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast),
1427
                lbp.difference, lbp.availableStretch, lbp.availableShrink);
1434
                lbp.difference, lbp.availableStretch, lbp.availableShrink);
1428
        if (lbp.startIndent != 0) {
1435
        if (lbp.startIndent != 0) {
1429
            lineArea.addTrait(Trait.START_INDENT, new Integer(lbp.startIndent));
1436
            lineArea.addTrait(Trait.START_INDENT, lbp.startIndent);
1430
        }
1437
        }
1431
        lineArea.setBPD(lbp.lineHeight);
1438
        lineArea.setBPD(lbp.lineHeight);
1432
        lineArea.setIPD(lbp.lineWidth);
1439
        lineArea.setIPD(lbp.lineWidth);
1433
        lineArea.addTrait(Trait.SPACE_BEFORE, new Integer(lbp.spaceBefore));
1440
        lineArea.addTrait(Trait.SPACE_BEFORE, lbp.spaceBefore);
1434
        lineArea.addTrait(Trait.SPACE_AFTER, new Integer(lbp.spaceAfter));
1441
        lineArea.addTrait(Trait.SPACE_AFTER, lbp.spaceAfter);
1435
        alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline);
1442
        alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline);
1436
1443
1437
        if (seq instanceof Paragraph) {
1444
        if (seq instanceof Paragraph) {

Return to bug 44328