use of com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project PdfBox-Android by TomRoush.
the class PageDrawer method showTransparencyGroup.
@Override
public void showTransparencyGroup(PDTransparencyGroup form) throws IOException {
if (!isContentRendered()) {
return;
}
TransparencyGroup group = new TransparencyGroup(form, false, getGraphicsState().getCurrentTransformationMatrix(), null);
// Bitmap image = group.getImage();
// if (image == null)
// {
// image is empty, don't bother
// return;
// }
// graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
setClip();
// both the DPI xform and the CTM were already applied to the group, so all we do
// here is draw it directly onto the Graphics2D device at the appropriate position
// PDRectangle bbox = group.getBBox();
// AffineTransform savedTransform = graphics.getTransform();
Matrix m = new Matrix(xform);
float xScale = Math.abs(m.getScalingFactorX());
float yScale = Math.abs(m.getScalingFactorY());
AffineTransform transform = new AffineTransform(xform);
transform.scale(1.0 / xScale, 1.0 / yScale);
if (flipTG) {
// graphics.translate(0, image.getHeight());
// graphics.scale(1, -1);
} else {
// graphics.translate(x * xScale, y * yScale);
}
PDSoftMask softMask = getGraphicsState().getSoftMask();
if (softMask != null) {
// graphics.setPaint(awtPaint);
if (isContentRendered()) {
// graphics.fill(
// new Rectangle2D.Float(0, 0, bbox.getWidth() * xScale, bbox.getHeight() * yScale));
}
} else {
if (isContentRendered()) {
// try
// {
// graphics.drawImage(image, null, null);
// }
// catch (InternalError ie)
// {
// Log.e("PdfBox-Android", "Exception drawing image, see JDK-6689349, " +
// "try rendering into a BufferedImage instead", ie);
// }
}
}
// graphics.setTransform(savedTransform);
}
use of com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup 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.form.PDTransparencyGroup in project PdfBox-Android by TomRoush.
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);
}
}
use of com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup 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();
}
}
}
use of com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup 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;
if (context.getResources().isImageXObject(name)) {
// we're done here, don't decode images when doing text extraction
return;
}
PDXObject xobject = context.getResources().getXObject(name);
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