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
|
(* CFF Font Support *)
open Utility
open Pdfio
type dictop =
| IntOp of int32
| RealOp of float
| Operator of int
| Operator2 of int
let string_of_dictop = function
| IntOp i -> "IntOp " ^ Int32.to_string i
| RealOp f -> "RealOp " ^ string_of_float f
| Operator i -> "Operator " ^ string_of_int i
| Operator2 i -> "Operator2 " ^ string_of_int i
let string_of_dictops ops =
fold_left (fun a b -> a ^ "\n" ^ b) "" (map string_of_dictop ops)
let read_card8 b =
i32toi (getval_32 b 8)
let read_card16 b =
i32toi (getval_32 b 16)
let discard_bytes b n =
for x = 1 to n do ignore (getval_32 b 8) done
let read_string b l =
let chars = ref [] in
for x = 1 to l do chars =| char_of_int (i32toi (getval_32 b 8)) done;
implode (rev !chars)
let read_index b =
let count = read_card16 b in
if count = 0 then [] else
let offsize = read_card8 b * 8 in
let offsets = ref [] in
(*i Printf.printf "read_index: count = %i, offsize = %i bytes\n" count
* offsize; i*)
for x = 1 to count + 1 do offsets =| i32toi (getval_32 b offsize) done;
let offsets = rev !offsets in
(*i Printf.printf "Got %i offsets from index\n" (length offsets); i*)
map (fun (x, y) -> y - x) (pairs offsets)
(* Read a dictionary, creating a dictop list, and parse to (key, value) pairs. l
is the length of the dictionary. *)
let rec read_float_dict_item prev n_read b =
match i32toi (getval_32 b 4) with
| 0xF ->
align b;
((n_read + 2) / 2), Scanf.sscanf (implode (rev prev)) "%f" ident
| 0x0 -> read_float_dict_item ('0'::prev) (n_read + 1) b
| 0x1 -> read_float_dict_item ('1'::prev) (n_read + 1) b
| 0x2 -> read_float_dict_item ('2'::prev) (n_read + 1) b
| 0x3 -> read_float_dict_item ('3'::prev) (n_read + 1) b
| 0x4 -> read_float_dict_item ('4'::prev) (n_read + 1) b
| 0x5 -> read_float_dict_item ('5'::prev) (n_read + 1) b
| 0x6 -> read_float_dict_item ('6'::prev) (n_read + 1) b
| 0x7 -> read_float_dict_item ('7'::prev) (n_read + 1) b
| 0x8 -> read_float_dict_item ('8'::prev) (n_read + 1) b
| 0x9 -> read_float_dict_item ('9'::prev) (n_read + 1) b
| 0xA -> read_float_dict_item ('.'::prev) (n_read + 1) b
| 0xB -> read_float_dict_item ('E'::prev) (n_read + 1) b
| 0xC -> read_float_dict_item ('-'::'E'::prev) (n_read + 1) b
| 0xD -> read_float_dict_item prev (n_read + 1) b
| 0xE -> read_float_dict_item ('-'::prev) (n_read + 1) b
| _ -> assert false
let read_dict_item b =
let b1 = read_card8 b in
if b1 >= 0 && b1 <= 21 then
if b1 = 12 then
let b2 = read_card8 b in
2, Operator2 b2
else
1, Operator b1
else if b1 = 28 then
let ob1 = read_card8 b in
let ob2 = read_card8 b in
3, IntOp (i32ofi ((ob1 lsl 8) lor ob2))
else if b1 = 29 then
let ob1 = getval_32 b 8 in
let ob2 = getval_32 b 8 in
let ob3 = getval_32 b 8 in
let ob4 = getval_32 b 8 in
let v =
lor32
(lor32 (lsl32 ob1 24) (lsl32 ob2 16))
(lor32 (lsl32 ob3 8) ob4)
in
5, IntOp v
else if b1 >= 32 && b1 <= 246 then
1, IntOp (i32ofi (b1 - 139))
else if b1 >= 247 && b1 <= 250 then
let ob1 = read_card8 b in
2, IntOp (i32ofi ((b1 - 247) * 256 + ob1 + 108))
else if b1 >= 251 && b1 <= 254 then
let ob1 = read_card8 b in
2, IntOp (i32ofi ((~- (b1 - 251)) * 256 - ob1 - 108))
else if b1 = 30 then
let bytes_read, num = read_float_dict_item [] 0 b in
bytes_read + 1, RealOp num
else
raise (Pdf.PDFError "bad operator/operand in read_dict_item")
let rec read_dict prev b l =
if l <= 0 then rev prev else
let bytes_read, op = read_dict_item b in
read_dict (op::prev) b (l - bytes_read)
(* In code, out code *)
let standard_encoding =
[(0, 0); (1, 0); (2, 0); (3, 0); (4, 0); (5, 0); (6, 0); (7, 0); (8, 0);
(9, 0); (10, 0); (11, 0); (12, 0); (13, 0); (14, 0); (15, 0); (16, 0);
(17, 0); (18, 0); (19, 0); (20, 0); (21, 0); (22, 0); (23, 0); (24, 0);
(25, 0); (26, 0); (27, 0); (28, 0); (29, 0); (30, 0); (31, 0); (32, 1);
(33, 2); (34, 3); (35, 4); (36, 5); (37, 6); (38, 7); (39, 8); (40, 9);
(41, 10); (42, 11); (43, 12); (44, 13); (45, 14); (46, 15); (47, 16);
(48, 17); (49, 18); (50, 19); (51, 20); (52, 21); (53, 22); (54, 23);
(55, 24); (56, 25); (57, 26); (58, 27); (59, 28); (60, 29); (61, 30);
(62, 31); (63, 32); (64, 33); (65, 34); (66, 35); (67, 36); (68, 37);
(69, 38); (70, 39); (71, 40); (72, 41); (73, 42); (74, 43); (75, 44);
(76, 45); (77, 46); (78, 47); (79, 48); (80, 49); (81, 50); (82, 51);
(83, 52); (84, 53); (85, 54); (86, 55); (87, 56); (88, 57); (89, 58);
(90, 59); (91, 60); (92, 61); (93, 62); (94, 63); (95, 64); (96, 65);
(97, 66); (98, 67); (99, 68); (100, 69); (101, 70); (102, 71); (103, 72);
(104, 73); (105, 74); (106, 75); (107, 76); (108, 77); (109, 78); (110, 79);
(111, 80); (112, 81); (113, 82); (114, 83); (115, 84); (116, 85); (117, 86);
(118, 87); (119, 88); (120, 89); (121, 90); (122, 91); (123, 92); (124, 93);
(125, 94); (126, 95); (127, 0); (128, 0); (129, 0); (130, 0); (131, 0);
(132, 0); (133, 0); (134, 0); (135, 0); (136, 0); (137, 0); (138, 0);
(139, 0); (140, 0); (141, 0); (142, 0); (143, 0); (144, 0); (145, 0);
(146, 0); (147, 0); (148, 0); (149, 0); (150, 0); (151, 0); (152, 0);
(153, 0); (154, 0); (155, 0); (156, 0); (157, 0); (158, 0); (159, 0);
(160, 0); (161, 96); (162, 97); (163, 98); (164, 99); (165, 100); (166, 101);
(167, 102); (168, 103); (169, 104); (170, 105); (171, 106); (172, 107);
(173, 108); (174, 109); (175, 110); (176, 0); (177, 111); (178, 112);
(179, 113); (180, 114); (181, 0); (182, 115); (183, 116); (184, 117);
(185, 118); (186, 119); (187, 120); (188, 121); (189, 122); (190, 0);
(191, 123); (192, 0); (193, 124); (194, 125); (195, 126); (196, 127);
(197, 128); (198, 129); (199, 130); (200, 131); (201, 0); (202, 132);
(203, 133); (204, 0); (205, 134); (206, 135); (207, 136); (208, 137);
(209, 0); (210, 0); (211, 0); (212, 0); (213, 0); (214, 0); (215, 0);
(216, 0); (217, 0); (218, 0); (219, 0); (220, 0); (221, 0); (222, 0);
(223, 0); (224, 0); (225, 138); (226, 0); (227, 139); (228, 0); (229, 0);
(230, 0); (231, 0); (232, 140); (233, 141); (234, 142); (235, 143);
(236, 0); (237, 0); (238, 0); (239, 0); (240, 0); (241, 144); (242, 0);
(243, 0); (244, 0); (245, 145); (246, 0); (247, 0); (248, 146); (249, 147);
(250, 148); (251, 149); (252, 0); (253, 0); (254, 0); (255, 0)]
let expert_encoding =
[(0, 0); (1, 0); (2, 0); (3, 0); (4, 0); (5, 0); (6, 0); (7, 0); (8, 0);
(9, 0); (10, 0); (11, 0); (12, 0); (13, 0); (14, 0); (15, 0); (16, 0);
(17, 0); (18, 0); (19, 0); (20, 0); (21, 0); (22, 0); (23, 0); (24, 0);
(25, 0); (26, 0); (27, 0); (28, 0); (29, 0); (30, 0); (31, 0); (32, 1);
(33, 229); (34, 230); (35, 0); (36, 231); (37, 232); (38, 233); (39, 234);
(40, 235); (41, 236); (42, 237); (43, 238); (44, 13); (45, 14); (46, 15);
(47, 99); (48, 239); (49, 240); (50, 241); (51, 242); (52, 243); (53, 244);
(54, 245); (55, 246); (56, 247); (57, 248); (58, 27); (59, 28); (60, 249);
(61, 250); (62, 251); (63, 252); (64, 0); (65, 253); (66, 254); (67, 255);
(68, 256); (69, 257); (70, 0); (71, 0); (72, 0); (73, 258); (74, 0); (75, 0);
(76, 259); (77, 260); (78, 261); (79, 262); (80, 0); (81, 0); (82, 263);
(83, 264); (84, 265); (85, 0); (86, 266); (87, 109); (88, 110); (89, 267);
(90, 268); (91, 269); (92, 0); (93, 270); (94, 271); (95, 272); (96, 273);
(97, 274); (98, 275); (99, 276); (100, 277); (101, 278); (102, 279);
(103, 280); (104, 281); (105, 282); (106, 283); (107, 284); (108, 285);
(109, 286); (110, 287); (111, 288); (112, 289); (113, 290); (114, 291);
(115, 292); (116, 293); (117, 294); (118, 295); (119, 296); (120, 297);
(121, 298); (122, 299); (123, 300); (124, 301); (125, 302); (126, 303);
(127, 0); (128, 0); (129, 0); (130, 0); (131, 0); (132, 0); (133, 0);
(134, 0); (135, 0); (136, 0); (137, 0); (138, 0); (139, 0); (140, 0);
(141, 0); (142, 0); (143, 0); (144, 0); (145, 0); (146, 0); (147, 0);
(148, 0); (149, 0); (150, 0); (151, 0); (152, 0); (153, 0); (154, 0);
(155, 0); (156, 0); (157, 0); (158, 0); (159, 0); (160, 0); (161, 304);
(162, 305); (163, 306); (164, 0); (165, 0); (166, 307); (167, 308);
(168, 309); (169, 310); (170, 311); (171, 0); (172, 312); (173, 0);
(174, 0); (175, 313); (176, 0); (177, 0); (178, 314); (179, 315);
(180, 0); (181, 0); (182, 316); (183, 317); (184, 318); (185, 0); (186, 0);
(187, 0); (188, 158); (189, 155); (190, 163); (191, 319); (192, 320);
(193, 321); (194, 322); (195, 323); (196, 324); (197, 325); (198, 0);
(199, 0); (200, 326); (201, 150); (202, 164); (203, 169); (204, 327);
(205, 328); (206, 329); (207, 330); (208, 331); (208, 332); (209, 332);
(210, 333); (211, 334); (212, 335); (213, 336); (214, 337); (215, 338);
(216, 339); (217, 340); (218, 341); (219, 342); (220, 343); (221, 344);
(222, 345); (223, 346); (224, 347); (225, 348); (226, 349); (227, 350);
(228, 351); (229, 352); (230, 353); (231, 354); (232, 355); (233, 356);
(234, 357); (235, 358); (236, 359); (237, 360); (238, 361); (239, 362);
(240, 363); (241, 364); (242, 365); (243, 366); (244, 367); (245, 268);
(246, 369); (247, 370); (248, 371); (249, 372); (250, 373); (251, 374);
(252, 375); (253, 376); (254, 377); (255, 378)]
let sids =
[(0, ".notdef"); (1, "space"); (2, "exclam"); (3, "quotedbl"); (4, "numbersign");
(5, "dollar"); (6, "percent"); (7, "ampersand"); (8, "quoteright"); (9, "parenleft");
(10, "parenright"); (11, "asterisk"); (12, "plus"); (13, "comma"); (14, "hyphen");
(15, "period"); (16, "slash"); (17, "zero"); (18, "one"); (19, "two"); (20, "three");
(21, "four"); (22, "five"); (23, "six"); (24, "seven"); (25, "eight"); (26, "nine");
(27, "colon"); (28, "semicolon"); (29, "less"); (30, "equal"); (31, "greater");
(32, "question"); (33, "at"); (34, "A"); (35, "B"); (36, "C"); (37, "D"); (38, "E");
(39, "F"); (40, "G"); (41, "H"); (42, "I"); (43, "J"); (44, "K"); (45, "L"); (46, "M");
(47, "N"); (48, "O"); (49, "P"); (50, "Q"); (51, "R"); (52, "S"); (53, "T"); (54, "U");
(55, "V"); (56, "W"); (57, "X"); (58, "Y"); (59, "Z"); (60, "bracketleft");
(61, "backslash"); (62, "bracketright"); (63, "asciicircum"); (64, "underscore");
(65, "quoteleft"); (66, "a"); (67, "b"); (68, "c"); (69, "d"); (70, "e"); (71, "f");
(72, "g"); (73, "h"); (74, "i"); (75, "j"); (76, "k"); (77, "l"); (78, "m"); (79, "n");
(80, "o"); (81, "p"); (82, "q"); (83, "r"); (84, "s"); (85, "t"); (86, "u"); (87, "v");
(88, "w"); (89, "x"); (90, "y"); (91, "z"); (92, "braceleft"); (93, "bar");
(94, "braceright"); (95, "asciitilde"); (96, "exclamdown"); (97, "cent"); (98, "sterling");
(99, "fraction"); (100, "yen"); (101, "florin"); (102, "section"); (103, "currency");
(104, "quotesingle"); (105, "quotedblleft"); (106, "guillemotleft"); (107, "guilsinglleft");
(108, "guilsinglright"); (109, "fi"); (110, "fl"); (111, "endash"); (112, "dagger");
(113, "daggerdbl"); (114, "periodcentered"); (115, "paragraph"); (116, "bullet");
(117, "quotesinglbase"); (118, "quotedblbase"); (119, "quotedblright");
(120, "guillemotright"); (121, "ellipsis"); (122, "perthousand"); (123, "questiondown");
(124, "grave"); (125, "acute"); (126, "circumflex"); (127, "tilde"); (128, "macron");
(129, "breve"); (130, "dotaccent"); (131, "dieresis"); (132, "ring"); (133, "cedilla");
(134, "hungarumlaut"); (135, "ogonek"); (136, "caron"); (137, "emdash"); (138, "AE");
(139, "ordfeminine"); (140, "Lslash"); (141, "Oslash"); (142, "OE"); (143, "ordmasculine");
(144, "ae"); (145, "dotlessi"); (146, "lslash"); (147, "oslash"); (148, "oe");
(149, "germandbls"); (150, "onesuperior"); (151, "logicalnot"); (152, "mu");
(153, "trademark"); (154, "Eth"); (155, "onehalf"); (156, "plusminus"); (157, "Thorn");
(158, "onequarter"); (159, "divide"); (160, "brokenbar"); (161, "degree"); (162, "thorn");
(163, "threequarters"); (164, "twosuperior"); (165, "registered"); (166, "minus");
(167, "eth"); (168, "multiply"); (169, "threesuperior"); (170, "copyright");
(171, "Aacute"); (172, "Acircumflex"); (173, "Adieresis"); (174, "Agrave"); (175, "Aring");
(176, "Atilde"); (177, "Ccedilla"); (178, "Eacute"); (179, "Ecircumflex"); (180, "Edieresis");
(181, "Egrave"); (182, "Iacute"); (183, "Icircumflex"); (184, "Idieresis"); (185, "Igrave");
(186, "Ntilde"); (187, "Oacute"); (188, "Ocircumflex"); (189, "Odieresis"); (190, "Ograve");
(191, "Otilde"); (192, "Scaron"); (193, "Uacute"); (194, "Ucircumflex"); (195, "Udieresis");
(196, "Ugrave"); (197, "Yacute"); (198, "Ydieresis"); (199, "Zcaron"); (200, "aacute");
(201, "acircumflex"); (202, "adieresis"); (203, "agrave"); (204, "aring"); (205, "atilde");
(206, "ccedilla"); (207, "eacute"); (208, "ecircumflex"); (209, "edieresis"); (210, "egrave");
(211, "iacute"); (212, "icircumflex"); (213, "idieresis"); (214, "igrave"); (215, "ntilde");
(216, "oacute"); (217, "ocircumflex"); (218, "odieresis"); (219, "ograve"); (220, "otilde");
(221, "scaron"); (222, "uacute"); (223, "ucircumflex"); (224, "udieresis"); (225, "ugrave");
(226, "yacute"); (227, "ydieresis"); (228, "zcaron");
(229, "exclamsmall"); (230, "Hungarumlautsmall"); (231, "dollaroldstyle"); (232, "dollarsuperior");
(233, "ampersandsmall"); (234, "Acutesmall"); (235, "parenleftsuperior");
(236, "parenrightsuperior"); (237, "twodotenleader"); (238, "onedotenleader");
(239, "zerooldstyle"); (240, "oneoldstyle"); (241, "twooldstyle");
(242, "threeoldstyle"); (243, "fouroldstyle"); (244, "fiveoldstyle"); (245, "sixoldstyle");
(246, "sevenoldstyle"); (247, "eightoldstyle"); (248, "nineoldstyle"); (249, "commasuperior");
(250, "threequartersemdash"); (251, "periodsuperior"); (252, "questionsmall");
(253, "asuperior"); (254, "bsuperior"); (255, "centsuperior"); (256, "dsuperior");
(257, "esuperior"); (258, "isuperior"); (259, "lsuperior"); (260, "msuperior"); (261, "nsuperior");
(262, "osuperior"); (263, "rsuperior"); (264, "ssuperior"); (265, "tsuperior");
(266, "ff"); (267, "ffi"); (268, "ffl"); (269, "parenleftinferior"); (270, "parenrightinferior");
(271, "Circumflexsmall"); (272, "hyphensuperior"); (273, "Gravesmall"); (274, "Asmall");
(275, "Bsmall"); (276, "Csmall"); (277, "Dsmall"); (278, "Esmall"); (279, "Fsmall"); (280, "Gsmall");
(281, "Hsmall"); (282, "Ismall"); (283, "Jsmall"); (284, "Ksmall"); (285, "Lsmall"); (286, "Msmall");
(287, "Nsmall"); (288, "Osmall"); (289, "Psmall"); (290, "Qsmall"); (291, "Rsmall"); (292, "Ssmall");
(293, "Tsmall"); (294, "Usmall"); (295, "Vsmall"); (296, "Wsmall"); (297, "Xsmall"); (298, "Ysmall");
(299, "Zsmall"); (300, "colonmonetary"); (301, "onefitted"); (302, "rupiah"); (303, "Tildesmall");
(304, "exclamdownsmall"); (305, "centoldstyle"); (306, "Lslashsmall"); (307, "Scaronsmall");
(308, "Zcaronsmall"); (309, "Dieresissmall"); (310, "Brevesmall"); (311, "Caronsmall");
(312, "Dotaccentsmall"); (313, "Macronsmall"); (314, "figuredash"); (315, "hypheninferior");
(316, "Ogoneksmall"); (317, "Ringsmall"); (318, "Cedillasmall"); (319, "questionsmalldown");
(320, "oneeighth"); (321, "threeeighths"); (322, "fiveeighths"); (323, "seveneighths");
(324, "onethird"); (325, "twothirds"); (326, "zerosuperior"); (327, "foursuperior");
(328, "fivesuperior"); (329, "sixsuperior"); (330, "sevensuperior"); (331, "eightsuperior");
(332, "ninesuperior"); (333, "zeroinferior"); (334, "oneinferior"); (335, "twoinferior");
(336, "threeinferior"); (337, "fourinferior"); (338, "fiveinferior"); (339, "sixinferior");
(340, "seveninferior"); (341, "eightinferior"); (342, "nineinferior"); (343, "centinferior");
(344, "dollarinferior"); (345, "periodinferior"); (346, "commainferior"); (347, "Agravesmall");
(348, "Aacutesmall"); (349, "Acircumflexsmall"); (350, "Atildesmall"); (351, "Adieresissmall");
(352, "Aringsmall"); (353, "AEsmall"); (354, "Ccedillasmall"); (355, "Egravesmall");
(356, "Eacutesmall"); (357, "Ecircumflexsmall"); (358, "Edieresissmall"); (359, "Igravesmall");
(360, "Iacutesmall"); (361, "Icircumflexsmall"); (362, "Idieresissmall"); (363, "Ethsmall");
(364, "Ntildesmall"); (365, "Ogravesmall"); (366, "Oacutesmall"); (367, "Ocircumflexsmall");
(368, "Otildesmall"); (369, "Odieresissmall"); (370, "OEsmall"); (371, "Oslashsmall");
(372, "Ugravesmall"); (373, "Uacutesmall"); (374, "Ucircumflexsmall"); (375, "Udieresissmall");
(376, "Yacutesmall"); (377, "Thornsmall"); (378, "Ydieresissmall"); (379, "001.000");
(380, "001.001"); (381, "001.002"); (382, "001.003"); (383, "Black"); (384, "Bold");
(385, "Book"); (386, "Light"); (387, "Medium"); (388, "Regular"); (389, "Roman");
(390, "Semibold")]
(* Read entries from the topdict, returning a list of the data therein. At the
moment, we ignore anything we're not interested in, substituting defaults as
appropriate, returning a list. *)
type topdict_entry =
| CharStringType of int
| CharSetOffset of int
| EncodingOffset of int
| CharStringOffset of int
| PrivateDict of int * int (*i (offset, length) i*)
| FontMatrix of Transform.transform_matrix
let parse_topdict_entry = function
| Operator2 6, [IntOp x] -> Some (CharStringType (i32toi x))
| Operator 15, [IntOp x] -> Some (CharSetOffset (i32toi x))
| Operator 16, [IntOp x] -> Some (EncodingOffset (i32toi x))
| Operator 17, [IntOp x] -> Some (CharStringOffset (i32toi x))
| Operator 18, [IntOp size; IntOp offset] -> Some (PrivateDict (i32toi offset, i32toi size))
| Operator2 7, [a; b; c; d; e; f] ->
let getnum = function
| IntOp i -> Int32.to_float i
| RealOp r -> r
| _ -> Printf.eprintf "cff.ml: bad mat"; 0.
in
Some
(FontMatrix
{Transform.a = getnum a; Transform.b = getnum b;
Transform.c = getnum c; Transform.d = getnum d;
Transform.e = getnum e; Transform.f = getnum f})
| _ -> None
let rec read_dict_sections prev ops =
match
let operands, more =
cleavewhile (function Operator _ | Operator2 _ -> false | _ -> true) ops
in
match more with
| Operator x::rest -> Some (Operator x, operands, rest)
| Operator2 x::rest -> Some (Operator2 x, operands, rest)
| _ -> None
with
| Some (Operator x, ops, more) ->
read_dict_sections ((Operator x, ops)::prev) more
| Some (Operator2 x, ops, more) ->
read_dict_sections ((Operator2 x, ops)::prev) more
| _ -> rev prev
let parse_topdict ops =
option_map parse_topdict_entry (read_dict_sections [] ops)
let string_of_topdict_entry = function
| CharStringType i -> "CharStringType is " ^ string_of_int i ^ "\n"
| CharSetOffset i -> "CharSetOffset is " ^ string_of_int i ^ "\n"
| EncodingOffset i -> "EncodingOffset is " ^ string_of_int i ^ "\n"
| CharStringOffset i -> "CharStringOffset is " ^ string_of_int i ^ "\n"
| PrivateDict (offset, size) -> "PrivateDict offset is " ^ string_of_int offset ^ " and size " ^ string_of_int size ^ "\n"
| FontMatrix m -> "FontMatrix is " ^ Transform.string_of_matrix m ^ "\n"
(* Same for private dictionary *)
type privatedict_entry =
| Subrs of int
let parse_privatedict_entry = function
| Operator 19, [IntOp offset] -> Some (Subrs (i32toi offset))
| _ -> None
let parse_privatedict ops =
option_map parse_privatedict_entry (read_dict_sections [] ops)
let string_of_privatedict_entry = function
| Subrs offset -> "Subrs: offset is " ^ string_of_int offset ^ "\n"
(* Read the encoding in b at offset off *)
let read_encoding b = function
| 0 -> standard_encoding
| 1 -> expert_encoding
| off ->
discard_bytes b off;
let fmt = read_card8 b in
match fmt with
| 0 ->
let numglyphs = read_card8 b in
let codes = ref [] in
for x = 1 to numglyphs do codes =| read_card8 b done;
if !codes = []
then []
else combine (ilist 1 numglyphs) (rev !codes)
| 1 ->
let numranges = read_card8 b in
let encoding = ref []
and n = ref 1 in
for x = 1 to numranges do
let first = read_card8 b in
let nLeft = read_card8 b in
encoding =@ rev (combine (ilist !n (!n + nLeft)) (ilist first (first + nLeft)));
n := !n + nLeft + 1
done;
(rev !encoding)
| n -> Printf.eprintf "Unknown encoding format (CFF)"; []
let read_charset b off numglyphs =
assert (numglyphs >= 0);
discard_bytes b off;
let fmt = read_card8 b in
match fmt with
| 0 ->
(*i flprint "Format 0\n"; i*)
let sids = ref []
and glyphsleft = ref numglyphs in
while !glyphsleft > 0 do
sids =| read_card16 b;
decr glyphsleft
done;
rev !sids
| 1 ->
(*i flprint "Format 1\n"; i*)
let sids = ref []
and glyphsleft = ref numglyphs in
while !glyphsleft > 0 do
let first = read_card16 b in
let left = read_card8 b in
sids =| ilist first (first + left);
glyphsleft -= (left + 1)
done;
take (flatten (rev !sids)) numglyphs
| 2 ->
let sids = ref []
and glyphsleft = ref numglyphs in
while !glyphsleft > 0 do
let first = read_card16 b in
let left = read_card16 b in
sids =| ilist first (first + left);
glyphsleft -= (left + 1)
done;
take (flatten (rev !sids)) numglyphs
| _ -> raise (Pdf.PDFError "CFF: Bad charset format")
let read_charstrings b charstringtype off =
discard_bytes b off;
map (read_string b) (read_index b)
type charstring_elt =
| CSOperator of int
| CSOperator2 of int
| CSInt of int32
| CSEndHere
let string_of_charstring_elt = function
| CSOperator i -> Printf.sprintf "CSOperator: %i\n" i
| CSOperator2 i -> Printf.sprintf "CSOperator2: %i\n" i
| CSInt i -> Printf.sprintf "CSInt %li\n" i
| CSEndHere -> "CSEndHere\n"
let string_of_charstring elts =
fold_left ( ^ ) "" (map string_of_charstring_elt elts)
(* Parse a charstring from an input *)
let lex_charstring_elt hintbits i =
let b = i.input_byte () in
if b = Pdfio.no_more then raise End_of_file else
if b < 11 then
CSOperator b
else if b = 12 then
let b1 = i.input_byte () in
CSOperator2 b1
else if b <= 18 then
CSOperator b
else if b <= 20 then
if hintbits = -1 then
CSEndHere
else
begin
(* For now, just ignore hint data *)
for x = 1 to (hintbits + 7) / 8 do nudge i done;
CSOperator b
end
else if b <= 27 then
CSOperator b
else if b <= 28 then
let b1 = i.input_byte () in
let b2 = i.input_byte () in
let num = ((b1 land 0b01111111) lsl 8) lor b2 in
if (b1 land 0b10000000) <> 0
then CSInt (i32ofi (num - 32768))
else CSInt (i32ofi num)
else if b <= 31 then
CSOperator b
else if b <= 246 then
CSInt (i32ofi (b - 139))
else if b <= 250 then
let b1 = i.input_byte () in
CSInt (i32ofi ((b - 247) * 256 + b1 + 108))
else if b <= 254 then
let b1 = i.input_byte () in
CSInt (i32ofi ((~-((b - 251) * 256)) - b1 - 108))
else (* 255 *)
let ob1 = i32ofi (i.input_byte ()) in
let ob2 = i32ofi (i.input_byte ()) in
let ob3 = i32ofi (i.input_byte ()) in
let ob4 = i32ofi (i.input_byte ()) in
CSInt
(lor32
(lor32 (lsl32 ob1 24) (lsl32 ob2 16))
(lor32 (lsl32 ob3 8) ob4))
(* Put elements on the stack. On a hint operator, count up what's on the stack,
and add one hintbit for each pair of operators. If another operator, clear
the stack. On moveto, we're done. *)
let count_hintbits i =
let hintbits = ref 0
and stk = ref []
and hint_ops = ref [] in
try
while true do
match lex_charstring_elt ~-1 i with
| CSOperator ((19 | 1 | 3 | 18 | 23) as p) ->
hint_ops =| p;
hintbits += length !stk / 2;
stk := []
| CSEndHere when
(mem 1 !hint_ops || mem 18 !hint_ops) &&
(not (mem 3 !hint_ops)) && not (mem 23 !hint_ops)
->
hintbits += length !stk / 2;
dpr "A"; raise End_of_file
| CSOperator n | CSOperator2 n ->
dpr "B"; raise End_of_file
| x ->
stk =| x
done;
0
with _ -> !hintbits
let lex_charstring s =
let elts = ref []
and i = input_of_string s in
let hintbits = count_hintbits i in
let i = input_of_string s in
try
while true do elts =| lex_charstring_elt hintbits i done;
[]
with
_ -> rev !elts
let mflprint x = () (*i flprint x i*)
(* Parse one or more paths into a [Pdfpages.op list]*)
let rec parse_charstring_inner (cx, cy) stk prev thing =
(*i Printf.printf "parse_charstring_inner: %f, %f\n" cx cy; i*)
match thing with
(* endchar *)
| CSOperator 14::_ | [] -> mflprint "op: endchar\n";
if prev = [] then [] else rev (Pdfpages.Op_f::prev)
(* rmoveto *)
| CSOperator 21::t -> mflprint "op: rmoveto\n";
begin match stk with
| CSInt y::CSInt x::CSInt _::_
| CSInt y::CSInt x::_ ->
let cx = i32tof x +. cx
and cy = i32tof y +. cy in
parse_charstring_inner (cx, cy) [] (Pdfpages.Op_m (cx, cy)::prev) t
| _ -> Printf.eprintf "bad rmoveto"; raise (Pdf.PDFError "bad rmoveto")
end
| CSOperator 4::t -> mflprint "op: vmoveto\n";
begin match stk with
| CSInt y::CSInt _::_
| CSInt y::_ ->
let cy = i32tof y +. cy in
parse_charstring_inner (cx, cy) [] (Pdfpages.Op_m (cx, cy)::prev) t
| _ -> Printf.eprintf "bad vmoveto"; raise (Pdf.PDFError "bad vmoveto")
end
| CSOperator 22::t -> mflprint "op: hmoveto\n";
begin match stk with
| CSInt x::CSInt _::_
| CSInt x::_ ->
let cx = i32tof x +. cx in
parse_charstring_inner (cx, cy) [] (Pdfpages.Op_m (cx, cy)::prev) t
| _ -> Printf.eprintf "bad hmoveto"; raise (Pdf.PDFError "bad hmoveto")
end
(* vvcurveto *)
| CSOperator 26::t -> mflprint "op: vvcurveto\n";
let stk = ref (rev stk)
and cx = ref cx
and cy = ref cy
and ops = ref [] in
if length !stk mod 4 > 0 then
begin match !stk with
| CSInt dx1::CSInt dya::CSInt dxb::CSInt dyb::CSInt dyc::more ->
let xa = i32tof dx1 +. !cx and ya = i32tof dya +. !cy in
let xb = i32tof dxb +. xa and yb = i32tof dyb +. ya in
let xc = i32tof dxb +. xa and yc = i32tof dyc +. yb in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
cx := xc; cy := yc; stk := more
| _ -> raise (Pdf.PDFError "CSOperator 26: bad operands")
end;
while !stk <> [] do
match !stk with
| CSInt dya::CSInt dxb::CSInt dyb::CSInt dyc::more ->
let xa = !cx and ya = i32tof dya +. !cy in
let xb = i32tof dxb +. xa and yb = i32tof dyb +. ya in
let xc = i32tof dxb +. xa and yc = i32tof dyc +. yb in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
cx := xc; cy := yc; stk := more
| _ -> raise (Pdf.PDFError "CSOperator 26: bad operands")
done;
parse_charstring_inner (!cx, !cy) [] (!ops @ prev) t
(* rlinecurve *)
| CSOperator 25::t -> mflprint "op: rlinecurve\n";
let stk = ref (rev stk)
and cx = ref cx
and cy = ref cy
and ops = ref [] in
(* rlinetos *)
for x = 1 to (length !stk - 6) / 2 do
match !stk with
| CSInt dxa::CSInt dya::more ->
stk := more;
let cx' = !cx +. i32tof dxa and cy' = !cy +. i32tof dya in
ops =| Pdfpages.Op_l (cx', cy');
cx := cx'; cy := cy'
| _ ->
raise (Pdf.PDFError "bad: rlinecurve / rlineto")
done;
(* rrcurvetos *)
begin match !stk with
| CSInt dxb::CSInt dyb::CSInt dxc::CSInt dyc::CSInt dxd::CSInt dyd::more ->
let xb = i32tof dxb +. !cx and yb = i32tof dyb +. !cy in
let xc = i32tof dxc +. xb and yc = i32tof dyc +. yb in
let xd = i32tof dxd +. xc and yd = i32tof dyd +. yc in
ops =| Pdfpages.Op_c (xb, yb, xc, yc, xd, yd);
cx := xd; cy := yd
| _ -> raise (Pdf.PDFError "bad: rlinecurve")
end;
parse_charstring_inner (!cx, !cy) [] (!ops @ prev) t
(* rcurveline *)
| CSOperator 24::t -> mflprint "op: rcurveline";
let stk = ref (rev stk)
and cx = ref cx
and cy = ref cy
and ops = ref [] in
(* rrcurvetos *)
for x = 1 to (length !stk - 2) / 6 do
match !stk with
| CSInt dxb::CSInt dyb::CSInt dxc::CSInt dyc::CSInt dxd::CSInt dyd::more ->
let xb = i32tof dxb +. !cx and yb = i32tof dyb +. !cy in
let xc = i32tof dxc +. xb and yc = i32tof dyc +. yb in
let xd = i32tof dxd +. xc and yd = i32tof dyd +. yc in
ops =| Pdfpages.Op_c (xb, yb, xc, yc, xd, yd);
cx := xd; cy := yd;
stk := more
| _ -> raise (Pdf.PDFError "bad: rlinecurve")
done;
(* rlineto *)
begin match !stk with
| CSInt dxa::CSInt dya::more ->
stk := more;
let cx' = !cx +. i32tof dxa and cy' = !cy +. i32tof dya in
ops =| Pdfpages.Op_l (cx', cy');
cx := cx'; cy := cy'
| _ ->
raise (Pdf.PDFError "bad: rlinecurve / rlineto")
end;
parse_charstring_inner (!cx, !cy) [] (!ops @ prev) t
(* hhcurveto *)
| CSOperator 27::t ->
mflprint "op: hhcurveto\n";
let ops = ref []
and stk = ref (rev stk)
and cx = ref cx
and cy = ref cy in
if odd (length !stk) then
begin
match !stk with
| CSInt dy1::CSInt dxa::CSInt dxb::CSInt dyb::CSInt dxc::more ->
let xa = i32tof dxa +. !cx and ya = i32tof dy1 +. !cy in
let xb = i32tof dxb +. xa and yb = i32tof dyb +. ya in
let xc = i32tof dxc +. xb and yc = yb in
stk := more;
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
cx := xc; cy := yc
| _ -> raise (Pdf.PDFError "hhcurveto: operand problem")
end;
while !stk <> [] do
match !stk with
| CSInt dxa::CSInt dxb::CSInt dyb::CSInt dxc::more ->
let xa = i32tof dxa +. !cx and ya = !cy in
let xb = xa +. i32tof dxb and yb = ya +. i32tof dyb in
let xc = xb +. i32tof dxc and yc = yb in
stk := more;
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
cx := xc; cy := yc
| _ -> raise (Pdf.PDFError "hhcurveto: operand problem")
done;
parse_charstring_inner (!cx, !cy) [] (!ops @ prev) t
(* vhcurveto *)
| CSOperator 30::t -> mflprint "vhcurveto:\n";
let ops = ref []
and stk = ref (rev stk)
and cx = ref cx
and cy = ref cy
and starts_horz = ref false in
(*i Printf.printf "At start of vhcurveto, cx, cy = %f, %f\n" !cx !cy;
* i*)
if length !stk mod 8 > 0 && (length !stk - 1) mod 8 > 0 then
(* dx1 dx2 dy2 dy3 {dya dxb dyb dxc dxd dxe dye dyf}* dxf? *)
begin match !stk with
| [CSInt dy1; CSInt dx2; CSInt dy2; CSInt dx3; CSInt dyf] ->
let xa = !cx and ya = !cy +. i32tof dy1 in
let xb = xa +. i32tof dx2 and yb = ya +. i32tof dy2 in
let xc = xb +. i32tof dx3 and yc = yb +. i32tof dyf in
(*i flprint "vhcurveto-A\n"; i*)
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
stk := []; flip starts_horz; cx := xc; cy := yc
| CSInt dy1::CSInt dx2::CSInt dy2::CSInt dx3::more ->
let xa = !cx and ya = !cy +. i32tof dy1 in
let xb = i32tof dx2 +. xa and yb = i32tof dy2 +. ya in
let xc = xb +. i32tof dx3 and yc = yb in
(*i flprint "vhcurveto-B\n";
Printf.printf "a = %f, %f - b = %f, %f - c = %f, %f\n" xa ya xb
yb xc yc; i*)
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
stk := more; flip starts_horz; cx := xc; cy := yc
| _ -> raise (Pdf.PDFError "vhcurveto: bad operands")
end;
(* {dxa dxb dyb dyc dyd dxe dye dxf}+ dyf? vhcurveto *)
let add_horz_start p q r s t =
let xa = i32tof p +. !cx and ya = !cy in
let xb = i32tof q +. xa and yb = i32tof r +. ya in
let xc = i32tof t +. xb and yc = i32tof s +. yb in
(*i Printf.printf "H %li %li %li %li %li\n" p q r s t;
Printf.printf "xa, ya, xb, yb, xc, yc = %f, %f %f, %f %f, %f\n" xa
ya xb yb xc yc; i*)
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
cx := xc; cy := yc;
(*i Printf.printf "Point is %f, %f\n" !cx !cy; i*)
and add_vert_start p q r s t =
let xa = !cx and ya = i32tof p +. !cy in
let xb = i32tof q +. xa and yb = i32tof r +. ya in
let xc = i32tof s +. xb and yc = i32tof t +. yb in
(*i Printf.printf "V %li %li %li %li %li\n" p q r s t;
Printf.printf "xa, ya, xb, yb, xc, yc = %f, %f %f, %f %f, %f\n" xa
ya xb yb xc yc; i*)
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
cx := xc; cy := yc;
(*i Printf.printf "Point is %f, %f\n" !cx !cy; i*)
in
while !stk <> [] do
match !stk with
| [CSInt dxa; CSInt dxb; CSInt dyb; CSInt dyc;
CSInt dyd; CSInt dxe; CSInt dye; CSInt dxf; CSInt dyf] ->
(* Two curves, last one free ending *)
if !starts_horz then
begin
add_horz_start dxa dxb dyb dyc 0l;
add_vert_start dyd dxe dye dxf dyf
end
else
begin
add_vert_start dxa dxb dyb dyc 0l;
add_horz_start dyd dxe dye dxf dyf
end;
stk := [];
| CSInt dya::CSInt dxb::CSInt dyb::CSInt dyc::
CSInt dyd::CSInt dxe::CSInt dye::CSInt dxf::more ->
(* Two curves, entirely unfree *)
if !starts_horz then
begin
add_horz_start dya dxb dyb dyc 0l;
add_vert_start dyd dxe dye dxf 0l
end
else
begin
add_vert_start dya dxb dyb dyc 0l;
add_horz_start dyd dxe dye dxf 0l
end;
stk := more;
| _ -> raise (Pdf.PDFError "vhcurveto: bad operands")
done;
parse_charstring_inner (!cx, !cy) [] (!ops @ prev) t
(* hvcurveto *)
| CSOperator 31::t -> mflprint "hvcurveto\n";
(*i Printf.printf "cx, cy = %f, %f\n" cx cy; i*)
let ops = ref []
and stk = ref (rev stk)
and cx = ref cx
and cy = ref cy
and starts_horz = ref true in
if length !stk mod 8 > 0 && (length !stk - 1) mod 8 > 0 then
(* dx1 dx2 dy2 dy3 {dya dxb dyb dxc dxd dxe dye dyf}* dxf? *)
begin match !stk with
| [CSInt dx1; CSInt dx2; CSInt dy2; CSInt dy3; CSInt dxf] ->
let xa = i32tof dx1 +. !cx and ya = !cy in
let xb = i32tof dx2 +. xa and yb = i32tof dy2 +. ya in
let xc = i32tof dxf +. xb and yc = i32tof dy3 +. yb in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
stk := []; flip starts_horz; cx := xc; cy := yc
| CSInt dx1::CSInt dx2::CSInt dy2::CSInt dy3::more ->
let xa = i32tof dx1 +. !cx and ya = !cy in
let xb = i32tof dx2 +. xa and yb = i32tof dy2 +. ya in
let xc = xb and yc = i32tof dy3 +. yb in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
stk := more; flip starts_horz; cx := xc; cy := yc
| _ -> raise (Pdf.PDFError "hvcurveto: bad operands")
end;
(* {dxa dxb dyb dyc dyd dxe dye dxf}+ dyf? hvcurveto *)
let add_horz_start p q r s t =
let xa = i32tof p +. !cx and ya = !cy in
let xb = i32tof q +. xa and yb = i32tof r +. ya in
let xc = i32tof s +. xb and yc = i32tof t +. yb in
(*i Printf.printf "add_horz_start: (%f, %f)\n(%f, %f)\n(%f,%f)\n" xa
* ya xb yb xc yc; i*)
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
cx := xc; cy := yc;
and add_vert_start p q r s t =
let xa = !cx and ya = i32tof p +. !cy in
let xb = i32tof q +. xa and yb = i32tof r +. ya in
let xc = i32tof s +. xb and yc = i32tof t +. yb in
(*i Printf.printf "add_vert_start: (%f, %f)\n(%f, %f)\n(%f,%f)\n" xa
* ya xb yb xc yc; i*)
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
cx := xc; cy := yc;
in
while !stk <> [] do
match !stk with
| [CSInt dxa; CSInt dxb; CSInt dyb; CSInt dyc;
CSInt dyd; CSInt dxe; CSInt dye; CSInt dxf; CSInt dyf] ->
(* Two curves, last one free ending *)
if !starts_horz then
begin
add_horz_start dxa dxb dyb 0l dyc;
add_vert_start dyd dxe dye dxf dyf
end
else
begin
add_vert_start dxa dxb dyb dyc 0l;
add_horz_start dyd dxe dye dyf dxf
end;
stk := []
| CSInt dya::CSInt dxb::CSInt dyb::CSInt dyc::
CSInt dyd::CSInt dxe::CSInt dye::CSInt dxf::more ->
(* Two curves, entirely unfree *)
if !starts_horz then
begin
add_horz_start dya dxb dyb 0l dyc;
add_vert_start dyd dxe dye dxf 0l
end
else
begin
add_vert_start dya dxb dyb dyc 0l;
add_horz_start dyd dxe dye 0l dxf
end;
stk := more
| _ -> raise (Pdf.PDFError "hvcurveto: bad operands")
done;
parse_charstring_inner (!cx, !cy) [] (!ops @ prev) t
(* rrcurveto *)
| CSOperator 8::t -> mflprint "rrcurveto\n";
let ops = ref []
and stk = ref (rev stk)
and cx = ref cx
and cy = ref cy in
while !stk <> [] do
match !stk with
| CSInt dxa::CSInt dya::CSInt dxb::CSInt dyb::CSInt dxc::CSInt dyc::more ->
let xa = !cx +. i32tof dxa and ya = !cy +. i32tof dya in
let xb = xa +. i32tof dxb and yb = ya +. i32tof dyb in
let xc = xb +. i32tof dxc and yc = yb +. i32tof dyc in
stk := more;
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
cx := xc; cy := yc
| _ -> raise (Pdf.PDFError "rrcurveto: args not multiple of 6\n")
done;
parse_charstring_inner (!cx, !cy) [] (!ops @ prev) t
(* vlineto *)
| CSOperator 7::t -> mflprint "vlineto\n";
let stk = ref (rev stk)
and first_is_horz = ref false
and ops = ref []
and cx = ref cx
and cy = ref cy in
(* 1. If odd, do the first one *)
if odd (length !stk) then
begin
begin match !stk with
| CSInt dy1::more ->
stk := more;
ops =| Pdfpages.Op_l (!cx, i32tof dy1 +. !cy);
cy := i32tof dy1 +. !cy
| _ -> raise (Pdf.PDFError "vlineto/odd fail")
end;
set first_is_horz
end;
(* 2. Do the rest *)
while !stk <> [] do
match !stk with
| CSInt p::CSInt q::more ->
stk := more;
if !first_is_horz then
begin
ops =| Pdfpages.Op_l (i32tof p +. !cx, !cy);
cx := i32tof p +. !cx;
ops =| Pdfpages.Op_l (!cx, i32tof q +. !cy);
cy := i32tof q +. !cy
end
else
begin
ops =| Pdfpages.Op_l (!cx, i32tof p +. !cy);
cy := i32tof p +. !cy;
ops =| Pdfpages.Op_l (i32tof q +. !cx, !cy);
cx := i32tof q +. !cx
end
| _ -> raise (Pdf.PDFError "vlineto/odd fail")
done;
parse_charstring_inner (!cx, !cy) [] (!ops @ prev) t
(* rlineto *)
| CSOperator 5::t -> mflprint "rlineto\n";
let stk = ref (rev stk)
and ops = ref []
and cx = ref cx
and cy = ref cy in
while !stk <> [] do
match !stk with
| CSInt dxa::CSInt dyb::more ->
stk := more;
ops =| Pdfpages.Op_l (!cx +. i32tof dxa, !cy +. i32tof dyb);
cx := !cx +. i32tof dxa;
cy := !cy +. i32tof dyb
| _ -> raise (Pdf.PDFError "rlineto")
done;
parse_charstring_inner (!cx, !cy) [] (!ops @ prev) t
(* hlineto *)
| CSOperator 6::t -> mflprint "hlineto\n";
if even (length stk) then
(* Even: alternating horizontal and vertical segments *)
let ops = ref []
and stk = ref (rev stk)
and cx = ref cx
and cy = ref cy in
while !stk <> [] do
match !stk with
| CSInt dxa::CSInt dyb::more ->
stk := more;
ops =| Pdfpages.Op_l (!cx +. i32tof dxa, !cy);
cx := !cx +. i32tof dxa;
ops =| Pdfpages.Op_l (!cx, !cy +. i32tof dyb);
cy := !cy +. i32tof dyb
| _ -> Printf.eprintf "%i items on stack\n" (length !stk); assert false
done;
parse_charstring_inner (!cx, !cy) [] (!ops @ prev) t
else
(* Odd: Horizontal line of length dx1 then alternating vertical and
horizontal segments. *)
let ops, cx', cy' =
match hd (rev stk) with
| CSInt dx1 ->
let ops = ref [Pdfpages.Op_l (cx +. i32tof dx1, cy)]
and stk = ref (tl (rev stk))
and cx = ref (cx +. i32tof dx1)
and cy = ref cy in
while !stk <> [] do
match !stk with
| CSInt dya::CSInt dxb::more ->
stk := more;
ops =| Pdfpages.Op_l (!cx, !cy +. i32tof dya);
cy := !cy +. i32tof dya;
ops =| Pdfpages.Op_l (!cx +. i32tof dxb, !cy);
cx := !cx +. i32tof dxb
| _ -> assert false
done;
!ops, !cx, !cy
| _ -> raise (Pdf.PDFError "bad csoperator 6")
in
parse_charstring_inner (cx', cy') [] (ops @ prev) t
| CSOperator2 34::t ->
mflprint "hflex\n";
let ops = ref [] in
begin match rev stk with
| CSInt dx1::CSInt dx2::CSInt dy2::CSInt dx3::CSInt dx4::CSInt dx5::CSInt dx6::more ->
let xa = cx +. i32tof dx1 and ya = cy in
let xb = xa +. i32tof dx2 and yb = ya +. i32tof dy2 in
let xc = xb +. i32tof dx3 and yc = yb in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
let xa = xc +. i32tof dx4 and ya = yc in
let xb = xa +. i32tof dx5 and yb = yc in
let xc = xb +. i32tof dx6 and yc = yc in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
parse_charstring_inner (xc, yc) [] (!ops @ prev) t
| _ -> raise (Pdf.PDFError "hflex: bad arguments")
end;
| CSOperator2 35::t ->
mflprint "flex";
let ops = ref [] in
begin match rev stk with
| CSInt dx1::CSInt dy1::CSInt dx2::CSInt dy2::CSInt dx3::CSInt dy3::CSInt dx4::CSInt dy4::
CSInt dx5::CSInt dy5::CSInt dx6::CSInt dy6::CSInt _::more ->
let xa = cx +. i32tof dx1 and ya = cy +. i32tof dy1 in
let xb = xa +. i32tof dx2 and yb = ya +. i32tof dy2 in
let xc = xb +. i32tof dx3 and yc = yb +. i32tof dy3 in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
let xa = xc +. i32tof dx4 and ya = yc +. i32tof dy4 in
let xb = xa +. i32tof dx5 and yb = ya +. i32tof dy5 in
let xc = xb +. i32tof dx6 and yc = yb +. i32tof dy6 in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
parse_charstring_inner (xc, yc) [] (!ops @ prev) t
| _ -> raise (Pdf.PDFError "flex: bad arguments.")
end
| CSOperator2 36::t ->
mflprint "hflex1\n";
(**i Printf.printf "cx = %f, cy = %f\n" cx cy; i*)
let ops = ref [] in
begin match rev stk with
| CSInt dx1::CSInt dy1::CSInt dx2::CSInt dy2::CSInt dx3::CSInt dx4::CSInt dx5::CSInt dy5::CSInt dx6::more ->
let xa = cx +. i32tof dx1 and ya = cy +. i32tof dy1 in
let xb = xa +. i32tof dx2 and yb = ya +. i32tof dy2 in
let xc = xb +. i32tof dx3 and yc = yb in
(*i Printf.printf "Curve one: %f %f %f %f %f %f\n" xa ya xb yb xc
* yc; i*)
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
let xa = xc +. i32tof dx4 and ya = yc in
let xb = xa +. i32tof dx5 and yb = ya +. i32tof dy5 in
let xc = xb +. i32tof dx6 and yc = yb in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
(*i Printf.printf "Curve two: %f %f %f %f %f %f\n" xa ya xb yb
* xc yc; i*)
parse_charstring_inner (xc, yc) [] (!ops @ prev) t
| _ -> raise (Pdf.PDFError "hflex1: bad arguments")
end
| CSOperator2 37::t ->
mflprint "flex1\n";
let ops = ref [] in
begin match rev stk with
| CSInt dx1::CSInt dy1::CSInt dx2::CSInt dy2::CSInt dx3::
CSInt dy3::CSInt dx4::CSInt dy4::CSInt dx5::CSInt dy5::CSInt d6::more ->
let xa = cx +. i32tof dx1 and ya = cy +. i32tof dy1 in
let xb = xa +. i32tof dx2 and yb = ya +. i32tof dy2 in
let xc = xb +. i32tof dx3 and yc = yb +. i32tof dy3 in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
let newdx, newdy =
let dx =
i32tof dx1 +. i32tof dx2 +. i32tof dx3 +. i32tof dx4 +. i32tof dx5
and dy =
i32tof dy1 +. i32tof dy2 +. i32tof dy3 +. i32tof dy4 +. i32tof dy5
in
if fabs dx > fabs dy then d6, 0l else 0l, d6
in
let xa = xc +. i32tof dx4 and ya = yc +. i32tof dy4 in
let xb = xa +. i32tof dx5 and yb = ya +. i32tof dy5 in
let xc = xb +. i32tof newdx and yc = yb +. i32tof newdy in
ops =| Pdfpages.Op_c (xa, ya, xb, yb, xc, yc);
parse_charstring_inner (xc, yc) [] (!ops @ prev) t
| _ -> raise (Pdf.PDFError "flex1: bad arguments")
end
(* hintmask / cntrmask *)
| CSOperator (19 | 20)::t ->
parse_charstring_inner (cx, cy) stk prev t
(* hint building *)
| CSOperator (1 | 3 | 18 | 23)::t ->
parse_charstring_inner (cx, cy) [] prev t
(* Obsolete: dotsection *)
| CSOperator2 0::t ->
parse_charstring_inner (cx, cy) stk prev t
(* anything else: stick it on the stack *)
| (CSOperator n | CSOperator2 n)::t ->
Printf.eprintf "CFF: operator %i not understood\n" n;
parse_charstring_inner (cx, cy) [] prev t
| h::t -> parse_charstring_inner (cx, cy) (h::stk) prev t
let parse_charstring lexemes =
try parse_charstring_inner (0., 0.) [] [] lexemes with
e -> (*i Printf.eprintf (Printexc.to_string e); i*) raise e
(* Given a op list, debug to letter.pdf *)
let debug_letter ops =
let page = Pdfdoc.blankpage Paper.a4 in
let page =
{page with
Pdfdoc.content =
let trop =
Pdfpages.Op_cm
(Transform.matrix_of_op (Transform.Scale ((0., 0.), 0.1, 0.1)))
in
[Pdfpages.stream_of_ops (trop::ops)]}
in
let pdf, pageroot = Pdfdoc.add_pagetree [page] (Pdf.empty ()) in
let pdf = Pdfdoc.add_root pageroot [] pdf in
Pdfwrite.pdf_to_file pdf "letter.pdf"
(* The undefined glyph *)
let notdef =
{Pdfgraphics.elements = [];
Pdfgraphics.fonts = [];
Pdfgraphics.resources = Pdf.Dictionary []}
let parse_cff_font data =
(* 1. Read the header *)
let get_bitstream () =
bitstream_of_input (input_of_bytestream data)
in
let b = get_bitstream () in
let _ = read_card8 b in (* MAJOR *)
let _ = read_card8 b in (* MINOR *)
let header_size = read_card8 b in
let _ = read_card8 b * 4 in (* OFFSIZE*)
(* 2. Wind forward past the possible rest of the header *)
discard_bytes b (header_size - 4);
(* 3. Read the name INDEX *)
let _ = map (read_string b) (read_index b) in
(* Read the Top DICT INDEX *)
let topdicts = read_index b in
let topdicts = map (read_dict [] b) topdicts in
(*i flprint "\nReading string index..."; i*)
(* Read the STRING INDEX. - strings for SIDs *)
let strings =
let stringnames = map (read_string b) (read_index b)
and fst = length sids in
(*i Printf.printf "fst = %i, length stringnames = %i, so ilist %i %i"
fst (length stringnames) fst (fst + length stringnames - 1); i*)
if stringnames = []
then []
else combine (ilist fst (fst + length stringnames - 1)) stringnames
in
(* READ THE GLOBAL SUBRS INDEX *)
(*i let index = read_index b in *) (* commented out because we don't use it
yet *)
(*d Printf.printf "Read global subrs index of length %i\n" (length index);
* d*)
(* END OF READING THE GLOBAL SUBRS INDEX *)
(*i flprint "done\n";
Printf.printf "Got %i strings for SIDs\n" (length strings);
iter (function (x, y) -> Printf.printf "%i = %s\n" x y) strings;
*)
(*i Printf.printf "%i TOPDICTs found\n" (length topdicts);
flprint "Top dict operators - RAW\n";
iter flprint (map string_of_dictops topdicts);
flprint "\nTop dict operators - PARSED\n"; i*)
let parsed = parse_topdict (hd topdicts) in
(*i Printf.printf "Found %i useful operators:\n" (length parsed);
flprint "\n";
flprint (fold_left ( ^ ) "" (map string_of_topdict_entry parsed)); i*)
(* 1. Read any PRIVATE DICT *)
(* let privatedict, pdoffset =
match keep (function PrivateDict _ -> true | _ -> false) parsed with
| [PrivateDict (offset, size)] ->
let b = get_bitstream () in
discard_bytes b offset;
let privdict = read_dict [] b size in
(* Print 'em out *)
let parsed = parse_privatedict privdict in
(*I Printf.printf "Found %i useful private dictionary operators:\n" (length parsed);
flprint "\n";
flprint (fold_left ( ^ ) "" (map
string_of_privatedict_entry parsed)); i*)
parsed, offset
| _ -> [], 0
in
let subrs =
match keep (function Subrs _ -> true | _ -> false) privatedict with
| [Subrs selfoffset] ->
let b = get_bitstream () in
discard_bytes b pdoffset;
discard_bytes b selfoffset;
let subrs = read_index b in
Printf.printf "SUBRS: Read %i subroutines from INDEX\n"
(length subrs);
[]
| _ -> []
in i*) (* commented out because we don't use it yet *)
(* A. Read encoding (codes to glpyh codes) *)
let encodingoffset =
match keep (function EncodingOffset _ -> true | _ -> false) parsed with
| [EncodingOffset i] -> i
| [] -> 0 (* Standard encoding *)
| _ -> raise (Pdf.PDFError "no encoding offset")
in
(*i flprint "about_to_call read_encoding...\n"; i*)
let encoding =
read_encoding (get_bitstream ()) encodingoffset
in
(*i Printf.printf "Read %i encoding entries\n" (length encoding);
iter (function (x, y) -> Printf.printf "%i, %i\n" x y) encoding;
i*)
(* C. Read char strings *)
let charstringtype =
match keep (function CharStringType _ -> true | _ -> false) parsed with
| [CharStringType i] -> i
| _ -> 2
and charstringoffset =
match keep (function CharStringOffset _ -> true | _ -> false) parsed with
| [CharStringOffset i] -> i
| _ -> raise (Pdf.PDFError "no encoding offset")
in
(*i Printf.printf "Charstring format is %i\n" charstringtype; i*)
let charstrings =
read_charstrings (get_bitstream ()) charstringtype charstringoffset
in
(*i Printf.printf "Read %i glyph descriptions\n" (length
* charstrings); i*)
(* B. Read charset (glpyh codes to glyph names) *)
let charsetoffset =
match keep (function CharSetOffset _ -> true | _ -> false) parsed with
| [CharSetOffset i] -> i
| _ -> 0
in
let fontmatrix =
match keep (function FontMatrix _ -> true | _ -> false) parsed with
| [FontMatrix m] -> m
| _ -> Transform.matrix_of_op (Transform.Scale ((0., 0.), 0.001, 0.001))
in
(*i Printf.printf "numglyphs = %i\n" (length charstrings - 1); i*)
let charset =
read_charset (get_bitstream ()) charsetoffset (length charstrings - 1)
in
let allids = sids @ strings in
let names = map (function c -> lookup_failnull c allids) charset in
(*i flprint "$$";
iter print_string names;
flprint "$$";
Printf.printf "Read %i charset SIDs\n" (length charset);
iter (function x -> Printf.printf "SID: %i\n" x) charset; i*)
let lexed_charstrings =
map
(fun (k, c) -> (*i Printf.printf "NUMBER %i\n" k; flprint " ";
i*) lex_charstring c)
(combine (ilist 1 (length charstrings)) charstrings)
in
(*i flprint "lexed charstrings\n";
iter2 (fun i s -> Printf.printf "number %i\n" i; flprint s) (indx
lexed_charstrings) (map string_of_charstring lexed_charstrings);
i*)
let parsed_charstrings =
map
(fun (k, c) -> (*i Printf.printf "NUMBER %i\n" k;*) parse_charstring c)
(combine (ilist 1 (length lexed_charstrings)) lexed_charstrings)
in
(*i flprint "Parsed all charstrings..\n";
iter
(function x -> Printf.printf "START\n %s\nEND\n" (Pdfpages.string_of_ops x); debug_letter x)
parsed_charstrings; *)
let paths = map Pdfgraphics.graphic_of_ops parsed_charstrings in
(*i iter flprint (map Pdfgraphics.string_of_graphic paths);
Printf.printf "Building path-name pairs\n%i paths (including notdef), %i items in charset (not including notdef)\n"
(length paths) (length charset); i*)
let path_name_pairs = combine (".notdef"::names) paths in
(*i flprint "Built path_name pairs, now making hash
* table\n"; i*)
(* Build table of input code -> name *)
let total_encoding =
let read_sid c =
(*i Printf.printf "Reading string for SID %i.." c; i*)
let r = lookup_failnull c (sids @ strings) in
(*i Printf.printf "done.. it's %s\n" r; i*) "/" ^ r
in
let charset_pairs =
combine (indx charset) (map read_sid charset)
in
(*i flprint "charset pairs, mapping glyph code -> glyph name\n";
iter (function (i, s) -> Printf.printf "%i, %s\n" i s) charset_pairs; i*)
option_map
(function (incode, glyphcode) ->
(*i Printf.printf "looking up incode %i which is * glyphcode %i\n" incode glyphcode; i*)
match lookup glyphcode charset_pairs with
| None -> None
| Some x -> Some (incode, x))
(map (function (x, y) -> (y, x)) encoding)
in
(*i Printf.printf "&&&&&&&&&&&& Made total implicit encoding of size %i\n" (length total_encoding);
flprint "Cff.parse_cff_data: all done!\n"; i*)
path_name_pairs, total_encoding, fontmatrix
(* Make a CharProc stream from a graphic. We need to filter out ops we don't
want. *)
let charprocstream_of_graphic g matrix =
Pdfpages.stream_of_ops
(Pdfpages.Op_d1 (0., 0., 0., 0., 0., 0.)::
lose
(function
| Pdfpages.Op_q
| Pdfpages.Op_Q
| Pdfpages.Op_cm _
| Pdfpages.Op_w _
| Pdfpages.Op_J _
| Pdfpages.Op_j _
| Pdfpages.Op_M _
| Pdfpages.Op_ri _
| Pdfpages.Op_CS _
| Pdfpages.Op_SCN _
| Pdfpages.Op_cs _
| Pdfpages.Op_scn _ -> true
| _ -> false)
(Pdfgraphics.ops_of_simple_graphic (Pdfgraphics.transform_graphic matrix g)))
(* Calculate the maximal bounding box of some graphics *)
let bbox_of_graphics gs =
fold_left
box_union_float
(max_float, min_float, max_float, min_float)
(map Pdfgraphics.bbox_of_graphic gs)
(* When we build the Type 3 font, it has no implicit encoding. So, if the source
Type 1 font did have one, we need to build a new encoding as a /Differences
array, including any existing differences in the old encoding and the
encoding implicit in the CFF font file. *)
let rec change_implicit_encoding total_implicit_encoding = function
| Pdftext.ImplicitInFontFile ->
(* Replace with the total implicit encoding *)
let diffs =
map (function (i, s) -> (s, i)) total_implicit_encoding
in
Pdftext.CustomEncoding (Pdftext.StandardEncoding, diffs)
| Pdftext.CustomEncoding (e, d) ->
Pdftext.CustomEncoding (change_implicit_encoding total_implicit_encoding e, d)
| Pdftext.FillUndefinedWithStandard e ->
Pdftext.FillUndefinedWithStandard (change_implicit_encoding total_implicit_encoding e)
| x -> x
(* Convert a Pdftext font in Type 1 format to a Pdftext font in type3 font.
This involves calculating FontBBox, FontMatrix and CharProcs entries, and
removing certain entries from the FontDescriptor *)
let to_type3 pdf = function
| Pdftext.SimpleFont
({Pdftext.fonttype = Pdftext.Type1;
Pdftext.encoding = encoding;
Pdftext.fontdescriptor =
Some ({Pdftext.fontfile = Some Pdftext.FontFile3 fontfileobj} as fontdescriptor)} as fontrec) ->
let parsed_cffdata, total_implicit_encoding, fontmatrix =
let str = Pdf.direct pdf (Pdf.Indirect fontfileobj) in
Pdfcodec.decode_pdfstream pdf str;
match str with
| Pdf.Stream {contents = (_, Pdf.Got data)} ->
begin try parse_cff_font data with
e -> Printf.eprintf "%s" (Printexc.to_string e); raise (Pdf.PDFError "CFF Parse failure")
end
| _ -> raise (Pdf.PDFError "CFF data not a stream")
in
(*i flprint "*************************** TOTAL IMPLICIT ENCODING\n";
iter
(function (i, s) -> Printf.printf "%i, %s\n" i s)
total_implicit_encoding; i*)
let fontdescriptor =
(* FIXME: Need to alter this possibly, adding implicit font encoding? *)
fontdescriptor
and charprocs =
let scalematrix =
Transform.matrix_compose
fontmatrix
(Transform.matrix_of_op (Transform.Scale ((0., 0.), 1000., 1000.)))
in
map
(function (n, g) ->
"/" ^ n, Pdf.Indirect (Pdf.addobj pdf (charprocstream_of_graphic g scalematrix)))
parsed_cffdata
and fontmatrix =
Transform.matrix_of_op (Transform.Scale ((0., 0.), 0.001, 0.001))
and fontbbox =
bbox_of_graphics (snd (split parsed_cffdata))
and encoding =
change_implicit_encoding total_implicit_encoding encoding
in
Pdftext.SimpleFont
{fontrec with
Pdftext.fonttype = Pdftext.Type3
{Pdftext.fontbbox = fontbbox;
Pdftext.fontmatrix = fontmatrix;
Pdftext.charprocs = charprocs;
Pdftext.type3_resources = Pdf.Dictionary []};
Pdftext.encoding = encoding;
Pdftext.fontdescriptor = Some fontdescriptor}
| _ ->
raise (Pdf.PDFError "to_type3: This is not a type 1 CFF font")
|