2272 lines · 92.3 KB · Java
RawDownload
            logicalFontIDs.put("dialoginput",4);            fontStyleIDs.put("plain",      0);            fontStyleIDs.put("bold",       1);            fontStyleIDs.put("italic",     2);            fontStyleIDs.put("bolditalic", 3);        }         private void initHashMaps() {            scriptIDs = new HashMap<String, Short>();            elcIDs = new HashMap<String, Short>();            componentFontNameIDs = new HashMap<String, Short>();            /*Init these tables to allow componentFontNameID, fontfileNameIDs              to start from "1".            */            componentFontNameIDs.put("", Short.valueOf((short)0));             fontfileNameIDs = new HashMap<String, Short>();            filenames = new HashMap<Short, Short>();            sequences = new HashMap<Short, short[]>();            scriptFonts = new HashMap<Short, Short[]>();            scriptAllfonts = new HashMap<Short, Short>();            exclusions = new HashMap<Short, int[]>();            awtfontpaths = new HashMap<Short, Short>();            proportionals = new HashMap<Short, Short>();            scriptFontsMotif = new HashMap<Short, Short[]>();            scriptAllfontsMotif = new HashMap<Short, Short>();            alphabeticSuffix = new HashMap<Short, Short>();            fallbackScriptIDs = EMPTY_SHORT_ARRAY;            /*              version              appendedfontpath            */        }         private int[] parseExclusions(String key, String exclusions) {            if (exclusions == null) {                return EMPTY_INT_ARRAY;            }            // range format is xxxx-XXXX,yyyyyy-YYYYYY,.....            int numExclusions = 1;            int pos = 0;            while ((pos = exclusions.indexOf(',', pos)) != -1) {                numExclusions++;                pos++;            }            int[] exclusionRanges = new int[numExclusions * 2];            pos = 0;            int newPos = 0;            for (int j = 0; j < numExclusions * 2; ) {                String lower, upper;                int lo = 0, up = 0;                try {                    newPos = exclusions.indexOf('-', pos);                    lower = exclusions.substring(pos, newPos);                    pos = newPos + 1;                    newPos = exclusions.indexOf(',', pos);                    if (newPos == -1) {                        newPos = exclusions.length();                    }                    upper = exclusions.substring(pos, newPos);                    pos = newPos + 1;                    int lowerLength = lower.length();                    int upperLength = upper.length();                    if (lowerLength != 4 && lowerLength != 6                        || upperLength != 4 && upperLength != 6) {                        throw new Exception();                    }                    lo = Integer.parseInt(lower, 16);                    up = Integer.parseInt(upper, 16);                    if (lo > up) {                        throw new Exception();                    }                } catch (Exception e) {                    if (FontUtilities.debugFonts() &&                        logger != null) {                        logger.config("Failed parsing " + key +                                  " property of font configuration.");                     }                    return EMPTY_INT_ARRAY;                }                exclusionRanges[j++] = lo;                exclusionRanges[j++] = up;            }            return exclusionRanges;        }         private Short getID(HashMap<String, Short> map, String key) {            Short ret = map.get(key);            if ( ret == null) {                map.put(key, (short)map.size());                return map.get(key);            }            return ret;        }         class FontProperties extends Properties {            public synchronized Object put(Object k, Object v) {                parseProperty((String)k, (String)v);                return null;            }        }         private void parseProperty(String key, String value) {            if (key.startsWith("filename.")) {                //the only special case is "MingLiu_HKSCS" which has "_" in its                //facename, we dont want to replace the "_" with " "                key = key.substring(9);                if (!"MingLiU_HKSCS".equals(key)) {                    key = key.replace('_', ' ');                }                Short faceID = getID(componentFontNameIDs, key);                Short fileID = getID(fontfileNameIDs, value);                //System.out.println("faceID=" + faceID + "/" + key + " -> "                //    + "fileID=" + fileID + "/" + value);                filenames.put(faceID, fileID);            } else if (key.startsWith("exclusion.")) {                key = key.substring(10);                exclusions.put(getID(scriptIDs,key), parseExclusions(key,value));            } else if (key.startsWith("sequence.")) {                key = key.substring(9);                boolean hasDefault = false;                boolean has1252 = false;                 //get the scriptID list                String[] ss = (String[])splitSequence(value).toArray(EMPTY_STRING_ARRAY);                short [] sa = new short[ss.length];                for (int i = 0; i < ss.length; i++) {                    if ("alphabetic/default".equals(ss[i])) {                        //System.out.println(key + " -> " + ss[i]);                        ss[i] = "alphabetic";                        hasDefault = true;                    } else if ("alphabetic/1252".equals(ss[i])) {                        //System.out.println(key + " -> " + ss[i]);                        ss[i] = "alphabetic";                        has1252 = true;                    }                    sa[i] = getID(scriptIDs, ss[i]).shortValue();                    //System.out.println("scriptID=" + si[i] + "/" + ss[i]);                }                //convert the "short[] -> string -> stringID"                short scriptArrayID = getShortArrayID(sa);                Short elcID = null;                int dot = key.indexOf('.');                if (dot == -1) {                    if ("fallback".equals(key)) {                        fallbackScriptIDs = sa;                        return;                    }                    if ("allfonts".equals(key)) {                        elcID = getID(elcIDs, "NULL.NULL.NULL");                    } else {                        if (logger != null) {                            logger.config("Error sequence def: <sequence." + key + ">");                        }                        return;                    }                } else {                    elcID = getID(elcIDs, key.substring(dot + 1));                    //System.out.println("elcID=" + elcID + "/" + key.substring(dot + 1));                    key = key.substring(0, dot);                }                short[] scriptArrayIDs = null;                if ("allfonts".equals(key)) {                    scriptArrayIDs = new short[1];                    scriptArrayIDs[0] = scriptArrayID;                } else {                    scriptArrayIDs = sequences.get(elcID);                    if (scriptArrayIDs == null) {                       scriptArrayIDs = new short[5];                    }                    Integer fid = logicalFontIDs.get(key);                    if (fid == null) {                        if (logger != null) {                            logger.config("Unrecognizable logicfont name " + key);                        }                        return;                    }                    //System.out.println("sequence." + key + "/" + id);                    scriptArrayIDs[fid.intValue()] = scriptArrayID;                }                sequences.put(elcID, scriptArrayIDs);                if (hasDefault) {                    alphabeticSuffix.put(elcID, getStringID("default"));                } else                if (has1252) {                    alphabeticSuffix.put(elcID, getStringID("1252"));                }            } else if (key.startsWith("allfonts.")) {                key = key.substring(9);                if (key.endsWith(".motif")) {                    key = key.substring(0, key.length() - 6);                    //System.out.println("motif: all." + key + "=" + value);                    scriptAllfontsMotif.put(getID(scriptIDs,key), getID(componentFontNameIDs,value));                } else {                    scriptAllfonts.put(getID(scriptIDs,key), getID(componentFontNameIDs,value));                }            } else if (key.startsWith("awtfontpath.")) {                key = key.substring(12);                //System.out.println("scriptID=" + getID(scriptIDs, key) + "/" + key);                awtfontpaths.put(getID(scriptIDs, key), getStringID(value));            } else if ("version".equals(key)) {                version = value;            } else if ("appendedfontpath".equals(key)) {                appendedfontpath = value;            } else if (key.startsWith("proportional.")) {                key = key.substring(13).replace('_', ' ');                //System.out.println(key + "=" + value);                proportionals.put(getID(componentFontNameIDs, key),                                  getID(componentFontNameIDs, value));            } else {                //"name.style.script(.motif)", we dont care anything else                int dot1, dot2;                boolean isMotif = false;                 dot1 = key.indexOf('.');                if (dot1 == -1) {                    if (logger != null) {                        logger.config("Failed parsing " + key +                                  " property of font configuration.");                     }                    return;                }                dot2 = key.indexOf('.', dot1 + 1);                if (dot2 == -1) {                    if (logger != null) {                        logger.config("Failed parsing " + key +                                  " property of font configuration.");                     }                    return;                }                if (key.endsWith(".motif")) {                    key = key.substring(0, key.length() - 6);                    isMotif = true;                    //System.out.println("motif: " + key + "=" + value);                }                Integer nameID = logicalFontIDs.get(key.substring(0, dot1));                Integer styleID = fontStyleIDs.get(key.substring(dot1+1, dot2));                Short scriptID = getID(scriptIDs, key.substring(dot2 + 1));                if (nameID == null || styleID == null) {                    if (logger != null) {                        logger.config("unrecognizable logicfont name/style at " + key);                    }                    return;                }                Short[] pnids;                if (isMotif) {                    pnids = scriptFontsMotif.get(scriptID);                } else {                    pnids = scriptFonts.get(scriptID);                }                if (pnids == null) {                    pnids =  new Short[20];                }                pnids[nameID.intValue() * NUM_STYLES + styleID.intValue()]                  = getID(componentFontNameIDs, value);                /*                System.out.println("key=" + key + "/<" + nameID + "><" + styleID                                     + "><" + scriptID + ">=" + value                                     + "/" + getID(componentFontNameIDs, value));                */                if (isMotif) {                    scriptFontsMotif.put(scriptID, pnids);                } else {                    scriptFonts.put(scriptID, pnids);                }            }        }    }}

Lines 2001–2272 of 2272. Previous lines