@@ -22,22 +22,16 @@ This file is part of the iText (R) project.
22
22
*/
23
23
package com .itextpdf .pdfua .checkers .utils ;
24
24
25
- import com .itextpdf .commons .utils .MessageFormatUtil ;
26
- import com .itextpdf .kernel .exceptions .PdfException ;
27
- import com .itextpdf .kernel .pdf .PdfArray ;
28
25
import com .itextpdf .kernel .pdf .PdfDictionary ;
29
- import com .itextpdf .kernel .pdf .PdfName ;
30
- import com .itextpdf .kernel .pdf .PdfObject ;
31
- import com .itextpdf .kernel .pdf .annot .PdfAnnotation ;
32
26
import com .itextpdf .kernel .pdf .tagging .IStructureNode ;
33
- import com .itextpdf .kernel .pdf .tagging .PdfObjRef ;
34
- import com .itextpdf .kernel .pdf .tagging .PdfStructElem ;
35
- import com .itextpdf .pdfua .exceptions .PdfUAConformanceException ;
36
- import com .itextpdf .pdfua .exceptions .PdfUAExceptionMessageConstants ;
27
+ import com .itextpdf .pdfua .checkers .utils .ua1 .PdfUA1AnnotationChecker ;
37
28
38
29
/**
39
30
* Class that provides methods for checking PDF/UA compliance of annotations.
31
+ *
32
+ * @deprecated in favor of {@link PdfUA1AnnotationChecker}
40
33
*/
34
+ @ Deprecated
41
35
public final class AnnotationCheckUtil {
42
36
private AnnotationCheckUtil () {
43
37
// Empty constructor.
@@ -48,36 +42,18 @@ private AnnotationCheckUtil() {
48
42
* set and annotation intersects CropBox (default value is MediaBox).
49
43
*
50
44
* @param annotDict annotation to check
51
- *
52
45
* @return {@code true} if annotation should be checked, otherwise {@code false}
53
46
*/
54
47
public static boolean isAnnotationVisible (PdfDictionary annotDict ) {
55
- if (annotDict .getAsNumber (PdfName .F ) != null ) {
56
- int flags = annotDict .getAsNumber (PdfName .F ).intValue ();
57
- if ((flags & PdfAnnotation .HIDDEN ) != 0 ) {
58
- return false ;
59
- }
60
- }
61
- if (annotDict .getAsDictionary (PdfName .P ) != null ) {
62
- PdfDictionary page = annotDict .getAsDictionary (PdfName .P );
63
- PdfArray pageBox = page .getAsArray (PdfName .CropBox ) == null ? page .getAsArray (PdfName .MediaBox ) : page .getAsArray (PdfName .CropBox );
64
- if (pageBox != null && annotDict .getAsArray (PdfName .Rect ) != null ) {
65
- PdfArray annotBox = annotDict .getAsArray (PdfName .Rect );
66
- try {
67
- if (pageBox .toRectangle ().getIntersection (annotBox .toRectangle ()) == null ) {
68
- return false ;
69
- }
70
- } catch (PdfException ignore ) {
71
- // ignore
72
- }
73
- }
74
- }
75
- return true ;
48
+ return PdfUA1AnnotationChecker .isAnnotationVisible (annotDict );
76
49
}
77
50
78
51
/**
79
52
* Helper class that checks the conformance of annotations while iterating the tag tree structure.
53
+ *
54
+ * @deprecated in favor of {@link PdfUA1AnnotationChecker.PdfUA1AnnotationHandler}
80
55
*/
56
+ @ Deprecated
81
57
public static class AnnotationHandler extends ContextAwareTagTreeIteratorHandler {
82
58
83
59
/**
@@ -96,70 +72,7 @@ public boolean accept(IStructureNode node) {
96
72
97
73
@ Override
98
74
public void processElement (IStructureNode elem ) {
99
- if (!(elem instanceof PdfObjRef )) {
100
- return ;
101
- }
102
- PdfObjRef objRef = (PdfObjRef ) elem ;
103
- PdfDictionary annotObj = objRef .getReferencedObject ();
104
- if (annotObj == null ) {
105
- return ;
106
- }
107
-
108
- if (annotObj .getAsDictionary (PdfName .P ) != null ) {
109
- PdfDictionary pageDict = annotObj .getAsDictionary (PdfName .P );
110
- if (!PdfName .S .equals (pageDict .getAsName (PdfName .Tabs ))) {
111
- throw new PdfUAConformanceException (PdfUAExceptionMessageConstants .PAGE_WITH_ANNOT_DOES_NOT_HAVE_TABS_WITH_S );
112
- }
113
- }
114
-
115
- PdfName subtype = annotObj .getAsName (PdfName .Subtype );
116
-
117
- if (!isAnnotationVisible (annotObj ) || PdfName .Popup .equals (subtype )) {
118
- return ;
119
- }
120
-
121
- if (PdfName .PrinterMark .equals (subtype )) {
122
- throw new PdfUAConformanceException (PdfUAExceptionMessageConstants .PRINTER_MARK_IS_NOT_PERMITTED );
123
- }
124
-
125
- if (PdfName .TrapNet .equals (subtype )) {
126
- throw new PdfUAConformanceException (PdfUAExceptionMessageConstants .ANNOT_TRAP_NET_IS_NOT_PERMITTED );
127
- }
128
-
129
- PdfStructElem parent = (PdfStructElem ) objRef .getParent ();
130
- if (!PdfName .Widget .equals (subtype ) &&
131
- !(annotObj .containsKey (PdfName .Contents ) || (parent != null && parent .getAlt () != null ))) {
132
- throw new PdfUAConformanceException (MessageFormatUtil .format (
133
- PdfUAExceptionMessageConstants .ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_OR_ALT_KEY , subtype .getValue ()));
134
- }
135
-
136
- if (PdfName .Link .equals (subtype )) {
137
- PdfStructElem parentLink = context .getElementIfRoleMatches (PdfName .Link , objRef .getParent ());
138
- if (parentLink == null ) {
139
- throw new PdfUAConformanceException (
140
- PdfUAExceptionMessageConstants .LINK_ANNOT_IS_NOT_NESTED_WITHIN_LINK );
141
- }
142
- if (!annotObj .containsKey (PdfName .Contents )) {
143
- throw new PdfUAConformanceException (PdfUAExceptionMessageConstants .LINK_ANNOTATION_SHOULD_HAVE_CONTENTS_KEY );
144
- }
145
- }
146
-
147
- if (PdfName .Screen .equals (subtype )) {
148
- PdfDictionary action = annotObj .getAsDictionary (PdfName .A );
149
- PdfDictionary additionalActions = annotObj .getAsDictionary (PdfName .AA );
150
- ActionCheckUtil .checkAction (action );
151
- checkAAEntry (additionalActions );
152
- }
153
- }
154
-
155
- private static void checkAAEntry (PdfDictionary additionalActions ) {
156
- if (additionalActions != null ) {
157
- for (PdfObject val : additionalActions .values ()) {
158
- if (val instanceof PdfDictionary ) {
159
- ActionCheckUtil .checkAction ((PdfDictionary ) val );
160
- }
161
- }
162
- }
75
+ PdfUA1AnnotationChecker .checkElement (this .context , elem );
163
76
}
164
77
}
165
78
}
0 commit comments