use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class COSArrayList method set.
/**
* {@inheritDoc}
*/
@Override
public E set(int index, E element) {
if (element instanceof String) {
COSString item = new COSString((String) element);
if (parentDict != null && index == 0) {
parentDict.setItem(dictKey, item);
}
array.set(index, item);
} else {
if (parentDict != null && index == 0) {
parentDict.setItem(dictKey, ((COSObjectable) element).getCOSObject());
}
array.set(index, ((COSObjectable) element).getCOSObject());
}
return actual.set(index, element);
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class COSArrayList method add.
/**
* {@inheritDoc}
*/
@Override
public boolean add(E o) {
// in the dictionary from a single item to an array.
if (parentDict != null) {
parentDict.setItem(dictKey, array);
// clear the parent dict so it doesn't happen again, there might be
// a usecase for keeping the parentDict around but not now.
parentDict = null;
}
// string is a special case because we can't subclass to be COSObjectable
if (o instanceof String) {
array.add(new COSString((String) o));
} else {
if (array != null) {
array.add(((COSObjectable) o).getCOSObject());
}
}
return actual.add(o);
}
use of com.tom_roush.pdfbox.cos.COSString 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;
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class PDNameTreeNode method getNames.
/**
* This will return a map of names on this level. The key will be a string,
* and the value will depend on where this class is being used.
*
* @return ordered map of COS objects or <code>null</code> if the dictionary
* contains no 'Names' entry on this level.
*
* @throws IOException If there is an error while creating the sub types.
* @see #getKids()
*/
public Map<String, T> getNames() throws IOException {
COSArray namesArray = (COSArray) node.getDictionaryObject(COSName.NAMES);
if (namesArray != null) {
Map<String, T> names = new LinkedHashMap<String, T>();
for (int i = 0; i < namesArray.size(); i += 2) {
COSString key = (COSString) namesArray.getObject(i);
COSBase cosValue = namesArray.getObject(i + 1);
names.put(key.getString(), convertCOSToPD(cosValue));
}
return Collections.unmodifiableMap(names);
} else {
return null;
}
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class AppearanceGeneratorHelper method getWidgetDefaultAppearanceString.
private PDDefaultAppearanceString getWidgetDefaultAppearanceString(PDAnnotationWidget widget) throws IOException {
COSString da = (COSString) widget.getCOSObject().getDictionaryObject(COSName.DA);
PDResources dr = field.getAcroForm().getDefaultResources();
return new PDDefaultAppearanceString(da, dr);
}
Aggregations