aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/fo/flow/TableCell.java
blob: f2df8328c580eba6fcaf3614084e191f1ff79835 (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
package org.apache.xml.fop.fo.flow;

// FOP
import org.apache.xml.fop.fo.*;
import org.apache.xml.fop.fo.properties.*;
import org.apache.xml.fop.layout.*;
import org.apache.xml.fop.apps.FOPException;

public class TableCell extends FObj {

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

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

    FontState fs;
    int startIndent;
    int endIndent;
    int spaceBefore;
    int spaceAfter;

    protected int startOffset;
    protected int width;
    protected int height = 0;

    BlockArea blockArea;

    public TableCell(FObj parent, PropertyList propertyList) {
	super(parent, propertyList);
	this.name = "fo:table-cell";
    }

    public void setStartOffset(int offset) {
	startOffset = offset;
    }

    public void setWidth(int width) {
	this.width = width;
    }

    public int layout(Area area) throws FOPException {
	if (this.marker == BREAK_AFTER) {
	    return OK;
	}

	if (this.marker == START) {
	    String fontFamily =
		this.properties.get("font-family").getString(); 
	    String fontStyle =
		this.properties.get("font-style").getString(); 
	    String fontWeight =
		this.properties.get("font-weight").getString(); 
	    int fontSize =
		this.properties.get("font-size").getLength().mvalue(); 
	    
	    this.fs = new FontState(area.getFontInfo(), fontFamily, 
				    fontStyle, fontWeight, fontSize);  
	    this.startIndent =
		this.properties.get("start-indent").getLength().mvalue(); 
	    this.endIndent =
		this.properties.get("end-indent").getLength().mvalue(); 
	    this.spaceBefore =
		this.properties.get("space-before.optimum").getLength().mvalue();  
	    this.spaceAfter =
		this.properties.get("space-after.optimum").getLength().mvalue(); 
	    if (area instanceof BlockArea) {
		area.end();
	    }

	    //if (this.isInListBody) {
	    //startIndent += bodyIndent + distanceBetweenStarts;
	    //}

	    this.marker = 0;

	}

	if ((spaceBefore != 0) && (this.marker ==0)) {
	    area.addDisplaySpace(spaceBefore);
	}

	this.blockArea =
	    new BlockArea(fs, area.getAllocationWidth(), 
			  area.spaceLeft(), startIndent, endIndent, 0,
			  0, 0, 0);
	blockArea.setPage(area.getPage());
	blockArea.start();

	int numChildren = this.children.size();
	for (int i = this.marker; i < numChildren; i++) {
	    FObj fo = (FObj) children.elementAt(i);
	    fo.setIsInTableCell();
	    fo.forceStartOffset(startOffset);
	    fo.forceWidth(width);
	    int status;
	    if ((status = fo.layout(blockArea)) != OK) {
		this.marker = i;
		if ((i == 0) && (status == AREA_FULL_NONE)) {
		    return AREA_FULL_NONE;
		} else {
		    return AREA_FULL_SOME;
		}
	    }
	    height += blockArea.getHeight();

	}
	blockArea.end();
	area.addChild(blockArea);

	return OK;
    }

    public int getHeight() {
	return height;
    }
}