Search in sources :

Example 1 with PDAnnotationSquareCircle

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle in project PdfBox-Android by TomRoush.

the class TestPDPageAnnotationsFiltering method initMock.

@Before
public void initMock() {
    COSDictionary mockedPageWithAnnotations = new COSDictionary();
    COSArray annotsDictionary = new COSArray();
    annotsDictionary.add(new PDAnnotationRubberStamp().getCOSObject());
    annotsDictionary.add(new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_SQUARE).getCOSObject());
    annotsDictionary.add(new PDAnnotationLink().getCOSObject());
    mockedPageWithAnnotations.setItem(COSName.ANNOTS, annotsDictionary);
    page = new PDPage(mockedPageWithAnnotations);
}
Also used : PDAnnotationRubberStamp(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationRubberStamp) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSArray(com.tom_roush.pdfbox.cos.COSArray) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) PDAnnotationSquareCircle(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle) Before(org.junit.Before)

Example 2 with PDAnnotationSquareCircle

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle in project PdfBox-Android by TomRoush.

the class COSArrayListTest method setUp.

/*
    * Create thre new different annotations an add them to the Java List/Array as
    * well as PDFBox List/Array implementations.
    */
@Before
public void setUp() throws Exception {
    annotationsList = new ArrayList<PDAnnotation>();
    PDAnnotationTextMarkup txtMark = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
    PDAnnotationLink txtLink = new PDAnnotationLink();
    PDAnnotationSquareCircle aCircle = new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_CIRCLE);
    annotationsList.add(txtMark);
    annotationsList.add(txtLink);
    annotationsList.add(aCircle);
    assertTrue(annotationsList.size() == 3);
    tbcAnnotationsList = new ArrayList<PDAnnotation>();
    tbcAnnotationsList.add(txtMark);
    tbcAnnotationsList.add(txtLink);
    tbcAnnotationsList.add(aCircle);
    assertTrue(tbcAnnotationsList.size() == 3);
    annotationsArray = new COSArray();
    annotationsArray.add(txtMark);
    annotationsArray.add(txtLink);
    annotationsArray.add(aCircle);
    assertTrue(annotationsArray.size() == 3);
    tbcAnnotationsArray = new COSBase[3];
    tbcAnnotationsArray[0] = txtMark.getCOSObject();
    tbcAnnotationsArray[1] = txtLink.getCOSObject();
    tbcAnnotationsArray[2] = aCircle.getCOSObject();
    assertTrue(tbcAnnotationsArray.length == 3);
    // add the annotations to the page
    pdPage = new PDPage();
    pdPage.setAnnotations(annotationsList);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDAnnotationTextMarkup(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup) PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) PDAnnotationSquareCircle(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle) Before(org.junit.Before)

Example 3 with PDAnnotationSquareCircle

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle in project PdfBox-Android by TomRoush.

the class COSArrayListTest method addToList.

/**
 * Test adding a PDModel element is in sync with underlying COSArray
 */
@Test
public void addToList() throws Exception {
    COSArrayList<PDAnnotation> cosArrayList = new COSArrayList<PDAnnotation>(annotationsList, annotationsArray);
    // add new annotation
    PDAnnotationSquareCircle aSquare = new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_SQUARE);
    cosArrayList.add(aSquare);
    assertTrue("List size shall be 4", annotationsList.size() == 4);
    assertTrue("COSArray size shall be 4", annotationsArray.size() == 4);
    PDAnnotation annot = (PDAnnotation) annotationsList.get(3);
    assertTrue("Added annotation shall be 4th entry in COSArray", annotationsArray.indexOf(annot.getCOSObject()) == 3);
    assertEquals("Provided COSArray and underlying COSArray shall be equal", annotationsArray, cosArrayList.toList());
}
Also used : PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) PDAnnotationSquareCircle(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle) Test(org.junit.Test)

Example 4 with PDAnnotationSquareCircle

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle in project PdfBox-Android by TomRoush.

the class TestPDPageAnnotationsFiltering method validateSelectedFew.

@Test
public void validateSelectedFew() throws IOException {
    List<PDAnnotation> annotations = page.getAnnotations(new AnnotationFilter() {

        @Override
        public boolean accept(PDAnnotation annotation) {
            return (annotation instanceof PDAnnotationLink || annotation instanceof PDAnnotationSquareCircle);
        }
    });
    Assert.assertEquals(2, annotations.size());
    Assert.assertTrue(annotations.get(0) instanceof PDAnnotationSquareCircle);
    Assert.assertTrue(annotations.get(1) instanceof PDAnnotationLink);
}
Also used : PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) AnnotationFilter(com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter) PDAnnotationSquareCircle(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle) Test(org.junit.Test)

