Search in sources :

Example 1 with PDSoftMask

use of com.tom_roush.pdfbox.pdmodel.graphics.state.PDSoftMask 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);
}
Also used : PDSoftMask(com.tom_roush.pdfbox.pdmodel.graphics.state.PDSoftMask) PDTransparencyGroup(com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup) Matrix(com.tom_roush.pdfbox.util.Matrix) AffineTransform(com.tom_roush.harmony.awt.geom.AffineTransform)

Example 2 with PDSoftMask

use of com.tom_roush.pdfbox.pdmodel.graphics.state.PDSoftMask in project PdfBox-Android by TomRoush.

the class PageDrawer method drawBitmap.

private void drawBitmap(Bitmap image, AffineTransform at) throws IOException {
    // graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
    setClip();
    AffineTransform imageTransform = new AffineTransform(at);
    PDSoftMask softMask = getGraphicsState().getSoftMask();
    if (softMask != null) {
        imageTransform.scale(1, -1);
        imageTransform.translate(0, -1);
        // Paint awtPaint = new TexturePaint(image,
        // new Rectangle2D.Double(imageTransform.getTranslateX(), imageTransform.getTranslateY(),
        // imageTransform.getScaleX(), imageTransform.getScaleY()));
        // awtPaint = applySoftMaskToPaint(awtPaint, softMask);
        // graphics.setPaint(awtPaint);
        RectF unitRect = new RectF(0, 0, 1, 1);
        if (isContentRendered()) {
        // graphics.fill(at.createTransformedShape(unitRect));
        }
    } else {
        COSBase transfer = getGraphicsState().getTransfer();
        if (transfer instanceof COSArray || transfer instanceof COSDictionary) {
            image = applyTransferFunction(image, transfer);
        }
        int width = image.getWidth();
        int height = image.getHeight();
        imageTransform.scale(1.0 / width, -1.0 / height);
        imageTransform.translate(0, -height);
        if (isContentRendered()) {
            canvas.drawBitmap(image, imageTransform.toMatrix(), paint);
        }
    }
}
Also used : RectF(android.graphics.RectF) PDSoftMask(com.tom_roush.pdfbox.pdmodel.graphics.state.PDSoftMask) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) AffineTransform(com.tom_roush.harmony.awt.geom.AffineTransform) COSBase(com.tom_roush.pdfbox.cos.COSBase) Paint(android.graphics.Paint)

Aggregations

AffineTransform (com.tom_roush.harmony.awt.geom.AffineTransform)2 PDSoftMask (com.tom_roush.pdfbox.pdmodel.graphics.state.PDSoftMask)2 Paint (android.graphics.Paint)1 RectF (android.graphics.RectF)1 COSArray (com.tom_roush.pdfbox.cos.COSArray)1 COSBase (com.tom_roush.pdfbox.cos.COSBase)1 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 PDTransparencyGroup (com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup)1 Matrix (com.tom_roush.pdfbox.util.Matrix)1