Source Code Cross Referenced for WinFontManager.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.awt.peer.FontPeer;
024:        import java.io.File;
025:        import java.util.Properties;
026:        import java.util.Vector;
027:
028:        import org.apache.harmony.awt.gl.font.FontManager;
029:        import org.apache.harmony.awt.gl.font.FontProperty;
030:
031:        /**
032:         *
033:         * Windows FontManager implementation.
034:         */
035:        public class WinFontManager extends FontManager {
036:
037:            static final int DEFAULT_PITCH = 0; // GDI DEFAULT_PITCH
038:            static final int FIXED_PITCH = 1; // GDI FIXED_PITCH
039:            static final int VARIABLE_PITCH = 2; // GDI VARIABLE_PITCH
040:
041:            static final int FF_DONTCARE = (0 << 4); // GDI FF_DONTCARE
042:            static final int FF_SWISS = (2 << 4); // GDI FF_SWISS
043:            static final int FF_MODERN = (3 << 4); // GDI FF_MODERN
044:            static final int FF_ROMAN = (1 << 4); // GDI FF_ROMAN
045:
046:            /** Available windows charset names */
047:            public static final String[] WINDOWS_CHARSET_NAMES = {
048:                    "ANSI_CHARSET", "DEFAULT_CHARSET", "SYMBOL_CHARSET", "SHIFTJIS_CHARSET", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
049:                    "GB2312_CHARSET", "HANGEUL_CHARSET", "CHINESEBIG5_CHARSET", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
050:                    "OEM_CHARSET", "JOHAB_CHARSET", "HEBREW_CHARSET", "ARABIC_CHARSET", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
051:                    "GREEK_CHARSET", "TURKISH_CHARSET", "VIETNAMESE_CHARSET", "THAI_CHARSET", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
052:                    "EASTEUROPE_CHARSET", "RUSSIAN_CHARSET", "MAC_CHARSET", "BALTIC_CHARSET" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
053:            };
054:
055:            /** WinFontManager singleton instance */
056:            public static final WinFontManager inst = new WinFontManager();
057:
058:            private WinFontManager() {
059:                super ();
060:                initFontProperties();
061:            }
062:
063:            @Override
064:            public void initLCIDTable() {
065:                NativeFont.initLCIDsTable(this .tableLCID);
066:            }
067:
068:            /**
069:             * Initializes fProperties array field for the current system configuration font
070:             * property file.
071:             * 
072:             * @return true is success, false if font property doesn't exist or doesn't
073:             * contain properties. 
074:             */
075:            public boolean initFontProperties() {
076:                File fpFile = getFontPropertyFile();
077:                if (fpFile == null) {
078:                    return false;
079:                }
080:
081:                Properties props = getProperties(fpFile);
082:                if (props == null) {
083:                    return false;
084:                }
085:
086:                for (String element : LOGICAL_FONT_NAMES) {
087:                    for (int j = 0; j < STYLE_NAMES.length; j++) {
088:                        Vector<FontProperty> propsVector = new Vector<FontProperty>();
089:
090:                        // Number of entries for a logical font
091:                        int numComp = 0;
092:                        // Is more entries for this style and logical font name left
093:                        boolean moreEntries = true;
094:                        String value = null;
095:
096:                        while (moreEntries) {
097:                            // Component Font Mappings property name
098:                            String property = FONT_MAPPING_KEYS[0]
099:                                    .replaceAll("LogicalFontName", element).replaceAll("StyleName", STYLE_NAMES[j]).replaceAll("ComponentIndex", String.valueOf(numComp)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
100:                            value = props.getProperty(property);
101:
102:                            // If the StyleName is omitted, it's assumed to be plain
103:                            if ((j == 0) && (value == null)) {
104:                                property = FONT_MAPPING_KEYS[1]
105:                                        .replaceAll("LogicalFontName", element).replaceAll("ComponentIndex", String.valueOf(numComp)); //$NON-NLS-1$ //$NON-NLS-2$
106:                                value = props.getProperty(property);
107:                            }
108:
109:                            if (value != null) {
110:
111:                                String fontName = value.substring(0, value
112:                                        .indexOf(",")); //$NON-NLS-1$
113:                                int ind = fontName.lastIndexOf("Bold"); //$NON-NLS-1$
114:                                if (ind != -1) {
115:                                    fontName = fontName.substring(0, ind - 1);
116:                                } else {
117:                                    ind = fontName.lastIndexOf("Italic"); //$NON-NLS-1$
118:                                    if (ind != -1) {
119:                                        fontName = fontName.substring(0,
120:                                                ind - 1);
121:                                    }
122:                                }
123:
124:                                String charset = value.substring(value
125:                                        .indexOf(",") + 1, value.length()); //$NON-NLS-1$
126:
127:                                // Font File Names property value
128:                                String fileName = props
129:                                        .getProperty(FONT_FILE_NAME
130:                                                .replaceAll(
131:                                                        "PlatformFontName", fontName).replaceAll(" ", "_")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
132:
133:                                // Exclusion Ranges property value
134:                                String exclString = props
135:                                        .getProperty(EXCLUSION_RANGES
136:                                                .replaceAll(
137:                                                        "LogicalFontName", element).replaceAll("ComponentIndex", String.valueOf(numComp))); //$NON-NLS-1$ //$NON-NLS-2$
138:                                int[] exclRange = parseIntervals(exclString);
139:
140:                                // Component Font Character Encodings property value
141:                                String encoding = props
142:                                        .getProperty(FONT_CHARACTER_ENCODING
143:                                                .replaceAll(
144:                                                        "LogicalFontName", element).replaceAll("ComponentIndex", String.valueOf(numComp))); //$NON-NLS-1$ //$NON-NLS-2$
145:
146:                                FontProperty fp = new WinFontProperty(fileName,
147:                                        fontName, charset, j, exclRange,
148:                                        encoding);
149:                                propsVector.add(fp);
150:                                numComp++;
151:                            } else {
152:                                moreEntries = false;
153:                            }
154:                        }
155:                        fProperties.put(element + "." + j, propsVector); //$NON-NLS-1$
156:                    }
157:                }
158:
159:                return true;
160:
161:            }
162:
163:            @Override
164:            public int getFaceIndex(String faceName) {
165:                for (int i = 0; i < NativeFont.faces.length; i++) {
166:                    if (NativeFont.faces[i].equalsIgnoreCase(faceName)) {
167:                        return i;
168:                    }
169:                }
170:                return -1;
171:            }
172:
173:            @Override
174:            public Font[] getAllFonts() {
175:                String faces[] = NativeFont.getAvailableFaces();
176:                int count = faces.length;
177:                Font[] fonts = new Font[count];
178:
179:                for (int i = 0; i < count; i++) {
180:                    fonts[i] = new Font(faces[i], Font.PLAIN, 1);
181:                }
182:
183:                return fonts;
184:            }
185:
186:            @Override
187:            public String[] getAllFamilies() {
188:                if (allFamilies == null) {
189:                    allFamilies = NativeFont.getFamilies();
190:                }
191:                return allFamilies;
192:            }
193:
194:            @Override
195:            public FontPeer createPhysicalFontPeer(String name, int style,
196:                    int size) {
197:                WindowsFont peer;
198:                if (isFamilyExist(name)) {
199:                    peer = new WindowsFont(name, style, size);
200:                    peer.setFamily(name);
201:                    return peer;
202:                }
203:                int faceIndex = getFaceIndex(name);
204:                if (faceIndex != -1) {
205:                    style |= NativeFont.fontStyles[faceIndex];
206:                    name = NativeFont.getFamily(faceIndex);
207:
208:                    peer = new WindowsFont(name, style, size);
209:                    return peer;
210:                }
211:
212:                return null;
213:            }
214:
215:            @Override
216:            public FontPeer createDefaultFont(int style, int size) {
217:                return new WindowsFont(DEFAULT_NAME, style, size);
218:            }
219:
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.