Search in sources :

Example 6 with PDRectangle

use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle 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 7 with PDRectangle

use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.

the class PDTextAppearanceHandler method drawRightPointer.

// TODO this is mostly identical to drawStar, except for scale, translation and symbol
private void drawRightPointer(PDAnnotationText annotation, final PDAppearanceContentStream contentStream) throws IOException {
    PDRectangle bbox = adjustRectAndBBox(annotation, 20, 17);
    float min = Math.min(bbox.getWidth(), bbox.getHeight());
    contentStream.setMiterLimit(4);
    contentStream.setLineJoinStyle(1);
    contentStream.setLineCapStyle(0);
    // value from Adobe
    contentStream.setLineWidth(0.59f);
    contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f));
    contentStream.transform(Matrix.getTranslateInstance(0, 50));
    // we get the shape of a Zapf Dingbats right pointer (0x27A4) and use that one.
    // Adobe uses a different font (which one?), or created the shape from scratch.
    Path path = PDType1Font.ZAPF_DINGBATS.getPath("a174");
    addPath(contentStream, path);
    contentStream.fillAndStroke();
}
Also used : Path(android.graphics.Path) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 8 with PDRectangle

use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.

the class PDTextAppearanceHandler method drawCrossHairs.

private void drawCrossHairs(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(0);
    contentStream.setLineCapStyle(0);
    // value from Adobe
    contentStream.setLineWidth(0.61f);
    contentStream.transform(Matrix.getScaleInstance(0.001f * min / 1.5f, 0.001f * min / 1.5f));
    contentStream.transform(Matrix.getTranslateInstance(0, 50));
    // we get the shape of a Symbol crosshair (0x2295) and use that one.
    // Adobe uses a different font (which one?), or created the shape from scratch.
    Path path = PDType1Font.SYMBOL.getPath("circleplus");
    addPath(contentStream, path);
    contentStream.fillAndStroke();
}
Also used : Path(android.graphics.Path) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 9 with PDRectangle

use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.

the class PDTextAppearanceHandler method drawCross.

private void drawCross(PDAnnotationText annotation, final PDAppearanceContentStream contentStream) throws IOException {
    PDRectangle bbox = adjustRectAndBBox(annotation, 19, 19);
    // should be a square, but who knows...
    float min = Math.min(bbox.getWidth(), bbox.getHeight());
    // small = offset nearest bbox edge
    // large = offset second nearest bbox edge
    float small = min / 10;
    float large = min / 5;
    contentStream.setMiterLimit(4);
    contentStream.setLineJoinStyle(1);
    contentStream.setLineCapStyle(0);
    // value from Adobe
    contentStream.setLineWidth(0.59f);
    contentStream.moveTo(small, large);
    contentStream.lineTo(large, small);
    contentStream.lineTo(min / 2, min / 2 - small);
    contentStream.lineTo(min - large, small);
    contentStream.lineTo(min - small, large);
    contentStream.lineTo(min / 2 + small, min / 2);
    contentStream.lineTo(min - small, min - large);
    contentStream.lineTo(min - large, min - small);
    contentStream.lineTo(min / 2, min / 2 + small);
    contentStream.lineTo(large, min - small);
    contentStream.lineTo(small, min - large);
    contentStream.lineTo(min / 2 - small, min / 2);
    contentStream.closeAndFillAndStroke();
// alternatively, this could also be drawn with Zapf Dingbats "a21"
// see DrawStar()
}
Also used : PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 10 with PDRectangle

use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.

the class PDTextAppearanceHandler method drawCheck.

// TODO this is mostly identical to drawStar, except for scale, translation and symbol
// maybe use a table with all values and draw from there
// this could also optionally use outer circle
private void drawCheck(PDAnnotationText annotation, final PDAppearanceContentStream contentStream) throws IOException {
    PDRectangle bbox = adjustRectAndBBox(annotation, 20, 19);
    float min = Math.min(bbox.getWidth(), bbox.getHeight());
    contentStream.setMiterLimit(4);
    contentStream.setLineJoinStyle(1);
    contentStream.setLineCapStyle(0);
    // value from Adobe
    contentStream.setLineWidth(0.59f);
    contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f));
    contentStream.transform(Matrix.getTranslateInstance(0, 50));
    // we get the shape of a Zapf Dingbats check (0x2714) and use that one.
    // Adobe uses a different font (which one?), or created the shape from scratch.
    Path path = PDType1Font.ZAPF_DINGBATS.getPath("a20");
    addPath(contentStream, path);
    contentStream.fillAndStroke();
}
Also used : Path(android.graphics.Path) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Aggregations

PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)82 IOException (java.io.IOException)19 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)13 PDAppearanceContentStream (com.tom_roush.pdfbox.pdmodel.PDAppearanceContentStream)12 PDColor (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)11 Matrix (com.tom_roush.pdfbox.util.Matrix)11 COSArray (com.tom_roush.pdfbox.cos.COSArray)10 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)10 PDAppearanceStream (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream)9 Path (android.graphics.Path)8 AffineTransform (com.tom_roush.harmony.awt.geom.AffineTransform)7 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)6 COSBase (com.tom_roush.pdfbox.cos.COSBase)5 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)5 PDPageContentStream (com.tom_roush.pdfbox.pdmodel.PDPageContentStream)5 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)4 COSName (com.tom_roush.pdfbox.cos.COSName)4 PDExtendedGraphicsState (com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState)4 PDAnnotationTextMarkup (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup)4 PDAnnotationWidget (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget)4