private static Double getNumber(COSObject object, double defaultValue) { if (object != null) { return object.getReal(); } return defaultValue; } }
public Double getRealKey(final ASAtom key) { return getKey(key).getReal(); }
public Double getReal() { return getDirect().getReal(); }
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; } }
public void copyPropertiesFormExtGState(PDExtGState extGState) { if (extGState != null) { COSObject smask = extGState.getCOSSMask(); if (smask != null) { this.sMask = smask; } COSObject bm = extGState.getCOSBM(); if (bm != null) { this.bm = bm; } Double ca_ns = extGState.getCA_NS().getReal(); if (ca_ns != null) { this.ca_ns = ca_ns.floatValue(); } Double ca = extGState.getCA().getReal(); if (ca != null) { this.ca = ca.floatValue(); } } }
public double[] getColor() { COSObject arr = getKey(ASAtom.C); if (arr != null && arr.getType() == COSObjType.COS_ARRAY) { if (arr.size().intValue() == 3) { Double redValue = arr.at(0).getReal(); Double greenValue = arr.at(1).getReal(); Double blueValue = arr.at(2).getReal(); if (redValue == null || greenValue == null || blueValue == null) { LOGGER.log(Level.FINE, "Outline's color contains non number value"); return null; } float red = redValue.floatValue(); float green = greenValue.floatValue(); float blue = blueValue.floatValue(); if (red < 0 || red > 1 || green < 0 || green > 1 || blue < 0 || blue > 1) { LOGGER.log(Level.FINE, "Outline's color contains wrong value"); return null; } return new double[]{red, green, blue}; } LOGGER.log(Level.FINE, "Outline's color contains not three elements"); return null; } return new double[]{0.0, 0.0, 0.0}; }
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 addSingleMappings(int cidBegin, COSArray arr) { for (int i = 0; i < arr.size().intValue(); i++) { if (!arr.at(i).getType().isNumber()) { LOGGER.log(Level.SEVERE, "W array in CIDFont has invalid entry."); continue; } this.singleMappings.put(Integer.valueOf(cidBegin + i), arr.at(i).getReal()); } }
/** * @return range array value for ICC profile, described in profile * dictionary */ public double[] getRange() { COSObject rangeObject = getObject().getKey(ASAtom.RANGE); if (rangeObject != null && rangeObject.getType() == COSObjType.COS_ARRAY) { int size = rangeObject.size().intValue(); Long estimatedSize = getNumberOfColorants(); if (estimatedSize != null && size != estimatedSize.intValue()*2) { LOGGER.log(Level.FINE, "Range array doesn't consist of " + estimatedSize.intValue()*2 + " elements"); } double[] res = new double[size]; for (int i = 0; i < size; ++i) { COSObject number = rangeObject.at(i); if (number == null || number.getReal() == null) { LOGGER.log(Level.FINE, "Range array contains non number value"); return null; } res[i] = number.getReal().doubleValue(); } return res; } return null; }
@Override public Double getCA() { COSObject ca = ((org.verapdf.pd.PDExtGState) simplePDObject).getCA(); 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 } }
/** * {@inheritDoc} */ @Override public Double getDefaultWidth() { COSObject dw = this.dictionary.getKey(ASAtom.DW); if (dw.getType().isNumber()) { return dw.getReal(); } else { return DEFAULT_CID_FONT_WIDTH; } }
@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 } }
@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; } } }
private static double[] getDoubleArrayForBox(COSArray array) { if (array == null) { return null; } double[] res = new double[4]; for (int i = 0; i < array.size(); ++i) { COSObject obj = array.at(i); if (obj.getType().isNumber()) { res[i] = obj.getReal().doubleValue(); } else { res[i] = 0; } } return res; }
/** * 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()); } } } }
/** * Gets width for glyph with given code in this font. * * @param code is code of glyph. * @return width for glyph with given code as specified in Widths array. */ public Double getWidth(int code) { if (dictionary.knownKey(ASAtom.WIDTHS).booleanValue() && dictionary.knownKey(ASAtom.FIRST_CHAR).booleanValue() && dictionary.knownKey(ASAtom.LAST_CHAR).booleanValue()) { int firstChar = dictionary.getIntegerKey(ASAtom.FIRST_CHAR).intValue(); int lastChar = dictionary.getIntegerKey(ASAtom.LAST_CHAR).intValue(); if (getWidths().size().intValue() > 0 && code >= firstChar && code <= lastChar) { return getWidths().at(code - firstChar).getReal(); } } if (fontDescriptor.knownKey(ASAtom.MISSING_WIDTH)) { return fontDescriptor.getMissingWidth(); } if (this instanceof PDType3Font) { return null; } return Double.valueOf(0); }
private double[] getFontMatrix() { COSObject fontMatrixObject = this.getObjectFromUserDict(ASAtom.getASAtom( Type1StringConstants.FONT_MATRIX_STRING)); if (fontMatrixObject != null && fontMatrixObject.getType() != COSObjType.COS_ARRAY) { double[] res = new double[6]; int pointer = 0; for (COSObject obj : ((COSArray) fontMatrixObject.get())) { if (obj.getType().isNumber()) { res[pointer++] = obj.getReal(); } } return res; } return DEFAULT_FONT_MATRIX; }
/** * @return a rectangle, expressed in the glyph coordinate system, that shall * specify the font bounding box. */ public double[] getFontBoundingBox() { if (fontBoundingBox == null) { COSBase bbox = this.getObject().getKey(ASAtom.FONT_BBOX).get(); if (bbox != null && bbox.getType() == COSObjType.COS_ARRAY && bbox.size() == 4) { double[] res = new double[4]; for (int i = 0; i < 4; ++i) { COSObject obj = bbox.at(i); if (obj.getType().isNumber()) { res[i] = obj.getReal(); } else { LOGGER.log(Level.SEVERE, "Font bounding box array for font " + fontName + " contains " + obj.getType()); return null; } } fontBoundingBox = res; } else { LOGGER.log(Level.SEVERE, "Font bounding box array for font " + fontName + " is not an array of 4 elements"); return null; } } return fontBoundingBox; }
/** * @return a rectangle, expressed in the glyph coordinate system, that shall * specify the font bounding box. */ public double[] getFontBoundingBox() { COSObject bbox = getKey(ASAtom.FONT_BBOX); if (bbox.getType() == COSObjType.COS_ARRAY || bbox.size() == 4) { double[] res = new double[4]; for (int i = 0; i < 4; ++i) { COSObject obj = bbox.at(i); if (obj.getType().isNumber()) { res[i] = obj.getReal(); } else { String fontName = getName() == null ? "" : getName(); LOGGER.log(Level.FINE, "Font bounding box array for font " + fontName + " contains " + obj.getType()); return null; } } return res; } else { String fontName = getName() == null ? "" : getName(); LOGGER.log(Level.FINE, "Font bounding box array for font " + fontName + " is not an array of 4 elements"); return null; } }
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; } } }