protected void do_endbfrange(CSOperation operation) { Iterator it = operation.getOperands(); while (it.hasNext()) { COSString start = (COSString) it.next(); COSString end = (COSString) it.next(); COSObject destination = (COSObject) it.next(); CMapRangeMap map; if (destination instanceof COSString) { byte[] destBytes = ((COSString) destination).byteValue(); if (destBytes.length > 2) { // this is special to /ToUnicode maps map = new CMapBFRangeStringMap( start.byteValue(), end.byteValue(), ((COSString) destination).byteValue()); } else { map = new CMapBFRangeCodeMap( start.byteValue(), end.byteValue(), ((COSString) destination).byteValue()); } } else { COSArray array = destination.asArray(); if (array.get(0) instanceof COSString) { // this is special to /ToUnicode maps map = new CMapBFRangeStringArrayMap( start.byteValue(), end.byteValue(), (COSArray) destination); } else { map = new CMapBFRangeNameArrayMap( start.byteValue(), end.byteValue(), (COSArray) destination); } } addMap(map); } }
/** @return the lazily created font descriptor of this font */ protected PDFontDescriptor createFontDescriptor() { COSObject base = cosGetField(DK_FontDescriptor); if (base.isNull()) { return createBuiltinFontDescriptor(); } return (PDFontDescriptorEmbedded) PDFontDescriptorEmbedded.META.createFromCos(base); }
protected void do_def(CSOperation operation) { // define key / value association Iterator it = operation.getOperands(); COSObject operand = COSNull.NULL; if (it.hasNext()) { operand = (COSObject) it.next(); } COSDictionary dict = operand.asDictionary(); if (dict == null) { COSName key = operand.asName(); if (key == null) { return; } COSObject value = COSNull.NULL; if (it.hasNext()) { value = (COSObject) it.next(); } addDefinition(key, value); } else { Iterator<Map.Entry<COSName, COSObject>> eit = dict.entryIterator(); while (eit.hasNext()) { Map.Entry<COSName, COSObject> entry = eit.next(); COSName key = entry.getKey(); COSObject value = entry.getValue(); addDefinition(key, value); } } }
/** * The destination page. ATTENTION: it is common have dangling destinations to invalid (null) * pages around! * * @return The destination page. Be sure to handle null return values. */ public PDPage getPage(PDDocument doc) { COSArray definition = cosGetArray(); COSObject page = definition.get(0); if (page.asNumber() != null) { int pageIndex = page.asNumber().intValue(); return doc.getPageTree().getPageAt(pageIndex); } if (page.asDictionary() != null) { return (PDPage) PDPageNode.META.createFromCos(page.asDictionary()); } return null; }
/** * set an encoding for the font * * @param newFontEncoding the new encoding to use */ public void setEncoding(Encoding newFontEncoding) { cachedEncoding = newFontEncoding; if (newFontEncoding != null) { COSObject ref = cachedEncoding.cosGetObject(); if (ref == null || ref.isNull()) { cosRemoveField(DK_Encoding); } else { cosSetField(DK_Encoding, ref); } } else { cosRemoveField(DK_Encoding); } }
public File getFile() { File file = null; COSObject cosFileSpec = cosGetField(DK_F); if (cosFileSpec instanceof COSString) { String fileSpec = cosFileSpec.stringValue(); file = new File(PDFFileTools.toOSPath(fileSpec)); } else if (cosFileSpec instanceof COSDictionary) { PDFileSpecification fileSpec = (PDFileSpecification) PDFileSpecification.META.createFromCos(cosFileSpec); String fileString = fileSpec.getFile(); if (fileString != null) { file = new File(PDFFileTools.toOSPath(fileString)); } } return file; }
/** * Create the encoding for the font. The encoding is specified either "by default", as a known * encoding name or a completely user defined difference encoding. * * <p>This is redefined for composite fonts, which use a different implementation. * * @return The encoding object for the font. * @throws IllegalArgumentException When the encoding defined in the font is not supported. */ protected Encoding createEncoding() { COSObject encoding = cosGetField(PDFont.DK_Encoding); if (encoding.isNull()) { return createDefaultEncoding(); } if (encoding instanceof COSName) { try { return Encoding.createNamed((COSName) encoding); } catch (Exception e) { // found PDF where the base name was /NULL... return createDefaultEncoding(); } } if (encoding instanceof COSDictionary) { return DifferenceEncoding.create((COSDictionary) encoding, this); } throw new IllegalArgumentException("encoding not supported"); }
/** * Answer true if this font's program is embedded within the document. * * @return Answer true if this font's program is embedded within the document. */ public boolean isEmbedded() { // shortcut for builtin fonts COSObject base = cosGetField(DK_FontDescriptor); if (base.isNull() && !(this instanceof PDFontType0)) { return false; } if (getFontDescriptor() == null) { return false; } if (getFontDescriptor().getFontFile() != null) { return true; } if (getFontDescriptor().getFontFile2() != null) { return true; } if (getFontDescriptor().getFontFile3() != null) { return true; } return false; }
/* * (non-Javadoc) * * @see * de.intarsys.pdf.cos.COSBasedObject.MetaClass#doDetermineClass(de. * intarsys.pdf.cos.COSObject) */ @Override protected COSBasedObject.MetaClass doDetermineClass(COSObject object) { COSDictionary dict; dict = object.asDictionary(); if (dict == null) { throw new IllegalArgumentException("font object is not a COSDictionary as required"); } COSName type = dict.get(DK_Type).asName(); if (type == null) { throw new IllegalArgumentException("Dictionary has no type"); } if (!type.equals(CN_Type_Font)) { throw new IllegalArgumentException("type <" + type + "> is not a valid font type"); } COSName subtype = dict.get(DK_Subtype).asName(); if (subtype == null) { throw new IllegalArgumentException("font not identified by subtype"); } if (subtype.equals(CN_Subtype_Type1)) { return PDFontType1.META; } else if (subtype.equals(CN_Subtype_TrueType)) { if (dict.get(DK_FontDescriptor).isNull()) { /* * treat as if Type1 was specified, because that's probably * what the creator meant; further processing would yield * wrong results anyway as FontDescriptor is a required * entry for TrueType fonts */ return PDFontType1.META; } return PDFontTrueType.META; } else if (subtype.equals(CN_Subtype_MMType1)) { return PDFontMMType1.META; } else if (subtype.equals(CN_Subtype_Type0)) { return PDFontType0.META; } else if (subtype.equals(CN_Subtype_Type3)) { return PDFontType3.META; } else if (subtype.equals(CN_Subtype_CIDFontType0)) { return CIDFontType0.META; } else if (subtype.equals(CN_Subtype_CIDFontType2)) { return CIDFontType2.META; } throw new IllegalArgumentException("font subtype <" + subtype + "> not supported"); }
public COSObject cosGetData() { COSObject data = cosGetField(DK_Data); return data.isNull() ? null : data; }