/** * Checks if attribute dict contains MCID key and returns it's value. * * @return MCID value or value if it is not present. */ public Long getMCID() { COSObject mcid = getAttribute(ASAtom.MCID, COSObjType.COS_INTEGER); return mcid == null ? null : mcid.getInteger(); }
private long getLongFromUserDict(String key) { COSObject number = userDict.get(ASAtom.getASAtom(key)); if (number == null) { return 0; } Long res = number.getInteger(); return res == null ? 0 : res; } }
public Long getInteger() { return getDirect().getInteger(); }
public Long getIntegerKey(final ASAtom key) { return getKey(key).getInteger(); }
private void index() throws PostScriptException { try { COSObject n = getTopNumber(); if (operandStack.size() >= n.getInteger().intValue()) { COSObject toCopy = operandStack.get(operandStack.size() - n.getInteger().intValue() - 1); operandStack.push(psCopyObject(toCopy)); } else { throw new PostScriptException("Stack does not contain " + n.getInteger() + " elements"); } } catch (PostScriptException e) { throw new PostScriptException("Can't execute index operator", e); } }
private void copy() throws PostScriptException { try { COSObject n = getTopNumber(); int size = operandStack.size(); if (size >= n.getInteger()) { List<COSObject> toCopy = operandStack.subList(size - n.getInteger().intValue(), size); List<COSObject> toAppend = new ArrayList<>(toCopy.size()); for (COSObject object : toCopy) { toAppend.add(psCopyObject(object)); } operandStack.addAll(toAppend); } else { throw new PostScriptException("Stack does not contain " + n.getInteger() + " elements to copy"); } } catch (PostScriptException e) { throw new PostScriptException("Can't execute copy operator", e); } }
private void roll() throws PostScriptException { // TODO: check this try { COSObject[] topTwoNumbers = getTopTwoNumbers(); int j = topTwoNumbers[0].getInteger().intValue(); int n = topTwoNumbers[1].getInteger().intValue(); int size = operandStack.size(); if (size >= n) { List<COSObject> lastElements = operandStack.subList(size - n, size); int splitPoint = n - 1 - ((j - 1) % n); operandStack.addAll(lastElements.subList(splitPoint - 1, size)); operandStack.addAll(lastElements.subList(0, splitPoint - 1)); } else { throw new PostScriptException("Stack has less than n elements"); } } catch (PostScriptException e) { throw new PostScriptException("Can't execute roll operator", e); } }
private void array() throws PostScriptException { try { COSObject arraySize = getTopNumber(); this.operandStack.push(COSArray.construct(arraySize.getInteger().intValue())); } catch (PostScriptException e) { throw new PostScriptException("Can't execute array operator", e); } }
public Long getHival() { return getObject().at(2).getInteger(); }
private void put() throws PostScriptException { try { if (operandStack.size() >= 3) { COSObject toPut = operandStack.pop(); COSObject index = getTopNumber(); COSObject array = operandStack.pop(); if (array.getType() == COSObjType.COS_ARRAY) { array.remove(index.getInteger().intValue()); array.insert(index.getInteger().intValue(), toPut); return; } } throw new PostScriptException("Problem with stack"); } catch (PostScriptException e) { throw new PostScriptException("Can't execute put operator", e); } }
private void opFor() throws PostScriptException { try { if (operandStack.empty()) { throw new PostScriptException("Problem with stack"); } COSObject proc = operandStack.pop(); if (!(proc instanceof PSProcedure)) { throw new PostScriptException("Object is not a procedure"); } COSObject limit = getTopNumber(); COSObject increment = getTopNumber(); COSObject initial = getTopNumber(); for (long i = initial.getInteger(); i <= limit.getInteger(); i += increment.getInteger()) { operandStack.push(COSInteger.construct(i)); ((PSProcedure) proc).executeProcedure(operandStack, userDict); } } catch (PostScriptException e) { throw new PostScriptException("Can't execute for operator", e); } }
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); } } }
/** * @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; }
@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; } } }
/** * Constructor from a COSObject. * * @param w is W array from CIDFont dictionary. */ public CIDWArray(COSArray w) { singleMappings = new HashMap<>(); ranges = new ArrayList<>(); if (w != null) { for (int i = 0; i < w.size().intValue(); ++i) { int cidBegin = w.at(i++).getInteger().intValue(); COSObject obj = w.at(i); if (obj.getType() == COSObjType.COS_INTEGER) { int cidEnd = obj.getInteger().intValue(); Double width = w.at(++i).getReal(); if (width == null) { LOGGER.log(Level.FINE, "Unexpected end of W array in CID font"); return; } this.ranges.add(new CIDWArrayRange(cidBegin, cidEnd, width.doubleValue())); } else if (obj.getType() == COSObjType.COS_ARRAY) { addSingleMappings(cidBegin, (COSArray) obj.getDirectBase()); } } } }
for (COSObject obj : differences) { if (obj.getType() == COSObjType.COS_INTEGER) { diffIndex = obj.getInteger().intValue(); } else if (obj.getType() == COSObjType.COS_NAME && diffIndex != -1) { res.put(Integer.valueOf(diffIndex++), obj.getString());
/** * @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; }
/** * @return int[] representation of ByteRange entry. */ public int[] getByteRange() { COSObject cosByteRange = this.getKey(ASAtom.BYTERANGE); if (cosByteRange.getType() == COSObjType.COS_ARRAY) { COSArray array = (COSArray) cosByteRange.getDirectBase(); if (array.size() >= 4) { int[] res = new int[4]; for (int i = 0; i < 4; ++i) { res[i] = array.at(i).getInteger().intValue(); } return res; } } return null; }
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); }
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; } } }