use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDResources method getXObject.
/**
* Returns the XObject resource with the given name, or null if none exists.
*
* @param name Name of the XObject resource.
*
* @return the XObject resource of the given name.
*
* @throws IOException if something went wrong.
*/
public PDXObject getXObject(COSName name) throws IOException {
COSObject indirect = getIndirect(COSName.XOBJECT, name);
if (cache != null && indirect != null) {
PDXObject cached = cache.getXObject(indirect);
if (cached != null) {
return cached;
}
}
// get the instance
PDXObject xobject;
COSBase value = get(COSName.XOBJECT, name);
if (value == null) {
xobject = null;
} else if (value instanceof COSObject) {
xobject = PDXObject.createXObject(((COSObject) value).getObject(), this);
} else {
xobject = PDXObject.createXObject(value, this);
}
if (cache != null && isAllowedCache(xobject)) {
cache.put(indirect, xobject);
}
return xobject;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class COSArrayList method convertFloatCOSArrayToList.
/**
* This will take an array of COSNumbers and return a COSArrayList of
* java.lang.Float values.
*
* @param floatArray The existing float Array.
*
* @return The list of Float objects.
*/
public static List<Float> convertFloatCOSArrayToList(COSArray floatArray) {
List<Float> retval = null;
if (floatArray != null) {
List<Float> numbers = new ArrayList<Float>(floatArray.size());
for (int i = 0; i < floatArray.size(); i++) {
COSBase base = floatArray.getObject(i);
if (base instanceof COSNumber) {
numbers.add(((COSNumber) base).floatValue());
} else {
numbers.add(null);
}
}
retval = new COSArrayList<Float>(numbers, floatArray);
}
return retval;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class COSArrayList method toCOSObjectList.
private List<COSBase> toCOSObjectList(Collection<?> list) {
List<COSBase> cosObjects = new ArrayList<COSBase>();
for (Object next : list) {
if (next instanceof String) {
cosObjects.add(new COSString((String) next));
} else {
COSObjectable cos = (COSObjectable) next;
cosObjects.add(cos.getCOSObject());
}
}
return cosObjects;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDType3CharProc method getWidth.
/**
* Get the width from a type3 charproc stream.
*
* @return the glyph width.
* @throws IOException if the stream could not be read, or did not have d0 or d1 as first
* operator, or if their first argument was not a number.
*/
public float getWidth() throws IOException {
List<COSBase> arguments = new ArrayList<COSBase>();
PDFStreamParser parser = new PDFStreamParser(this);
Object token = parser.parseNextToken();
while (token != null) {
if (token instanceof COSObject) {
arguments.add(((COSObject) token).getObject());
} else if (token instanceof Operator) {
return parseWidth((Operator) token, arguments);
} else {
arguments.add((COSBase) token);
}
token = parser.parseNextToken();
}
throw new IOException("Unexpected end of stream");
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDType3CharProc method getGlyphBBox.
/**
* Calculate the bounding box of this glyph. This will work only if the first operator in the
* stream is d1.
*
* @return the bounding box of this glyph, or null if the first operator is not d1.
* @throws IOException If an io error occurs while parsing the stream.
*/
public PDRectangle getGlyphBBox() throws IOException {
List<COSBase> arguments = new ArrayList<COSBase>();
PDFStreamParser parser = new PDFStreamParser(this);
Object token = parser.parseNextToken();
while (token != null) {
if (token instanceof COSObject) {
arguments.add(((COSObject) token).getObject());
} else if (token instanceof Operator) {
if (((Operator) token).getName().equals("d1") && arguments.size() == 6) {
for (int i = 0; i < 6; ++i) {
if (!(arguments.get(i) instanceof COSNumber)) {
return null;
}
}
return new PDRectangle(((COSNumber) arguments.get(2)).floatValue(), ((COSNumber) arguments.get(3)).floatValue(), ((COSNumber) arguments.get(4)).floatValue() - ((COSNumber) arguments.get(2)).floatValue(), ((COSNumber) arguments.get(5)).floatValue() - ((COSNumber) arguments.get(3)).floatValue());
} else {
return null;
}
} else {
arguments.add((COSBase) token);
}
token = parser.parseNextToken();
}
return null;
}
Aggregations