Search in sources :

Example 11 with PDExtendedGraphicsState

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

the class PDTextAppearanceHandler method drawRightArrow.

private void drawRightArrow(PDAnnotationText annotation, final PDAppearanceContentStream contentStream) throws IOException {
    PDRectangle bbox = adjustRectAndBBox(annotation, 20, 20);
    float min = Math.min(bbox.getWidth(), bbox.getHeight());
    contentStream.setMiterLimit(4);
    contentStream.setLineJoinStyle(1);
    contentStream.setLineCapStyle(0);
    // value from Adobe
    contentStream.setLineWidth(0.59f);
    // Adobe first fills a white circle with CA ca 0.6, so do we
    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);
    drawCircle2(contentStream, min / 2, min / 2, min / 2 - 1);
    contentStream.fill();
    contentStream.restoreGraphicsState();
    contentStream.saveGraphicsState();
    // rescale so that the glyph fits into circle and move it to circle center
    // values gathered by trial and error
    contentStream.transform(Matrix.getScaleInstance(0.001f * min / 1.3f, 0.001f * min / 1.3f));
    contentStream.transform(Matrix.getTranslateInstance(200, 300));
    // we get the shape of a Zapf Dingbats right arrow (0x2794) and use that one.
    // Adobe uses a different font (which one?), or created the shape from scratch.
    Path path = PDType1Font.ZAPF_DINGBATS.getPath("a160");
    addPath(contentStream, path);
    contentStream.restoreGraphicsState();
    // surprisingly, this one not counterclockwise.
    drawCircle(contentStream, min / 2, min / 2, min / 2 - 1);
    contentStream.fillAndStroke();
}
Also used : Path(android.graphics.Path) PDExtendedGraphicsState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

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