KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > java2d > FontMetricsMapper


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: FontMetricsMapper.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.render.java2d;
21
22 // Java
23
import java.awt.Graphics2D JavaDoc;
24 import java.util.Map JavaDoc;
25
26 // FOP
27
import org.apache.fop.fonts.FontMetrics;
28 import org.apache.fop.fonts.FontType;
29 import org.apache.fop.fonts.Typeface;
30
31
32 /**
33  * This class implements org.apache.fop.layout.FontMetrics and
34  * is added to the hash table in FontInfo. It deferes the
35  * actual calculation of the metrics to
36  * Java2DFontMetrics. It only keeps the java name and
37  * style as member varibles
38  */

39
40 public class FontMetricsMapper extends Typeface implements FontMetrics {
41
42     /**
43      * This is a Java2DFontMetrics that does the real calculation.
44      * It is only one class that dynamically determines the font-size.
45      */

46     private static Java2DFontMetrics metric = null;
47
48     /**
49      * The java name of the font.
50      * # Make the family name immutable.
51      */

52     private final String JavaDoc family;
53
54     /**
55      * The java style of the font.
56      * # Make the style immutable.
57      */

58     private final int style;
59
60     /**
61      * Constructs a new Font-metrics.
62      * @param family the family name of the font (java value)
63      * @param style the java type style value of the font
64      * @param graphics a Graphics2D object - this is needed so
65      * that we can get an instance of java.awt.FontMetrics
66      */

67     public FontMetricsMapper(String JavaDoc family, int style, Graphics2D JavaDoc graphics) {
68         this.family = family;
69         this.style = style;
70         if (metric == null) {
71             metric = new Java2DFontMetrics(graphics);
72         }
73     }
74
75     /**
76      * @see org.apache.fop.fonts.FontMetrics#getFontName()
77      */

78     public String JavaDoc getFontName() {
79         return family;
80     }
81
82     /**
83      * @see org.apache.fop.fonts.FontMetrics#getFontType()
84      */

85     public FontType getFontType() {
86         return FontType.OTHER;
87     }
88     
89     /**
90      * @see org.apache.fop.fonts.FontMetrics#getMaxAscent(int)
91      */

92     public int getMaxAscent(int size) {
93         return metric.getMaxAscent(family, style, size);
94     }
95
96     /**
97      * @see org.apache.fop.fonts.FontMetrics#getAscender(int)
98      */

99     public int getAscender(int size) {
100         return metric.getAscender(family, style, size);
101     }
102
103     /**
104      * @see org.apache.fop.fonts.FontMetrics#getCapHeight(int)
105      */

106     public int getCapHeight(int size) {
107         return metric.getCapHeight(family, style, size);
108     }
109
110     /**
111      * @see org.apache.fop.fonts.FontMetrics#getDescender(int)
112      */

113     public int getDescender(int size) {
114         return metric.getDescender(family, style, size);
115     }
116
117     /**
118      * @see org.apache.fop.fonts.FontMetrics#getXHeight(int)
119      */

120     public int getXHeight(int size) {
121         return metric.getXHeight(family, style, size);
122     }
123
124     /**
125      * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
126      */

127     public int getWidth(int i, int size) {
128         return metric.width(i, family, style, size);
129     }
130
131
132     /**
133      * @see org.apache.fop.fonts.FontMetrics#getWidths()
134      */

135     public int[] getWidths() {
136         return metric.getWidths(family, style, Java2DFontMetrics.FONT_SIZE);
137     }
138
139     /**
140      * Gets a Font instance of the Font that this
141      * FontMetrics describes in the desired size.
142      * @param size font size
143      * @return font with the desired characeristics.
144      */

145     public java.awt.Font JavaDoc getFont(int size) {
146         return metric.getFont(family, style, size);
147     }
148
149     /**
150      * @see org.apache.fop.fonts.FontMetrics#getKerningInfo()
151      */

152     public Map JavaDoc getKerningInfo() {
153         return java.util.Collections.EMPTY_MAP;
154     }
155
156     /**
157      * @see org.apache.fop.fonts.FontMetrics#hasKerningInfo()
158      */

159     public boolean hasKerningInfo() {
160         return false;
161     }
162
163     /** @see org.apache.fop.fonts.Typeface#getEncoding() */
164     public String JavaDoc getEncoding() {
165         return null; //Not applicable to Java2D rendering
166
}
167
168     /** @see org.apache.fop.fonts.Typeface#mapChar(char) */
169     public char mapChar(char c) {
170         return c;
171     }
172
173     /** @see org.apache.fop.fonts.Typeface#hasChar(char) */
174     public boolean hasChar(char c) {
175         return metric.hasChar(family, style, Java2DFontMetrics.FONT_SIZE, c);
176     }
177
178 }
179
180
181
182
183
184
Popular Tags