private static List<COSObject> parseNames(COSObject obj) { if (obj != null && obj.getType() == COSObjType.COS_ARRAY) { List<COSObject> names = new ArrayList<>(obj.size()); for (int i = 0; i < obj.size(); ++i) { names.add(obj.at(i)); } return Collections.unmodifiableList(names); } return Collections.emptyList(); } }
public Integer size() { return getDirect().size(); }
/** * Transform array of dictionaries to list of structure elements * * @param children array of children structure elements * @return list of structure elements */ private static List<PDStructElem> getChildrenFromArray(COSObject children, Map<ASAtom, ASAtom> roleMap, boolean checkType) { if (children.size().intValue() > 0) { List<PDStructElem> list = new ArrayList<>(); for (int i = 0; i < children.size().intValue(); ++i) { COSObject elem = children.at(i); if (elem.getType() == COSObjType.COS_DICT && isStructElem(elem, checkType)) { list.add(new PDStructElem(elem, roleMap)); } } return Collections.unmodifiableList(list); } return Collections.emptyList(); }
private static List<PDSeparation> getColorants(COSObject colorantsDict) { List<PDSeparation> list = new ArrayList<>(colorantsDict.size().intValue()); for (COSObject value : colorantsDict.getValues()) { org.verapdf.pd.colors.PDColorSpace colorSpace = org.verapdf.factory.colors.ColorSpaceFactory .getColorSpace(value); if (ASAtom.SEPARATION.equals(colorSpace.getType())) { list.add((GFPDSeparation) ColorSpaceFactory.getColorSpace(colorSpace)); } } return Collections.unmodifiableList(list); } }
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 double[] getRealArray(COSObject array, int estimatedSize, String arrayName, boolean checkSize) { if (arrayName == null) { throw new IllegalArgumentException("Array object can not be null"); } if (array != null && array.getType() == COSObjType.COS_ARRAY) { int size = array.size().intValue(); if (checkSize && size != estimatedSize) { LOGGER.log(Level.FINE, arrayName + " array doesn't consist of " + estimatedSize + " elements"); } double[] res = new double[size]; for (int i = 0; i < size; ++i) { COSObject number = array.at(i); if (number == null || number.getReal() == null) { LOGGER.log(Level.FINE, arrayName + " array contains non number value"); return null; } res[i] = number.getReal().doubleValue(); } return res; } return null; } }
private List<PDSeparation> getColorants() { COSObject attributes = ((org.verapdf.pd.colors.PDDeviceN) this.simplePDObject).getAttributes(); if (attributes != null && attributes.getType() == COSObjType.COS_DICT) { COSObject colorantsDict = attributes.getKey(ASAtom.COLORANTS); if (colorantsDict.getType() == COSObjType.COS_DICT && colorantsDict.size().intValue() > 0) { return GFPDDeviceN.getColorants(colorantsDict); } } return Collections.emptyList(); }
/** * @return the list of number tree nodes that are kids of this node or null * if no kids are present. */ public List<PDNumberTreeNode> getKids() { COSObject kids = this.getKey(ASAtom.KIDS); if (kids != null && !kids.empty() && kids.getType() == COSObjType.COS_ARRAY) { List<PDNumberTreeNode> res = new ArrayList<>(kids.size()); for (COSObject obj : (COSArray) kids.get()) { res.add(new PDNumberTreeNode(obj)); } return Collections.unmodifiableList(res); } return null; }
protected void updateFromObject() { COSObject filters = getObject(); if(filters.getType().equals(COSObjType.COS_ARRAY)) { int size = filters.size(); this.entries.clear(); for (int i = 0; i < size; i++) { this.entries.add(filters.at(i).getName()); } } else if (filters.getType().equals(COSObjType.COS_NAME)) { this.entries.clear(); this.entries.add(filters.getName()); } }
public List<ASAtom> getFilters() { COSObject filters = getKey(ASAtom.FILTER); if (filters != null) { List<ASAtom> res = new ArrayList<>(); switch (filters.getType()) { case COS_NAME: res.add(filters.getName()); break; case COS_ARRAY: for (int i = 0; i < filters.size().intValue(); ++i) { COSObject elem = filters.at(i); if (elem.getType() == COSObjType.COS_NAME) { res.add(elem.getName()); } else { LOGGER.log(Level.SEVERE, "Filter array contain non COSName element"); } } break; } return Collections.unmodifiableList(res); } return Collections.emptyList(); }
private static List<CosNumber> getNumbersFromArray(COSObject array) { if (array.size().intValue() > 0) { List<CosNumber> color = new ArrayList<>(); for (COSObject colorValue : (COSArray) array.getDirectBase()) { if (colorValue.getType().isNumber()) { color.add(GFCosNumber.fromPDFParserNumber(colorValue.get())); } } return Collections.unmodifiableList(color); } else { // Array size is 0 but it is present List<CosNumber> res = new ArrayList<>(1); res.add(GFCosNumber.fromPDFParserNumber(COSInteger.construct(0).getDirectBase())); return res; } }
private Map<String, COSObject> parseNames() { COSObject names = getKey(ASAtom.NAMES); if (names != null && names.getType() == COSObjType.COS_ARRAY) { Map<String, COSObject> res = new LinkedHashMap<>(); for (int i = 0; i < names.size(); i+=2) { COSObject keyObj = names.at(i); String key = keyObj == null ? null : keyObj.getString(); if (key != null) { COSObject value = names.at(i+1); res.put(key, value); } } return res; } return Collections.emptyMap(); } }
public static StructureType createStructureType(COSObject object) { if (object == null) { throw new IllegalArgumentException("Argument object can not be null"); } COSObjType objType = object.getType(); if (objType == COSObjType.COS_NAME) { return createStructureType(object, null); } else if (objType == COSObjType.COS_ARRAY && object.size() >= 2) { return createStructureType(object.at(0), object.at(1)); } return null; }
public COSObject getStructureElement(PDNumberTreeNode parentTreeRoot, Long mcid) { if (structParent != null) { return parentTreeRoot.getObject(structParent); } if (mcid != null && structParents != null) { COSObject parents = parentTreeRoot.getObject(structParents); if (parents != null && !parents.empty() && parents.getType() == COSObjType.COS_ARRAY && parents.size() > mcid) { return parents.at(mcid.intValue()); } } return null; }
private void processCOSArrayInOrder(COSObject array, Set<String> groupNames) { for (int i = 0; i < array.size().intValue(); i++) { COSObject element = array.at(i); if (element.getType() == COSObjType.COS_ARRAY) { processCOSArrayInOrder(element, groupNames); } else if (element.getType() == COSObjType.COS_DICT) { processCOSDictionaryInOrder(element, groupNames); } } }
public List<PDOutputIntent> getOutputIntents() { COSObject base = getKey(ASAtom.OUTPUT_INTENTS); if (base != null && base.getType() == COSObjType.COS_ARRAY) { if (base.isIndirect()) { base = base.getDirect(); } List<PDOutputIntent> result = new ArrayList<>(base.size()); for (COSObject obj : (COSArray) base.getDirectBase()) { if (obj != null && obj.getType().isDictionaryBased()) { result.add(new PDOutputIntent(obj)); } } return Collections.unmodifiableList(result); } return Collections.emptyList(); }
private void length() throws PostScriptException { COSObject topObject = popTopObject(); if (topObject.getType().isDictionaryBased() || topObject.getType() == COSObjType.COS_ARRAY) { operandStack.push(COSInteger.construct(topObject.size())); return; } throw new PostScriptException("Can't execute length operator"); }
/** * @return map from numbers to objects that is represented by this node or * null if nums are not present. * TODO: test method */ public Map<Long, COSObject> getNums() { COSObject nums = this.getKey(ASAtom.NUMS); if (nums != null && !nums.empty() && nums.getType() == COSObjType.COS_ARRAY) { Map<Long, COSObject> res = new HashMap<>(); for (int i = 0; i < nums.size() - 1; i += 2) { // size - 1 checks case with odd amount of entries in array COSObject key = nums.at(i); if (key.getType() == COSObjType.COS_INTEGER) { COSObject value = nums.at(i + 1); res.put(key.getInteger(), value); } } return Collections.unmodifiableMap(res); } return null; }
/** * Constructor from type 1 font dictionary. * @param dictionary is type 1 font dictionary. */ public PDType1Font(COSDictionary dictionary) { super(dictionary); if (isNameStandard() && this.fontDescriptor.getObject().size() == 0) { fontMetrics = StandardFontMetricsFactory.getFontMetrics(this.getName()); this.fontDescriptor = PDFontDescriptor.getDescriptorFromMetrics(fontMetrics); } }
/** * @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; }