InstructionFactory.java
18 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.io.stream.InputByteStream
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFParseException
* com.adobe.internal.pdftoolkit.core.types.ASArray
* com.adobe.internal.pdftoolkit.core.types.ASDictionary
* com.adobe.internal.pdftoolkit.core.types.ASHexString
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASNumber
* com.adobe.internal.pdftoolkit.core.types.ASObject
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.content;
import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFParseException;
import com.adobe.internal.pdftoolkit.core.types.ASArray;
import com.adobe.internal.pdftoolkit.core.types.ASDictionary;
import com.adobe.internal.pdftoolkit.core.types.ASHexString;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASNumber;
import com.adobe.internal.pdftoolkit.core.types.ASObject;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.content.Instruction;
import com.adobe.internal.pdftoolkit.pdf.content.OperandStack;
import java.util.Set;
public class InstructionFactory {
private InstructionFactory() {
}
public static Instruction newGSave() {
return new Instruction(ASName.k_q);
}
public static Instruction newGRestore() {
return new Instruction(ASName.k_Q);
}
public static Instruction newConcatMatrix(double a, double b, double c, double d, double x, double y) {
Instruction inst = new Instruction(ASName.k_cm);
inst.push(a);
inst.push(b);
inst.push(c);
inst.push(d);
inst.push(x);
inst.push(y);
return inst;
}
public static Instruction newColorStroke(double[] colorComponents) throws PDFInvalidParameterException {
Instruction colorInstruction = null;
if (colorComponents != null) {
switch (colorComponents.length) {
case 0: {
break;
}
case 1: {
colorInstruction = InstructionFactory.newDeviceGrayStroke(colorComponents[0]);
break;
}
case 3: {
colorInstruction = InstructionFactory.newDeviceRGBStroke(colorComponents[0], colorComponents[1], colorComponents[2]);
break;
}
case 4: {
colorInstruction = InstructionFactory.newDeviceCMYKStroke(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);
break;
}
default: {
throw new PDFInvalidParameterException("Invalid length '" + colorComponents.length + "' of color component array, should be 1 (DeviceGray), 3 (DeviceRGB) or 4 (DeviceCMYK)");
}
}
}
return colorInstruction;
}
public static Instruction newColorFill(double[] colorComponents) throws PDFInvalidParameterException {
Instruction colorInstruction = null;
if (colorComponents != null) {
switch (colorComponents.length) {
case 0: {
break;
}
case 1: {
colorInstruction = InstructionFactory.newDeviceGrayFill(colorComponents[0]);
break;
}
case 3: {
colorInstruction = InstructionFactory.newDeviceRGBFill(colorComponents[0], colorComponents[1], colorComponents[2]);
break;
}
case 4: {
colorInstruction = InstructionFactory.newDeviceCMYKFill(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);
break;
}
default: {
throw new PDFInvalidParameterException("Invalid length '" + colorComponents.length + "' of color component array, should be 1 (DeviceGray), 3 (DeviceRGB) or 4 (DeviceCMYK)");
}
}
}
return colorInstruction;
}
public static Instruction newDeviceGrayStroke(double gray) {
Instruction inst = new Instruction(ASName.k_G);
inst.push(gray);
return inst;
}
public static Instruction newDeviceGrayFill(double gray) {
Instruction inst = new Instruction(ASName.k_g);
inst.push(gray);
return inst;
}
public static Instruction newDeviceRGBStroke(double red, double green, double blue) {
Instruction inst = new Instruction(ASName.k_RG);
inst.push(red);
inst.push(green);
inst.push(blue);
return inst;
}
public static Instruction newDeviceRGBFill(double red, double green, double blue) {
Instruction inst = new Instruction(ASName.k_rg);
inst.push(red);
inst.push(green);
inst.push(blue);
return inst;
}
public static Instruction newDeviceCMYKStroke(double c, double m, double y, double k) {
Instruction inst = new Instruction(ASName.k_K);
inst.push(c);
inst.push(m);
inst.push(y);
inst.push(k);
return inst;
}
public static Instruction newDeviceCMYKFill(double c, double m, double y, double k) {
Instruction inst = new Instruction(ASName.k_k);
inst.push(c);
inst.push(m);
inst.push(y);
inst.push(k);
return inst;
}
public static Instruction newLineWidth(double lineWidth) {
Instruction inst = new Instruction(ASName.k_w);
inst.push(lineWidth);
return inst;
}
public static Instruction newLineCapStyle(int style) {
Instruction inst = new Instruction(ASName.k_J);
inst.push(style);
return inst;
}
public static Instruction newLineJoin(int join) {
Instruction inst = new Instruction(ASName.k_j);
inst.push(join);
return inst;
}
public static Instruction newMiterLimit(double miter) {
Instruction inst = new Instruction(ASName.k_M);
inst.push(miter);
return inst;
}
public static Instruction newLineDashPattern(double[] dash, int phase) {
Instruction inst = new Instruction(ASName.k_d);
ASArray dashArray = new ASArray();
for (int i = 0; i < dash.length; ++i) {
ASNumber dashDbl = new ASNumber(dash[i]);
dashArray.add((ASObject)dashDbl);
}
inst.push(dashArray);
inst.push(phase);
return inst;
}
public static Instruction newInvokeNamedXObject(ASName xobjectName) {
Instruction inst = new Instruction(ASName.k_Do);
inst.push(xobjectName);
return inst;
}
public static Instruction newInvokeNamedExtGState(ASName extgstateName) {
Instruction inst = new Instruction(ASName.k_gs);
inst.push(extgstateName);
return inst;
}
public static Instruction newBeginText() {
return new Instruction(ASName.k_BT);
}
public static Instruction newEndText() {
return new Instruction(ASName.k_ET);
}
public static Instruction newCharactorSpacing(double charSpace) {
Instruction inst = new Instruction(ASName.k_Tc);
inst.push(charSpace);
return inst;
}
public static Instruction newWordSpacing(double wordSpace) {
Instruction inst = new Instruction(ASName.k_Tw);
inst.push(wordSpace);
return inst;
}
public static Instruction newHorizontalScaling(double horizontalScale) {
Instruction inst = new Instruction(ASName.k_Tz);
inst.push(horizontalScale);
return inst;
}
public static Instruction newTextLeading(double textLeading) {
Instruction inst = new Instruction(ASName.k_TL);
inst.push(textLeading);
return inst;
}
public static Instruction newTextFont(ASName fontName, double fontSize) {
Instruction inst = new Instruction(ASName.k_Tf);
inst.push(fontName);
inst.push(fontSize);
return inst;
}
public static Instruction newTextFont(ASName fontName, ASNumber fontSize) {
Instruction inst = new Instruction(ASName.k_Tf);
inst.push(fontName);
inst.push(fontSize);
return inst;
}
public static Instruction newTextRenderingMode(int renderingMode) {
Instruction inst = new Instruction(ASName.k_Tr);
inst.push(renderingMode);
return inst;
}
public static Instruction newTextRise(double textRise) {
Instruction inst = new Instruction(ASName.k_Ts);
inst.push(textRise);
return inst;
}
public static Instruction newTextPosition(double tX, double tY) {
Instruction inst = new Instruction(ASName.k_Td);
inst.push(tX);
inst.push(tY);
return inst;
}
public static Instruction newTextPositionAndLeading(double tX, double tY) {
Instruction inst = new Instruction(ASName.k_TD);
inst.push(tX);
inst.push(tY);
return inst;
}
public static Instruction newTextMatrix(double a, double b, double c, double d, double e, double f) {
Instruction inst = new Instruction(ASName.k_Tm);
inst.push(a);
inst.push(b);
inst.push(c);
inst.push(d);
inst.push(e);
inst.push(f);
return inst;
}
public static Instruction newTextNextLine() {
return new Instruction(ASName.k_TStar);
}
public static Instruction newShowText(byte[] text) {
Instruction inst = new Instruction(ASName.k_Tj);
inst.push(new ASString(text));
return inst;
}
public static Instruction newShowText(ASHexString hexStr) {
Instruction inst = new Instruction(ASName.k_Tj);
inst.push(hexStr);
return inst;
}
public static Instruction newShowText(ASString str) {
Instruction inst = new Instruction(ASName.k_Tj);
inst.push(str);
return inst;
}
private static Instruction newShowWithCCode(int[] text, int startIndex, int endIndex, int numBytes) throws PDFIOException, PDFParseException {
Instruction inst = new Instruction(ASName.k_Tj);
try {
inst.push(new ASString(text, startIndex, endIndex, numBytes, 0));
}
catch (PDFInvalidParameterException e) {
throw new RuntimeException("Internal coding error.", (Throwable)e);
}
return inst;
}
public static Instruction newShow2BytesCIDs(int[] text) throws PDFIOException, PDFParseException {
return InstructionFactory.newShowWithCCode(text, 0, text.length - 1, 2);
}
public static Instruction newShow2ByteCCodes(int[] text, int startIndex, int endIndex) throws PDFIOException, PDFParseException {
return InstructionFactory.newShowWithCCode(text, startIndex, endIndex, 2);
}
public static Instruction newShow1ByteCIDs(int[] text) throws PDFIOException, PDFParseException {
return InstructionFactory.newShowWithCCode(text, 0, text.length - 1, 1);
}
public static Instruction newShow1ByteCCodes(int[] text, int startIndex, int endIndex) throws PDFIOException, PDFParseException {
return InstructionFactory.newShowWithCCode(text, startIndex, endIndex, 1);
}
public static Instruction newShowTextNextLine(byte[] text) {
Instruction inst = new Instruction(ASName.k_SingleQuote);
inst.push(new ASString(text));
return inst;
}
public static Instruction newShowTextNextLine(double aW, double aC, byte[] text) {
Instruction inst = new Instruction(ASName.k_DoubleQuote);
inst.push(aW);
inst.push(aC);
inst.push(new ASString(text));
return inst;
}
public static Instruction newMoveTo(double x, double y) {
Instruction inst = new Instruction(ASName.k_m);
inst.push(x);
inst.push(y);
return inst;
}
public static Instruction newLineTo(double x, double y) {
Instruction inst = new Instruction(ASName.k_l);
inst.push(x);
inst.push(y);
return inst;
}
public static Instruction newCurveTo(double x1, double y1, double x2, double y2, double x3, double y3) {
Instruction inst = new Instruction(ASName.k_c);
inst.push(x1);
inst.push(y1);
inst.push(x2);
inst.push(y2);
inst.push(x3);
inst.push(y3);
return inst;
}
public static Instruction newRectangle(double x, double y, double w, double h) {
Instruction inst = new Instruction(ASName.k_re);
inst.push(x);
inst.push(y);
inst.push(w);
inst.push(h);
return inst;
}
public static Instruction newClosePath() {
return new Instruction(ASName.k_h);
}
public static Instruction newStrokePath() {
return new Instruction(ASName.k_S);
}
public static Instruction newFillAndStrokePath() {
return new Instruction(ASName.k_B);
}
public static Instruction newCloseFillAndStrokePath() {
return new Instruction(ASName.k_b);
}
public static Instruction newCloseAndStrokePath() {
return new Instruction(ASName.k_s);
}
public static Instruction newFillPath() {
return new Instruction(ASName.k_f);
}
public static Instruction newShading(ASName name) {
Instruction inst = new Instruction(ASName.k_sh);
inst.push(name);
return inst;
}
public static Instruction newFlatness(double tolerance) {
Instruction inst = new Instruction(ASName.k_i);
inst.push(tolerance);
return inst;
}
public static Instruction newBeginMarkedContent(ASName name, ASName namedResource) {
Instruction inst = new Instruction(ASName.k_BDC);
inst.push(name);
inst.push(namedResource);
return inst;
}
public static Instruction newBeginMarkedContent(ASName name, ASDictionary properties) {
Instruction inst = new Instruction(ASName.k_BDC);
inst.push(name);
inst.push(properties);
return inst;
}
public static Instruction newBeginMarkedContent(ASName name) {
Instruction inst = new Instruction(ASName.k_BMC);
inst.push(name);
return inst;
}
public static Instruction newEndMarkedContent() {
return new Instruction(ASName.k_EMC);
}
public static Instruction newMarkedPoint(ASName name, ASName namedResource) {
Instruction inst = new Instruction(ASName.k_DP);
inst.push(name);
inst.push(namedResource);
return inst;
}
public static Instruction newMarkedPoint(ASName name, ASDictionary property) {
Instruction inst = new Instruction(ASName.k_DP);
inst.push(name);
inst.push(property);
return inst;
}
public static Instruction newMarkedPoint(ASName name) {
Instruction inst = new Instruction(ASName.k_MP);
inst.push(name);
return inst;
}
public static Instruction newStrokeColorSpace(ASName namedResource) {
Instruction inst = new Instruction(ASName.k_CS);
inst.push(namedResource);
return inst;
}
public static Instruction newFillColorSpace(ASName namedResource) {
Instruction inst = new Instruction(ASName.k_cs);
inst.push(namedResource);
return inst;
}
public static Instruction newStrokeColorSpace(double[] colorValues) {
Instruction inst = new Instruction(ASName.k_SCN);
for (int i = 0; i < colorValues.length; ++i) {
inst.push(colorValues[i]);
}
return inst;
}
public static Instruction newFillColorSpace(double[] colorValues) {
Instruction inst = new Instruction(ASName.k_scn);
for (int i = 0; i < colorValues.length; ++i) {
inst.push(colorValues[i]);
}
return inst;
}
public static Instruction newStrokeColorSpace(double[] colorValues, ASName namedResource) {
Instruction inst = new Instruction(ASName.k_SCN);
for (int i = 0; i < colorValues.length; ++i) {
inst.push(colorValues[i]);
}
inst.push(namedResource);
return inst;
}
public static Instruction newFillColorSpace(double[] colorValues, ASName namedResource) {
Instruction inst = new Instruction(ASName.k_scn);
for (int i = 0; i < colorValues.length; ++i) {
inst.push(colorValues[i]);
}
inst.push(namedResource);
return inst;
}
public static Instruction newClipPath() {
return new Instruction(ASName.k_W);
}
public static Instruction newClipPathStar() {
return new Instruction(ASName.k_WStar);
}
public static Instruction newEndPathNoOp() {
return new Instruction(ASName.k_n);
}
public static Instruction newRelativeColorimetric() {
Instruction inst = new Instruction(ASName.k_ri);
inst.push(ASName.k_RelativeColorimetric);
return inst;
}
public static Instruction newInlineImageBegin() {
return new Instruction(ASName.k_BI);
}
public static Instruction newInlineImageDict(ASDictionary imageDict, InputByteStream imageData) {
Instruction inst = new Instruction(ASName.k_ID);
OperandStack operands = inst.getOperands();
operands.pushInputByteStream(imageData);
Set keys = imageDict.keySet();
for (ASName key : keys) {
operands.pushName(key);
operands.push((Object)imageDict.get((Object)key));
}
return inst;
}
public static Instruction newInlineImageEnd() {
return new Instruction(ASName.k_EI);
}
}