aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/layoutmgr/ContentLayoutManager.java
blob: 27204bedc4914493ecaa3d25f3a912dfc40f166b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * $Id$
 * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
 * For details on use and redistribution please refer to the
 * LICENSE file included with these sources.
 */

package org.apache.fop.layoutmgr;


import org.apache.fop.area.Area;
import org.apache.fop.area.MinOptMax;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.PageViewport;

import java.util.ArrayList;

/**
 * Content Layout Manager.
 * For use with objects that contain inline areas such as
 * leader use-content and title.
 */
public class ContentLayoutManager implements LayoutManager {
    Area holder;
    int stackSize;
    LayoutManager parentLM;

    public ContentLayoutManager(Area area) {
        holder = area;
    }

    public void fillArea(LayoutManager curLM) {

        ArrayList childBreaks = new ArrayList();
        MinOptMax stack = new MinOptMax();
        int ipd = 1000000;
        BreakPoss bp;

        LayoutContext childLC = new LayoutContext(LayoutContext.NEW_AREA);
        childLC.setLeadingSpace(new SpaceSpecifier(false));
        childLC.setTrailingSpace(new SpaceSpecifier(false));
        // set stackLimit for lines
        childLC.setStackLimit(new MinOptMax(ipd));
        childLC.setRefIPD(ipd);

        while (!curLM.isFinished()) {
            if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
                stack.add(bp.getStackingSize());
                childBreaks.add(bp);
            }
        }

        LayoutContext lc = new LayoutContext(0);
        lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
        lc.setLeadingSpace(new SpaceSpecifier(false));
        lc.setTrailingSpace(new SpaceSpecifier(false));
        PositionIterator breakPosIter =
          new BreakPossPosIter(childBreaks, 0, childBreaks.size());
        curLM.addAreas(breakPosIter, lc);
        stackSize = stack.opt;
    }

    public int getStackingSize() {
        return stackSize;
    }

    public boolean generatesInlineAreas() {
        return true;
    }

    public Area getParentArea (Area childArea) {
        return holder;
    }

    public boolean addChild (Area childArea) {
        holder.addChild(childArea);
        return true;
    }

    public void setParentLM(LayoutManager lm) {
        parentLM = lm;
    }

    public boolean canBreakBefore(LayoutContext lc) {
        return false;
    }

    public BreakPoss getNextBreakPoss(LayoutContext context) {
        return null;
    }

    public boolean isFinished() {
        return false;
    }

    public void setFinished(boolean isFinished) {
    }

    public void addAreas(PositionIterator posIter, LayoutContext context) {
    }

    public void init() {
    }

    public void resetPosition(Position position) {
    }

    public void getWordChars(StringBuffer sbChars, Position bp1,
                             Position bp2) {
    }

    public String getCurrentPageNumber() {
        return parentLM.getCurrentPageNumber();
    }

    public PageViewport resolveRefID(String ref) {
        return parentLM.resolveRefID(ref);;
    }

    public void addIDToPage(String id) {
        parentLM.addIDToPage(id);
    }

    public void addUnresolvedArea(String id, Resolveable res) {
        parentLM.addUnresolvedArea(id, res);
    }
}