protected ByteArrayOutputStream writeMainSection()

in src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java [219:253]


    protected ByteArrayOutputStream writeMainSection(byte[] decoded, List<PostscriptParser.PSElement> mainSection,
                                                     PostscriptParser.PSElement charStrings) throws IOException {
        ByteArrayOutputStream main = new ByteArrayOutputStream();
        //Find the ID of the three most commonly subroutines defined in Type 1 fonts
        String rd = findVariable(decoded, mainSection, new String[] {"string currentfile exch readstring pop"}, "RD");
        String nd = findVariable(decoded, mainSection, new String[] {"def", "noaccess def"}, "noaccess def");
        String np = findVariable(decoded, mainSection, new String[] {"put", "noaccess put"}, "noaccess put");
        main.write(subrsBeforeStream.toByteArray());
        writeString("/lenIV 4 def", main);
        writeString("/Subrs " + subByteMap.size() + " array" + eol, main);
        for (Map.Entry<Integer, byte[]> e : subByteMap.entrySet()) {
            if (e.getValue() != null) {
                byte[] encoded = BinaryCoder.encodeBytes(e.getValue(), 4330, 4);
                writeString("dup " + e.getKey() + " " + encoded.length + " " + rd + " ", main);
                main.write(encoded);
                writeString(" " + np + eol, main);
            }
        }
        writeString(nd + eol, main);
        main.write(subrsEndStream.toByteArray());
        //Write the subset charString array
        writeString(eol + String.format("/CharStrings %d dict dup begin",
                subsetCharStrings.size()), main);
        for (Map.Entry<String, byte[]> entry : subsetCharStrings.entrySet()) {
            writeString(eol + String.format("%s %d %s ", entry.getKey(),
                    entry.getValue().length, rd),
                    main);
            main.write(entry.getValue());
            writeString(" " + nd, main);
        }
        writeString(eol + "end", main);
        main.write(decoded, charStrings.getEndPoint(), decoded.length - charStrings.getEndPoint());

        return main;
    }