1 /*
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
135 }
136
137 @Override
138 protected Charset getDefaultFontCharset(String fontName) {
139 return new WDefaultFontCharset(fontName);
140 }
141
142 @Override
143 public String getFaceNameFromComponentFontName(String componentFontName) {
144 // for Windows, the platform name is the face name
145 return componentFontName;
146 }
147
148 @Override
149 protected String getFileNameFromComponentFontName(String componentFontName) {
150 return getFileNameFromPlatformName(componentFontName);
151 }
152
153 /**
154 * Returns the component font name (face name plus charset) of the
155 * font that should be used for AWT text components. May return null.
156 */
157 public String getTextComponentFontName(String familyName, int style) {
158 FontDescriptor[] fontDescriptors = getFontDescriptors(familyName, style);
159 String fontName = findFontWithCharset(fontDescriptors, textInputCharset);
160 if (fontName == null) {
161 fontName = findFontWithCharset(fontDescriptors, "DEFAULT_CHARSET");
162 }
163 return fontName;
164 }
165
166 private String findFontWithCharset(FontDescriptor[] fontDescriptors, String charset) {
167 String fontName = null;
168 for (int i = 0; i < fontDescriptors.length; i++) {
169 String componentFontName = fontDescriptors[i].getNativeName();
170 if (componentFontName.endsWith(charset)) {
171 fontName = componentFontName;
172 }
173 }
174 return fontName;
175 }
176
177 private static HashMap<String, String> subsetCharsetMap = new HashMap<>();
178 private static HashMap<String, String> subsetEncodingMap = new HashMap<>();
179 private static String textInputCharset;
180
181 private void initTables(String defaultEncoding) {
|
1 /*
2 * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
135 }
136
137 @Override
138 protected Charset getDefaultFontCharset(String fontName) {
139 return new WDefaultFontCharset(fontName);
140 }
141
142 @Override
143 public String getFaceNameFromComponentFontName(String componentFontName) {
144 // for Windows, the platform name is the face name
145 return componentFontName;
146 }
147
148 @Override
149 protected String getFileNameFromComponentFontName(String componentFontName) {
150 return getFileNameFromPlatformName(componentFontName);
151 }
152
153 /**
154 * Returns the component font name (face name plus charset) of the
155 * font that should be used for AWT text components.
156 */
157 public String getTextComponentFontName(String familyName, int style) {
158 FontDescriptor[] fontDescriptors = getFontDescriptors(familyName, style);
159 String fontName = findFontWithCharset(fontDescriptors, textInputCharset);
160 if ((fontName == null) && !textInputCharset.equals("DEFAULT_CHARSET")) {
161 fontName = findFontWithCharset(fontDescriptors, "DEFAULT_CHARSET");
162 }
163 if (fontName == null) {
164 fontName = (fontDescriptors.length > 0) ? fontDescriptors[0].getNativeName()
165 : "Arial.ANSI_CHARSET";
166 }
167 return fontName;
168 }
169
170 private String findFontWithCharset(FontDescriptor[] fontDescriptors, String charset) {
171 String fontName = null;
172 for (int i = 0; i < fontDescriptors.length; i++) {
173 String componentFontName = fontDescriptors[i].getNativeName();
174 if (componentFontName.endsWith(charset)) {
175 fontName = componentFontName;
176 }
177 }
178 return fontName;
179 }
180
181 private static HashMap<String, String> subsetCharsetMap = new HashMap<>();
182 private static HashMap<String, String> subsetEncodingMap = new HashMap<>();
183 private static String textInputCharset;
184
185 private void initTables(String defaultEncoding) {
|