1 /*
2 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 *
25 */
26
27 /*
28 * (C) Copyright IBM Corp. 1999, All rights reserved.
29 */
30
31 package sun.font;
32
33 import java.awt.Font;
34 import java.awt.GraphicsEnvironment;
35 import java.awt.font.TextAttribute;
36 import java.util.ArrayList;
37 import java.util.Map;
38 import sun.text.CodePointIterator;
39
40 /**
41 * This class maps an individual character to a Font family which can
42 * display it. The character-to-Font mapping does not depend on the
43 * character's context, so a particular character will be mapped to the
44 * same font family each time.
45 * <p>
46 * Typically, clients will call getIndexFor(char) for each character
47 * in a style run. When getIndexFor() returns a different value from
48 * ones seen previously, the characters up to that point will be assigned
49 * a font obtained from getFont().
50 */
51 public final class FontResolver {
52
53 // An array of all fonts available to the runtime. The fonts
54 // will be searched in order.
55 private Font[] allFonts;
205 }
206 }
207 }
208 return fontIndex;
209 }
210
211 /**
212 * Return a Font from a given font index with properties
213 * from attributes. The font index, which should have been produced
214 * by getFontIndex(), determines a font family. The size and style
215 * of the Font reflect the properties in attributes. Any Font or
216 * font family specifications in attributes are ignored, on the
217 * assumption that clients have already handled them.
218 * @param index an index from getFontIndex() which determines the
219 * font family
220 * @param attributes a Map from which the size and style of the Font
221 * are determined. The default size is 12 and the default style
222 * is Font.PLAIN
223 * @see #getFontIndex
224 */
225 public Font getFont(int index, Map attributes) {
226 Font font = defaultFont;
227
228 if (index >= 2) {
229 font = allFonts[index-2];
230 }
231
232 return font.deriveFont(attributes);
233 }
234
235 private static FontResolver INSTANCE;
236
237 /**
238 * Return a shared instance of FontResolver.
239 */
240 public static FontResolver getInstance() {
241 if (INSTANCE == null) {
242 INSTANCE = new FontResolver();
243 }
244 return INSTANCE;
245 }
|
1 /*
2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 *
25 */
26
27 /*
28 * (C) Copyright IBM Corp. 1999, All rights reserved.
29 */
30
31 package sun.font;
32
33 import java.awt.Font;
34 import java.awt.GraphicsEnvironment;
35 import java.awt.font.TextAttribute;
36 import java.text.AttributedCharacterIterator;
37 import java.util.ArrayList;
38 import java.util.Map;
39 import sun.text.CodePointIterator;
40
41 /**
42 * This class maps an individual character to a Font family which can
43 * display it. The character-to-Font mapping does not depend on the
44 * character's context, so a particular character will be mapped to the
45 * same font family each time.
46 * <p>
47 * Typically, clients will call getIndexFor(char) for each character
48 * in a style run. When getIndexFor() returns a different value from
49 * ones seen previously, the characters up to that point will be assigned
50 * a font obtained from getFont().
51 */
52 public final class FontResolver {
53
54 // An array of all fonts available to the runtime. The fonts
55 // will be searched in order.
56 private Font[] allFonts;
206 }
207 }
208 }
209 return fontIndex;
210 }
211
212 /**
213 * Return a Font from a given font index with properties
214 * from attributes. The font index, which should have been produced
215 * by getFontIndex(), determines a font family. The size and style
216 * of the Font reflect the properties in attributes. Any Font or
217 * font family specifications in attributes are ignored, on the
218 * assumption that clients have already handled them.
219 * @param index an index from getFontIndex() which determines the
220 * font family
221 * @param attributes a Map from which the size and style of the Font
222 * are determined. The default size is 12 and the default style
223 * is Font.PLAIN
224 * @see #getFontIndex
225 */
226 public Font getFont(int index,
227 Map<? extends AttributedCharacterIterator.Attribute, ?> attributes) {
228 Font font = defaultFont;
229
230 if (index >= 2) {
231 font = allFonts[index-2];
232 }
233
234 return font.deriveFont(attributes);
235 }
236
237 private static FontResolver INSTANCE;
238
239 /**
240 * Return a shared instance of FontResolver.
241 */
242 public static FontResolver getInstance() {
243 if (INSTANCE == null) {
244 INSTANCE = new FontResolver();
245 }
246 return INSTANCE;
247 }
|