KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > flow > AbstractGraphics


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: AbstractGraphics.java 488960 2006-12-20 08:34:28Z spepping $ */
19
20 package org.apache.fop.fo.flow;
21
22 import org.apache.fop.apps.FOPException;
23 import org.apache.fop.datatypes.Length;
24 import org.apache.fop.fo.FONode;
25 import org.apache.fop.fo.FObj;
26 import org.apache.fop.fo.PropertyList;
27 import org.apache.fop.fo.properties.CommonAccessibility;
28 import org.apache.fop.fo.properties.CommonAural;
29 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
30 import org.apache.fop.fo.properties.CommonMarginInline;
31 import org.apache.fop.fo.properties.CommonRelativePosition;
32 import org.apache.fop.fo.properties.KeepProperty;
33 import org.apache.fop.fo.properties.LengthRangeProperty;
34 import org.apache.fop.fo.properties.SpaceProperty;
35
36 /**
37  * Common base class for instream-foreign-object and external-graphics
38  * flow formatting objects.
39  */

40 public abstract class AbstractGraphics extends FObj {
41     
42     // The value of properties relevant for fo:instream-foreign-object
43
// and external-graphics.
44
private CommonBorderPaddingBackground commonBorderPaddingBackground;
45     private Length alignmentAdjust;
46     private int alignmentBaseline;
47     private Length baselineShift;
48     private LengthRangeProperty blockProgressionDimension;
49     // private ToBeImplementedProperty clip;
50
private Length contentHeight;
51     private Length contentWidth;
52     private int displayAlign;
53     private int dominantBaseline;
54     private Length height;
55     private String JavaDoc id;
56     private LengthRangeProperty inlineProgressionDimension;
57     private SpaceProperty lineHeight;
58     private int overflow;
59     private int scaling;
60     private int textAlign;
61     private Length width;
62     // Unused but valid items, commented out for performance:
63
// private CommonAccessibility commonAccessibility;
64
// private CommonAural commonAural;
65
// private CommonMarginInline commonMarginInline;
66
// private CommonRelativePosition commonRelativePosition;
67
// private String contentType;
68
// private KeepProperty keepWithNext;
69
// private KeepProperty keepWithPrevious;
70
// private int scalingMethod;
71
// End of property values
72

73
74
75     /**
76      * constructs an instream-foreign-object object (called by Maker).
77      *
78      * @param parent the parent formatting object
79      */

80     public AbstractGraphics(FONode parent) {
81         super(parent);
82     }
83
84     /**
85      * @see org.apache.fop.fo.FObj#bind(PropertyList)
86      */

87     public void bind(PropertyList pList) throws FOPException {
88         commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
89         alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
90         alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
91         baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
92         blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
93         // clip = pList.get(PR_CLIP);
94
contentHeight = pList.get(PR_CONTENT_HEIGHT).getLength();
95         contentWidth = pList.get(PR_CONTENT_WIDTH).getLength();
96         displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
97         dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
98         height = pList.get(PR_HEIGHT).getLength();
99         id = pList.get(PR_ID).getString();
100         inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange();
101         lineHeight = pList.get(PR_LINE_HEIGHT).getSpace();
102         overflow = pList.get(PR_OVERFLOW).getEnum();
103         scaling = pList.get(PR_SCALING).getEnum();
104         textAlign = pList.get(PR_TEXT_ALIGN).getEnum();
105         width = pList.get(PR_WIDTH).getLength();
106     }
107
108     /**
109      * Given the ipd and the content width calculates the
110      * required x offset based on the text-align property
111      * @param ipd the inline-progression-dimension of the object
112      * @param cwidth the calculated content width of the object
113      * @return the X offset
114      */

115     public int computeXOffset (int ipd, int cwidth) {
116         int xoffset = 0;
117         switch (textAlign) {
118             case EN_CENTER:
119                 xoffset = (ipd - cwidth) / 2;
120                 break;
121             case EN_END:
122                 xoffset = ipd - cwidth;
123                 break;
124             case EN_START:
125                 break;
126             case EN_JUSTIFY:
127             default:
128                 break;
129         }
130         return xoffset;
131     }
132
133     /**
134      * Given the bpd and the content height calculates the
135      * required y offset based on the display-align property
136      * @param bpd the block-progression-dimension of the object
137      * @param cheight the calculated content height of the object
138      * @return the Y offset
139      */

140     public int computeYOffset(int bpd, int cheight) {
141         int yoffset = 0;
142         switch (displayAlign) {
143             case EN_BEFORE:
144                 break;
145             case EN_AFTER:
146                 yoffset = bpd - cheight;
147                 break;
148             case EN_CENTER:
149                 yoffset = (bpd - cheight) / 2;
150                 break;
151             case EN_AUTO:
152             default:
153                 break;
154         }
155         return yoffset;
156     }
157
158     /**
159      * @return the "id" property.
160      */

161     public String JavaDoc getId() {
162         return id;
163     }
164
165     /**
166      * @return the Common Border, Padding, and Background Properties.
167      */

168     public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
169         return commonBorderPaddingBackground;
170     }
171
172     /**
173      * @return the "line-height" property.
174      */

175     public SpaceProperty getLineHeight() {
176         return lineHeight;
177     }
178
179     /**
180      * @return the "inline-progression-dimension" property.
181      */

182     public LengthRangeProperty getInlineProgressionDimension() {
183         return inlineProgressionDimension;
184     }
185
186     /**
187      * @return the "block-progression-dimension" property.
188      */

189     public LengthRangeProperty getBlockProgressionDimension() {
190         return blockProgressionDimension;
191     }
192
193     /**
194      * @return the "height" property.
195      */

196     public Length getHeight() {
197         return height;
198     }
199
200     /**
201      * @return the "width" property.
202      */

203     public Length getWidth() {
204         return width;
205     }
206
207     /**
208      * @return the "content-height" property.
209      */

210     public Length getContentHeight() {
211         return contentHeight;
212     }
213
214     /**
215      * @return the "content-width" property.
216      */

217     public Length getContentWidth() {
218         return contentWidth;
219     }
220
221     /**
222      * @return the "scaling" property.
223      */

224     public int getScaling() {
225         return scaling;
226     }
227
228     /**
229      * @return the "overflow" property.
230      */

231     public int getOverflow() {
232         return overflow;
233     }
234
235     /**
236      * @return the "alignment-adjust" property
237      */

238     public Length getAlignmentAdjust() {
239         return alignmentAdjust;
240     }
241     
242     /**
243      * @return the "alignment-baseline" property
244      */

245     public int getAlignmentBaseline() {
246         return alignmentBaseline;
247     }
248     
249     /**
250      * @return the "baseline-shift" property
251      */

252     public Length getBaselineShift() {
253         return baselineShift;
254     }
255     
256     /**
257      * @return the "dominant-baseline" property
258      */

259     public int getDominantBaseline() {
260         return dominantBaseline;
261     }
262     
263     /**
264      * @return the graphics intrinsic width
265      */

266     public abstract int getIntrinsicWidth();
267
268     /**
269      * @return the graphics intrinsic height
270      */

271     public abstract int getIntrinsicHeight();
272 }
273
Popular Tags