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: Character.java 567294 2007-08-18 17:00:50Z vhennebert $ */
019:
020: package org.apache.fop.fo.flow;
021:
022: import java.awt.Color;
023:
024: import org.apache.fop.apps.FOPException;
025: import org.apache.fop.datatypes.Length;
026: import org.apache.fop.fo.CharIterator;
027: import org.apache.fop.fo.FONode;
028: import org.apache.fop.fo.FObj;
029: import org.apache.fop.fo.PropertyList;
030: import org.apache.fop.fo.ValidationException;
031: import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
032: import org.apache.fop.fo.properties.CommonFont;
033: import org.apache.fop.fo.properties.CommonHyphenation;
034: import org.apache.fop.fo.properties.CommonTextDecoration;
035: import org.apache.fop.fo.properties.Property;
036: import org.apache.fop.fo.properties.SpaceProperty;
037: import org.xml.sax.Locator;
038:
039: /**
040: * This class represents the flow object 'fo:character'. Its use is defined by
041: * the spec: "The fo:character flow object represents a character that is mapped to
042: * a glyph for presentation. It is an atomic unit to the formatter.
043: * When the result tree is interpreted as a tree of formatting objects,
044: * a character in the result tree is treated as if it were an empty
045: * element of type fo:character with a character attribute
046: * equal to the Unicode representation of the character.
047: * The semantics of an "auto" value for character properties, which is
048: * typically their initial value, are based on the Unicode codepoint.
049: * Overrides may be specified in an implementation-specific manner." (6.6.3)
050: *
051: */
052: public class Character extends FObj {
053: // The value of properties relevant for fo:character.
054: private CommonBorderPaddingBackground commonBorderPaddingBackground;
055: private CommonFont commonFont;
056: private CommonHyphenation commonHyphenation;
057: private Length alignmentAdjust;
058: private int alignmentBaseline;
059: private Length baselineShift;
060: /** Holds the character value */
061: protected char character;
062: private Color color;
063: private int dominantBaseline;
064: // private ToBeImplementedProperty glyphOrientationHorizontal;
065: // private ToBeImplementedProperty glyphOrientationVertical;
066: private Property letterSpacing;
067: private SpaceProperty lineHeight;
068: /** Holds the text decoration values. May be null */
069: private CommonTextDecoration textDecoration;
070: // private ToBeImplementedProperty textShadow;
071: private Property wordSpacing;
072: // Unused but valid items, commented out for performance:
073: // private CommonAural commonAural;
074: // private CommonMarginInline commonMarginInline;
075: // private CommonRelativePosition commonRelativePosition;
076: // private int treatAsWordSpace;
077: // private Length textDepth;
078: // private Length textAltitude;
079: // private KeepProperty keepWithNext;
080: // private KeepProperty keepWithPrevious;
081: // private int scoreSpaces;
082: // private int suppressAtLineBreak;
083: // private int textTransform;
084: // private int visibility;
085: // End of property values
086:
087: /** constant indicating that the character is OK */
088: public static final int OK = 0;
089: /** constant indicating that the character does not fit */
090: public static final int DOESNOT_FIT = 1;
091:
092: /**
093: * @param parent FONode that is the parent of this object
094: */
095: public Character(FONode parent) {
096: super (parent);
097: }
098:
099: /**
100: * {@inheritDoc}
101: */
102: public void bind(PropertyList pList) throws FOPException {
103: super .bind(pList);
104: commonBorderPaddingBackground = pList
105: .getBorderPaddingBackgroundProps();
106: commonFont = pList.getFontProps();
107: commonHyphenation = pList.getHyphenationProps();
108:
109: alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
110: alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
111: baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
112: character = pList.get(PR_CHARACTER).getCharacter();
113: color = pList.get(PR_COLOR).getColor(getUserAgent());
114: dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
115: // glyphOrientationHorizontal = pList.get(PR_GLYPH_ORIENTATION_HORIZONTAL);
116: // glyphOrientationVertical = pList.get(PR_GLYPH_ORIENTATION_VERTICAL);
117: letterSpacing = pList.get(PR_LETTER_SPACING);
118: lineHeight = pList.get(PR_LINE_HEIGHT).getSpace();
119: textDecoration = pList.getTextDecorationProps();
120: // textShadow = pList.get(PR_TEXT_SHADOW);
121: wordSpacing = pList.get(PR_WORD_SPACING);
122: }
123:
124: /**
125: * {@inheritDoc}
126: */
127: protected void startOfNode() throws FOPException {
128: super .startOfNode();
129: getFOEventHandler().character(this );
130: }
131:
132: /**
133: * {@inheritDoc}
134: */
135: protected void validateChildNode(Locator loc, String nsURI,
136: String localName) throws ValidationException {
137: invalidChildError(loc, nsURI, localName);
138: }
139:
140: /**
141: * {@inheritDoc}
142: */
143: public CharIterator charIterator() {
144: return new FOCharIterator(this );
145: }
146:
147: /**
148: * @return the Common Border, Padding, and Background Properties.
149: */
150: public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
151: return commonBorderPaddingBackground;
152: }
153:
154: /**
155: * @return the Common Font Properties.
156: */
157: public CommonFont getCommonFont() {
158: return commonFont;
159: }
160:
161: /**
162: * @return the Common Hyphenation Properties.
163: */
164: public CommonHyphenation getCommonHyphenation() {
165: return commonHyphenation;
166: }
167:
168: /**
169: * @return the "character" property.
170: */
171: public char getCharacter() {
172: return character;
173: }
174:
175: /**
176: * @return the "color" property.
177: */
178: public Color getColor() {
179: return color;
180: }
181:
182: /**
183: * @return the "alignment-adjust" property
184: */
185: public Length getAlignmentAdjust() {
186: return alignmentAdjust;
187: }
188:
189: /**
190: * @return the "alignment-baseline" property
191: */
192: public int getAlignmentBaseline() {
193: return alignmentBaseline;
194: }
195:
196: /**
197: * @return the "baseline-shift" property
198: */
199: public Length getBaselineShift() {
200: return baselineShift;
201: }
202:
203: /**
204: * @return the "dominant-baseline" property
205: */
206: public int getDominantBaseline() {
207: return dominantBaseline;
208: }
209:
210: /**
211: * @return the "letter-spacing" property.
212: */
213: public Property getLetterSpacing() {
214: return letterSpacing;
215: }
216:
217: /**
218: * @return the "line-height" property.
219: */
220: public SpaceProperty getLineHeight() {
221: return lineHeight;
222: }
223:
224: /** @return the "text-decoration" property. */
225: public CommonTextDecoration getTextDecoration() {
226: return textDecoration;
227: }
228:
229: /**
230: * @return the "word-spacing" property.
231: */
232: public Property getWordSpacing() {
233: return wordSpacing;
234: }
235:
236: /**
237: * {@inheritDoc}
238: */
239: public String getLocalName() {
240: return "character";
241: }
242:
243: /**
244: * {@inheritDoc}
245: */
246: public int getNameId() {
247: return FO_CHARACTER;
248: }
249:
250: }
|