27
28 import java.awt.*;
29 import java.io.File;
30 import java.security.AccessController;
31 import java.security.PrivilegedAction;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.Hashtable;
35 import java.util.Locale;
36 import java.util.TreeMap;
37 import java.util.Vector;
38
39 import javax.swing.plaf.FontUIResource;
40
41 import sun.awt.FontConfiguration;
42 import sun.awt.HeadlessToolkit;
43 import sun.awt.util.ThreadGroupUtils;
44 import sun.lwawt.macosx.*;
45
46 public final class CFontManager extends SunFontManager {
47 private FontConfigManager fcManager = null;
48 private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
49
50 @Override
51 protected FontConfiguration createFontConfiguration() {
52 FontConfiguration fc = new CFontConfiguration(this);
53 fc.init();
54 return fc;
55 }
56
57 @Override
58 public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
59 boolean preferPropFonts)
60 {
61 return new CFontConfiguration(this, preferLocaleFonts, preferPropFonts);
62 }
63
64 /*
65 * Returns an array of two strings. The first element is the
66 * name of the font. The second element is the file name.
67 */
214 };
215 AccessController.doPrivileged(
216 (PrivilegedAction<Void>) () -> {
217 /* The thread must be a member of a thread group
218 * which will not get GCed before VM exit.
219 * Make its parent the top-level thread group.
220 */
221 ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
222 fileCloser = new Thread(rootTG, fileCloserRunnable);
223 fileCloser.setContextClassLoader(null);
224 Runtime.getRuntime().addShutdownHook(fileCloser);
225 return null;
226 }
227 );
228 }
229 }
230 }
231 return font2D;
232 }
233
234 /*
235 public synchronized FontConfigManager getFontConfigManager() {
236 if (fcManager == null) {
237 fcManager = new FontConfigManager();
238 }
239 return fcManager;
240 }
241 */
242
243 protected void registerFontsInDir(String dirName, boolean useJavaRasterizer, int fontRank, boolean defer, boolean resolveSymLinks) {
244 loadNativeDirFonts(dirName);
245 super.registerFontsInDir(dirName, useJavaRasterizer, fontRank, defer, resolveSymLinks);
246 }
247
248 private native void loadNativeDirFonts(String dirName);
249 private native void loadNativeFonts();
250
251 void registerFont(String fontName, String fontFamilyName) {
252 final CFont font = new CFont(fontName, fontFamilyName);
253
254 registerGenericFont(font);
255 }
256
257 void registerItalicDerived() {
258 FontFamily[] famArr = FontFamily.getAllFontFamilies();
259 for (int i=0; i<famArr.length; i++) {
260 FontFamily family = famArr[i];
261
262 Font2D f2dPlain = family.getFont(Font.PLAIN);
|
27
28 import java.awt.*;
29 import java.io.File;
30 import java.security.AccessController;
31 import java.security.PrivilegedAction;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.Hashtable;
35 import java.util.Locale;
36 import java.util.TreeMap;
37 import java.util.Vector;
38
39 import javax.swing.plaf.FontUIResource;
40
41 import sun.awt.FontConfiguration;
42 import sun.awt.HeadlessToolkit;
43 import sun.awt.util.ThreadGroupUtils;
44 import sun.lwawt.macosx.*;
45
46 public final class CFontManager extends SunFontManager {
47 private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
48
49 @Override
50 protected FontConfiguration createFontConfiguration() {
51 FontConfiguration fc = new CFontConfiguration(this);
52 fc.init();
53 return fc;
54 }
55
56 @Override
57 public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
58 boolean preferPropFonts)
59 {
60 return new CFontConfiguration(this, preferLocaleFonts, preferPropFonts);
61 }
62
63 /*
64 * Returns an array of two strings. The first element is the
65 * name of the font. The second element is the file name.
66 */
213 };
214 AccessController.doPrivileged(
215 (PrivilegedAction<Void>) () -> {
216 /* The thread must be a member of a thread group
217 * which will not get GCed before VM exit.
218 * Make its parent the top-level thread group.
219 */
220 ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
221 fileCloser = new Thread(rootTG, fileCloserRunnable);
222 fileCloser.setContextClassLoader(null);
223 Runtime.getRuntime().addShutdownHook(fileCloser);
224 return null;
225 }
226 );
227 }
228 }
229 }
230 return font2D;
231 }
232
233 protected void registerFontsInDir(String dirName, boolean useJavaRasterizer, int fontRank, boolean defer, boolean resolveSymLinks) {
234 loadNativeDirFonts(dirName);
235 super.registerFontsInDir(dirName, useJavaRasterizer, fontRank, defer, resolveSymLinks);
236 }
237
238 private native void loadNativeDirFonts(String dirName);
239 private native void loadNativeFonts();
240
241 void registerFont(String fontName, String fontFamilyName) {
242 final CFont font = new CFont(fontName, fontFamilyName);
243
244 registerGenericFont(font);
245 }
246
247 void registerItalicDerived() {
248 FontFamily[] famArr = FontFamily.getAllFontFamilies();
249 for (int i=0; i<famArr.length; i++) {
250 FontFamily family = famArr[i];
251
252 Font2D f2dPlain = family.getFont(Font.PLAIN);
|