use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDStandardAttributeObject method getNumberOrArrayOfNumber.
/**
* Gets a number or an array of numbers.
*
* @param name the attribute name
* @param defaultValue the default value
* @return a Float or an array of floats
*/
protected Object getNumberOrArrayOfNumber(String name, float defaultValue) {
COSBase v = this.getCOSObject().getDictionaryObject(name);
if (v instanceof COSArray) {
COSArray array = (COSArray) v;
float[] values = new float[array.size()];
for (int i = 0; i < array.size(); i++) {
COSBase item = array.getObject(i);
if (item instanceof COSNumber) {
values[i] = ((COSNumber) item).floatValue();
}
}
return values;
}
if (v instanceof COSNumber) {
return ((COSNumber) v).floatValue();
}
if (defaultValue == UNSPECIFIED) {
return null;
}
return defaultValue;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDOptionalContentProperties method isGroupEnabled.
/**
* Indicates whether an optional content group is enabled.
* @param group the group object
* @return true if the group is enabled
*/
public boolean isGroupEnabled(PDOptionalContentGroup group) {
// TODO handle Optional Content Configuration Dictionaries,
// i.e. OCProperties/Configs
PDOptionalContentProperties.BaseState baseState = getBaseState();
boolean enabled = !baseState.equals(BaseState.OFF);
if (group == null) {
return enabled;
}
COSDictionary d = getD();
COSBase base = d.getDictionaryObject(COSName.ON);
if (base instanceof COSArray) {
for (COSBase o : (COSArray) base) {
COSDictionary dictionary = toDictionary(o);
if (dictionary == group.getCOSObject()) {
return true;
}
}
}
base = d.getDictionaryObject(COSName.OFF);
if (base instanceof COSArray) {
for (COSBase o : (COSArray) base) {
COSDictionary dictionary = toDictionary(o);
if (dictionary == group.getCOSObject()) {
return false;
}
}
}
return enabled;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDOptionalContentProperties method setGroupEnabled.
/**
* Enables or disables an optional content group.
* @param group the group object
* @param enable true to enable, false to disable
* @return true if the group already had an on or off setting, false otherwise
*/
public boolean setGroupEnabled(PDOptionalContentGroup group, boolean enable) {
COSArray on;
COSArray off;
COSDictionary d = getD();
COSBase base = d.getDictionaryObject(COSName.ON);
if (!(base instanceof COSArray)) {
on = new COSArray();
d.setItem(COSName.ON, on);
} else {
on = (COSArray) base;
}
base = d.getDictionaryObject(COSName.OFF);
if (!(base instanceof COSArray)) {
off = new COSArray();
d.setItem(COSName.OFF, off);
} else {
off = (COSArray) base;
}
boolean found = false;
if (enable) {
for (COSBase o : off) {
COSDictionary groupDictionary = toDictionary(o);
if (groupDictionary == group.getCOSObject()) {
// enable group
off.remove(o);
on.add(o);
found = true;
break;
}
}
} else {
for (COSBase o : on) {
COSDictionary groupDictionary = toDictionary(o);
if (groupDictionary == group.getCOSObject()) {
// disable group
on.remove(o);
off.add(o);
found = true;
break;
}
}
}
if (!found) {
if (enable) {
on.add(group.getCOSObject());
} else {
off.add(group.getCOSObject());
}
}
return found;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDOptionalContentProperties method isGroupEnabled.
/**
* Indicates whether <em>at least one</em> optional content group with this name is enabled.
* There may be disabled optional content groups with this name even if this function returns
* true.
*
* @param groupName the group name
* @return true if at least one group is enabled
*/
public boolean isGroupEnabled(String groupName) {
boolean result = false;
COSArray ocgs = getOCGs();
for (COSBase o : ocgs) {
COSDictionary ocg = toDictionary(o);
String name = ocg.getString(COSName.NAME);
if (groupName.equals(name) && isGroupEnabled(new PDOptionalContentGroup(ocg))) {
result = true;
}
}
return result;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDOptionalContentProperties method setGroupEnabled.
/**
* Enables or disables all optional content groups with the given name.
*
* @param groupName the group name
* @param enable true to enable, false to disable
* @return true if at least one group with this name already had an on or off setting, false
* otherwise
*/
public boolean setGroupEnabled(String groupName, boolean enable) {
boolean result = false;
COSArray ocgs = getOCGs();
for (COSBase o : ocgs) {
COSDictionary ocg = toDictionary(o);
String name = ocg.getString(COSName.NAME);
if (groupName.equals(name) && setGroupEnabled(new PDOptionalContentGroup(ocg), enable)) {
result = true;
}
}
return result;
}
Aggregations