aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/fo/pagination/RegionBody.java
blob: 9c4d46078cd016aaeb2dcbb4da514a710aba1957 (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
/*
 * $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.pagination;

// FOP
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.properties.Overflow;
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.apps.FOPException;
import org.apache.fop.layout.RegionArea;
import org.apache.fop.layout.BodyRegionArea;
import org.apache.fop.layout.BorderAndPadding;
import org.apache.fop.layout.BackgroundProps;
import org.apache.fop.layout.MarginProps;

public class RegionBody extends Region {


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

    }

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

    public static final String REGION_CLASS = "body";

    ColorType backgroundColor;

    protected RegionBody(FObj parent,
                         PropertyList propertyList) throws FOPException {
        super(parent, propertyList);
    }

    RegionArea makeRegionArea(int allocationRectangleXPosition,
                              int allocationRectangleYPosition,
                              int allocationRectangleWidth,
                              int allocationRectangleHeight) {

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

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

        // this.properties.get("clip");
        // this.properties.get("display-align");
        // this.properties.get("region-name");
        // this.properties.get("reference-orientation");
        // this.properties.get("writing-mode");

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

        BodyRegionArea body = new BodyRegionArea(allocationRectangleXPosition
                                                 + mProps.marginLeft,
                                                 allocationRectangleYPosition
                                                 - mProps.marginTop,
                                                 allocationRectangleWidth
                                                 - mProps.marginLeft
                                                 - mProps.marginRight,
                                                 allocationRectangleHeight
                                                 - mProps.marginTop
                                                 - mProps.marginBottom);

        int overflow = this.properties.get("overflow").getEnum();
        String columnCountAsString =
            this.properties.get("column-count").getString();
        int columnCount = 1;
        try {
            columnCount = Integer.parseInt(columnCountAsString);
        } catch (NumberFormatException nfe) {
            log.error("Bad value on region body 'column-count'");
            columnCount = 1;
        }
        if ((columnCount > 1) && (overflow == Overflow.SCROLL)) {
            // recover by setting 'column-count' to 1. This is allowed but
            // not required by the spec.
            log.error("Setting 'column-count' to 1 because "
                                   + "'overflow' is set to 'scroll'");
            columnCount = 1;
        }
        body.setColumnCount(columnCount);

        int columnGap =
            this.properties.get("column-gap").getLength().mvalue();
        body.setColumnGap(columnGap);

        body.setBackgroundColor(backgroundColor);

        return body;
    }

    protected String getDefaultRegionName() {
        return "xsl-region-body";
    }

    protected String getElementName() {
        return "fo:region-body";
    }

    public String getRegionClass() {
        return REGION_CLASS;
    }

}