KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: Character.java,v 1.12.2.4 2003/04/11 00:24:38 pietsch Exp $
3  * ============================================================================
4  * The Apache Software License, Version 1.1
5  * ============================================================================
6  *
7  * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modifica-
10  * tion, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if any, must
20  * include the following acknowledgment: "This product includes software
21  * developed by the Apache Software Foundation (http://www.apache.org/)."
22  * Alternately, this acknowledgment may appear in the software itself, if
23  * and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "FOP" and "Apache Software Foundation" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * apache@apache.org.
29  *
30  * 5. Products derived from this software may not be called "Apache", nor may
31  * "Apache" appear in their name, without prior written permission of the
32  * Apache Software Foundation.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  * ============================================================================
45  *
46  * This software consists of voluntary contributions made by many individuals
47  * on behalf of the Apache Software Foundation and was originally created by
48  * James Tauber <jtauber@jtauber.com>. For more information on the Apache
49  * Software Foundation, please see <http://www.apache.org/>.
50  */

51 package org.apache.fop.fo.flow;
52
53 // fop
54
import org.apache.fop.fo.*;
55 import org.apache.fop.datatypes.ColorType;
56 import org.apache.fop.layout.BlockArea;
57 import org.apache.fop.layout.*;
58 import org.apache.fop.fo.FObj;
59 import org.apache.fop.layout.LineArea;
60 import org.apache.fop.apps.FOPException;
61
62
63 /**
64  * this class represents the flow object 'fo:character'. Its use is defined by
65  * the spec: "The fo:character flow object represents a character that is mapped to
66  * a glyph for presentation. It is an atomic unit to the formatter.
67  * When the result tree is interpreted as a tree of formatting objects,
68  * a character in the result tree is treated as if it were an empty
69  * element of type fo:character with a character attribute
70  * equal to the Unicode representation of the character.
71  * The semantics of an "auto" value for character properties, which is
72  * typically their initial value, are based on the Unicode codepoint.
73  * Overrides may be specified in an implementation-specific manner." (6.6.3)
74  *
75  */

76 public class Character extends FObj {
77     public static final int OK = 0;
78     public static final int DOESNOT_FIT = 1;
79
80     public static class Maker extends FObj.Maker {
81         public FObj make(FObj parent, PropertyList propertyList,
82                          String JavaDoc systemId, int line, int column)
83             throws FOPException {
84             return new Character JavaDoc(parent, propertyList, systemId, line, column);
85         }
86     }
87
88     public static FObj.Maker maker() {
89         return new Character.Maker JavaDoc();
90     }
91
92     public Character(FObj parent, PropertyList propertyList,
93                      String JavaDoc systemId, int line, int column) {
94         super(parent, propertyList, systemId, line, column);
95     }
96
97     public String JavaDoc getName() {
98         return "fo:character";
99     }
100
101     public int layout(Area area) throws FOPException {
102         BlockArea blockArea;
103         if (!(area instanceof BlockArea)) {
104             log.warn("currently Character can only be in a BlockArea");
105             return Status.OK;
106         }
107         blockArea = (BlockArea)area;
108         boolean textDecoration;
109
110         // Common Aural Properties
111
AuralProps mAurProps = propMgr.getAuralProps();
112
113         // Common Border, Padding, and Background Properties
114
BorderAndPadding bap = propMgr.getBorderAndPadding();
115         BackgroundProps bProps = propMgr.getBackgroundProps();
116
117         // Common Font Properties
118
//this.fontState = propMgr.getFontState(area.getFontInfo());
119

120         // Common Hyphenation Properties
121
HyphenationProps mHyphProps = propMgr.getHyphenationProps();
122
123         // Common Margin Properties-Inline
124
MarginInlineProps mProps = propMgr.getMarginInlineProps();
125
126         // Common Relative Position Properties
127
RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
128
129         // this.properties.get("alignment-adjust");
130
// this.properties.get("treat-as-word-space");
131
// this.properties.get("alignment-baseline");
132
// this.properties.get("baseline-shift");
133
// this.properties.get("character");
134
// this.properties.get("color");
135
// this.properties.get("dominant-baseline");
136
// this.properties.get("text-depth");
137
// this.properties.get("text-altitude");
138
// this.properties.get("glyph-orientation-horizontal");
139
// this.properties.get("glyph-orientation-vertical");
140
// this.properties.get("id");
141
// this.properties.get("keep-with-next");
142
// this.properties.get("keep-with-previous");
143
// this.properties.get("letter-spacing");
144
// this.properties.get("line-height");
145
// this.properties.get("line-height-shift-adjustment");
146
// this.properties.get("score-spaces");
147
// this.properties.get("suppress-at-line-break");
148
// this.properties.get("text-decoration");
149
// this.properties.get("text-shadow");
150
// this.properties.get("text-transform");
151
// this.properties.get("word-spacing");
152

153         // color properties
154
ColorType c = this.properties.get("color").getColorType();
155         float red = c.red();
156         float green = c.green();
157         float blue = c.blue();
158
159         int whiteSpaceCollapse =
160             this.properties.get("white-space-collapse").getEnum();
161         int wrapOption = this.parent.properties.get("wrap-option").getEnum();
162
163         int tmp = this.properties.get("text-decoration").getEnum();
164         if (tmp == org.apache.fop.fo.properties.TextDecoration.UNDERLINE) {
165             textDecoration = true;
166         } else {
167             textDecoration = false;
168         }
169
170         // Character specific properties
171
char characterValue = this.properties.get("character").getCharacter();
172
173
174         // initialize id
175
String JavaDoc id = this.properties.get("id").getString();
176         try {
177             blockArea.getIDReferences().initializeID(id, blockArea);
178         }
179         catch(FOPException e) {
180             if (!e.isLocationSet()) {
181                 e.setLocation(systemId, line, column);
182             }
183             throw e;
184         }
185
186         LineArea la = blockArea.getCurrentLineArea();
187         if (la == null) {
188             return Status.AREA_FULL_NONE;
189         }
190         la.changeFont(propMgr.getFontState(area.getFontInfo()));
191         la.changeColor(red, green, blue);
192         la.changeWrapOption(wrapOption);
193         la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
194         blockArea.setupLinkSet(this.getLinkSet());
195         int result = la.addCharacter(characterValue, this.getLinkSet(),
196                                      textDecoration);
197         if (result == Character.DOESNOT_FIT) {
198             la = blockArea.createNextLineArea();
199             if (la == null) {
200                 return Status.AREA_FULL_NONE;
201             }
202             la.changeFont(propMgr.getFontState(area.getFontInfo()));
203             la.changeColor(red, green, blue);
204             la.changeWrapOption(wrapOption);
205             la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
206             blockArea.setupLinkSet(this.getLinkSet());
207             la.addCharacter(characterValue, this.getLinkSet(),
208                             textDecoration);
209         }
210         return Status.OK;
211
212     }
213
214 }
215
Popular Tags