Source Code Cross Referenced for LinuxNativeFont.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » gl » font » 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 
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:        /**
018:         * @author Ilya S. Okomin
019:         * @version $Revision$
020:         */package org.apache.harmony.awt.gl.font;
021:
022:        import java.awt.Font;
023:        import java.io.IOException;
024:
025:        import java.util.*;
026:
027:        import org.apache.harmony.awt.gl.font.FontPeerImpl;
028:        import org.apache.harmony.awt.internal.nls.Messages;
029:
030:        /**
031:         *
032:         *  Library wrapper of native linux font functions.
033:         */
034:        public class LinuxNativeFont {
035:
036:            public static final int FC_SLANT_ROMAN = 0;
037:            public static final int FC_SLANT_ITALIC = 100;
038:            public static final int FC_SLANT_OBLIQUE = 110;
039:            public static final int FC_WEIGHT_MEDIUM = 100;
040:
041:            /**
042:             * Returns array of Strings that represents list of all font families names
043:             * available on the system.  
044:             */
045:            public synchronized static native String[] getFontFamiliesNames();
046:
047:            /**
048:             * Returns true if the new font was added to the system, false
049:             * otherwise.  Methods checks if the number of system fonts
050:             * changed after font configuration was rebuilt.
051:             *   
052:             * @param absolutePath absolute path to the font.
053:             */
054:            public synchronized static native String embedFontNative(
055:                    String absolutePath);
056:
057:            /**
058:             * Initiailzes native Xft font object from specified parameters and returns 
059:             * font handle, also sets font type to the font peer parameter. 
060:             * NullPointerException is thrown if there are errors in native code. 
061:             * 
062:             * @param linFont LinuxFont instance
063:             * @param family font family name
064:             * @param style style of the font
065:             * @param size size of the font
066:             * @param styleName style name of the font
067:             */
068:            public synchronized static native long initializeFont(
069:                    LinuxFont linFont, String family, int style, int size,
070:                    String styleName);
071:
072:            /** 
073:             * Returns number of glyphs in specified XftFont if success. 
074:             * 
075:             * @param hndFont XftFont handle
076:             */
077:
078:            public synchronized static native int getNumGlyphsNative(
079:                    long hndFont);
080:
081:            /**
082:             * Returns true, if XftFont object can display specified char.
083:             * 
084:             * @param hndFont XftFont handle
085:             * @param c specified char
086:             */
087:            // !! Instead of this method getGlyphCode can be used
088:            // TODO: implement method and find out if this method faster than getGlyphCode 
089:            // usage 
090:            public synchronized static native boolean canDisplayCharNative(
091:                    long hndFont, char c);
092:
093:            /**
094:             * Returns family name of the XftFont object.
095:             * 
096:             * @param hndFont XftFont handle
097:             */
098:            public synchronized static native String getFamilyNative(
099:                    long hndFont);
100:
101:            /**
102:             * Returns face name of the XftFont object.
103:             * 
104:             * @param hndFont XftFont handle
105:             */
106:            public synchronized static native String getFontNameNative(
107:                    long hndFont);
108:
109:            /**
110:             * Returns XftFont's postscript name.
111:             * Returned value is the name of the font in system default locale or
112:             * for english langid if there is no results for default locale settings. 
113:             * 
114:             * @param fnt XftFont handle
115:             */
116:            public synchronized static native String getFontPSNameNative(
117:                    long fnt);
118:
119:            /**
120:             * Getting antialiasing font from existing font
121:             */
122:            public static native long getAntialiasedFont(long font,
123:                    long display, boolean isAntialiasing);
124:
125:            /**
126:             * Disposing XftFont object.
127:             * 
128:             * @param hndFont XftFont handle
129:             * @param display Display handle
130:             */
131:            public synchronized static native void pFontFree(long hndFont,
132:                    long display);
133:
134:            /**
135:             * Returns tangent of Italic angle of given Font.
136:             * Returned value is null and NullPointerException is thrown if there is Xft error.
137:             * 
138:             * @param hndFont XftFont handle
139:             * @param fontType type of the font
140:             */
141:            public synchronized static native float getItalicAngleNative(
142:                    long hndFont, int fontType);
143:
144:            /** 
145:             * Returns an array of available system fonts names.
146:             * In case of errors in native code NullPointerException is thrown.
147:             */
148:            public synchronized static native String[] getFonts();
149:
150:            /**
151:             * Returns array of values of font metrics corresponding to the given XftFont 
152:             * font object. NullPointerException is thrown in case errors in native code.
153:             * 
154:             * @param hFont XftFont handle
155:             * @param fontSize size of the font
156:             * @param isAntialiased parameter true if antialiased metrics required
157:             * @param usesFractionalMetrics true if results calculated using fractional metrics
158:             * @param fontType type of the specified font
159:             */
160:            public synchronized static native float[] getNativeLineMetrics(
161:                    long hFont, int fontSize, boolean isAntialiased,
162:                    boolean usesFractionalMetrics, int fontType);
163:
164:            /** 
165:             * Returns array of glyph metrics values for the specified character
166:             * null is returned and NullPointerException is thrown in case of FreeType 
167:             * errors.
168:             * 
169:             * @param pFnt XftFont handle
170:             * @param c specified char
171:             */
172:            public synchronized static native float[] getGlyphInfoNative(
173:                    long pFnt, char c, int fontSize);
174:
175:            /** 
176:             * Returns array of glyph metrics values in pixels for the specified character
177:             * null is returned and NullPointerException is thrown in case of FreeType errors.
178:             * 
179:             * @param pFnt XftFont handle
180:             * @param c specified char
181:             */
182:            public synchronized static native int[] getGlyphPxlInfoNative(
183:                    long display, long pFnt, char c);
184:
185:            /**
186:             * Returns glyphs code corresponding to the characters in String specified, null 
187:             * is returned if failure. NullPointerException is thrown in case of Display 
188:             * is null.
189:             * 
190:             * @param fnt XftFont handle
191:             * @param uChar specified char
192:             * @param display Display handle
193:             */
194:            // TODO: implement native call
195:            public synchronized static native int[] getGlyphCodesNative(
196:                    long fnt, String str, int len);
197:
198:            /**
199:             * Returns glyph code corresponding to the specified character, null is 
200:             * returned if failure. NullPointerException is thrown in case of Display is null.
201:             * 
202:             * @param fnt XftFont handle
203:             * @param uChar specified char
204:             * @param display Display handle
205:             */
206:            public synchronized static native int getGlyphCodeNative(long fnt,
207:                    char uChar, long display);
208:
209:            /**
210:             * Updates specified folder where temporary font created from InputStream stored.
211:             * This method used in LinuxFont dispose method, it re-caches ~/.fonts
212:             * directory, after temporary font file is deleted.
213:             *   
214:             * @param tempFontFileName directory that is being re-cached name.
215:             * @return not null value if success, 0 otherwise
216:             */
217:            public synchronized static native int RemoveFontResource(
218:                    String tempFontFileName);
219:
220:            /**
221:             * Draws text on XftDraw with specified parameters using Xft library.
222:             * 
223:             * @param xftDraw XftDraw handle
224:             * @param display Display handle
225:             * @param colormap Colormap handle
226:             * @param font XftFont handle
227:             * @param x X coordinate where to draw at
228:             * @param y Y coordinate where to draw at
229:             * @param chars array of chars to draw
230:             * @param len length of the array of chars
231:             * @param xcolor XColor handle, the color of the text
232:             */
233:            public synchronized static native void drawStringNative(
234:                    long xftDraw, long display, long colormap, long font,
235:                    int x, int y, char[] chars, int len, long xcolor);
236:
237:            // FreeType routines
238:
239:            /**
240:             * Returns pointer to GlyphBitmap structure that represents bitmap
241:             * with parameters of the character specified or 0 if failures 
242:             * in native code.
243:             * 
244:             * @param fnt XftFont handle
245:             * @param chr specified char
246:             */
247:            public synchronized static native long NativeInitGlyphBitmap(
248:                    long fnt, char chr);
249:
250:            /**
251:             * Disposes memory block that is used by FreeType FT_Bitmap structure
252:             * by pointer specified.
253:             * 
254:             * @param ptr specified pointer to the memory block
255:             */
256:            public synchronized static native void NativeFreeGlyphBitmap(
257:                    long bitmap);
258:
259:            /**
260:             * Returns pointer to the FreeType FT_Outline structure. 
261:             * 
262:             * @param pFont XFT font handle
263:             * @param c specified character
264:             */
265:            public synchronized static native long getGlyphOutline(long pFont,
266:                    char c);
267:
268:            /**
269:             * Disposes memory block that is used by FreeType FT_Outline structure
270:             * by pointer specified.
271:             * 
272:             * @param ptr specified pointer to the memory block
273:             */
274:            public synchronized static native void freeGlyphOutline(long ptr);
275:
276:            /**
277:             * Returns an array of pairs of coordinates [x1, y1, x2, y2...] from 
278:             * FreeType FT_Vector structure.  
279:             * 
280:             * @param ft_vector pointer to the memory block with FT_Vector structure
281:             * @param size number of elements in FT_Vector structure
282:             */
283:            public synchronized static native float[] getPointsFromFTVector(
284:                    long ft_vector, int size);
285:
286:            // Xft routines
287:
288:            /**
289:             * Returns XftDraw handle created from specified parameters using Xft library.
290:             * 
291:             * @param display Display handle 
292:             * @param drawable Drawable handle
293:             * @param visual Visual handle
294:             */
295:            public synchronized static native long createXftDrawNative(
296:                    long display, long drawable, long visual);
297:
298:            /**
299:             * Destroys XftDraw object.
300:             * @param xftDraw XftDraw handle 
301:             */
302:            public synchronized static native void freeXftDrawNative(
303:                    long xftDraw);
304:
305:            /**
306:             * Set new subwindow mode to XftDraw object
307:             *  
308:             * @param xftDraw XftDraw handle 
309:             * @param mode new mode
310:             */
311:            public static native void xftDrawSetSubwindowModeNative(
312:                    long xftDraw, int mode);
313:
314:            /**
315:             * Sets clipping rectangles in Xft drawable to the specified clipping rectangles. 
316:             * 
317:             * @param xftDraw XftDraw handle
318:             * @param xOrigin x position to start
319:             * @param yOrigin y position to start
320:             * @param rects handle to the memory block representing XRectangles array
321:             * @param n number of rectangles
322:             * 
323:             * @return result true if success in native call, false otherwise 
324:             */
325:            public static native boolean XftDrawSetClipRectangles(long xftDraw,
326:                    int xOrigin, int yOrigin, long rects, int n);
327:
328:            //  public static native boolean isCharExists(char chr);
329:
330:            /**
331:             * Returns an array of extrametrics of the font:<p>
332:             *  elem[0] - the average width of characters in the font (Type1 - 0.0f)<p>
333:             *  elem[1] - horizontal size for subscripts (Type1 - 0.7f * fontHeight)<p> 
334:             *  elem[2] - vertical size for subscripts (Type1 - 0.65f * fontHeight)<p> 
335:             *  elem[3] - horizontal offset for subscripts (Type1 - 0.0f)<p>
336:             *  elem[4] - vertical offset value for subscripts(Type1 - 0.15f * fontHeight)<p>
337:             *  elem[5] - horizontal size for superscripts (Type1 - 0.7f * fontHeight)<p>
338:             *  elem[6] - vertical size for superscripts (Type1 - 0.65f * fontHeight)<p>
339:             *  elem[7] - horizontal offset for superscripts (Type1 - 0.0f)<p> 
340:             *  elem[8] - vertical offset for superscripts (Type1 - 0.45f * fontHeight)<p> 
341:             * For TrueType fonts metrics are taken from OS2 table, for Type1 fonts
342:             * metrics are calculated using coefficients (read FontExtraMetrics comments).
343:             * OS2 table can be found at http://www.freetype.org/freetype2/docs/reference/ft2-truetype_tables.html#TT_OS2
344:             * 
345:             * @param hFont XFT font handle
346:             * @param fontSize font size
347:             * @param fontType type of the font
348:             */
349:            public synchronized static native float[] getExtraMetricsNative(
350:                    long hFont, int fontSize, int fontType);
351:
352:            /**
353:             * Initializes LCID table
354:             */
355:            public static void initLCIDsTable(Hashtable ht) {
356:
357:                /*
358:                 *  Language records with LCID values (0x04**).
359:                 */
360:                ht.put(new String("ar"), new Short((short) 0x0401)); // ar-dz //$NON-NLS-1$
361:                ht.put(new String("bg"), new Short((short) 0x0402)); //$NON-NLS-1$
362:                ht.put(new String("ca"), new Short((short) 0x0403)); //$NON-NLS-1$
363:                ht.put(new String("zh"), new Short((short) 0x0404)); // zh-tw //$NON-NLS-1$
364:                ht.put(new String("cs"), new Short((short) 0x0405)); //$NON-NLS-1$
365:                ht.put(new String("da"), new Short((short) 0x0406)); //$NON-NLS-1$
366:                ht.put(new String("de"), new Short((short) 0x0407)); // de-de //$NON-NLS-1$
367:                ht.put(new String("el"), new Short((short) 0x0408)); //$NON-NLS-1$
368:                ht.put(new String("fi"), new Short((short) 0x040b)); //$NON-NLS-1$
369:                ht.put(new String("fr"), new Short((short) 0x040c)); // fr-fr //$NON-NLS-1$
370:                ht.put(new String("iw"), new Short((short) 0x040d)); // "he" //$NON-NLS-1$
371:                ht.put(new String("hu"), new Short((short) 0x040e)); //$NON-NLS-1$
372:                ht.put(new String("is"), new Short((short) 0x040f)); //$NON-NLS-1$
373:                ht.put(new String("it"), new Short((short) 0x0410)); // it-it //$NON-NLS-1$
374:                ht.put(new String("ja"), new Short((short) 0x0411)); //$NON-NLS-1$
375:                ht.put(new String("ko"), new Short((short) 0x0412)); //$NON-NLS-1$
376:                ht.put(new String("nl"), new Short((short) 0x0413)); // nl-nl //$NON-NLS-1$
377:                ht.put(new String("no"), new Short((short) 0x0414)); // no_no //$NON-NLS-1$
378:                ht.put(new String("pl"), new Short((short) 0x0415)); //$NON-NLS-1$
379:                ht.put(new String("pt"), new Short((short) 0x0416)); // pt-br //$NON-NLS-1$
380:                ht.put(new String("rm"), new Short((short) 0x0417)); //$NON-NLS-1$
381:                ht.put(new String("ro"), new Short((short) 0x0418)); //$NON-NLS-1$
382:                ht.put(new String("ru"), new Short((short) 0x0419)); //$NON-NLS-1$
383:                ht.put(new String("hr"), new Short((short) 0x041a)); //$NON-NLS-1$
384:                ht.put(new String("sk"), new Short((short) 0x041b)); //$NON-NLS-1$
385:                ht.put(new String("sq"), new Short((short) 0x041c)); //$NON-NLS-1$
386:                ht.put(new String("sv"), new Short((short) 0x041d)); // sv-se //$NON-NLS-1$
387:                ht.put(new String("th"), new Short((short) 0x041e)); //$NON-NLS-1$
388:                ht.put(new String("tr"), new Short((short) 0x041f)); //$NON-NLS-1$
389:                ht.put(new String("ur"), new Short((short) 0x0420)); //$NON-NLS-1$
390:                ht.put(new String("in"), new Short((short) 0x0421)); // "id" //$NON-NLS-1$
391:                ht.put(new String("uk"), new Short((short) 0x0422)); //$NON-NLS-1$
392:                ht.put(new String("be"), new Short((short) 0x0423)); //$NON-NLS-1$
393:                ht.put(new String("sl"), new Short((short) 0x0424)); //$NON-NLS-1$
394:                ht.put(new String("et"), new Short((short) 0x0425)); //$NON-NLS-1$
395:                ht.put(new String("lv"), new Short((short) 0x0426)); //$NON-NLS-1$
396:                ht.put(new String("lt"), new Short((short) 0x0427)); //$NON-NLS-1$
397:                ht.put(new String("fa"), new Short((short) 0x0429)); //$NON-NLS-1$
398:                ht.put(new String("vi"), new Short((short) 0x042a)); //$NON-NLS-1$
399:                ht.put(new String("hy"), new Short((short) 0x042b)); //$NON-NLS-1$
400:                ht.put(new String("eu"), new Short((short) 0x042d)); //$NON-NLS-1$
401:                ht.put(new String("sb"), new Short((short) 0x042e)); //$NON-NLS-1$
402:                ht.put(new String("mk"), new Short((short) 0x042f)); //$NON-NLS-1$
403:                ht.put(new String("sx"), new Short((short) 0x0430)); //$NON-NLS-1$
404:                ht.put(new String("ts"), new Short((short) 0x0431)); //$NON-NLS-1$
405:                ht.put(new String("tn"), new Short((short) 0x0432)); //$NON-NLS-1$
406:                ht.put(new String("xh"), new Short((short) 0x0434)); //$NON-NLS-1$
407:                ht.put(new String("zu"), new Short((short) 0x0435)); //$NON-NLS-1$
408:                ht.put(new String("af"), new Short((short) 0x0436)); //$NON-NLS-1$
409:                ht.put(new String("fo"), new Short((short) 0x0438)); //$NON-NLS-1$
410:                ht.put(new String("hi"), new Short((short) 0x0439)); //$NON-NLS-1$
411:                ht.put(new String("mt"), new Short((short) 0x043a)); //$NON-NLS-1$
412:                ht.put(new String("gd"), new Short((short) 0x043c)); //$NON-NLS-1$
413:                ht.put(new String("yi"), new Short((short) 0x043d)); //$NON-NLS-1$
414:                ht.put(new String("sw"), new Short((short) 0x0441)); //$NON-NLS-1$
415:                ht.put(new String("tt"), new Short((short) 0x0444)); //$NON-NLS-1$
416:                ht.put(new String("ta"), new Short((short) 0x0449)); //$NON-NLS-1$
417:                ht.put(new String("mr"), new Short((short) 0x044e)); //$NON-NLS-1$
418:                ht.put(new String("sa"), new Short((short) 0x044f)); //$NON-NLS-1$
419:
420:                /*
421:                 *  Language-country records.
422:                 */
423:                ht.put(new String("ar_SA"), new Short((short) 0x401)); //$NON-NLS-1$
424:                ht.put(new String("bg_BG"), new Short((short) 0x402)); //$NON-NLS-1$
425:                ht.put(new String("ca_ES"), new Short((short) 0x403)); //$NON-NLS-1$
426:                ht.put(new String("zh_TW"), new Short((short) 0x404)); //$NON-NLS-1$
427:                ht.put(new String("cs_CZ"), new Short((short) 0x405)); //$NON-NLS-1$
428:                ht.put(new String("da_DK"), new Short((short) 0x406)); //$NON-NLS-1$
429:                ht.put(new String("de_DE"), new Short((short) 0x407)); //$NON-NLS-1$
430:                ht.put(new String("el_GR"), new Short((short) 0x408)); //$NON-NLS-1$
431:                ht.put(new String("en_US"), new Short((short) 0x409)); //$NON-NLS-1$
432:                ht.put(new String("es_ES"), new Short((short) 0x40a)); //$NON-NLS-1$
433:                ht.put(new String("fi_FI"), new Short((short) 0x40b)); //$NON-NLS-1$
434:                ht.put(new String("fr_FR"), new Short((short) 0x40c)); //$NON-NLS-1$
435:                ht.put(new String("he_IL"), new Short((short) 0x40d)); //$NON-NLS-1$
436:                ht.put(new String("hu_HU"), new Short((short) 0x40e)); //$NON-NLS-1$
437:                ht.put(new String("is_IS"), new Short((short) 0x40f)); //$NON-NLS-1$
438:                ht.put(new String("it_IT"), new Short((short) 0x410)); //$NON-NLS-1$
439:                ht.put(new String("ja_JP"), new Short((short) 0x411)); //$NON-NLS-1$
440:                ht.put(new String("ko_KR"), new Short((short) 0x412)); //$NON-NLS-1$
441:                ht.put(new String("nl_NL"), new Short((short) 0x413)); //$NON-NLS-1$
442:                ht.put(new String("nb_NO"), new Short((short) 0x414)); //$NON-NLS-1$
443:                ht.put(new String("pl_PL"), new Short((short) 0x415)); //$NON-NLS-1$
444:                ht.put(new String("pt_BR"), new Short((short) 0x416)); //$NON-NLS-1$
445:                ht.put(new String("ro_RO"), new Short((short) 0x418)); //$NON-NLS-1$
446:                ht.put(new String("ru_RU"), new Short((short) 0x419)); //$NON-NLS-1$
447:                ht.put(new String("hr_HR"), new Short((short) 0x41a)); //$NON-NLS-1$
448:                ht.put(new String("sk_SK"), new Short((short) 0x41b)); //$NON-NLS-1$
449:                ht.put(new String("sq_AL"), new Short((short) 0x41c)); //$NON-NLS-1$
450:                ht.put(new String("sv_SE"), new Short((short) 0x41d)); //$NON-NLS-1$
451:                ht.put(new String("th_TH"), new Short((short) 0x41e)); //$NON-NLS-1$
452:                ht.put(new String("tr_TR"), new Short((short) 0x41f)); //$NON-NLS-1$
453:                ht.put(new String("ur_PK"), new Short((short) 0x420)); //$NON-NLS-1$
454:                ht.put(new String("id_ID"), new Short((short) 0x421)); //$NON-NLS-1$
455:                ht.put(new String("uk_UA"), new Short((short) 0x422)); //$NON-NLS-1$
456:                ht.put(new String("be_BY"), new Short((short) 0x423)); //$NON-NLS-1$
457:                ht.put(new String("sl_SI"), new Short((short) 0x424)); //$NON-NLS-1$
458:                ht.put(new String("et_EE"), new Short((short) 0x425)); //$NON-NLS-1$
459:                ht.put(new String("lv_LV"), new Short((short) 0x426)); //$NON-NLS-1$
460:                ht.put(new String("lt_LT"), new Short((short) 0x427)); //$NON-NLS-1$
461:                ht.put(new String("fa_IR"), new Short((short) 0x429)); //$NON-NLS-1$
462:                ht.put(new String("vi_VN"), new Short((short) 0x42a)); //$NON-NLS-1$
463:                ht.put(new String("hy_AM"), new Short((short) 0x42b)); //$NON-NLS-1$
464:                ht.put(new String("az_AZ"), new Short((short) 0x42c)); //$NON-NLS-1$
465:                ht.put(new String("eu_ES"), new Short((short) 0x42d)); //$NON-NLS-1$
466:                ht.put(new String("mk_MK"), new Short((short) 0x42f)); //$NON-NLS-1$
467:                ht.put(new String("af_ZA"), new Short((short) 0x436)); //$NON-NLS-1$
468:                ht.put(new String("ka_GE"), new Short((short) 0x437)); //$NON-NLS-1$
469:                ht.put(new String("fo_FO"), new Short((short) 0x438)); //$NON-NLS-1$
470:                ht.put(new String("hi_IN"), new Short((short) 0x439)); //$NON-NLS-1$
471:                ht.put(new String("ms_MY"), new Short((short) 0x43e)); //$NON-NLS-1$
472:                ht.put(new String("kk_KZ"), new Short((short) 0x43f)); //$NON-NLS-1$
473:                ht.put(new String("ky_KG"), new Short((short) 0x440)); //$NON-NLS-1$
474:                ht.put(new String("sw_KE"), new Short((short) 0x441)); //$NON-NLS-1$
475:                ht.put(new String("uz_UZ"), new Short((short) 0x443)); //$NON-NLS-1$
476:                ht.put(new String("tt_TA"), new Short((short) 0x444)); //$NON-NLS-1$
477:                ht.put(new String("pa_IN"), new Short((short) 0x446)); //$NON-NLS-1$
478:                ht.put(new String("gu_IN"), new Short((short) 0x447)); //$NON-NLS-1$
479:                ht.put(new String("ta_IN"), new Short((short) 0x449)); //$NON-NLS-1$
480:                ht.put(new String("te_IN"), new Short((short) 0x44a)); //$NON-NLS-1$
481:                ht.put(new String("kn_IN"), new Short((short) 0x44b)); //$NON-NLS-1$
482:                ht.put(new String("mr_IN"), new Short((short) 0x44e)); //$NON-NLS-1$
483:                ht.put(new String("sa_IN"), new Short((short) 0x44f)); //$NON-NLS-1$
484:                ht.put(new String("mn_MN"), new Short((short) 0x450)); //$NON-NLS-1$
485:                ht.put(new String("gl_ES"), new Short((short) 0x456)); //$NON-NLS-1$
486:                ht.put(new String("ko_IN"), new Short((short) 0x457)); //$NON-NLS-1$
487:                ht.put(new String("sy_SY"), new Short((short) 0x45a)); //$NON-NLS-1$
488:                ht.put(new String("di_MV"), new Short((short) 0x465)); //$NON-NLS-1$
489:                ht.put(new String("ar_IQ"), new Short((short) 0x801)); //$NON-NLS-1$
490:                ht.put(new String("zh_CN"), new Short((short) 0x804)); //$NON-NLS-1$
491:                ht.put(new String("de_CH"), new Short((short) 0x807)); //$NON-NLS-1$
492:                ht.put(new String("en_GB"), new Short((short) 0x809)); //$NON-NLS-1$
493:                ht.put(new String("es_MX"), new Short((short) 0x80a)); //$NON-NLS-1$
494:                ht.put(new String("fr_BE"), new Short((short) 0x80c)); //$NON-NLS-1$
495:                ht.put(new String("it_CH"), new Short((short) 0x810)); //$NON-NLS-1$
496:                ht.put(new String("nl_BE"), new Short((short) 0x813)); //$NON-NLS-1$
497:                ht.put(new String("nn_NO"), new Short((short) 0x814)); //$NON-NLS-1$
498:                ht.put(new String("pt_PT"), new Short((short) 0x816)); //$NON-NLS-1$
499:                ht.put(new String("sr_SP"), new Short((short) 0x81a)); //$NON-NLS-1$
500:                ht.put(new String("sv_FI"), new Short((short) 0x81d)); //$NON-NLS-1$
501:                ht.put(new String("az_AZ"), new Short((short) 0x82c)); //$NON-NLS-1$
502:                ht.put(new String("ms_BN"), new Short((short) 0x83e)); //$NON-NLS-1$
503:                ht.put(new String("uz_UZ"), new Short((short) 0x843)); //$NON-NLS-1$
504:                ht.put(new String("ar_EG"), new Short((short) 0xc01)); //$NON-NLS-1$
505:                ht.put(new String("zh_HK"), new Short((short) 0xc04)); //$NON-NLS-1$
506:                ht.put(new String("de_AT"), new Short((short) 0xc07)); //$NON-NLS-1$
507:                ht.put(new String("en_AU"), new Short((short) 0xc09)); //$NON-NLS-1$
508:                ht.put(new String("es_ES"), new Short((short) 0xc0a)); //$NON-NLS-1$
509:                ht.put(new String("fr_CA"), new Short((short) 0xc0c)); //$NON-NLS-1$
510:                ht.put(new String("sr_SP"), new Short((short) 0xc1a)); //$NON-NLS-1$
511:                ht.put(new String("ar_LY"), new Short((short) 0x1001)); //$NON-NLS-1$
512:                ht.put(new String("zh_SG"), new Short((short) 0x1004)); //$NON-NLS-1$
513:                ht.put(new String("de_LU"), new Short((short) 0x1007)); //$NON-NLS-1$
514:                ht.put(new String("en_CA"), new Short((short) 0x1009)); //$NON-NLS-1$
515:                ht.put(new String("es_GT"), new Short((short) 0x100a)); //$NON-NLS-1$
516:                ht.put(new String("fr_CH"), new Short((short) 0x100c)); //$NON-NLS-1$
517:                ht.put(new String("ar_DZ"), new Short((short) 0x1401)); //$NON-NLS-1$
518:                ht.put(new String("zh_MO"), new Short((short) 0x1404)); //$NON-NLS-1$
519:                ht.put(new String("de_LI"), new Short((short) 0x1407)); //$NON-NLS-1$
520:                ht.put(new String("en_NZ"), new Short((short) 0x1409)); //$NON-NLS-1$
521:                ht.put(new String("es_CR"), new Short((short) 0x140a)); //$NON-NLS-1$
522:                ht.put(new String("fr_LU"), new Short((short) 0x140c)); //$NON-NLS-1$
523:                ht.put(new String("ar_MA"), new Short((short) 0x1801)); //$NON-NLS-1$
524:                ht.put(new String("en_IE"), new Short((short) 0x1809)); //$NON-NLS-1$
525:                ht.put(new String("es_PA"), new Short((short) 0x180a)); //$NON-NLS-1$
526:                ht.put(new String("fr_MC"), new Short((short) 0x180c)); //$NON-NLS-1$
527:                ht.put(new String("ar_TN"), new Short((short) 0x1c01)); //$NON-NLS-1$
528:                ht.put(new String("en_ZA"), new Short((short) 0x1c09)); //$NON-NLS-1$
529:                ht.put(new String("es_DO"), new Short((short) 0x1c0a)); //$NON-NLS-1$
530:                ht.put(new String("ar_OM"), new Short((short) 0x2001)); //$NON-NLS-1$
531:                ht.put(new String("en_JM"), new Short((short) 0x2009)); //$NON-NLS-1$
532:                ht.put(new String("es_VE"), new Short((short) 0x200a)); //$NON-NLS-1$
533:                ht.put(new String("ar_YE"), new Short((short) 0x2401)); //$NON-NLS-1$
534:                ht.put(new String("en_CB"), new Short((short) 0x2409)); //$NON-NLS-1$
535:                ht.put(new String("es_CO"), new Short((short) 0x240a)); //$NON-NLS-1$
536:                ht.put(new String("ar_SY"), new Short((short) 0x2801)); //$NON-NLS-1$
537:                ht.put(new String("en_BZ"), new Short((short) 0x2809)); //$NON-NLS-1$
538:                ht.put(new String("es_PE"), new Short((short) 0x280a)); //$NON-NLS-1$
539:                ht.put(new String("ar_JO"), new Short((short) 0x2c01)); //$NON-NLS-1$
540:                ht.put(new String("en_TT"), new Short((short) 0x2c09)); //$NON-NLS-1$
541:                ht.put(new String("es_AR"), new Short((short) 0x2c0a)); //$NON-NLS-1$
542:                ht.put(new String("ar_LB"), new Short((short) 0x3001)); //$NON-NLS-1$
543:                ht.put(new String("en_ZW"), new Short((short) 0x3009)); //$NON-NLS-1$
544:                ht.put(new String("es_EC"), new Short((short) 0x300a)); //$NON-NLS-1$
545:                ht.put(new String("ar_KW"), new Short((short) 0x3401)); //$NON-NLS-1$
546:                ht.put(new String("en_PH"), new Short((short) 0x3409)); //$NON-NLS-1$
547:                ht.put(new String("es_CL"), new Short((short) 0x340a)); //$NON-NLS-1$
548:                ht.put(new String("ar_AE"), new Short((short) 0x3801)); //$NON-NLS-1$
549:                ht.put(new String("es_UY"), new Short((short) 0x380a)); //$NON-NLS-1$
550:                ht.put(new String("ar_BH"), new Short((short) 0x3c01)); //$NON-NLS-1$
551:                ht.put(new String("es_PY"), new Short((short) 0x3c0a)); //$NON-NLS-1$
552:                ht.put(new String("ar_QA"), new Short((short) 0x4001)); //$NON-NLS-1$
553:                ht.put(new String("es_BO"), new Short((short) 0x400a)); //$NON-NLS-1$
554:                ht.put(new String("es_SV"), new Short((short) 0x440a)); //$NON-NLS-1$
555:                ht.put(new String("es_HN"), new Short((short) 0x480a)); //$NON-NLS-1$
556:                ht.put(new String("es_NI"), new Short((short) 0x4c0a)); //$NON-NLS-1$
557:                ht.put(new String("es_PR"), new Short((short) 0x500a)); //$NON-NLS-1$
558:            }
559:
560:            /**
561:             * List of font faces names of system fonts supported by a system.
562:             */
563:            public static String[] faces;
564:
565:            /**
566:             * List of font style names of system fonts supported by a system 
567:             * corresponding to faces indexing.
568:             */
569:            public static String[] styleNames;
570:
571:            /**
572:             * List of family indexes in families array corresponding to the faces 
573:             * indexing.
574:             */
575:            public static int[] famIndices;
576:
577:            /**
578:             * List of font styles of system fonts supported by a system 
579:             * corresponding to faces indexing.
580:             */
581:            public static int[] fontStyles;
582:
583:            /**
584:             * The number of different fonts installed onto the system.
585:             */
586:            public static int facesCount;
587:
588:            /**
589:             * Set of all unique families installed onto the system.
590:             */
591:            public static Vector fams = new Vector();
592:
593:            /**
594:             * Returns family name that corresponds to the face with specified 
595:             * face index.
596:             * 
597:             * @param faceIndex index of the face in faces array
598:             */
599:            public static String getFamilyFromFaceIndex(int faceIndex) {
600:                return (String) fams.get(famIndices[faceIndex]);
601:            }
602:
603:            /**
604:             * Returns font style name of the font with face having specified index.
605:             * 
606:             * @param faceIndex specified index of the face in faces array
607:             */
608:            public static String getFontStyleName(int faceIndex) {
609:                return styleNames[faceIndex];
610:            }
611:
612:            /**
613:             * Returns font style of the font with face having specified index.
614:             * 
615:             * @param faceIndex specified index of the face in faces array
616:             */
617:            public static int getFontStyle(int faceIndex) {
618:                return fontStyles[faceIndex];
619:            }
620:
621:            /**
622:             * Returns array of Strings that represent face names of all fonts
623:             * supported by a system. 
624:             */
625:            public static String[] getFaces() {
626:                if (faces == null)
627:                    initFaces();
628:                return faces;
629:            }
630:
631:            /**
632:             * Initializes famIndices, styles, style names and faces arrays 
633:             * according to the font information available on the system. 
634:             */
635:            public static void initFaces() {
636:                if (facesCount == 0) {
637:                    String[] fontNames = getFonts();
638:                    facesCount = fontNames.length;
639:                    faces = new String[facesCount];
640:                    styleNames = new String[facesCount];
641:                    famIndices = new int[facesCount];
642:                    fontStyles = new int[facesCount];
643:
644:                    for (int i = 0; i < facesCount; i++) {
645:                        initFace(i, fontNames[i]);
646:                    }
647:                }
648:            }
649:
650:            /**
651:             * Initializes specified elements with index specified of famIndices, styles and 
652:             * faces arrays according to the given faceString. faceString has format 
653:             * "family name"-"style name"-style.
654:             * 
655:             * @param index index of element to identify
656:             * @param faceString String defining family name, style name and style in 
657:             * special format
658:             */
659:            public static void initFace(int index, String faceString) {
660:                String delim = "-"; //$NON-NLS-1$
661:                int pos;
662:                if (faceString == null) {
663:                    return;
664:                }
665:
666:                String str = faceString;
667:                pos = str.lastIndexOf(delim);
668:
669:                // get style value
670:                int style = Integer.parseInt(str.substring(pos + 1));
671:                str = str.substring(0, pos);
672:
673:                pos = str.lastIndexOf(delim);
674:
675:                // get family name
676:                String family = str.substring(0, pos);
677:                int famIndex = fams.indexOf(family);
678:                if (famIndex == -1) {
679:                    fams.add(family);
680:                    famIndex = fams.size() - 1;
681:                }
682:                famIndices[index] = famIndex;
683:
684:                styleNames[index] = str.substring(pos + 1);
685:
686:                fontStyles[index] = style;
687:
688:                faces[index] = family + " " + styleNames[index]; //$NON-NLS-1$
689:            }
690:
691:            /** Returns the list of system font families names. */
692:            public static String[] getFamilies() {
693:                initFaces();
694:
695:                int size = fams.size();
696:                String[] names = new String[size];
697:                for (int i = 0; i < size; i++) {
698:                    names[i] = (String) fams.get(i);
699:                }
700:                return names;
701:            }
702:
703:            /**
704:             * Returns an array of instances of 1 pt. sized plain Font objects
705:             * corresponding to fonts supported by a system. 
706:             */
707:            public static Font[] getAllFonts() {
708:                initFaces();
709:
710:                Font[] fonts = new Font[faces.length];
711:                for (int i = 0; i < fonts.length; i++) {
712:                    fonts[i] = new Font(faces[i], Font.PLAIN, 1);
713:                }
714:                return fonts;
715:            }
716:
717:            /**
718:             * Adds new plain font with 1 pt. size from font resource file to the 
719:             * system if similar font wasn't into the system before. Method returns 
720:             * font object, corresponding to the specified resource. 
721:             *  
722:             * @param absolutePath absolute path to the font resource file
723:             */
724:            public static Font embedFont(String absolutePath)
725:                    throws IOException {
726:                String familyName = embedFontNative(absolutePath);
727:                if (familyName == null)
728:                    throw new IOException(Messages.getString("awt.299"));
729:
730:                return new Font(familyName, Font.PLAIN, 1);
731:            }
732:
733:            /** flag, returns true if native linuxfont was loaded */
734:            private static boolean isLibLoaded = false;
735:
736:            static void loadLibrary() {
737:                if (!isLibLoaded) {
738:                    java.security.AccessController
739:                            .doPrivileged(new java.security.PrivilegedAction() {
740:                                public Object run() {
741:                                    System.loadLibrary("linuxfont"); //$NON-NLS-1$
742:                                    return null;
743:                                }
744:                            });
745:                    isLibLoaded = true;
746:                }
747:            }
748:
749:            /* load native Font library */
750:            static {
751:                loadLibrary();
752:            }
753:
754:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.