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

(-)old/area/inline/FilledArea.java (+24 lines)
Lines 19-24 Link Here
19
package org.apache.fop.area.inline;
19
package org.apache.fop.area.inline;
20
20
21
import java.util.List;
21
import java.util.List;
22
import java.util.ListIterator;
22
import java.util.ArrayList;
23
import java.util.ArrayList;
23
24
24
/**
25
/**
Lines 37-42 Link Here
37
     * Create a new filled area.
38
     * Create a new filled area.
38
     */
39
     */
39
    public FilledArea() {
40
    public FilledArea() {
41
    }
42
43
    /**
44
     * Set the offset of the descendant TextAreas,
45
     * instead of the offset of the FilledArea itself.
46
     *
47
     * @param v the offset
48
     */
49
    public void setOffset(int v) {
50
        setChildOffset(inlines.listIterator(), v);
51
    }
52
53
    private void setChildOffset(ListIterator childrenIterator, int v) {
54
        while (childrenIterator.hasNext()) {
55
            InlineArea child = (InlineArea) childrenIterator.next();
56
            if (child instanceof InlineParent) {
57
                setChildOffset(((InlineParent) child).getChildAreas().listIterator(), v);
58
            } else if (child instanceof org.apache.fop.area.inline.Viewport) {
59
                // nothing
60
            } else {
61
                child.setOffset(v);
62
            }
63
        }
40
    }
64
    }
41
65
42
    /**
66
    /**
(-)old/layoutmgr/BlockLayoutManager.java (-1 / +3 lines)
Lines 65-70 Link Here
65
    private int lead = 12000;
65
    private int lead = 12000;
66
    private int lineHeight = 14000;
66
    private int lineHeight = 14000;
67
    private int follow = 2000;
67
    private int follow = 2000;
68
    private int middleShift = 0;
68
69
69
    private int iStartPos = 0;
70
    private int iStartPos = 0;
70
71
Lines 81-86 Link Here
81
    private void setBlockTextInfo(TextInfo ti) {
82
    private void setBlockTextInfo(TextInfo ti) {
82
        lead = ti.fs.getAscender();
83
        lead = ti.fs.getAscender();
83
        follow = -ti.fs.getDescender();
84
        follow = -ti.fs.getDescender();
85
        middleShift = - ti.fs.getXHeight() / 2;
84
        lineHeight = ti.lineHeight;
86
        lineHeight = ti.lineHeight;
85
    }
87
    }
86
88
Lines 156-162 Link Here
156
     */
158
     */
157
    private LineLayoutManager createLineManager(LayoutManager firstlm) {
159
    private LineLayoutManager createLineManager(LayoutManager firstlm) {
158
        LineLayoutManager llm;
160
        LineLayoutManager llm;
159
        llm = new LineLayoutManager(fobj, lineHeight, lead, follow);
161
        llm = new LineLayoutManager(fobj, lineHeight, lead, follow, middleShift);
160
        List inlines = new ArrayList();
162
        List inlines = new ArrayList();
161
        inlines.add(firstlm);
163
        inlines.add(firstlm);
162
        while (proxyLMiter.hasNext()) {
164
        while (proxyLMiter.hasNext()) {
(-)old/layoutmgr/CharacterLayoutManager.java (-10 / +10 lines)
Lines 47-52 Link Here
47
        super(node);
47
        super(node);
48
        InlineArea inline = getCharacterInlineArea(node);
48
        InlineArea inline = getCharacterInlineArea(node);
49
        setCurrentArea(inline);
49
        setCurrentArea(inline);
50
        setAlignment(node.getPropEnum(PR_VERTICAL_ALIGN));
50
51
51
        textInfo = node.getPropertyManager().getTextLayoutProps
52
        textInfo = node.getPropertyManager().getTextLayoutProps
52
            (node.getFOEventHandler().getFontInfo());
53
            (node.getFOEventHandler().getFontInfo());
Lines 74-88 Link Here
74
     */
75
     */
75
    protected void offsetArea(LayoutContext context) {
76
    protected void offsetArea(LayoutContext context) {
76
        int bpd = curArea.getBPD();
77
        int bpd = curArea.getBPD();
77
        switch (alignment) {
78
        switch (verticalAlignment) {
78
            case VerticalAlign.MIDDLE:
79
            case VerticalAlign.MIDDLE:
79
                curArea.setOffset(context.getBaseline() - bpd / 2 /* - fontLead/2 */);
80
                curArea.setOffset(context.getMiddleBaseline() + textInfo.fs.getXHeight() / 2);
80
            break;
81
            break;
81
            case VerticalAlign.TOP:
82
            case VerticalAlign.TOP:
82
                //curArea.setOffset(0);
83
                curArea.setOffset(textInfo.fs.getAscender());
83
            break;
84
            break;
84
            case VerticalAlign.BOTTOM:
85
            case VerticalAlign.BOTTOM:
85
                curArea.setOffset(context.getLineHeight() - bpd);
86
                curArea.setOffset(context.getLineHeight() - bpd + textInfo.fs.getAscender());
86
            break;
87
            break;
87
            case VerticalAlign.BASELINE:
88
            case VerticalAlign.BASELINE:
88
            default:
89
            default:
Lines 121-136 Link Here
121
        int lead = 0;
122
        int lead = 0;
122
        int total = 0;
123
        int total = 0;
123
        int middle = 0;
124
        int middle = 0;
124
        switch (alignment) {
125
        switch (verticalAlignment) {
125
            case VerticalAlign.MIDDLE  : middle = bpd / 2 ;
126
            case VerticalAlign.MIDDLE  : middle = bpd / 2 ;
126
                                         lead = bpd / 2 ;
127
                                         break;
128
            case VerticalAlign.TOP     : total = bpd;
129
                                         break;
127
                                         break;
128
            case VerticalAlign.TOP     : // fall through
130
            case VerticalAlign.BOTTOM  : total = bpd;
129
            case VerticalAlign.BOTTOM  : total = bpd;
131
                                         break;
130
                                         break;
132
            case VerticalAlign.BASELINE:
131
            case VerticalAlign.BASELINE: // fall through
133
            default:                     lead = bpd;
132
            default                    : lead = textInfo.fs.getAscender();
133
                                         total = bpd;
134
                                         break;
134
                                         break;
135
        }
135
        }
136
136
(-)old/layoutmgr/ContentLayoutManager.java (-13 / +39 lines)
Lines 22-27 Link Here
22
import org.apache.fop.apps.FOUserAgent;
22
import org.apache.fop.apps.FOUserAgent;
23
import org.apache.fop.fo.flow.Marker;
23
import org.apache.fop.fo.flow.Marker;
24
import org.apache.fop.area.Area;
24
import org.apache.fop.area.Area;
25
import org.apache.fop.area.inline.InlineArea;
25
import org.apache.fop.area.Resolveable;
26
import org.apache.fop.area.Resolveable;
26
import org.apache.fop.area.PageViewport;
27
import org.apache.fop.area.PageViewport;
27
28
Lines 40-51 Link Here
40
 * For use with objects that contain inline areas such as
41
 * For use with objects that contain inline areas such as
41
 * leader use-content and title.
42
 * leader use-content and title.
42
 */
43
 */
43
public class ContentLayoutManager implements LayoutManager {
44
public class ContentLayoutManager implements InlineLayoutManager {
44
    private FOUserAgent userAgent;
45
    private FOUserAgent userAgent;
45
    private Area holder;
46
    private Area holder;
46
    private int stackSize;
47
    private int stackSize;
47
    private LayoutManager parentLM;
48
    private LayoutManager parentLM;
48
    private List childLMs = new ArrayList(1);
49
    private InlineLayoutManager childLM = null;
49
50
50
    /**
51
    /**
51
     * logging instance
52
     * logging instance
Lines 137-142 Link Here
137
        stackSize = stack.opt;
138
        stackSize = stack.opt;
138
    }
139
    }
139
140
141
    public void addAreas(PositionIterator posIter, LayoutContext context) {
142
        // add the content areas
143
        // the area width has already been adjusted, and it must remain unchanged
144
        // so save its value before calling addAreas, and set it again afterwards
145
        int savedIPD = ((InlineArea)holder).getIPD();
146
        // set to zero the ipd adjustment ratio, to avoid spaces in the pattern
147
        // to be modified
148
        LayoutContext childContext = new LayoutContext(context);
149
        childContext.setIPDAdjust(0.0);
150
        childLM.addAreas(posIter, childContext);
151
        ((InlineArea)holder).setIPD(savedIPD);
152
    }
153
140
    public int getStackingSize() {
154
    public int getStackingSize() {
141
        return stackSize;
155
        return stackSize;
142
    }
156
    }
Lines 202-210 Link Here
202
    }
216
    }
203
217
204
    /** @see org.apache.fop.layoutmgr.LayoutManager */
218
    /** @see org.apache.fop.layoutmgr.LayoutManager */
205
    public void addAreas(PositionIterator posIter, LayoutContext context) { }
206
207
    /** @see org.apache.fop.layoutmgr.LayoutManager */
208
    public void initialize() {
219
    public void initialize() {
209
        //to be done
220
        //to be done
210
    }
221
    }
Lines 259-264 Link Here
259
     * @see org.apache.fop.layoutmgr.LayoutManager#getChildLMs
270
     * @see org.apache.fop.layoutmgr.LayoutManager#getChildLMs
260
     */
271
     */
261
    public List getChildLMs() {
272
    public List getChildLMs() {
273
        List childLMs = new ArrayList(1);
274
        childLMs.add(childLM);
262
        return childLMs;
275
        return childLMs;
263
    }
276
    }
264
277
Lines 271-277 Link Here
271
        }
284
        }
272
        lm.setParent(this);
285
        lm.setParent(this);
273
        lm.initialize();
286
        lm.initialize();
274
        childLMs.add(lm);
287
        childLM = (InlineLayoutManager)lm;
275
        log.trace(this.getClass().getName()
288
        log.trace(this.getClass().getName()
276
                  + ": Adding child LM " + lm.getClass().getName());
289
                  + ": Adding child LM " + lm.getClass().getName());
277
    }
290
    }
Lines 290-299 Link Here
290
        }
303
        }
291
    }
304
    }
292
305
293
    public LinkedList getNextKnuthElements(LayoutContext context,
306
    public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
294
                                           int alignment) {
307
        LinkedList contentList = new LinkedList();
308
        LinkedList returnedList;
309
310
        while (!childLM.isFinished()) {
311
            // get KnuthElements from childLM
312
            returnedList = childLM.getNextKnuthElements(context, alignment);
313
314
            if (returnedList != null) {
315
                // move elements to contentList, and accumulate their size
316
               KnuthElement contentElement;
317
               while (returnedList.size() > 0) {
318
                    contentElement = (KnuthElement)returnedList.removeFirst();
319
                    stackSize += contentElement.getW();
320
                    contentList.add(contentElement);
321
                }
322
            }
323
        }
324
295
        setFinished(true);
325
        setFinished(true);
296
        return null;
326
        return contentList;
297
    }
327
    }
298
328
299
    public KnuthElement addALetterSpaceTo(KnuthElement element) {
329
    public KnuthElement addALetterSpaceTo(KnuthElement element) {
Lines 314-323 Link Here
314
                                              int flaggedPenalty,
344
                                              int flaggedPenalty,
315
                                              int alignment) {
345
                                              int alignment) {
316
        return null;
346
        return null;
317
    }
318
319
    public int getWordSpaceIPD() {
320
        return 0;
321
    }
347
    }
322
}
348
}
323
349
(-)old/layoutmgr/InlineLayoutManager.java (+84 lines)
Line 0 Link Here
1
/*
2
 * Copyright 1999-2004 The Apache Software Foundation.
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 * 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 * 
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
/* $Id$ */
18
 
