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);
}
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);
}
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());
}
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);
}
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);
}
}
Aggregations