001: /*
002: * @(#)PPCFontPeer.java 1.11 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: /**
028: * PPCFontPeer.java
029: *
030: */package sun.awt.pocketpc;
031:
032: import java.awt.Font;
033: import sun.io.CharToByteConverter;
034: import sun.awt.PlatformFont;
035:
036: public class PPCFontPeer extends PlatformFont {
037:
038: /*
039: * Name for Pocket PC FontSet.
040: */
041: private String wfsname;
042:
043: private PPCFontPeer(Font font) {
044: super (font.getName(), font.getStyle());
045:
046: if (props != null) {
047: wfsname = props.getProperty("fontset." + aliasName + "."
048: + styleString);
049: }
050: init(font);
051: }
052:
053: static PPCFontPeer getFontPeer(Font font) {
054: PPCFontPeer peer = getPeer(font);
055: if (peer == null) {
056: peer = new PPCFontPeer(font);
057: }
058:
059: return peer;
060: }
061:
062: private native void init(Font font);
063:
064: private static native PPCFontPeer getPeer(Font font);
065:
066: public CharToByteConverter getFontCharset(String charsetName,
067: String fontName) {
068:
069: CharToByteConverter fc;
070: if (charsetName.equals("default")) {
071: fc = (CharToByteConverter) charsetRegistry.get(fontName);
072: } else {
073: fc = (CharToByteConverter) charsetRegistry.get(charsetName);
074: }
075: if (fc instanceof CharToByteConverter) {
076: return fc;
077: }
078:
079: Class fcc = null;
080:
081: try {
082: fcc = Class.forName(charsetName);
083: } catch (ClassNotFoundException e) {
084: try {
085: fcc = Class.forName("sun.io." + charsetName);
086: } catch (ClassNotFoundException exx) {
087: try {
088: fcc = Class.forName("sun.awt.pocketpc."
089: + charsetName);
090: } catch (ClassNotFoundException ex) {
091: fc = getDefaultFontCharset(fontName);
092: }
093: }
094: }
095:
096: if (fc == null) {
097: try {
098: fc = (CharToByteConverter) fcc.newInstance();
099: } catch (InstantiationException e) {
100: return getDefaultFontCharset(fontName);
101: } catch (IllegalAccessException e) {
102: return getDefaultFontCharset(fontName);
103: }
104: }
105:
106: if (charsetName.equals("default")) {
107: charsetRegistry.put(fontName, fc);
108: } else {
109: charsetRegistry.put(charsetName, fc);
110: }
111: return fc;
112: }
113:
114: private CharToByteConverter getDefaultFontCharset(String fontName) {
115: return new PPCDefaultFontCharset(fontName);
116: }
117:
118: /*
119: * If font properties cannot be loaded (possibly because there is no file
120: * system present), use a set of en_US properties by default.
121: */
122: static {
123: if ((fprops.getProperty("serif.0").equals("unknown"))
124: || (fprops.getProperty("sansserif.0").equals("unknown"))
125: || (fprops.getProperty("monospaced.0")
126: .equals("unknown"))
127: || (fprops.getProperty("dialog.0").equals("unknown"))
128: || (fprops.getProperty("dialoginput.0")
129: .equals("unknown"))) {
130: fprops.put("dialog.0", "Arial,ANSI_CHARSET");
131: fprops.put("dialog.1",
132: "WingDings,SYMBOL_CHARSET,NEED_CONVERTED");
133: fprops.put("dialog.2",
134: "Symbol,SYMBOL_CHARSET,NEED_CONVERTED");
135: fprops.put("dialoginput.0", "Courier New,ANSI_CHARSET");
136: fprops.put("dialoginput.1",
137: "WingDings,SYMBOL_CHARSET,NEED_CONVERTED");
138: fprops.put("dialoginput.2",
139: "Symbol,SYMBOL_CHARSET,NEED_CONVERTED");
140: fprops.put("serif.0", "Times New Roman,ANSI_CHARSET");
141: fprops.put("serif.1",
142: "WingDings,SYMBOL_CHARSET,NEED_CONVERTED");
143: fprops.put("serif.2",
144: "Symbol,SYMBOL_CHARSET,NEED_CONVERTED");
145: fprops.put("sansserif.0", "Arial,ANSI_CHARSET");
146: fprops.put("sansserif.1",
147: "WingDings,SYMBOL_CHARSET,NEED_CONVERTED");
148: fprops.put("sansserif.2",
149: "Symbol,SYMBOL_CHARSET,NEED_CONVERTED");
150: fprops.put("monospaced.0", "Courier New,ANSI_CHARSET");
151: fprops.put("monospaced.1",
152: "WingDings,SYMBOL_CHARSET,NEED_CONVERTED");
153: fprops.put("monospaced.2",
154: "Symbol,SYMBOL_CHARSET,NEED_CONVERTED");
155: fprops.put("timesroman.0", "Times New Roman,ANSI_CHARSET");
156: fprops.put("helvetica.0", "Arial,ANSI_CHARSET");
157: fprops.put("courier.0", "Courier New,ANSI_CHARSET");
158: fprops.put("zapfdingbats.0", "WingDings,SYMBOL_CHARSET");
159: fprops.put("default.char", "2751");
160: fprops.put("fontcharset.dialog.1",
161: "sun.awt.pocketpc.CharToByteWingDings");
162: fprops.put("fontcharset.dialog.2",
163: "sun.awt.CharToByteSymbol");
164: fprops.put("fontcharset.dialoginput.1",
165: "sun.awt.pocketpc.CharToByteWingDings");
166: fprops.put("fontcharset.dialoginput.2",
167: "sun.awt.CharToByteSymbol");
168: fprops.put("fontcharset.serif.1",
169: "sun.awt.pocketpc.CharToByteWingDings");
170: fprops.put("fontcharset.serif.2",
171: "sun.awt.CharToByteSymbol");
172: fprops.put("fontcharset.sansserif.1",
173: "sun.awt.pocketpc.CharToByteWingDings");
174: fprops.put("fontcharset.sansserif.2",
175: "sun.awt.CharToByteSymbol");
176: fprops.put("fontcharset.monospaced.1",
177: "sun.awt.pocketpc.CharToByteWingDings");
178: fprops.put("fontcharset.monospaced.2",
179: "sun.awt.CharToByteSymbol");
180: fprops.put("exclusion.dialog.0", "0100-20ab,20ad-ffff");
181: fprops
182: .put("exclusion.dialoginput.0",
183: "0100-20ab,20ad-ffff");
184: fprops.put("exclusion.serif.0", "0100-20ab,20ad-ffff");
185: fprops.put("exclusion.sansserif.0", "0100-20ab,20ad-ffff");
186: fprops.put("exclusion.monospaced.0", "0100-20ab,20ad-ffff");
187: fprops.put("inputtextcharset", "ANSI_CHARSET");
188: }
189: }
190: }
|