Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4091081

font loading bug/enhancement

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.1.6
    • 1.1.5
    • client-libs
    • 1.1.6
    • x86
    • windows_nt
    • Verified



        Name: chT40241 Date: 11/06/97


        In sun.awt.windows.WFontPeer, the author intended for "default" charsets to be hashed under the given fontName. However, the original code immediately returns after getting the default font charset without caching it (shown below). It seems clearly that the author intended to cache it, but the return prevents it. The fix is very simple, and the changed lines are commented.

        This change is very important because the original code results in 3 exceptions being thrown every time the code looks up a "default" charset. Thus, when a large number of java.awt.Font objects are instantiated, 3 times that number of exceptions are thrown. Preventing these redundant exceptions leads to a significant speed up of such code.

        Revised code for sun.awt.windows.WFontPeer:
        (please excuse the reformatting but I can't fit it in with this small input window):

            public CharToByteConverter
        getFontCharset(String charsetName,
                                                 String fontName){

        CharToByteConverter fc;
        if (charsetName.equals("default")){
        fc = (CharToByteConverter)charsetRegistry.get(fontName);
        } else {
        fc = (CharToByteConverter)charsetRegistry.get(charsetName);
        }
        if (fc instanceof CharToByteConverter){
        return fc;
        }

        Class fcc = null;

        try {
        fcc = Class.forName(charsetName);
        } catch(ClassNotFoundException e){
        try {
        fcc = Class.forName("sun.io." + charsetName);
        } catch (ClassNotFoundException exx){
        try {
        fcc = Class.forName("sun.awt.windows." + charsetName);
        } catch(ClassNotFoundException ex){
        fc = getDefaultFontCharset(fontName); // *** CHANGED line above
        // ORIGINAL LINE:
                                          //return getDefaultFontCharset(fontName);
        }
        }
        }

        if (fc == null) { // *** ADDED
        try {
        fc = (CharToByteConverter)fcc.newInstance();
        } catch(InstantiationException e){
        return getDefaultFontCharset(fontName);
        } catch(IllegalAccessException e){
        return getDefaultFontCharset(fontName);
        }
        } // *** ADDED

        if (charsetName.equals("default")){
        charsetRegistry.put(fontName, fc);
        } else {
        charsetRegistry.put(charsetName, fc);
        }
        return fc;
            }



        ======================================================================

              ehawkessunw Eric Hawkes (Inactive)
              chickeysunw Chuck Hickey (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: