KickJava   Java API By Example, From Geeks To Geeks.

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


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: OutlineFont.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.afp.fonts;
21
22 /**
23  * A font defined as a set of lines and curves as opposed to a bitmap font. An
24  * outline font can be scaled to any size and otherwise transformed more easily
25  * than a bitmap font, and with more attractive results. <p/>
26  *
27  */

28 public class OutlineFont extends AFPFont {
29
30     /** The character set for this font */
31     private CharacterSet _characterSet = null;
32
33     /**
34      * Constructor for an outline font.
35      *
36      * @param name
37      * the name of the font
38      * @param characterSet
39      * the chracter set
40      */

41     public OutlineFont(String JavaDoc name, CharacterSet characterSet) {
42         super(name);
43         _characterSet = characterSet;
44     }
45
46     /**
47      * Get the character set metrics.
48      *
49      * @return the character set
50      */

51     public CharacterSet getCharacterSet() {
52
53         return _characterSet;
54
55     }
56
57     /**
58      * Get the character set metrics.
59      * @param size ignored
60      * @return the character set
61      */

62     public CharacterSet getCharacterSet(int size) {
63
64         return _characterSet;
65
66     }
67
68     /**
69      * Get the first character in this font.
70      */

71     public int getFirstChar() {
72
73         return _characterSet.getFirstChar();
74
75     }
76
77     /**
78      * Get the last character in this font.
79      */

80     public int getLastChar() {
81
82         return _characterSet.getLastChar();
83
84     }
85
86     /**
87      * The ascender is the part of a lowercase letter that extends above the
88      * "x-height" (the height of the letter "x"), such as "d", "t", or "h". Also
89      * used to denote the part of the letter extending above the x-height.
90      *
91      * @param size
92      * the point size
93      */

94     public int getAscender(int size) {
95
96         return _characterSet.getAscender() / 1000 * size;
97
98     }
99
100     /**
101      * Obtains the height of capital letters for the specified point size.
102      *
103      * @param size
104      * the point size
105      */

106     public int getCapHeight(int size) {
107
108         return _characterSet.getCapHeight() / 1000 * size;
109
110     }
111
112     /**
113      * The descender is the part of a lowercase letter that extends below the
114      * base line, such as "g", "j", or "p". Also used to denote the part of the
115      * letter extending below the base line.
116      *
117      * @param size
118      * the point size
119      */

120     public int getDescender(int size) {
121
122         return _characterSet.getDescender() / 1000 * size;
123
124     }
125
126     /**
127      * The "x-height" (the height of the letter "x").
128      *
129      * @param size
130      * the point size
131      */

132     public int getXHeight(int size) {
133
134         return _characterSet.getXHeight() / 1000 * size;
135
136     }
137
138     /**
139      * Obtain the width of the character for the specified point size.
140      */

141     public int getWidth(int character, int size) {
142
143         return _characterSet.width(character) / 1000 * size;
144
145     }
146
147     /**
148      * Get the getWidth (in 1/1000ths of a point size) of all characters in this
149      * character set.
150      *
151      * @param size
152      * the point size
153      * @return the widths of all characters
154      */

155     public int[] getWidths(int size) {
156
157         int[] widths = _characterSet.getWidths();
158         for (int i = 0; i < widths.length; i++) {
159             widths[i] = widths[i] / 1000 * size;
160         }
161         return widths;
162
163     }
164
165     /**
166      * Get the getWidth (in 1/1000ths of a point size) of all characters in this
167      * character set.
168      *
169      * @return the widths of all characters
170      */

171     public int[] getWidths() {
172
173         return getWidths(1000);
174
175     }
176
177     /**
178      * Map a Unicode character to a code point in the font.
179      * @param c character to map
180      * @return the mapped character
181      */

182     public char mapChar(char c) {
183         return _characterSet.mapChar(c);
184     }
185
186     /**
187      * Get the encoding of the font.
188      * @return the encoding
189      */

190     public String JavaDoc getEncoding() {
191         return _characterSet.getEncoding();
192     }
193
194 }
Popular Tags