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);
}
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;
}
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;
}
Aggregations