Spaces:
Running
Running
File size: 117,700 Bytes
5cee033 |
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 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 |
/* poppler-document.cc: glib wrapper for poppler
* Copyright (C) 2005, Red Hat, Inc.
*
* Copyright (C) 2016 Jakub Alba <[email protected]>
* Copyright (C) 2018, 2019, 2021, 2022 Marek Kasik <[email protected]>
* Copyright (C) 2019 Masamichi Hosoda <[email protected]>
* Copyright (C) 2019, 2021, 2024 Oliver Sander <[email protected]>
* Copyright (C) 2020, 2022 Albert Astals Cid <[email protected]>
* Copyright (C) 2021 André Guerreiro <[email protected]>
* Copyright (C) 2024 g10 Code GmbH, Author: Sune Stolborg Vuorela <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include <cstring>
#include <glib.h>
#ifndef G_OS_WIN32
# include <fcntl.h>
# include <sys/stat.h>
# include <sys/types.h>
# include <unistd.h>
#endif
#ifndef __GI_SCANNER__
# include <memory>
# include <goo/gfile.h>
# include <splash/SplashBitmap.h>
# include <CachedFile.h>
# include <DateInfo.h>
# include <FILECacheLoader.h>
# include <GlobalParams.h>
# include <PDFDoc.h>
# include <SignatureInfo.h>
# include <Outline.h>
# include <ErrorCodes.h>
# include <UnicodeMap.h>
# include <GfxState.h>
# include <SplashOutputDev.h>
# include <Stream.h>
# include <FontInfo.h>
# include <PDFDocEncoding.h>
# include <OptionalContent.h>
# include <ViewerPreferences.h>
# include "UTF.h"
#endif
#include "poppler.h"
#include "poppler-private.h"
#include "poppler-enums.h"
#include "poppler-input-stream.h"
#include "poppler-cached-file-loader.h"
#ifdef G_OS_WIN32
# include <stringapiset.h>
#endif
/**
* SECTION:poppler-document
* @short_description: Information about a document
* @title: PopplerDocument
*
* The #PopplerDocument is an object used to refer to a main document.
*/
enum
{
PROP_0,
PROP_TITLE,
PROP_FORMAT,
PROP_FORMAT_MAJOR,
PROP_FORMAT_MINOR,
PROP_SUBTYPE,
PROP_SUBTYPE_STRING,
PROP_SUBTYPE_PART,
PROP_SUBTYPE_CONF,
PROP_AUTHOR,
PROP_SUBJECT,
PROP_KEYWORDS,
PROP_CREATOR,
PROP_PRODUCER,
PROP_CREATION_DATE,
PROP_MOD_DATE,
PROP_LINEARIZED,
PROP_PAGE_LAYOUT,
PROP_PAGE_MODE,
PROP_VIEWER_PREFERENCES,
PROP_PERMISSIONS,
PROP_METADATA,
PROP_PRINT_SCALING,
PROP_PRINT_DUPLEX,
PROP_PRINT_N_COPIES,
PROP_CREATION_DATETIME,
PROP_MOD_DATETIME
};
static void poppler_document_layers_free(PopplerDocument *document);
typedef struct _PopplerDocumentClass PopplerDocumentClass;
struct _PopplerDocumentClass
{
GObjectClass parent_class;
};
G_DEFINE_TYPE(PopplerDocument, poppler_document, G_TYPE_OBJECT)
static PopplerDocument *_poppler_document_new_from_pdfdoc(std::unique_ptr<GlobalParamsIniter> &&initer, PDFDoc *newDoc, GError **error)
{
PopplerDocument *document;
if (!newDoc->isOk()) {
int fopen_errno;
switch (newDoc->getErrorCode()) {
case errOpenFile:
// If there was an error opening the file, count it as a G_FILE_ERROR
// and set the GError parameters accordingly. (this assumes that the
// only way to get an errOpenFile error is if newDoc was created using
// a filename and thus fopen was called, which right now is true.
fopen_errno = newDoc->getFopenErrno();
g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(fopen_errno), "%s", g_strerror(fopen_errno));
break;
case errBadCatalog:
g_set_error(error, POPPLER_ERROR, POPPLER_ERROR_BAD_CATALOG, "Failed to read the document catalog");
break;
case errDamaged:
g_set_error(error, POPPLER_ERROR, POPPLER_ERROR_DAMAGED, "PDF document is damaged");
break;
case errEncrypted:
g_set_error(error, POPPLER_ERROR, POPPLER_ERROR_ENCRYPTED, "Document is encrypted");
break;
default:
g_set_error(error, POPPLER_ERROR, POPPLER_ERROR_INVALID, "Failed to load document");
}
delete newDoc;
return nullptr;
}
document = (PopplerDocument *)g_object_new(POPPLER_TYPE_DOCUMENT, nullptr);
document->initer = std::move(initer);
document->doc = newDoc;
document->output_dev = new CairoOutputDev();
document->output_dev->startDoc(document->doc);
return document;
}
static std::optional<GooString> poppler_password_to_latin1(const gchar *password)
{
gchar *password_latin;
if (!password) {
return {};
}
password_latin = g_convert(password, -1, "ISO-8859-1", "UTF-8", nullptr, nullptr, nullptr);
std::optional<GooString> password_g = GooString(password_latin);
g_free(password_latin);
return password_g;
}
/**
* poppler_document_new_from_file:
* @uri: uri of the file to load
* @password: (allow-none): password to unlock the file with, or %NULL
* @error: (allow-none): Return location for an error, or %NULL
*
* Creates a new #PopplerDocument. If %NULL is returned, then @error will be
* set. Possible errors include those in the #POPPLER_ERROR and #G_FILE_ERROR
* domains.
*
* Return value: A newly created #PopplerDocument, or %NULL
**/
PopplerDocument *poppler_document_new_from_file(const char *uri, const char *password, GError **error)
{
PDFDoc *newDoc;
char *filename;
auto initer = std::make_unique<GlobalParamsIniter>(_poppler_error_cb);
filename = g_filename_from_uri(uri, nullptr, error);
if (!filename) {
return nullptr;
}
const std::optional<GooString> password_g = poppler_password_to_latin1(password);
#ifdef G_OS_WIN32
wchar_t *filenameW;
int length;
length = MultiByteToWideChar(CP_UTF8, 0, filename, -1, nullptr, 0);
filenameW = new WCHAR[length];
if (!filenameW)
return nullptr;
length = MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, length);
newDoc = new PDFDoc(filenameW, length, password_g, password_g);
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
delete newDoc;
newDoc = new PDFDoc(filenameW, length, GooString(password), GooString(password));
}
delete[] filenameW;
#else
newDoc = new PDFDoc(std::make_unique<GooString>(filename), password_g, password_g);
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
delete newDoc;
newDoc = new PDFDoc(std::make_unique<GooString>(filename), GooString(password), GooString(password));
}
#endif
g_free(filename);
return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
}
/**
* poppler_document_new_from_data:
* @data: (array length=length) (element-type guint8): the pdf data
* @length: the length of #data
* @password: (nullable): password to unlock the file with, or %NULL
* @error: (nullable): Return location for an error, or %NULL
*
* Creates a new #PopplerDocument. If %NULL is returned, then @error will be
* set. Possible errors include those in the #POPPLER_ERROR and #G_FILE_ERROR
* domains.
*
* Note that @data is not copied nor is a new reference to it created.
* It must remain valid and cannot be destroyed as long as the returned
* document exists.
*
* Return value: A newly created #PopplerDocument, or %NULL
*
* Deprecated: 0.82: This requires directly managing @length and @data.
* Use poppler_document_new_from_bytes() instead.
**/
PopplerDocument *poppler_document_new_from_data(char *data, int length, const char *password, GError **error)
{
PDFDoc *newDoc;
MemStream *str;
auto initer = std::make_unique<GlobalParamsIniter>(_poppler_error_cb);
// create stream
str = new MemStream(data, 0, length, Object(objNull));
const std::optional<GooString> password_g = poppler_password_to_latin1(password);
newDoc = new PDFDoc(str, password_g, password_g);
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
str = dynamic_cast<MemStream *>(str->copy());
delete newDoc;
newDoc = new PDFDoc(str, GooString(password), GooString(password));
}
return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
}
class BytesStream : public MemStream
{
std::unique_ptr<GBytes, decltype(&g_bytes_unref)> m_bytes;
public:
BytesStream(GBytes *bytes, Object &&dictA) : MemStream(static_cast<const char *>(g_bytes_get_data(bytes, nullptr)), 0, g_bytes_get_size(bytes), std::move(dictA)), m_bytes { g_bytes_ref(bytes), &g_bytes_unref } { }
~BytesStream() override;
};
BytesStream::~BytesStream() = default;
class OwningFileStream final : public FileStream
{
public:
OwningFileStream(std::unique_ptr<GooFile> fileA, Object &&dictA) : FileStream(fileA.get(), 0, false, fileA->size(), std::move(dictA)), file(std::move(fileA)) { }
~OwningFileStream() override;
private:
std::unique_ptr<GooFile> file;
};
OwningFileStream::~OwningFileStream() = default;
/**
* poppler_document_new_from_bytes:
* @bytes: a #GBytes
* @password: (allow-none): password to unlock the file with, or %NULL
* @error: (allow-none): Return location for an error, or %NULL
*
* Creates a new #PopplerDocument from @bytes. The returned document
* will hold a reference to @bytes.
*
* On error, %NULL is returned, with @error set. Possible errors include
* those in the #POPPLER_ERROR and #G_FILE_ERROR domains.
*
* Return value: (transfer full): a newly created #PopplerDocument, or %NULL
*
* Since: 0.82
**/
PopplerDocument *poppler_document_new_from_bytes(GBytes *bytes, const char *password, GError **error)
{
PDFDoc *newDoc;
BytesStream *str;
g_return_val_if_fail(bytes != nullptr, nullptr);
g_return_val_if_fail(error == nullptr || *error == nullptr, nullptr);
auto initer = std::make_unique<GlobalParamsIniter>(_poppler_error_cb);
// create stream
str = new BytesStream(bytes, Object(objNull));
const std::optional<GooString> password_g = poppler_password_to_latin1(password);
newDoc = new PDFDoc(str, password_g, password_g);
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
str = dynamic_cast<BytesStream *>(str->copy());
delete newDoc;
newDoc = new PDFDoc(str, GooString(password), GooString(password));
}
return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
}
static inline gboolean stream_is_memory_buffer_or_local_file(GInputStream *stream)
{
return G_IS_MEMORY_INPUT_STREAM(stream) || (G_IS_FILE_INPUT_STREAM(stream) && strcmp(g_type_name_from_instance((GTypeInstance *)stream), "GLocalFileInputStream") == 0);
}
/**
* poppler_document_new_from_stream:
* @stream: a #GInputStream to read from
* @length: the stream length, or -1 if not known
* @password: (allow-none): password to unlock the file with, or %NULL
* @cancellable: (allow-none): a #GCancellable, or %NULL
* @error: (allow-none): Return location for an error, or %NULL
*
* Creates a new #PopplerDocument reading the PDF contents from @stream.
* Note that the given #GInputStream must be seekable or %G_IO_ERROR_NOT_SUPPORTED
* will be returned.
* Possible errors include those in the #POPPLER_ERROR, #G_FILE_ERROR
* and #G_IO_ERROR domains.
*
* Returns: (transfer full): a new #PopplerDocument, or %NULL
*
* Since: 0.22
*/
PopplerDocument *poppler_document_new_from_stream(GInputStream *stream, goffset length, const char *password, GCancellable *cancellable, GError **error)
{
PDFDoc *newDoc;
BaseStream *str;
g_return_val_if_fail(G_IS_INPUT_STREAM(stream), NULL);
g_return_val_if_fail(length == (goffset)-1 || length > 0, NULL);
auto initer = std::make_unique<GlobalParamsIniter>(_poppler_error_cb);
if (!G_IS_SEEKABLE(stream) || !g_seekable_can_seek(G_SEEKABLE(stream))) {
g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Stream is not seekable");
return nullptr;
}
if (stream_is_memory_buffer_or_local_file(stream)) {
if (length == (goffset)-1) {
if (!g_seekable_seek(G_SEEKABLE(stream), 0, G_SEEK_END, cancellable, error)) {
g_prefix_error(error, "Unable to determine length of stream: ");
return nullptr;
}
length = g_seekable_tell(G_SEEKABLE(stream));
}
str = new PopplerInputStream(stream, cancellable, 0, false, length, Object(objNull));
} else {
CachedFile *cachedFile = new CachedFile(new PopplerCachedFileLoader(stream, cancellable, length));
str = new CachedFileStream(cachedFile, 0, false, cachedFile->getLength(), Object(objNull));
}
const std::optional<GooString> password_g = poppler_password_to_latin1(password);
newDoc = new PDFDoc(str, password_g, password_g);
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
str = str->copy();
delete newDoc;
newDoc = new PDFDoc(str, GooString(password), GooString(password));
}
return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
}
/**
* poppler_document_new_from_gfile:
* @file: a #GFile to load
* @password: (allow-none): password to unlock the file with, or %NULL
* @cancellable: (allow-none): a #GCancellable, or %NULL
* @error: (allow-none): Return location for an error, or %NULL
*
* Creates a new #PopplerDocument reading the PDF contents from @file.
* Possible errors include those in the #POPPLER_ERROR and #G_FILE_ERROR
* domains.
*
* Returns: (transfer full): a new #PopplerDocument, or %NULL
*
* Since: 0.22
*/
PopplerDocument *poppler_document_new_from_gfile(GFile *file, const char *password, GCancellable *cancellable, GError **error)
{
PopplerDocument *document;
GFileInputStream *stream;
g_return_val_if_fail(G_IS_FILE(file), NULL);
if (g_file_is_native(file)) {
gchar *uri;
uri = g_file_get_uri(file);
document = poppler_document_new_from_file(uri, password, error);
g_free(uri);
return document;
}
stream = g_file_read(file, cancellable, error);
if (!stream) {
return nullptr;
}
document = poppler_document_new_from_stream(G_INPUT_STREAM(stream), -1, password, cancellable, error);
g_object_unref(stream);
return document;
}
#ifndef G_OS_WIN32
/**
* poppler_document_new_from_fd:
* @fd: a valid file descriptor
* @password: (allow-none): password to unlock the file with, or %NULL
* @error: (allow-none): Return location for an error, or %NULL
*
* Creates a new #PopplerDocument reading the PDF contents from the file
* descriptor @fd. @fd must refer to a regular file, or STDIN, and be open
* for reading.
* Possible errors include those in the #POPPLER_ERROR and #G_FILE_ERROR
* domains.
* Note that this function takes ownership of @fd; you must not operate on it
* again, nor close it.
*
* Returns: (transfer full): a new #PopplerDocument, or %NULL
*
* Since: 21.12.0
*/
PopplerDocument *poppler_document_new_from_fd(int fd, const char *password, GError **error)
{
struct stat statbuf;
int flags;
BaseStream *stream;
PDFDoc *newDoc;
g_return_val_if_fail(fd != -1, nullptr);
auto initer = std::make_unique<GlobalParamsIniter>(_poppler_error_cb);
if (fstat(fd, &statbuf) == -1 || (flags = fcntl(fd, F_GETFL, &flags)) == -1) {
int errsv = errno;
g_set_error_literal(error, G_FILE_ERROR, g_file_error_from_errno(errsv), g_strerror(errsv));
close(fd);
return nullptr;
}
switch (flags & O_ACCMODE) {
case O_RDONLY:
case O_RDWR:
break;
case O_WRONLY:
default:
g_set_error(error, G_FILE_ERROR, G_FILE_ERROR_BADF, "File descriptor %d is not readable", fd);
close(fd);
return nullptr;
}
if (fd == fileno(stdin) || !S_ISREG(statbuf.st_mode)) {
FILE *file;
if (fd == fileno(stdin)) {
file = stdin;
} else {
file = fdopen(fd, "rb");
if (!file) {
int errsv = errno;
g_set_error_literal(error, G_FILE_ERROR, g_file_error_from_errno(errsv), g_strerror(errsv));
close(fd);
return nullptr;
}
}
CachedFile *cachedFile = new CachedFile(new FILECacheLoader(file));
stream = new CachedFileStream(cachedFile, 0, false, cachedFile->getLength(), Object(objNull));
} else {
stream = new OwningFileStream(GooFile::open(fd), Object(objNull));
}
const std::optional<GooString> password_g = poppler_password_to_latin1(password);
newDoc = new PDFDoc(stream, password_g, password_g);
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
stream = stream->copy();
delete newDoc;
newDoc = new PDFDoc(stream, GooString(password), GooString(password));
}
return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
}
#endif /* !G_OS_WIN32 */
static gboolean handle_save_error(int err_code, GError **error)
{
switch (err_code) {
case errNone:
break;
case errOpenFile:
g_set_error(error, POPPLER_ERROR, POPPLER_ERROR_OPEN_FILE, "Failed to open file for writing");
break;
case errEncrypted:
g_set_error(error, POPPLER_ERROR, POPPLER_ERROR_ENCRYPTED, "Document is encrypted");
break;
default:
g_set_error(error, POPPLER_ERROR, POPPLER_ERROR_INVALID, "Failed to save document");
}
return err_code == errNone;
}
/**
* poppler_document_save:
* @document: a #PopplerDocument
* @uri: uri of file to save
* @error: (allow-none): return location for an error, or %NULL
*
* Saves @document. Any change made in the document such as
* form fields filled, annotations added or modified
* will be saved.
* If @error is set, %FALSE will be returned. Possible errors
* include those in the #G_FILE_ERROR domain.
*
* Return value: %TRUE, if the document was successfully saved
**/
gboolean poppler_document_save(PopplerDocument *document, const char *uri, GError **error)
{
char *filename;
gboolean retval = FALSE;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), FALSE);
filename = g_filename_from_uri(uri, nullptr, error);
if (filename != nullptr) {
GooString fname(filename);
int err_code;
g_free(filename);
err_code = document->doc->saveAs(fname);
retval = handle_save_error(err_code, error);
}
return retval;
}
/**
* poppler_document_save_a_copy:
* @document: a #PopplerDocument
* @uri: uri of file to save
* @error: (allow-none): return location for an error, or %NULL
*
* Saves a copy of the original @document.
* Any change made in the document such as
* form fields filled by the user will not be saved.
* If @error is set, %FALSE will be returned. Possible errors
* include those in the #G_FILE_ERROR domain.
*
* Return value: %TRUE, if the document was successfully saved
**/
gboolean poppler_document_save_a_copy(PopplerDocument *document, const char *uri, GError **error)
{
char *filename;
gboolean retval = FALSE;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), FALSE);
filename = g_filename_from_uri(uri, nullptr, error);
if (filename != nullptr) {
GooString fname(filename);
int err_code;
g_free(filename);
err_code = document->doc->saveWithoutChangesAs(fname);
retval = handle_save_error(err_code, error);
}
return retval;
}
#ifndef G_OS_WIN32
/**
* poppler_document_save_to_fd:
* @document: a #PopplerDocument
* @fd: a valid file descriptor open for writing
* @include_changes: whether to include user changes (e.g. form fills)
* @error: (allow-none): return location for an error, or %NULL
*
* Saves @document. Any change made in the document such as
* form fields filled, annotations added or modified
* will be saved if @include_changes is %TRUE, or discarded i
* @include_changes is %FALSE.
*
* Note that this function takes ownership of @fd; you must not operate on it
* again, nor close it.
*
* If @error is set, %FALSE will be returned. Possible errors
* include those in the #G_FILE_ERROR domain.
*
* Return value: %TRUE, if the document was successfully saved
*
* Since: 21.12.0
**/
gboolean poppler_document_save_to_fd(PopplerDocument *document, int fd, gboolean include_changes, GError **error)
{
FILE *file;
OutStream *stream;
int rv;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), FALSE);
g_return_val_if_fail(fd != -1, FALSE);
file = fdopen(fd, "wb");
if (file == nullptr) {
int errsv = errno;
g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errsv), "Failed to open FD %d for writing: %s", fd, g_strerror(errsv));
return FALSE;
}
stream = new FileOutStream(file, 0);
if (include_changes) {
rv = document->doc->saveAs(stream);
} else {
rv = document->doc->saveWithoutChangesAs(stream);
}
delete stream;
return handle_save_error(rv, error);
}
#endif /* !G_OS_WIN32 */
static void poppler_document_finalize(GObject *object)
{
PopplerDocument *document = POPPLER_DOCUMENT(object);
poppler_document_layers_free(document);
delete document->output_dev;
delete document->doc;
delete document->initer.release();
G_OBJECT_CLASS(poppler_document_parent_class)->finalize(object);
}
/**
* poppler_document_get_id:
* @document: A #PopplerDocument
* @permanent_id: (out) (allow-none): location to store an allocated string, use g_free() to free the returned string
* @update_id: (out) (allow-none): location to store an allocated string, use g_free() to free the returned string
*
* Returns the PDF file identifier represented as two byte string arrays of size 32.
* @permanent_id is the permanent identifier that is built based on the file
* contents at the time it was originally created, so that this identifer
* never changes. @update_id is the update identifier that is built based on
* the file contents at the time it was last updated.
*
* Note that returned strings are not null-terminated, they have a fixed
* size of 32 bytes.
*
* Returns: %TRUE if the @document contains an id, %FALSE otherwise
*
* Since: 0.16
*/
gboolean poppler_document_get_id(PopplerDocument *document, gchar **permanent_id, gchar **update_id)
{
GooString permanent;
GooString update;
gboolean retval = FALSE;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), FALSE);
if (permanent_id) {
*permanent_id = nullptr;
}
if (update_id) {
*update_id = nullptr;
}
if (document->doc->getID(permanent_id ? &permanent : nullptr, update_id ? &update : nullptr)) {
if (permanent_id) {
*permanent_id = g_new(char, 32);
memcpy(*permanent_id, permanent.c_str(), 32);
}
if (update_id) {
*update_id = g_new(char, 32);
memcpy(*update_id, update.c_str(), 32);
}
retval = TRUE;
}
return retval;
}
/**
* poppler_document_get_n_pages:
* @document: A #PopplerDocument
*
* Returns the number of pages in a loaded document.
*
* Return value: Number of pages
**/
int poppler_document_get_n_pages(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), 0);
return document->doc->getNumPages();
}
/**
* poppler_document_get_page:
* @document: A #PopplerDocument
* @index: a page index
*
* Returns the #PopplerPage indexed at @index. This object is owned by the
* caller.
*
* Return value: (transfer full) : The #PopplerPage at @index
**/
PopplerPage *poppler_document_get_page(PopplerDocument *document, int index)
{
Page *page;
g_return_val_if_fail(0 <= index && index < poppler_document_get_n_pages(document), NULL);
page = document->doc->getPage(index + 1);
if (!page) {
return nullptr;
}
return _poppler_page_new(document, page, index);
}
/**
* poppler_document_get_page_by_label:
* @document: A #PopplerDocument
* @label: a page label
*
* Returns the #PopplerPage reference by @label. This object is owned by the
* caller. @label is a human-readable string representation of the page number,
* and can be document specific. Typically, it is a value such as "iii" or "3".
*
* By default, "1" refers to the first page.
*
* Return value: (transfer full) :The #PopplerPage referenced by @label
**/
PopplerPage *poppler_document_get_page_by_label(PopplerDocument *document, const char *label)
{
Catalog *catalog;
GooString label_g(label);
int index;
catalog = document->doc->getCatalog();
if (!catalog->labelToIndex(&label_g, &index)) {
return nullptr;
}
return poppler_document_get_page(document, index);
}
/**
* poppler_document_get_n_attachments:
* @document: A #PopplerDocument
*
* Returns the number of attachments in a loaded document.
* See also poppler_document_get_attachments()
*
* Return value: Number of attachments
*
* Since: 0.18
*/
guint poppler_document_get_n_attachments(PopplerDocument *document)
{
Catalog *catalog;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), 0);
catalog = document->doc->getCatalog();
return catalog && catalog->isOk() ? catalog->numEmbeddedFiles() : 0;
}
/**
* poppler_document_has_attachments:
* @document: A #PopplerDocument
*
* Returns %TRUE of @document has any attachments.
*
* Return value: %TRUE, if @document has attachments.
**/
gboolean poppler_document_has_attachments(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), FALSE);
return (poppler_document_get_n_attachments(document) != 0);
}
/**
* poppler_document_get_attachments:
* @document: A #PopplerDocument
*
* Returns a #GList containing #PopplerAttachment<!-- -->s. These attachments
* are unowned, and must be unreffed, and the list must be freed with
* g_list_free().
*
* Return value: (element-type PopplerAttachment) (transfer full): a list of available attachments.
**/
GList *poppler_document_get_attachments(PopplerDocument *document)
{
Catalog *catalog;
int n_files, i;
GList *retval = nullptr;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
catalog = document->doc->getCatalog();
if (catalog == nullptr || !catalog->isOk()) {
return nullptr;
}
n_files = catalog->numEmbeddedFiles();
for (i = 0; i < n_files; i++) {
PopplerAttachment *attachment;
const std::unique_ptr<FileSpec> emb_file = catalog->embeddedFile(i);
if (!emb_file->isOk() || !emb_file->getEmbeddedFile()->isOk()) {
continue;
}
attachment = _poppler_attachment_new(emb_file.get());
if (attachment != nullptr) {
retval = g_list_prepend(retval, attachment);
}
}
return g_list_reverse(retval);
}
/**
* poppler_named_dest_from_bytestring:
* @data: (array length=length): the bytestring data
* @length: the bytestring length
*
* Converts a bytestring into a zero-terminated string suitable to
* pass to poppler_document_find_dest().
*
* Note that the returned string has no defined encoding and is not
* suitable for display to the user.
*
* The returned data must be freed using g_free().
*
* Returns: (transfer full): the named dest
*
* Since: 0.73
*/
char *poppler_named_dest_from_bytestring(const guint8 *data, gsize length)
{
const guint8 *p, *pend;
char *dest, *q;
g_return_val_if_fail(length != 0 || data != nullptr, nullptr);
/* Each source byte needs maximally 2 destination chars (\\ or \0) */
q = dest = (gchar *)g_malloc(length * 2 + 1);
pend = data + length;
for (p = data; p < pend; ++p) {
switch (*p) {
case '\0':
*q++ = '\\';
*q++ = '0';
break;
case '\\':
*q++ = '\\';
*q++ = '\\';
break;
default:
*q++ = *p;
break;
}
}
*q = 0; /* zero terminate */
return dest;
}
/**
* poppler_named_dest_to_bytestring:
* @name: the named dest string
* @length: (out): a location to store the length of the returned bytestring
*
* Converts a named dest string (e.g. from #PopplerDest.named_dest) into a
* bytestring, inverting the transformation of
* poppler_named_dest_from_bytestring().
*
* Note that the returned data is not zero terminated and may also
* contains embedded NUL bytes.
*
* If @name is not a valid named dest string, returns %NULL.
*
* The returned data must be freed using g_free().
*
* Returns: (array length=length) (transfer full) (nullable): a new bytestring,
* or %NULL
*
* Since: 0.73
*/
guint8 *poppler_named_dest_to_bytestring(const char *name, gsize *length)
{
const char *p;
guint8 *data, *q;
gsize len;
g_return_val_if_fail(name != nullptr, nullptr);
g_return_val_if_fail(length != nullptr, nullptr);
len = strlen(name);
q = data = (guint8 *)g_malloc(len);
for (p = name; *p; ++p) {
if (*p == '\\') {
p++;
len--;
if (*p == '0') {
*q++ = '\0';
} else if (*p == '\\') {
*q++ = '\\';
} else {
goto invalid;
}
} else {
*q++ = *p;
}
}
*length = len;
return data;
invalid:
g_free(data);
*length = 0;
return nullptr;
}
/**
* poppler_document_find_dest:
* @document: A #PopplerDocument
* @link_name: a named destination
*
* Creates a #PopplerDest for the named destination @link_name in @document.
*
* Note that named destinations are bytestrings, not string. That means that
* unless @link_name was returned by a poppler function (e.g. is
* #PopplerDest.named_dest), it needs to be converted to string
* using poppler_named_dest_from_bytestring() before being passed to this
* function.
*
* The returned value must be freed with poppler_dest_free().
*
* Return value: (transfer full): a new #PopplerDest destination, or %NULL if
* @link_name is not a destination.
**/
PopplerDest *poppler_document_find_dest(PopplerDocument *document, const gchar *link_name)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), nullptr);
g_return_val_if_fail(link_name != nullptr, nullptr);
gsize len;
guint8 *data = poppler_named_dest_to_bytestring(link_name, &len);
if (data == nullptr) {
return nullptr;
}
GooString g_link_name((const char *)data, (int)len);
g_free(data);
std::unique_ptr<LinkDest> link_dest = document->doc->findDest(&g_link_name);
if (link_dest == nullptr) {
return nullptr;
}
PopplerDest *dest = _poppler_dest_new_goto(document, link_dest.get());
return dest;
}
static gint _poppler_dest_compare_keys(gconstpointer a, gconstpointer b, gpointer user_data)
{
return g_strcmp0(static_cast<const gchar *>(a), static_cast<const gchar *>(b));
}
static void _poppler_dest_destroy_value(gpointer value)
{
poppler_dest_free(static_cast<PopplerDest *>(value));
}
/**
* poppler_document_create_dests_tree:
* @document: A #PopplerDocument
*
* Creates a balanced binary tree of all named destinations in @document
*
* The tree key is strings in the form returned by
* poppler_named_dest_to_bytestring() which constains a destination name.
* The tree value is the #PopplerDest which contains a named destination.
* The return value must be freed with g_tree_destroy().
*
* Returns: (transfer full) (nullable): the #GTree, or %NULL
* Since: 0.78
**/
GTree *poppler_document_create_dests_tree(PopplerDocument *document)
{
GTree *tree;
Catalog *catalog;
PopplerDest *dest;
int i;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), nullptr);
catalog = document->doc->getCatalog();
if (catalog == nullptr) {
return nullptr;
}
tree = g_tree_new_full(_poppler_dest_compare_keys, nullptr, g_free, _poppler_dest_destroy_value);
// Iterate from name-dict
const int nDests = catalog->numDests();
for (i = 0; i < nDests; ++i) {
// The names of name-dict cannot contain \0,
// so we can use strlen().
auto name = catalog->getDestsName(i);
std::unique_ptr<LinkDest> link_dest = catalog->getDestsDest(i);
if (link_dest) {
gchar *key = poppler_named_dest_from_bytestring(reinterpret_cast<const guint8 *>(name), strlen(name));
dest = _poppler_dest_new_goto(document, link_dest.get());
g_tree_insert(tree, key, dest);
}
}
// Iterate form name-tree
const int nDestsNameTree = catalog->numDestNameTree();
for (i = 0; i < nDestsNameTree; ++i) {
auto name = catalog->getDestNameTreeName(i);
std::unique_ptr<LinkDest> link_dest = catalog->getDestNameTreeDest(i);
if (link_dest) {
gchar *key = poppler_named_dest_from_bytestring(reinterpret_cast<const guint8 *>(name->c_str()), name->getLength());
dest = _poppler_dest_new_goto(document, link_dest.get());
g_tree_insert(tree, key, dest);
}
}
return tree;
}
char *_poppler_goo_string_to_utf8(const GooString *s)
{
if (s == nullptr) {
return nullptr;
}
char *result;
if (hasUnicodeByteOrderMark(s->toStr())) {
result = g_convert(s->c_str() + 2, s->getLength() - 2, "UTF-8", "UTF-16BE", nullptr, nullptr, nullptr);
} else if (hasUnicodeByteOrderMarkLE(s->toStr())) {
result = g_convert(s->c_str() + 2, s->getLength() - 2, "UTF-8", "UTF-16LE", nullptr, nullptr, nullptr);
} else {
int len;
gunichar *ucs4_temp;
int i;
len = s->getLength();
ucs4_temp = g_new(gunichar, len + 1);
for (i = 0; i < len; ++i) {
ucs4_temp[i] = pdfDocEncoding[(unsigned char)s->getChar(i)];
}
ucs4_temp[i] = 0;
result = g_ucs4_to_utf8(ucs4_temp, -1, nullptr, nullptr, nullptr);
g_free(ucs4_temp);
}
return result;
}
static GooString *_poppler_goo_string_from_utf8(const gchar *src)
{
if (src == nullptr) {
return nullptr;
}
gsize outlen;
gchar *utf16 = g_convert(src, -1, "UTF-16BE", "UTF-8", nullptr, &outlen, nullptr);
if (utf16 == nullptr) {
return nullptr;
}
GooString *result = new GooString(utf16, outlen);
g_free(utf16);
if (!hasUnicodeByteOrderMark(result->toStr())) {
prependUnicodeByteOrderMark(result->toNonConstStr());
}
return result;
}
static PopplerPageLayout convert_page_layout(Catalog::PageLayout pageLayout)
{
switch (pageLayout) {
case Catalog::pageLayoutSinglePage:
return POPPLER_PAGE_LAYOUT_SINGLE_PAGE;
case Catalog::pageLayoutOneColumn:
return POPPLER_PAGE_LAYOUT_ONE_COLUMN;
case Catalog::pageLayoutTwoColumnLeft:
return POPPLER_PAGE_LAYOUT_TWO_COLUMN_LEFT;
case Catalog::pageLayoutTwoColumnRight:
return POPPLER_PAGE_LAYOUT_TWO_COLUMN_RIGHT;
case Catalog::pageLayoutTwoPageLeft:
return POPPLER_PAGE_LAYOUT_TWO_PAGE_LEFT;
case Catalog::pageLayoutTwoPageRight:
return POPPLER_PAGE_LAYOUT_TWO_PAGE_RIGHT;
case Catalog::pageLayoutNone:
default:
return POPPLER_PAGE_LAYOUT_UNSET;
}
}
static PopplerPageMode convert_page_mode(Catalog::PageMode pageMode)
{
switch (pageMode) {
case Catalog::pageModeOutlines:
return POPPLER_PAGE_MODE_USE_OUTLINES;
case Catalog::pageModeThumbs:
return POPPLER_PAGE_MODE_USE_THUMBS;
case Catalog::pageModeFullScreen:
return POPPLER_PAGE_MODE_FULL_SCREEN;
case Catalog::pageModeOC:
return POPPLER_PAGE_MODE_USE_OC;
case Catalog::pageModeAttach:
return POPPLER_PAGE_MODE_USE_ATTACHMENTS;
case Catalog::pageModeNone:
default:
return POPPLER_PAGE_MODE_UNSET;
}
}
static PopplerPDFSubtype convert_pdf_subtype(PDFSubtype pdfSubtype)
{
switch (pdfSubtype) {
case subtypePDFA:
return POPPLER_PDF_SUBTYPE_PDF_A;
case subtypePDFE:
return POPPLER_PDF_SUBTYPE_PDF_E;
case subtypePDFUA:
return POPPLER_PDF_SUBTYPE_PDF_UA;
case subtypePDFVT:
return POPPLER_PDF_SUBTYPE_PDF_VT;
case subtypePDFX:
return POPPLER_PDF_SUBTYPE_PDF_X;
case subtypeNone:
return POPPLER_PDF_SUBTYPE_NONE;
case subtypeNull:
default:
return POPPLER_PDF_SUBTYPE_UNSET;
}
}
static PopplerPDFPart convert_pdf_subtype_part(PDFSubtypePart pdfSubtypePart)
{
switch (pdfSubtypePart) {
case subtypePart1:
return POPPLER_PDF_SUBTYPE_PART_1;
case subtypePart2:
return POPPLER_PDF_SUBTYPE_PART_2;
case subtypePart3:
return POPPLER_PDF_SUBTYPE_PART_3;
case subtypePart4:
return POPPLER_PDF_SUBTYPE_PART_4;
case subtypePart5:
return POPPLER_PDF_SUBTYPE_PART_5;
case subtypePart6:
return POPPLER_PDF_SUBTYPE_PART_6;
case subtypePart7:
return POPPLER_PDF_SUBTYPE_PART_7;
case subtypePart8:
return POPPLER_PDF_SUBTYPE_PART_8;
case subtypePartNone:
return POPPLER_PDF_SUBTYPE_PART_NONE;
case subtypePartNull:
default:
return POPPLER_PDF_SUBTYPE_PART_UNSET;
}
}
static PopplerPDFConformance convert_pdf_subtype_conformance(PDFSubtypeConformance pdfSubtypeConf)
{
switch (pdfSubtypeConf) {
case subtypeConfA:
return POPPLER_PDF_SUBTYPE_CONF_A;
case subtypeConfB:
return POPPLER_PDF_SUBTYPE_CONF_B;
case subtypeConfG:
return POPPLER_PDF_SUBTYPE_CONF_G;
case subtypeConfN:
return POPPLER_PDF_SUBTYPE_CONF_N;
case subtypeConfP:
return POPPLER_PDF_SUBTYPE_CONF_P;
case subtypeConfPG:
return POPPLER_PDF_SUBTYPE_CONF_PG;
case subtypeConfU:
return POPPLER_PDF_SUBTYPE_CONF_U;
case subtypeConfNone:
return POPPLER_PDF_SUBTYPE_CONF_NONE;
case subtypeConfNull:
default:
return POPPLER_PDF_SUBTYPE_CONF_UNSET;
}
}
/**
* poppler_document_get_pdf_version_string:
* @document: A #PopplerDocument
*
* Returns the PDF version of @document as a string (e.g. PDF-1.6)
*
* Return value: a new allocated string containing the PDF version
* of @document, or %NULL
*
* Since: 0.16
**/
gchar *poppler_document_get_pdf_version_string(PopplerDocument *document)
{
gchar *retval;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
retval = g_strndup("PDF-", 15); /* allocates 16 chars, pads with \0s */
g_ascii_formatd(retval + 4, 15 + 1 - 4, "%.2g", document->doc->getPDFMajorVersion() + document->doc->getPDFMinorVersion() / 10.0);
return retval;
}
/**
* poppler_document_get_pdf_version:
* @document: A #PopplerDocument
* @major_version: (out) (nullable): return location for the PDF major version number
* @minor_version: (out) (nullable): return location for the PDF minor version number
*
* Updates values referenced by @major_version & @minor_version with the
* major and minor PDF versions of @document.
*
* Since: 0.16
**/
void poppler_document_get_pdf_version(PopplerDocument *document, guint *major_version, guint *minor_version)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
if (major_version) {
*major_version = document->doc->getPDFMajorVersion();
}
if (minor_version) {
*minor_version = document->doc->getPDFMinorVersion();
}
}
/**
* poppler_document_get_title:
* @document: A #PopplerDocument
*
* Returns the document's title
*
* Return value: a new allocated string containing the title
* of @document, or %NULL
*
* Since: 0.16
**/
gchar *poppler_document_get_title(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
const std::unique_ptr<GooString> goo_title = document->doc->getDocInfoTitle();
return _poppler_goo_string_to_utf8(goo_title.get());
}
/**
* poppler_document_set_title:
* @document: A #PopplerDocument
* @title: A new title
*
* Sets the document's title. If @title is %NULL, Title entry
* is removed from the document's Info dictionary.
*
* Since: 0.46
**/
void poppler_document_set_title(PopplerDocument *document, const gchar *title)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
GooString *goo_title;
if (!title) {
goo_title = nullptr;
} else {
goo_title = _poppler_goo_string_from_utf8(title);
if (!goo_title) {
return;
}
}
document->doc->setDocInfoTitle(goo_title);
}
/**
* poppler_document_get_author:
* @document: A #PopplerDocument
*
* Returns the author of the document
*
* Return value: a new allocated string containing the author
* of @document, or %NULL
*
* Since: 0.16
**/
gchar *poppler_document_get_author(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
const std::unique_ptr<GooString> goo_author = document->doc->getDocInfoAuthor();
return _poppler_goo_string_to_utf8(goo_author.get());
}
/**
* poppler_document_set_author:
* @document: A #PopplerDocument
* @author: A new author
*
* Sets the document's author. If @author is %NULL, Author
* entry is removed from the document's Info dictionary.
*
* Since: 0.46
**/
void poppler_document_set_author(PopplerDocument *document, const gchar *author)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
GooString *goo_author;
if (!author) {
goo_author = nullptr;
} else {
goo_author = _poppler_goo_string_from_utf8(author);
if (!goo_author) {
return;
}
}
document->doc->setDocInfoAuthor(goo_author);
}
/**
* poppler_document_get_subject:
* @document: A #PopplerDocument
*
* Returns the subject of the document
*
* Return value: a new allocated string containing the subject
* of @document, or %NULL
*
* Since: 0.16
**/
gchar *poppler_document_get_subject(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
const std::unique_ptr<GooString> goo_subject = document->doc->getDocInfoSubject();
return _poppler_goo_string_to_utf8(goo_subject.get());
}
/**
* poppler_document_set_subject:
* @document: A #PopplerDocument
* @subject: A new subject
*
* Sets the document's subject. If @subject is %NULL, Subject
* entry is removed from the document's Info dictionary.
*
* Since: 0.46
**/
void poppler_document_set_subject(PopplerDocument *document, const gchar *subject)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
GooString *goo_subject;
if (!subject) {
goo_subject = nullptr;
} else {
goo_subject = _poppler_goo_string_from_utf8(subject);
if (!goo_subject) {
return;
}
}
document->doc->setDocInfoSubject(goo_subject);
}
/**
* poppler_document_get_keywords:
* @document: A #PopplerDocument
*
* Returns the keywords associated to the document
*
* Return value: a new allocated string containing keywords associated
* to @document, or %NULL
*
* Since: 0.16
**/
gchar *poppler_document_get_keywords(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
const std::unique_ptr<GooString> goo_keywords = document->doc->getDocInfoKeywords();
return _poppler_goo_string_to_utf8(goo_keywords.get());
}
/**
* poppler_document_set_keywords:
* @document: A #PopplerDocument
* @keywords: New keywords
*
* Sets the document's keywords. If @keywords is %NULL,
* Keywords entry is removed from the document's Info dictionary.
*
* Since: 0.46
**/
void poppler_document_set_keywords(PopplerDocument *document, const gchar *keywords)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
GooString *goo_keywords;
if (!keywords) {
goo_keywords = nullptr;
} else {
goo_keywords = _poppler_goo_string_from_utf8(keywords);
if (!goo_keywords) {
return;
}
}
document->doc->setDocInfoKeywords(goo_keywords);
}
/**
* poppler_document_get_creator:
* @document: A #PopplerDocument
*
* Returns the creator of the document. If the document was converted
* from another format, the creator is the name of the product
* that created the original document from which it was converted.
*
* Return value: a new allocated string containing the creator
* of @document, or %NULL
*
* Since: 0.16
**/
gchar *poppler_document_get_creator(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
const std::unique_ptr<GooString> goo_creator = document->doc->getDocInfoCreator();
return _poppler_goo_string_to_utf8(goo_creator.get());
}
/**
* poppler_document_set_creator:
* @document: A #PopplerDocument
* @creator: A new creator
*
* Sets the document's creator. If @creator is %NULL, Creator
* entry is removed from the document's Info dictionary.
*
* Since: 0.46
**/
void poppler_document_set_creator(PopplerDocument *document, const gchar *creator)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
GooString *goo_creator;
if (!creator) {
goo_creator = nullptr;
} else {
goo_creator = _poppler_goo_string_from_utf8(creator);
if (!goo_creator) {
return;
}
}
document->doc->setDocInfoCreator(goo_creator);
}
/**
* poppler_document_get_producer:
* @document: A #PopplerDocument
*
* Returns the producer of the document. If the document was converted
* from another format, the producer is the name of the product
* that converted it to PDF
*
* Return value: a new allocated string containing the producer
* of @document, or %NULL
*
* Since: 0.16
**/
gchar *poppler_document_get_producer(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
const std::unique_ptr<GooString> goo_producer = document->doc->getDocInfoProducer();
return _poppler_goo_string_to_utf8(goo_producer.get());
}
/**
* poppler_document_set_producer:
* @document: A #PopplerDocument
* @producer: A new producer
*
* Sets the document's producer. If @producer is %NULL,
* Producer entry is removed from the document's Info dictionary.
*
* Since: 0.46
**/
void poppler_document_set_producer(PopplerDocument *document, const gchar *producer)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
GooString *goo_producer;
if (!producer) {
goo_producer = nullptr;
} else {
goo_producer = _poppler_goo_string_from_utf8(producer);
if (!goo_producer) {
return;
}
}
document->doc->setDocInfoProducer(goo_producer);
}
/**
* poppler_document_get_creation_date:
* @document: A #PopplerDocument
*
* Returns the date the document was created as seconds since the Epoch
*
* Return value: the date the document was created, or -1
*
* Since: 0.16
**/
time_t poppler_document_get_creation_date(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), (time_t)-1);
const std::unique_ptr<GooString> str = document->doc->getDocInfoCreatDate();
if (!str) {
return (time_t)-1;
}
time_t date;
gboolean success = _poppler_convert_pdf_date_to_gtime(str.get(), &date);
return (success) ? date : (time_t)-1;
}
/**
* poppler_document_set_creation_date:
* @document: A #PopplerDocument
* @creation_date: A new creation date
*
* Sets the document's creation date. If @creation_date is -1, CreationDate
* entry is removed from the document's Info dictionary.
*
* Since: 0.46
**/
void poppler_document_set_creation_date(PopplerDocument *document, time_t creation_date)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
GooString *str = creation_date == (time_t)-1 ? nullptr : timeToDateString(&creation_date);
document->doc->setDocInfoCreatDate(str);
}
/**
* poppler_document_get_creation_date_time:
* @document: A #PopplerDocument
*
* Returns the date the document was created as a #GDateTime
*
* Returns: (nullable): the date the document was created, or %NULL
*
* Since: 20.09.0
**/
GDateTime *poppler_document_get_creation_date_time(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), nullptr);
std::unique_ptr<GooString> str { document->doc->getDocInfoCreatDate() };
if (!str) {
return nullptr;
}
return _poppler_convert_pdf_date_to_date_time(str.get());
}
/**
* poppler_document_set_creation_date_time:
* @document: A #PopplerDocument
* @creation_datetime: (nullable): A new creation #GDateTime
*
* Sets the document's creation date. If @creation_datetime is %NULL,
* CreationDate entry is removed from the document's Info dictionary.
*
* Since: 20.09.0
**/
void poppler_document_set_creation_date_time(PopplerDocument *document, GDateTime *creation_datetime)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
GooString *str = nullptr;
if (creation_datetime) {
str = _poppler_convert_date_time_to_pdf_date(creation_datetime);
}
document->doc->setDocInfoCreatDate(str);
}
/**
* poppler_document_get_modification_date:
* @document: A #PopplerDocument
*
* Returns the date the document was most recently modified as seconds since the Epoch
*
* Return value: the date the document was most recently modified, or -1
*
* Since: 0.16
**/
time_t poppler_document_get_modification_date(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), (time_t)-1);
const std::unique_ptr<GooString> str = document->doc->getDocInfoModDate();
if (!str) {
return (time_t)-1;
}
time_t date;
gboolean success = _poppler_convert_pdf_date_to_gtime(str.get(), &date);
return (success) ? date : (time_t)-1;
}
/**
* poppler_document_set_modification_date:
* @document: A #PopplerDocument
* @modification_date: A new modification date
*
* Sets the document's modification date. If @modification_date is -1, ModDate
* entry is removed from the document's Info dictionary.
*
* Since: 0.46
**/
void poppler_document_set_modification_date(PopplerDocument *document, time_t modification_date)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
GooString *str = modification_date == (time_t)-1 ? nullptr : timeToDateString(&modification_date);
document->doc->setDocInfoModDate(str);
}
/**
* poppler_document_get_modification_date_time:
* @document: A #PopplerDocument
*
* Returns the date the document was most recently modified as a #GDateTime
*
* Returns: (nullable): the date the document was modified, or %NULL
*
* Since: 20.09.0
**/
GDateTime *poppler_document_get_modification_date_time(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), nullptr);
std::unique_ptr<GooString> str { document->doc->getDocInfoModDate() };
if (!str) {
return nullptr;
}
return _poppler_convert_pdf_date_to_date_time(str.get());
}
/**
* poppler_document_set_modification_date_time:
* @document: A #PopplerDocument
* @modification_datetime: (nullable): A new modification #GDateTime
*
* Sets the document's modification date. If @modification_datetime is %NULL,
* ModDate entry is removed from the document's Info dictionary.
*
* Since: 20.09.0
**/
void poppler_document_set_modification_date_time(PopplerDocument *document, GDateTime *modification_datetime)
{
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
GooString *str = nullptr;
if (modification_datetime) {
str = _poppler_convert_date_time_to_pdf_date(modification_datetime);
}
document->doc->setDocInfoModDate(str);
}
/**
* poppler_document_is_linearized:
* @document: A #PopplerDocument
*
* Returns whether @document is linearized or not. Linearization of PDF
* enables efficient incremental access of the PDF file in a network environment.
*
* Return value: %TRUE if @document is linearized, %FALSE otherwise
*
* Since: 0.16
**/
gboolean poppler_document_is_linearized(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), FALSE);
return document->doc->isLinearized();
}
/**
* poppler_document_get_n_signatures:
* @document: A #PopplerDocument
*
* Returns how many digital signatures @document contains.
* PDF digital signatures ensure that the content hash not been altered since last edit and
* that it was produced by someone the user can trust
*
* Return value: The number of signatures found in the document
*
* Since: 21.12.0
**/
gint poppler_document_get_n_signatures(const PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), 0);
return document->doc->getSignatureFields().size();
}
/**
* poppler_document_get_signature_fields:
* @document: A #PopplerDocument
*
* Returns a #GList containing all signature #PopplerFormField<!-- -->s in the document.
*
* Return value: (element-type PopplerFormField) (transfer full): a list of all signature form fields.
*
* Since: 22.02.0
**/
GList *poppler_document_get_signature_fields(PopplerDocument *document)
{
std::vector<FormFieldSignature *> signature_fields;
FormWidget *widget;
GList *result = nullptr;
gsize i;
signature_fields = document->doc->getSignatureFields();
for (i = 0; i < signature_fields.size(); i++) {
widget = signature_fields[i]->getCreateWidget();
if (widget != nullptr) {
result = g_list_prepend(result, _poppler_form_field_new(document, widget));
}
}
return g_list_reverse(result);
}
/**
* poppler_document_get_page_layout:
* @document: A #PopplerDocument
*
* Returns the page layout that should be used when the document is opened
*
* Return value: a #PopplerPageLayout that should be used when the document is opened
*
* Since: 0.16
**/
PopplerPageLayout poppler_document_get_page_layout(PopplerDocument *document)
{
Catalog *catalog;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), POPPLER_PAGE_LAYOUT_UNSET);
catalog = document->doc->getCatalog();
if (catalog && catalog->isOk()) {
return convert_page_layout(catalog->getPageLayout());
}
return POPPLER_PAGE_LAYOUT_UNSET;
}
/**
* poppler_document_get_page_mode:
* @document: A #PopplerDocument
*
* Returns a #PopplerPageMode representing how the document should
* be initially displayed when opened.
*
* Return value: a #PopplerPageMode that should be used when document is opened
*
* Since: 0.16
**/
PopplerPageMode poppler_document_get_page_mode(PopplerDocument *document)
{
Catalog *catalog;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), POPPLER_PAGE_MODE_UNSET);
catalog = document->doc->getCatalog();
if (catalog && catalog->isOk()) {
return convert_page_mode(catalog->getPageMode());
}
return POPPLER_PAGE_MODE_UNSET;
}
/**
* poppler_document_get_print_scaling:
* @document: A #PopplerDocument
*
* Returns the print scaling value suggested by author of the document.
*
* Return value: a #PopplerPrintScaling that should be used when document is printed
*
* Since: 0.73
**/
PopplerPrintScaling poppler_document_get_print_scaling(PopplerDocument *document)
{
Catalog *catalog;
ViewerPreferences *preferences;
PopplerPrintScaling print_scaling = POPPLER_PRINT_SCALING_APP_DEFAULT;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), POPPLER_PRINT_SCALING_APP_DEFAULT);
catalog = document->doc->getCatalog();
if (catalog && catalog->isOk()) {
preferences = catalog->getViewerPreferences();
if (preferences) {
switch (preferences->getPrintScaling()) {
default:
case ViewerPreferences::PrintScaling::printScalingAppDefault:
print_scaling = POPPLER_PRINT_SCALING_APP_DEFAULT;
break;
case ViewerPreferences::PrintScaling::printScalingNone:
print_scaling = POPPLER_PRINT_SCALING_NONE;
break;
}
}
}
return print_scaling;
}
/**
* poppler_document_get_print_duplex:
* @document: A #PopplerDocument
*
* Returns the duplex mode value suggested for printing by author of the document.
* Value POPPLER_PRINT_DUPLEX_NONE means that the document does not specify this
* preference.
*
* Returns: a #PopplerPrintDuplex that should be used when document is printed
*
* Since: 0.80
**/
PopplerPrintDuplex poppler_document_get_print_duplex(PopplerDocument *document)
{
Catalog *catalog;
ViewerPreferences *preferences;
PopplerPrintDuplex duplex = POPPLER_PRINT_DUPLEX_NONE;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), POPPLER_PRINT_DUPLEX_NONE);
catalog = document->doc->getCatalog();
if (catalog && catalog->isOk()) {
preferences = catalog->getViewerPreferences();
if (preferences) {
switch (preferences->getDuplex()) {
default:
case ViewerPreferences::Duplex::duplexNone:
duplex = POPPLER_PRINT_DUPLEX_NONE;
break;
case ViewerPreferences::Duplex::duplexSimplex:
duplex = POPPLER_PRINT_DUPLEX_SIMPLEX;
break;
case ViewerPreferences::Duplex::duplexDuplexFlipShortEdge:
duplex = POPPLER_PRINT_DUPLEX_DUPLEX_FLIP_SHORT_EDGE;
break;
case ViewerPreferences::Duplex::duplexDuplexFlipLongEdge:
duplex = POPPLER_PRINT_DUPLEX_DUPLEX_FLIP_LONG_EDGE;
break;
}
}
}
return duplex;
}
/**
* poppler_document_get_print_n_copies:
* @document: A #PopplerDocument
*
* Returns the suggested number of copies to be printed.
* This preference should be applied only if returned value
* is greater than 1 since value 1 usually means that
* the document does not specify it.
*
* Returns: Number of copies
*
* Since: 0.80
**/
gint poppler_document_get_print_n_copies(PopplerDocument *document)
{
Catalog *catalog;
ViewerPreferences *preferences;
gint retval = 1;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), 1);
catalog = document->doc->getCatalog();
if (catalog && catalog->isOk()) {
preferences = catalog->getViewerPreferences();
if (preferences) {
retval = preferences->getNumCopies();
}
}
return retval;
}
/**
* poppler_document_get_print_page_ranges:
* @document: A #PopplerDocument
* @n_ranges: (out): return location for number of ranges
*
* Returns the suggested page ranges to print in the form of array
* of #PopplerPageRange<!-- -->s and number of ranges.
* %NULL pointer means that the document does not specify page ranges
* for printing.
*
* Returns: (array length=n_ranges) (transfer full): an array
* of #PopplerPageRange<!-- -->s or %NULL. Free the array when
* it is no longer needed.
*
* Since: 0.80
**/
PopplerPageRange *poppler_document_get_print_page_ranges(PopplerDocument *document, int *n_ranges)
{
Catalog *catalog;
ViewerPreferences *preferences;
std::vector<std::pair<int, int>> ranges;
PopplerPageRange *result = nullptr;
g_return_val_if_fail(n_ranges != nullptr, nullptr);
*n_ranges = 0;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), nullptr);
catalog = document->doc->getCatalog();
if (catalog && catalog->isOk()) {
preferences = catalog->getViewerPreferences();
if (preferences) {
ranges = preferences->getPrintPageRange();
*n_ranges = ranges.size();
result = g_new(PopplerPageRange, ranges.size());
for (size_t i = 0; i < ranges.size(); ++i) {
result[i].start_page = ranges[i].first;
result[i].end_page = ranges[i].second;
}
}
}
return result;
}
/**
* poppler_document_get_permissions:
* @document: A #PopplerDocument
*
* Returns the flags specifying which operations are permitted when the document is opened.
*
* Return value: a set of flags from #PopplerPermissions enumeration
*
* Since: 0.16
**/
PopplerPermissions poppler_document_get_permissions(PopplerDocument *document)
{
guint flag = 0;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), POPPLER_PERMISSIONS_FULL);
if (document->doc->okToPrint()) {
flag |= POPPLER_PERMISSIONS_OK_TO_PRINT;
}
if (document->doc->okToChange()) {
flag |= POPPLER_PERMISSIONS_OK_TO_MODIFY;
}
if (document->doc->okToCopy()) {
flag |= POPPLER_PERMISSIONS_OK_TO_COPY;
}
if (document->doc->okToAddNotes()) {
flag |= POPPLER_PERMISSIONS_OK_TO_ADD_NOTES;
}
if (document->doc->okToFillForm()) {
flag |= POPPLER_PERMISSIONS_OK_TO_FILL_FORM;
}
if (document->doc->okToAccessibility()) {
flag |= POPPLER_PERMISSIONS_OK_TO_EXTRACT_CONTENTS;
}
if (document->doc->okToAssemble()) {
flag |= POPPLER_PERMISSIONS_OK_TO_ASSEMBLE;
}
if (document->doc->okToPrintHighRes()) {
flag |= POPPLER_PERMISSIONS_OK_TO_PRINT_HIGH_RESOLUTION;
}
return (PopplerPermissions)flag;
}
/**
* poppler_document_get_pdf_subtype_string:
* @document: A #PopplerDocument
*
* Returns the PDF subtype version of @document as a string.
*
* Returns: (transfer full) (nullable): a newly allocated string containing
* the PDF subtype version of @document, or %NULL
*
* Since: 0.70
**/
gchar *poppler_document_get_pdf_subtype_string(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
std::unique_ptr<GooString> infostring;
switch (document->doc->getPDFSubtype()) {
case subtypePDFA:
infostring = document->doc->getDocInfoStringEntry("GTS_PDFA1Version");
break;
case subtypePDFE:
infostring = document->doc->getDocInfoStringEntry("GTS_PDFEVersion");
break;
case subtypePDFUA:
infostring = document->doc->getDocInfoStringEntry("GTS_PDFUAVersion");
break;
case subtypePDFVT:
infostring = document->doc->getDocInfoStringEntry("GTS_PDFVTVersion");
break;
case subtypePDFX:
infostring = document->doc->getDocInfoStringEntry("GTS_PDFXVersion");
break;
case subtypeNone:
case subtypeNull:
default: {
/* nothing */
}
}
return _poppler_goo_string_to_utf8(infostring.get());
}
/**
* poppler_document_get_pdf_subtype:
* @document: A #PopplerDocument
*
* Returns the subtype of @document as a #PopplerPDFSubtype.
*
* Returns: the document's subtype
*
* Since: 0.70
**/
PopplerPDFSubtype poppler_document_get_pdf_subtype(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), POPPLER_PDF_SUBTYPE_NONE);
return convert_pdf_subtype(document->doc->getPDFSubtype());
}
/**
* poppler_document_get_pdf_part:
* @document: A #PopplerDocument
*
* Returns the part of the conforming standard that the @document adheres to
* as a #PopplerPDFSubtype.
*
* Returns: the document's subtype part
*
* Since: 0.70
**/
PopplerPDFPart poppler_document_get_pdf_part(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), POPPLER_PDF_SUBTYPE_PART_NONE);
return convert_pdf_subtype_part(document->doc->getPDFSubtypePart());
}
/**
* poppler_document_get_pdf_conformance:
* @document: A #PopplerDocument
*
* Returns the conformance level of the @document as #PopplerPDFConformance.
*
* Returns: the document's subtype conformance level
*
* Since: 0.70
**/
PopplerPDFConformance poppler_document_get_pdf_conformance(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), POPPLER_PDF_SUBTYPE_CONF_NONE);
return convert_pdf_subtype_conformance(document->doc->getPDFSubtypeConformance());
}
/**
* poppler_document_get_metadata:
* @document: A #PopplerDocument
*
* Returns the XML metadata string of the document
*
* Return value: a new allocated string containing the XML
* metadata, or %NULL
*
* Since: 0.16
**/
gchar *poppler_document_get_metadata(PopplerDocument *document)
{
Catalog *catalog;
gchar *retval = nullptr;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
catalog = document->doc->getCatalog();
if (catalog && catalog->isOk()) {
std::unique_ptr<GooString> s = catalog->readMetadata();
if (s) {
retval = g_strdup(s->c_str());
}
}
return retval;
}
/**
* poppler_document_reset_form:
* @document: A #PopplerDocument
* @fields: (element-type utf8) (nullable): list of fields to reset
* @exclude_fields: whether to reset all fields except those in @fields
*
* Resets the form fields specified by fields if exclude_fields is FALSE.
* Resets all others if exclude_fields is TRUE.
* All form fields are reset regardless of the exclude_fields flag
* if fields is empty.
*
* Since: 0.90
**/
void poppler_document_reset_form(PopplerDocument *document, GList *fields, gboolean exclude_fields)
{
std::vector<std::string> list;
Catalog *catalog;
GList *iter;
Form *form;
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
catalog = document->doc->getCatalog();
if (catalog && catalog->isOk()) {
form = catalog->getForm();
if (form) {
for (iter = fields; iter != nullptr; iter = iter->next) {
list.emplace_back((char *)iter->data);
}
form->reset(list, exclude_fields);
}
}
}
/**
* poppler_document_has_javascript:
* @document: A #PopplerDocument
*
* Returns whether @document has any javascript in it.
*
* Since: 0.90
**/
gboolean poppler_document_has_javascript(PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), FALSE);
return document->doc->hasJavascript();
}
static void poppler_document_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
PopplerDocument *document = POPPLER_DOCUMENT(object);
guint version;
switch (prop_id) {
case PROP_TITLE:
g_value_take_string(value, poppler_document_get_title(document));
break;
case PROP_FORMAT:
g_value_take_string(value, poppler_document_get_pdf_version_string(document));
break;
case PROP_FORMAT_MAJOR:
poppler_document_get_pdf_version(document, &version, nullptr);
g_value_set_uint(value, version);
break;
case PROP_FORMAT_MINOR:
poppler_document_get_pdf_version(document, nullptr, &version);
g_value_set_uint(value, version);
break;
case PROP_AUTHOR:
g_value_take_string(value, poppler_document_get_author(document));
break;
case PROP_SUBJECT:
g_value_take_string(value, poppler_document_get_subject(document));
break;
case PROP_KEYWORDS:
g_value_take_string(value, poppler_document_get_keywords(document));
break;
case PROP_CREATOR:
g_value_take_string(value, poppler_document_get_creator(document));
break;
case PROP_PRODUCER:
g_value_take_string(value, poppler_document_get_producer(document));
break;
case PROP_CREATION_DATE:
g_value_set_int(value, poppler_document_get_creation_date(document));
break;
case PROP_CREATION_DATETIME:
g_value_take_boxed(value, poppler_document_get_creation_date_time(document));
break;
case PROP_MOD_DATE:
g_value_set_int(value, poppler_document_get_modification_date(document));
break;
case PROP_MOD_DATETIME:
g_value_take_boxed(value, poppler_document_get_modification_date_time(document));
break;
case PROP_LINEARIZED:
g_value_set_boolean(value, poppler_document_is_linearized(document));
break;
case PROP_PAGE_LAYOUT:
g_value_set_enum(value, poppler_document_get_page_layout(document));
break;
case PROP_PAGE_MODE:
g_value_set_enum(value, poppler_document_get_page_mode(document));
break;
case PROP_VIEWER_PREFERENCES:
/* FIXME: write... */
g_value_set_flags(value, POPPLER_VIEWER_PREFERENCES_UNSET);
break;
case PROP_PRINT_SCALING:
g_value_set_enum(value, poppler_document_get_print_scaling(document));
break;
case PROP_PRINT_DUPLEX:
g_value_set_enum(value, poppler_document_get_print_duplex(document));
break;
case PROP_PRINT_N_COPIES:
g_value_set_int(value, poppler_document_get_print_n_copies(document));
break;
case PROP_PERMISSIONS:
g_value_set_flags(value, poppler_document_get_permissions(document));
break;
case PROP_SUBTYPE:
g_value_set_enum(value, poppler_document_get_pdf_subtype(document));
break;
case PROP_SUBTYPE_STRING:
g_value_take_string(value, poppler_document_get_pdf_subtype_string(document));
break;
case PROP_SUBTYPE_PART:
g_value_set_enum(value, poppler_document_get_pdf_part(document));
break;
case PROP_SUBTYPE_CONF:
g_value_set_enum(value, poppler_document_get_pdf_conformance(document));
break;
case PROP_METADATA:
g_value_take_string(value, poppler_document_get_metadata(document));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
}
static void poppler_document_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
PopplerDocument *document = POPPLER_DOCUMENT(object);
switch (prop_id) {
case PROP_TITLE:
poppler_document_set_title(document, g_value_get_string(value));
break;
case PROP_AUTHOR:
poppler_document_set_author(document, g_value_get_string(value));
break;
case PROP_SUBJECT:
poppler_document_set_subject(document, g_value_get_string(value));
break;
case PROP_KEYWORDS:
poppler_document_set_keywords(document, g_value_get_string(value));
break;
case PROP_CREATOR:
poppler_document_set_creator(document, g_value_get_string(value));
break;
case PROP_PRODUCER:
poppler_document_set_producer(document, g_value_get_string(value));
break;
case PROP_CREATION_DATE:
poppler_document_set_creation_date(document, g_value_get_int(value));
break;
case PROP_CREATION_DATETIME:
poppler_document_set_creation_date_time(document, (GDateTime *)g_value_get_boxed(value));
break;
case PROP_MOD_DATE:
poppler_document_set_modification_date(document, g_value_get_int(value));
break;
case PROP_MOD_DATETIME:
poppler_document_set_modification_date_time(document, (GDateTime *)g_value_get_boxed(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
}
static void poppler_document_class_init(PopplerDocumentClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = poppler_document_finalize;
gobject_class->get_property = poppler_document_get_property;
gobject_class->set_property = poppler_document_set_property;
/**
* PopplerDocument:title:
*
* The document's title or %NULL
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_TITLE, g_param_spec_string("title", "Document Title", "The title of the document", nullptr, G_PARAM_READWRITE));
/**
* PopplerDocument:format:
*
* The PDF version as string. See also poppler_document_get_pdf_version_string()
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_FORMAT, g_param_spec_string("format", "PDF Format", "The PDF version of the document", nullptr, G_PARAM_READABLE));
/**
* PopplerDocument:format-major:
*
* The PDF major version number. See also poppler_document_get_pdf_version()
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_FORMAT_MAJOR, g_param_spec_uint("format-major", "PDF Format Major", "The PDF major version number of the document", 0, G_MAXUINT, 1, G_PARAM_READABLE));
/**
* PopplerDocument:format-minor:
*
* The PDF minor version number. See also poppler_document_get_pdf_version()
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_FORMAT_MINOR, g_param_spec_uint("format-minor", "PDF Format Minor", "The PDF minor version number of the document", 0, G_MAXUINT, 0, G_PARAM_READABLE));
/**
* PopplerDocument:author:
*
* The author of the document
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_AUTHOR, g_param_spec_string("author", "Author", "The author of the document", nullptr, G_PARAM_READWRITE));
/**
* PopplerDocument:subject:
*
* The subject of the document
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_SUBJECT, g_param_spec_string("subject", "Subject", "Subjects the document touches", nullptr, G_PARAM_READWRITE));
/**
* PopplerDocument:keywords:
*
* The keywords associated to the document
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_KEYWORDS, g_param_spec_string("keywords", "Keywords", "Keywords", nullptr, G_PARAM_READWRITE));
/**
* PopplerDocument:creator:
*
* The creator of the document. See also poppler_document_get_creator()
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_CREATOR, g_param_spec_string("creator", "Creator", "The software that created the document", nullptr, G_PARAM_READWRITE));
/**
* PopplerDocument:producer:
*
* The producer of the document. See also poppler_document_get_producer()
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_PRODUCER, g_param_spec_string("producer", "Producer", "The software that converted the document", nullptr, G_PARAM_READWRITE));
/**
* PopplerDocument:creation-date:
*
* The date the document was created as seconds since the Epoch, or -1
*
* Deprecated: 20.09.0: This will overflow in 2038. Use creation-datetime
* instead.
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_CREATION_DATE,
g_param_spec_int("creation-date", "Creation Date", "The date and time the document was created", -1, G_MAXINT, -1, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_DEPRECATED)));
/**
* PopplerDocument:creation-datetime:
* The #GDateTime the document was created.
*
* Since: 20.09.0
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_CREATION_DATETIME, g_param_spec_boxed("creation-datetime", "Creation DateTime", "The date and time the document was created", G_TYPE_DATE_TIME, G_PARAM_READWRITE));
/**
* PopplerDocument:mod-date:
*
* The date the document was most recently modified as seconds since the Epoch, or -1
*
* Deprecated: 20.09.0: This will overflow in 2038. Use mod-datetime instead.
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_MOD_DATE,
g_param_spec_int("mod-date", "Modification Date", "The date and time the document was modified", -1, G_MAXINT, -1, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_DEPRECATED)));
/**
* PopplerDocument:mod-datetime:
*
* The #GDateTime the document was most recently modified.
*
* Since: 20.09.0
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_MOD_DATETIME, g_param_spec_boxed("mod-datetime", "Modification DateTime", "The date and time the document was modified", G_TYPE_DATE_TIME, G_PARAM_READWRITE));
/**
* PopplerDocument:linearized:
*
* Whether document is linearized. See also poppler_document_is_linearized()
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_LINEARIZED, g_param_spec_boolean("linearized", "Fast Web View Enabled", "Is the document optimized for web viewing?", FALSE, G_PARAM_READABLE));
/**
* PopplerDocument:page-layout:
*
* The page layout that should be used when the document is opened
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_PAGE_LAYOUT, g_param_spec_enum("page-layout", "Page Layout", "Initial Page Layout", POPPLER_TYPE_PAGE_LAYOUT, POPPLER_PAGE_LAYOUT_UNSET, G_PARAM_READABLE));
/**
* PopplerDocument:page-mode:
*
* The mode that should be used when the document is opened
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_PAGE_MODE, g_param_spec_enum("page-mode", "Page Mode", "Page Mode", POPPLER_TYPE_PAGE_MODE, POPPLER_PAGE_MODE_UNSET, G_PARAM_READABLE));
/**
* PopplerDocument:viewer-preferences:
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_VIEWER_PREFERENCES,
g_param_spec_flags("viewer-preferences", "Viewer Preferences", "Viewer Preferences", POPPLER_TYPE_VIEWER_PREFERENCES, POPPLER_VIEWER_PREFERENCES_UNSET, G_PARAM_READABLE));
/**
* PopplerDocument:print-scaling:
*
* Since: 0.73
*/
g_object_class_install_property(
G_OBJECT_CLASS(klass), PROP_PRINT_SCALING,
g_param_spec_enum("print-scaling", "Print Scaling", "Print Scaling Viewer Preference", POPPLER_TYPE_PRINT_SCALING, POPPLER_PRINT_SCALING_APP_DEFAULT, (GParamFlags)(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
/**
* PopplerDocument:print-duplex:
*
* Since: 0.80
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_PRINT_DUPLEX,
g_param_spec_enum("print-duplex", "Print Duplex", "Duplex Viewer Preference", POPPLER_TYPE_PRINT_DUPLEX, POPPLER_PRINT_DUPLEX_NONE, (GParamFlags)(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
/**
* PopplerDocument:print-n-copies:
*
* Suggested number of copies to be printed for this document
*
* Since: 0.80
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_PRINT_N_COPIES,
g_param_spec_int("print-n-copies", "Number of Copies to Print", "Number of Copies Viewer Preference", 1, G_MAXINT, 1, (GParamFlags)(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
/**
* PopplerDocument:permissions:
*
* Flags specifying which operations are permitted when the document is opened
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_PERMISSIONS, g_param_spec_flags("permissions", "Permissions", "Permissions", POPPLER_TYPE_PERMISSIONS, POPPLER_PERMISSIONS_FULL, G_PARAM_READABLE));
/**
* PopplerDocument:subtype:
*
* Document PDF subtype type
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_SUBTYPE, g_param_spec_enum("subtype", "PDF Format Subtype Type", "The PDF subtype of the document", POPPLER_TYPE_PDF_SUBTYPE, POPPLER_PDF_SUBTYPE_UNSET, G_PARAM_READABLE));
/**
* PopplerDocument:subtype-string:
*
* Document PDF subtype. See also poppler_document_get_pdf_subtype_string()
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_SUBTYPE_STRING, g_param_spec_string("subtype-string", "PDF Format Subtype", "The PDF subtype of the document", nullptr, G_PARAM_READABLE));
/**
* PopplerDocument:subtype-part:
*
* Document PDF subtype part
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_SUBTYPE_PART,
g_param_spec_enum("subtype-part", "PDF Format Subtype Part", "The part of PDF conformance", POPPLER_TYPE_PDF_PART, POPPLER_PDF_SUBTYPE_PART_UNSET, G_PARAM_READABLE));
/**
* PopplerDocument:subtype-conformance:
*
* Document PDF subtype conformance
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_SUBTYPE_CONF,
g_param_spec_enum("subtype-conformance", "PDF Format Subtype Conformance", "The conformance level of PDF subtype", POPPLER_TYPE_PDF_CONFORMANCE, POPPLER_PDF_SUBTYPE_CONF_UNSET, G_PARAM_READABLE));
/**
* PopplerDocument:metadata:
*
* Document metadata in XML format, or %NULL
*/
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_METADATA, g_param_spec_string("metadata", "XML Metadata", "Embedded XML metadata", nullptr, G_PARAM_READABLE));
}
static void poppler_document_init(PopplerDocument *document) { }
/* PopplerIndexIter: For determining the index of a tree */
struct _PopplerIndexIter
{
PopplerDocument *document;
const std::vector<OutlineItem *> *items;
int index;
};
G_DEFINE_BOXED_TYPE(PopplerIndexIter, poppler_index_iter, poppler_index_iter_copy, poppler_index_iter_free)
/**
* poppler_index_iter_copy:
* @iter: a #PopplerIndexIter
*
* Creates a new #PopplerIndexIter as a copy of @iter. This must be freed with
* poppler_index_iter_free().
*
* Return value: a new #PopplerIndexIter
**/
PopplerIndexIter *poppler_index_iter_copy(PopplerIndexIter *iter)
{
PopplerIndexIter *new_iter;
g_return_val_if_fail(iter != nullptr, NULL);
new_iter = g_slice_dup(PopplerIndexIter, iter);
new_iter->document = (PopplerDocument *)g_object_ref(new_iter->document);
return new_iter;
}
/**
* poppler_index_iter_new:
* @document: a #PopplerDocument
*
* Returns the root #PopplerIndexIter for @document, or %NULL. This must be
* freed with poppler_index_iter_free().
*
* Certain documents have an index associated with them. This index can be used
* to help the user navigate the document, and is similar to a table of
* contents. Each node in the index will contain a #PopplerAction that can be
* displayed to the user — typically a #POPPLER_ACTION_GOTO_DEST or a
* #POPPLER_ACTION_URI<!-- -->.
*
* Here is a simple example of some code that walks the full index:
*
* <informalexample><programlisting>
* static void
* walk_index (PopplerIndexIter *iter)
* {
* do
* {
* /<!-- -->* Get the action and do something with it *<!-- -->/
* PopplerIndexIter *child = poppler_index_iter_get_child (iter);
* if (child)
* walk_index (child);
* poppler_index_iter_free (child);
* }
* while (poppler_index_iter_next (iter));
* }
* ...
* {
* iter = poppler_index_iter_new (document);
* walk_index (iter);
* poppler_index_iter_free (iter);
* }
*</programlisting></informalexample>
*
* Return value: a new #PopplerIndexIter
**/
PopplerIndexIter *poppler_index_iter_new(PopplerDocument *document)
{
PopplerIndexIter *iter;
Outline *outline;
const std::vector<OutlineItem *> *items;
outline = document->doc->getOutline();
if (outline == nullptr) {
return nullptr;
}
items = outline->getItems();
if (items == nullptr) {
return nullptr;
}
iter = g_slice_new(PopplerIndexIter);
iter->document = (PopplerDocument *)g_object_ref(document);
iter->items = items;
iter->index = 0;
return iter;
}
/**
* poppler_index_iter_get_child:
* @parent: a #PopplerIndexIter
*
* Returns a newly created child of @parent, or %NULL if the iter has no child.
* See poppler_index_iter_new() for more information on this function.
*
* Return value: a new #PopplerIndexIter
**/
PopplerIndexIter *poppler_index_iter_get_child(PopplerIndexIter *parent)
{
PopplerIndexIter *child;
OutlineItem *item;
g_return_val_if_fail(parent != nullptr, NULL);
item = (*parent->items)[parent->index];
item->open();
if (!(item->hasKids() && item->getKids())) {
return nullptr;
}
child = g_slice_new0(PopplerIndexIter);
child->document = (PopplerDocument *)g_object_ref(parent->document);
child->items = item->getKids();
g_assert(child->items);
return child;
}
static gchar *unicode_to_char(const Unicode *unicode, int len)
{
const UnicodeMap *uMap = globalParams->getUtf8Map();
GooString gstr;
gchar buf[8]; /* 8 is enough for mapping an unicode char to a string */
int i, n;
for (i = 0; i < len; ++i) {
n = uMap->mapUnicode(unicode[i], buf, sizeof(buf));
gstr.append(buf, n);
}
return g_strdup(gstr.c_str());
}
/**
* poppler_index_iter_is_open:
* @iter: a #PopplerIndexIter
*
* Returns whether this node should be expanded by default to the user. The
* document can provide a hint as to how the document's index should be expanded
* initially.
*
* Return value: %TRUE, if the document wants @iter to be expanded
**/
gboolean poppler_index_iter_is_open(PopplerIndexIter *iter)
{
OutlineItem *item;
item = (*iter->items)[iter->index];
return item->isOpen();
}
/**
* poppler_index_iter_get_action:
* @iter: a #PopplerIndexIter
*
* Returns the #PopplerAction associated with @iter. It must be freed with
* poppler_action_free().
*
* Return value: a new #PopplerAction
**/
PopplerAction *poppler_index_iter_get_action(PopplerIndexIter *iter)
{
OutlineItem *item;
const LinkAction *link_action;
PopplerAction *action;
gchar *title;
g_return_val_if_fail(iter != nullptr, NULL);
item = (*iter->items)[iter->index];
link_action = item->getAction();
const std::vector<Unicode> &itemTitle = item->getTitle();
title = unicode_to_char(itemTitle.data(), itemTitle.size());
action = _poppler_action_new(iter->document, link_action, title);
g_free(title);
return action;
}
/**
* poppler_index_iter_next:
* @iter: a #PopplerIndexIter
*
* Sets @iter to point to the next action at the current level, if valid. See
* poppler_index_iter_new() for more information.
*
* Return value: %TRUE, if @iter was set to the next action
**/
gboolean poppler_index_iter_next(PopplerIndexIter *iter)
{
g_return_val_if_fail(iter != nullptr, FALSE);
iter->index++;
if (iter->index >= (int)iter->items->size()) {
return FALSE;
}
return TRUE;
}
/**
* poppler_index_iter_free:
* @iter: a #PopplerIndexIter
*
* Frees @iter.
**/
void poppler_index_iter_free(PopplerIndexIter *iter)
{
if (G_UNLIKELY(iter == nullptr)) {
return;
}
g_object_unref(iter->document);
g_slice_free(PopplerIndexIter, iter);
}
struct _PopplerFontsIter
{
std::vector<FontInfo *> items;
int index;
};
G_DEFINE_BOXED_TYPE(PopplerFontsIter, poppler_fonts_iter, poppler_fonts_iter_copy, poppler_fonts_iter_free)
/**
* poppler_fonts_iter_get_full_name:
* @iter: a #PopplerFontsIter
*
* Returns the full name of the font associated with @iter
*
* Returns: the font full name
*/
const char *poppler_fonts_iter_get_full_name(PopplerFontsIter *iter)
{
FontInfo *info;
info = iter->items[iter->index];
const std::optional<std::string> &name = info->getName();
if (name) {
return name->c_str();
} else {
return nullptr;
}
}
/**
* poppler_fonts_iter_get_name:
* @iter: a #PopplerFontsIter
*
* Returns the name of the font associated with @iter
*
* Returns: the font name
*/
const char *poppler_fonts_iter_get_name(PopplerFontsIter *iter)
{
FontInfo *info;
const char *name;
name = poppler_fonts_iter_get_full_name(iter);
info = iter->items[iter->index];
if (info->getSubset() && name) {
while (*name && *name != '+') {
name++;
}
if (*name) {
name++;
}
}
return name;
}
/**
* poppler_fonts_iter_get_substitute_name:
* @iter: a #PopplerFontsIter
*
* The name of the substitute font of the font associated with @iter or %NULL if
* the font is embedded
*
* Returns: the name of the substitute font or %NULL if font is embedded
*
* Since: 0.20
*/
const char *poppler_fonts_iter_get_substitute_name(PopplerFontsIter *iter)
{
FontInfo *info;
info = iter->items[iter->index];
const std::optional<std::string> &name = info->getSubstituteName();
if (name) {
return name->c_str();
} else {
return nullptr;
}
}
/**
* poppler_fonts_iter_get_file_name:
* @iter: a #PopplerFontsIter
*
* The filename of the font associated with @iter or %NULL if
* the font is embedded
*
* Returns: the filename of the font or %NULL if font is embedded
*/
const char *poppler_fonts_iter_get_file_name(PopplerFontsIter *iter)
{
FontInfo *info;
info = iter->items[iter->index];
const std::optional<std::string> &file = info->getFile();
if (file) {
return file->c_str();
} else {
return nullptr;
}
}
/**
* poppler_fonts_iter_get_font_type:
* @iter: a #PopplerFontsIter
*
* Returns the type of the font associated with @iter
*
* Returns: the font type
*/
PopplerFontType poppler_fonts_iter_get_font_type(PopplerFontsIter *iter)
{
FontInfo *info;
g_return_val_if_fail(iter != nullptr, POPPLER_FONT_TYPE_UNKNOWN);
info = iter->items[iter->index];
return (PopplerFontType)info->getType();
}
/**
* poppler_fonts_iter_get_encoding:
* @iter: a #PopplerFontsIter
*
* Returns the encoding of the font associated with @iter
*
* Returns: the font encoding
*
* Since: 0.20
*/
const char *poppler_fonts_iter_get_encoding(PopplerFontsIter *iter)
{
FontInfo *info;
info = iter->items[iter->index];
const std::string &encoding = info->getEncoding();
if (!encoding.empty()) {
return encoding.c_str();
} else {
return nullptr;
}
}
/**
* poppler_fonts_iter_is_embedded:
* @iter: a #PopplerFontsIter
*
* Returns whether the font associated with @iter is embedded in the document
*
* Returns: %TRUE if font is embedded, %FALSE otherwise
*/
gboolean poppler_fonts_iter_is_embedded(PopplerFontsIter *iter)
{
FontInfo *info;
info = iter->items[iter->index];
return info->getEmbedded();
}
/**
* poppler_fonts_iter_is_subset:
* @iter: a #PopplerFontsIter
*
* Returns whether the font associated with @iter is a subset of another font
*
* Returns: %TRUE if font is a subset, %FALSE otherwise
*/
gboolean poppler_fonts_iter_is_subset(PopplerFontsIter *iter)
{
FontInfo *info;
info = iter->items[iter->index];
return info->getSubset();
}
/**
* poppler_fonts_iter_next:
* @iter: a #PopplerFontsIter
*
* Sets @iter to point to the next font
*
* Returns: %TRUE, if @iter was set to the next font
**/
gboolean poppler_fonts_iter_next(PopplerFontsIter *iter)
{
g_return_val_if_fail(iter != nullptr, FALSE);
iter->index++;
if (iter->index >= (int)iter->items.size()) {
return FALSE;
}
return TRUE;
}
/**
* poppler_fonts_iter_copy:
* @iter: a #PopplerFontsIter to copy
*
* Creates a copy of @iter
*
* Returns: a new allocated copy of @iter
*/
PopplerFontsIter *poppler_fonts_iter_copy(PopplerFontsIter *iter)
{
PopplerFontsIter *new_iter;
g_return_val_if_fail(iter != nullptr, NULL);
new_iter = g_slice_dup(PopplerFontsIter, iter);
new_iter->items.resize(iter->items.size());
for (std::size_t i = 0; i < iter->items.size(); i++) {
FontInfo *info = iter->items[i];
new_iter->items[i] = new FontInfo(*info);
}
return new_iter;
}
/**
* poppler_fonts_iter_free:
* @iter: a #PopplerFontsIter
*
* Frees the given #PopplerFontsIter
*/
void poppler_fonts_iter_free(PopplerFontsIter *iter)
{
if (G_UNLIKELY(iter == nullptr)) {
return;
}
for (auto entry : iter->items) {
delete entry;
}
iter->items.~vector<FontInfo *>();
g_slice_free(PopplerFontsIter, iter);
}
static PopplerFontsIter *poppler_fonts_iter_new(std::vector<FontInfo *> &&items)
{
PopplerFontsIter *iter;
iter = g_slice_new(PopplerFontsIter);
new ((void *)&iter->items) std::vector<FontInfo *>(std::move(items));
iter->index = 0;
return iter;
}
typedef struct _PopplerFontInfoClass PopplerFontInfoClass;
struct _PopplerFontInfoClass
{
GObjectClass parent_class;
};
G_DEFINE_TYPE(PopplerFontInfo, poppler_font_info, G_TYPE_OBJECT)
static void poppler_font_info_finalize(GObject *object);
static void poppler_font_info_class_init(PopplerFontInfoClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = poppler_font_info_finalize;
}
static void poppler_font_info_init(PopplerFontInfo *font_info)
{
font_info->document = nullptr;
font_info->scanner = nullptr;
}
static void poppler_font_info_finalize(GObject *object)
{
PopplerFontInfo *font_info = POPPLER_FONT_INFO(object);
delete font_info->scanner;
g_object_unref(font_info->document);
G_OBJECT_CLASS(poppler_font_info_parent_class)->finalize(object);
}
/**
* poppler_font_info_new:
* @document: a #PopplerDocument
*
* Creates a new #PopplerFontInfo object
*
* Returns: a new #PopplerFontInfo instance
*/
PopplerFontInfo *poppler_font_info_new(PopplerDocument *document)
{
PopplerFontInfo *font_info;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
font_info = (PopplerFontInfo *)g_object_new(POPPLER_TYPE_FONT_INFO, nullptr);
font_info->document = (PopplerDocument *)g_object_ref(document);
font_info->scanner = new FontInfoScanner(document->doc);
return font_info;
}
/**
* poppler_font_info_scan:
* @font_info: a #PopplerFontInfo
* @n_pages: number of pages to scan
* @iter: (out): return location for a #PopplerFontsIter
*
* Scans the document associated with @font_info for fonts. At most
* @n_pages will be scanned starting from the current iterator. @iter will
* point to the first font scanned.
*
* Here is a simple example of code to scan fonts in a document
*
* <informalexample><programlisting>
* font_info = poppler_font_info_new (document);
* while (poppler_font_info_scan (font_info, 20, &fonts_iter)) {
* if (!fonts_iter)
* continue; /<!-- -->* No fonts found in these 20 pages *<!-- -->/
* do {
* /<!-- -->* Do something with font iter *<!-- -->/
* g_print ("Font Name: %s\n", poppler_fonts_iter_get_name (fonts_iter));
* } while (poppler_fonts_iter_next (fonts_iter));
* poppler_fonts_iter_free (fonts_iter);
* }
* </programlisting></informalexample>
*
* Returns: %TRUE, if there are more fonts left to scan
*/
gboolean poppler_font_info_scan(PopplerFontInfo *font_info, int n_pages, PopplerFontsIter **iter)
{
g_return_val_if_fail(iter != nullptr, FALSE);
std::vector<FontInfo *> items = font_info->scanner->scan(n_pages);
if (items.empty()) {
*iter = nullptr;
return FALSE;
} else {
*iter = poppler_fonts_iter_new(std::move(items));
}
return TRUE;
}
/* For backward compatibility */
void poppler_font_info_free(PopplerFontInfo *font_info)
{
g_return_if_fail(font_info != nullptr);
g_object_unref(font_info);
}
/* Optional content (layers) */
static Layer *layer_new(OptionalContentGroup *oc)
{
Layer *layer;
layer = g_slice_new0(Layer);
layer->oc = oc;
return layer;
}
static void layer_free(Layer *layer)
{
if (G_UNLIKELY(!layer)) {
return;
}
if (layer->kids) {
g_list_free_full(layer->kids, (GDestroyNotify)layer_free);
}
if (layer->label) {
g_free(layer->label);
}
g_slice_free(Layer, layer);
}
static GList *get_optional_content_rbgroups(OCGs *ocg)
{
Array *rb;
GList *groups = nullptr;
rb = ocg->getRBGroupsArray();
if (rb) {
int i, j;
for (i = 0; i < rb->getLength(); ++i) {
Array *rb_array;
GList *group = nullptr;
Object obj = rb->get(i);
if (!obj.isArray()) {
continue;
}
rb_array = obj.getArray();
for (j = 0; j < rb_array->getLength(); ++j) {
OptionalContentGroup *oc;
const Object &ref = rb_array->getNF(j);
if (!ref.isRef()) {
continue;
}
oc = ocg->findOcgByRef(ref.getRef());
group = g_list_prepend(group, oc);
}
groups = g_list_prepend(groups, group);
}
}
return groups;
}
GList *_poppler_document_get_layer_rbgroup(PopplerDocument *document, Layer *layer)
{
GList *l;
for (l = document->layers_rbgroups; l && l->data; l = g_list_next(l)) {
GList *group = (GList *)l->data;
if (g_list_find(group, layer->oc)) {
return group;
}
}
return nullptr;
}
static GList *get_optional_content_items_sorted(OCGs *ocg, Layer *parent, Array *order)
{
GList *items = nullptr;
Layer *last_item = parent;
int i;
for (i = 0; i < order->getLength(); ++i) {
Object orderItem = order->get(i);
if (orderItem.isDict()) {
const Object &ref = order->getNF(i);
if (ref.isRef()) {
OptionalContentGroup *oc = ocg->findOcgByRef(ref.getRef());
Layer *layer = layer_new(oc);
items = g_list_prepend(items, layer);
last_item = layer;
}
} else if (orderItem.isArray() && orderItem.arrayGetLength() > 0) {
if (!last_item) {
last_item = layer_new(nullptr);
items = g_list_prepend(items, last_item);
}
last_item->kids = get_optional_content_items_sorted(ocg, last_item, orderItem.getArray());
last_item = nullptr;
} else if (orderItem.isString()) {
last_item->label = _poppler_goo_string_to_utf8(orderItem.getString());
}
}
return g_list_reverse(items);
}
static GList *get_optional_content_items(OCGs *ocg)
{
Array *order;
GList *items = nullptr;
order = ocg->getOrderArray();
if (order) {
items = get_optional_content_items_sorted(ocg, nullptr, order);
} else {
const auto &ocgs = ocg->getOCGs();
for (const auto &oc : ocgs) {
Layer *layer = layer_new(oc.second.get());
items = g_list_prepend(items, layer);
}
items = g_list_reverse(items);
}
return items;
}
GList *_poppler_document_get_layers(PopplerDocument *document)
{
if (!document->layers) {
Catalog *catalog = document->doc->getCatalog();
OCGs *ocg = catalog->getOptContentConfig();
if (!ocg) {
return nullptr;
}
document->layers = get_optional_content_items(ocg);
document->layers_rbgroups = get_optional_content_rbgroups(ocg);
}
return document->layers;
}
static void poppler_document_layers_free(PopplerDocument *document)
{
if (G_UNLIKELY(!document->layers)) {
return;
}
g_list_free_full(document->layers, (GDestroyNotify)layer_free);
g_list_free_full(document->layers_rbgroups, (GDestroyNotify)g_list_free);
document->layers = nullptr;
document->layers_rbgroups = nullptr;
}
/* PopplerLayersIter */
struct _PopplerLayersIter
{
PopplerDocument *document;
GList *items;
int index;
};
G_DEFINE_BOXED_TYPE(PopplerLayersIter, poppler_layers_iter, poppler_layers_iter_copy, poppler_layers_iter_free)
/**
* poppler_layers_iter_copy:
* @iter: a #PopplerLayersIter
*
* Creates a new #PopplerLayersIter as a copy of @iter. This must be freed with
* poppler_layers_iter_free().
*
* Return value: a new #PopplerLayersIter
*
* Since 0.12
**/
PopplerLayersIter *poppler_layers_iter_copy(PopplerLayersIter *iter)
{
PopplerLayersIter *new_iter;
g_return_val_if_fail(iter != nullptr, NULL);
new_iter = g_slice_dup(PopplerLayersIter, iter);
new_iter->document = (PopplerDocument *)g_object_ref(new_iter->document);
return new_iter;
}
/**
* poppler_layers_iter_free:
* @iter: a #PopplerLayersIter
*
* Frees @iter.
*
* Since: 0.12
**/
void poppler_layers_iter_free(PopplerLayersIter *iter)
{
if (G_UNLIKELY(iter == nullptr)) {
return;
}
g_object_unref(iter->document);
g_slice_free(PopplerLayersIter, iter);
}
/**
* poppler_layers_iter_new:
* @document: a #PopplerDocument
*
* Since: 0.12
**/
PopplerLayersIter *poppler_layers_iter_new(PopplerDocument *document)
{
PopplerLayersIter *iter;
GList *items;
items = _poppler_document_get_layers(document);
if (!items) {
return nullptr;
}
iter = g_slice_new0(PopplerLayersIter);
iter->document = (PopplerDocument *)g_object_ref(document);
iter->items = items;
return iter;
}
/**
* poppler_layers_iter_get_child:
* @parent: a #PopplerLayersIter
*
* Returns a newly created child of @parent, or %NULL if the iter has no child.
* See poppler_layers_iter_new() for more information on this function.
*
* Return value: a new #PopplerLayersIter, or %NULL
*
* Since: 0.12
**/
PopplerLayersIter *poppler_layers_iter_get_child(PopplerLayersIter *parent)
{
PopplerLayersIter *child;
Layer *layer;
g_return_val_if_fail(parent != nullptr, NULL);
layer = (Layer *)g_list_nth_data(parent->items, parent->index);
if (!layer || !layer->kids) {
return nullptr;
}
child = g_slice_new0(PopplerLayersIter);
child->document = (PopplerDocument *)g_object_ref(parent->document);
child->items = layer->kids;
g_assert(child->items);
return child;
}
/**
* poppler_layers_iter_get_title:
* @iter: a #PopplerLayersIter
*
* Returns the title associated with @iter. It must be freed with
* g_free().
*
* Return value: a new string containing the @iter's title or %NULL if @iter doesn't have a title.
* The returned string should be freed with g_free() when no longer needed.
*
* Since: 0.12
**/
gchar *poppler_layers_iter_get_title(PopplerLayersIter *iter)
{
Layer *layer;
g_return_val_if_fail(iter != nullptr, NULL);
layer = (Layer *)g_list_nth_data(iter->items, iter->index);
return layer->label ? g_strdup(layer->label) : nullptr;
}
/**
* poppler_layers_iter_get_layer:
* @iter: a #PopplerLayersIter
*
* Returns the #PopplerLayer associated with @iter.
*
* Return value: (transfer full): a new #PopplerLayer, or %NULL if
* there isn't any layer associated with @iter
*
* Since: 0.12
**/
PopplerLayer *poppler_layers_iter_get_layer(PopplerLayersIter *iter)
{
Layer *layer;
PopplerLayer *poppler_layer = nullptr;
g_return_val_if_fail(iter != nullptr, NULL);
layer = (Layer *)g_list_nth_data(iter->items, iter->index);
if (layer->oc) {
GList *rb_group = nullptr;
rb_group = _poppler_document_get_layer_rbgroup(iter->document, layer);
poppler_layer = _poppler_layer_new(iter->document, layer, rb_group);
}
return poppler_layer;
}
/**
* poppler_layers_iter_next:
* @iter: a #PopplerLayersIter
*
* Sets @iter to point to the next action at the current level, if valid. See
* poppler_layers_iter_new() for more information.
*
* Return value: %TRUE, if @iter was set to the next action
*
* Since: 0.12
**/
gboolean poppler_layers_iter_next(PopplerLayersIter *iter)
{
g_return_val_if_fail(iter != nullptr, FALSE);
iter->index++;
if (iter->index >= (gint)g_list_length(iter->items)) {
return FALSE;
}
return TRUE;
}
typedef struct _PopplerPSFileClass PopplerPSFileClass;
struct _PopplerPSFileClass
{
GObjectClass parent_class;
};
G_DEFINE_TYPE(PopplerPSFile, poppler_ps_file, G_TYPE_OBJECT)
static void poppler_ps_file_finalize(GObject *object);
static void poppler_ps_file_class_init(PopplerPSFileClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = poppler_ps_file_finalize;
}
static void poppler_ps_file_init(PopplerPSFile *ps_file)
{
ps_file->out = nullptr;
ps_file->fd = -1;
ps_file->filename = nullptr;
ps_file->paper_width = -1;
ps_file->paper_height = -1;
ps_file->duplex = FALSE;
}
static void poppler_ps_file_finalize(GObject *object)
{
PopplerPSFile *ps_file = POPPLER_PS_FILE(object);
delete ps_file->out;
g_object_unref(ps_file->document);
g_free(ps_file->filename);
#ifndef G_OS_WIN32
if (ps_file->fd != -1) {
close(ps_file->fd);
}
#endif /* !G_OS_WIN32 */
G_OBJECT_CLASS(poppler_ps_file_parent_class)->finalize(object);
}
/**
* poppler_ps_file_new:
* @document: a #PopplerDocument
* @filename: the path of the output filename
* @first_page: the first page to print
* @n_pages: the number of pages to print
*
* Create a new postscript file to render to
*
* Return value: (transfer full): a PopplerPSFile
**/
PopplerPSFile *poppler_ps_file_new(PopplerDocument *document, const char *filename, int first_page, int n_pages)
{
PopplerPSFile *ps_file;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
g_return_val_if_fail(filename != nullptr, NULL);
g_return_val_if_fail(n_pages > 0, NULL);
ps_file = (PopplerPSFile *)g_object_new(POPPLER_TYPE_PS_FILE, nullptr);
ps_file->document = (PopplerDocument *)g_object_ref(document);
ps_file->filename = g_strdup(filename);
ps_file->first_page = first_page + 1;
ps_file->last_page = first_page + 1 + n_pages - 1;
return ps_file;
}
#ifndef G_OS_WIN32
/**
* poppler_ps_file_new_fd:
* @document: a #PopplerDocument
* @fd: a valid file descriptor open for writing
* @first_page: the first page to print
* @n_pages: the number of pages to print
*
* Create a new postscript file to render to.
* Note that this function takes ownership of @fd; you must not operate on it
* again, nor close it.
*
* Return value: (transfer full): a #PopplerPSFile
*
* Since: 21.12.0
**/
PopplerPSFile *poppler_ps_file_new_fd(PopplerDocument *document, int fd, int first_page, int n_pages)
{
PopplerPSFile *ps_file;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), nullptr);
g_return_val_if_fail(fd != -1, nullptr);
g_return_val_if_fail(n_pages > 0, nullptr);
ps_file = (PopplerPSFile *)g_object_new(POPPLER_TYPE_PS_FILE, nullptr);
ps_file->document = (PopplerDocument *)g_object_ref(document);
ps_file->fd = fd;
ps_file->first_page = first_page + 1;
ps_file->last_page = first_page + 1 + n_pages - 1;
return ps_file;
}
#endif /* !G_OS_WIN32 */
/**
* poppler_ps_file_set_paper_size:
* @ps_file: a PopplerPSFile which was not yet printed to.
* @width: the paper width in 1/72 inch
* @height: the paper height in 1/72 inch
*
* Set the output paper size. These values will end up in the
* DocumentMedia, the BoundingBox DSC comments and other places in the
* generated PostScript.
*
**/
void poppler_ps_file_set_paper_size(PopplerPSFile *ps_file, double width, double height)
{
g_return_if_fail(ps_file->out == nullptr);
ps_file->paper_width = width;
ps_file->paper_height = height;
}
/**
* poppler_ps_file_set_duplex:
* @ps_file: a PopplerPSFile which was not yet printed to
* @duplex: whether to force duplex printing (on printers which support this)
*
* Enable or disable Duplex printing.
*
**/
void poppler_ps_file_set_duplex(PopplerPSFile *ps_file, gboolean duplex)
{
g_return_if_fail(ps_file->out == nullptr);
ps_file->duplex = duplex;
}
/**
* poppler_ps_file_free:
* @ps_file: a PopplerPSFile
*
* Frees @ps_file
*
**/
void poppler_ps_file_free(PopplerPSFile *ps_file)
{
g_return_if_fail(ps_file != nullptr);
g_object_unref(ps_file);
}
/**
* poppler_document_get_form_field:
* @document: a #PopplerDocument
* @id: an id of a #PopplerFormField
*
* Returns the #PopplerFormField for the given @id. It must be freed with
* g_object_unref()
*
* Return value: (transfer full): a new #PopplerFormField or %NULL if
* not found
**/
PopplerFormField *poppler_document_get_form_field(PopplerDocument *document, gint id)
{
Page *page;
unsigned pageNum;
unsigned fieldNum;
FormWidget *field;
FormWidget::decodeID(id, &pageNum, &fieldNum);
page = document->doc->getPage(pageNum);
if (!page) {
return nullptr;
}
const std::unique_ptr<FormPageWidgets> widgets = page->getFormWidgets();
if (!widgets) {
return nullptr;
}
field = widgets->getWidget(fieldNum);
if (field) {
return _poppler_form_field_new(document, field);
}
return nullptr;
}
gboolean _poppler_convert_pdf_date_to_gtime(const GooString *date, time_t *gdate)
{
gchar *date_string;
gboolean retval;
if (hasUnicodeByteOrderMark(date->toStr())) {
date_string = g_convert(date->c_str() + 2, date->getLength() - 2, "UTF-8", "UTF-16BE", nullptr, nullptr, nullptr);
} else {
date_string = g_strndup(date->c_str(), date->getLength());
}
retval = poppler_date_parse(date_string, gdate);
g_free(date_string);
return retval;
}
/**
* _poppler_convert_pdf_date_to_date_time:
* @date: a PDF date
*
* Converts the PDF date in @date to a #GDateTime.
*
* Returns: The converted date, or %NULL on error.
**/
GDateTime *_poppler_convert_pdf_date_to_date_time(const GooString *date)
{
GDateTime *date_time = nullptr;
GTimeZone *time_zone = nullptr;
int year, mon, day, hour, min, sec, tzHours, tzMins;
char tz;
if (parseDateString(date, &year, &mon, &day, &hour, &min, &sec, &tz, &tzHours, &tzMins)) {
if (tz == '+' || tz == '-') {
gchar *identifier;
identifier = g_strdup_printf("%c%02u:%02u", tz, tzHours, tzMins);
#if GLIB_CHECK_VERSION(2, 68, 0)
time_zone = g_time_zone_new_identifier(identifier);
if (!time_zone) {
g_debug("Failed to create time zone for identifier \"%s\"", identifier);
time_zone = g_time_zone_new_utc();
}
#else
time_zone = g_time_zone_new(identifier);
#endif
g_free(identifier);
} else if (tz == '\0' || tz == 'Z') {
time_zone = g_time_zone_new_utc();
} else {
g_warning("unexpected tz val '%c'", tz);
time_zone = g_time_zone_new_utc();
}
date_time = g_date_time_new(time_zone, year, mon, day, hour, min, sec);
g_time_zone_unref(time_zone);
}
return date_time;
}
/**
* _poppler_convert_date_time_to_pdf_date:
* @datetime: a #GDateTime
*
* Converts a #GDateTime to a PDF date.
*
* Returns: The converted date
**/
GooString *_poppler_convert_date_time_to_pdf_date(GDateTime *datetime)
{
int offset_min;
gchar *date_str;
std::unique_ptr<GooString> out_str;
offset_min = g_date_time_get_utc_offset(datetime) / 1000000 / 60;
date_str = g_date_time_format(datetime, "D:%Y%m%d%H%M%S");
if (offset_min == 0) {
out_str = GooString::format("{0:s}Z", date_str);
} else {
char tz = offset_min > 0 ? '+' : '-';
out_str = GooString::format("{0:s}{1:c}{2:02d}'{3:02d}'", date_str, tz, offset_min / 60, offset_min % 60);
}
g_free(date_str);
return out_str.release();
}
static void _poppler_sign_document_thread(GTask *task, PopplerDocument *document, const PopplerSigningData *signing_data, GCancellable *cancellable)
{
const PopplerCertificateInfo *certificate_info;
const char *signing_data_signature_text;
const PopplerColor *font_color;
const PopplerColor *border_color;
const PopplerColor *background_color;
gboolean ret;
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
g_return_if_fail(signing_data != nullptr);
signing_data_signature_text = poppler_signing_data_get_signature_text(signing_data);
if (signing_data_signature_text == nullptr) {
g_task_return_new_error(task, POPPLER_ERROR, POPPLER_ERROR_SIGNING, "No signature given");
return;
}
certificate_info = poppler_signing_data_get_certificate_info(signing_data);
if (certificate_info == nullptr) {
g_task_return_new_error(task, POPPLER_ERROR, POPPLER_ERROR_SIGNING, "Invalid certificate information provided for signing");
return;
}
PopplerPage *page = poppler_document_get_page(document, poppler_signing_data_get_page(signing_data));
if (page == nullptr) {
g_task_return_new_error(task, POPPLER_ERROR, POPPLER_ERROR_SIGNING, "Invalid page number selected for signing");
return;
}
font_color = poppler_signing_data_get_font_color(signing_data);
border_color = poppler_signing_data_get_border_color(signing_data);
background_color = poppler_signing_data_get_background_color(signing_data);
std::unique_ptr<GooString> signature_text = std::make_unique<GooString>(utf8ToUtf16WithBom(signing_data_signature_text));
std::unique_ptr<GooString> signature_text_left = std::make_unique<GooString>(utf8ToUtf16WithBom(poppler_signing_data_get_signature_text_left(signing_data)));
const auto field_partial_name = new GooString(poppler_signing_data_get_field_partial_name(signing_data), strlen(poppler_signing_data_get_field_partial_name(signing_data)));
const auto owner_pwd = std::optional<GooString>(poppler_signing_data_get_document_owner_password(signing_data));
const auto user_pwd = std::optional<GooString>(poppler_signing_data_get_document_user_password(signing_data));
const auto reason = std::unique_ptr<GooString>(poppler_signing_data_get_reason(signing_data) ? new GooString(poppler_signing_data_get_reason(signing_data), strlen(poppler_signing_data_get_reason(signing_data))) : nullptr);
const auto location = std::unique_ptr<GooString>(poppler_signing_data_get_location(signing_data) ? new GooString(poppler_signing_data_get_location(signing_data), strlen(poppler_signing_data_get_location(signing_data))) : nullptr);
const PopplerRectangle *rect = poppler_signing_data_get_signature_rectangle(signing_data);
ret = document->doc->sign(poppler_signing_data_get_destination_filename(signing_data), poppler_certificate_info_get_id((PopplerCertificateInfo *)certificate_info),
poppler_signing_data_get_password(signing_data) ? poppler_signing_data_get_password(signing_data) : "", field_partial_name, poppler_signing_data_get_page(signing_data) + 1,
PDFRectangle(rect->x1, rect->y1, rect->x2, rect->y2), *signature_text, *signature_text_left, poppler_signing_data_get_font_size(signing_data), poppler_signing_data_get_left_font_size(signing_data),
std::make_unique<AnnotColor>(font_color->red, font_color->green, font_color->blue), poppler_signing_data_get_border_width(signing_data),
std::make_unique<AnnotColor>(border_color->red, border_color->green, border_color->blue), std::make_unique<AnnotColor>(background_color->red, background_color->green, background_color->blue), reason.get(),
location.get(), poppler_signing_data_get_image_path(signing_data) ? poppler_signing_data_get_image_path(signing_data) : "", owner_pwd, user_pwd);
g_task_return_boolean(task, ret);
}
/**
* poppler_document_sign:
* @document: a #PopplerDocument
* @signing_data: a #PopplerSigningData
* @cancellable: a #GCancellable
* @callback: a #GAsyncReadyCallback
* @user_data: user data used by callback function
*
* Sign #document using #signing_data.
*
* Since: 23.07.0
**/
void poppler_document_sign(PopplerDocument *document, const PopplerSigningData *signing_data, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
GTask *task;
g_return_if_fail(POPPLER_IS_DOCUMENT(document));
g_return_if_fail(signing_data != nullptr);
task = g_task_new(document, cancellable, callback, user_data);
g_task_set_task_data(task, (void *)signing_data, nullptr);
g_task_run_in_thread(task, (GTaskThreadFunc)_poppler_sign_document_thread);
g_object_unref(task);
}
/**
* poppler_document_sign_finish:
* @document: a #PopplerDocument
* @result: a #GAsyncResult
* @error: a #GError
*
* Finish poppler_sign_document and get return status or error.
*
* Returns: %TRUE on successful signing a document, otherwise %FALSE and error is set.
*
* Since: 23.07.0
**/
gboolean poppler_document_sign_finish(PopplerDocument *document, GAsyncResult *result, GError **error)
{
g_return_val_if_fail(g_task_is_valid(result, document), FALSE);
return g_task_propagate_boolean(G_TASK(result), error);
}
|