blob: 23cf0ec7a4991c3d36c8b8c3de38ebfcedeab0a2 (
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
|
/*
* $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.render;
// FOP
import org.apache.fop.pdf.PDFPathPaint;
import org.apache.fop.pdf.PDFColor;
import org.apache.fop.image.ImageArea;
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.properties.*;
import org.apache.fop.layout.*;
import org.apache.fop.layout.inline.*;
import org.apache.fop.datatypes.*;
import org.apache.fop.render.pdf.FontSetup;
import org.apache.log.Logger;
// Java
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
/**
* Abstract base class for all renderers.
*
*/
public abstract class AbstractRenderer implements Renderer {
protected Logger log;
/**
* the current vertical position in millipoints from bottom
*/
protected int currentYPosition = 0;
/**
* the current horizontal position in millipoints from left
*/
protected int currentXPosition = 0;
/**
* the horizontal position of the current area container
*/
protected int currentAreaContainerXPosition = 0;
public void setLogger(Logger logger) {
log = logger;
}
public void renderSpanArea(SpanArea area) {
Enumeration e = area.getChildren().elements();
while (e.hasMoreElements()) {
org.apache.fop.layout.Box b =
(org.apache.fop.layout.Box)e.nextElement();
b.render(this); // column areas
}
}
protected abstract void doFrame(Area area);
/**
* render area container
*
* @param area the area container to render
*/
public void renderAreaContainer(AreaContainer area) {
int saveY = this.currentYPosition;
int saveX = this.currentAreaContainerXPosition;
if (area.getPosition() == Position.ABSOLUTE) {
// XPosition and YPosition give the content rectangle position
this.currentYPosition = area.getYPosition();
this.currentAreaContainerXPosition = area.getXPosition();
} else if (area.getPosition() == Position.RELATIVE) {
this.currentYPosition -= area.getYPosition();
this.currentAreaContainerXPosition += area.getXPosition();
} else if (area.getPosition() == Position.STATIC) {
this.currentYPosition -= area.getPaddingTop()
+ area.getBorderTopWidth();
/*
* this.currentAreaContainerXPosition +=
* area.getPaddingLeft() + area.getBorderLeftWidth();
*/
}
this.currentXPosition = this.currentAreaContainerXPosition;
doFrame(area);
Enumeration e = area.getChildren().elements();
while (e.hasMoreElements()) {
Box b = (Box)e.nextElement();
b.render(this);
}
// Restore previous origin
this.currentYPosition = saveY;
this.currentAreaContainerXPosition = saveX;
if (area.getPosition() == Position.STATIC) {
this.currentYPosition -= area.getHeight();
}
/**
* **
* if (area.getPosition() != Position.STATIC) {
* this.currentYPosition = saveY;
* this.currentAreaContainerXPosition = saveX;
* } else
* this.currentYPosition -= area.getHeight();
* **
*/
}
/**
* render block area
*
* @param area the block area to render
*/
public void renderBlockArea(BlockArea area) {
// KLease: Temporary test to fix block positioning
// Offset ypos by padding and border widths
this.currentYPosition -= (area.getPaddingTop()
+ area.getBorderTopWidth());
doFrame(area);
Enumeration e = area.getChildren().elements();
while (e.hasMoreElements()) {
Box b = (Box)e.nextElement();
b.render(this);
}
this.currentYPosition -= (area.getPaddingBottom()
+ area.getBorderBottomWidth());
}
/**
* render line area
*
* @param area area to render
*/
public void renderLineArea(LineArea area) {
int rx = this.currentAreaContainerXPosition + area.getStartIndent();
int ry = this.currentYPosition;
int w = area.getContentWidth();
int h = area.getHeight();
this.currentYPosition -= area.getPlacementOffset();
this.currentXPosition = rx;
int bl = this.currentYPosition;
Enumeration e = area.getChildren().elements();
while (e.hasMoreElements()) {
Box b = (Box)e.nextElement();
if (b instanceof InlineArea) {
InlineArea ia = (InlineArea)b;
this.currentYPosition = ry - ia.getYOffset();
} else {
this.currentYPosition = ry - area.getPlacementOffset();
}
b.render(this);
}
this.currentYPosition = ry - h;
this.currentXPosition = rx;
}
}
|