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 44B57200AE4 for ; Thu, 26 May 2016 01:24:31 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 43145160A39; Wed, 25 May 2016 23:24:31 +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 406CC160A29 for ; Thu, 26 May 2016 01:24:30 +0200 (CEST) Received: (qmail 45172 invoked by uid 500); 25 May 2016 22:54:21 -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 44624 invoked by uid 99); 25 May 2016 22:51:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 May 2016 22:51:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id DBCE618055A for ; Wed, 25 May 2016 22:51:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.799 X-Spam-Level: * X-Spam-Status: No, score=1.799 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id i-ymKfj0NhT6 for ; Wed, 25 May 2016 22:51:00 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with ESMTP id B41755F46D for ; Wed, 25 May 2016 22:50:59 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 88DD7E0178 for ; Wed, 25 May 2016 22:50:58 +0000 (UTC) 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 A592C3A01DD for ; Wed, 25 May 2016 22:50:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1745546 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation: PDAnnotationSquareCircle.java PDAppearanceContentStream.java handlers/PDCircleAppearanceHandler.java handlers/PDSquareAppearanceHandler.java Date: Wed, 25 May 2016 22:50:57 -0000 To: commits@pdfbox.apache.org From: msahyoun@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160525225057.A592C3A01DD@svn01-us-west.apache.org> archived-at: Wed, 25 May 2016 23:24:31 -0000 Author: msahyoun Date: Wed May 25 22:50:56 2016 New Revision: 1745546 URL: http://svn.apache.org/viewvc?rev=1745546&view=rev Log: PDFBOX-3353: add support for circle annotations Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java (with props) Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceContentStream.java pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java?rev=1745546&r1=1745545&r2=1745546&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java Wed May 25 22:50:56 2016 @@ -23,6 +23,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDAppearanceHandler; +import org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDCircleAppearanceHandler; import org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDSquareAppearanceHandler; /** @@ -34,6 +35,8 @@ public class PDAnnotationSquareCircle ex { private PDAppearanceHandler squareAppearanceHandler; + private PDAppearanceHandler circleAppearanceHandler; + /** * Constant for a Rectangular type of annotation. */ @@ -74,6 +77,16 @@ public class PDAnnotationSquareCircle ex this.squareAppearanceHandler = squareAppearanceHandler; } + /** + * Set a custom appearance handler for generating the annotations appearance streams. + * + * @param circleAppearanceHandler + */ + public void setCustomCircleAppearanceHandler(PDAppearanceHandler circleAppearanceHandler) + { + this.circleAppearanceHandler = circleAppearanceHandler; + } + public void constructAppearances() { if (getSubtype() == SUB_TYPE_SQUARE) @@ -88,9 +101,17 @@ public class PDAnnotationSquareCircle ex squareAppearanceHandler.generateAppearanceStreams(); } } - else if (getSubtype() == SUB_TYPE_SQUARE) + else if (getSubtype() == SUB_TYPE_CIRCLE) { - + if (circleAppearanceHandler == null) + { + PDCircleAppearanceHandler appearanceHandler = new PDCircleAppearanceHandler(this); + appearanceHandler.generateAppearanceStreams(); + } + else + { + circleAppearanceHandler.generateAppearanceStreams(); + } } } Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceContentStream.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceContentStream.java?rev=1745546&r1=1745545&r2=1745546&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceContentStream.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceContentStream.java Wed May 25 22:50:56 2016 @@ -250,7 +250,7 @@ public final class PDAppearanceContentSt * @param hasBackground shall there be a background color. * @throws IOException if an IO error occurs while writing to the stream. */ - public void closePath(float lineWidth, boolean hasBackground) throws IOException + public void drawShape(float lineWidth, boolean hasBackground) throws IOException { if (lineWidth < 1e-6) { writeOperator("n"); Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java?rev=1745546&view=auto ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java (added) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java Wed May 25 22:50:56 2016 @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.pdfbox.pdmodel.interactive.annotation.handlers; + +import java.io.IOException; + +import org.apache.pdfbox.cos.COSArray; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceContentStream; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary; + +/** + * Handler to generate the square annotations appearance. + * + */ +public class PDCircleAppearanceHandler extends PDAbstractAppearanceHandler +{ + + public PDCircleAppearanceHandler(PDAnnotation annotation) + { + super(annotation); + } + + @Override + public void generateAppearanceStreams() + { + generateNormalAppearance(); + generateRolloverAppearance(); + generateDownAppearance(); + } + + @Override + public void generateNormalAppearance() + { + float lineWidth = getLineWidth(); + try + { + PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream();; + contentStream.setStrokingColorOnDemand(getColor()); + boolean hasBackground = contentStream + .setNonStrokingColorOnDemand(((PDAnnotationSquareCircle) getAnnotation()).getInteriorColor()); + + handleOpacity(((PDAnnotationSquareCircle) getAnnotation()).getConstantOpacity()); + + contentStream.setBorderLine(lineWidth, ((PDAnnotationSquareCircle) getAnnotation()).getBorderStyle()); + + // the differences rectangle + // TODO: this only works for border effect solid. Cloudy needs a different approach. + setRectDifference(lineWidth); + + // Acrobat applies a padding to each side of the bbox so the line is completely within + // the bbox. + // TODO: Needs validation for Circles as Adobe Reader seems to extend the bbox bei the rect differenve + // for circle annotations. + PDRectangle bbox = getRectangle(); + PDRectangle borderEdge = getPaddedRectangle(bbox,lineWidth/2); + + // lower left corner + float x0 = borderEdge.getLowerLeftX(); + float y0 = borderEdge.getLowerLeftY(); + // upper right corner + float x1 = borderEdge.getUpperRightX(); + float y1 = borderEdge.getUpperRightY(); + // mid points + float xm = x0 + borderEdge.getWidth() / 2; + float ym = y0 + borderEdge.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 = borderEdge.getHeight() / 2 * magic; + float hOffset = borderEdge.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, hasBackground); + contentStream.close(); + } catch (IOException e) + { + e.printStackTrace(); + } + } + + @Override + public void generateRolloverAppearance() + { + // TODO to be implemented + } + + @Override + public void generateDownAppearance() + { + // TODO to be implemented + } + + /** + * Get the line with of the border. + * + * Get the width of the line used to draw a border around the annotation. + * This may either be specified by the annotation dictionaries Border + * setting or by the W entry in the BS border style dictionary. If both are + * missing the default width is 1. + * + * @return the line width + */ + // TODO: according to the PDF spec the use of the BS entry is annotation + // specific + // so we will leave that to be implemented by individual handlers. + // If at the end all annotations support the BS entry this can be handled + // here and removed from the individual handlers. + float getLineWidth() + { + PDAnnotationSquareCircle annotation = (PDAnnotationSquareCircle) getAnnotation(); + + PDBorderStyleDictionary bs = annotation.getBorderStyle(); + + if (bs != null) + { + return bs.getWidth(); + } else + { + COSArray borderCharacteristics = annotation.getBorder(); + if (borderCharacteristics != null && borderCharacteristics.size() >= 3) + { + return borderCharacteristics.getInt(3); + } + } + + return 1; + } +} Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java?rev=1745546&r1=1745545&r2=1745546&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java Wed May 25 22:50:56 2016 @@ -71,7 +71,7 @@ public class PDSquareAppearanceHandler e contentStream.addRect(borderEdge.getLowerLeftX() , borderEdge.getLowerLeftY(), borderEdge.getWidth(), borderEdge.getHeight()); - contentStream.closePath(lineWidth, hasBackground); + contentStream.drawShape(lineWidth, hasBackground); contentStream.close(); } catch (IOException e)