Search in sources :

Example 11 with COSFloat

use of com.tom_roush.pdfbox.cos.COSFloat in project PdfBox-Android by TomRoush.

the class COSDictionaryMap method convertBasicTypesToMap.

/**
 * This will take a COS dictionary and convert it into COSDictionaryMap.  All cos
 * objects will be converted to their primitive form.
 *
 * @param map The COS mappings.
 * @return A standard java map.
 * @throws IOException If there is an error during the conversion.
 */
public static COSDictionaryMap<String, Object> convertBasicTypesToMap(COSDictionary map) throws IOException {
    COSDictionaryMap<String, Object> retval = null;
    if (map != null) {
        Map<String, Object> actualMap = new HashMap<String, Object>();
        for (COSName key : map.keySet()) {
            COSBase cosObj = map.getDictionaryObject(key);
            Object actualObject = null;
            if (cosObj instanceof COSString) {
                actualObject = ((COSString) cosObj).getString();
            } else if (cosObj instanceof COSInteger) {
                actualObject = ((COSInteger) cosObj).intValue();
            } else if (cosObj instanceof COSName) {
                actualObject = ((COSName) cosObj).getName();
            } else if (cosObj instanceof COSFloat) {
                actualObject = ((COSFloat) cosObj).floatValue();
            } else if (cosObj instanceof COSBoolean) {
                actualObject = ((COSBoolean) cosObj).getValue() ? Boolean.TRUE : Boolean.FALSE;
            } else {
                throw new IOException("Error:unknown type of object to convert:" + cosObj);
            }
            actualMap.put(key.getName(), actualObject);
        }
        retval = new COSDictionaryMap<String, Object>(actualMap, map);
    }
    return retval;
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSName(com.tom_roush.pdfbox.cos.COSName) HashMap(java.util.HashMap) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString) IOException(java.io.IOException) COSString(com.tom_roush.pdfbox.cos.COSString) COSBoolean(com.tom_roush.pdfbox.cos.COSBoolean) COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Example 12 with COSFloat

use of com.tom_roush.pdfbox.cos.COSFloat in project PdfBox-Android by TomRoush.

the class PDOutlineItem method getTextColor.

/**
 * Get the RGB text color of this node.  Default is black and this method
 * will never return null.
 *
 * @return The structure element of this node.
 */
public PDColor getTextColor() {
    COSArray csValues = (COSArray) getCOSObject().getDictionaryObject(COSName.C);
    if (csValues == null) {
        csValues = new COSArray();
        csValues.growToSize(3, new COSFloat(0));
        getCOSObject().setItem(COSName.C, csValues);
    }
    return new PDColor(csValues, PDDeviceRGB.INSTANCE);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSFloat(com.tom_roush.pdfbox.cos.COSFloat) PDColor(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)

Example 13 with COSFloat

use of com.tom_roush.pdfbox.cos.COSFloat in project PdfBox-Android by TomRoush.

the class PDStandardAttributeObject method setArrayOfNumber.

/**
 * Sets an array of float numbers.
 *
 * @param name the attribute name
 * @param values the float numbers
 */
protected void setArrayOfNumber(String name, float[] values) {
    COSArray array = new COSArray();
    for (float value : values) {
        array.add(new COSFloat(value));
    }
    COSBase oldBase = this.getCOSObject().getDictionaryObject(name);
    this.getCOSObject().setItem(name, array);
    COSBase newBase = this.getCOSObject().getDictionaryObject(name);
    this.potentiallyNotifyChanged(oldBase, newBase);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Example 14 with COSFloat

use of com.tom_roush.pdfbox.cos.COSFloat in project PdfBox-Android by TomRoush.

the class Matrix method toCOSArray.

/**
 * Returns a COS array which represent the geometric relevant
 * components of the matrix. The last column of the matrix is ignored,
 * only the first two columns are returned. This is analog to the
 * Matrix(COSArray) constructor.
 */
public COSArray toCOSArray() {
    COSArray array = new COSArray();
    array.add(new COSFloat(single[0]));
    array.add(new COSFloat(single[1]));
    array.add(new COSFloat(single[3]));
    array.add(new COSFloat(single[4]));
    array.add(new COSFloat(single[6]));
    array.add(new COSFloat(single[7]));
    return array;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Example 15 with COSFloat

use of com.tom_roush.pdfbox.cos.COSFloat in project PdfBox-Android by TomRoush.

the class PDAbstractPattern method setMatrix.

/**
 * Sets the optional Matrix entry for the Pattern.
 * @param transform the transformation matrix
 */
public void setMatrix(AffineTransform transform) {
    COSArray matrix = new COSArray();
    double[] values = new double[6];
    transform.getMatrix(values);
    for (double v : values) {
        matrix.add(new COSFloat((float) v));
    }
    getCOSObject().setItem(COSName.MATRIX, matrix);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Aggregations

COSFloat (com.tom_roush.pdfbox.cos.COSFloat)20 COSArray (com.tom_roush.pdfbox.cos.COSArray)16 COSBase (com.tom_roush.pdfbox.cos.COSBase)5 COSBoolean (com.tom_roush.pdfbox.cos.COSBoolean)2 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)2 COSName (com.tom_roush.pdfbox.cos.COSName)2 COSString (com.tom_roush.pdfbox.cos.COSString)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)1 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)1 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)1 PDColor (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1