GState.java
12.6 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* 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.ASCoordinate
* 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.content.processor;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
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.ASCoordinate;
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.content.processor.Path;
import com.adobe.internal.pdftoolkit.pdf.content.processor.TextState;
import com.adobe.internal.pdftoolkit.pdf.graphics.PDFDashPattern;
import com.adobe.internal.pdftoolkit.pdf.graphics.PDFExtGState;
import com.adobe.internal.pdftoolkit.pdf.graphics.PDFLineCap;
import com.adobe.internal.pdftoolkit.pdf.graphics.PDFLineJoin;
import com.adobe.internal.pdftoolkit.pdf.graphics.colorspaces.PDFRenderingIntent;
import com.adobe.internal.pdftoolkit.pdf.graphics.optionalcontent.PDFOCObject;
import java.awt.Shape;
import java.awt.geom.Area;
public class GState {
private PDFOCObject ocGroup;
private ASMatrix ctm = ASMatrix.createIdentityMatrix();
protected Area clippingArea;
private double lineWidth = 1.0;
private PDFLineCap lineCap = PDFLineCap.BUTT_CAP;
private PDFLineJoin lineJoin = PDFLineJoin.MITER_JOIN;
private double miterLimit = 10.0;
private PDFDashPattern dashPattern = new PDFDashPattern();
private PDFRenderingIntent renderingIntent = PDFRenderingIntent.RELATIVE_COLORIMETRIC;
private boolean strokeAdjustment = false;
private ASName[] blendMode = null;
private CosDictionary softMask = null;
private double strokeAlpha = 1.0;
private double nonStrokeAlpha = 1.0;
private boolean alphaSource = false;
private double alphaConstant = 1.0;
private boolean strokeOverprint = false;
private boolean nonStrokeOverprint = false;
private int overprintMode = 0;
private double flatness = 1.0;
private double smoothness = 0.0;
private boolean textKnockout = true;
private TextState textState = new TextState();
private ASName useBlackPTComp = ASName.k_Default;
protected boolean isClipAreaInfinite = false;
public GState(ASRectangle clipRect) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.clippingArea = new Area(new Path(clipRect).getShape());
}
public GState() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.isClipAreaInfinite = true;
}
protected void initClippingArea() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASRectangle rect = new ASRectangle(-3.4028234663852886E38, -3.4028234663852886E38, 3.4028234663852886E38, 3.4028234663852886E38);
this.clippingArea = new Area(new Path(rect).getShape());
}
public GState(GState gState) {
this.ctm = gState.ctm;
if (gState.clippingArea != null) {
this.clippingArea = new Area(gState.clippingArea);
}
this.lineWidth = gState.lineWidth;
this.lineCap = gState.lineCap;
this.lineJoin = gState.lineJoin;
this.miterLimit = gState.miterLimit;
this.dashPattern = new PDFDashPattern(gState.dashPattern);
this.renderingIntent = gState.renderingIntent;
this.strokeAdjustment = gState.strokeAdjustment;
this.strokeAlpha = gState.strokeAlpha;
this.nonStrokeAlpha = gState.nonStrokeAlpha;
this.alphaSource = gState.alphaSource;
this.alphaConstant = gState.alphaConstant;
this.strokeOverprint = gState.strokeOverprint;
this.nonStrokeOverprint = gState.nonStrokeOverprint;
this.flatness = gState.flatness;
this.smoothness = gState.smoothness;
this.ocGroup = gState.ocGroup;
this.textState = new TextState(gState.textState);
this.isClipAreaInfinite = gState.isClipAreaInfinite;
this.blendMode = gState.getBlendMode();
this.softMask = gState.getSoftMask();
this.overprintMode = gState.getOverprintMode();
}
public ASMatrix getCTM() {
return this.ctm;
}
public void setCTM(ASMatrix ctm) {
this.ctm = ctm;
}
public void addPathToClip(Path clipPath) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.isClipAreaInfinite = false;
if (this.clippingArea == null) {
this.initClippingArea();
}
this.clippingArea.intersect(clipPath.getArea());
}
public double getLineWidth() {
return this.lineWidth;
}
public void setLineWidth(double lineWidth) {
this.lineWidth = lineWidth;
}
public PDFLineCap getLineCap() {
return this.lineCap;
}
public void setLineCap(PDFLineCap lineCap) {
this.lineCap = lineCap;
}
public PDFLineJoin getLineJoin() {
return this.lineJoin;
}
public void setLineJoin(PDFLineJoin lineJoin) {
this.lineJoin = lineJoin;
}
public double getMiterLimit() {
return this.miterLimit;
}
public void setMiterLimit(double miterLimit) {
this.miterLimit = miterLimit;
}
public PDFDashPattern getDashPattern() {
return this.dashPattern;
}
public void setDashPattern(PDFDashPattern dashPattern) {
this.dashPattern = dashPattern;
}
public PDFRenderingIntent getRenderingIntent() {
return this.renderingIntent;
}
public void setRenderingIntent(PDFRenderingIntent intent) {
this.renderingIntent = intent;
}
public boolean getStrokeAdjustment() {
return this.strokeAdjustment;
}
public void setStrokeAdjustment(boolean strokeAdjustment) {
this.strokeAdjustment = strokeAdjustment;
}
public double getStrokeAlpha() {
return this.strokeAlpha;
}
public void setStrokeAlpha(double alpha) {
this.strokeAlpha = alpha;
}
public double getNonStrokeAlpha() {
return this.nonStrokeAlpha;
}
public void setNonStrokeAlpha(double alpha) {
this.nonStrokeAlpha = alpha;
}
public boolean getAlphaSource() {
return this.alphaSource;
}
public void setAlphaSource(boolean alphaSource) {
this.alphaSource = alphaSource;
}
public double getAlphaConstant() {
return this.alphaConstant;
}
public void setAlphaConstant(double alphaConstant) {
this.alphaConstant = alphaConstant;
}
public boolean getStrokeOverprint() {
return this.strokeOverprint;
}
public void setStrokeOverprint(boolean overprint) {
this.strokeOverprint = overprint;
}
public boolean getNonStrokeOverprint() {
return this.nonStrokeOverprint;
}
public void setNonStrokeOverprint(boolean overprint) {
this.nonStrokeOverprint = overprint;
}
public int getOverprintMode() {
return this.overprintMode;
}
public void setOverprintMode(int overprintMode) {
this.overprintMode = overprintMode;
}
public double getFlatness() {
return this.flatness;
}
public void setFlatness(double flatness) {
this.flatness = flatness;
}
public double getSmoothness() {
return this.smoothness;
}
public void setSmoothness(double smoothness) {
this.smoothness = smoothness;
}
public CosDictionary getSoftMask() {
return this.softMask;
}
public void setSoftMask(CosDictionary softMask) {
this.softMask = softMask;
}
public boolean getTextKnockout() {
return this.textKnockout;
}
public void setTextKnockout(boolean textKnockout) {
this.textKnockout = textKnockout;
}
public TextState getTextState() {
return this.textState;
}
public void setTextState(TextState textState) {
this.textState = textState;
}
public ASName getUseBlackPTComp() {
return this.useBlackPTComp;
}
public void setUseBlackPTComp(ASName useBlackPTComp) {
this.useBlackPTComp = useBlackPTComp;
}
public PDFOCObject getOcGroup() {
return this.ocGroup;
}
public void setOcGroup(PDFOCObject ocGroup) {
this.ocGroup = ocGroup;
}
public void setBlendMode(ASName[] bleandMode) {
this.blendMode = bleandMode;
}
public ASName[] getBlendMode() {
return this.blendMode;
}
public void loadExtGState(PDFExtGState extGState) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (extGState != null) {
CosObject value;
if (extGState.hasLineWidth()) {
this.setLineWidth(extGState.getLineWidth());
}
if (extGState.hasLineCap()) {
try {
this.setLineCap(PDFLineCap.getInstance(extGState.getLineCap()));
}
catch (PDFInvalidParameterException e) {
throw new PDFInvalidDocumentException((Throwable)e);
}
}
if (extGState.hasLineJoin()) {
try {
this.setLineJoin(PDFLineJoin.getInstance(extGState.getLineJoin()));
}
catch (PDFInvalidParameterException e) {
throw new PDFInvalidDocumentException((Throwable)e);
}
}
if (extGState.hasMiterLimit()) {
this.setMiterLimit(extGState.getMiterLimit());
}
if (extGState.hasRenderingIntent()) {
PDFRenderingIntent intent = PDFRenderingIntent.getIntentForValue(extGState.getRenderingIntent());
if (intent == null) {
throw new PDFInvalidDocumentException("unrecognized rendering intent");
}
this.setRenderingIntent(intent);
}
if (extGState.hasOverprintStroke()) {
this.setStrokeOverprint(extGState.getOverprintStroke());
}
if (extGState.hasOverprintFill()) {
this.setNonStrokeOverprint(extGState.getOverprintFill());
} else if (extGState.hasOverprintStroke()) {
this.setNonStrokeOverprint(extGState.getOverprintStroke());
}
if (extGState.hasOverprintMode()) {
this.setOverprintMode(extGState.getOverprintMode());
}
if (extGState.hasFlatness()) {
this.setFlatness(extGState.getFlatness());
}
if (extGState.hasSmoothness()) {
this.setSmoothness(extGState.getSmoothness());
}
if (extGState.haStrokeAdjustment()) {
this.setStrokeAdjustment(extGState.getStrokeAdjustment());
}
if (extGState.hasOpacityStroke()) {
this.setStrokeAlpha(extGState.getOpacityStroke());
}
if (extGState.hasOpacityFill()) {
this.setNonStrokeAlpha(extGState.getOpacityFill());
}
if (extGState.hasAlphaSource()) {
this.setAlphaSource(extGState.getAlphaSource());
}
if (extGState.hasTextKnockout()) {
this.setTextKnockout(extGState.getTextKnockout());
}
if (extGState.hasBlendMode()) {
this.setBlendMode(extGState.getBlendMode());
}
if (extGState.hasSoftMask() && (value = extGState.getCosDictionary().get(ASName.k_SMask)) instanceof CosDictionary) {
this.setSoftMask((CosDictionary)value);
}
}
}
public boolean pointInsideClippingPath(ASCoordinate point) {
return this.isClipAreaInfinite || this.clippingArea.contains(point.x(), point.y());
}
}