/** * 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; }
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); } } }
/* * (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"); }