Search in sources :

Example 1 with PDExtendedGraphicsState

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

the class PDTextAppearanceHandler method drawCircles.

private void drawCircles(PDAnnotationText annotation, final PDAppearanceContentStream contentStream) throws IOException {
    PDRectangle bbox = adjustRectAndBBox(annotation, 20, 20);
    // strategy used by Adobe:
    // 1) add small circle in white using /ca /CA 0.6 and width 1
    // 2) fill
    // 3) add small circle in one direction
    // 4) add large circle in other direction
    // 5) stroke + fill
    // with square width 20 small r = 6.36, large r = 9.756
    float smallR = 6.36f;
    float largeR = 9.756f;
    contentStream.setMiterLimit(4);
    contentStream.setLineJoinStyle(1);
    contentStream.setLineCapStyle(0);
    contentStream.saveGraphicsState();
    contentStream.setLineWidth(1);
    PDExtendedGraphicsState gs = new PDExtendedGraphicsState();
    gs.setAlphaSourceFlag(false);
    gs.setStrokingAlphaConstant(0.6f);
    gs.setNonStrokingAlphaConstant(0.6f);
    gs.setBlendMode(BlendMode.NORMAL);
    contentStream.setGraphicsStateParameters(gs);
    contentStream.setNonStrokingColor(1f);
    drawCircle(contentStream, bbox.getWidth() / 2, bbox.getHeight() / 2, smallR);
    contentStream.fill();
    contentStream.restoreGraphicsState();
    // value from Adobe
    contentStream.setLineWidth(0.59f);
    drawCircle(contentStream, bbox.getWidth() / 2, bbox.getHeight() / 2, smallR);
    drawCircle2(contentStream, bbox.getWidth() / 2, bbox.getHeight() / 2, largeR);
    contentStream.fillAndStroke();
}
Also used : PDExtendedGraphicsState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 2 with PDExtendedGraphicsState

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

the class PDResources method getExtGState.

/**
 * Returns the extended graphics state resource with the given name, or null if none exists.
 *
 * @param name Name of the graphics state resource.
 *
 * @return the extended graphics state resource with the given name.
 */
public PDExtendedGraphicsState getExtGState(COSName name) {
    COSObject indirect = getIndirect(COSName.EXT_G_STATE, name);
    if (cache != null && indirect != null) {
        PDExtendedGraphicsState cached = cache.getExtGState(indirect);
        if (cached != null) {
            return cached;
        }
    }
    // get the instance
    PDExtendedGraphicsState extGState = null;
    COSDictionary dict = (COSDictionary) get(COSName.EXT_G_STATE, name);
    if (dict != null) {
        extGState = new PDExtendedGraphicsState(dict);
    }
    if (cache != null) {
        cache.put(indirect, extGState);
    }
    return extGState;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) PDExtendedGraphicsState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState) COSObject(com.tom_roush.pdfbox.cos.COSObject)

Example 3 with PDExtendedGraphicsState

use of com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState 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;
}
Also used : PDTransparencyGroup(com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup) COSName(com.tom_roush.pdfbox.cos.COSName) PDExtendedGraphicsState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState) BlendMode(com.tom_roush.pdfbox.pdmodel.graphics.blend.BlendMode) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) IOException(java.io.IOException) PDXObject(com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)

Example 4 with PDExtendedGraphicsState

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

the class PDFRenderer method hasBlendMode.

private boolean hasBlendMode(PDPage page) {
    // check the current resources for blend modes
    PDResources resources = page.getResources();
    if (resources == null) {
        return false;
    }
    for (COSName name : resources.getExtGStateNames()) {
        PDExtendedGraphicsState extGState = resources.getExtGState(name);
        if (extGState == null) {
            // see PDFBOX-3950-23EGDHXSBBYQLKYOKGZUOVYVNE675PRD.pdf
            continue;
        }
        BlendMode blendMode = extGState.getBlendMode();
        if (blendMode != BlendMode.NORMAL) {
            return true;
        }
    }
    return false;
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) PDExtendedGraphicsState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState) BlendMode(com.tom_roush.pdfbox.pdmodel.graphics.blend.BlendMode) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources)

Example 5 with PDExtendedGraphicsState

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

the class SetGraphicsStateParameters 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;
    }
    // set parameters from graphics state parameter dictionary
    COSName graphicsName = (COSName) base0;
    PDExtendedGraphicsState gs = context.getResources().getExtGState(graphicsName);
    if (gs == null) {
        Log.e("PdfBox-Android", "name for 'gs' operator not found in resources: /" + graphicsName.getName());
        return;
    }
    gs.copyIntoGraphicsState(context.getGraphicsState());
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) MissingOperandException(com.tom_roush.pdfbox.contentstream.operator.MissingOperandException) PDExtendedGraphicsState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Aggregations

PDExtendedGraphicsState (com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState)11 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)5 Path (android.graphics.Path)3 COSName (com.tom_roush.pdfbox.cos.COSName)3 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)3 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)2 BlendMode (com.tom_roush.pdfbox.pdmodel.graphics.blend.BlendMode)2 IOException (java.io.IOException)2 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)1 COSBase (com.tom_roush.pdfbox.cos.COSBase)1 COSObject (com.tom_roush.pdfbox.cos.COSObject)1 PDAppearanceContentStream (com.tom_roush.pdfbox.pdmodel.PDAppearanceContentStream)1 PDFormContentStream (com.tom_roush.pdfbox.pdmodel.PDFormContentStream)1 PDXObject (com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)1 PDColor (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)1 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)1 PDTransparencyGroup (com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup)1 PDAnnotationTextMarkup (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup)1