aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/fo/flow/BlockContainer.java
blob: 563fbbfcc06b16ba0b5878c827e78725699c78ed (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * $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.fo.flow;

// FOP
import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.*;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.layout.*;
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.*;

// Java
import java.util.Hashtable;
import java.util.Enumeration;

public class BlockContainer extends FObj {

    ColorType backgroundColor;
    int position;

    int top;
    int bottom;
    int left;
    int right;
    int width;
    int height;

    int span;

    AreaContainer areaContainer;

    public static class Maker extends FObj.Maker {
        public FObj make(FObj parent,
                         PropertyList propertyList) throws FOPException {
            return new BlockContainer(parent, propertyList);
        }

    }

    public static FObj.Maker maker() {
        return new BlockContainer.Maker();
    }

    PageSequence pageSequence;

    protected BlockContainer(FObj parent,
                             PropertyList propertyList) throws FOPException {
        super(parent, propertyList);
        this.name = "fo:block-container";
        this.span = this.properties.get("span").getEnum();
    }

    public Status layout(Area area) throws FOPException {
        if (this.marker == START) {

            // Common Accessibility Properties
            AbsolutePositionProps mAbsProps = propMgr.getAbsolutePositionProps();

            // Common Border, Padding, and Background Properties
            BorderAndPadding bap = propMgr.getBorderAndPadding();
            BackgroundProps bProps = propMgr.getBackgroundProps();

            // Common Margin-Block Properties
            MarginProps mProps = propMgr.getMarginProps();

            // this.properties.get("block-progression-dimension");
            // this.properties.get("break-after");
            // this.properties.get("break-before");
            // this.properties.get("clip");
            // this.properties.get("display-align");
            // this.properties.get("height");
            // this.properties.get("id");
            // this.properties.get("keep-together");
            // this.properties.get("keep-with-next");
            // this.properties.get("keep-with-previous");
            // this.properties.get("overflow");
            // this.properties.get("reference-orientation");
            // this.properties.get("span");
            // this.properties.get("width");
            // this.properties.get("writing-mode");

            this.marker = 0;

            this.backgroundColor =
                this.properties.get("background-color").getColorType();

            this.position = this.properties.get("position").getEnum();
            this.top = this.properties.get("top").getLength().mvalue();
            this.bottom = this.properties.get("bottom").getLength().mvalue();
            this.left = this.properties.get("left").getLength().mvalue();
            this.right = this.properties.get("right").getLength().mvalue();
            this.width = this.properties.get("width").getLength().mvalue();
            this.height = this.properties.get("height").getLength().mvalue();
            span = this.properties.get("span").getEnum();

            // initialize id
            String id = this.properties.get("id").getString();
            area.getIDReferences().initializeID(id, area);
        }

        boolean prevChildMustKeepWithNext = false;

        AreaContainer container = (AreaContainer)area;
        if ((this.width == 0) && (this.height == 0)) {
            width = right - left;
            height = bottom - top;
        }

        this.areaContainer =
            new AreaContainer(propMgr.getFontState(container.getFontInfo()),
                              container.getXPosition() + left,
                              container.getYPosition() - top, width, height,
                              position);

        areaContainer.setPage(area.getPage());
        areaContainer.setBackgroundColor(backgroundColor);
        areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding());
        areaContainer.start();

        areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
        areaContainer.setIDReferences(area.getIDReferences());

        int numChildren = this.children.size();
        for (int i = this.marker; i < numChildren; i++) {
            FObj fo = (FObj)children.elementAt(i);
            Status status;
            if ((status = fo.layout(areaContainer)).isIncomplete()) {
                /*
                 * if ((prevChildMustKeepWithNext) && (status.laidOutNone())) {
                 * this.marker = i - 1;
                 * FObj prevChild = (FObj) children.elementAt(this.marker);
                 * prevChild.removeAreas();
                 * prevChild.resetMarker();
                 * return new Status(Status.AREA_FULL_SOME);
                 * // should probably return AREA_FULL_NONE if first
                 * // or perhaps an entirely new status code
                 * } else {
                 * this.marker = i;
                 * return status;
                 * }
                 */
            }
            if (status.getCode() == Status.KEEP_WITH_NEXT) {
                prevChildMustKeepWithNext = true;
            }
        }
        area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());

        areaContainer.end();
        if (position == Position.ABSOLUTE)
            areaContainer.setHeight(height);
        area.addChild(areaContainer);

        return new Status(Status.OK);
    }

    /**
     * Return the content width of the boxes generated by this block
     * container FO.
     */
    public int getContentWidth() {
        if (areaContainer != null)
            return areaContainer.getContentWidth();    // getAllocationWidth()??
        else
            return 0;    // not laid out yet
    }

    public boolean generatesReferenceAreas() {
        return true;
    }

    public int getSpan() {
        return this.span;
    }

}