private void counttomark() { // check behaviour in case of missing mark long res = 0; for (int i = operandStack.size() - 1; i >= 0; --i) { if (operandStack.get(i) == PSStackMark.getInstance() || i == 0) { operandStack.push(COSInteger.construct(res)); return; } res++; } }
public void visitFromInteger(COSInteger obj) { this.copy.assign(COSInteger.construct(obj.get())); }
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 void executeOperatorOnOneTopNumber(String operator) throws PostScriptException { try { COSObject argument = getTopNumber(); COSObject res; switch (operator) { case "abs": res = COSReal.construct(Math.abs(argument.getReal())); break; case "neg": res = COSReal.construct(-argument.getReal()); break; case "ceiling": res = COSInteger.construct((long) Math.ceil(argument.getReal())); break; case "floor": res = COSInteger.construct((long) Math.floor(argument.getReal())); break; case "round": res = COSInteger.construct(Math.round(argument.getReal())); break; default: throw new PostScriptException("Unknown operator " + operator); } operandStack.push(res); } catch (PostScriptException e) { throw new PostScriptException("Can't execute " + operator + " operator", e); } }
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"); }
/** * This method makes sure that Index array is correctly initialized. * * @throws IOException */ private void initializeIndex() throws IOException { index = (COSArray) xrefCOSStream.getKey(ASAtom.INDEX).getDirectBase(); if (index == null) { COSObject[] defaultIndex = new COSObject[2]; defaultIndex[0] = COSInteger.construct(0); defaultIndex[1] = xrefCOSStream.getKey(ASAtom.SIZE); index = (COSArray) COSArray.construct(2, defaultIndex).getDirectBase(); } else if (index.size() % 2 != 0) { throw new IOException("Index array in xref stream has odd amount of elements."); } }
this.integers.add(Long.valueOf(token.integer)); if (this.integers.size() == 3) { COSObject result = COSInteger.construct(this.integers.peek().longValue()); this.integers.remove(); return result; COSObject result = COSInteger.construct(this.integers.peek().longValue()); this.integers.remove(); while (!this.integers.isEmpty()) { this.objects.add(COSInteger.construct(this.integers.peek().longValue())); this.integers.remove();
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); } }
this.integers.add(Long.valueOf(token.integer)); if (this.integers.size() == 3) { COSObject result = COSInteger.construct(this.integers.peek().longValue()); this.integers.remove(); return result; COSObject result = COSInteger.construct(this.integers.peek().longValue()); this.integers.remove(); while (!this.integers.isEmpty()) { this.objects.add(COSInteger.construct(this.integers.peek().longValue())); this.integers.remove();
break; case "count": COSObject stackSize = COSInteger.construct(this.operandStack.size()); this.operandStack.push(stackSize); break;
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; } } }
protected void updateToObject() { COSObject branch = getObject(); COSObject kids = COSArray.construct(); for (PDPageTreeNode node : this.children) { kids.add(node.getObject()); } branch.setKey(ASAtom.KIDS, kids); COSObject count = COSInteger.construct(this.leafCount); branch.setKey(ASAtom.COUNT, count); PDPageTreeBranch parentNode = getParent(); if (parentNode != null) { branch.setKey(ASAtom.PARENT, parentNode.getObject()); } }
result = COSReal.construct(token.real); } else if (token.type.equals(Token.Type.TT_INTEGER)) { result = COSInteger.construct(token.integer);