001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: AbstractGraphics.java 554423 2007-07-08 19:47:53Z adelmelle $ */
019:
020: package org.apache.fop.fo.flow;
021:
022: import org.apache.fop.apps.FOPException;
023: import org.apache.fop.datatypes.Length;
024: import org.apache.fop.fo.FONode;
025: import org.apache.fop.fo.FObj;
026: import org.apache.fop.fo.PropertyList;
027: import org.apache.fop.fo.properties.CommonAccessibility;
028: import org.apache.fop.fo.properties.CommonAural;
029: import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
030: import org.apache.fop.fo.properties.CommonMarginInline;
031: import org.apache.fop.fo.properties.CommonRelativePosition;
032: import org.apache.fop.fo.properties.KeepProperty;
033: import org.apache.fop.fo.properties.LengthRangeProperty;
034: import org.apache.fop.fo.properties.SpaceProperty;
035:
036: /**
037: * Common base class for instream-foreign-object and external-graphics
038: * flow formatting objects.
039: */
040: public abstract class AbstractGraphics extends FObj {
041:
042: // The value of properties relevant for fo:instream-foreign-object
043: // and external-graphics.
044: private CommonBorderPaddingBackground commonBorderPaddingBackground;
045: private Length alignmentAdjust;
046: private int alignmentBaseline;
047: private Length baselineShift;
048: private LengthRangeProperty blockProgressionDimension;
049: // private ToBeImplementedProperty clip;
050: private Length contentHeight;
051: private Length contentWidth;
052: private int displayAlign;
053: private int dominantBaseline;
054: private Length height;
055: private String id;
056: private LengthRangeProperty inlineProgressionDimension;
057: private SpaceProperty lineHeight;
058: private int overflow;
059: private int scaling;
060: private int textAlign;
061: private Length width;
062:
063: // Unused but valid items, commented out for performance:
064: // private CommonAccessibility commonAccessibility;
065: // private CommonAural commonAural;
066: // private CommonMarginInline commonMarginInline;
067: // private CommonRelativePosition commonRelativePosition;
068: // private String contentType;
069: // private KeepProperty keepWithNext;
070: // private KeepProperty keepWithPrevious;
071: // private int scalingMethod;
072: // End of property values
073:
074: /**
075: * constructs an instream-foreign-object object (called by Maker).
076: *
077: * @param parent the parent formatting object
078: */
079: public AbstractGraphics(FONode parent) {
080: super (parent);
081: }
082:
083: /**
084: * @see org.apache.fop.fo.FObj#bind(PropertyList)
085: */
086: public void bind(PropertyList pList) throws FOPException {
087: commonBorderPaddingBackground = pList
088: .getBorderPaddingBackgroundProps();
089: alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
090: alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
091: baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
092: blockProgressionDimension = pList.get(
093: PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
094: // clip = pList.get(PR_CLIP);
095: contentHeight = pList.get(PR_CONTENT_HEIGHT).getLength();
096: contentWidth = pList.get(PR_CONTENT_WIDTH).getLength();
097: displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
098: dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
099: height = pList.get(PR_HEIGHT).getLength();
100: id = pList.get(PR_ID).getString();
101: inlineProgressionDimension = pList.get(
102: PR_INLINE_PROGRESSION_DIMENSION).getLengthRange();
103: lineHeight = pList.get(PR_LINE_HEIGHT).getSpace();
104: overflow = pList.get(PR_OVERFLOW).getEnum();
105: scaling = pList.get(PR_SCALING).getEnum();
106: textAlign = pList.get(PR_TEXT_ALIGN).getEnum();
107: width = pList.get(PR_WIDTH).getLength();
108: }
109:
110: /**
111: * Given the ipd and the content width calculates the
112: * required x offset based on the text-align property
113: * @param ipd the inline-progression-dimension of the object
114: * @param cwidth the calculated content width of the object
115: * @return the X offset
116: */
117: public int computeXOffset(int ipd, int cwidth) {
118: int xoffset = 0;
119: switch (textAlign) {
120: case EN_CENTER:
121: xoffset = (ipd - cwidth) / 2;
122: break;
123: case EN_END:
124: xoffset = ipd - cwidth;
125: break;
126: case EN_START:
127: break;
128: case EN_JUSTIFY:
129: default:
130: break;
131: }
132: return xoffset;
133: }
134:
135: /**
136: * Given the bpd and the content height calculates the
137: * required y offset based on the display-align property
138: * @param bpd the block-progression-dimension of the object
139: * @param cheight the calculated content height of the object
140: * @return the Y offset
141: */
142: public int computeYOffset(int bpd, int cheight) {
143: int yoffset = 0;
144: switch (displayAlign) {
145: case EN_BEFORE:
146: break;
147: case EN_AFTER:
148: yoffset = bpd - cheight;
149: break;
150: case EN_CENTER:
151: yoffset = (bpd - cheight) / 2;
152: break;
153: case EN_AUTO:
154: default:
155: break;
156: }
157: return yoffset;
158: }
159:
160: /**
161: * @return the "id" property.
162: */
163: public String getId() {
164: return id;
165: }
166:
167: /**
168: * @return the Common Border, Padding, and Background Properties.
169: */
170: public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
171: return commonBorderPaddingBackground;
172: }
173:
174: /**
175: * @return the "line-height" property.
176: */
177: public SpaceProperty getLineHeight() {
178: return lineHeight;
179: }
180:
181: /**
182: * @return the "inline-progression-dimension" property.
183: */
184: public LengthRangeProperty getInlineProgressionDimension() {
185: return inlineProgressionDimension;
186: }
187:
188: /**
189: * @return the "block-progression-dimension" property.
190: */
191: public LengthRangeProperty getBlockProgressionDimension() {
192: return blockProgressionDimension;
193: }
194:
195: /**
196: * @return the "height" property.
197: */
198: public Length getHeight() {
199: return height;
200: }
201:
202: /**
203: * @return the "width" property.
204: */
205: public Length getWidth() {
206: return width;
207: }
208:
209: /**
210: * @return the "content-height" property.
211: */
212: public Length getContentHeight() {
213: return contentHeight;
214: }
215:
216: /**
217: * @return the "content-width" property.
218: */
219: public Length getContentWidth() {
220: return contentWidth;
221: }
222:
223: /**
224: * @return the "scaling" property.
225: */
226: public int getScaling() {
227: return scaling;
228: }
229:
230: /**
231: * @return the "overflow" property.
232: */
233: public int getOverflow() {
234: return overflow;
235: }
236:
237: /**
238: * @return the "alignment-adjust" property
239: */
240: public Length getAlignmentAdjust() {
241: if (alignmentAdjust.getEnum() == EN_AUTO) {
242: final Length intrinsicAlignmentAdjust = this
243: .getIntrinsicAlignmentAdjust();
244: if (intrinsicAlignmentAdjust != null) {
245: return intrinsicAlignmentAdjust;
246: }
247: }
248: return alignmentAdjust;
249: }
250:
251: /**
252: * @return the "alignment-baseline" property
253: */
254: public int getAlignmentBaseline() {
255: return alignmentBaseline;
256: }
257:
258: /**
259: * @return the "baseline-shift" property
260: */
261: public Length getBaselineShift() {
262: return baselineShift;
263: }
264:
265: /**
266: * @return the "dominant-baseline" property
267: */
268: public int getDominantBaseline() {
269: return dominantBaseline;
270: }
271:
272: /**
273: * @return the graphics intrinsic width in millipoints
274: */
275: public abstract int getIntrinsicWidth();
276:
277: /**
278: * @return the graphics intrinsic height in millipoints
279: */
280: public abstract int getIntrinsicHeight();
281:
282: /**
283: * @return the graphics intrinsic alignment-adjust
284: */
285: public abstract Length getIntrinsicAlignmentAdjust();
286: }
|