< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/WFontConfiguration.java

Print this page


   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


 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) {
 182         subsetCharsetMap.put("alphabetic", "ANSI_CHARSET");
 183         subsetCharsetMap.put("alphabetic/1252", "ANSI_CHARSET");
 184         subsetCharsetMap.put("alphabetic/default", "DEFAULT_CHARSET");
 185         subsetCharsetMap.put("arabic", "ARABIC_CHARSET");
 186         subsetCharsetMap.put("chinese-ms936", "GB2312_CHARSET");
 187         subsetCharsetMap.put("chinese-gb18030", "GB2312_CHARSET");
 188         subsetCharsetMap.put("chinese-ms950", "CHINESEBIG5_CHARSET");
 189         subsetCharsetMap.put("chinese-hkscs", "CHINESEBIG5_CHARSET");
 190         subsetCharsetMap.put("cyrillic", "RUSSIAN_CHARSET");
 191         subsetCharsetMap.put("devanagari", "DEFAULT_CHARSET");


   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


 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             FontDescriptor desc = fontDescriptors[i];
 170             String componentFontName = desc.getNativeName();
 171             if ((desc.isDefaultFont() && charset.equals("DEFAULT_CHARSET")) ||
 172                 componentFontName.endsWith(charset)) {
 173                 fontName = componentFontName;
 174                 break;
 175             }
 176         }
 177         return fontName;
 178     }
 179 
 180     private static HashMap<String, String> subsetCharsetMap = new HashMap<>();
 181     private static HashMap<String, String> subsetEncodingMap = new HashMap<>();
 182     private static String textInputCharset;
 183 
 184     private void initTables(String defaultEncoding) {
 185         subsetCharsetMap.put("alphabetic", "ANSI_CHARSET");
 186         subsetCharsetMap.put("alphabetic/1252", "ANSI_CHARSET");
 187         subsetCharsetMap.put("alphabetic/default", "DEFAULT_CHARSET");
 188         subsetCharsetMap.put("arabic", "ARABIC_CHARSET");
 189         subsetCharsetMap.put("chinese-ms936", "GB2312_CHARSET");
 190         subsetCharsetMap.put("chinese-gb18030", "GB2312_CHARSET");
 191         subsetCharsetMap.put("chinese-ms950", "CHINESEBIG5_CHARSET");
 192         subsetCharsetMap.put("chinese-hkscs", "CHINESEBIG5_CHARSET");
 193         subsetCharsetMap.put("cyrillic", "RUSSIAN_CHARSET");
 194         subsetCharsetMap.put("devanagari", "DEFAULT_CHARSET");


< prev index next >