Skip to content

Commit a6905f1

Browse files
committed
Make PdfPolyGeomAnnotation abstract
Add package private PdfPolygonAnnotation and PdfPolylineAnnotation DEVSIX-526
1 parent dbc6439 commit a6905f1

File tree

4 files changed

+140
-17
lines changed

4 files changed

+140
-17
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/annot/PdfAnnotation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,10 @@ public static PdfAnnotation makeAnnotation(PdfObject pdfObject) {
301301
annotation = new PdfCircleAnnotation((PdfDictionary) pdfObject);
302302
} else if (PdfName.Line.equals(subtype)) {
303303
annotation = new PdfLineAnnotation((PdfDictionary) pdfObject);
304-
} else if (PdfName.Polygon.equals(subtype) || PdfName.PolyLine.equals(subtype)) {
305-
annotation = new PdfPolyGeomAnnotation((PdfDictionary) pdfObject);
304+
} else if (PdfName.Polygon.equals(subtype)) {
305+
annotation = new PdfPolygonAnnotation((PdfDictionary) pdfObject);
306+
} else if (PdfName.PolyLine.equals(subtype)) {
307+
annotation = new PdfPolylineAnnotation((PdfDictionary) pdfObject);
306308
} else if (PdfName.Redact.equals(subtype)) {
307309
annotation = new PdfRedactAnnotation((PdfDictionary) pdfObject);
308310
} else if (PdfName.Watermark.equals(subtype)) {

kernel/src/main/java/com/itextpdf/kernel/pdf/annot/PdfPolyGeomAnnotation.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,23 @@ This file is part of the iText (R) project.
5555
import org.slf4j.LoggerFactory;
5656
import com.itextpdf.kernel.pdf.PdfObject;
5757

58-
public class PdfPolyGeomAnnotation extends PdfMarkupAnnotation {
58+
public abstract class PdfPolyGeomAnnotation extends PdfMarkupAnnotation {
5959

6060
private static final long serialVersionUID = -9038993253308315792L;
6161

6262
/**
63-
* Subtypes
63+
* @deprecated , use {@link PdfName#Polygon} instead.
6464
*/
65+
@Deprecated
6566
public static final PdfName Polygon = PdfName.Polygon;
67+
/**
68+
* @deprecated , use {@link PdfName#PolyLine} instead.
69+
*/
70+
@Deprecated
6671
public static final PdfName PolyLine = PdfName.PolyLine;
6772

68-
private PdfPolyGeomAnnotation(Rectangle rect, PdfName subtype, float[] vertices) {
73+
PdfPolyGeomAnnotation(Rectangle rect, float[] vertices) {
6974
super(rect);
70-
setSubtype(subtype);
7175
setVertices(vertices);
7276
}
7377

@@ -79,16 +83,11 @@ protected PdfPolyGeomAnnotation(PdfDictionary pdfObject) {
7983
}
8084

8185
public static PdfPolyGeomAnnotation createPolygon(Rectangle rect, float[] vertices) {
82-
return new PdfPolyGeomAnnotation(rect, Polygon, vertices);
86+
return new PdfPolygonAnnotation(rect, vertices);
8387
}
8488

8589
public static PdfPolyGeomAnnotation createPolyLine(Rectangle rect, float[] vertices) {
86-
return new PdfPolyGeomAnnotation(rect, PolyLine, vertices);
87-
}
88-
89-
@Override
90-
public PdfName getSubtype() {
91-
return getPdfObject().getAsName(PdfName.Subtype);
90+
return new PdfPolylineAnnotation(rect, vertices);
9291
}
9392

9493
public PdfArray getVertices() {
@@ -163,10 +162,6 @@ public PdfPolyGeomAnnotation setPath(PdfArray path) {
163162
return (PdfPolyGeomAnnotation) put(PdfName.Path, path);
164163
}
165164

166-
private void setSubtype(PdfName subtype) {
167-
put(PdfName.Subtype, subtype);
168-
}
169-
170165
/**
171166
* The dictionaries for some annotation types (such as free text and polygon annotations) can include the BS entry.
172167
* That entry specifies a border style dictionary that has more settings than the array specified for the Border
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2019 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.kernel.pdf.annot;
44+
45+
import com.itextpdf.kernel.geom.Rectangle;
46+
import com.itextpdf.kernel.pdf.PdfDictionary;
47+
import com.itextpdf.kernel.pdf.PdfName;
48+
49+
class PdfPolygonAnnotation extends PdfPolyGeomAnnotation {
50+
51+
PdfPolygonAnnotation(PdfDictionary pdfObject) {
52+
super(pdfObject);
53+
}
54+
55+
PdfPolygonAnnotation(Rectangle rect, float[] vertices) {
56+
super(rect, vertices);
57+
}
58+
59+
@Override
60+
public PdfName getSubtype() {
61+
return PdfName.Polygon;
62+
}
63+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2019 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.kernel.pdf.annot;
44+
45+
import com.itextpdf.kernel.geom.Rectangle;
46+
import com.itextpdf.kernel.pdf.PdfDictionary;
47+
import com.itextpdf.kernel.pdf.PdfName;
48+
49+
class PdfPolylineAnnotation extends PdfPolyGeomAnnotation {
50+
51+
PdfPolylineAnnotation(Rectangle rect, float[] vertices) {
52+
super(rect, vertices);
53+
}
54+
55+
PdfPolylineAnnotation(PdfDictionary pdfObject) {
56+
super(pdfObject);
57+
}
58+
59+
@Override
60+
public PdfName getSubtype() {
61+
return PdfName.PolyLine;
62+
}
63+
}

0 commit comments

Comments
 (0)