Search in sources :

Example 61 with COSBase

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

the class PDStructureElement method removeAttribute.

/**
 * Removes an attribute object.
 *
 * @param attributeObject the attribute object
 */
public void removeAttribute(PDAttributeObject attributeObject) {
    COSName key = COSName.A;
    COSBase a = this.getCOSObject().getDictionaryObject(key);
    if (a instanceof COSArray) {
        COSArray array = (COSArray) a;
        array.remove(attributeObject.getCOSObject());
        if ((array.size() == 2) && (array.getInt(1) == 0)) {
            this.getCOSObject().setItem(key, array.getObject(0));
        }
    } else {
        COSBase directA = a;
        if (a instanceof COSObject) {
            directA = ((COSObject) a).getObject();
        }
        if (attributeObject.getCOSObject().equals(directA)) {
            this.getCOSObject().setItem(key, null);
        }
    }
    attributeObject.setStructureElement(null);
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSObject(com.tom_roush.pdfbox.cos.COSObject) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 62 with COSBase

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

the class PDStructureElement method removeClassName.

/**
 * Removes a class name.
 *
 * @param className the class name
 */
public void removeClassName(String className) {
    if (className == null) {
        return;
    }
    COSName key = COSName.C;
    COSBase c = this.getCOSObject().getDictionaryObject(key);
    COSName name = COSName.getPDFName(className);
    if (c instanceof COSArray) {
        COSArray array = (COSArray) c;
        array.remove(name);
        if ((array.size() == 2) && (array.getInt(1) == 0)) {
            this.getCOSObject().setItem(key, array.getObject(0));
        }
    } else {
        COSBase directC = c;
        if (c instanceof COSObject) {
            directC = ((COSObject) c).getObject();
        }
        if (name.equals(directC)) {
            this.getCOSObject().setItem(key, null);
        }
    }
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSObject(com.tom_roush.pdfbox.cos.COSObject) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 63 with COSBase

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

the class PDStructureElement method addClassName.

/**
 * Adds a class name.
 *
 * @param className the class name
 */
public void addClassName(String className) {
    if (className == null) {
        return;
    }
    COSName key = COSName.C;
    COSBase c = this.getCOSObject().getDictionaryObject(key);
    COSArray array;
    if (c instanceof COSArray) {
        array = (COSArray) c;
    } else {
        array = new COSArray();
        if (c != null) {
            array.add(c);
            array.add(COSInteger.get(0));
        }
    }
    this.getCOSObject().setItem(key, array);
    array.add(COSName.getPDFName(className));
    array.add(COSInteger.get(this.getRevisionNumber()));
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 64 with COSBase

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

the class PDStructureElement method attributeChanged.

/**
 * Updates the revision number for the given attribute object.
 *
 * @param attributeObject the attribute object
 */
public void attributeChanged(PDAttributeObject attributeObject) {
    COSName key = COSName.A;
    COSBase a = this.getCOSObject().getDictionaryObject(key);
    if (a instanceof COSArray) {
        COSArray array = (COSArray) a;
        for (int i = 0; i < array.size(); i++) {
            COSBase entry = array.getObject(i);
            if (entry.equals(attributeObject.getCOSObject())) {
                COSBase next = array.get(i + 1);
                if (next instanceof COSInteger) {
                    array.set(i + 1, COSInteger.get(this.getRevisionNumber()));
                }
            }
        }
    } else {
        COSArray array = new COSArray();
        array.add(a);
        array.add(COSInteger.get(this.getRevisionNumber()));
        this.getCOSObject().setItem(key, array);
    }
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 65 with COSBase

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

the class PDFourColours method getColourByIndex.

/**
 * Gets the colour by edge index.
 *
 * @param index edge index
 * @return the colour
 */
private PDGamma getColourByIndex(int index) {
    PDGamma retval = null;
    COSBase item = this.array.getObject(index);
    if (item instanceof COSArray) {
        retval = new PDGamma((COSArray) item);
    }
    return retval;
}
Also used : PDGamma(com.tom_roush.pdfbox.pdmodel.graphics.color.PDGamma) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Aggregations

COSBase (com.tom_roush.pdfbox.cos.COSBase)215 COSArray (com.tom_roush.pdfbox.cos.COSArray)108 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)68 COSName (com.tom_roush.pdfbox.cos.COSName)50 COSObject (com.tom_roush.pdfbox.cos.COSObject)42 IOException (java.io.IOException)34 COSString (com.tom_roush.pdfbox.cos.COSString)33 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)29 ArrayList (java.util.ArrayList)29 COSStream (com.tom_roush.pdfbox.cos.COSStream)20 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)14 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)11 HashMap (java.util.HashMap)11 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)10 Map (java.util.Map)10 List (java.util.List)9 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)8 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)7 COSObjectKey (com.tom_roush.pdfbox.cos.COSObjectKey)7 PDFStreamParser (com.tom_roush.pdfbox.pdfparser.PDFStreamParser)6