private void initializeContents(final COSObject pageDict) { COSObject contents = pageDict.getKey(ASAtom.CONTENTS); if (!contents.empty() && contents.getType() == COSObjType.COS_STREAM) { this.content = new PDPageContentStream(contents); } else if (!contents.empty() && contents.getType() == COSObjType.COS_ARRAY) { try { this.content = new PDPageContentStream(COSStream.concatenateStreams((COSArray) contents.getDirectBase())); } catch (IOException e) { this.content = new PDPageContentStream(contents.at(0)); } } }
private String getStringKey(ASAtom key) { if (info != null && info.getType() == COSObjType.COS_DICT) { return info.getStringKey(key); } return null; }
@Override public Boolean getNeedAppearances() { COSObject cosNeedAppearances = ((org.verapdf.pd.form.PDAcroForm) simplePDObject).getNeedAppearances(); if (cosNeedAppearances.getType() == COSObjType.COS_BOOLEAN) { return cosNeedAppearances.getBoolean(); } else if (cosNeedAppearances.empty()) { return null; } else { LOGGER.log(Level.SEVERE, "Value of NeedAppearances key is not a boolean. Ignoring NeedAppearances"); // value that fails the check return true; } }
private COSObject getEmbeddedFile() { if (embFile != null && !embFile.empty()){ COSObject efDict = embFile.getKey(ASAtom.EF); if (efDict != null && efDict.getType() == COSObjType.COS_DICT) { COSObject file = efDict.getKey(ASAtom.F); if (file != null && file.getType() == COSObjType.COS_STREAM) { return file; } } } return null; }
@Override public String getValue() { COSObject value = this.formField.getV(); if (value == null || value.empty()) { return null; } else { COSObjType type = value.getType(); switch (type) { case COS_BOOLEAN: return String.valueOf(value.getBoolean()); case COS_STRING: case COS_NAME: return value.getString(); case COS_INTEGER: return String.valueOf(value.getInteger()); case COS_REAL: return String.valueOf(value.getReal()); default: return valueMap.containsKey(type) ? valueMap.get(type) : null; } } }
public COSStream getPS() { COSObject ps = getKey(ASAtom.PS); if (ps != null && ps.getType() == COSObjType.COS_STREAM) { return (COSStream) ps.getDirectBase(); } return null; }
/** * @return array of two numbers representing limits of this node or null if * proper limits array is not present. */ public long[] getLimitsArray() { COSObject limits = this.getKey(ASAtom.LIMITS); if (limits != null && !limits.empty() && limits.getType() == COSObjType.COS_ARRAY && limits.size() >= 2) { long[] res = new long[2]; res[0] = limits.at(0).getInteger(); res[1] = limits.at(1).getInteger(); return res; } return null; }
private void addLabelsFromArray(COSArray nums) { for (int i = 0; i < nums.size(); i+=2) { COSObject cosKey = nums.at(i); Long key = cosKey == null ? null : cosKey.getInteger(); COSObject cosValue = nums.at(i+1); if (key != null && cosValue != null && !cosValue.empty() && cosValue.getType() == COSObjType.COS_DICT) { PageLabelDictionary pageLabelDictionary = new PageLabelDictionary((COSDictionary) cosValue.getDirectBase(), key.intValue()); this.labelsMap.put(key.intValue(), pageLabelDictionary); } } }
private static COSObject psCopyObject(COSObject toCopy) { switch (toCopy.getType()) { case COS_BOOLEAN: return COSBoolean.construct(toCopy.getBoolean()); case COS_INTEGER: return COSInteger.construct(toCopy.getInteger()); case COS_NAME: return COSName.construct(toCopy.getName()); case COS_REAL: return COSReal.construct(toCopy.getReal()); default: // In all other cases copied object share the same memory location return toCopy; } } }
public Long getRotation() { COSObject current = getObject(); while (current != null && current.getType().isDictionaryBased()) { COSObject object = current.getKey(ASAtom.ROTATE); if (object != null && !object.empty()) { if (object.getType() == COSObjType.COS_INTEGER) { return object.getInteger(); } else { return Long.valueOf(0); } } else { current = current.getKey(ASAtom.PARENT); } } return Long.valueOf(0); }
public PageLabels getPageLabels() { COSObject labelsTree = getKey(ASAtom.PAGE_LABELS); if (labelsTree != null && !labelsTree.empty() && labelsTree.getType() == COSObjType.COS_DICT) { return new PageLabels((COSDictionary) labelsTree.getDirectBase()); } return null; }
public Map<ASAtom, ASAtom> getRoleMap() { COSObject roleMap = getKey(ASAtom.ROLE_MAP); if (roleMap != null && roleMap.getType() == COSObjType.COS_DICT && roleMap.size() > 0) { Map<ASAtom, ASAtom> res = new HashMap<>(); Set<ASAtom> keys = roleMap.getKeySet(); for (ASAtom key : keys) { ASAtom value = roleMap.getNameKey(key); if (value != null) { res.put(key, value); } } return Collections.unmodifiableMap(res); } return Collections.emptyMap(); }
private static boolean areColorantsPresent(org.verapdf.pd.colors.PDDeviceN simplePDObject) { COSObject attributes = simplePDObject.getAttributes(); if (attributes != null && attributes.getType() == COSObjType.COS_DICT) { COSObject colorantsDict = attributes.getKey(ASAtom.COLORANTS); List<COSObject> colorantsArray = simplePDObject.getNames(); Set<ASAtom> componentNames = new TreeSet<>(); if (colorantsDict != null && colorantsDict.getType() == COSObjType.COS_DICT) { componentNames.addAll(colorantsDict.getKeySet()); } COSArray components = getProcessComponents(attributes); if (components != null) { for (COSObject component : components) { if (component.getType() == COSObjType.COS_NAME) { componentNames.add(component.getName()); } } } return GFPDDeviceN.areColorantsPresent(componentNames, colorantsArray); } return false; }
public Map<ASAtom, PDAppearanceStream> getSubDictionary() { if (!isSubDictionary()) { throw new IllegalStateException("Current appearance entry is a stream"); } Map<ASAtom, PDAppearanceStream> res = new HashMap<>(); for (ASAtom key : getObject().getKeySet()) { COSObject obj = getKey(key); if (obj.isIndirect()) { obj = obj.getDirect(); } if (obj != null && obj.getType() == COSObjType.COS_STREAM) { res.put(key, new PDAppearanceStream(obj)); } } return Collections.unmodifiableMap(res); }
private static void addObjectWithTypeKeyCheck(List<COSObject> objects, COSObject obj, ASAtom type) { if (obj != null && !obj.empty() && obj.getType().isDictionaryBased()) { ASAtom actualType = obj.getNameKey(ASAtom.TYPE); if (actualType == type) { objects.add(obj); } } }
private static void registerDictionaryAFKeys(COSObject dictionary) { if (dictionary == null || !(dictionary.getType().isDictionaryBased())) { return; } COSObject af = dictionary.getKey(ASAtom.AF); if (af != null && af.getType() == COSObjType.COS_ARRAY) { registerFileSpecificationKeys((COSArray) af.getDirectBase()); } }
private Map<ASAtom, PDCryptFilter> getCryptFilters() { HashMap<ASAtom, PDCryptFilter> res = new HashMap<>(); COSObject cf = getKey(ASAtom.CF); if (cf == null || cf.getType() != COSObjType.COS_DICT) { return res; } Set<ASAtom> filters = cf.getKeySet(); for (ASAtom filterName : filters) { res.put(filterName, new PDCryptFilter(cf.getKey(filterName))); } return res; }
@Override public Double getca() { COSObject ca = ((org.verapdf.pd.PDExtGState) simplePDObject).getCA_NS(); if (ca.getType().isNumber()) { return ca.getReal(); } else if (ca.empty()) { return null; } else { LOGGER.log(Level.SEVERE, "Value of ca key is not a number. Ignoring ca"); return 2.0; // check is failed } }