19
package org.apache.fop.layoutmgr;
20
21
import java.util.LinkedList;
22
import java.util.List;
23
24
/**
25
 * The interface for LayoutManagers which generate inline areas
26
 */
27
public interface InlineLayoutManager extends LayoutManager {
28
29
    /**
30
     * Get a sequence of KnuthElements representing the content 
31
     * of the node assigned to the LM
32
     * 
33
     * @param context   the LayoutContext used to store layout information
34
     * @param alignment the desired text alignement
35
     * @return          the list of KnuthElements
36
     */
37
    LinkedList getNextKnuthElements(LayoutContext context, int alignment);
38
39
    /**
40
     * Tell the LM to modify its data, adding a letter space 
41
     * to the word fragment represented by the given element,
42
     * and returning a corrected element
43
     *
44
     * @param element the element which must be given one more letter space
45
     * @return        the new element replacing the old one
46
     */
47
    KnuthElement addALetterSpaceTo(KnuthElement element);
48
49
    /**
50
     * Get the word chars corresponding to the given position
51
     *
52
     * @param sbChars the StringBuffer used to append word chars
53
     * @param pos     the Position referring to the needed word chars
54
     */
55
    void getWordChars(StringBuffer sbChars, Position pos);
56
57
    /**
58
     * Tell the LM to hyphenate a word
59
     *
60
     * @param pos the Position referring to the word
61
     * @param hc  the HyphContext storing hyphenation information
62
     */
63
    void hyphenate(Position pos, HyphContext hc);
64
65
    /**
66
     * Tell the LM to apply the changes due to hyphenation
67
     *
68
     * @param oldList the list of the old elements the changes refer to
69
     * @return        true if the LM had to change its data, false otherwise
70
     */
71
    boolean applyChanges(List oldList);
72
73
    /**
74
     * Get a sequence of KnuthElements representing the content 
75
     * of the node assigned to the LM, after changes have been applied
76
     *
77
     * @param oldList        the elements to replace
78
     * @param flaggedPenalty the penalty value for hyphenated lines
79
     * @param alignment      the desired text alignment
80
     * @return               the updated list of KnuthElements
81
     */
82
    LinkedList getChangedKnuthElements(List oldList, int flaggedPenalty,
83
                                       int alignment);
84
}
(-)old/layoutmgr/InlineStackingLayoutManager.java (-103 / +19 lines)
Lines 39-45 Link Here
39
 * LayoutManager for objects which stack children in the inline direction,
39
 * LayoutManager for objects which stack children in the inline direction,
40
 * such as Inline or Line
40
 * such as Inline or Line
41
 */
41
 */
