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: OutlineFont.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.render.afp.fonts;
021:
022: /**
023: * A font defined as a set of lines and curves as opposed to a bitmap font. An
024: * outline font can be scaled to any size and otherwise transformed more easily
025: * than a bitmap font, and with more attractive results. <p/>
026: *
027: */
028: public class OutlineFont extends AFPFont {
029:
030: /** The character set for this font */
031: private CharacterSet _characterSet = null;
032:
033: /**
034: * Constructor for an outline font.
035: *
036: * @param name
037: * the name of the font
038: * @param characterSet
039: * the chracter set
040: */
041: public OutlineFont(String name, CharacterSet characterSet) {
042: super (name);
043: _characterSet = characterSet;
044: }
045:
046: /**
047: * Get the character set metrics.
048: *
049: * @return the character set
050: */
051: public CharacterSet getCharacterSet() {
052:
053: return _characterSet;
054:
055: }
056:
057: /**
058: * Get the character set metrics.
059: * @param size ignored
060: * @return the character set
061: */
062: public CharacterSet getCharacterSet(int size) {
063:
064: return _characterSet;
065:
066: }
067:
068: /**
069: * Get the first character in this font.
070: */
071: public int getFirstChar() {
072:
073: return _characterSet.getFirstChar();
074:
075: }
076:
077: /**
078: * Get the last character in this font.
079: */
080: public int getLastChar() {
081:
082: return _characterSet.getLastChar();
083:
084: }
085:
086: /**
087: * The ascender is the part of a lowercase letter that extends above the
088: * "x-height" (the height of the letter "x"), such as "d", "t", or "h". Also
089: * used to denote the part of the letter extending above the x-height.
090: *
091: * @param size
092: * the point size
093: */
094: public int getAscender(int size) {
095:
096: return _characterSet.getAscender() / 1000 * size;
097:
098: }
099:
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 getEncoding() {
191: return _characterSet.getEncoding();
192: }
193:
194: }
|