1 /* 2 * Copyright (c) 2011, 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 23 * questions. 24 */ 25 26 package com.sun.javafx.font; 27 28 import java.security.AccessController; 29 import java.security.PrivilegedAction; 30 import java.util.ArrayList; 31 import java.util.HashMap; 32 import java.util.Locale; 33 34 import com.sun.glass.utils.NativeLibLoader; 35 36 class MacFontFinder { 37 38 static { 39 AccessController.doPrivileged( 40 (PrivilegedAction<Void>) () -> { 41 NativeLibLoader.loadLibrary("javafx_font"); 42 return null; 43 } 44 ); 45 } 46 47 private static final int SystemFontType = 2; /*kCTFontSystemFontType*/ 48 private static final int MonospacedFontType = 1; /*kCTFontUserFixedPitchFontType*/ 49 private native static String getFont(int type); 50 public static String getSystemFont() { 51 return getFont(SystemFontType); 52 } 53 54 public static String getMonospacedFont() { 55 return getFont(MonospacedFontType); 56 } 57 58 native static float getSystemFontSize(); 59 60 public static boolean populateFontFileNameMap( 61 HashMap<String,String> fontToFileMap, 62 HashMap<String,String> fontToFamilyNameMap, 63 HashMap<String,ArrayList<String>> familyToFontListMap, 64 Locale locale) { 65 66 if (fontToFileMap == null || 67 fontToFamilyNameMap == null || 68 familyToFontListMap == null) { 69 return false; 70 } 71 if (locale == null) { 72 locale = Locale.ENGLISH; 73 } 74 String[] fontData = getFontData(); 75 if (fontData == null) return false; 76 77 int i = 0; 78 while (i < fontData.length) { 79 String name = fontData[i++]; 80 String family = fontData[i++]; 81 String file = fontData[i++]; 82 83 if (!PrismFontFactory.useNativeRasterizer) { 84 /* Skip OTF/CID keyed fonts for T2K (RT-15755) */ 85 if (file.endsWith(".otf")) { 86 if (name.indexOf(" Pro W") != -1) continue; 87 if (name.indexOf(" ProN W") != -1) continue; 88 if (name.indexOf(" Std W") != -1) continue; 89 if (name.indexOf(" StdN W") != -1) continue; 90 if (name.indexOf("Hiragino") != -1) continue; 91 } 92 } 93 if (PrismFontFactory.debugFonts) { 94 System.err.println("[MacFontFinder] Name=" + name); 95 System.err.println("\tFamily=" + family); 96 System.err.println("\tFile=" + file); 97 } 98 99 String lcName = name.toLowerCase(locale); 100 String lcFamily = family.toLowerCase(locale); 101 fontToFileMap.put(lcName, file); 102 fontToFamilyNameMap.put(lcName, family); 103 ArrayList<String> list = familyToFontListMap.get(lcFamily); 104 if (list == null) { 105 list = new ArrayList<String>(); 106 familyToFontListMap.put(lcFamily, list); 107 } 108 list.add(name); 109 } 110 return true; 111 } 112 /* 113 * 114 * @param familyName 115 * @return array of post-script font names 116 */ 117 private native static String[] getFontData(); 118 } 119