Example 5 with PDAnnotationSquareCircle

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle in project PdfBox-Android by TomRoush.

the class PDCircleAppearanceHandler method generateNormalAppearance.

@Override
public void generateNormalAppearance() {
    float lineWidth = getLineWidth();
    PDAnnotationSquareCircle annotation = (PDAnnotationSquareCircle) getAnnotation();
    PDAppearanceContentStream contentStream = null;
    try {
        contentStream = getNormalAppearanceAsContentStream();
        boolean hasStroke = contentStream.setStrokingColorOnDemand(getColor());
        boolean hasBackground = contentStream.setNonStrokingColorOnDemand(annotation.getInteriorColor());
        setOpacity(contentStream, annotation.getConstantOpacity());
        contentStream.setBorderLine(lineWidth, annotation.getBorderStyle(), annotation.getBorder());
        PDBorderEffectDictionary borderEffect = annotation.getBorderEffect();
        if (borderEffect != null && borderEffect.getStyle().equals(PDBorderEffectDictionary.STYLE_CLOUDY)) {
            CloudyBorder cloudyBorder = new CloudyBorder(contentStream, borderEffect.getIntensity(), lineWidth, getRectangle());
            cloudyBorder.createCloudyEllipse(annotation.getRectDifference());
            annotation.setRectangle(cloudyBorder.getRectangle());
            annotation.setRectDifference(cloudyBorder.getRectDifference());
            PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream();
            appearanceStream.setBBox(cloudyBorder.getBBox());
            appearanceStream.setMatrix(cloudyBorder.getMatrix());
        } else {
            // Acrobat applies a padding to each side of the bbox so the line is completely within
            // the bbox.
            PDRectangle borderBox = handleBorderBox(annotation, lineWidth);
            // lower left corner
            float x0 = borderBox.getLowerLeftX();
            float y0 = borderBox.getLowerLeftY();
            // upper right corner
            float x1 = borderBox.getUpperRightX();
            float y1 = borderBox.getUpperRightY();
            // mid points
            float xm = x0 + borderBox.getWidth() / 2;
            float ym = y0 + borderBox.getHeight() / 2;
            // see http://spencermortensen.com/articles/bezier-circle/
            // the below number was calculated from sampling content streams
            // generated using Adobe Reader
            float magic = 0.55555417f;
            // control point offsets
            float vOffset = borderBox.getHeight() / 2 * magic;
            float hOffset = borderBox.getWidth() / 2 * magic;
            contentStream.moveTo(xm, y1);
            contentStream.curveTo((xm + hOffset), y1, x1, (ym + vOffset), x1, ym);
            contentStream.curveTo(x1, (ym - vOffset), (xm + hOffset), y0, xm, y0);
            contentStream.curveTo((xm - hOffset), y0, x0, (ym - vOffset), x0, ym);
            contentStream.curveTo(x0, (ym + vOffset), (xm - hOffset), y1, xm, y1);
            contentStream.closePath();
        }
        contentStream.drawShape(lineWidth, hasStroke, hasBackground);
    } catch (IOException e) {
        Log.e("PdfBox-Android", e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(contentStream);
    }
}
Also used : PDAppearanceContentStream(com.tom_roush.pdfbox.pdmodel.PDAppearanceContentStream) PDAppearanceStream(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream) PDBorderEffectDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) IOException(java.io.IOException) PDAnnotationSquareCircle(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle)

Aggregations

PDAnnotationSquareCircle (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle)6 PDAnnotation (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation)3 PDAnnotationLink (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink)3 COSArray (com.tom_roush.pdfbox.cos.COSArray)2 PDAppearanceContentStream (com.tom_roush.pdfbox.pdmodel.PDAppearanceContentStream)2 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)2 PDAppearanceStream (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream)2 PDBorderEffectDictionary (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary)2 IOException (java.io.IOException)2 Before (org.junit.Before)2 Test (org.junit.Test)2 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)1 AnnotationFilter (com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter)1 PDAnnotationRubberStamp (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationRubberStamp)1 PDAnnotationTextMarkup (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup)1