Source Code Cross Referenced for FLFontManager.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » gl » font » fontlib » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.awt.gl.font.fontlib 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        package org.apache.harmony.awt.gl.font.fontlib;
018:
019:        import java.awt.Font;
020:        import java.awt.FontFormatException;
021:        import java.awt.peer.FontPeer;
022:        import java.io.File;
023:        import java.io.FilenameFilter;
024:        import java.io.IOException;
025:        import java.util.ArrayList;
026:        import java.util.Enumeration;
027:        import java.util.Hashtable;
028:        import java.util.Iterator;
029:
030:        import org.apache.harmony.awt.gl.font.CompositeFont;
031:        import org.apache.harmony.awt.gl.font.FontManager;
032:        import org.apache.harmony.awt.gl.font.FontPeerImpl;
033:        import org.apache.harmony.awt.internal.nls.Messages;
034:
035:        public class FLFontManager extends FontManager {
036:
037:            private ArrayList<Font> allFonts = new ArrayList<Font>();
038:
039:            static {
040:                System.loadLibrary("FL");
041:            }
042:
043:            public FLFontManager() {
044:
045:                Runtime.getRuntime().addShutdownHook(new DisposeNativeHook());
046:
047:                initManager();
048:
049:                addPath(new File(System.getProperty("java.home")
050:                        + "/lib/fonts/"));
051:                addPath(new File("C:\\WINNT\\Fonts"));
052:                addPath(new File("/usr/X11R6/lib/X11/fonts/Type1/"));
053:                addPath(new File("/usr/X11R6/lib/X11/fonts/truetype/"));
054:
055:                Font[] nativeFonts = getAllFontsNative();
056:
057:                if (nativeFonts != null)
058:                    for (int i = 0; i < nativeFonts.length; i++) {
059:                        allFonts.add(nativeFonts[i]);
060:                    }
061:
062:                allFamilies = getAllFamilies();
063:            }
064:
065:            class FLFilenameFilter implements  FilenameFilter {
066:
067:                public boolean accept(File dir, String str) {
068:                    String suffix = str.substring(str.length() - 3)
069:                            .toLowerCase();
070:                    return suffix.equals("pfb") || suffix.equals("pfa")
071:                            || suffix.equals("ttf");
072:                }
073:
074:            }
075:
076:            FilenameFilter filter = new FLFilenameFilter();
077:
078:            private void addPath(File path) {
079:                if (!path.canRead() || !path.isDirectory())
080:                    return;
081:
082:                String[] strMas = path.list(filter);
083:
084:                String dir = path.getAbsolutePath();
085:
086:                Font newFont;
087:
088:                for (int i = 0; i < strMas.length; i++) {
089:                    String str = strMas[i].substring(strMas[i].length() - 3)
090:                            .toLowerCase();
091:                    newFont = addFont(dir + "/" + strMas[i],
092:                            str.equals("ttf") ? Font.TRUETYPE_FONT
093:                                    : Font.TYPE1_FONT);
094:
095:                    if (newFont != null) {
096:                        allFonts.add(newFont);
097:                    }
098:                }
099:            }
100:
101:            @Override
102:            public FontPeer createPhysicalFontPeer(String name, int style,
103:                    int size) {
104:                FontPeerImpl peer = null;
105:
106:                if (isFontExistInList(name, style)) {
107:                    try {
108:                        peer = new FLFontPeer(name, style, size);
109:
110:                        peer.setFamily(name);
111:                    } catch (NullPointerException e) {
112:                        peer = new FLFontPeer(DEFAULT_NAME, style, size);
113:
114:                        peer.setFamily(DEFAULT_NAME);
115:                    }
116:                } else {
117:                    peer = new FLFontPeer(DEFAULT_NAME, style, size);
118:
119:                    peer.setFamily(DEFAULT_NAME);
120:                }
121:
122:                return peer;
123:            }
124:
125:            private boolean isFontExistInList(String name, int style) {
126:                for (Font font : allFonts) {
127:                    if (font.getStyle() == style && font.getName().equals(name)) {
128:                        return true;
129:                    }
130:                }
131:
132:                return false;
133:            }
134:
135:            @Override
136:            public FontPeer createDefaultFont(int style, int size) {
137:                //return getFontPeer(DIALOG_NAME, style, size);
138:                return createPhysicalFontPeer(DEFAULT_NAME, style, size);
139:            }
140:
141:            /**
142:             * Initializes LCID table
143:             */
144:            @Override
145:            public void initLCIDTable() {
146:
147:                Hashtable<String, Short> ht = tableLCID;
148:
149:                /*
150:                 *  Language records with LCID values (0x04**).
151:                 */
152:                ht.put(new String("ar"), new Short((short) 0x0401)); // ar-dz //$NON-NLS-1$
153:                ht.put(new String("bg"), new Short((short) 0x0402)); //$NON-NLS-1$
154:                ht.put(new String("ca"), new Short((short) 0x0403)); //$NON-NLS-1$
155:                ht.put(new String("zh"), new Short((short) 0x0404)); // zh-tw //$NON-NLS-1$
156:                ht.put(new String("cs"), new Short((short) 0x0405)); //$NON-NLS-1$
157:                ht.put(new String("da"), new Short((short) 0x0406)); //$NON-NLS-1$
158:                ht.put(new String("de"), new Short((short) 0x0407)); // de-de //$NON-NLS-1$
159:                ht.put(new String("el"), new Short((short) 0x0408)); //$NON-NLS-1$
160:                ht.put(new String("fi"), new Short((short) 0x040b)); //$NON-NLS-1$
161:                ht.put(new String("fr"), new Short((short) 0x040c)); // fr-fr //$NON-NLS-1$
162:                ht.put(new String("iw"), new Short((short) 0x040d)); // "he" //$NON-NLS-1$
163:                ht.put(new String("hu"), new Short((short) 0x040e)); //$NON-NLS-1$
164:                ht.put(new String("is"), new Short((short) 0x040f)); //$NON-NLS-1$
165:                ht.put(new String("it"), new Short((short) 0x0410)); // it-it //$NON-NLS-1$
166:                ht.put(new String("ja"), new Short((short) 0x0411)); //$NON-NLS-1$
167:                ht.put(new String("ko"), new Short((short) 0x0412)); //$NON-NLS-1$
168:                ht.put(new String("nl"), new Short((short) 0x0413)); // nl-nl //$NON-NLS-1$
169:                ht.put(new String("no"), new Short((short) 0x0414)); // no_no //$NON-NLS-1$
170:                ht.put(new String("pl"), new Short((short) 0x0415)); //$NON-NLS-1$
171:                ht.put(new String("pt"), new Short((short) 0x0416)); // pt-br //$NON-NLS-1$
172:                ht.put(new String("rm"), new Short((short) 0x0417)); //$NON-NLS-1$
173:                ht.put(new String("ro"), new Short((short) 0x0418)); //$NON-NLS-1$
174:                ht.put(new String("ru"), new Short((short) 0x0419)); //$NON-NLS-1$
175:                ht.put(new String("hr"), new Short((short) 0x041a)); //$NON-NLS-1$
176:                ht.put(new String("sk"), new Short((short) 0x041b)); //$NON-NLS-1$
177:                ht.put(new String("sq"), new Short((short) 0x041c)); //$NON-NLS-1$
178:                ht.put(new String("sv"), new Short((short) 0x041d)); // sv-se //$NON-NLS-1$
179:                ht.put(new String("th"), new Short((short) 0x041e)); //$NON-NLS-1$
180:                ht.put(new String("tr"), new Short((short) 0x041f)); //$NON-NLS-1$
181:                ht.put(new String("ur"), new Short((short) 0x0420)); //$NON-NLS-1$
182:                ht.put(new String("in"), new Short((short) 0x0421)); // "id" //$NON-NLS-1$
183:                ht.put(new String("uk"), new Short((short) 0x0422)); //$NON-NLS-1$
184:                ht.put(new String("be"), new Short((short) 0x0423)); //$NON-NLS-1$
185:                ht.put(new String("sl"), new Short((short) 0x0424)); //$NON-NLS-1$
186:                ht.put(new String("et"), new Short((short) 0x0425)); //$NON-NLS-1$
187:                ht.put(new String("lv"), new Short((short) 0x0426)); //$NON-NLS-1$
188:                ht.put(new String("lt"), new Short((short) 0x0427)); //$NON-NLS-1$
189:                ht.put(new String("fa"), new Short((short) 0x0429)); //$NON-NLS-1$
190:                ht.put(new String("vi"), new Short((short) 0x042a)); //$NON-NLS-1$
191:                ht.put(new String("hy"), new Short((short) 0x042b)); //$NON-NLS-1$
192:                ht.put(new String("eu"), new Short((short) 0x042d)); //$NON-NLS-1$
193:                ht.put(new String("sb"), new Short((short) 0x042e)); //$NON-NLS-1$
194:                ht.put(new String("mk"), new Short((short) 0x042f)); //$NON-NLS-1$
195:                ht.put(new String("sx"), new Short((short) 0x0430)); //$NON-NLS-1$
196:                ht.put(new String("ts"), new Short((short) 0x0431)); //$NON-NLS-1$
197:                ht.put(new String("tn"), new Short((short) 0x0432)); //$NON-NLS-1$
198:                ht.put(new String("xh"), new Short((short) 0x0434)); //$NON-NLS-1$
199:                ht.put(new String("zu"), new Short((short) 0x0435)); //$NON-NLS-1$
200:                ht.put(new String("af"), new Short((short) 0x0436)); //$NON-NLS-1$
201:                ht.put(new String("fo"), new Short((short) 0x0438)); //$NON-NLS-1$
202:                ht.put(new String("hi"), new Short((short) 0x0439)); //$NON-NLS-1$
203:                ht.put(new String("mt"), new Short((short) 0x043a)); //$NON-NLS-1$
204:                ht.put(new String("gd"), new Short((short) 0x043c)); //$NON-NLS-1$
205:                ht.put(new String("yi"), new Short((short) 0x043d)); //$NON-NLS-1$
206:                ht.put(new String("sw"), new Short((short) 0x0441)); //$NON-NLS-1$
207:                ht.put(new String("tt"), new Short((short) 0x0444)); //$NON-NLS-1$
208:                ht.put(new String("ta"), new Short((short) 0x0449)); //$NON-NLS-1$
209:                ht.put(new String("mr"), new Short((short) 0x044e)); //$NON-NLS-1$
210:                ht.put(new String("sa"), new Short((short) 0x044f)); //$NON-NLS-1$
211:
212:                /*
213:                 *  Language-country records.
214:                 */
215:                ht.put(new String("ar_SA"), new Short((short) 0x401)); //$NON-NLS-1$
216:                ht.put(new String("bg_BG"), new Short((short) 0x402)); //$NON-NLS-1$
217:                ht.put(new String("ca_ES"), new Short((short) 0x403)); //$NON-NLS-1$
218:                ht.put(new String("zh_TW"), new Short((short) 0x404)); //$NON-NLS-1$
219:                ht.put(new String("cs_CZ"), new Short((short) 0x405)); //$NON-NLS-1$
220:                ht.put(new String("da_DK"), new Short((short) 0x406)); //$NON-NLS-1$
221:                ht.put(new String("de_DE"), new Short((short) 0x407)); //$NON-NLS-1$
222:                ht.put(new String("el_GR"), new Short((short) 0x408)); //$NON-NLS-1$
223:                ht.put(new String("en_US"), new Short((short) 0x409)); //$NON-NLS-1$
224:                ht.put(new String("es_ES"), new Short((short) 0x40a)); //$NON-NLS-1$
225:                ht.put(new String("fi_FI"), new Short((short) 0x40b)); //$NON-NLS-1$
226:                ht.put(new String("fr_FR"), new Short((short) 0x40c)); //$NON-NLS-1$
227:                ht.put(new String("he_IL"), new Short((short) 0x40d)); //$NON-NLS-1$
228:                ht.put(new String("hu_HU"), new Short((short) 0x40e)); //$NON-NLS-1$
229:                ht.put(new String("is_IS"), new Short((short) 0x40f)); //$NON-NLS-1$
230:                ht.put(new String("it_IT"), new Short((short) 0x410)); //$NON-NLS-1$
231:                ht.put(new String("ja_JP"), new Short((short) 0x411)); //$NON-NLS-1$
232:                ht.put(new String("ko_KR"), new Short((short) 0x412)); //$NON-NLS-1$
233:                ht.put(new String("nl_NL"), new Short((short) 0x413)); //$NON-NLS-1$
234:                ht.put(new String("nb_NO"), new Short((short) 0x414)); //$NON-NLS-1$
235:                ht.put(new String("pl_PL"), new Short((short) 0x415)); //$NON-NLS-1$
236:                ht.put(new String("pt_BR"), new Short((short) 0x416)); //$NON-NLS-1$
237:                ht.put(new String("ro_RO"), new Short((short) 0x418)); //$NON-NLS-1$
238:                ht.put(new String("ru_RU"), new Short((short) 0x419)); //$NON-NLS-1$
239:                ht.put(new String("hr_HR"), new Short((short) 0x41a)); //$NON-NLS-1$
240:                ht.put(new String("sk_SK"), new Short((short) 0x41b)); //$NON-NLS-1$
241:                ht.put(new String("sq_AL"), new Short((short) 0x41c)); //$NON-NLS-1$
242:                ht.put(new String("sv_SE"), new Short((short) 0x41d)); //$NON-NLS-1$
243:                ht.put(new String("th_TH"), new Short((short) 0x41e)); //$NON-NLS-1$
244:                ht.put(new String("tr_TR"), new Short((short) 0x41f)); //$NON-NLS-1$
245:                ht.put(new String("ur_PK"), new Short((short) 0x420)); //$NON-NLS-1$
246:                ht.put(new String("id_ID"), new Short((short) 0x421)); //$NON-NLS-1$
247:                ht.put(new String("uk_UA"), new Short((short) 0x422)); //$NON-NLS-1$
248:                ht.put(new String("be_BY"), new Short((short) 0x423)); //$NON-NLS-1$
249:                ht.put(new String("sl_SI"), new Short((short) 0x424)); //$NON-NLS-1$
250:                ht.put(new String("et_EE"), new Short((short) 0x425)); //$NON-NLS-1$
251:                ht.put(new String("lv_LV"), new Short((short) 0x426)); //$NON-NLS-1$
252:                ht.put(new String("lt_LT"), new Short((short) 0x427)); //$NON-NLS-1$
253:                ht.put(new String("fa_IR"), new Short((short) 0x429)); //$NON-NLS-1$
254:                ht.put(new String("vi_VN"), new Short((short) 0x42a)); //$NON-NLS-1$
255:                ht.put(new String("hy_AM"), new Short((short) 0x42b)); //$NON-NLS-1$
256:                ht.put(new String("az_AZ"), new Short((short) 0x42c)); //$NON-NLS-1$
257:                ht.put(new String("eu_ES"), new Short((short) 0x42d)); //$NON-NLS-1$
258:                ht.put(new String("mk_MK"), new Short((short) 0x42f)); //$NON-NLS-1$
259:                ht.put(new String("af_ZA"), new Short((short) 0x436)); //$NON-NLS-1$
260:                ht.put(new String("ka_GE"), new Short((short) 0x437)); //$NON-NLS-1$
261:                ht.put(new String("fo_FO"), new Short((short) 0x438)); //$NON-NLS-1$
262:                ht.put(new String("hi_IN"), new Short((short) 0x439)); //$NON-NLS-1$
263:                ht.put(new String("ms_MY"), new Short((short) 0x43e)); //$NON-NLS-1$
264:                ht.put(new String("kk_KZ"), new Short((short) 0x43f)); //$NON-NLS-1$
265:                ht.put(new String("ky_KG"), new Short((short) 0x440)); //$NON-NLS-1$
266:                ht.put(new String("sw_KE"), new Short((short) 0x441)); //$NON-NLS-1$
267:                ht.put(new String("uz_UZ"), new Short((short) 0x443)); //$NON-NLS-1$
268:                ht.put(new String("tt_TA"), new Short((short) 0x444)); //$NON-NLS-1$
269:                ht.put(new String("pa_IN"), new Short((short) 0x446)); //$NON-NLS-1$
270:                ht.put(new String("gu_IN"), new Short((short) 0x447)); //$NON-NLS-1$
271:                ht.put(new String("ta_IN"), new Short((short) 0x449)); //$NON-NLS-1$
272:                ht.put(new String("te_IN"), new Short((short) 0x44a)); //$NON-NLS-1$
273:                ht.put(new String("kn_IN"), new Short((short) 0x44b)); //$NON-NLS-1$
274:                ht.put(new String("mr_IN"), new Short((short) 0x44e)); //$NON-NLS-1$
275:                ht.put(new String("sa_IN"), new Short((short) 0x44f)); //$NON-NLS-1$
276:                ht.put(new String("mn_MN"), new Short((short) 0x450)); //$NON-NLS-1$
277:                ht.put(new String("gl_ES"), new Short((short) 0x456)); //$NON-NLS-1$
278:                ht.put(new String("ko_IN"), new Short((short) 0x457)); //$NON-NLS-1$
279:                ht.put(new String("sy_SY"), new Short((short) 0x45a)); //$NON-NLS-1$
280:                ht.put(new String("di_MV"), new Short((short) 0x465)); //$NON-NLS-1$
281:                ht.put(new String("ar_IQ"), new Short((short) 0x801)); //$NON-NLS-1$
282:                ht.put(new String("zh_CN"), new Short((short) 0x804)); //$NON-NLS-1$
283:                ht.put(new String("de_CH"), new Short((short) 0x807)); //$NON-NLS-1$
284:                ht.put(new String("en_GB"), new Short((short) 0x809)); //$NON-NLS-1$
285:                ht.put(new String("es_MX"), new Short((short) 0x80a)); //$NON-NLS-1$
286:                ht.put(new String("fr_BE"), new Short((short) 0x80c)); //$NON-NLS-1$
287:                ht.put(new String("it_CH"), new Short((short) 0x810)); //$NON-NLS-1$
288:                ht.put(new String("nl_BE"), new Short((short) 0x813)); //$NON-NLS-1$
289:                ht.put(new String("nn_NO"), new Short((short) 0x814)); //$NON-NLS-1$
290:                ht.put(new String("pt_PT"), new Short((short) 0x816)); //$NON-NLS-1$
291:                ht.put(new String("sr_SP"), new Short((short) 0x81a)); //$NON-NLS-1$
292:                ht.put(new String("sv_FI"), new Short((short) 0x81d)); //$NON-NLS-1$
293:                ht.put(new String("az_AZ"), new Short((short) 0x82c)); //$NON-NLS-1$
294:                ht.put(new String("ms_BN"), new Short((short) 0x83e)); //$NON-NLS-1$
295:                ht.put(new String("uz_UZ"), new Short((short) 0x843)); //$NON-NLS-1$
296:                ht.put(new String("ar_EG"), new Short((short) 0xc01)); //$NON-NLS-1$
297:                ht.put(new String("zh_HK"), new Short((short) 0xc04)); //$NON-NLS-1$
298:                ht.put(new String("de_AT"), new Short((short) 0xc07)); //$NON-NLS-1$
299:                ht.put(new String("en_AU"), new Short((short) 0xc09)); //$NON-NLS-1$
300:                ht.put(new String("es_ES"), new Short((short) 0xc0a)); //$NON-NLS-1$
301:                ht.put(new String("fr_CA"), new Short((short) 0xc0c)); //$NON-NLS-1$
302:                ht.put(new String("sr_SP"), new Short((short) 0xc1a)); //$NON-NLS-1$
303:                ht.put(new String("ar_LY"), new Short((short) 0x1001)); //$NON-NLS-1$
304:                ht.put(new String("zh_SG"), new Short((short) 0x1004)); //$NON-NLS-1$
305:                ht.put(new String("de_LU"), new Short((short) 0x1007)); //$NON-NLS-1$
306:                ht.put(new String("en_CA"), new Short((short) 0x1009)); //$NON-NLS-1$
307:                ht.put(new String("es_GT"), new Short((short) 0x100a)); //$NON-NLS-1$
308:                ht.put(new String("fr_CH"), new Short((short) 0x100c)); //$NON-NLS-1$
309:                ht.put(new String("ar_DZ"), new Short((short) 0x1401)); //$NON-NLS-1$
310:                ht.put(new String("zh_MO"), new Short((short) 0x1404)); //$NON-NLS-1$
311:                ht.put(new String("de_LI"), new Short((short) 0x1407)); //$NON-NLS-1$
312:                ht.put(new String("en_NZ"), new Short((short) 0x1409)); //$NON-NLS-1$
313:                ht.put(new String("es_CR"), new Short((short) 0x140a)); //$NON-NLS-1$
314:                ht.put(new String("fr_LU"), new Short((short) 0x140c)); //$NON-NLS-1$
315:                ht.put(new String("ar_MA"), new Short((short) 0x1801)); //$NON-NLS-1$
316:                ht.put(new String("en_IE"), new Short((short) 0x1809)); //$NON-NLS-1$
317:                ht.put(new String("es_PA"), new Short((short) 0x180a)); //$NON-NLS-1$
318:                ht.put(new String("fr_MC"), new Short((short) 0x180c)); //$NON-NLS-1$
319:                ht.put(new String("ar_TN"), new Short((short) 0x1c01)); //$NON-NLS-1$
320:                ht.put(new String("en_ZA"), new Short((short) 0x1c09)); //$NON-NLS-1$
321:                ht.put(new String("es_DO"), new Short((short) 0x1c0a)); //$NON-NLS-1$
322:                ht.put(new String("ar_OM"), new Short((short) 0x2001)); //$NON-NLS-1$
323:                ht.put(new String("en_JM"), new Short((short) 0x2009)); //$NON-NLS-1$
324:                ht.put(new String("es_VE"), new Short((short) 0x200a)); //$NON-NLS-1$
325:                ht.put(new String("ar_YE"), new Short((short) 0x2401)); //$NON-NLS-1$
326:                ht.put(new String("en_CB"), new Short((short) 0x2409)); //$NON-NLS-1$
327:                ht.put(new String("es_CO"), new Short((short) 0x240a)); //$NON-NLS-1$
328:                ht.put(new String("ar_SY"), new Short((short) 0x2801)); //$NON-NLS-1$
329:                ht.put(new String("en_BZ"), new Short((short) 0x2809)); //$NON-NLS-1$
330:                ht.put(new String("es_PE"), new Short((short) 0x280a)); //$NON-NLS-1$
331:                ht.put(new String("ar_JO"), new Short((short) 0x2c01)); //$NON-NLS-1$
332:                ht.put(new String("en_TT"), new Short((short) 0x2c09)); //$NON-NLS-1$
333:                ht.put(new String("es_AR"), new Short((short) 0x2c0a)); //$NON-NLS-1$
334:                ht.put(new String("ar_LB"), new Short((short) 0x3001)); //$NON-NLS-1$
335:                ht.put(new String("en_ZW"), new Short((short) 0x3009)); //$NON-NLS-1$
336:                ht.put(new String("es_EC"), new Short((short) 0x300a)); //$NON-NLS-1$
337:                ht.put(new String("ar_KW"), new Short((short) 0x3401)); //$NON-NLS-1$
338:                ht.put(new String("en_PH"), new Short((short) 0x3409)); //$NON-NLS-1$
339:                ht.put(new String("es_CL"), new Short((short) 0x340a)); //$NON-NLS-1$
340:                ht.put(new String("ar_AE"), new Short((short) 0x3801)); //$NON-NLS-1$
341:                ht.put(new String("es_UY"), new Short((short) 0x380a)); //$NON-NLS-1$
342:                ht.put(new String("ar_BH"), new Short((short) 0x3c01)); //$NON-NLS-1$
343:                ht.put(new String("es_PY"), new Short((short) 0x3c0a)); //$NON-NLS-1$
344:                ht.put(new String("ar_QA"), new Short((short) 0x4001)); //$NON-NLS-1$
345:                ht.put(new String("es_BO"), new Short((short) 0x400a)); //$NON-NLS-1$
346:                ht.put(new String("es_SV"), new Short((short) 0x440a)); //$NON-NLS-1$
347:                ht.put(new String("es_HN"), new Short((short) 0x480a)); //$NON-NLS-1$
348:                ht.put(new String("es_NI"), new Short((short) 0x4c0a)); //$NON-NLS-1$
349:                ht.put(new String("es_PR"), new Short((short) 0x500a)); //$NON-NLS-1$
350:            }
351:
352:            @Override
353:            public String[] getAllFamilies() {
354:                if (allFamilies != null) {
355:                    return allFamilies;
356:                }
357:                if (allFonts == null) {
358:                    return null;
359:                }
360:
361:                ArrayList<String> al = new ArrayList<String>();
362:                String str;
363:
364:                for (Font font : allFonts) {
365:                    str = font.getName();
366:                    if (!al.contains(str)) {
367:                        al.add(str);
368:                    }
369:                }
370:
371:                allFamilies = new String[al.size()];
372:                al.toArray(allFamilies);
373:
374:                //        if (allFamilies != null)
375:                //            for (int i = 0; i < allFamilies.length; i ++) {            
376:                //                System.out.println(allFamilies[i]);
377:                //            }
378:
379:                return allFamilies;
380:            }
381:
382:            @Override
383:            public Font[] getAllFonts() {
384:                return allFonts.toArray(new Font[0]);
385:            }
386:
387:            public Font embedFont(String path, int type)
388:                    throws FontFormatException, IOException {
389:                Font newFont = addFont(path, type);
390:
391:                if (newFont == null) {
392:                    if ((new File(path)).canRead()) {
393:                        //awt.9B=Can't create font - bad font data
394:                        throw new FontFormatException(Messages
395:                                .getString("awt.9B")); //$NON-NLS-1$                        
396:                    } else {
397:                        throw new IOException();
398:                    }
399:                }
400:
401:                allFonts.add(newFont);
402:
403:                allFamilies = getAllFamilies();
404:
405:                return newFont;
406:            }
407:
408:            private native Font addFont(String path, int type);
409:
410:            private native void initManager();
411:
412:            private native Font[] getAllFontsNative();
413:
414:            private native void dispose();
415:
416:            /**
417:             * Returns platform-dependent Font peer created from the specified 
418:             * Font object from the table with cached FontPeers instances.
419:             * 
420:             * Note, this method checks whether FontPeer with specified parameters 
421:             * exists in the table with cached FontPeers' instances. If there is no needed 
422:             * instance - it is created and cached.
423:             * 
424:             * @param fontName name of the font 
425:             * @param _fontStyle style of the font 
426:             * @param size font size
427:             * 
428:             * @return platform dependent FontPeer implementation created from 
429:             * the specified parameters
430:             */
431:            public FontPeer getFontPeer(String fontName, int _fontStyle,
432:                    int size) {
433:
434:                //updateFontsTable();
435:
436:                FontPeer peer = null;
437:                String key;
438:                String name;
439:                int fontStyle = _fontStyle;
440:
441:                int logicalIndex = getLogicalFaceIndex(fontName);
442:
443:                if (logicalIndex != -1) {
444:                    name = getLogicalFaceFromFont(fontStyle, logicalIndex);
445:                    fontStyle = getStyleFromLogicalFace(name);
446:                    key = name.concat(String.valueOf(size));
447:                } else {
448:                    name = fontName;
449:                    key = name.concat(String.valueOf(fontStyle)).concat(
450:                            String.valueOf(size));
451:                }
452:
453:                HashMapReference hmr = fontsTable.get(key);
454:                if (hmr != null) {
455:                    peer = hmr.get();
456:                }
457:
458:                if (peer == null) {
459:                    peer = createFontPeer(name, fontStyle, size, logicalIndex);
460:                    if (peer == null) {
461:                        peer = getFontPeer(DIALOG_NAME, fontStyle, size);
462:                    } else if (logicalIndex == -1) {
463:                        fontsTable.put(key, new HashMapReference(key, peer,
464:                                queue));
465:                    }
466:                }
467:
468:                return peer;
469:            }
470:
471:            /**
472:             * Returns default font peer class with "Default" name that is usually 
473:             * used when font with specified font names and style doesn't exsist 
474:             * on a system. 
475:             * 
476:             * @param style style of the font
477:             * @param size size of the font
478:             */
479:            public FontPeer getDefaultFont(int style, int size) {
480:
481:                FontPeer peer = null;
482:                String key = DEFAULT_NAME.concat(String.valueOf(style)).concat(
483:                        String.valueOf(size));
484:
485:                HashMapReference hmr = fontsTable.get(key);
486:                if (hmr != null) {
487:                    peer = hmr.get();
488:                }
489:
490:                if (peer == null) {
491:                    peer = createDefaultFont(style, size);
492:
493:                    ((FontPeerImpl) peer).setFamily(DEFAULT_NAME);
494:                    ((FontPeerImpl) peer).setPSName(DEFAULT_NAME);
495:                    ((FontPeerImpl) peer).setFontName(DEFAULT_NAME);
496:
497:                    fontsTable.put(key, new HashMapReference(key, peer, queue));
498:                }
499:
500:                return peer;
501:            }
502:
503:            public void removeFontFromHash(FontPeerImpl font) {
504:                fontsTable.remove(font.getName().concat(
505:                        String.valueOf(font.getStyle())).concat(
506:                        String.valueOf(font.getSize())));
507:            }
508:
509:            /**
510:             * Freeing native resources. This hook is used to avoid 
511:             * sudden application exit and to free resources created in native code.
512:             */
513:            private class DisposeNativeHook extends Thread {
514:
515:                @Override
516:                public void run() {
517:                    try {
518:                        /* Disposing native font peer's resources */
519:                        Enumeration<String> kEnum = fontsTable.keys();
520:
521:                        while (kEnum.hasMoreElements()) {
522:                            Object key = kEnum.nextElement();
523:                            HashMapReference hmr = fontsTable.get(key);
524:                            FontPeerImpl delPeer = (FontPeerImpl) hmr.get();
525:
526:                            if ((delPeer != null)
527:                                    && (delPeer.getClass() != CompositeFont.class)) {
528:                                // there's nothing to dispose in CompositeFont objects
529:
530:                                delPeer.dispose();
531:                            }
532:                        }
533:
534:                        dispose();
535:
536:                    } catch (Throwable t) {
537:                        throw new RuntimeException(t);
538:                    }
539:                }
540:            }
541:        }
www___.__j_a___v_a_2___s_.___c_om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.