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

import org.apache.fop.layout.Area;
import org.apache.fop.layout.FontState;
import org.apache.fop.layout.FontInfo;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.StreamRenderer;
import org.apache.fop.datatypes.ColorType;

import java.util.List;

/**
 * base class for representation of mixed content formatting objects
 * and their processing
 */
public class FObjMixed extends FObj {
    TextInfo textInfo = null;
    protected FontInfo fontInfo = null;

    public FObjMixed(FONode parent) {
        super(parent);
    }

    public void setStreamRenderer(StreamRenderer st) {
        fontInfo = st.getFontInfo();
    }

    public void addLayoutManager(List lms) {
        // set start and end properties for this element, id, etc.
        int numChildren = this.children.size();
        for (int i = 0; i < numChildren; i++) {
            Object o = children.get(i);
            if (o instanceof FObj) {
                FObj fo = (FObj) o;
                fo.addLayoutManager(lms);
            }
        }
    }

    protected void addCharacters(char data[], int start, int length) {
        if (textInfo == null) {
            textInfo = new TextInfo();

            try {
                textInfo.fs = propMgr.getFontState(fontInfo);
            } catch (FOPException fopex) {
                log.error("Error setting FontState for characters: " +
                          fopex.getMessage());
            }

            ColorType c = getProperty("color").getColorType();
            textInfo.color = c;

            textInfo.verticalAlign =
              getProperty("vertical-align").getEnum();

            textInfo.wrapOption = getProperty("wrap-option").getEnum();
            textInfo.whiteSpaceCollapse =
              getProperty("white-space-collapse").getEnum();

        }

        FOText ft = new FOText(data, start, length, textInfo);
        ft.setLogger(log);
        addChild(ft);
    }

    public Status layout(Area area) throws FOPException {

        if (this.properties != null) {
            Property prop = this.properties.get("id");
            if (prop != null) {
                String id = prop.getString();

                if (this.marker == START) {
                    if (area.getIDReferences() != null)
                        area.getIDReferences().createID(id);
                    this.marker = 0;
                }

                if (this.marker == 0) {
                    if (area.getIDReferences() != null)
                        area.getIDReferences().configureID(id, area);
                }
            }
        }

        int numChildren = this.children.size();
        for (int i = this.marker; i < numChildren; i++) {
            FONode fo = (FONode) children.get(i);
            Status status;
            if ((status = fo.layout(area)).isIncomplete()) {
                this.marker = i;
                return status;
            }
        }
        return new Status(Status.OK);
    }

    public CharIterator charIterator() {
        return new RecursiveCharIterator(this);
    }

}