42
public class InlineStackingLayoutManager extends AbstractLayoutManager {
42
public class InlineStackingLayoutManager extends AbstractLayoutManager
43
                                         implements InlineLayoutManager {
43
44
44
45
45
    private static class StackingIter extends PositionIterator {
46
    private static class StackingIter extends PositionIterator {
Lines 222-307 Link Here
222
        hmPrevIPD.clear();
223
        hmPrevIPD.clear();
223
    }
224
    }
224
225
225
    /**
226
     * Get the next break position for this layout manager.
227
     * The next break position will be an position within the
228
     * areas return by the child inline layout managers.
229
     *
230
     * @param lc the layout context for finding breaks
231
     * @return the next break position
232
     */
233
    public BreakPoss getNextBreakPoss(LayoutContext lc) {
234
        // Get a break from currently active child LM
235
        BreakPoss bp = null;
236
        LayoutManager curLM;
237
        SpaceSpecifier leadingSpace = lc.getLeadingSpace();
238
239
        if (lc.startsNewArea()) {
240
            // First call to this LM in new parent "area", but this may
241
            // not be the first area created by this inline
242
            childLC = new LayoutContext(lc);
243
            lc.getLeadingSpace().addSpace(inlineProps.spaceStart);
244
245
            // Check for "fence"
246
            if (hasLeadingFence(!lc.isFirstArea())) {
247
                // Reset leading space sequence for child areas
248
                leadingSpace = new SpaceSpecifier(false);
249
            }
250
            // Reset state variables
251
            clearPrevIPD(); // Clear stored prev content dimensions
252
        }
253
254
        // We only do this loop more than once if a childLM returns
255
        // a null BreakPoss, meaning it has nothing (more) to layout.
256
        while ((curLM = getChildLM()) != null) {
257
258
            // ignore nested blocks for now
259
            if (!curLM.generatesInlineAreas()) {
260
                log.warn("ignoring block inside inline fo");
261
                curLM.setFinished(true);
262
                continue;
263
            }
264
            /* If first break for this child LM, set START_AREA flag
265
             * and initialize pending space from previous LM sibling's
266
             * trailing space specifiers.
267
             */
268
            boolean bFirstChildBP = (prevBP == null
269
                                     || prevBP.getLayoutManager() != curLM);
270
271
            initChildLC(childLC, prevBP, lc.startsNewArea(),
272
                        bFirstChildBP, leadingSpace);
273
            if (lc.tryHyphenate()) {
274
                childLC.setHyphContext(lc.getHyphContext());
275
            }
276
277
            if (((bp = curLM.getNextBreakPoss(childLC)) != null)
278
                    || (lc.tryHyphenate()
279
                    && !lc.getHyphContext().hasMoreHyphPoints())) {
280
                break;
281
            }
282
            // If LM has no content, should it generate any area? If not,
283
            // should trailing space from a previous area interact with
284
            // leading space from a following area?
285
        }
286
        if (bp == null) {
287
            setFinished(true);
288
            return null; // There was no childLM with anything to layout
289
            // Alternative is to return a BP with the isLast flag set
290
        } else {
291
            boolean bIsLast = false;
292
            if (getChildLM() == null) {
293
                bIsLast = true;
294
                setFinished(true);
295
            } else if (bp.couldEndLine()) {
296
                /* Child LM ends with suppressible spaces. See if it could
297
                 * end this LM's area too. Child LM finish flag is NOT set!
298
                 */
299
                bIsLast = !hasMoreLM(bp.getLayoutManager());
300
            }
301
            return makeBreakPoss(bp, lc, bIsLast);
302
        }
303
    }
304
305
    /** ATTENTION: ALSO USED BY LineLayoutManager! */
226
    /** ATTENTION: ALSO USED BY LineLayoutManager! */
306
    protected void initChildLC(LayoutContext childLC, BreakPoss prevBP,
227
    protected void initChildLC(LayoutContext childLC, BreakPoss prevBP,
307
                               boolean bStartParent, boolean bFirstChildBP,
228
                               boolean bStartParent, boolean bFirstChildBP,
Lines 487-494 Link Here
487
            = new StackingIter(positionList.listIterator());
408
            = new StackingIter(positionList.listIterator());
488
409
489
        LayoutManager prevLM = null;
410
        LayoutManager prevLM = null;
490
        LayoutManager childLM ;
411
        InlineLayoutManager childLM ;
491
        while ((childLM = childPosIter.getNextChildLM()) != null) {
412
        while ((childLM = (InlineLayoutManager) childPosIter.getNextChildLM())
413
               != null) {
492
            getContext().setFlags(LayoutContext.LAST_AREA,
414
            getContext().setFlags(LayoutContext.LAST_AREA,
493
                                  context.isLastArea() && childLM == lastLM);
415
                                  context.isLastArea() && childLM == lastLM);
494
            childLM.addAreas(childPosIter, getContext());
416
            childLM.addAreas(childPosIter, getContext());
Lines 590-596 Link Here
590
    }
512
    }
591
513
592
    public LinkedList getNextKnuthElements(LayoutContext lc, int alignment) {
514
    public LinkedList getNextKnuthElements(LayoutContext lc, int alignment) {
593
        LayoutManager curLM;
515
        InlineLayoutManager curLM;
594
516
595
        // the list returned by child LM
517
        // the list returned by child LM
596
        LinkedList returnedList;
518
        LinkedList returnedList;
Lines 616-622 Link Here
616
            clearPrevIPD(); // Clear stored prev content dimensions
538
            clearPrevIPD(); // Clear stored prev content dimensions
617
        }
539
        }
618
540
619
        while ((curLM = getChildLM()) != null) {
541
        while ((curLM = (InlineLayoutManager) getChildLM()) != null) {
620
            // get KnuthElements from curLM
542
            // get KnuthElements from curLM
621
            returnedList = curLM.getNextKnuthElements(lc, alignment);
543
            returnedList = curLM.getNextKnuthElements(lc, alignment);
622
            if (returnedList != null) {
544
            if (returnedList != null) {
Lines 644-650 Link Here
644
        element.setPosition(savedPos.getPosition());
566
        element.setPosition(savedPos.getPosition());
645
567
646
        KnuthElement newElement
568
        KnuthElement newElement
647
            = element.getLayoutManager().addALetterSpaceTo(element);
569
            = ((InlineLayoutManager)
570
               element.getLayoutManager()).addALetterSpaceTo(element);
648
        newElement.setPosition
571
        newElement.setPosition
649
            (new NonLeafPosition(this, newElement.getPosition()));
572
            (new NonLeafPosition(this, newElement.getPosition()));
650
        element.setPosition(savedPos);
573
        element.setPosition(savedPos);
Lines 653-664 Link Here
653
576
654
    public void getWordChars(StringBuffer sbChars, Position pos) {
577
    public void getWordChars(StringBuffer sbChars, Position pos) {
655
        Position newPos = ((NonLeafPosition) pos).getPosition();
578
        Position newPos = ((NonLeafPosition) pos).getPosition();
656
        newPos.getLM().getWordChars(sbChars, newPos);
579
        ((InlineLayoutManager)
580
         newPos.getLM()).getWordChars(sbChars, newPos);
657
    }
581
    }
658
582
659
    public void hyphenate(Position pos, HyphContext hc) {
583
    public void hyphenate(Position pos, HyphContext hc) {
660
        Position newPos = ((NonLeafPosition) pos).getPosition();
584
        Position newPos = ((NonLeafPosition) pos).getPosition();
661
        newPos.getLM().hyphenate(newPos, hc);
585
        ((InlineLayoutManager)
586
         newPos.getLM()).hyphenate(newPos, hc);
662
    }
587
    }
663
588
664
    public boolean applyChanges(List oldList) {
589
    public boolean applyChanges(List oldList) {
Lines 673-686 Link Here
673
        // reset the iterator
598
        // reset the iterator
674
        oldListIterator = oldList.listIterator();
599
        oldListIterator = oldList.listIterator();
675
600
676
        LayoutManager prevLM = null;
601
        InlineLayoutManager prevLM = null;
677
        LayoutManager currLM;
602
        InlineLayoutManager currLM;
678
        int fromIndex = 0;
603
        int fromIndex = 0;
679
604
680
        boolean bSomethingChanged = false;
605
        boolean bSomethingChanged = false;
681
        while(oldListIterator.hasNext()) {
606
        while(oldListIterator.hasNext()) {
682
            oldElement = (KnuthElement) oldListIterator.next();
607
            oldElement = (KnuthElement) oldListIterator.next();
683
            currLM = oldElement.getLayoutManager();
608
            currLM = (InlineLayoutManager) oldElement.getLayoutManager();
684
            // initialize prevLM
609
            // initialize prevLM
685
            if (prevLM == null) {
610
            if (prevLM == null) {
686
                prevLM = currLM;
611
                prevLM = currLM;
Lines 733-745 Link Here
733
        KnuthElement returnedElement;
658
        KnuthElement returnedElement;
734
        LinkedList returnedList = new LinkedList();
659
        LinkedList returnedList = new LinkedList();
735
        LinkedList returnList = new LinkedList();
660
        LinkedList returnList = new LinkedList();
736
        LayoutManager prevLM = null;
661
        InlineLayoutManager prevLM = null;
737
        LayoutManager currLM;
662
        InlineLayoutManager currLM;
738
        int fromIndex = 0;
663
        int fromIndex = 0;
739
664
740
        while(oldListIterator.hasNext()) {
665
        while(oldListIterator.hasNext()) {
741
            oldElement = (KnuthElement) oldListIterator.next();
666
            oldElement = (KnuthElement) oldListIterator.next();
742
            currLM = oldElement.getLayoutManager();
667
            currLM = (InlineLayoutManager) oldElement.getLayoutManager();
743
            if (prevLM == null) {
668
            if (prevLM == null) {
744
                prevLM = currLM;
669
                prevLM = currLM;
745
            }
670
            }
Lines 782-796 Link Here
782
            returnList.add(returnedElement);
707
            returnList.add(returnedElement);
783
        }
708
        }
784
        return returnList;
709
        return returnList;
785
    }
786
787
    public int getWordSpaceIPD() {
788
        LayoutManager firstChild = getChildLM();
789
        if (firstChild != null) {
790
            return firstChild.getWordSpaceIPD();
791
        } else {
792
            return 0;
793
        }
794
    }
710
    }
795
}
711
}
796
712
(-)old/layoutmgr/LayoutContext.java (+11 lines)
Lines 86-91 Link Here
86
86
87
    private int iLineHeight;
87
    private int iLineHeight;
88
    private int iBaseline;
88
    private int iBaseline;
89
    private int iMiddleShift;
89
90
90
    public LayoutContext(LayoutContext parentLC) {
91
    public LayoutContext(LayoutContext parentLC) {
91
        this.flags = parentLC.flags;
92
        this.flags = parentLC.flags;
Lines 98-103 Link Here
98
        this.ipdAdjust = parentLC.ipdAdjust;
99
        this.ipdAdjust = parentLC.ipdAdjust;
99
        this.iLineHeight = parentLC.iLineHeight;
100
        this.iLineHeight = parentLC.iLineHeight;
100
        this.iBaseline = parentLC.iBaseline;
101
        this.iBaseline = parentLC.iBaseline;
102
        this.iMiddleShift = parentLC.iMiddleShift;
101
        // Copy other fields as necessary. Use clone???
103
        // Copy other fields as necessary. Use clone???
102
    }
104
    }
103
105
Lines 225-230 Link Here
225
        return iBaseline;
227
        return iBaseline;
226
    }
228
    }
227
    
229
    
230
    public void setMiddleShift(int ms) {
231
        iMiddleShift = ms;
232
    }
233
234
    public int getMiddleBaseline() {
235
        return iBaseline + iMiddleShift;
236
    }
237
    
228
    public String toString() {
238
    public String toString() {
229
        return "Layout Context:" +
239
        return "Layout Context:" +
230
        "\nStack Limit: \t" + (getStackLimit() == null ? "null" : getStackLimit().toString()) +
240
        "\nStack Limit: \t" + (getStackLimit() == null ? "null" : getStackLimit().toString()) +
Lines 235-240 Link Here
235
        "\nIPD Adjust: \t" + getIPDAdjust() +
245
        "\nIPD Adjust: \t" + getIPDAdjust() +
236
        "\nLine Height: \t" + getLineHeight() +
246
        "\nLine Height: \t" + getLineHeight() +
237
        "\nBaseline: \t" + getBaseline() +
247
        "\nBaseline: \t" + getBaseline() +
248
        "\nMiddleBaseline: \t" + getMiddleBaseline() +
238
        "\nResolve Leading Space: \t" + resolveLeadingSpace() +
249
        "\nResolve Leading Space: \t" + resolveLeadingSpace() +
239
        "\nSuppress Leading Space: \t" + suppressLeadingSpace() +
250
        "\nSuppress Leading Space: \t" + suppressLeadingSpace() +
240
        "\nIs First Area: \t" + isFirstArea() + 
251
        "\nIs First Area: \t" + isFirstArea() + 
(-)old/layoutmgr/LayoutManager.java (-16 lines)
Lines 18-24 Link Here
18
 
18
 
19
package org.apache.fop.layoutmgr;
19
package org.apache.fop.layoutmgr;
20
20
21
import java.util.LinkedList;
22
import java.util.List;
21
import java.util.List;
23
import java.util.Map;
22
import java.util.Map;
24
23
Lines 237-255 Link Here
237
     * @param newLMs the list of LMs to be added
236
     * @param newLMs the list of LMs to be added
238
     */
237
     */
239
    void addChildLMs(List newLMs);
238
    void addChildLMs(List newLMs);
240
241
    LinkedList getNextKnuthElements(LayoutContext context, int alignment);
242
243
    KnuthElement addALetterSpaceTo(KnuthElement element);
244
245
    void getWordChars(StringBuffer sbChars, Position pos);
246
247
    void hyphenate(Position pos, HyphContext hc);
248
249
    boolean applyChanges(List oldList);
250
251
    LinkedList getChangedKnuthElements(List oldList, int flaggedPenalty,
252
                                       int alignment);
253
254
    int getWordSpaceIPD();
255
}
239
}
(-)old/layoutmgr/LeaderLayoutManager.java (-10 / +97 lines)
Lines 23-28 Link Here
23
import org.apache.fop.area.inline.InlineArea;
23
import org.apache.fop.area.inline.InlineArea;
24
import org.apache.fop.area.inline.Space;
24
import org.apache.fop.area.inline.Space;
25
import org.apache.fop.area.inline.TextArea;
25
import org.apache.fop.area.inline.TextArea;
26
import org.apache.fop.datatypes.Length;
27
import org.apache.fop.fo.Constants;
28
import org.apache.fop.fo.flow.Inline;
26
import org.apache.fop.fo.flow.Leader;
29
import org.apache.fop.fo.flow.Leader;
27
import org.apache.fop.fonts.Font;
30
import org.apache.fop.fonts.Font;
28
import org.apache.fop.traits.MinOptMax;
31
import org.apache.fop.traits.MinOptMax;
Lines 38-43 Link Here
38
    Leader ldrNode;
41
    Leader ldrNode;
39
    Font font = null;
42
    Font font = null;
40
    
43
    
44
    private LinkedList contentList = null;
45
    private ContentLayoutManager clm = null;
46
41
    /**
47
    /**
42
     * Constructor
48
     * Constructor
43
     *
49
     *
Lines 48-54 Link Here
48
        super(node);
54
        super(node);
49
        ldrNode = node;
55
        ldrNode = node;
50
        font = node.getFontState();
56
        font = node.getFontState();
51
        setAlignment(node.getPropEnum(PR_LEADER_ALIGNMENT));
57
        setAlignment(node.getPropEnum(PR_VERTICAL_ALIGN));
52
    }
58
    }
53
59
54
    public InlineArea get(LayoutContext context) {
60
    public InlineArea get(LayoutContext context) {
Lines 83-92 Link Here
83
            char dot = '.'; // userAgent.getLeaderDotCharacter();
89
            char dot = '.'; // userAgent.getLeaderDotCharacter();
84
90
85
            t.setTextArea("" + dot);
91
            t.setTextArea("" + dot);
92
            t.setIPD(font.getCharWidth(dot));
86
            t.addTrait(Trait.FONT_NAME, font.getFontName());
93
            t.addTrait(Trait.FONT_NAME, font.getFontName());
87
            t.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
94
            t.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
88
            // set offset of dot within inline parent
89
            t.setOffset(font.getAscender());
90
            int width = font.getCharWidth(dot);
95
            int width = font.getCharWidth(dot);
91
            Space spacer = null;
96
            Space spacer = null;
92
            if (ldrNode.getPatternWidth() > width) {
97
            if (ldrNode.getPatternWidth() > width) {
Lines 115-121 Link Here
115
            // get breaks then add areas to FilledArea
120
            // get breaks then add areas to FilledArea
116
            FilledArea fa = new FilledArea();
121
            FilledArea fa = new FilledArea();
117
122
118
            ContentLayoutManager clm = new ContentLayoutManager(fa);
123
            clm = new ContentLayoutManager(fa);
119
            clm.setUserAgent(ldrNode.getUserAgent());
124
            clm.setUserAgent(ldrNode.getUserAgent());
120
            addChildLM(clm);
125
            addChildLM(clm);
121
126
Lines 123-129 Link Here
123
            lm = new InlineStackingLayoutManager(ldrNode);
128
            lm = new InlineStackingLayoutManager(ldrNode);
124
            clm.addChildLM(lm);
129
            clm.addChildLM(lm);
125
130
126
            clm.fillArea(lm);
131
            contentList = clm.getNextKnuthElements(new LayoutContext(0), 0);
127
            int width = clm.getStackingSize();
132
            int width = clm.getStackingSize();
128
            Space spacer = null;
133
            Space spacer = null;
129
            if (ldrNode.getPatternWidth() > width) {
134
            if (ldrNode.getPatternWidth() > width) {
Lines 140-145 Link Here
140
        return leaderArea;
145
        return leaderArea;
141
     }
146
     }
142
147
148
    protected void offsetArea(LayoutContext context) {
149
        int pattern = ldrNode.getLeaderPattern();
150
        int bpd = curArea.getBPD();
151
152
        switch (pattern) {
153
            case LeaderPattern.RULE: 
154
                switch (verticalAlignment) {
155
                    case VerticalAlign.TOP:
156
                        curArea.setOffset(0);
157
                    break;
158
                    case VerticalAlign.MIDDLE:
159
                        curArea.setOffset(context.getMiddleBaseline() - bpd / 2);
160
                    break;
161
                    case VerticalAlign.BOTTOM:
162
                        curArea.setOffset(context.getLineHeight() - bpd);
163
                    break;
164
                    case VerticalAlign.BASELINE: // fall through
165
                    default:
166
                        curArea.setOffset(context.getBaseline() - bpd);
167
                    break;
168
                }
169
            break;
170
            case LeaderPattern.DOTS: 
171
                switch (verticalAlignment) {
172
                    case VerticalAlign.TOP:
173
                        curArea.setOffset(0);
174
                    break;
175
                    case VerticalAlign.MIDDLE:
176
                        curArea.setOffset(context.getMiddleBaseline());
177
                    break;
178
                    case VerticalAlign.BOTTOM:
179
                        curArea.setOffset(context.getLineHeight() - bpd + font.getAscender());
180
                    break;
181
                    case VerticalAlign.BASELINE: // fall through
182
                    default:
183
                        curArea.setOffset(context.getBaseline());
184
                    break;
185
                }
186
            break;
187
            case LeaderPattern.SPACE: 
188
                // nothing to do
189
            break;
190
            case LeaderPattern.USECONTENT: 
191
                switch (verticalAlignment) {
192
                    case VerticalAlign.TOP:
193
                        curArea.setOffset(0);
194
                    break;
195
                    case VerticalAlign.MIDDLE:
196
                        curArea.setOffset(context.getMiddleBaseline());
197
                    break;
198
                    case VerticalAlign.BOTTOM:
199
                        curArea.setOffset(context.getLineHeight() - bpd);
200
                    break;
201
                    case VerticalAlign.BASELINE: // fall through
202
                    default:
203
                        curArea.setOffset(context.getBaseline());
204
                    break;
205
                }
206
            break;
207
        }
208
    }
209
210
    public void addAreas(PositionIterator posIter, LayoutContext context) {
211
        if (ldrNode.getLeaderPattern() != LeaderPattern.USECONTENT) {
212
            // use LeafNodeLayoutManager.addAreas()
213
            super.addAreas(posIter, context);
214
        } else {
215
            addID();
216
217
            widthAdjustArea(context);
218
219
            // add content areas
220
            KnuthPossPosIter contentIter = new KnuthPossPosIter(contentList, 0, contentList.size());
221
            clm.addAreas(contentIter, context);
222
            offsetArea(context);
223
224
            parentLM.addChild(curArea);
225
226
            while (posIter.hasNext()) {
227
                posIter.next();
228
            }
229
        }
230
    }
231
143
    public LinkedList getNextKnuthElements(LayoutContext context,
232
    public LinkedList getNextKnuthElements(LayoutContext context,
144
                                           int alignment) {
233
                                           int alignment) {
145
        MinOptMax ipd;
234
        MinOptMax ipd;
Lines 157-171 Link Here
157
        int lead = 0;
246
        int lead = 0;
158
        int total = 0;
247
        int total = 0;
159
        int middle = 0;
248
        int middle = 0;
160
        switch (alignment) {
249
        switch (verticalAlignment) {
161
            case VerticalAlign.MIDDLE  : middle = bpd / 2 ;
250
            case VerticalAlign.MIDDLE  : middle = bpd / 2 ;
162
                                         lead = bpd / 2 ;
163
                                         break;
164
            case VerticalAlign.TOP     : total = bpd;
165
                                         break;
251
                                         break;
252
            case VerticalAlign.TOP     : // fall through
166
            case VerticalAlign.BOTTOM  : total = bpd;
253
            case VerticalAlign.BOTTOM  : total = bpd;
167
                                         break;
254
                                         break;
168
            case VerticalAlign.BASELINE:
255
            case VerticalAlign.BASELINE: // fall through
169
            default:                     lead = bpd;
256
            default:                     lead = bpd;
170
                                         break;
257
                                         break;
171
        }
258
        }
(-)old/layoutmgr/LeafNodeLayoutManager.java (-64 / +7 lines)
Lines 33-44 Link Here
33
 * This class can be extended to handle the creation and adding of the
33
 * This class can be extended to handle the creation and adding of the
34
 * inline area.
34
 * inline area.
35
 */
35
 */
36
public class LeafNodeLayoutManager extends AbstractLayoutManager {
36
public class LeafNodeLayoutManager extends AbstractLayoutManager 
37
                                   implements InlineLayoutManager {
37
    /**
38
    /**
38
     * The inline area that this leafnode will add.
39
     * The inline area that this leafnode will add.
39
     */
40
     */
40
    protected InlineArea curArea = null;
41
    protected InlineArea curArea = null;
41
    protected int alignment;
42
    protected int verticalAlignment;
42
    private int lead;
43
    private int lead;
43
    private MinOptMax ipd;
44
    private MinOptMax ipd;
44
45
Lines 122-128 Link Here
122
     * @param al the vertical alignment positioning
123
     * @param al the vertical alignment positioning
123
     */
124
     */
124
    public void setAlignment(int al) {
125
    public void setAlignment(int al) {
125
        alignment = al;
126
        verticalAlignment = al;
126
    }
127
    }
127
128
128
    /**
129
    /**
Lines 153-201 Link Here
153
    }
154
    }
154
155
155
    /**
156
    /**
156
     * Get the next break position.
157
     * Since this holds an inline area it will return a single
158
     * break position.
159
     * @param context the layout context for this inline area
160
     * @return the break poisition for adding this inline area
161
     */
162
    public BreakPoss getNextBreakPoss(LayoutContext context) {
163
        curArea = get(context);
164
        if (curArea == null) {
165
            setFinished(true);
166
            return null;
167
        }
168
        BreakPoss bp = new BreakPoss(new LeafPosition(this, 0),
169
                                     BreakPoss.CAN_BREAK_AFTER
170
                                     | BreakPoss.CAN_BREAK_BEFORE | BreakPoss.ISFIRST
171
                                     | BreakPoss.ISLAST);
172
        ipd = getAllocationIPD(context.getRefIPD());
173
        bp.setStackingSize(ipd);
174
        bp.setNonStackingSize(new MinOptMax(curArea.getBPD()));
175
        bp.setTrailingSpace(new SpaceSpecifier(false));
176
177
        int bpd = curArea.getBPD();
178
        switch (alignment) {
179
            case VerticalAlign.MIDDLE:
180
                bp.setMiddle(bpd / 2 /* - fontLead/2 */);
181
                bp.setLead(bpd / 2 /* + fontLead/2 */);
182
            break;
183
            case VerticalAlign.TOP:
184
                bp.setTotal(bpd);
185
            break;
186
            case VerticalAlign.BOTTOM:
187
                bp.setTotal(bpd);
188
            break;
189
            case VerticalAlign.BASELINE:
190
            default:
191
                bp.setLead(bpd);
192
            break;
193
        }
194
        setFinished(true);
195
        return bp;
196
    }
197
198
    /**
199
     * Get the allocation ipd of the inline area.
157
     * Get the allocation ipd of the inline area.
200
     * This method may be overridden to handle percentage values.
158
     * This method may be overridden to handle percentage values.
201
     * @param refIPD the ipd of the parent reference area
159
     * @param refIPD the ipd of the parent reference area
Lines 206-224 Link Here
206
    }
164
    }
207
165
208
    /**
166
    /**
209
     * Reset the position.
210
     * If the reset position is null then this inline area should be
211
     * restarted.
212
     * @param resetPos the position to reset.
213
     */
214
    public void resetPosition(Position resetPos) {
215
        // only reset if setting null, start again
216
        if (resetPos == null) {
217
            setFinished(false);
218
        }
219
    }
220
221
    /**
222
     * Add the area for this layout manager.
167
     * Add the area for this layout manager.
223
     * This adds the single inline area to the parent.
168
     * This adds the single inline area to the parent.
224
     * @param posIter the position iterator
169
     * @param posIter the position iterator
Lines 246-254 Link Here
246
     */
191
     */
247
    protected void offsetArea(LayoutContext context) {
192
    protected void offsetArea(LayoutContext context) {
248
        int bpd = curArea.getBPD();
193
        int bpd = curArea.getBPD();
249
        switch (alignment) {
194
        switch (verticalAlignment) {
250
            case VerticalAlign.MIDDLE:
195
            case VerticalAlign.MIDDLE:
251
                curArea.setOffset(context.getBaseline() - bpd / 2 /* - fontLead/2 */);
196
                curArea.setOffset(context.getMiddleBaseline() - bpd / 2);
252
            break;
197
            break;
253
            case VerticalAlign.TOP:
198
            case VerticalAlign.TOP:
254
                //curArea.setOffset(0);
199
                //curArea.setOffset(0);
Lines 307-313 Link Here
307
        int lead = 0;
252
        int lead = 0;
308
        int total = 0;
253
        int total = 0;
309
        int middle = 0;
254
        int middle = 0;
310
        switch (alignment) {
255
        switch (verticalAlignment) {
311
            case VerticalAlign.MIDDLE  : middle = bpd / 2 ;
256
            case VerticalAlign.MIDDLE  : middle = bpd / 2 ;
312
                                         lead = bpd / 2 ;
257
                                         lead = bpd / 2 ;
313
                                         break;
258
                                         break;
Lines 341-348 Link Here
341
    }
286
    }
342
287
343
    public void hyphenate(Position pos, HyphContext hc) {
288
    public void hyphenate(Position pos, HyphContext hc) {
344
        // use the AbstractLayoutManager.hyphenate() null implementation
345
        super.hyphenate(pos, hc);
346
    }
289
    }
347
290
348
    public boolean applyChanges(List oldList) {
291
    public boolean applyChanges(List oldList) {
(-)old/layoutmgr/LineLayoutManager.java (-100 / +79 lines)
Lines 111-116 Link Here
111
    private int lineHeight;
111
    private int lineHeight;
112
    private int lead;
112
    private int lead;
113
    private int follow;
113
    private int follow;
114
    private int middleShift; // offset of the middle baseline with respect to the main baseline
114
115
115
    // inline start pos when adding areas
116
    // inline start pos when adding areas
116
    private int iStartPos = 0;
117
    private int iStartPos = 0;
Lines 136-141 Link Here
136
    // suggested modification to the "optimum" number of lines
137
    // suggested modification to the "optimum" number of lines
137
    private int looseness = 0;
138
    private int looseness = 0;
138
139
140
    // this constant is used to create elements when text-align is center:
141
    // every TextLM descendant of LineLM must use the same value, 
142
    // otherwise the line breaking algorithm does not find the right
143
    // break point
144
    public static final int DEFAULT_SPACE_WIDTH = 3336;
139
    private static final int INFINITE_RATIO = 1000;
145
    private static final int INFINITE_RATIO = 1000;
140
146
141
    // this class represent a feasible breaking point
147
    // this class represent a feasible breaking point
Lines 257-266 Link Here
257
    // which was the first element in the paragraph
263
    // which was the first element in the paragraph
258
    // returned by each LM
264
    // returned by each LM
259
    private class Update {
265
    private class Update {
260
        private LayoutManager inlineLM;
266
        private InlineLayoutManager inlineLM;
261
        private int iFirstIndex;
267
        private int iFirstIndex;
262
268
263
        public Update(LayoutManager lm, int index) {
269
        public Update(InlineLayoutManager lm, int index) {
264
            inlineLM = lm;
270
            inlineLM = lm;
265
            iFirstIndex = index;
271
            iFirstIndex = index;
266
        }
272
        }
Lines 273-300 Link Here
273
        public int ignoreAtEnd = 0;
279
        public int ignoreAtEnd = 0;
274
        // minimum space at the end of the last line (in millipoints)
280
        // minimum space at the end of the last line (in millipoints)
275
        public int lineFillerWidth;
281
        public int lineFillerWidth;
276
        // word space dimension (in millipoints)
277
        private int wordSpaceIPD;
278
282
279
        public void startParagraph(int lineWidth) {
283
        public void startParagraph(int lineWidth) {
280
            // get the word space dimension, which needs to be known
281
            // in order to center text
282
            LayoutManager lm;
283
            if ((lm = getChildLM()) != null) {
284
                wordSpaceIPD = lm.getWordSpaceIPD();
285
            }
286
287
            // set the minimum amount of empty space at the end of the
284
            // set the minimum amount of empty space at the end of the
288
            // last line
285
            // last line
289
            if (bTextAlignment == CENTER) {
286
            if (bTextAlignment == CENTER) {
290
                lineFillerWidth = 0; 
287
                lineFillerWidth = 0; 
291
            } else {
288
            } else {
292
                lineFillerWidth = (int)(lineWidth / 6); 
289
                lineFillerWidth = (int)(lineWidth / 12); 
293
            }
290
            }
294
291
295
            // add auxiliary elements at the beginning of the paragraph
292
            // add auxiliary elements at the beginning of the paragraph
296
            if (bTextAlignment == CENTER && bTextAlignmentLast != JUSTIFY) {
293
            if (bTextAlignment == CENTER && bTextAlignmentLast != JUSTIFY) {
297
                this.add(new KnuthGlue(0, 3 * wordSpaceIPD, 0,
294
                this.add(new KnuthGlue(0, 3 * DEFAULT_SPACE_WIDTH, 0,
298
                                       null, false));
295
                                       null, false));
299
                ignoreAtStart ++;
296
                ignoreAtStart ++;
300
            }
297
            }
Lines 318-324 Link Here
318
            if (this.size() > ignoreAtStart) {
315
            if (this.size() > ignoreAtStart) {
319
                if (bTextAlignment == CENTER
316
                if (bTextAlignment == CENTER
320
                    && bTextAlignmentLast != JUSTIFY) {
317
                    && bTextAlignmentLast != JUSTIFY) {
321
                    this.add(new KnuthGlue(0, 3 * wordSpaceIPD, 0,
318
                    this.add(new KnuthGlue(0, 3 * DEFAULT_SPACE_WIDTH, 0,
322
                                           null, false));
319
                                           null, false));
323
                    this.add(new KnuthPenalty(0, -KnuthElement.INFINITE,
320
                    this.add(new KnuthPenalty(0, -KnuthElement.INFINITE,
324
                                              false, null, false));
321
                                              false, null, false));
Lines 355-361 Link Here
355
     * @param l the default lead, from top to baseline
352
     * @param l the default lead, from top to baseline
356
     * @param f the default follow, from baseline to bottom
353
     * @param f the default follow, from baseline to bottom
357
     */
354
     */
358
    public LineLayoutManager(FObj node, int lh, int l, int f) {
355
    public LineLayoutManager(FObj node, int lh, int l, int f, int ms) {
359
        super(node);
356
        super(node);
360
        // the child FObj are owned by the parent BlockLM
357
        // the child FObj are owned by the parent BlockLM
361
        // this LM has all its childLMs preloaded
358
        // this LM has all its childLMs preloaded
Lines 363-368 Link Here
363
        lineHeight = lh;
360
        lineHeight = lh;
364
        lead = l;
361
        lead = l;
365
        follow = f;
362
        follow = f;
363
        middleShift = ms;
366
        initialize(); // Normally done when started by parent!
364
        initialize(); // Normally done when started by parent!
367
    }
365
    }
368
366
Lines 376-382 Link Here
376
    public BreakPoss getNextBreakPoss(LayoutContext context) {
374
    public BreakPoss getNextBreakPoss(LayoutContext context) {
377
        // Get a break from currently active child LM
375
        // Get a break from currently active child LM
378
        // Set up constraints for inline level managers
376
        // Set up constraints for inline level managers
379
        LayoutManager curLM ; // currently active LM
377
        InlineLayoutManager curLM ; // currently active LM
380
        BreakPoss prev = null;
378
        BreakPoss prev = null;
381
        BreakPoss bp = null; // proposed BreakPoss
379
        BreakPoss bp = null; // proposed BreakPoss
382
380
Lines 412-437 Link Here
412
410
413
            Paragraph knuthPar = new Paragraph();
411
            Paragraph knuthPar = new Paragraph();
414
            knuthPar.startParagraph(availIPD.opt);
412
            knuthPar.startParagraph(availIPD.opt);
415
            while ((curLM = getChildLM()) != null) {
413
            while ((curLM = (InlineLayoutManager) getChildLM()) != null) {
416
                if ((returnedList
414
                if ((returnedList
417
                     = curLM.getNextKnuthElements(inlineLC,
415
                     = curLM.getNextKnuthElements(inlineLC,
418
                                                  effectiveAlignment))
416
                                                  effectiveAlignment))
419
                    != null) {
417
                    != null) {
420
                    // if there are two consecutive KnuthBox, the first one 
418
                    // look at the first element
421
                    // does not represent a whole word, so it must be given
422
                    // one more letter space
423
                    thisElement = (KnuthElement) returnedList.getFirst();
419
                    thisElement = (KnuthElement) returnedList.getFirst();
424
                    if (returnedList.size() > 1
425
                        || !(thisElement.isPenalty()
426
                             && ((KnuthPenalty) thisElement).getP()
427
                             == -KnuthElement.INFINITE)) {
428
                        if (thisElement.isBox() && !thisElement.isAuxiliary()
420
                        if (thisElement.isBox() && !thisElement.isAuxiliary()
429
                            && bPrevWasKnuthBox) {
421
                            && bPrevWasKnuthBox) {
430
                            prevBox = (KnuthBox) knuthPar.removeLast();
422
                            prevBox = (KnuthBox) knuthPar.removeLast();
423
                        // if there are two consecutive KnuthBoxes the
424
                        // first one does not represent a whole word,
425
                        // so it must be given one more letter space
431
                            if (!prevBox.isAuxiliary()) {
426
                            if (!prevBox.isAuxiliary()) {
432
                                // if letter spacing is constant,
427
                                // if letter spacing is constant,
433
                                // only prevBox needs to be replaced;
428
                                // only prevBox needs to be replaced;
434
                                knuthPar.addLast(prevBox.getLayoutManager()
429
                            knuthPar.addLast(((InlineLayoutManager)
430
                                              prevBox.getLayoutManager())
435
                                                 .addALetterSpaceTo(prevBox));
431
                                                 .addALetterSpaceTo(prevBox));
436
                            } else {
432
                            } else {
437
                                // prevBox is the last element
433
                                // prevBox is the last element
Lines 446-468 Link Here
446
                                    = (KnuthPenalty) knuthPar.removeLast();
442
                                    = (KnuthPenalty) knuthPar.removeLast();
447
                                prevBox = (KnuthBox) knuthPar.getLast();
443
                                prevBox = (KnuthBox) knuthPar.getLast();
448
                                knuthPar.addLast(auxPenalty);
444
                                knuthPar.addLast(auxPenalty);
449
                                knuthPar.addLast(prevBox.getLayoutManager()
445
                            knuthPar.addLast(((InlineLayoutManager)
446
                                              prevBox.getLayoutManager())
450
                                                 .addALetterSpaceTo(prevBox));
447
                                                 .addALetterSpaceTo(prevBox));
451
                                knuthPar.addLast(auxBox);
448
                                knuthPar.addLast(auxBox);
452
                }
449
                }
453
                        }
450
                        }
454
                        if (((KnuthElement) returnedList.getLast()).isBox()) {
451
452
                    // look at the last element
453
                    KnuthElement lastElement = (KnuthElement) returnedList.getLast();
454
                    boolean bForceLinefeed = false;
455
                    if (lastElement.isBox()) {
455
                            bPrevWasKnuthBox = true;
456
                            bPrevWasKnuthBox = true;
456
                        } else {
457
                        } else {
457
                            bPrevWasKnuthBox = false;
458
                            bPrevWasKnuthBox = false;
459
                        if (lastElement.isPenalty()
460
                            && ((KnuthPenalty) lastElement).getP()
461
                                == -KnuthPenalty.INFINITE) {
462
                            // a penalty item whose value is -inf
463
                            // represents a preserved linefeed,
464
                            // wich forces a line break
465
                            bForceLinefeed = true;
466
                            returnedList.removeLast();
467
                        }
458
                        }
468
                        }
469
459
                        // add the new elements to the paragraph
470
                        // add the new elements to the paragraph
460
                        knuthPar.addAll(returnedList);
471
                        knuthPar.addAll(returnedList);
461
                    } else {
472
                    if (bForceLinefeed) {
462
                        // a list with a single penalty item
463
                        // whose value is -inf
464
                        // represents a preserved linefeed,
465
                        // wich forces a line break
466
                        knuthPar.endParagraph();
473
                        knuthPar.endParagraph();
467
                        knuthPar = new Paragraph();
474
                        knuthPar = new Paragraph();
468
                        knuthPar.startParagraph(availIPD.opt);
475
                        knuthPar.startParagraph(availIPD.opt);
Lines 472-478 Link Here
472
                    // curLM returned null; this can happen
479
                    // curLM returned null; this can happen
473
                    // if it has nothing more to layout,
480
                    // if it has nothing more to layout,
474
                    // so just iterate once more to see
481
                    // so just iterate once more to see
475
                    // if there are other chilren
482
                    // if there are other children
476
                }
483
                }
477
            }
484
            }
478
            knuthPar.endParagraph();
485
            knuthPar.endParagraph();
Lines 652-704 Link Here
652
            double ratio = (textAlign == JUSTIFY)
659
            double ratio = (textAlign == JUSTIFY)
653
                ? bestActiveNode.adjustRatio : 0;
660
                ? bestActiveNode.adjustRatio : 0;
654
661
655
            // lead to baseline is
662
            makeLineBreakPosition(par,
656
            // max of: baseline fixed alignment and middle/2
663
                                  (i > 1 ? bestActiveNode.previous.position + 1: 0),
657
            // after baseline is
658
            // max: top height-lead, middle/2 and bottom height-lead
659
            int halfLeading = (lineHeight - lead - follow) / 2;
660
            // height before baseline
661
            int lineLead = lead + halfLeading;
662
            // maximum size of top and bottom alignment
663
            int maxtb = follow + halfLeading;
664
            // max size of middle alignment below baseline
665
            int middlefollow = maxtb;
666
667
            // index of the first KnuthElement in this line
668
            int firstElementIndex = 0;
669
            if (line > 1) {
670
                firstElementIndex = bestActiveNode.previous.position + 1;
671
            }
672
            ListIterator inlineIterator = par.listIterator(firstElementIndex);
673
            for (int j = 0;
674
                 j < (bestActiveNode.position - firstElementIndex + 1);
675
                 j++) {
676
                KnuthElement element = (KnuthElement) inlineIterator.next();
677
                if (element.isBox()) {
678
                    if (((KnuthBox) element).getLead() > lineLead) {
679
                        lineLead = ((KnuthBox) element).getLead();
680
                    }
681
                    if (((KnuthBox) element).getTotal() > maxtb) {
682
                        maxtb = ((KnuthBox) element).getTotal();
683
                    }
684
                    if (((KnuthBox) element).getMiddle() > middlefollow) {
685
                        middlefollow = ((KnuthBox) element).getMiddle();
686
                    }
687
                }
688
            }
689
690
            if (maxtb - lineLead > middlefollow) {
691
                middlefollow = maxtb - lineLead;
692
            }
693
694
            // add nodes at the beginning of the list, as they are found
695
            // backwards, from the last one to the first one
696
            breakpoints.add(0,
697
                            new LineBreakPosition(this,
698
                                                  bestActiveNode.position,
664
                                                  bestActiveNode.position,
699
                                                  ratio, 0, indent,
665
                                  0, ratio, indent);
700
                                                  lineLead + middlefollow,
666
701
                                                  lineLead));
702
            bestActiveNode = bestActiveNode.previous;
667
            bestActiveNode = bestActiveNode.previous;
703
        }
668
        }
704
        if (bForced) {
669
        if (bForced) {
Lines 710-731 Link Here
710
    }
675
    }
711
676
712
    private void fallback(Paragraph par, int line) {
677
    private void fallback(Paragraph par, int line) {
713
        // lead to baseline is
678
        makeLineBreakPosition(par,
714
        // max of: baseline fixed alignment and middle/2
679
                              lastDeactivatedNode.position,
715
        // after baseline is
680
                              par.size() - 1,
716
        // max: top height-lead, middle/2 and bottom height-lead
681
                              line, 0, 0);
682
    }
683
684
    private void makeLineBreakPosition(Paragraph par,
685
                                       int firstElementIndex, int lastElementIndex,
686
                                       int insertIndex, double ratio, int indent) {
687
        // line height calculation
688
717
        int halfLeading = (lineHeight - lead - follow) / 2;
689
        int halfLeading = (lineHeight - lead - follow) / 2;
718
        // height before baseline
690
        // height before the main baseline
719
        int lineLead = lead + halfLeading;
691
        int lineLead = lead + halfLeading;
720
        // maximum size of top and bottom alignment
692
        // maximum size of top and bottom alignment
721
        int maxtb = follow + halfLeading;
693
        int maxtb = follow + halfLeading;
722
        // max size of middle alignment below baseline
694
        // max size of middle alignment before and after the middle baseline
723
        int middlefollow = maxtb;
695
        int middlefollow = maxtb;
724
696
725
        ListIterator inlineIterator
697
        ListIterator inlineIterator
726
            = par.listIterator(lastDeactivatedNode.position);
698
            = par.listIterator(firstElementIndex);
727
        for (int j = lastDeactivatedNode.position;
699
        for (int j = firstElementIndex;
728
             j < (par.size());
700
             j <= lastElementIndex;
729
             j++) {
701
             j++) {
730
            KnuthElement element = (KnuthElement) inlineIterator.next();
702
            KnuthElement element = (KnuthElement) inlineIterator.next();
731
            if (element.isBox()) {
703
            if (element.isBox()) {
Lines 735-742 Link Here
735
                if (((KnuthBox) element).getTotal() > maxtb) {
707
                if (((KnuthBox) element).getTotal() > maxtb) {
736
                    maxtb = ((KnuthBox) element).getTotal();
708
                    maxtb = ((KnuthBox) element).getTotal();
737
                }
709
                }
738
                if (((KnuthBox) element).getMiddle() > middlefollow) {
710
                if (((KnuthBox) element).getMiddle() > lineLead + middleShift) {
739
                    middlefollow = ((KnuthBox) element).getMiddle();
711
                    lineLead += ((KnuthBox) element).getMiddle()
712
                                - lineLead - middleShift;
713
                }
714
                if (((KnuthBox) element).getMiddle() > middlefollow - middleShift) {
715
                    middlefollow += ((KnuthBox) element).getMiddle()
716
                                    - middlefollow + middleShift;
740
                }
717
                }
741
            }
718
            }
742
        }
719
        }
Lines 745-758 Link Here
745
                    middlefollow = maxtb - lineLead;
722
                    middlefollow = maxtb - lineLead;
746
        }
723
        }
747
724
748
        breakpoints.add(line,
725
        breakpoints.add(insertIndex,
749
                        new LineBreakPosition(this, par.size() - 1,
726
                        new LineBreakPosition(this,
750
                                              0, 0, 0,
727
                                              lastElementIndex ,
728
                                              ratio, 0, indent,
751
                                              lineLead + middlefollow,
729
                                              lineLead + middlefollow,
752
                                              lineLead));
730
                                              lineLead));
753
    }
731
    }
754
732
755
756
    private void considerLegalBreak(LinkedList par, int lineWidth,
733
    private void considerLegalBreak(LinkedList par, int lineWidth,
757
                                    KnuthElement element,
734
                                    KnuthElement element,
758
                                    int totalWidth, int totalStretch,
735
                                    int totalWidth, int totalStretch,
Lines 974-981 Link Here
974
        LinkedList updateList = new LinkedList();
951
        LinkedList updateList = new LinkedList();
975
        KnuthElement firstElement = null;
952
        KnuthElement firstElement = null;
976
        KnuthElement nextElement = null;
953
        KnuthElement nextElement = null;
977
        // current TextLayoutManager
954
        // current InlineLayoutManager
978
        LayoutManager currLM = null;
955
        InlineLayoutManager currLM = null;
979
        // number of KnuthBox elements containing word fragments
956
        // number of KnuthBox elements containing word fragments
980
        int boxCount;
957
        int boxCount;
981
        // number of auxiliary KnuthElements between KnuthBoxes
958
        // number of auxiliary KnuthElements between KnuthBoxes
Lines 987-993 Link Here
987
            firstElement = (KnuthElement) currParIterator.next();
964
            firstElement = (KnuthElement) currParIterator.next();
988
            // 
965
            // 
989
            if (firstElement.getLayoutManager() != currLM) {
966
            if (firstElement.getLayoutManager() != currLM) {
990
                currLM = firstElement.getLayoutManager();
967
                currLM = (InlineLayoutManager) firstElement.getLayoutManager();
991
                if (currLM != null) { 
968
                if (currLM != null) { 
992
                    updateList.add(new Update(currLM, currParIterator.previousIndex()));
969
                    updateList.add(new Update(currLM, currParIterator.previousIndex()));
993
                } else {
970
                } else {
Lines 1008-1014 Link Here
1008
                    if (nextElement.isBox() && !nextElement.isAuxiliary()) {
985
                    if (nextElement.isBox() && !nextElement.isAuxiliary()) {
1009
                        // a non-auxiliary KnuthBox: append word chars
986
                        // a non-auxiliary KnuthBox: append word chars
1010
                        if (currLM != nextElement.getLayoutManager()) {
987
                        if (currLM != nextElement.getLayoutManager()) {
1011
                            currLM = nextElement.getLayoutManager();
988
                            currLM = (InlineLayoutManager) nextElement.getLayoutManager();
1012
                            updateList.add(new Update(currLM, currParIterator.previousIndex()));
989
                            updateList.add(new Update(currLM, currParIterator.previousIndex()));
1013
                        }
990
                        }
1014
                        // append text to recreate the whole word
991
                        // append text to recreate the whole word
Lines 1036-1042 Link Here
1036
                    for (int i = 0; i < (boxCount + auxCount); i++) {
1013
                    for (int i = 0; i < (boxCount + auxCount); i++) {
1037
                        element = (KnuthElement) currParIterator.next();
1014
                        element = (KnuthElement) currParIterator.next();
1038
                        if (element.isBox() && !element.isAuxiliary()) {
1015
                        if (element.isBox() && !element.isAuxiliary()) {
1039
                            element.getLayoutManager().hyphenate(element.getPosition(), hc);
1016
                            ((InlineLayoutManager)
1017
                             element.getLayoutManager()).hyphenate(element.getPosition(), hc);
1040
                        } else {
1018
                        } else {
1041
                            // nothing to do, element is an auxiliary KnuthElement
1019
                            // nothing to do, element is an auxiliary KnuthElement
1042
                        }
1020
                        }
Lines 1070-1076 Link Here
1070
1048
1071
            // applyChanges() returns true if the LM modifies its data,
1049
            // applyChanges() returns true if the LM modifies its data,
1072
            // so it must return new KnuthElements to replace the old ones
1050
            // so it must return new KnuthElements to replace the old ones
1073
            if (currUpdate.inlineLM
1051
            if (((InlineLayoutManager) currUpdate.inlineLM)
1074
                .applyChanges(currPar.subList(fromIndex + iAddedElements,
1052
                .applyChanges(currPar.subList(fromIndex + iAddedElements,
1075
                                              toIndex + iAddedElements))) {
1053
                                              toIndex + iAddedElements))) {
1076
                // insert the new KnuthElements
1054
                // insert the new KnuthElements
Lines 1420-1425 Link Here
1420
            lineArea.setBPD(lbp.lineHeight);
1398
            lineArea.setBPD(lbp.lineHeight);
1421
            lc.setBaseline(lbp.baseline);
1399
            lc.setBaseline(lbp.baseline);
1422
            lc.setLineHeight(lbp.lineHeight);
1400
            lc.setLineHeight(lbp.lineHeight);
1401
            lc.setMiddleShift(middleShift);
1423
            setCurrentArea(lineArea);
1402
            setCurrentArea(lineArea);
1424
1403
1425
            Paragraph currPar = (Paragraph) knuthParagraphs.get(iCurrParIndex);
1404
            Paragraph currPar = (Paragraph) knuthParagraphs.get(iCurrParIndex);
(-)old/layoutmgr/TextLayoutManager.java (-23 / +65 lines)
Lines 24-33 Link Here
24
import java.util.ListIterator;
24
import java.util.ListIterator;
25
25
26
import org.apache.fop.fo.FOText;
26
import org.apache.fop.fo.FOText;
27
import org.apache.fop.fo.Constants;
27
import org.apache.fop.traits.SpaceVal;
28
import org.apache.fop.traits.SpaceVal;
28
import org.apache.fop.area.Trait;
29
import org.apache.fop.area.Trait;
29
import org.apache.fop.area.inline.InlineArea;
30
import org.apache.fop.area.inline.InlineArea;
30
import org.apache.fop.area.inline.TextArea;
31
import org.apache.fop.area.inline.TextArea;
32
import org.apache.fop.area.inline.Space;
31
import org.apache.fop.util.CharUtilities;
33
import org.apache.fop.util.CharUtilities;
32
import org.apache.fop.traits.MinOptMax;
34
import org.apache.fop.traits.MinOptMax;
33
35
Lines 35-41 Link Here
35
 * LayoutManager for text (a sequence of characters) which generates one
37
 * LayoutManager for text (a sequence of characters) which generates one
36
 * or more inline areas.
38
 * or more inline areas.
37
 */
39
 */
38
public class TextLayoutManager extends AbstractLayoutManager {
40
public class TextLayoutManager extends LeafNodeLayoutManager {
39
41
40
    /**
42
    /**
41
     * Store information about each potential text area.
43
     * Store information about each potential text area.
Lines 115-120 Link Here
115
    private short iTempStart = 0;
117
    private short iTempStart = 0;
116
    private LinkedList changeList = null;
118
    private LinkedList changeList = null;
117
119
120
    private int textHeight;
121
    private int lead = 0;
122
    private int total = 0;
123
    private int middle = 0;
124
118
    /**
125
    /**
119
     * Create a Text layout manager.
126
     * Create a Text layout manager.
120
     *
127
     *
Lines 155-160 Link Here
155
        wordSpaceIPD = new MinOptMax(spaceCharIPD + ws.getSpace().min,
162
        wordSpaceIPD = new MinOptMax(spaceCharIPD + ws.getSpace().min,
156
                                     spaceCharIPD + ws.getSpace().opt,
163
                                     spaceCharIPD + ws.getSpace().opt,
157
                                     spaceCharIPD + ws.getSpace().max);
164
                                     spaceCharIPD + ws.getSpace().max);
165
166
        // set text height
167
        textHeight = foText.textInfo.fs.getAscender()
168
                     - foText.textInfo.fs.getDescender();
169
170
        setAlignment(foText.textInfo.verticalAlign);
171
        switch (verticalAlignment) {
172
            case VerticalAlign.MIDDLE  : middle = textHeight / 2 ;
173
                                         break;
174
            case VerticalAlign.TOP     : // fall through
175
            case VerticalAlign.BOTTOM  : total = textHeight;
176
                                         break;
177
            case VerticalAlign.BASELINE: // fall through
178
            default                    : lead = foText.textInfo.fs.getAscender();
179
                                         total = textHeight;
180
                                         break;
181
        }
158
    }
182
    }
159
183
160
    /**
184
    /**
Lines 576-582 Link Here
576
        iTotalAdjust += (iWordSpaceDim - wordSpaceIPD.opt) * iWScount;
600
        iTotalAdjust += (iWordSpaceDim - wordSpaceIPD.opt) * iWScount;
577
601
578
        TextArea t = createTextArea(str, realWidth.opt + iTotalAdjust,
602
        TextArea t = createTextArea(str, realWidth.opt + iTotalAdjust,
579
                                    context.getBaseline());
603
                                    context);
580
604
581
        // iWordSpaceDim is computed in relation to wordSpaceIPD.opt
605
        // iWordSpaceDim is computed in relation to wordSpaceIPD.opt
582
        // but the renderer needs to know the adjustment in relation
606
        // but the renderer needs to know the adjustment in relation
Lines 608-620 Link Here
608
     * @param base the baseline position
632
     * @param base the baseline position
609
     * @return the new word area
633
     * @return the new word area
610
     */
634
     */
611
    protected TextArea createTextArea(String str, int width, int base) {
635
    protected TextArea createTextArea(String str, int width, LayoutContext context) {
612
        TextArea textArea = new TextArea();
636
        TextArea textArea = new TextArea();
613
        textArea.setIPD(width);
637
        textArea.setIPD(width);
614
        textArea.setBPD(foText.textInfo.fs.getAscender()
638
        textArea.setBPD(foText.textInfo.fs.getAscender()
615
                           - foText.textInfo.fs.getDescender());
639
                           - foText.textInfo.fs.getDescender());
640
        int bpd = textArea.getBPD();
641
        switch (verticalAlignment) {
642
            case VerticalAlign.MIDDLE:
643
                textArea.setOffset(context.getMiddleBaseline() + foText.textInfo.fs.getXHeight() / 2);
644
            break;
645
            case VerticalAlign.TOP:
616
        textArea.setOffset(foText.textInfo.fs.getAscender());
646
        textArea.setOffset(foText.textInfo.fs.getAscender());
617
        textArea.setOffset(base);
647
            break;
648
            case VerticalAlign.BOTTOM:
649
                textArea.setOffset(context.getLineHeight() - bpd + foText.textInfo.fs.getAscender());
650
            break;
651
            case VerticalAlign.BASELINE:
652
            default:
653
                textArea.setOffset(context.getBaseline());
654
            break;
655
        }
618
656
619
        textArea.setTextArea(str);
657
        textArea.setTextArea(str);
620
        textArea.addTrait(Trait.FONT_NAME, foText.textInfo.fs.getFontName());
658
        textArea.addTrait(Trait.FONT_NAME, foText.textInfo.fs.getFontName());
Lines 629-636 Link Here
629
        LinkedList returnList = new LinkedList();
667
        LinkedList returnList = new LinkedList();
630
668
631
        while (iNextStart < textArray.length) {
669
        while (iNextStart < textArray.length) {
632
            if (textArray[iNextStart] == SPACE) {
670
            if (textArray[iNextStart] == SPACE
671
                || textArray[iNextStart] == NBSPACE) {
633
                // normal, breaking space
672
                // normal, breaking space
673
                // or non-breaking space
674
                if (textArray[iNextStart] == NBSPACE) {
675
                    returnList.add
676
                        (new KnuthPenalty(0, KnuthElement.INFINITE, false,
677
                                          new LeafPosition(this, vecAreaInfo.size() - 1),
678
                                          false));
679
                }
634
                switch (alignment) {
680
                switch (alignment) {
635
                case CENTER :
681
                case CENTER :
636
                    vecAreaInfo.add
682
                    vecAreaInfo.add
Lines 638-651 Link Here
638
                                      (short) 1, (short) 0,
684
                                      (short) 1, (short) 0,
639
                                      wordSpaceIPD, false));
685
                                      wordSpaceIPD, false));
640
                    returnList.add
686
                    returnList.add
641
                        (new KnuthGlue(0, 3 * wordSpaceIPD.opt, 0,
687
                        (new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
642
                                       new LeafPosition(this, vecAreaInfo.size() - 1), false));
688
                                       new LeafPosition(this, vecAreaInfo.size() - 1), false));
643
                    returnList.add
689
                    returnList.add
644
                        (new KnuthPenalty(0, 0, false,
690
                        (new KnuthPenalty(0, 0, false,
645
                                          new LeafPosition(this, -1), true));
691
                                          new LeafPosition(this, -1), true));
646
                    returnList.add
692
                    returnList.add
647
                        (new KnuthGlue(wordSpaceIPD.opt,
693
                        (new KnuthGlue(wordSpaceIPD.opt,
648
                                       - 6 * wordSpaceIPD.opt, 0,
694
                                       - 6 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
649
                                       new LeafPosition(this, -1), true));
695
                                       new LeafPosition(this, -1), true));
650
                    returnList.add
696
                    returnList.add
651
                        (new KnuthBox(0, 0, 0, 0,
697
                        (new KnuthBox(0, 0, 0, 0,
Lines 654-660 Link Here
654
                        (new KnuthPenalty(0, KnuthElement.INFINITE, false,
700
                        (new KnuthPenalty(0, KnuthElement.INFINITE, false,
655
                                          new LeafPosition(this, -1), true));
701
                                          new LeafPosition(this, -1), true));
656
                    returnList.add
702
                    returnList.add
657
                        (new KnuthGlue(0, 3 * wordSpaceIPD.opt, 0,
703
                        (new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
658
                                       new LeafPosition(this, -1), true));
704
                                       new LeafPosition(this, -1), true));
659
                    iNextStart ++;
705
                    iNextStart ++;
660
                    break;
706
                    break;
Lines 719-726 Link Here
719
                iNextStart ++;
765
                iNextStart ++;
720
            } else if (textArray[iNextStart] == NEWLINE) {
766
            } else if (textArray[iNextStart] == NEWLINE) {
721
                // linefeed; this can happen when linefeed-treatment="preserve"
767
                // linefeed; this can happen when linefeed-treatment="preserve"
722
                // the linefeed character is the first one in textArray,
768
                // add a penalty item to the list and return
723
                // so we can just return a list with a penalty item
724
                returnList.add
769
                returnList.add
725
                    (new KnuthPenalty(0, -KnuthElement.INFINITE,
770
                    (new KnuthPenalty(0, -KnuthElement.INFINITE,
726
                                      false, null, false));
771
                                      false, null, false));
Lines 751-764 Link Here
751
                    // constant letter space; simply return a box
796
                    // constant letter space; simply return a box
752
                    // whose width includes letter spaces
797
                    // whose width includes letter spaces
753
                    returnList.add
798
                    returnList.add
754
                        (new KnuthBox(wordIPD.opt, 0, 0, 0,
799
                        (new KnuthBox(wordIPD.opt, lead, total, middle,
755
                                      new LeafPosition(this, vecAreaInfo.size() - 1), false));
800
                                      new LeafPosition(this, vecAreaInfo.size() - 1), false));
756
                    iNextStart = iTempStart;
801
                    iNextStart = iTempStart;
757
                } else {
802
                } else {
758
                    // adjustable letter space;
803
                    // adjustable letter space;
759
                    // some other KnuthElements are needed
804
                    // some other KnuthElements are needed
760
                    returnList.add
805
                    returnList.add
761
                        (new KnuthBox(wordIPD.opt - (iTempStart - iThisStart - 1) * letterSpaceIPD.opt, 0, 0, 0,
806
                        (new KnuthBox(wordIPD.opt - (iTempStart - iThisStart - 1) * letterSpaceIPD.opt,
807
                                      lead, total, middle,
762
                                      new LeafPosition(this, vecAreaInfo.size() - 1), false));
808
                                      new LeafPosition(this, vecAreaInfo.size() - 1), false));
763
                    returnList.add
809
                    returnList.add
764
                        (new KnuthPenalty(0, KnuthElement.INFINITE, false,
810
                        (new KnuthPenalty(0, KnuthElement.INFINITE, false,
Lines 769-775 Link Here
769
                                       (iTempStart - iThisStart - 1) * (letterSpaceIPD.opt - letterSpaceIPD.min),
815
                                       (iTempStart - iThisStart - 1) * (letterSpaceIPD.opt - letterSpaceIPD.min),
770
                                       new LeafPosition(this, -1), true));
816
                                       new LeafPosition(this, -1), true));
771
                    returnList.add
817
                    returnList.add
772
                        (new KnuthBox(0, 0, 0, 0,
818
                        (new KnuthBox(0, lead, total, middle,
773
                                      new LeafPosition(this, -1), true));
819
                                      new LeafPosition(this, -1), true));
774
                    iNextStart = iTempStart;
820
                    iNextStart = iTempStart;
775
                }
821
                }
Lines 783-799 Link Here
783
        }
829
        }
784
    }
830
    }
785
831
786
    public int getWordSpaceIPD() {
787
        return wordSpaceIPD.opt;
788
    }
789
790
    public KnuthElement addALetterSpaceTo(KnuthElement element) {
832
    public KnuthElement addALetterSpaceTo(KnuthElement element) {
791
        LeafPosition pos = (LeafPosition) element.getPosition();
833
        LeafPosition pos = (LeafPosition) element.getPosition();
792
        AreaInfo ai = (AreaInfo) vecAreaInfo.get(pos.getLeafPos());
834
        AreaInfo ai = (AreaInfo) vecAreaInfo.get(pos.getLeafPos());
793
        ai.iLScount ++;
835
        ai.iLScount ++;
794
        ai.ipdArea.add(letterSpaceIPD);
836
        ai.ipdArea.add(letterSpaceIPD);
795
        if (letterSpaceIPD.min == letterSpaceIPD.max) {
837
        if (letterSpaceIPD.min == letterSpaceIPD.max) {
796
            return new KnuthBox(ai.ipdArea.opt, 0, 0, 0, pos, false);
838
            return new KnuthBox(ai.ipdArea.opt, lead, total, middle, pos, false);
797
        } else {
839
        } else {
798
            return new KnuthGlue(ai.iLScount * letterSpaceIPD.opt,
840
            return new KnuthGlue(ai.iLScount * letterSpaceIPD.opt,
799
                                 ai.iLScount * (letterSpaceIPD.max - letterSpaceIPD.opt),
841
                                 ai.iLScount * (letterSpaceIPD.max - letterSpaceIPD.opt),
Lines 912-924 Link Here
912
                // ai refers either to a word or a word fragment
954
                // ai refers either to a word or a word fragment
913
                if (letterSpaceIPD.min == letterSpaceIPD.max) {
955
                if (letterSpaceIPD.min == letterSpaceIPD.max) {
914
                    returnList.add
956
                    returnList.add
915
                        (new KnuthBox(ai.ipdArea.opt, 0, 0, 0,
957
                        (new KnuthBox(ai.ipdArea.opt, lead, total, middle,
916
                                      new LeafPosition(this, iReturnedIndex), false));
958
                                      new LeafPosition(this, iReturnedIndex), false));
917
                } else {
959
                } else {
918
                    returnList.add
960
                    returnList.add
919
                        (new KnuthBox(ai.ipdArea.opt
961
                        (new KnuthBox(ai.ipdArea.opt
920
                                      - ai.iLScount * letterSpaceIPD.opt,
962
                                      - ai.iLScount * letterSpaceIPD.opt,
921
                                      0, 0, 0, 
963
                                      lead, total, middle, 
922
                                      new LeafPosition(this, iReturnedIndex), false));
964
                                      new LeafPosition(this, iReturnedIndex), false));
923
                    returnList.add
965
                    returnList.add
924
                        (new KnuthPenalty(0, KnuthElement.INFINITE, false,
966
                        (new KnuthPenalty(0, KnuthElement.INFINITE, false,
Lines 943-956 Link Here
943
                switch (alignment) {
985
                switch (alignment) {
944
                case CENTER :
986
                case CENTER :
945
                    returnList.add
987
                    returnList.add
946
                        (new KnuthGlue(0, 3 * wordSpaceIPD.opt, 0,
988
                        (new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
947
                                       new LeafPosition(this, iReturnedIndex), false));
989
                                       new LeafPosition(this, iReturnedIndex), false));
948
                    returnList.add
990
                    returnList.add
949
                        (new KnuthPenalty(0, 0, false,
991
                        (new KnuthPenalty(0, 0, false,
950
                                          new LeafPosition(this, -1), true));
992
                                          new LeafPosition(this, -1), true));
951
                    returnList.add
993
                    returnList.add
952
                        (new KnuthGlue(wordSpaceIPD.opt,
994
                        (new KnuthGlue(wordSpaceIPD.opt,
953
                                       - 6 * wordSpaceIPD.opt, 0,
995
                                       - 6 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
954
                                       new LeafPosition(this, -1), true));
996
                                       new LeafPosition(this, -1), true));
955
                    returnList.add
997
                    returnList.add
956
                        (new KnuthBox(0, 0, 0, 0,
998
                        (new KnuthBox(0, 0, 0, 0,
Lines 959-965 Link Here
959
                        (new KnuthPenalty(0, KnuthElement.INFINITE, false,
1001
                        (new KnuthPenalty(0, KnuthElement.INFINITE, false,
960
                                          new LeafPosition(this, -1), true));
1002
                                          new LeafPosition(this, -1), true));
961
                    returnList.add
1003
                    returnList.add
962
                        (new KnuthGlue(0, 3 * wordSpaceIPD.opt, 0,
1004
                        (new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
963
                                       new LeafPosition(this, -1), true));
1005
                                       new LeafPosition(this, -1), true));
964
                    iReturnedIndex ++;
1006
                    iReturnedIndex ++;
965
                    break;
1007
                    break;

Return to bug 31206