Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2EEF7200CD8 for ; Wed, 2 Aug 2017 18:22:18 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 26BDA169CAF; Wed, 2 Aug 2017 16:22:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4DBD3169CAC for ; Wed, 2 Aug 2017 18:22:17 +0200 (CEST) Received: (qmail 43205 invoked by uid 500); 2 Aug 2017 16:22:15 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 43196 invoked by uid 99); 2 Aug 2017 16:22:15 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Aug 2017 16:22:15 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 7B1363A04B2 for ; Wed, 2 Aug 2017 16:22:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1803855 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java Date: Wed, 02 Aug 2017 16:22:12 -0000 To: commits@pdfbox.apache.org From: tilman@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170802162214.7B1363A04B2@svn01-us-west.apache.org> archived-at: Wed, 02 Aug 2017 16:22:18 -0000 Author: tilman Date: Wed Aug 2 16:22:12 2017 New Revision: 1803855 URL: http://svn.apache.org/viewvc?rev=1803855&view=rev Log: PDFBOX-2852: remove unneeded code; use jdk7 syntax Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java?rev=1803855&r1=1803854&r2=1803855&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java (original) +++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java Wed Aug 2 16:22:12 2017 @@ -79,27 +79,28 @@ public class PDSquareAnnotationTest // the width of the annotations = page.getAnnotations(); - - PDAnnotationSquareCircle annotation = new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_SQUARE); - - PDBorderStyleDictionary borderThin = new PDBorderStyleDictionary(); - borderThin.setWidth(borderWidth); - - PDColor red = new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE); - annotation.setContents("Square Annotation"); - annotation.setColor(red); - annotation.setBorderStyle(borderThin); - - - annotation.setRectangle(rectangle); - - annotation.constructAppearances(); - annotations.add(annotation); - document.close(); + try (PDDocument document = new PDDocument()) + { + PDPage page = new PDPage(); + document.addPage(page); + List annotations = page.getAnnotations(); + + PDAnnotationSquareCircle annotation = new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_SQUARE); + + PDBorderStyleDictionary borderThin = new PDBorderStyleDictionary(); + borderThin.setWidth(borderWidth); + + PDColor red = new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE); + annotation.setContents("Square Annotation"); + annotation.setColor(red); + annotation.setBorderStyle(borderThin); + + + annotation.setRectangle(rectangle); + + annotation.constructAppearances(); + annotations.add(annotation); + } } @Test @@ -109,60 +110,54 @@ public class PDSquareAnnotationTest final int borderWidth = 1; File file = new File(IN_DIR, NAME_OF_PDF); - PDDocument document = PDDocument.load(file); - PDPage page = document.getPage(0); - List annotations = page.getAnnotations(); - - PDAnnotationSquareCircle annotation = (PDAnnotationSquareCircle) annotations.get(0); - - PDRectangle rectangle = new PDRectangle(); - rectangle.setLowerLeftX(91.5958f); - rectangle.setLowerLeftY(741.91f); - rectangle.setUpperRightX(113.849f); - rectangle.setUpperRightY(757.078f); - - // test the correct setting of the appearance stream - assertNotNull("Appearance dictionary shall not be null", annotation.getAppearance()); - assertNotNull("Normal appearance shall not be null", annotation.getAppearance().getNormalAppearance()); - PDAppearanceStream appearanceStream = annotation.getAppearance().getNormalAppearance().getAppearanceStream(); - assertNotNull("Appearance stream shall not be null", appearanceStream); - assertEquals(rectangle.getLowerLeftX(), appearanceStream.getBBox().getLowerLeftX(), DELTA); - assertEquals(rectangle.getLowerLeftY(), appearanceStream.getBBox().getLowerLeftY(), DELTA); - assertEquals(rectangle.getWidth(), appearanceStream.getBBox().getWidth(), DELTA); - assertEquals(rectangle.getHeight(), appearanceStream.getBBox().getHeight(), DELTA); - - Matrix matrix = appearanceStream.getMatrix(); - assertNotNull("Matrix shall not be null", matrix); - - // should have been translated to a 0 origin - assertEquals(-rectangle.getLowerLeftX(), matrix.getTranslateX(), DELTA); - assertEquals(-rectangle.getLowerLeftY(), matrix.getTranslateY(), DELTA); - - // test the content of the apperance stream - PDStream contentStream = appearanceStream.getContentStream(); - assertNotNull("Content stream shall not be null", contentStream); - PDFStreamParser parser = new PDFStreamParser(appearanceStream); - parser.parse(); - List tokens = parser.getTokens(); - - // the samples content stream should contain 10 tokens - assertEquals(10, tokens.size()); - - // setting of the stroking color - assertEquals(1, ((COSInteger) tokens.get(0)).intValue()); - assertEquals(0, ((COSInteger) tokens.get(1)).intValue()); - assertEquals(0, ((COSInteger) tokens.get(2)).intValue()); - assertEquals("RG", ((Operator) tokens.get(3)).getName()); - - // setting of the rectangle for the border - // it shall be inset by the border width - assertEquals(rectangle.getLowerLeftX() + borderWidth, ((COSFloat) tokens.get(4)).floatValue(), DELTA); - assertEquals(rectangle.getLowerLeftY() + borderWidth, ((COSFloat) tokens.get(5)).floatValue(), DELTA); - assertEquals(rectangle.getWidth() - 2 * borderWidth, ((COSFloat) tokens.get(6)).floatValue(), DELTA); - assertEquals(rectangle.getHeight() - 2 * borderWidth, ((COSFloat) tokens.get(7)).floatValue(), DELTA); - assertEquals("re", ((Operator) tokens.get(8)).getName()); - assertEquals("S", ((Operator) tokens.get(9)).getName()); - - document.close(); + try (PDDocument document = PDDocument.load(file)) + { + PDPage page = document.getPage(0); + List annotations = page.getAnnotations(); + + PDAnnotationSquareCircle annotation = (PDAnnotationSquareCircle) annotations.get(0); + + // test the correct setting of the appearance stream + assertNotNull("Appearance dictionary shall not be null", annotation.getAppearance()); + assertNotNull("Normal appearance shall not be null", annotation.getAppearance().getNormalAppearance()); + PDAppearanceStream appearanceStream = annotation.getAppearance().getNormalAppearance().getAppearanceStream(); + assertNotNull("Appearance stream shall not be null", appearanceStream); + assertEquals(rectangle.getLowerLeftX(), appearanceStream.getBBox().getLowerLeftX(), DELTA); + assertEquals(rectangle.getLowerLeftY(), appearanceStream.getBBox().getLowerLeftY(), DELTA); + assertEquals(rectangle.getWidth(), appearanceStream.getBBox().getWidth(), DELTA); + assertEquals(rectangle.getHeight(), appearanceStream.getBBox().getHeight(), DELTA); + + Matrix matrix = appearanceStream.getMatrix(); + assertNotNull("Matrix shall not be null", matrix); + + // should have been translated to a 0 origin + assertEquals(-rectangle.getLowerLeftX(), matrix.getTranslateX(), DELTA); + assertEquals(-rectangle.getLowerLeftY(), matrix.getTranslateY(), DELTA); + + // test the content of the apperance stream + PDStream contentStream = appearanceStream.getContentStream(); + assertNotNull("Content stream shall not be null", contentStream); + PDFStreamParser parser = new PDFStreamParser(appearanceStream); + parser.parse(); + List tokens = parser.getTokens(); + + // the samples content stream should contain 10 tokens + assertEquals(10, tokens.size()); + + // setting of the stroking color + assertEquals(1, ((COSInteger) tokens.get(0)).intValue()); + assertEquals(0, ((COSInteger) tokens.get(1)).intValue()); + assertEquals(0, ((COSInteger) tokens.get(2)).intValue()); + assertEquals("RG", ((Operator) tokens.get(3)).getName()); + + // setting of the rectangle for the border + // it shall be inset by the border width + assertEquals(rectangle.getLowerLeftX() + borderWidth, ((COSFloat) tokens.get(4)).floatValue(), DELTA); + assertEquals(rectangle.getLowerLeftY() + borderWidth, ((COSFloat) tokens.get(5)).floatValue(), DELTA); + assertEquals(rectangle.getWidth() - 2 * borderWidth, ((COSFloat) tokens.get(6)).floatValue(), DELTA); + assertEquals(rectangle.getHeight() - 2 * borderWidth, ((COSFloat) tokens.get(7)).floatValue(), DELTA); + assertEquals("re", ((Operator) tokens.get(8)).getName()); + assertEquals("S", ((Operator) tokens.get(9)).getName()); + } } }