PDFAnnotationUtils.java
6.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASMatrix
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASRectangle
*/
package com.adobe.internal.pdftoolkit.pdf.interactive.annotation;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASMatrix;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASRectangle;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosUtils;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.graphics.PDFRectangle;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotation;
import java.util.ArrayList;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
class PDFAnnotationUtils {
PDFAnnotationUtils() {
}
static double[] getInteriorColor(PDFAnnotation pdfAnnot) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (pdfAnnot == null) {
throw new PDFInvalidDocumentException("PDFAnnotation is null");
}
CosArray cosColor = pdfAnnot.getDictionaryArrayValue(ASName.k_IC);
if (cosColor == null) {
return null;
}
return cosColor.getArrayDouble();
}
static void setInteriorColor(double[] color, PDFAnnotation pdfAnnot) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (pdfAnnot == null) {
throw new PDFInvalidDocumentException("Annotation is null");
}
CosArray cosColor = null;
if (color != null && color.length != 0) {
cosColor = PDFCosUtils.newCosArray(pdfAnnot.getPDFDocument());
for (int i = 0; i < color.length; ++i) {
cosColor.addDouble(color[i]);
}
}
pdfAnnot.setDictionaryArrayValue(ASName.k_IC, cosColor);
}
static void setHighlight(String highlight, PDFAnnotation pdfAnnot) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (pdfAnnot == null) {
throw new PDFInvalidDocumentException("Annotation is null");
}
if (highlight != null) {
if (highlight.equalsIgnoreCase("push")) {
pdfAnnot.setDictionaryNameValue(ASName.k_H, "P");
}
if (highlight.equalsIgnoreCase("outline")) {
pdfAnnot.setDictionaryNameValue(ASName.k_H, "O");
}
if (highlight.equalsIgnoreCase("invert")) {
pdfAnnot.setDictionaryNameValue(ASName.k_H, "I");
}
if (highlight.equalsIgnoreCase("none")) {
pdfAnnot.setDictionaryNameValue(ASName.k_H, "N");
}
if (highlight.equalsIgnoreCase("p")) {
pdfAnnot.setDictionaryNameValue(ASName.k_H, "P");
}
if (highlight.equalsIgnoreCase("o")) {
pdfAnnot.setDictionaryNameValue(ASName.k_H, "O");
}
if (highlight.equalsIgnoreCase("i")) {
pdfAnnot.setDictionaryNameValue(ASName.k_H, "I");
}
if (highlight.equalsIgnoreCase("n")) {
pdfAnnot.setDictionaryNameValue(ASName.k_H, "N");
}
}
}
static double[] transformFringe(PDFAnnotation annot, ASMatrix matrix, double rotationAngle, double[] fringe) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
double[] newFringe = null;
if (fringe != null) {
PDFDocument doc = annot.getPDFDocument();
PDFRectangle annotRect = annot.getRect().normalized(doc);
ASRectangle fringedRect = new ASRectangle(annotRect.left() + fringe[0], annotRect.bottom() + fringe[3], annotRect.right() - fringe[2], annotRect.top() - fringe[1]);
PDFRectangle transAnnotRect = PDFRectangle.newInstance(doc, annotRect.getRectangle().transform(matrix)).normalized(doc);
PDFRectangle transFringedRect = PDFRectangle.newInstance(doc, fringedRect.transform(matrix)).normalized(doc);
newFringe = new double[]{transFringedRect.left() - transAnnotRect.left(), transAnnotRect.top() - transFringedRect.top(), transAnnotRect.right() - transFringedRect.right(), transFringedRect.bottom() - transAnnotRect.bottom()};
}
return newFringe;
}
static double[] transfromRectangle(double[] rect, double width, double height, int rotationAngle) {
double[] newRect = new double[rect.length];
switch (rotationAngle) {
case 0: {
return rect;
}
case 90: {
for (int i = 0; i < rect.length; i += 2) {
newRect[i] = width - rect[i + 1];
newRect[i + 1] = rect[i];
}
break;
}
case 180: {
for (int i = 0; i < rect.length; i += 2) {
newRect[i] = width - rect[i];
newRect[i + 1] = height - rect[i + 1];
}
break;
}
case 270: {
for (int i = 0; i < rect.length; i += 2) {
newRect[i] = rect[i + 1];
newRect[i + 1] = height - rect[i];
}
break;
}
}
return newRect;
}
static ArrayList<Double> getList(double[] array) {
ArrayList<Double> list = new ArrayList<Double>();
for (int i = 0; i < array.length; ++i) {
list.add(array[i]);
}
return list;
}
}