KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > afp > fonts > CharacterSetOrientation


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: CharacterSetOrientation.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.afp.fonts;
21
22
23 /**
24  * The IBM Font Object Content Architecture (FOCA) supports presentation
25  * of character shapes by defining their characteristics, which include
26  * Font-Description information for identifying the characters, Font-Metric
27  * information for positioning the characters, and Character-Shape
28  * information for presenting the character images.
29  *
30  * Presenting a graphic character on a presentation surface requires
31  * that you communicate this information clearly to rotate and position
32  * characters correctly on the physical or logical page.
33  *
34  * This class proivdes font metric information for a particular font
35  * as by the orientation.
36  *
37  * This informtaion is obtained directly from the AFP font files which must
38  * be installed in the classpath under in the location specified by the path
39  * attribute in the afp-font.xml file.
40  * <p/>
41  */

42 public class CharacterSetOrientation {
43
44     /**
45      * The code page to which the character set relates
46      */

47     private String JavaDoc _codePage;
48
49     /**
50      * The encoding used for the code page
51      */

52     private String JavaDoc _encoding;
53
54     /**
55      * The ascender height for the character set
56      */

57     private int _ascender;
58
59     /**
60      * The descender depth for the character set
61      */

62     private int _descender;
63
64     /**
65      * The height of capital letters
66      */

67     private int _capHeight;
68
69     /**
70      * The characters in the charcater set
71      */

72     private int[] _characters = new int[256];
73
74     /**
75      * The height of lowercase letters
76      */

77     private int _xHeight;
78
79     /**
80      * The first character
81      */

82     private int _firstCharacter;
83
84     /**
85      * The last character
86      */

87     private int _lastCharacter;
88
89
90     /**
91      * The character set orientation
92      */

93     private int _orientation = 0;
94
95     /**
96      * Constructor for the CharacterSetOrientation, the orientation is
97      * expressed as the degrees rotation (i.e 0, 90, 180, 270)
98      * @param orientation the character set orientation
99      */

100     public CharacterSetOrientation(int orientation) {
101
102         _orientation = orientation;
103
104     }
105
106     /**
107      * Ascender height is the distance from the character baseline to the
108      * top of the character box. A negative ascender height signifies that
109      * all of the graphic character is below the character baseline. For
110      * a character rotation other than 0, ascender height loses its
111      * meaning when the character is lying on its side or is upside down
112      * with respect to normal viewing orientation. For the general case,
113      * Ascender Height is the character�s most positive y-axis value.
114      * For bounded character boxes, for a given character having an
115      * ascender, ascender height and baseline offset are equal.
116      * @return the ascender value in millipoints
117      */

118     public int getAscender() {
119         return _ascender;
120     }
121
122     /**
123      * Cap height is the average height of the uppercase characters in
124      * a font. This value is specified by the designer of a font and is
125      * usually the height of the uppercase M.
126      * @return the cap height value in millipoints
127      */

128     public int getCapHeight() {
129         return _capHeight;
130     }
131
132     /**
133      * Descender depth is the distance from the character baseline to
134      * the bottom of a character box. A negative descender depth signifies
135      * that all of the graphic character is above the character baseline.
136      * @return the descender value in millipoints
137      */

138     public int getDescender() {
139         return _descender;
140     }
141
142     /**
143      * The first character in the character set
144      * @return the first character
145      */

146     public int getFirstChar() {
147         return _firstCharacter;
148     }
149
150     /**
151      * The last character in the character set
152      * @return the last character
153      */

154     public int getLastChar() {
155         return _lastCharacter;
156     }
157
158     /**
159      * The orientation for these metrics in the character set
160      * @return the orientation
161      */

162     public int getOrientation() {
163         return _orientation;
164     }
165
166     /**
167      * Get the width (in 1/1000ths of a point size) of all characters
168      * in this character set.
169      * @return the widths of all characters
170      */

171     public int[] getWidths() {
172
173         int arr[] = new int[(getLastChar() - getFirstChar()) + 1];
174         System.arraycopy(_characters, getFirstChar(), arr, 0, (getLastChar() - getFirstChar()) + 1);
175         return arr;
176
177     }
178
179     /**
180      * XHeight refers to the height of the lower case letters above
181      * the baseline.
182      * @return heightX the typical height of characters
183      */

184     public int getXHeight() {
185         return _xHeight;
186     }
187
188     /**
189      * Get the width (in 1/1000ths of a point size) of the character
190      * identified by the parameter passed.
191      * @param character the character to evaluate
192      * @return the widths of the character
193      */

194     public int width(int character) {
195         return _characters[character];
196     }
197
198     /**
199      * Ascender height is the distance from the character baseline to the
200      * top of the character box. A negative ascender height signifies that
201      * all of the graphic character is below the character baseline. For
202      * a character rotation other than 0, ascender height loses its
203      * meaning when the character is lying on its side or is upside down
204      * with respect to normal viewing orientation. For the general case,
205      * Ascender Height is the character�s most positive y-axis value.
206      * For bounded character boxes, for a given character having an
207      * ascender, ascender height and baseline offset are equal.
208      * @param ascender the ascender to set
209      */

210     public void setAscender(int ascender) {
211         _ascender = ascender;
212     }
213
214     /**
215      * Cap height is the average height of the uppercase characters in
216      * a font. This value is specified by the designer of a font and is
217      * usually the height of the uppercase M.
218      * @param capHeight the cap height to set
219      */

220     public void setCapHeight(int capHeight) {
221         _capHeight = capHeight;
222     }
223
224     /**
225      * Descender depth is the distance from the character baseline to
226      * the bottom of a character box. A negative descender depth signifies
227      * that all of the graphic character is above the character baseline.
228      * @param descender the descender value in millipoints
229      */

230     public void setDescender(int descender) {
231         _descender = descender;
232     }
233
234     /**
235      * The first character in the character set
236      * @param firstCharacter the first character
237      */

238     public void setFirstChar(int firstCharacter) {
239         _firstCharacter = firstCharacter;
240     }
241
242     /**
243      * The last character in the character set
244      * @param lastCharacter the last character
245      */

246     public void setLastChar(int lastCharacter) {
247         _lastCharacter = lastCharacter;
248     }
249
250     /**
251      * Set the width (in 1/1000ths of a point size) of the character
252      * identified by the parameter passed.
253      * @param character the character for which the width is being set
254      * @param width the widths of the character
255      */

256     public void setWidth(int character, int width) {
257
258         if (character >= _characters.length) {
259             // Increase the size of the array if necessary
260
int arr[] = new int[(character - _firstCharacter) + 1];
261             System.arraycopy(_characters, 0, arr, 0, _characters.length);
262             _characters = arr;
263         }
264         _characters[character] = width;
265
266     }
267
268     /**
269      * XHeight refers to the height of the lower case letters above
270      * the baseline.
271      * @param xHeight the typical height of characters
272      */

273     public void setXHeight(int xHeight) {
274         _xHeight = xHeight;
275     }
276 }
277
Popular Tags