Search in sources :

Example 1 with PDShading

use of com.tom_roush.pdfbox.pdmodel.graphics.shading.PDShading in project PdfBox-Android by TomRoush.

the class PDResources method getShading.

/**
 * Returns the shading resource with the given name, or null if none exists.
 *
 * @param name Name of the shading resource.
 *
 * @return the shading resource of the given name.
 *
 * @throws IOException if something went wrong.
 */
public PDShading getShading(COSName name) throws IOException {
    COSObject indirect = getIndirect(COSName.SHADING, name);
    if (cache != null && indirect != null) {
        PDShading cached = cache.getShading(indirect);
        if (cached != null) {
            return cached;
        }
    }
    // get the instance
    PDShading shading = null;
    COSDictionary dict = (COSDictionary) get(COSName.SHADING, name);
    if (dict != null) {
        shading = PDShading.create(dict);
    }
    if (cache != null) {
        cache.put(indirect, shading);
    }
    return shading;
}
Also used : PDShading(com.tom_roush.pdfbox.pdmodel.graphics.shading.PDShading) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSObject(com.tom_roush.pdfbox.cos.COSObject)

Example 2 with PDShading

use of com.tom_roush.pdfbox.pdmodel.graphics.shading.PDShading in project PdfBox-Android by TomRoush.

the class PageDrawer method shadingFill.

@Override
public void shadingFill(COSName shadingName) throws IOException {
    PDShading shading = getResources().getShading(shadingName);
    if (shading == null) {
        Log.e("PdfBox-Android", "shading " + shadingName + " does not exist in resources dictionary");
        return;
    }
    Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
    // Paint paint = shading.toPaint(ctm);
    // paint = applySoftMaskToPaint(paint, getGraphicsState().getSoftMask());
    // graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
    // graphics.setPaint(paint);
    // graphics.setClip(null);
    // lastClip = null;
    // get the transformed BBox and intersect with current clipping path
    // need to do it here and not in shading getRaster() because it may have been rotated
    PDRectangle bbox = shading.getBBox();
    if (bbox != null) {
    // Area bboxArea = new Area(bbox.transform(ctm));
    // bboxArea.intersect(getGraphicsState().getCurrentClippingPath());
    // graphics.fill(bboxArea);
    } else {
    // graphics.fill(getGraphicsState().getCurrentClippingPath());
    }
}
Also used : PDShading(com.tom_roush.pdfbox.pdmodel.graphics.shading.PDShading) Matrix(com.tom_roush.pdfbox.util.Matrix) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Aggregations

PDShading (com.tom_roush.pdfbox.pdmodel.graphics.shading.PDShading)2 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 COSObject (com.tom_roush.pdfbox.cos.COSObject)1 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)1 Matrix (com.tom_roush.pdfbox.util.Matrix)1