use of org.apache.pdfbox.pdmodel.ResourceCache in project pdfbox by apache.
the class PDColorSpace method createFromCOSObject.
private static PDColorSpace createFromCOSObject(COSObject colorSpace, PDResources resources) throws IOException {
PDColorSpace cs;
if (resources != null && resources.getResourceCache() != null) {
ResourceCache resourceCache = resources.getResourceCache();
cs = resourceCache.getColorSpace(colorSpace);
if (cs != null) {
return cs;
}
}
cs = create(colorSpace.getObject(), resources);
if (resources != null && resources.getResourceCache() != null && cs != null) {
ResourceCache resourceCache = resources.getResourceCache();
resourceCache.put(colorSpace, cs);
}
return cs;
}
use of org.apache.pdfbox.pdmodel.ResourceCache in project pdfbox by apache.
the class PDXObject method createXObject.
/**
* Creates a new XObject instance of the appropriate type for the COS stream.
*
* @param base The stream which is wrapped by this XObject.
* @param resources
* @return A new XObject instance.
* @throws java.io.IOException if there is an error creating the XObject.
*/
public static PDXObject createXObject(COSBase base, PDResources resources) throws IOException {
if (base == null) {
// TODO throw an exception?
return null;
}
if (!(base instanceof COSStream)) {
throw new IOException("Unexpected object type: " + base.getClass().getName());
}
COSStream stream = (COSStream) base;
String subtype = stream.getNameAsString(COSName.SUBTYPE);
if (COSName.IMAGE.getName().equals(subtype)) {
return new PDImageXObject(new PDStream(stream), resources);
} else if (COSName.FORM.getName().equals(subtype)) {
ResourceCache cache = resources != null ? resources.getResourceCache() : null;
COSDictionary group = (COSDictionary) stream.getDictionaryObject(COSName.GROUP);
if (group != null && COSName.TRANSPARENCY.equals(group.getCOSName(COSName.S))) {
return new PDTransparencyGroup(stream, cache);
}
return new PDFormXObject(stream, cache);
} else if (COSName.PS.getName().equals(subtype)) {
return new PDPostScriptXObject(stream);
} else {
throw new IOException("Invalid XObject Subtype: " + subtype);
}
}
Aggregations