private void readCharMap()

in src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java [154:208]


    private void readCharMap(FontContainer font, Map<Integer, String> gidToGlyph, GlyphData[] glyphData,
                             PDCIDFont mainFont, Map<Integer, Integer> oldToNewGIMap) throws IOException {
        int widthPos = font.getFirstChar() + 1;
        for (Map.Entry<Integer, String> i : gidToGlyph.entrySet()) {
            String mappedChar = i.getValue();
            int key = i.getKey();
            boolean skipWidth = (mappedChar == null) || mappedChar.length() == 0;
            if (skipWidth) {
                mappedChar = (char)charMapGlobal.size() + "tmp";
            } else if (mappedChar.length() > 1) {
                mappedChar = "" + (char)mappedChar.hashCode();
            }
            if (!charMapGlobal.containsKey(mappedChar)) {
                char c = mappedChar.charAt(0);
                if (glyphData.length > 0
                        && glyphData[key] == null
                        && !CharUtilities.isAdjustableSpace(c)) {
                    continue;
                }
                boolean addToEnd = charMapGlobal.containsValue(key);
                if (addToEnd) {
                    int glyphIndex = charMapGlobal.size() + 1;
                    while (charMapGlobal.values().contains(glyphIndex)) {
                        glyphIndex++;
                    }
                    addPrivateUseMapping(c, glyphIndex);
                    charMapGlobal.put(mappedChar, glyphIndex);
                } else {
                    addPrivateUseMapping(c, key);
                    charMapGlobal.put(mappedChar, key);
                }
                int glyph = 0;
                if (hasChar(c)) {
                    glyph = (int) mapChar(c);
                }
                oldToNewGIMap.put(key, glyph);
                if (!skipWidth) {
                    if (!(font.font instanceof PDTrueTypeFont)) {
                        widthPos = key;
                    }
                    float w = font.font.getWidth(widthPos);
                    if (w >= 0) {
                        if (mainFont instanceof PDCIDFontType0) {
                            newWidth.put(key, (int)w);
                        } else {
                            newWidth.put(glyph, (int)w);
                        }
                    }
                }
            }
            if (!skipWidth) {
                widthPos++;
            }
        }
    }