| 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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484 | 1×
1×
1×
1×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
1×
222×
1×
100×
1×
75×
10×
75×
15×
1×
1164×
1×
1131×
911×
1×
906×
1×
982×
25×
982×
1×
1×
128×
1×
70×
25×
70×
1×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
1×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
1×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
1×
1776×
888×
888×
888×
888×
888×
888×
888×
888×
888×
888×
888×
888×
888×
1×
8×
3×
3×
5×
1×
1×
4×
4×
4×
4×
4×
4×
1×
4×
4×
4×
4×
4×
4×
1×
1×
1×
1×
1×
1×
1×
8×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
3×
1×
1×
1×
1×
232×
232×
222×
222×
232×
1×
15×
15×
15×
15×
1×
15×
15×
10×
10×
1×
232×
232×
232×
232×
14×
14×
232×
232×
232×
232×
232×
232×
232×
232×
232×
232×
250×
250×
232×
232×
232×
232×
232×
232×
232×
1×
1×
1×
232×
232×
232×
232×
232×
232×
232×
14×
14×
232×
232×
14×
14×
232×
232×
14×
14×
1×
232×
232×
232×
1×
232×
232×
232×
232×
232×
232×
232×
250×
250×
250×
250×
250×
250×
250×
250×
10×
240×
250×
250×
250×
232×
232×
232×
1×
240×
240×
240×
240×
240×
240×
240×
1×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
1×
1×
1×
10×
10×
10×
10×
10×
1×
10×
10×
10×
10×
10×
10×
10×
10×
10×
10×
1×
250×
250×
250×
250×
250×
250×
250×
250×
250×
250×
250×
1×
1×
250×
250×
250×
250×
250×
250×
250×
250×
250×
250×
1×
232×
1×
1×
232×
232×
232×
232×
232×
232×
1×
250×
250×
250×
236×
236×
250×
1×
250×
250×
240×
250×
1×
250×
250×
240×
250×
1×
2026×
902×
1124×
1×
1×
1124×
1124×
1124×
233×
233×
223×
5×
5×
5×
5×
5×
233×
891×
891×
891×
891×
891×
891×
1124×
1124×
1124×
1×
1124×
1124×
15×
15×
15×
15×
1×
1124×
891×
891×
891×
1×
1124×
233×
233×
233×
1×
1×
1×
1×
233×
233×
233×
233×
233×
1×
1124×
232×
232×
232×
14×
14×
14×
14×
14×
14×
14×
1×
1×
15×
15×
15×
15×
15×
15×
15×
15×
1×
85×
1×
50×
50×
50×
50×
1×
60×
60×
1×
1×
1×
1×
25×
25×
25×
25×
25×
1×
1×
20×
20×
20×
20×
20×
20×
20×
20×
20×
20×
20×
20×
1×
20×
20×
20×
20×
20×
20×
20×
1×
20×
20×
20×
20×
20×
20×
20×
20×
20×
20×
20×
20×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
25×
1×
2566×
1×
1×
1×
1×
20×
20×
20×
20×
20×
20×
20×
20×
20×
120×
20×
20×
1×
1×
20×
1×
20×
20×
1×
20×
20×
1×
20×
20×
1×
20×
20×
1×
20×
20×
1×
20×
20×
1×
20×
20×
1×
20×
20×
1×
1×
1×
1×
1×
| define(["require", "exports", "./enum", "./enum", "./fonts/enum", "./../input-output/pdf-stream-writer", "./pdf-pen", "./brushes/pdf-brush", "./brushes/pdf-solid-brush", "./fonts/pdf-font", "./pdf-transformation-matrix", "./../drawing/pdf-drawing", "./constants", "./../primitives/pdf-string", "./fonts/pdf-string-format", "./../collections/object-object-pair/dictionary", "./pdf-transparency", "./fonts/string-layouter", "./../input-output/pdf-dictionary-properties", "./fonts/string-tokenizer", "./../document/automatic-fields/automatic-field-info-collection", "./../document/automatic-fields/automatic-field-info", "./../input-output/pdf-operators", "./fonts/unicode-true-type-font", "./../primitives/pdf-string", "./fonts/rtl-renderer", "./enum", "./figures/enum", "./../../implementation/graphics/brushes/pdf-gradient-brush", "./brushes/pdf-tiling-brush"], function (require, exports, enum_1, enum_2, enum_3, pdf_stream_writer_1, pdf_pen_1, pdf_brush_1, pdf_solid_brush_1, pdf_font_1, pdf_transformation_matrix_1, pdf_drawing_1, constants_1, pdf_string_1, pdf_string_format_1, dictionary_1, pdf_transparency_1, string_layouter_1, pdf_dictionary_properties_1, string_tokenizer_1, automatic_field_info_collection_1, automatic_field_info_1, pdf_operators_1, unicode_true_type_font_1, pdf_string_2, rtl_renderer_1, enum_4, enum_5, pdf_gradient_brush_1, pdf_tiling_brush_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var PdfGraphics = (function () {
function PdfGraphics(arg1, arg2, arg3) {
this.currentColorSpace = enum_1.PdfColorSpace.Rgb;
this.previousTextRenderingMode = enum_1.TextRenderingMode.Fill;
this.previousCharacterSpacing = 0.0;
this.previousWordSpacing = 0.0;
this.previousTextScaling = 100.0;
this.procedureSets = new constants_1.ProcedureSets();
this.isNormalRender = true;
this.isUseFontSize = false;
this.isItalic = false;
this.isEmfTextScaled = false;
this.isEmf = false;
this.isEmfPlus = false;
this.isBaselineFormat = true;
this.emfScalingFactor = new pdf_drawing_1.SizeF(0, 0);
this.colorSpaceChanged = false;
this.dictionaryProperties = new pdf_dictionary_properties_1.DictionaryProperties();
this.isOverloadWithPosition = false;
this.isPointOverload = false;
this.currentColorSpaces = ['RGB', 'CMYK', 'GrayScale', 'Indexed'];
this.isImageOptimized = false;
this.graphicsState = [];
this.istransparencySet = false;
this.internalAutomaticFields = null;
this.startCutIndex = -1;
this.getResources = arg2;
this.canvasSize = arg1;
Iif (arg3 instanceof pdf_stream_writer_1.PdfStreamWriter) {
this.pdfStreamWriter = arg3;
}
else {
this.pdfStreamWriter = new pdf_stream_writer_1.PdfStreamWriter(arg3);
}
this.initialize();
}
Object.defineProperty(PdfGraphics.prototype, "stringLayoutResult", {
get: function () {
return this.pdfStringLayoutResult;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphics.prototype, "size", {
get: function () {
return this.canvasSize;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphics.prototype, "mediaBoxUpperRightBound", {
get: function () {
if (typeof this.internalMediaBoxUpperRightBound === 'undefined') {
this.internalMediaBoxUpperRightBound = 0;
}
return this.internalMediaBoxUpperRightBound;
},
set: function (value) {
this.internalMediaBoxUpperRightBound = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphics.prototype, "clientSize", {
get: function () {
return new pdf_drawing_1.SizeF(this.clipBounds.width, this.clipBounds.height);
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphics.prototype, "colorSpace", {
get: function () {
return this.currentColorSpace;
},
set: function (value) {
this.currentColorSpace = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphics.prototype, "streamWriter", {
get: function () {
return this.pdfStreamWriter;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphics.prototype, "matrix", {
get: function () {
if (this.transformationMatrix == null) {
this.transformationMatrix = new pdf_transformation_matrix_1.PdfTransformationMatrix();
}
return this.transformationMatrix;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphics.prototype, "layer", {
get: function () {
return this.pageLayer;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphics.prototype, "page", {
get: function () {
return this.pageLayer.page;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphics.prototype, "automaticFields", {
get: function () {
if (this.internalAutomaticFields == null || typeof this.internalAutomaticFields === 'undefined') {
this.internalAutomaticFields = new automatic_field_info_collection_1.PdfAutomaticFieldInfoCollection();
}
return this.internalAutomaticFields;
},
enumerable: true,
configurable: true
});
PdfGraphics.prototype.initialize = function () {
this.bStateSaved = false;
this.currentPen = null;
this.currentBrush = null;
this.currentFont = null;
this.currentColorSpace = enum_1.PdfColorSpace.Rgb;
this.bCSInitialized = false;
this.transformationMatrix = null;
this.previousTextRenderingMode = (-1);
this.previousCharacterSpacing = -1.0;
this.previousWordSpacing = -1.0;
this.previousTextScaling = -100.0;
this.currentStringFormat = null;
this.clipBounds = new pdf_drawing_1.RectangleF(new pdf_drawing_1.PointF(0, 0), this.size);
this.getResources.getResources().requireProcedureSet(this.procedureSets.pdf);
};
PdfGraphics.prototype.drawPdfTemplate = function (template, location, size) {
Iif (typeof size === 'undefined') {
if (template == null) {
throw Error('ArgumentNullException-template');
}
this.drawPdfTemplate(template, location, template.size);
}
else {
Iif (template == null) {
throw Error('ArgumentNullException-template');
}
var scaleX = (template.width > 0) ? size.width / template.width : 1;
var scaleY = (template.height > 0) ? size.height / template.height : 1;
var bNeedScale = !(scaleX === 1 && scaleY === 1);
var state = this.save();
var matrix = new pdf_transformation_matrix_1.PdfTransformationMatrix();
Eif (this.pageLayer != null) {
this.getTranslateTransform(location.x, location.y + size.height, matrix);
}
Iif (bNeedScale) {
this.getScaleTransform(scaleX, scaleY, matrix);
}
this.pdfStreamWriter.modifyCtm(matrix);
var resources = this.getResources.getResources();
var name_1 = resources.getName(template);
this.pdfStreamWriter.executeObject(name_1);
this.restore(state);
var g = template.graphics;
Eif (g != null) {
for (var index = 0; index < g.automaticFields.automaticFields.length; index++) {
var fieldInfo = g.automaticFields.automaticFields[index];
var newLocation = new pdf_drawing_1.PointF(fieldInfo.location.x + location.x, fieldInfo.location.y + location.y);
var scalingX = template.size.width == 0 ? 0 : size.width / template.size.width;
var scalingY = template.size.height == 0 ? 0 : size.height / template.size.height;
this.automaticFields.add(new automatic_field_info_1.PdfAutomaticFieldInfo(fieldInfo.field, newLocation, scalingX, scalingY));
this.page.dictionary.modify();
}
}
this.getResources.getResources().requireProcedureSet(this.procedureSets.imageB);
this.getResources.getResources().requireProcedureSet(this.procedureSets.imageC);
this.getResources.getResources().requireProcedureSet(this.procedureSets.imageI);
this.getResources.getResources().requireProcedureSet(this.procedureSets.text);
}
};
PdfGraphics.prototype.drawString = function (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
Iif (typeof arg1 === 'string' && arg2 instanceof pdf_font_1.PdfFont && (arg3 instanceof pdf_pen_1.PdfPen || arg3 === null) && (arg4 instanceof pdf_brush_1.PdfBrush || arg4 === null) && typeof arg5 === 'number' && typeof arg6 === 'number' && (arg7 instanceof pdf_string_format_1.PdfStringFormat || arg7 === null) && typeof arg8 === 'undefined') {
this.isOverloadWithPosition = true;
this.drawString(arg1, arg2, arg3, arg4, arg5, arg6, (this.clientSize.width - arg5), 0, arg7);
}
else {
var temparg3 = arg3;
var temparg4 = arg4;
var temparg5 = arg5;
var temparg6 = arg6;
var temparg7 = arg7;
var temparg8 = arg8;
var temparg9 = arg9;
var layouter = new string_layouter_1.PdfStringLayouter();
var result = layouter.layout(arg1, arg2, temparg9, new pdf_drawing_1.SizeF(temparg7, temparg8), this.isOverloadWithPosition, this.clientSize);
Eif (!result.empty) {
var rect = this.checkCorrectLayoutRectangle(result.actualSize, temparg5, temparg6, temparg9);
Iif (temparg7 <= 0) {
temparg5 = rect.x;
temparg7 = rect.width;
}
Iif (temparg8 <= 0) {
temparg6 = rect.y;
temparg8 = rect.height;
}
this.drawStringLayoutResult(result, arg2, temparg3, temparg4, new pdf_drawing_1.RectangleF(temparg5, temparg6, temparg7, temparg8), temparg9);
this.isEmfTextScaled = false;
this.emfScalingFactor = new pdf_drawing_1.SizeF(0, 0);
}
this.getResources.getResources().requireProcedureSet(this.procedureSets.text);
this.isNormalRender = true;
this.pdfStringLayoutResult = result;
this.isUseFontSize = false;
}
};
PdfGraphics.prototype.drawLine = function (arg1, arg2, arg3, arg4, arg5) {
if (arg2 instanceof pdf_drawing_1.PointF) {
var temparg2 = arg2;
var temparg3 = arg3;
this.drawLine(arg1, temparg2.x, temparg2.y, temparg3.x, temparg3.y);
}
else {
var temparg2 = arg2;
var temparg3 = arg3;
var temparg4 = arg4;
var temparg5 = arg5;
this.stateControl(arg1, null, null);
var sw = this.streamWriter;
sw.beginPath(temparg2, temparg3);
sw.appendLineSegment(temparg4, temparg5);
sw.strokePath();
this.getResources.getResources().requireProcedureSet(this.procedureSets.pdf);
}
};
PdfGraphics.prototype.drawRectangle = function (arg1, arg2, arg3, arg4, arg5, arg6) {
if (arg1 instanceof pdf_pen_1.PdfPen && typeof arg2 === 'number') {
var temparg3 = arg3;
this.drawRectangle(arg1, null, arg2, temparg3, arg4, arg5);
}
else if (arg1 instanceof pdf_brush_1.PdfBrush && typeof arg2 === 'number') {
var temparg3 = arg3;
this.drawRectangle(null, arg1, arg2, temparg3, arg4, arg5);
}
else {
var temparg3 = arg3;
var temparg4 = arg4;
var temparg5 = arg5;
var temparg6 = arg6;
Iif ((arg2 instanceof pdf_tiling_brush_1.PdfTilingBrush)) {
this.bCSInitialized = false;
var xOffset = (this.matrix.matrix.offsetX + temparg3);
var yOffset = void 0;
if (((this.layer != null) && (this.layer.page != null))) {
yOffset = ((this.layer.page.size.height - this.matrix.matrix.offsetY) + temparg4);
}
else {
yOffset = ((this.clientSize.height - this.matrix.matrix.offsetY) + temparg4);
}
(arg2).location = new pdf_drawing_1.PointF(xOffset, yOffset);
(arg2).graphics.colorSpace = this.colorSpace;
}
else if ((arg2 instanceof pdf_gradient_brush_1.PdfGradientBrush)) {
arg2.colorSpace = this.colorSpace;
}
Iif (arg2 instanceof pdf_solid_brush_1.PdfSolidBrush && arg2.color.isEmpty) {
arg2 = null;
}
var temparg1 = arg1;
var temparg2 = arg2;
this.stateControl(temparg1, temparg2, null);
this.streamWriter.appendRectangle(temparg3, temparg4, temparg5, temparg6);
this.drawPathHelper(temparg1, temparg2, false);
}
};
PdfGraphics.prototype.drawRoundedRectangle = function (pen, brush, x, y, width, height, radius) {
if (pen === null) {
throw new Error('pen');
}
if (brush === null) {
throw new Error('brush');
}
if (radius === 0) {
this.drawRectangle(pen, brush, x, y, width, height);
}
else {
var bounds = [x, y, width, height];
var diameter = radius * 2;
var size = [diameter, diameter];
var arc = [bounds[0], bounds[1], size[0], size[1]];
this._pathPoints = [];
this._pathTypes = [];
var startFigure = true;
startFigure = this._addArc(arc[0], arc[1], arc[2], arc[3], 180, 90, startFigure);
arc[0] = (bounds[0] + bounds[2]) - diameter;
startFigure = this._addArc(arc[0], arc[1], arc[2], arc[3], 270, 90, startFigure);
arc[1] = (bounds[1] + bounds[3]) - diameter;
startFigure = this._addArc(arc[0], arc[1], arc[2], arc[3], 0, 90, startFigure);
arc[0] = bounds[0];
startFigure = this._addArc(arc[0], arc[1], arc[2], arc[3], 90, 90, startFigure);
var index = this._pathPoints.length - 1;
var type = ((this._pathTypes[index]));
type = (type | enum_5.PathPointType.CloseSubpath);
this._pathTypes[index] = (type);
this._drawPath(pen, brush, this._pathPoints, this._pathTypes, enum_1.PdfFillMode.Alternate);
this._pathPoints = [];
this._pathTypes = [];
}
};
PdfGraphics.prototype._addArc = function (x, y, width, height, startAngle, sweepAngle, startFigure) {
var points = this._getBezierArcPoints(x, y, (x + width), (y + height), startAngle, sweepAngle);
for (var i = 0; i < points.length; i = i + 8) {
var point = [points[i], points[i + 1], points[i + 2], points[i + 3], points[i + 4], points[i + 5], points[i + 6], points[i + 7]];
startFigure = this._addArcPoints(point, enum_5.PathPointType.Bezier3, startFigure);
}
return startFigure;
};
PdfGraphics.prototype._addArcPoints = function (points, pointType, startFigure) {
for (var i = 0; i < points.length; i++) {
var point = new pdf_drawing_1.PointF(points[i], points[(i + 1)]);
if (i === 0) {
if (this._pathPoints.length === 0 || startFigure) {
this._addPoint(point, enum_5.PathPointType.Start);
startFigure = false;
}
else if (point.x !== this._getLastPoint().x || point.y !== this._getLastPoint().y) {
this._addPoint(point, enum_5.PathPointType.Line);
}
}
else {
this._addPoint(point, pointType);
}
i++;
}
return startFigure;
};
PdfGraphics.prototype._getLastPoint = function () {
var lastPoint = new pdf_drawing_1.PointF(0, 0);
var count = this._pathPoints.length;
if (count > 0) {
lastPoint.x = this._pathPoints[(count - 1)].x;
lastPoint.y = this._pathPoints[(count - 1)].y;
}
return lastPoint;
};
PdfGraphics.prototype._addPoint = function (point, type) {
this._pathPoints.push(point);
this._pathTypes.push(type);
};
PdfGraphics.prototype._getBezierArcPoints = function (x1, y1, x2, y2, s1, e1) {
if ((x1 > x2)) {
var tmp = void 0;
tmp = x1;
x1 = x2;
x2 = tmp;
}
if ((y2 > y1)) {
var tmp = void 0;
tmp = y1;
y1 = y2;
y2 = tmp;
}
var fragAngle;
var numFragments;
if ((Math.abs(e1) <= 90)) {
fragAngle = e1;
numFragments = 1;
}
else {
numFragments = (Math.ceil((Math.abs(e1) / 90)));
fragAngle = (e1 / numFragments);
}
var xcen = ((x1 + x2) / 2);
var ycen = ((y1 + y2) / 2);
var rx = ((x2 - x1) / 2);
var ry = ((y2 - y1) / 2);
var halfAng = ((fragAngle * (Math.PI / 360)));
var kappa = (Math.abs(4.0 / 3.0 * (1.0 - Math.cos(halfAng)) / Math.sin(halfAng)));
var pointList = [];
for (var i = 0; (i < numFragments); i++) {
var theta0 = (((s1 + (i * fragAngle)) * (Math.PI / 180)));
var theta1 = (((s1 + ((i + 1) * fragAngle)) * (Math.PI / 180)));
var cos0 = (Math.cos(theta0));
var cos1 = (Math.cos(theta1));
var sin0 = (Math.sin(theta0));
var sin1 = (Math.sin(theta1));
if ((fragAngle > 0)) {
pointList.push((xcen + (rx * cos0)), (ycen - (ry * sin0)), (xcen + (rx * (cos0 - (kappa * sin0)))), (ycen - (ry * (sin0 + (kappa * cos0)))), (xcen + (rx * (cos1 + (kappa * sin1)))), (ycen - (ry * (sin1 - (kappa * cos1)))), (xcen + (rx * cos1)), (ycen - (ry * sin1)));
}
else {
pointList.push((xcen + (rx * cos0)), (ycen - (ry * sin0)), (xcen + (rx * (cos0 + (kappa * sin0)))), (ycen - (ry * (sin0 - (kappa * cos0)))), (xcen + (rx * (cos1 - (kappa * sin1)))), (ycen - (ry * (sin1 + (kappa * cos1)))), (xcen + (rx * cos1)), (ycen - (ry * sin1)));
}
}
return pointList;
};
PdfGraphics.prototype.drawPathHelper = function (arg1, arg2, arg3, arg4) {
if (typeof arg3 === 'boolean') {
var temparg3 = arg3;
this.drawPathHelper(arg1, arg2, enum_1.PdfFillMode.Winding, temparg3);
}
else {
var temparg3 = arg3;
var temparg4 = arg4;
var isPen = arg1 != null;
var isBrush = arg2 != null;
var isEvenOdd = (temparg3 === enum_1.PdfFillMode.Alternate);
Iif (isPen && isBrush) {
this.streamWriter.fillStrokePath(isEvenOdd);
}
else Iif (!isPen && !isBrush) {
this.streamWriter.endPath();
}
else if (isPen) {
this.streamWriter.strokePath();
}
else {
this.streamWriter.fillPath(isEvenOdd);
}
}
};
PdfGraphics.prototype.drawImage = function (arg1, arg2, arg3, arg4, arg5) {
if (typeof arg2 === 'number' && typeof arg3 === 'number' && typeof arg4 === 'undefined') {
var size = arg1.physicalDimension;
this.drawImage(arg1, arg2, arg3, size.width, size.height);
}
else {
var temparg2 = arg2;
var temparg3 = arg3;
var temparg4 = arg4;
var temparg5 = arg5;
arg1.save();
var matrix = new pdf_transformation_matrix_1.PdfTransformationMatrix();
this.getTranslateTransform(temparg2, (temparg3 + temparg5), matrix);
this.getScaleTransform(arg4, arg5, matrix);
this.pdfStreamWriter.write('q');
this.pdfStreamWriter.modifyCtm(matrix);
var resources = this.getResources.getResources();
if (typeof this.pageLayer !== 'undefined' && this.page != null) {
resources.document = this.page.document;
}
var name_2 = resources.getName(arg1);
if (typeof this.pageLayer !== 'undefined') {
this.page.setResources(resources);
}
this.pdfStreamWriter.executeObject(name_2);
this.pdfStreamWriter.write(pdf_operators_1.Operators.restoreState);
this.pdfStreamWriter.write(pdf_operators_1.Operators.newLine);
var resource = this.getResources.getResources();
resource.requireProcedureSet(this.procedureSets.imageB);
resource.requireProcedureSet(this.procedureSets.imageC);
resource.requireProcedureSet(this.procedureSets.imageI);
resource.requireProcedureSet(this.procedureSets.text);
}
};
PdfGraphics.prototype.getLineBounds = function (lineIndex, result, font, layoutRectangle, format) {
var bounds;
if (!result.empty && lineIndex < result.lineCount && lineIndex >= 0) {
var line = result.lines[lineIndex];
var vShift = this.getTextVerticalAlignShift(result.actualSize.height, layoutRectangle.height, format);
var y = vShift + layoutRectangle.y + (result.lineHeight * lineIndex);
var lineWidth = line.width;
var hShift = this.getHorizontalAlignShift(lineWidth, layoutRectangle.width, format);
var lineIndent = this.getLineIndent(line, format, layoutRectangle, (lineIndex === 0));
hShift += (!this.rightToLeft(format)) ? lineIndent : 0;
var x = layoutRectangle.x + hShift;
var width = (!this.shouldJustify(line, layoutRectangle.width, format)) ? lineWidth - lineIndent : layoutRectangle.width - lineIndent;
var height = result.lineHeight;
bounds = new pdf_drawing_1.RectangleF(x, y, width, height);
}
else {
bounds = new pdf_drawing_1.RectangleF(0, 0, 0, 0);
}
return bounds;
};
PdfGraphics.prototype.checkCorrectLayoutRectangle = function (textSize, x, y, format) {
var layoutedRectangle = new pdf_drawing_1.RectangleF(x, y, textSize.width, textSize.width);
if (format != null) {
switch (format.alignment) {
case enum_1.PdfTextAlignment.Center:
layoutedRectangle.x -= layoutedRectangle.width / 2;
break;
case enum_1.PdfTextAlignment.Right:
layoutedRectangle.x -= layoutedRectangle.width;
break;
}
switch (format.lineAlignment) {
case enum_2.PdfVerticalAlignment.Middle:
layoutedRectangle.y -= layoutedRectangle.height / 2;
break;
case enum_2.PdfVerticalAlignment.Bottom:
layoutedRectangle.y -= layoutedRectangle.height;
break;
}
}
return layoutedRectangle;
};
PdfGraphics.prototype.setLayer = function (layer) {
this.pageLayer = layer;
var page = layer.page;
Eif (page != null && typeof page !== 'undefined') {
page.beginSave = this.pageSave;
}
};
PdfGraphics.prototype.pageSave = function (page) {
Eif (page.graphics.automaticFields != null) {
for (var i = 0; i < page.graphics.automaticFields.automaticFields.length; i++) {
var fieldInfo = page.graphics.automaticFields.automaticFields[i];
fieldInfo.field.performDraw(page.graphics, fieldInfo.location, fieldInfo.scalingX, fieldInfo.scalingY);
}
}
};
PdfGraphics.prototype.drawStringLayoutResult = function (result, font, pen, brush, layoutRectangle, format) {
Eif (!result.empty) {
this.applyStringSettings(font, pen, brush, format, layoutRectangle);
var textScaling = (format != null) ? format.horizontalScalingFactor : 100.0;
if (textScaling !== this.previousTextScaling && !this.isEmfTextScaled) {
this.pdfStreamWriter.setTextScaling(textScaling);
this.previousTextScaling = textScaling;
}
var height = (format == null || format.lineSpacing === 0) ? font.height : format.lineSpacing + font.height;
var subScript = (format != null && format.subSuperScript === enum_3.PdfSubSuperScript.SubScript);
var shift = 0;
shift = (subScript) ? height - (font.height + font.metrics.getDescent(format)) : (height - font.metrics.getAscent(format));
this.shift = shift;
this.pdfStreamWriter.startNextLine(layoutRectangle.x, layoutRectangle.y - shift);
this.pdfStreamWriter.setLeading(+height);
var resultHeight = 0;
var remainingString = '';
for (var i = 0; i < result.lines.length; i++) {
resultHeight += result.lineHeight;
Iif ((layoutRectangle.y + resultHeight) > this.clientSize.height) {
this.startCutIndex = i;
break;
}
}
for (var j = this.startCutIndex; (j < result.lines.length && j >= 0); j++) {
remainingString += result.lines[j].text;
}
var bounds = new pdf_drawing_1.RectangleF(layoutRectangle.x, layoutRectangle.y, layoutRectangle.width, layoutRectangle.height);
this.drawLayoutResult(result, font, format, layoutRectangle);
this.underlineStrikeoutText(pen, brush, result, font, bounds, format);
this.isEmfPlus = false;
this.isUseFontSize = false;
Iif (this.startCutIndex !== -1) {
var page = this.getNextPage();
page.graphics.drawString(remainingString, font, pen, brush, layoutRectangle.x, 0, layoutRectangle.width, 0, format);
}
}
else {
throw new Error('ArgumentNullException:result');
}
};
PdfGraphics.prototype.getNextPage = function () {
var section = this.currentPage.section;
var nextPage = null;
var index = section.indexOf(this.currentPage);
if (index === section.count - 1) {
nextPage = section.add();
}
else {
nextPage = section.getPages()[index + 1];
}
return nextPage;
};
PdfGraphics.prototype.setClip = function (rectangle, mode) {
if (typeof mode === 'undefined') {
this.setClip(rectangle, enum_1.PdfFillMode.Winding);
}
else {
this.pdfStreamWriter.appendRectangle(rectangle);
this.pdfStreamWriter.clipPath((mode === enum_1.PdfFillMode.Alternate));
}
};
PdfGraphics.prototype.applyStringSettings = function (font, pen, brush, format, bounds) {
Iif (brush instanceof pdf_tiling_brush_1.PdfTilingBrush) {
this.bCSInitialized = false;
brush.graphics.colorSpace = this.colorSpace;
}
else Iif ((brush instanceof pdf_gradient_brush_1.PdfGradientBrush)) {
this.bCSInitialized = false;
brush.colorSpace = this.colorSpace;
}
var setLineWidth = false;
var tm = this.getTextRenderingMode(pen, brush, format);
this.stateControl(pen, brush, font, format);
this.pdfStreamWriter.beginText();
if ((tm) !== this.previousTextRenderingMode) {
this.pdfStreamWriter.setTextRenderingMode(tm);
this.previousTextRenderingMode = tm;
}
var cs = (format != null) ? format.characterSpacing : 0;
if (cs !== this.previousCharacterSpacing && !this.isEmfTextScaled) {
this.pdfStreamWriter.setCharacterSpacing(cs);
this.previousCharacterSpacing = cs;
}
var ws = (format != null) ? format.wordSpacing : 0;
if (ws !== this.previousWordSpacing) {
this.pdfStreamWriter.setWordSpacing(ws);
this.previousWordSpacing = ws;
}
};
PdfGraphics.prototype.getTextVerticalAlignShift = function (textHeight, boundsHeight, format) {
var shift = 0;
Iif (boundsHeight >= 0 && format != null && format.lineAlignment !== enum_2.PdfVerticalAlignment.Top) {
switch (format.lineAlignment) {
case enum_2.PdfVerticalAlignment.Middle:
shift = (boundsHeight - textHeight) / 2;
break;
case enum_2.PdfVerticalAlignment.Bottom:
shift = boundsHeight - textHeight;
break;
}
}
return shift;
};
PdfGraphics.prototype.drawLayoutResult = function (result, font, format, layoutRectangle) {
var vAlignShift = this.getTextVerticalAlignShift(result.actualSize.height, layoutRectangle.height, format);
Iif (vAlignShift !== 0) {
this.pdfStreamWriter.startNextLine(0, vAlignShift);
}
var ttfFont = font;
var unicode = (ttfFont != null && ttfFont.isUnicode);
var embed = (ttfFont != null && ttfFont.isEmbedFont);
var lines = result.lines;
for (var i = 0, len = lines.length; (i < len && i !== this.startCutIndex); i++) {
var lineInfo = lines[i];
var line = lineInfo.text;
var lineWidth = lineInfo.width;
var hAlignShift = this.getHorizontalAlignShift(lineWidth, layoutRectangle.width, format);
var lineIndent = this.getLineIndent(lineInfo, format, layoutRectangle, (i === 0));
hAlignShift += (!this.rightToLeft(format)) ? lineIndent : 0;
Iif (hAlignShift !== 0 && !this.isEmfTextScaled) {
this.pdfStreamWriter.startNextLine(hAlignShift, 0);
}
if (unicode) {
this.drawUnicodeLine(lineInfo, layoutRectangle, font, format);
}
else {
this.drawAsciiLine(lineInfo, layoutRectangle, font, format);
}
Iif (hAlignShift !== 0 && !this.isEmfTextScaled) {
this.pdfStreamWriter.startNextLine(-hAlignShift, 0);
}
Iif (this.isOverloadWithPosition && lines.length > 1) {
this.pdfStreamWriter.startNextLine(-(layoutRectangle.x), 0);
layoutRectangle.x = 0;
layoutRectangle.width = this.clientSize.width;
this.isOverloadWithPosition = false;
this.isPointOverload = true;
}
else Iif (this.isOverloadWithPosition) {
this.isOverloadWithPosition = false;
}
}
this.getResources.getResources().requireProcedureSet(this.procedureSets.text);
Iif (vAlignShift !== 0) {
this.pdfStreamWriter.startNextLine(0, -(vAlignShift - result.lineHeight));
}
this.pdfStreamWriter.endText();
};
PdfGraphics.prototype.drawAsciiLine = function (lineInfo, layoutRectangle, font, format) {
this.justifyLine(lineInfo, layoutRectangle.width, format);
var value = '';
Iif (lineInfo.text.indexOf('(') !== -1 || lineInfo.text.indexOf(')') !== -1) {
for (var i = 0; i < lineInfo.text.length; i++) {
if (lineInfo.text[i] === '(') {
value += '\\\(';
}
else if (lineInfo.text[i] === ')') {
value += '\\\)';
}
else {
value += lineInfo.text[i];
}
}
}
Eif (value === '') {
value = lineInfo.text;
}
var line = '(' + value + ')';
this.pdfStreamWriter.showNextLineText(new pdf_string_1.PdfString(line));
};
PdfGraphics.prototype.drawUnicodeLine = function (lineInfo, layoutRectangle, font, format) {
var line = lineInfo.text;
var lineWidth = lineInfo.width;
var rtl = (format !== null && typeof format !== 'undefined' && format.rightToLeft);
var useWordSpace = (format !== null && typeof format !== 'undefined' && (format.wordSpacing !== 0 || format.alignment === enum_1.PdfTextAlignment.Justify));
var ttfFont = font;
var wordSpacing = this.justifyLine(lineInfo, layoutRectangle.width, format);
var rtlRender = new rtl_renderer_1.RtlRenderer();
Iif (rtl || (format !== null && typeof format !== 'undefined' && format.textDirection !== enum_4.PdfTextDirection.None)) {
var blocks = null;
var rightAlign = (format !== null && typeof format !== 'undefined' && format.alignment === enum_1.PdfTextAlignment.Right);
if (format !== null && typeof format !== 'undefined' && format.textDirection !== enum_4.PdfTextDirection.None) {
blocks = rtlRender.layout(line, ttfFont, (format.textDirection === enum_4.PdfTextDirection.RightToLeft) ? true : false, useWordSpace, format);
}
else {
blocks = rtlRender.layout(line, ttfFont, rightAlign, useWordSpace, format);
}
var words = null;
if (blocks.length > 1) {
if (format !== null && typeof format !== 'undefined' && format.textDirection !== enum_4.PdfTextDirection.None) {
words = rtlRender.splitLayout(line, ttfFont, (format.textDirection === enum_4.PdfTextDirection.RightToLeft) ? true : false, useWordSpace, format);
}
else {
words = rtlRender.splitLayout(line, ttfFont, rightAlign, useWordSpace, format);
}
}
else {
words = [line];
}
this.drawUnicodeBlocks(blocks, words, ttfFont, format, wordSpacing);
}
else {
Iif (useWordSpace) {
var result = this.breakUnicodeLine(line, ttfFont, null);
var blocks = result.tokens;
var words = result.words;
this.drawUnicodeBlocks(blocks, words, ttfFont, format, wordSpacing);
}
else {
var token = this.convertToUnicode(line, ttfFont);
var value = this.getUnicodeString(token);
this.streamWriter.showNextLineText(value);
}
}
};
PdfGraphics.prototype.drawUnicodeBlocks = function (blocks, words, font, format, wordSpacing) {
if (blocks == null) {
throw new Error('Argument Null Exception : blocks');
}
if (words == null) {
throw new Error('Argument Null Exception : words');
}
if (font == null) {
throw new Error('Argument Null Exception : font');
}
this.streamWriter.startNextLine();
var x = 0;
var xShift = 0;
var firstLineIndent = 0;
var paragraphIndent = 0;
try {
if (format !== null && typeof format !== 'undefined') {
firstLineIndent = format.firstLineIndent;
paragraphIndent = format.paragraphIndent;
format.firstLineIndent = 0;
format.paragraphIndent = 0;
}
var spaceWidth = font.getCharWidth(string_tokenizer_1.StringTokenizer.whiteSpace, format) + wordSpacing;
var characterSpacing = (format != null) ? format.characterSpacing : 0;
var wordSpace = (format !== null && typeof format !== 'undefined' && wordSpacing === 0) ? format.wordSpacing : 0;
spaceWidth += characterSpacing + wordSpace;
for (var i = 0; i < blocks.length; i++) {
var token = blocks[i];
var word = words[i];
var tokenWidth = 0;
if (x !== 0) {
this.streamWriter.startNextLine(x, 0);
}
if (word.length > 0) {
tokenWidth += font.measureString(word, format).width;
tokenWidth += characterSpacing;
var val = this.getUnicodeString(token);
this.streamWriter.showText(val);
}
if (i !== blocks.length - 1) {
x = tokenWidth + spaceWidth;
xShift += x;
}
}
if (xShift > 0) {
this.streamWriter.startNextLine(-xShift, 0);
}
}
finally {
if (format !== null && typeof format !== 'undefined') {
format.firstLineIndent = firstLineIndent;
format.paragraphIndent = paragraphIndent;
}
}
};
PdfGraphics.prototype.breakUnicodeLine = function (line, ttfFont, words) {
if (line === null) {
throw new Error('Argument Null Exception : line');
}
words = line.split(null);
var tokens = [];
for (var i = 0; i < words.length; i++) {
var word = words[i];
var token = this.convertToUnicode(word, ttfFont);
tokens[i] = token;
}
return { tokens: tokens, words: words };
};
PdfGraphics.prototype.getUnicodeString = function (token) {
Iif (token === null) {
throw new Error('Argument Null Exception : token');
}
var val = new pdf_string_1.PdfString(token);
val.converted = true;
val.encode = pdf_string_2.InternalEnum.ForceEncoding.Ascii;
return val;
};
PdfGraphics.prototype.convertToUnicode = function (text, ttfFont) {
var token = null;
Iif (text == null) {
throw new Error('Argument Null Exception : text');
}
Iif (ttfFont == null) {
throw new Error('Argument Null Exception : ttfFont');
}
Eif (ttfFont.fontInternal instanceof unicode_true_type_font_1.UnicodeTrueTypeFont) {
var ttfReader = ttfFont.fontInternal.ttfReader;
ttfFont.setSymbols(text);
token = ttfReader.convertString(text);
var bytes = pdf_string_1.PdfString.toUnicodeArray(token, false);
token = pdf_string_1.PdfString.byteToString(bytes);
}
return token;
};
PdfGraphics.prototype.justifyLine = function (lineInfo, boundsWidth, format) {
var line = lineInfo.text;
var lineWidth = lineInfo.width;
var shouldJustify = this.shouldJustify(lineInfo, boundsWidth, format);
var hasWordSpacing = (format != null && format.wordSpacing !== 0);
var symbols = string_tokenizer_1.StringTokenizer.spaces;
var whitespacesCount = string_tokenizer_1.StringTokenizer.getCharsCount(line, symbols);
var wordSpace = 0;
Iif (shouldJustify) {
if (hasWordSpacing) {
lineWidth -= (whitespacesCount * format.wordSpacing);
}
var difference = boundsWidth - lineWidth;
wordSpace = difference / whitespacesCount;
this.pdfStreamWriter.setWordSpacing(wordSpace);
}
else {
Iif (hasWordSpacing) {
this.pdfStreamWriter.setWordSpacing(format.wordSpacing);
}
else {
this.pdfStreamWriter.setWordSpacing(0);
}
}
return wordSpace;
};
PdfGraphics.prototype.reset = function (size) {
this.canvasSize = size;
this.streamWriter.clear();
this.initialize();
this.initializeCoordinates();
};
PdfGraphics.prototype.shouldJustify = function (lineInfo, boundsWidth, format) {
var line = lineInfo.text;
var lineWidth = lineInfo.width;
var justifyStyle = (format != null && format.alignment === enum_1.PdfTextAlignment.Justify);
var goodWidth = (boundsWidth >= 0 && lineWidth < boundsWidth);
var symbols = string_tokenizer_1.StringTokenizer.spaces;
var whitespacesCount = string_tokenizer_1.StringTokenizer.getCharsCount(line, symbols);
var hasSpaces = (whitespacesCount > 0 && line[0] !== string_tokenizer_1.StringTokenizer.whiteSpace);
var goodLineBreakStyle = ((lineInfo.lineType & string_layouter_1.LineType.LayoutBreak) > 0) || (format && format.wordWrap === enum_3.PdfWordWrapType.None);
var shouldJustify = (justifyStyle && goodWidth && hasSpaces && goodLineBreakStyle);
return shouldJustify;
};
PdfGraphics.prototype.underlineStrikeoutText = function (pen, brush, result, font, layoutRectangle, format) {
Iif (font.underline || font.strikeout) {
var linePen = this.createUnderlineStikeoutPen(pen, brush, font, format);
if (linePen != null) {
var vShift = this.getTextVerticalAlignShift(result.actualSize.height, layoutRectangle.height, format);
var underlineYOffset = 0;
underlineYOffset = layoutRectangle.y + vShift + font.metrics.getAscent(format) + 1.5 * linePen.width;
var strikeoutYOffset = layoutRectangle.y + vShift + font.metrics.getHeight(format) / 2 + 1.5 * linePen.width;
var lines = result.lines;
for (var i = 0, len = result.lineCount; i < len; i++) {
var lineInfo = lines[i];
var line = lineInfo.text;
var lineWidth = lineInfo.width;
var hShift = this.getHorizontalAlignShift(lineWidth, layoutRectangle.width, format);
var lineIndent = this.getLineIndent(lineInfo, format, layoutRectangle, (i === 0));
hShift += (!this.rightToLeft(format)) ? lineIndent : 0;
var x1 = layoutRectangle.x + hShift;
var x2 = (!this.shouldJustify(lineInfo, layoutRectangle.width, format)) ? x1 + lineWidth - lineIndent : x1 + layoutRectangle.width - lineIndent;
if (font.underline) {
var y = underlineYOffset;
this.drawLine(linePen, x1, y, x2, y);
underlineYOffset += result.lineHeight;
}
if (font.strikeout) {
var y = strikeoutYOffset;
this.drawLine(linePen, x1, y, x2, y);
strikeoutYOffset += result.lineHeight;
}
if (this.isPointOverload && lines.length > 1) {
layoutRectangle.x = 0;
layoutRectangle.width = this.clientSize.width;
}
}
this.isPointOverload = false;
}
}
};
PdfGraphics.prototype.createUnderlineStikeoutPen = function (pen, brush, font, format) {
var lineWidth = font.metrics.getSize(format) / 20;
var linePen = null;
if (pen != null) {
linePen = new pdf_pen_1.PdfPen(pen.color, lineWidth);
}
else if (brush != null) {
linePen = new pdf_pen_1.PdfPen(brush, lineWidth);
}
return linePen;
};
PdfGraphics.prototype.getTextRenderingMode = function (pen, brush, format) {
var tm = enum_1.TextRenderingMode.None;
Iif (pen != null && brush != null) {
tm = enum_1.TextRenderingMode.FillStroke;
}
else Iif (pen != null) {
tm = enum_1.TextRenderingMode.Stroke;
}
else {
tm = enum_1.TextRenderingMode.Fill;
}
Iif (format != null && format.clipPath) {
tm |= enum_1.TextRenderingMode.ClipFlag;
}
return tm;
};
PdfGraphics.prototype.getLineIndent = function (lineInfo, format, layoutBounds, firstLine) {
var lineIndent = 0;
var firstParagraphLine = ((lineInfo.lineType & string_layouter_1.LineType.FirstParagraphLine) > 0);
if (format != null && firstParagraphLine) {
lineIndent = (firstLine) ? format.firstLineIndent : format.paragraphIndent;
lineIndent = (layoutBounds.width > 0) ? Math.min(layoutBounds.width, lineIndent) : lineIndent;
}
return lineIndent;
};
PdfGraphics.prototype.getHorizontalAlignShift = function (lineWidth, boundsWidth, format) {
var shift = 0;
if (boundsWidth >= 0 && format != null && format.alignment !== enum_1.PdfTextAlignment.Left) {
switch (format.alignment) {
case enum_1.PdfTextAlignment.Center:
shift = (boundsWidth - lineWidth) / 2;
break;
case enum_1.PdfTextAlignment.Right:
shift = boundsWidth - lineWidth;
break;
}
}
return shift;
};
PdfGraphics.prototype.rightToLeft = function (format) {
var rtl = (format !== null && typeof format !== 'undefined' && format.rightToLeft);
if (format !== null && typeof format !== 'undefined') {
Iif (format.textDirection !== enum_4.PdfTextDirection.None && typeof format.textDirection !== 'undefined') {
rtl = true;
}
}
return rtl;
};
PdfGraphics.prototype.stateControl = function (pen, brush, font, format) {
if (typeof format === 'undefined') {
this.stateControl(pen, brush, font, null);
}
else {
if (brush instanceof pdf_gradient_brush_1.PdfGradientBrush) {
this.bCSInitialized = false;
brush.colorSpace = this.colorSpace;
}
Iif (brush instanceof pdf_tiling_brush_1.PdfTilingBrush) {
this.bCSInitialized = false;
brush.graphics.colorSpace = this.colorSpace;
}
var saveState = false;
if (brush !== null) {
var solidBrush = brush;
if (typeof this.pageLayer !== 'undefined' && this.pageLayer != null) {
if (this.colorSpaceChanged === false) {
this.lastDocumentCS = this.pageLayer.page.document.colorSpace;
this.lastGraphicsCS = this.pageLayer.page.graphics.colorSpace;
this.colorSpace = this.pageLayer.page.document.colorSpace;
this.currentColorSpace = this.pageLayer.page.document.colorSpace;
this.colorSpaceChanged = true;
}
}
this.initCurrentColorSpace(this.currentColorSpace);
}
else Eif (pen != null) {
var pdfPen = pen;
Eif (typeof this.pageLayer !== 'undefined' && this.pageLayer != null) {
this.colorSpace = this.pageLayer.page.document.colorSpace;
this.currentColorSpace = this.pageLayer.page.document.colorSpace;
}
this.initCurrentColorSpace(this.currentColorSpace);
}
this.penControl(pen, saveState);
this.brushControl(brush, saveState);
this.fontControl(font, format, saveState);
}
};
PdfGraphics.prototype.initCurrentColorSpace = function (colorspace) {
var re = this.getResources.getResources();
if (!this.bCSInitialized) {
Eif (this.currentColorSpace != enum_1.PdfColorSpace.GrayScale) {
this.pdfStreamWriter.setColorSpace('Device' + this.currentColorSpaces[this.currentColorSpace], true);
this.pdfStreamWriter.setColorSpace('Device' + this.currentColorSpaces[this.currentColorSpace], false);
this.bCSInitialized = true;
}
else {
this.pdfStreamWriter.setColorSpace('DeviceGray', true);
this.pdfStreamWriter.setColorSpace('DeviceGray', false);
this.bCSInitialized = true;
}
}
};
PdfGraphics.prototype.penControl = function (pen, saveState) {
if (pen != null) {
this.currentPen = pen;
pen.monitorChanges(this.currentPen, this.pdfStreamWriter, this.getResources, saveState, this.colorSpace, this.matrix.clone());
this.currentPen = pen.clone();
}
};
PdfGraphics.prototype.brushControl = function (brush, saveState) {
if (brush != null && typeof brush !== 'undefined') {
var b = brush.clone();
var lgb = b;
if (lgb !== null && typeof lgb !== 'undefined' && !(brush instanceof pdf_solid_brush_1.PdfSolidBrush) && !(brush instanceof pdf_tiling_brush_1.PdfTilingBrush)) {
var m = lgb.matrix;
var matrix = this.matrix.clone();
Iif ((m != null)) {
m.multiply(matrix);
matrix = m;
}
lgb.matrix = matrix;
}
this.currentBrush = lgb;
var br = (brush);
b.monitorChanges(this.currentBrush, this.pdfStreamWriter, this.getResources, saveState, this.colorSpace);
this.currentBrush = brush;
brush = null;
}
};
PdfGraphics.prototype.fontControl = function (font, format, saveState) {
if (font != null) {
var curSubSuper = (format != null) ? format.subSuperScript : enum_3.PdfSubSuperScript.None;
var prevSubSuper = (this.currentStringFormat != null) ? this.currentStringFormat.subSuperScript : enum_3.PdfSubSuperScript.None;
if (saveState || font !== this.currentFont || curSubSuper !== prevSubSuper) {
var resources = this.getResources.getResources();
this.currentFont = font;
this.currentStringFormat = format;
var size = font.metrics.getSize(format);
this.isEmfTextScaled = false;
var fontName = resources.getName(font);
this.pdfStreamWriter.setFont(font, fontName, size);
}
}
};
PdfGraphics.prototype.setTransparency = function (arg1, arg2, arg3) {
if (typeof arg2 === 'undefined') {
this.istransparencySet = true;
this.setTransparency(arg1, arg1, enum_2.PdfBlendMode.Normal);
}
else if (typeof arg2 === 'number' && typeof arg3 === 'undefined') {
this.setTransparency(arg1, arg2, enum_2.PdfBlendMode.Normal);
}
else {
if (this.trasparencies == null) {
this.trasparencies = new dictionary_1.TemporaryDictionary();
}
var transp = null;
var td = new TransparencyData(arg1, arg2, arg3);
if (this.trasparencies.containsKey(td)) {
transp = this.trasparencies.getValue(td);
}
if (transp == null) {
transp = new pdf_transparency_1.PdfTransparency(arg1, arg2, arg3);
this.trasparencies.setValue(td, transp);
}
var resources = this.getResources.getResources();
var name_3 = resources.getName(transp);
var sw = this.streamWriter;
sw.setGraphicsState(name_3);
}
};
PdfGraphics.prototype.clipTranslateMargins = function (x, y, left, top, right, bottom) {
Eif (x instanceof pdf_drawing_1.RectangleF && typeof y === 'undefined') {
this.clipBounds = x;
this.pdfStreamWriter.writeComment('Clip margins.');
this.pdfStreamWriter.appendRectangle(x);
this.pdfStreamWriter.closePath();
this.pdfStreamWriter.clipPath(false);
this.pdfStreamWriter.writeComment('Translate co-ordinate system.');
this.translateTransform(x.x, x.y);
}
else if (typeof x === 'number') {
var clipArea = new pdf_drawing_1.RectangleF(left, top, this.size.width - left - right, this.size.height - top - bottom);
this.clipBounds = clipArea;
this.pdfStreamWriter.writeComment("Clip margins.");
this.pdfStreamWriter.appendRectangle(clipArea);
this.pdfStreamWriter.closePath();
this.pdfStreamWriter.clipPath(false);
this.pdfStreamWriter.writeComment("Translate co-ordinate system.");
this.translateTransform(x, y);
}
};
PdfGraphics.prototype.updateY = function (y) {
return -y;
};
PdfGraphics.prototype.translateTransform = function (offsetX, offsetY) {
var matrix = new pdf_transformation_matrix_1.PdfTransformationMatrix();
this.getTranslateTransform(offsetX, offsetY, matrix);
this.pdfStreamWriter.modifyCtm(matrix);
this.matrix.multiply(matrix);
};
PdfGraphics.prototype.getTranslateTransform = function (x, y, input) {
input.translate(x, this.updateY(y));
return input;
};
PdfGraphics.prototype.scaleTransform = function (scaleX, scaleY) {
var matrix = new pdf_transformation_matrix_1.PdfTransformationMatrix();
this.getScaleTransform(scaleX, scaleY, matrix);
this.pdfStreamWriter.modifyCtm(matrix);
this.matrix.multiply(matrix);
};
PdfGraphics.prototype.getScaleTransform = function (x, y, input) {
if (input == null) {
input = new pdf_transformation_matrix_1.PdfTransformationMatrix();
}
input.scale(x, y);
return input;
};
PdfGraphics.prototype.rotateTransform = function (angle) {
var matrix = new pdf_transformation_matrix_1.PdfTransformationMatrix();
this.getRotateTransform(angle, matrix);
this.pdfStreamWriter.modifyCtm(matrix);
this.matrix.multiply(matrix);
};
PdfGraphics.prototype.initializeCoordinates = function () {
this.pdfStreamWriter.writeComment('Change co-ordinate system to left/top.');
Eif (this.mediaBoxUpperRightBound !== -(this.size.height)) {
Eif (this.cropBox == null) {
Eif (this.mediaBoxUpperRightBound === this.size.height || this.mediaBoxUpperRightBound === 0) {
this.translateTransform(0, this.updateY(this.size.height));
}
else {
this.translateTransform(0, this.updateY(this.mediaBoxUpperRightBound));
}
}
}
};
PdfGraphics.prototype.getRotateTransform = function (angle, input) {
if (input == null || typeof input === 'undefined') {
input = new pdf_transformation_matrix_1.PdfTransformationMatrix();
}
input.rotate(this.updateY(angle));
return input;
};
PdfGraphics.prototype.save = function () {
var state = new PdfGraphicsState(this, this.matrix.clone());
state.brush = this.currentBrush;
state.pen = this.currentPen;
state.font = this.currentFont;
state.colorSpace = this.currentColorSpace;
state.characterSpacing = this.previousCharacterSpacing;
state.wordSpacing = this.previousWordSpacing;
state.textScaling = this.previousTextScaling;
state.textRenderingMode = this.previousTextRenderingMode;
this.graphicsState.push(state);
this.pdfStreamWriter.saveGraphicsState();
return state;
};
PdfGraphics.prototype.restore = function (state) {
Iif (typeof state === 'undefined') {
if (this.graphicsState.length > 0) {
this.doRestoreState();
}
}
else {
Eif (this.graphicsState.indexOf(state) !== -1) {
for (;;) {
Iif (this.graphicsState.length === 0) {
break;
}
var popState = this.doRestoreState();
Eif (popState === state) {
break;
}
}
}
}
};
PdfGraphics.prototype.doRestoreState = function () {
var state = this.graphicsState.pop();
this.transformationMatrix = state.matrix;
this.currentBrush = state.brush;
this.currentPen = state.pen;
this.currentFont = state.font;
this.currentColorSpace = state.colorSpace;
this.previousCharacterSpacing = state.characterSpacing;
this.previousWordSpacing = state.wordSpacing;
this.previousTextScaling = state.textScaling;
this.previousTextRenderingMode = state.textRenderingMode;
this.pdfStreamWriter.restoreGraphicsState();
return state;
};
PdfGraphics.prototype.drawPath = function (pen, brush, path) {
this._drawPath(pen, brush, path.pathPoints, path.pathTypes, path.fillMode);
};
PdfGraphics.prototype._drawPath = function (pen, brush, pathPoints, pathTypes, fillMode) {
if (brush instanceof pdf_tiling_brush_1.PdfTilingBrush) {
this.bCSInitialized = false;
brush.graphics.colorSpace = this.colorSpace;
}
else if (brush instanceof pdf_gradient_brush_1.PdfGradientBrush) {
this.bCSInitialized = false;
brush.colorSpace = this.colorSpace;
}
this.stateControl(pen, brush, null);
this.buildUpPath(pathPoints, pathTypes);
this.drawPathHelper(pen, brush, fillMode, false);
};
PdfGraphics.prototype.drawArc = function (arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
if (arg2 instanceof pdf_drawing_1.RectangleF) {
this.drawArc(arg1, arg2.x, arg2.y, arg2.width, arg2.height, arg3, arg4);
}
else {
if ((arg7 !== 0)) {
this.stateControl(arg1, null, null);
this.constructArcPath(arg2, arg3, (arg2 + arg4), (arg3 + arg5), arg6, arg7);
this.drawPathHelper(arg1, null, false);
}
}
};
PdfGraphics.prototype.buildUpPath = function (arg1, arg2) {
var cnt = arg1.length;
for (var i = 0; i < cnt; ++i) {
var typeValue = 0;
var point = arg1[i];
switch (((arg2[i] & (PdfGraphics.pathTypesValuesMask)))) {
case enum_5.PathPointType.Start:
this.pdfStreamWriter.beginPath(point.x, point.y);
break;
case enum_5.PathPointType.Bezier3:
var p2 = new pdf_drawing_1.PointF(0, 0);
var p3 = new pdf_drawing_1.PointF(0, 0);
var result1 = this.getBezierPoints(arg1, arg2, i, p2, p3);
this.pdfStreamWriter.appendBezierSegment(point, result1.p2, result1.p3);
i = result1.i;
break;
case enum_5.PathPointType.Line:
this.pdfStreamWriter.appendLineSegment(point);
break;
default:
throw new Error('ArithmeticException - Incorrect path formation.');
}
typeValue = arg2[i];
this.checkFlags(typeValue);
}
};
PdfGraphics.prototype.getBezierPoints = function (points, types, i, p2, p3) {
var errorMsg = 'Malforming path.';
++i;
if ((((types[i] & PdfGraphics.pathTypesValuesMask)) === enum_5.PathPointType.Bezier3)) {
p2 = points[i];
++i;
if ((((types[i] & PdfGraphics.pathTypesValuesMask)) === enum_5.PathPointType.Bezier3)) {
p3 = points[i];
}
else {
throw new Error('ArgumentException : errorMsg');
}
}
else {
throw new Error('ArgumentException : errorMsg');
}
return { i: i, p2: p2, p3: p3 };
};
PdfGraphics.prototype.checkFlags = function (type) {
if ((((type & (enum_5.PathPointType.CloseSubpath))) === enum_5.PathPointType.CloseSubpath)) {
this.pdfStreamWriter.closePath();
}
};
PdfGraphics.prototype.constructArcPath = function (x1, y1, x2, y2, startAng, sweepAngle) {
var points = this.getBezierArc(x1, y1, x2, y2, startAng, sweepAngle);
if ((points.length === 0)) {
return;
}
var pt = [points[0], points[1], points[2], points[3], points[4], points[5], points[6], points[7]];
this.pdfStreamWriter.beginPath(pt[0], pt[1]);
var i = 0;
for (i = 0; i < points.length; i = i + 8) {
pt = [points[i], points[i + 1], points[i + 2], points[i + 3], points[i + 4], points[i + 5], points[i + 6], points[i + 7]];
this.pdfStreamWriter.appendBezierSegment(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]);
}
};
PdfGraphics.prototype.getBezierArc = function (numX1, numY1, numX2, numY2, s1, e1) {
if ((numX1 > numX2)) {
var tmp = void 0;
tmp = numX1;
numX1 = numX2;
numX2 = tmp;
}
if ((numY2 > numY1)) {
var tmp = void 0;
tmp = numY1;
numY1 = numY2;
numY2 = tmp;
}
var fragAngle1;
var numFragments;
if ((Math.abs(e1) <= 90)) {
fragAngle1 = e1;
numFragments = 1;
}
else {
numFragments = (Math.ceil((Math.abs(e1) / 90)));
fragAngle1 = (e1 / numFragments);
}
var xcen = ((numX1 + numX2) / 2);
var ycen = ((numY1 + numY2) / 2);
var rx = ((numX2 - numX1) / 2);
var ry = ((numY2 - numY1) / 2);
var halfAng = ((fragAngle1 * (Math.PI / 360)));
var kappa = (Math.abs(4.0 / 3.0 * (1.0 - Math.cos(halfAng)) / Math.sin(halfAng)));
var pointsList = [];
for (var i = 0; (i < numFragments); i++) {
var thetaValue0 = (((s1 + (i * fragAngle1)) * (Math.PI / 180)));
var thetaValue1 = (((s1 + ((i + 1) * fragAngle1)) * (Math.PI / 180)));
var cos0 = (Math.cos(thetaValue0));
var cos1 = (Math.cos(thetaValue1));
var sin0 = (Math.sin(thetaValue0));
var sin1 = (Math.sin(thetaValue1));
if ((fragAngle1 > 0)) {
pointsList.push((xcen + (rx * cos0)), (ycen - (ry * sin0)), (xcen + (rx * (cos0 - (kappa * sin0)))), (ycen - (ry * (sin0 + (kappa * cos0)))), (xcen + (rx * (cos1 + (kappa * sin1)))), (ycen - (ry * (sin1 - (kappa * cos1)))), (xcen + (rx * cos1)), (ycen - (ry * sin1)));
}
else {
pointsList.push((xcen + (rx * cos0)), (ycen - (ry * sin0)), (xcen + (rx * (cos0 + (kappa * sin0)))), (ycen - (ry * (sin0 - (kappa * cos0)))), (xcen + (rx * (cos1 - (kappa * sin1)))), (ycen - (ry * (sin1 + (kappa * cos1)))), (xcen + (rx * cos1)), (ycen - (ry * sin1)));
}
}
return pointsList;
};
PdfGraphics.pathTypesValuesMask = 0xf;
PdfGraphics.transparencyObject = false;
return PdfGraphics;
}());
exports.PdfGraphics = PdfGraphics;
var GetResourceEventHandler = (function () {
function GetResourceEventHandler(sender) {
this.sender = sender;
}
GetResourceEventHandler.prototype.getResources = function () {
return this.sender.getResources();
};
return GetResourceEventHandler;
}());
exports.GetResourceEventHandler = GetResourceEventHandler;
var PdfGraphicsState = (function () {
function PdfGraphicsState(graphics, matrix) {
this.internalTextRenderingMode = enum_1.TextRenderingMode.Fill;
this.internalCharacterSpacing = 0.0;
this.internalWordSpacing = 0.0;
this.internalTextScaling = 100.0;
this.pdfColorSpace = enum_1.PdfColorSpace.Rgb;
Eif (typeof graphics !== 'undefined') {
this.pdfGraphics = graphics;
var elements_1 = [];
graphics.matrix.matrix.elements.forEach(function (element) {
elements_1.push(element);
});
this.transformationMatrix = new pdf_transformation_matrix_1.PdfTransformationMatrix();
this.transformationMatrix.matrix = new pdf_transformation_matrix_1.Matrix(elements_1);
}
}
Object.defineProperty(PdfGraphicsState.prototype, "graphics", {
get: function () {
return this.pdfGraphics;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphicsState.prototype, "matrix", {
get: function () {
return this.transformationMatrix;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphicsState.prototype, "characterSpacing", {
get: function () {
return this.internalCharacterSpacing;
},
set: function (value) {
this.internalCharacterSpacing = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphicsState.prototype, "wordSpacing", {
get: function () {
return this.internalWordSpacing;
},
set: function (value) {
this.internalWordSpacing = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphicsState.prototype, "textScaling", {
get: function () {
return this.internalTextScaling;
},
set: function (value) {
this.internalTextScaling = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphicsState.prototype, "pen", {
get: function () {
return this.pdfPen;
},
set: function (value) {
this.pdfPen = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphicsState.prototype, "brush", {
get: function () {
return this.pdfBrush;
},
set: function (value) {
this.pdfBrush = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphicsState.prototype, "font", {
get: function () {
return this.pdfFont;
},
set: function (value) {
this.pdfFont = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphicsState.prototype, "colorSpace", {
get: function () {
return this.pdfColorSpace;
},
set: function (value) {
this.pdfColorSpace = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfGraphicsState.prototype, "textRenderingMode", {
get: function () {
return this.internalTextRenderingMode;
},
set: function (value) {
this.internalTextRenderingMode = value;
},
enumerable: true,
configurable: true
});
return PdfGraphicsState;
}());
exports.PdfGraphicsState = PdfGraphicsState;
var TransparencyData = (function () {
function TransparencyData(alphaPen, alphaBrush, blendMode) {
this.alphaPen = alphaPen;
this.alphaBrush = alphaBrush;
this.blendMode = blendMode;
}
return TransparencyData;
}());
});
|