use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDDefaultAppearanceString method processSetFont.
/**
* Process the set font and font size operator.
*
* @param operands the font name and size
* @throws IOException in case there are missing operators or the font is not within the resources
*/
private void processSetFont(List<COSBase> operands) throws IOException {
if (operands.size() < 2) {
throw new IOException("Missing operands for set font operator " + Arrays.toString(operands.toArray()));
}
COSBase base0 = operands.get(0);
COSBase base1 = operands.get(1);
if (!(base0 instanceof COSName)) {
return;
}
if (!(base1 instanceof COSNumber)) {
return;
}
COSName fontName = (COSName) base0;
PDFont font = defaultResources.getFont(fontName);
float fontSize = ((COSNumber) base1).floatValue();
// todo: handle cases where font == null with special mapping logic (see PDFBOX-2661)
if (font == null) {
throw new IOException("Could not find font: /" + fontName.getName());
}
setFontName(fontName);
setFont(font);
setFontSize(fontSize);
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class FieldUtils method getPairableItems.
/**
* Return either one of a list which can have two-element arrays entries.
* <p>
* Some entries in a dictionary can either be an array of elements
* or an array of two-element arrays. This method will either return
* the elements in the array or in case of two-element arrays, the element
* designated by the pair index
* </p>
* <p>
* An {@link IllegalArgumentException} will be thrown if the items contain
* two-element arrays and the index is not 0 or 1.
* </p>
*
* @param items the array of elements or two-element arrays
* @param pairIdx the index into the two-element array
* @return a List of single elements
*/
static List<String> getPairableItems(COSBase items, int pairIdx) {
if (pairIdx < 0 || pairIdx > 1) {
throw new IllegalArgumentException("Only 0 and 1 are allowed as an index into two-element arrays");
}
if (items instanceof COSString) {
List<String> array = new ArrayList<String>();
array.add(((COSString) items).getString());
return array;
} else if (items instanceof COSArray) {
List<String> entryList = new ArrayList<String>();
for (COSBase entry : (COSArray) items) {
if (entry instanceof COSString) {
entryList.add(((COSString) entry).getString());
} else if (entry instanceof COSArray) {
COSArray cosArray = (COSArray) entry;
if (cosArray.size() >= pairIdx + 1 && cosArray.get(pairIdx) instanceof COSString) {
entryList.add(((COSString) cosArray.get(pairIdx)).getString());
}
}
}
return entryList;
}
return Collections.emptyList();
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDAcroForm method getXFA.
/**
* Get the XFA resource, the XFA resource is only used for PDF 1.5+ forms.
*
* @return The xfa resource or null if it does not exist.
*/
public PDXFAResource getXFA() {
PDXFAResource xfa = null;
COSBase base = dictionary.getDictionaryObject(COSName.XFA);
if (base != null) {
xfa = new PDXFAResource(base);
}
return xfa;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDAcroForm method getDefaultResources.
/**
* This will get the default resources for the AcroForm.
*
* @return The default resources or null if there is none.
*/
public PDResources getDefaultResources() {
PDResources retval = null;
COSBase base = dictionary.getDictionaryObject(COSName.DR);
if (base instanceof COSDictionary) {
retval = new PDResources((COSDictionary) base, document.getResourceCache());
}
return retval;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDTerminalField method getWidgets.
/**
* Returns the widget annotations associated with this field.
*
* @return The list of widget annotations. Be aware that this list is <i>not</i> backed by the
* actual widget collection of the field, so adding or deleting has no effect on the PDF
* document until you call {@link #setWidgets(java.util.List) setWidgets()} with the modified
* list.
*/
@Override
public List<PDAnnotationWidget> getWidgets() {
List<PDAnnotationWidget> widgets = new ArrayList<PDAnnotationWidget>();
COSArray kids = (COSArray) getCOSObject().getDictionaryObject(COSName.KIDS);
if (kids == null) {
// the field itself is a widget
widgets.add(new PDAnnotationWidget(getCOSObject()));
} else if (kids.size() > 0) {
// there are multiple widgets
for (int i = 0; i < kids.size(); i++) {
COSBase kid = kids.getObject(i);
if (kid instanceof COSDictionary) {
widgets.add(new PDAnnotationWidget((COSDictionary) kid));
}
}
}
return widgets;
}
Aggregations