use of com.tom_roush.pdfbox.pdmodel.graphics.PDXObject 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.pdmodel.graphics.PDXObject in project PdfBox-Android by TomRoush.
the class PageDrawer method hasBlendMode.
private boolean hasBlendMode(PDTransparencyGroup group, Set<COSBase> groupsDone) {
if (groupsDone.contains(group.getCOSObject())) {
// The group was already processed. Avoid endless recursion.
return false;
}
groupsDone.add(group.getCOSObject());
PDResources resources = group.getResources();
if (resources == null) {
return false;
}
for (COSName name : resources.getExtGStateNames()) {
PDExtendedGraphicsState extGState = resources.getExtGState(name);
if (extGState == null) {
continue;
}
BlendMode blendMode = extGState.getBlendMode();
if (blendMode != BlendMode.NORMAL) {
return true;
}
}
// Recursively process nested transparency groups
for (COSName name : resources.getXObjectNames()) {
PDXObject xObject;
try {
xObject = resources.getXObject(name);
} catch (IOException ex) {
continue;
}
if (xObject instanceof PDTransparencyGroup && hasBlendMode((PDTransparencyGroup) xObject, groupsDone)) {
return true;
}
}
return false;
}
use of com.tom_roush.pdfbox.pdmodel.graphics.PDXObject in project PdfBox-Android by TomRoush.
the class PDObjectReference method getReferencedObject.
/**
* Gets a higher-level object for the referenced object.
* Currently this method may return a {@link PDAnnotation},
* a {@link PDXObject} or <code>null</code>.
*
* @return a higher-level object for the referenced object
*/
public COSObjectable getReferencedObject() {
COSBase obj = this.getCOSObject().getDictionaryObject(COSName.OBJ);
if (!(obj instanceof COSDictionary)) {
return null;
}
try {
if (obj instanceof COSStream) {
// <-- TODO: valid?
PDXObject xobject = PDXObject.createXObject(obj, null);
if (xobject != null) {
return xobject;
}
}
COSDictionary objDictionary = (COSDictionary) obj;
PDAnnotation annotation = PDAnnotation.createAnnotation(obj);
/*
* COSName.TYPE is optional, so if annotation is of type unknown and
* COSName.TYPE is not COSName.ANNOT it still may be an annotation.
* TODO shall we return the annotation object instead of null?
* what else can be the target of the object reference?
*/
if (!(annotation instanceof PDAnnotationUnknown) || COSName.ANNOT.equals(objDictionary.getDictionaryObject(COSName.TYPE))) {
return annotation;
}
} catch (IOException exception) {
// this can only happen if the target is an XObject.
}
return null;
}
use of com.tom_roush.pdfbox.pdmodel.graphics.PDXObject in project PdfBox-Android by TomRoush.
the class PDAcroForm method resolveNeedsTranslation.
/**
* Check if there is a translation needed to place the annotations content.
*
* @param appearanceStream
* @return the need for a translation transformation.
*/
private boolean resolveNeedsTranslation(PDAppearanceStream appearanceStream) {
boolean needsTranslation = true;
PDResources resources = appearanceStream.getResources();
if (resources != null && resources.getXObjectNames().iterator().hasNext()) {
Iterator<COSName> xObjectNames = resources.getXObjectNames().iterator();
while (xObjectNames.hasNext()) {
try {
// if the BBox of the PDFormXObject does not start at 0,0
// there is no need do translate as this is done by the BBox definition.
PDXObject xObject = resources.getXObject(xObjectNames.next());
if (xObject instanceof PDFormXObject) {
PDRectangle bbox = ((PDFormXObject) xObject).getBBox();
float llX = bbox.getLowerLeftX();
float llY = bbox.getLowerLeftY();
if (Float.compare(llX, 0) != 0 && Float.compare(llY, 0) != 0) {
needsTranslation = false;
}
}
} catch (IOException e) {
// we can safely ignore the exception here
// as this might only cause a misplacement
}
}
return needsTranslation;
}
return true;
}
use of com.tom_roush.pdfbox.pdmodel.graphics.PDXObject in project PdfBox-Android by TomRoush.
the class DrawObject method process.
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
if (arguments.isEmpty()) {
throw new MissingOperandException(operator, arguments);
}
COSBase base0 = arguments.get(0);
if (!(base0 instanceof COSName)) {
return;
}
COSName name = (COSName) base0;
PDXObject xobject = context.getResources().getXObject(name);
((PDFMarkedContentExtractor) context).xobject(xobject);
if (xobject instanceof PDFormXObject) {
try {
context.increaseLevel();
if (context.getLevel() > 25) {
Log.e("PdfBox-Android", "recursion is too deep, skipping form XObject");
return;
}
PDFormXObject form = (PDFormXObject) xobject;
if (form instanceof PDTransparencyGroup) {
context.showTransparencyGroup((PDTransparencyGroup) form);
} else {
context.showForm(form);
}
} finally {
context.decreaseLevel();
}
}
}
Aggregations