Search in sources :

Example 16 with PDStream

use of com.tom_roush.pdfbox.pdmodel.common.PDStream in project PdfBox-Android by TomRoush.

the class PDCIDFontType2Embedder method buildToUnicodeCMap.

private void buildToUnicodeCMap(Map<Integer, Integer> newGIDToOldCID) throws IOException {
    ToUnicodeWriter toUniWriter = new ToUnicodeWriter();
    boolean hasSurrogates = false;
    for (int gid = 1, max = ttf.getMaximumProfile().getNumGlyphs(); gid <= max; gid++) {
        // optional CID2GIDMap for subsetting
        int cid;
        if (newGIDToOldCID != null) {
            if (!newGIDToOldCID.containsKey(gid)) {
                continue;
            } else {
                cid = newGIDToOldCID.get(gid);
            }
        } else {
            cid = gid;
        }
        // skip composite glyph components that have no code point
        // old GID -> Unicode
        List<Integer> codes = cmapLookup.getCharCodes(cid);
        if (codes != null) {
            // use the first entry even for ambiguous mappings
            int codePoint = codes.get(0);
            if (codePoint > 0xFFFF) {
                hasSurrogates = true;
            }
            toUniWriter.add(cid, new String(new int[] { codePoint }, 0, 1));
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    toUniWriter.writeTo(out);
    InputStream cMapStream = new ByteArrayInputStream(out.toByteArray());
    PDStream stream = new PDStream(document, cMapStream, COSName.FLATE_DECODE);
    // surrogate code points, requires PDF 1.5
    if (hasSurrogates) {
        float version = document.getVersion();
        if (version < 1.5) {
            document.setVersion(1.5f);
        }
    }
    dict.setItem(COSName.TO_UNICODE, stream);
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PDStream(com.tom_roush.pdfbox.pdmodel.common.PDStream)

Example 17 with PDStream

use of com.tom_roush.pdfbox.pdmodel.common.PDStream in project PdfBox-Android by TomRoush.

the class PDFontDescriptor method getFontFile2.

/**
 * A stream containing a true type font program.
 *
 * @return A stream containing a true type font program.
 */
public PDStream getFontFile2() {
    PDStream retval = null;
    COSBase obj = dic.getDictionaryObject(COSName.FONT_FILE2);
    if (obj instanceof COSStream) {
        retval = new PDStream((COSStream) obj);
    }
    return retval;
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDStream(com.tom_roush.pdfbox.pdmodel.common.PDStream)

Example 18 with PDStream

use of com.tom_roush.pdfbox.pdmodel.common.PDStream in project PdfBox-Android by TomRoush.

the class PDFontDescriptor method getFontFile3.

/**
 * A stream containing a font program that is not true type or type 1.
 *
 * @return A stream containing a font program.
 */
public PDStream getFontFile3() {
    PDStream retval = null;
    COSBase obj = dic.getDictionaryObject(COSName.FONT_FILE3);
    if (obj instanceof COSStream) {
        retval = new PDStream((COSStream) obj);
    }
    return retval;
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDStream(com.tom_roush.pdfbox.pdmodel.common.PDStream)

Aggregations

PDStream (com.tom_roush.pdfbox.pdmodel.common.PDStream)18 COSStream (com.tom_roush.pdfbox.cos.COSStream)6 COSBase (com.tom_roush.pdfbox.cos.COSBase)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 COSArray (com.tom_roush.pdfbox.cos.COSArray)3 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)3 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)3 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)3 IOException (java.io.IOException)3 AffineTransform (com.tom_roush.harmony.awt.geom.AffineTransform)2 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)2 COSName (com.tom_roush.pdfbox.cos.COSName)2 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)2 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 TTFParser (com.tom_roush.fontbox.ttf.TTFParser)1 BoundingBox (com.tom_roush.fontbox.util.BoundingBox)1 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)1 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)1