use of com.tom_roush.pdfbox.cos.COSName 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);
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDStructureElement method setAttributes.
/**
* Sets the attributes together with their revision numbers (A).
*
* @param attributes the attributes
*/
public void setAttributes(Revisions<PDAttributeObject> attributes) {
COSName key = COSName.A;
if ((attributes.size() == 1) && (attributes.getRevisionNumber(0) == 0)) {
PDAttributeObject attributeObject = attributes.getObject(0);
attributeObject.setStructureElement(this);
this.getCOSObject().setItem(key, attributeObject);
return;
}
COSArray array = new COSArray();
for (int i = 0; i < attributes.size(); i++) {
PDAttributeObject attributeObject = attributes.getObject(i);
attributeObject.setStructureElement(this);
int revisionNumber = attributes.getRevisionNumber(i);
if (revisionNumber < 0) {
throw new IllegalArgumentException("The revision number shall be > -1");
}
array.add(attributeObject);
array.add(COSInteger.get(revisionNumber));
}
this.getCOSObject().setItem(key, array);
}
use of com.tom_roush.pdfbox.cos.COSName 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);
}
}
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDStructureElement method setClassNames.
/**
* Sets the class names together with their revision numbers (C).
*
* @param classNames the class names
*/
public void setClassNames(Revisions<String> classNames) {
if (classNames == null) {
return;
}
COSName key = COSName.C;
if ((classNames.size() == 1) && (classNames.getRevisionNumber(0) == 0)) {
String className = classNames.getObject(0);
this.getCOSObject().setName(key, className);
return;
}
COSArray array = new COSArray();
for (int i = 0; i < classNames.size(); i++) {
String className = classNames.getObject(i);
int revisionNumber = classNames.getRevisionNumber(i);
if (revisionNumber < 0) {
throw new IllegalArgumentException("The revision number shall be > -1");
}
array.add(COSName.getPDFName(className));
array.add(COSInteger.get(revisionNumber));
}
this.getCOSObject().setItem(key, array);
}
use of com.tom_roush.pdfbox.cos.COSName 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()));
}
Aggregations