< prev index next >

src/java.desktop/share/classes/sun/font/SunFontManager.java

Print this page




  38 import java.util.ArrayList;
  39 import java.util.HashMap;
  40 import java.util.HashSet;
  41 import java.util.Hashtable;
  42 import java.util.Iterator;
  43 import java.util.List;
  44 import java.util.Locale;
  45 import java.util.Map;
  46 import java.util.NoSuchElementException;
  47 import java.util.StringTokenizer;
  48 import java.util.TreeMap;
  49 import java.util.Vector;
  50 import java.util.concurrent.ConcurrentHashMap;
  51 
  52 import javax.swing.plaf.FontUIResource;
  53 import sun.awt.AppContext;
  54 import sun.awt.FontConfiguration;
  55 import sun.awt.SunToolkit;
  56 import sun.awt.util.ThreadGroupUtils;
  57 import sun.java2d.FontSupport;
  58 import sun.misc.ManagedLocalsThread;
  59 import sun.util.logging.PlatformLogger;
  60 
  61 /**
  62  * The base implementation of the {@link FontManager} interface. It implements
  63  * the platform independent, shared parts of OpenJDK's FontManager
  64  * implementations. The platform specific parts are declared as abstract
  65  * methods that have to be implemented by specific implementations.
  66  */
  67 public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
  68 
  69     private static class TTFilter implements FilenameFilter {
  70         public boolean accept(File dir,String name) {
  71             /* all conveniently have the same suffix length */
  72             int offset = name.length()-4;
  73             if (offset <= 0) { /* must be at least A.ttf */
  74                 return false;
  75             } else {
  76                 return(name.startsWith(".ttf", offset) ||
  77                        name.startsWith(".TTF", offset) ||
  78                        name.startsWith(".ttc", offset) ||


2496                             }
2497                             if (tmpFontFiles != null) {
2498                                 File[] files = new File[tmpFontFiles.size()];
2499                                 files = tmpFontFiles.toArray(files);
2500                                 for (int f=0; f<files.length;f++) {
2501                                     try {
2502                                         files[f].delete();
2503                                     } catch (Exception e) {
2504                                     }
2505                                 }
2506                             }
2507 
2508                             return null;
2509                           }
2510 
2511                           });
2512                       }
2513                     };
2514                     AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
2515                         ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
2516                         fileCloser = new ManagedLocalsThread(rootTG,
2517                                                              fileCloserRunnable);
2518                         fileCloser.setContextClassLoader(null);
2519                         Runtime.getRuntime().addShutdownHook(fileCloser);
2520                         return null;
2521                     });
2522                 }
2523             }
2524         }
2525         return fList.toArray(new Font2D[0]);
2526     }
2527 
2528     /* remind: used in X11GraphicsEnvironment and called often enough
2529      * that we ought to obsolete this code
2530      */
2531     public synchronized String getFullNameByFileName(String fileName) {
2532         PhysicalFont[] physFonts = getPhysicalFonts();
2533         for (int i=0;i<physFonts.length;i++) {
2534             if (physFonts[i].platName.equals(fileName)) {
2535                 return (physFonts[i].getFontName(null));
2536             }
2537         }




  38 import java.util.ArrayList;
  39 import java.util.HashMap;
  40 import java.util.HashSet;
  41 import java.util.Hashtable;
  42 import java.util.Iterator;
  43 import java.util.List;
  44 import java.util.Locale;
  45 import java.util.Map;
  46 import java.util.NoSuchElementException;
  47 import java.util.StringTokenizer;
  48 import java.util.TreeMap;
  49 import java.util.Vector;
  50 import java.util.concurrent.ConcurrentHashMap;
  51 
  52 import javax.swing.plaf.FontUIResource;
  53 import sun.awt.AppContext;
  54 import sun.awt.FontConfiguration;
  55 import sun.awt.SunToolkit;
  56 import sun.awt.util.ThreadGroupUtils;
  57 import sun.java2d.FontSupport;

  58 import sun.util.logging.PlatformLogger;
  59 
  60 /**
  61  * The base implementation of the {@link FontManager} interface. It implements
  62  * the platform independent, shared parts of OpenJDK's FontManager
  63  * implementations. The platform specific parts are declared as abstract
  64  * methods that have to be implemented by specific implementations.
  65  */
  66 public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
  67 
  68     private static class TTFilter implements FilenameFilter {
  69         public boolean accept(File dir,String name) {
  70             /* all conveniently have the same suffix length */
  71             int offset = name.length()-4;
  72             if (offset <= 0) { /* must be at least A.ttf */
  73                 return false;
  74             } else {
  75                 return(name.startsWith(".ttf", offset) ||
  76                        name.startsWith(".TTF", offset) ||
  77                        name.startsWith(".ttc", offset) ||


2495                             }
2496                             if (tmpFontFiles != null) {
2497                                 File[] files = new File[tmpFontFiles.size()];
2498                                 files = tmpFontFiles.toArray(files);
2499                                 for (int f=0; f<files.length;f++) {
2500                                     try {
2501                                         files[f].delete();
2502                                     } catch (Exception e) {
2503                                     }
2504                                 }
2505                             }
2506 
2507                             return null;
2508                           }
2509 
2510                           });
2511                       }
2512                     };
2513                     AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
2514                         ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
2515                         fileCloser = new Thread(rootTG, fileCloserRunnable,
2516                                                 "FileCloser", 0, false);
2517                         fileCloser.setContextClassLoader(null);
2518                         Runtime.getRuntime().addShutdownHook(fileCloser);
2519                         return null;
2520                     });
2521                 }
2522             }
2523         }
2524         return fList.toArray(new Font2D[0]);
2525     }
2526 
2527     /* remind: used in X11GraphicsEnvironment and called often enough
2528      * that we ought to obsolete this code
2529      */
2530     public synchronized String getFullNameByFileName(String fileName) {
2531         PhysicalFont[] physFonts = getPhysicalFonts();
2532         for (int i=0;i<physFonts.length;i++) {
2533             if (physFonts[i].platName.equals(fileName)) {
2534                 return (physFonts[i].getFontName(null));
2535             }
2536         }


< prev index next >