use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class PDOptionalContentGroup method getRenderState.
// TODO Add support for "Intent"
/**
* @param destination to be rendered
* @return state or null if undefined
*/
public RenderState getRenderState(RenderDestination destination) {
COSName state = null;
COSDictionary usage = (COSDictionary) dict.getDictionaryObject("Usage");
if (usage != null) {
if (RenderDestination.PRINT.equals(destination)) {
COSDictionary print = (COSDictionary) usage.getDictionaryObject("Print");
state = print == null ? null : (COSName) print.getDictionaryObject("PrintState");
} else if (RenderDestination.VIEW.equals(destination)) {
COSDictionary view = (COSDictionary) usage.getDictionaryObject("View");
state = view == null ? null : (COSName) view.getDictionaryObject("ViewState");
}
// Fallback to export
if (state == null) {
COSDictionary export = (COSDictionary) usage.getDictionaryObject("Export");
state = export == null ? null : (COSName) export.getDictionaryObject("ExportState");
}
}
return state == null ? null : RenderState.valueOf(state);
}
use of com.tom_roush.pdfbox.cos.COSDictionary 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.COSDictionary 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.COSDictionary 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.COSDictionary in project PdfBox-Android by TomRoush.
the class PDOptionalContentProperties method setBaseState.
/**
* Sets the base state for optional content groups.
* @param state the base state
*/
public void setBaseState(BaseState state) {
COSDictionary d = getD();
d.setItem(COSName.BASE_STATE, state.getName());
}
Aggregations