Spaces:
Running
Running
File size: 74,836 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 |
/* poppler-structure.cc: glib interface to poppler
*
* Copyright (C) 2013 Igalia S.L.
* Copyright (C) 2018 Albert Astals Cid <[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"
#ifndef __GI_SCANNER__
# include <StructTreeRoot.h>
# include <StructElement.h>
# include <GlobalParams.h>
# include <UnicodeMap.h>
# include <cmath>
#endif /* !__GI_SCANNER__ */
#include "poppler.h"
#include "poppler-private.h"
#include "poppler-structure-element.h"
/**
* SECTION:poppler-structure-element
* @short_description: Document structure element.
* @title: PopplerStructureElement
*
* Instances of #PopplerStructureElement are used to describe the structure
* of a #PopplerDocument. To access the elements in the structure of the
* document, use poppler_structure_element_iter_new() to obtain an iterator
* for the top-level #PopplerStructureElement, and then use the
* #PopplerStructureElementIter methods to traverse the structure tree.
*/
typedef struct _PopplerStructureElementClass
{
GObjectClass parent_class;
} PopplerStructureElementClass;
G_DEFINE_TYPE(PopplerStructureElement, poppler_structure_element, G_TYPE_OBJECT)
static PopplerStructureElement *_poppler_structure_element_new(PopplerDocument *document, const StructElement *element)
{
PopplerStructureElement *poppler_structure_element;
g_assert(POPPLER_IS_DOCUMENT(document));
g_assert(element);
poppler_structure_element = (PopplerStructureElement *)g_object_new(POPPLER_TYPE_STRUCTURE_ELEMENT, nullptr, NULL);
poppler_structure_element->document = (PopplerDocument *)g_object_ref(document);
poppler_structure_element->elem = element;
return poppler_structure_element;
}
static void poppler_structure_element_init(PopplerStructureElement *poppler_structure_element) { }
static void poppler_structure_element_finalize(GObject *object)
{
PopplerStructureElement *poppler_structure_element = POPPLER_STRUCTURE_ELEMENT(object);
/* poppler_structure_element->elem is owned by the StructTreeRoot */
g_object_unref(poppler_structure_element->document);
G_OBJECT_CLASS(poppler_structure_element_parent_class)->finalize(object);
}
static void poppler_structure_element_class_init(PopplerStructureElementClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = poppler_structure_element_finalize;
}
/**
* poppler_structure_element_get_kind:
* @poppler_structure_element: A #PopplerStructureElement
*
* Return value: A #PopplerStructureElementKind value.
*
* Since: 0.26
*/
PopplerStructureElementKind poppler_structure_element_get_kind(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), POPPLER_STRUCTURE_ELEMENT_CONTENT);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, POPPLER_STRUCTURE_ELEMENT_CONTENT);
switch (poppler_structure_element->elem->getType()) {
case StructElement::MCID:
return POPPLER_STRUCTURE_ELEMENT_CONTENT;
case StructElement::OBJR:
return POPPLER_STRUCTURE_ELEMENT_OBJECT_REFERENCE;
case StructElement::Document:
return POPPLER_STRUCTURE_ELEMENT_DOCUMENT;
case StructElement::Part:
return POPPLER_STRUCTURE_ELEMENT_PART;
case StructElement::Art:
return POPPLER_STRUCTURE_ELEMENT_ARTICLE;
case StructElement::Sect:
return POPPLER_STRUCTURE_ELEMENT_SECTION;
case StructElement::Div:
return POPPLER_STRUCTURE_ELEMENT_DIV;
case StructElement::Span:
return POPPLER_STRUCTURE_ELEMENT_SPAN;
case StructElement::Quote:
return POPPLER_STRUCTURE_ELEMENT_QUOTE;
case StructElement::Note:
return POPPLER_STRUCTURE_ELEMENT_NOTE;
case StructElement::Reference:
return POPPLER_STRUCTURE_ELEMENT_REFERENCE;
case StructElement::BibEntry:
return POPPLER_STRUCTURE_ELEMENT_BIBENTRY;
case StructElement::Code:
return POPPLER_STRUCTURE_ELEMENT_CODE;
case StructElement::Link:
return POPPLER_STRUCTURE_ELEMENT_LINK;
case StructElement::Annot:
return POPPLER_STRUCTURE_ELEMENT_ANNOT;
case StructElement::BlockQuote:
return POPPLER_STRUCTURE_ELEMENT_BLOCKQUOTE;
case StructElement::Caption:
return POPPLER_STRUCTURE_ELEMENT_CAPTION;
case StructElement::NonStruct:
return POPPLER_STRUCTURE_ELEMENT_NONSTRUCT;
case StructElement::TOC:
return POPPLER_STRUCTURE_ELEMENT_TOC;
case StructElement::TOCI:
return POPPLER_STRUCTURE_ELEMENT_TOC_ITEM;
case StructElement::Index:
return POPPLER_STRUCTURE_ELEMENT_INDEX;
case StructElement::Private:
return POPPLER_STRUCTURE_ELEMENT_PRIVATE;
case StructElement::P:
return POPPLER_STRUCTURE_ELEMENT_PARAGRAPH;
case StructElement::H:
return POPPLER_STRUCTURE_ELEMENT_HEADING;
case StructElement::H1:
return POPPLER_STRUCTURE_ELEMENT_HEADING_1;
case StructElement::H2:
return POPPLER_STRUCTURE_ELEMENT_HEADING_2;
case StructElement::H3:
return POPPLER_STRUCTURE_ELEMENT_HEADING_3;
case StructElement::H4:
return POPPLER_STRUCTURE_ELEMENT_HEADING_4;
case StructElement::H5:
return POPPLER_STRUCTURE_ELEMENT_HEADING_5;
case StructElement::H6:
return POPPLER_STRUCTURE_ELEMENT_HEADING_6;
case StructElement::L:
return POPPLER_STRUCTURE_ELEMENT_LIST;
case StructElement::LI:
return POPPLER_STRUCTURE_ELEMENT_LIST_ITEM;
case StructElement::Lbl:
return POPPLER_STRUCTURE_ELEMENT_LIST_LABEL;
case StructElement::LBody:
return POPPLER_STRUCTURE_ELEMENT_LIST_BODY;
case StructElement::Table:
return POPPLER_STRUCTURE_ELEMENT_TABLE;
case StructElement::TR:
return POPPLER_STRUCTURE_ELEMENT_TABLE_ROW;
case StructElement::TH:
return POPPLER_STRUCTURE_ELEMENT_TABLE_HEADING;
case StructElement::TD:
return POPPLER_STRUCTURE_ELEMENT_TABLE_DATA;
case StructElement::THead:
return POPPLER_STRUCTURE_ELEMENT_TABLE_HEADER;
case StructElement::TFoot:
return POPPLER_STRUCTURE_ELEMENT_TABLE_FOOTER;
case StructElement::TBody:
return POPPLER_STRUCTURE_ELEMENT_TABLE_BODY;
case StructElement::Ruby:
return POPPLER_STRUCTURE_ELEMENT_RUBY;
case StructElement::RB:
return POPPLER_STRUCTURE_ELEMENT_RUBY_BASE_TEXT;
case StructElement::RT:
return POPPLER_STRUCTURE_ELEMENT_RUBY_ANNOT_TEXT;
case StructElement::RP:
return POPPLER_STRUCTURE_ELEMENT_RUBY_PUNCTUATION;
case StructElement::Warichu:
return POPPLER_STRUCTURE_ELEMENT_WARICHU;
case StructElement::WT:
return POPPLER_STRUCTURE_ELEMENT_WARICHU_TEXT;
case StructElement::WP:
return POPPLER_STRUCTURE_ELEMENT_WARICHU_PUNCTUATION;
case StructElement::Figure:
return POPPLER_STRUCTURE_ELEMENT_FIGURE;
case StructElement::Formula:
return POPPLER_STRUCTURE_ELEMENT_FORMULA;
case StructElement::Form:
return POPPLER_STRUCTURE_ELEMENT_FORM;
/* There should never be elements of type StructElement::Unknown */
case StructElement::Unknown:
g_assert_not_reached();
}
g_assert_not_reached();
return POPPLER_STRUCTURE_ELEMENT_CONTENT;
}
template<typename EnumType>
struct EnumNameValue
{
const gchar *name;
EnumType value;
static const EnumNameValue<EnumType> values[];
static const Attribute::Type attribute_type;
};
#define ENUM_VALUES(E, A) \
template<> \
const Attribute::Type EnumNameValue<E>::attribute_type = Attribute::A; \
template<> \
const EnumNameValue<E> EnumNameValue<E>::values[] =
ENUM_VALUES(PopplerStructurePlacement, Placement) { { "Block", POPPLER_STRUCTURE_PLACEMENT_BLOCK }, { "Inline", POPPLER_STRUCTURE_PLACEMENT_INLINE }, { "Before", POPPLER_STRUCTURE_PLACEMENT_BEFORE },
{ "Start", POPPLER_STRUCTURE_PLACEMENT_START }, { "End", POPPLER_STRUCTURE_PLACEMENT_END }, {} };
ENUM_VALUES(PopplerStructureWritingMode, WritingMode) { { "LrTb", POPPLER_STRUCTURE_WRITING_MODE_LR_TB }, { "RlTb", POPPLER_STRUCTURE_WRITING_MODE_RL_TB }, { "TbRl", POPPLER_STRUCTURE_WRITING_MODE_TB_RL }, {} };
ENUM_VALUES(PopplerStructureBorderStyle, BorderStyle) { { "None", POPPLER_STRUCTURE_BORDER_STYLE_NONE }, { "Hidden", POPPLER_STRUCTURE_BORDER_STYLE_HIDDEN },
{ "Dotted", POPPLER_STRUCTURE_BORDER_STYLE_DOTTED }, { "Dashed", POPPLER_STRUCTURE_BORDER_STYLE_DASHED },
{ "Solid", POPPLER_STRUCTURE_BORDER_STYLE_SOLID }, { "Double", POPPLER_STRUCTURE_BORDER_STYLE_DOUBLE },
{ "Groove", POPPLER_STRUCTURE_BORDER_STYLE_GROOVE }, { "Inset", POPPLER_STRUCTURE_BORDER_STYLE_INSET },
{ "Outset", POPPLER_STRUCTURE_BORDER_STYLE_OUTSET }, {} };
ENUM_VALUES(PopplerStructureTextAlign,
TextAlign) { { "Start", POPPLER_STRUCTURE_TEXT_ALIGN_START }, { "Center", POPPLER_STRUCTURE_TEXT_ALIGN_CENTER }, { "End", POPPLER_STRUCTURE_TEXT_ALIGN_END }, { "Justify", POPPLER_STRUCTURE_TEXT_ALIGN_JUSTIFY }, {} };
ENUM_VALUES(PopplerStructureBlockAlign,
BlockAlign) { { "Before", POPPLER_STRUCTURE_BLOCK_ALIGN_BEFORE }, { "Middle", POPPLER_STRUCTURE_BLOCK_ALIGN_MIDDLE }, { "After", POPPLER_STRUCTURE_BLOCK_ALIGN_AFTER }, { "Justify", POPPLER_STRUCTURE_BLOCK_ALIGN_JUSTIFY }, {} };
ENUM_VALUES(PopplerStructureInlineAlign, InlineAlign) { { "Start", POPPLER_STRUCTURE_INLINE_ALIGN_START }, { "Center", POPPLER_STRUCTURE_INLINE_ALIGN_CENTER }, { "End", POPPLER_STRUCTURE_INLINE_ALIGN_END }, {} };
ENUM_VALUES(PopplerStructureTextDecoration, TextDecorationType) { { "None", POPPLER_STRUCTURE_TEXT_DECORATION_NONE },
{ "Underline", POPPLER_STRUCTURE_TEXT_DECORATION_UNDERLINE },
{ "Overline", POPPLER_STRUCTURE_TEXT_DECORATION_OVERLINE },
{ "LineThrough", POPPLER_STRUCTURE_TEXT_DECORATION_LINETHROUGH },
{} };
ENUM_VALUES(PopplerStructureRubyAlign, RubyAlign) { { "Start", POPPLER_STRUCTURE_RUBY_ALIGN_START }, { "Center", POPPLER_STRUCTURE_RUBY_ALIGN_CENTER }, { "End", POPPLER_STRUCTURE_RUBY_ALIGN_END },
{ "Justify", POPPLER_STRUCTURE_RUBY_ALIGN_JUSTIFY }, { "Distribute", POPPLER_STRUCTURE_RUBY_ALIGN_DISTRIBUTE }, {} };
ENUM_VALUES(PopplerStructureRubyPosition, RubyPosition) {
{ "Before", POPPLER_STRUCTURE_RUBY_POSITION_BEFORE }, { "After", POPPLER_STRUCTURE_RUBY_POSITION_AFTER }, { "Warichu", POPPLER_STRUCTURE_RUBY_POSITION_WARICHU }, { "Inline", POPPLER_STRUCTURE_RUBY_POSITION_INLINE }, {}
};
ENUM_VALUES(PopplerStructureGlyphOrientation, GlyphOrientationVertical) { { "Auto", POPPLER_STRUCTURE_GLYPH_ORIENTATION_AUTO }, { "90", POPPLER_STRUCTURE_GLYPH_ORIENTATION_90 },
{ "180", POPPLER_STRUCTURE_GLYPH_ORIENTATION_180 }, { "270", POPPLER_STRUCTURE_GLYPH_ORIENTATION_270 },
{ "360", POPPLER_STRUCTURE_GLYPH_ORIENTATION_0 }, { "-90", POPPLER_STRUCTURE_GLYPH_ORIENTATION_270 },
{ "-180", POPPLER_STRUCTURE_GLYPH_ORIENTATION_180 }, {} };
ENUM_VALUES(PopplerStructureListNumbering, ListNumbering) { { "None", POPPLER_STRUCTURE_LIST_NUMBERING_NONE },
{ "Disc", POPPLER_STRUCTURE_LIST_NUMBERING_DISC },
{ "Circle", POPPLER_STRUCTURE_LIST_NUMBERING_CIRCLE },
{ "Square", POPPLER_STRUCTURE_LIST_NUMBERING_SQUARE },
{ "Decimal", POPPLER_STRUCTURE_LIST_NUMBERING_DECIMAL },
{ "UpperRoman", POPPLER_STRUCTURE_LIST_NUMBERING_UPPER_ROMAN },
{ "LowerRoman", POPPLER_STRUCTURE_LIST_NUMBERING_LOWER_ROMAN },
{ "UpperAlpha", POPPLER_STRUCTURE_LIST_NUMBERING_UPPER_ALPHA },
{ "LowerAlpha", POPPLER_STRUCTURE_LIST_NUMBERING_LOWER_ALPHA },
{} };
ENUM_VALUES(PopplerStructureFormRole,
Role) { { "rb", POPPLER_STRUCTURE_FORM_ROLE_RADIO_BUTTON }, { "cb", POPPLER_STRUCTURE_FORM_ROLE_CHECKBOX }, { "pb", POPPLER_STRUCTURE_FORM_ROLE_PUSH_BUTTON }, { "tv", POPPLER_STRUCTURE_FORM_ROLE_TEXT_VALUE }, {} };
ENUM_VALUES(PopplerStructureFormState, checked) { { "on", POPPLER_STRUCTURE_FORM_STATE_ON }, { "off", POPPLER_STRUCTURE_FORM_STATE_OFF }, { "neutral", POPPLER_STRUCTURE_FORM_STATE_NEUTRAL }, {} };
ENUM_VALUES(PopplerStructureTableScope, Scope) { { "Row", POPPLER_STRUCTURE_TABLE_SCOPE_ROW }, { "Column", POPPLER_STRUCTURE_TABLE_SCOPE_COLUMN }, { "Both", POPPLER_STRUCTURE_TABLE_SCOPE_BOTH }, {} };
#undef ENUM_VALUES
template<typename EnumType>
static EnumType name_to_enum(const Object *name_value)
{
/*
* Non-NULL names must always be valid because Poppler
* discards the invalid attributes when parsing them.
*/
g_assert(name_value != nullptr);
for (const EnumNameValue<EnumType> *item = EnumNameValue<EnumType>::values; item->name; item++) {
if (name_value->isName(item->name)) {
return item->value;
}
}
g_assert_not_reached();
return static_cast<EnumType>(-1);
}
template<typename EnumType>
static EnumType attr_to_enum(PopplerStructureElement *poppler_structure_element)
{
const Attribute *attr = poppler_structure_element->elem->findAttribute(EnumNameValue<EnumType>::attribute_type, true);
return name_to_enum<EnumType>((attr != nullptr) ? attr->getValue() : Attribute::getDefaultValue(EnumNameValue<EnumType>::attribute_type));
}
static inline const Object *attr_value_or_default(PopplerStructureElement *poppler_structure_element, Attribute::Type attribute_type)
{
const Attribute *attr = poppler_structure_element->elem->findAttribute(attribute_type, true);
return attr ? attr->getValue() : Attribute::getDefaultValue(attribute_type);
}
/**
* poppler_structure_element_get_page:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the page number in which the element is contained.
*
* Return value: Number of the page that contains the element, of
* <code>-1</code> if not defined.
*
* Since: 0.26
*/
gint poppler_structure_element_get_page(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), -1);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, -1);
Ref ref;
if (poppler_structure_element->elem->getPageRef(ref)) {
return poppler_structure_element->document->doc->findPage(ref) - 1;
}
return -1;
}
/**
* poppler_structure_element_is_content:
* @poppler_structure_element: A #PopplerStructureElement
*
* Checks whether an element is actual document content.
*
* Return value: %TRUE if the element is content, or %FALSE otherwise.
*
* Since: 0.26
*/
gboolean poppler_structure_element_is_content(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), FALSE);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, FALSE);
return poppler_structure_element->elem->isContent();
}
/**
* poppler_structure_element_is_inline:
* @poppler_structure_element: A #PopplerStructureElement
*
* Checks whether an element is an inline element.
*
* Return value: %TRUE if the element is an inline element, or %FALSE otherwise.
*
* Since: 0.26
*/
gboolean poppler_structure_element_is_inline(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), FALSE);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, FALSE);
return poppler_structure_element->elem->isInline();
}
/**
* poppler_structure_element_is_block:
* @poppler_structure_element: A #PopplerStructureElement
*
* Checks whether an element is a block element.
*
* Return value: %TRUE if the element is a block element, or %FALSE otherwise.
*
* Since: 0.26
*/
gboolean poppler_structure_element_is_block(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), FALSE);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, FALSE);
return poppler_structure_element->elem->isBlock();
}
/**
* poppler_structure_element_is_grouping:
* @poppler_structure_element: A #PopplerStructureElement
*
* Checks whether an element is a grouping element.
*
* Return value: %TRUE if the element is a grouping element, %FALSE
* otherwise.
*
* Since: 0.26
*/
gboolean poppler_structure_element_is_grouping(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), FALSE);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, FALSE);
return poppler_structure_element->elem->isGrouping();
}
/**
* poppler_structure_element_get_id:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the identifier of an element.
*
* Return value: (transfer full): The identifier of the element (if
* defined), or %NULL.
*
* Since: 0.26
*/
gchar *poppler_structure_element_get_id(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), NULL);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, NULL);
const GooString *string = poppler_structure_element->elem->getID();
return string ? _poppler_goo_string_to_utf8(string) : nullptr;
}
/**
* poppler_structure_element_get_title:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the title of an element.
*
* Return value: (transfer full): The title of the element, or %NULL.
*
* Since: 0.26
*/
gchar *poppler_structure_element_get_title(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), NULL);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, NULL);
const GooString *string = poppler_structure_element->elem->getTitle();
return string ? _poppler_goo_string_to_utf8(string) : nullptr;
}
/**
* poppler_structure_element_get_abbreviation:
* @poppler_structure_element: A #PopplerStructureElement
*
* Acronyms and abbreviations contained in elements of type
* #POPPLER_STRUCTURE_ELEMENT_SPAN may have an associated expanded
* text form, which can be retrieved using this function.
*
* Return value: (transfer full): Text of the expanded abbreviation if the
* element text is an abbreviation or acrony, %NULL if not.
*
* Since: 0.26
*/
gchar *poppler_structure_element_get_abbreviation(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), NULL);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, NULL);
if (poppler_structure_element->elem->getType() != StructElement::Span) {
return nullptr;
}
const GooString *string = poppler_structure_element->elem->getExpandedAbbr();
return string ? _poppler_goo_string_to_utf8(string) : nullptr;
}
/**
* poppler_structure_element_get_language:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the language and country code for the content in an element,
* in two-letter ISO format, e.g. <code>en_ES</code>, or %NULL if not
* defined.
*
* Return value: (transfer full): language and country code, or %NULL.
*
* Since: 0.26
*/
gchar *poppler_structure_element_get_language(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), NULL);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, NULL);
const GooString *string = poppler_structure_element->elem->getLanguage();
return string ? _poppler_goo_string_to_utf8(string) : nullptr;
}
/**
* poppler_structure_element_get_alt_text:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the “alternate” text representation of the element (and its child
* elements). This is mostly used for non-text elements like images and
* figures, to specify a textual description of the element.
*
* Note that for elements containing proper text, the function
* poppler_structure_element_get_text() must be used instead.
*
* Return value: (transfer full): The alternate text representation for the
* element, or %NULL if not defined.
*
* Since: 0.26
*/
gchar *poppler_structure_element_get_alt_text(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), NULL);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, NULL);
const GooString *string = poppler_structure_element->elem->getAltText();
return string ? _poppler_goo_string_to_utf8(string) : nullptr;
}
/**
* poppler_structure_element_get_actual_text:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the actual text enclosed by the element (and its child elements).
* The actual text is mostly used for non-text elements like images and
* figures which <emphasis>do</emphasis> have the graphical appearance of text, like
* a logo. For those the actual text is the equivalent text to those
* graphical elements which look like text when rendered.
*
* Note that for elements containing proper text, the function
* poppler_structure_element_get_text() must be used instead.
*
* Return value: (transfer full): The actual text for the element, or %NULL
* if not defined.
*
* Since: 0.26
*/
gchar *poppler_structure_element_get_actual_text(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), NULL);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, NULL);
const GooString *string = poppler_structure_element->elem->getActualText();
return string ? _poppler_goo_string_to_utf8(string) : nullptr;
}
/**
* poppler_structure_element_get_text:
* @poppler_structure_element: A #PopplerStructureElement
* @flags: A #PopplerStructureGetTextFlags value, or
* %POPPLER_STRUCTURE_GET_TEXT_NONE to disable all the flags.
*
* Obtains the text enclosed by an element, or the text enclosed by the
* elements in the subtree (including the element itself).
*
* Return value: (transfer full): A string.
*
* Since: 0.26
*/
gchar *poppler_structure_element_get_text(PopplerStructureElement *poppler_structure_element, PopplerStructureGetTextFlags flags)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), NULL);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, NULL);
GooString *string = poppler_structure_element->elem->getText(flags & POPPLER_STRUCTURE_GET_TEXT_RECURSIVE);
gchar *result = string ? _poppler_goo_string_to_utf8(string) : nullptr;
delete string;
return result;
}
struct _PopplerStructureElementIter
{
PopplerDocument *document;
union {
const StructElement *elem;
const StructTreeRoot *root;
};
gboolean is_root;
unsigned index;
};
G_DEFINE_BOXED_TYPE(PopplerStructureElementIter, poppler_structure_element_iter, poppler_structure_element_iter_copy, poppler_structure_element_iter_free)
/**
* poppler_structure_element_iter_copy:
* @iter: a #PopplerStructureElementIter
*
* Creates a new #PopplerStructureElementIter as a copy of @iter. The
* returned value must be freed with poppler_structure_element_iter_free().
*
* Return value: (transfer full): a new #PopplerStructureElementIter
*
* Since: 0.26
*/
PopplerStructureElementIter *poppler_structure_element_iter_copy(PopplerStructureElementIter *iter)
{
PopplerStructureElementIter *new_iter;
g_return_val_if_fail(iter != nullptr, NULL);
new_iter = g_slice_dup(PopplerStructureElementIter, iter);
new_iter->document = (PopplerDocument *)g_object_ref(new_iter->document);
return new_iter;
}
/**
* poppler_structure_element_iter_free:
* @iter: a #PopplerStructureElementIter
*
* Frees @iter.
*
* Since: 0.26
*/
void poppler_structure_element_iter_free(PopplerStructureElementIter *iter)
{
if (G_UNLIKELY(iter == nullptr)) {
return;
}
g_object_unref(iter->document);
g_slice_free(PopplerStructureElementIter, iter);
}
/**
* poppler_structure_element_iter_new:
* @poppler_document: a #PopplerDocument.
*
* Returns the root #PopplerStructureElementIter for @document, or %NULL. The
* returned value must be freed with poppler_structure_element_iter_free().
*
* Documents may have an associated structure tree —mostly, Tagged-PDF
* compliant documents— which can be used to obtain information about
* the document structure and its contents. Each node in the tree contains
* a #PopplerStructureElement.
*
* Here is a simple example that walks the whole tree:
*
* <informalexample><programlisting>
* static void
* walk_structure (PopplerStructureElementIter *iter)
* {
* do {
* /<!-- -->* Get the element and do something with it *<!-- -->/
* PopplerStructureElementIter *child = poppler_structure_element_iter_get_child (iter);
* if (child)
* walk_structure (child);
* poppler_structure_element_iter_free (child);
* } while (poppler_structure_element_iter_next (iter));
* }
* ...
* {
* iter = poppler_structure_element_iter_new (document);
* walk_structure (iter);
* poppler_structure_element_iter_free (iter);
* }
* </programlisting></informalexample>
*
* Return value: (transfer full): a new #PopplerStructureElementIter, or %NULL if document
* doesn't have structure tree.
*
* Since: 0.26
*/
PopplerStructureElementIter *poppler_structure_element_iter_new(PopplerDocument *poppler_document)
{
PopplerStructureElementIter *iter;
g_return_val_if_fail(POPPLER_IS_DOCUMENT(poppler_document), NULL);
const StructTreeRoot *root = poppler_document->doc->getStructTreeRoot();
if (root == nullptr) {
return nullptr;
}
if (root->getNumChildren() == 0) {
return nullptr;
}
iter = g_slice_new0(PopplerStructureElementIter);
iter->document = (PopplerDocument *)g_object_ref(poppler_document);
iter->is_root = TRUE;
iter->root = root;
return iter;
}
/**
* poppler_structure_element_iter_next:
* @iter: a #PopplerStructureElementIter
*
* Sets @iter to point to the next structure element at the current level
* of the tree, if valid. See poppler_structure_element_iter_new() for more
* information.
*
* Return value: %TRUE, if @iter was set to the next structure element
*
* Since: 0.26
*/
gboolean poppler_structure_element_iter_next(PopplerStructureElementIter *iter)
{
unsigned elements;
g_return_val_if_fail(iter != nullptr, FALSE);
elements = iter->is_root ? iter->root->getNumChildren() : iter->elem->getNumChildren();
return ++iter->index < elements;
}
/**
* poppler_structure_element_iter_get_element:
* @iter: a #PopplerStructureElementIter
*
* Returns the #PopplerStructureElementIter associated with @iter.
*
* Return value: (transfer full): a new #PopplerStructureElementIter
*
* Since: 0.26
*/
PopplerStructureElement *poppler_structure_element_iter_get_element(PopplerStructureElementIter *iter)
{
g_return_val_if_fail(iter != nullptr, NULL);
const StructElement *elem = iter->is_root ? iter->root->getChild(iter->index) : iter->elem->getChild(iter->index);
return _poppler_structure_element_new(iter->document, elem);
}
/**
* poppler_structure_element_iter_get_child:
* @parent: a #PopplerStructureElementIter
*
* Returns a new iterator to the children elements of the
* #PopplerStructureElement associated with @iter. The returned value must
* be freed with poppler_structure_element_iter_free().
*
* Return value: a new #PopplerStructureElementIter
*
* Since: 0.26
*/
PopplerStructureElementIter *poppler_structure_element_iter_get_child(PopplerStructureElementIter *parent)
{
const StructElement *elem;
g_return_val_if_fail(parent != nullptr, NULL);
elem = parent->is_root ? parent->root->getChild(parent->index) : parent->elem->getChild(parent->index);
if (elem->getNumChildren() > 0) {
PopplerStructureElementIter *child = g_slice_new0(PopplerStructureElementIter);
child->document = (PopplerDocument *)g_object_ref(parent->document);
child->elem = elem;
return child;
}
return nullptr;
}
struct _PopplerTextSpan
{
gchar *text;
gchar *font_name;
guint flags;
PopplerColor color;
};
G_DEFINE_BOXED_TYPE(PopplerTextSpan, poppler_text_span, poppler_text_span_copy, poppler_text_span_free)
enum
{
POPPLER_TEXT_SPAN_FIXED_WIDTH = (1 << 0),
POPPLER_TEXT_SPAN_SERIF = (1 << 1),
POPPLER_TEXT_SPAN_ITALIC = (1 << 2),
POPPLER_TEXT_SPAN_BOLD = (1 << 3),
};
static PopplerTextSpan *text_span_poppler_text_span(const TextSpan &span)
{
PopplerTextSpan *new_span = g_slice_new0(PopplerTextSpan);
if (GooString *text = span.getText()) {
new_span->text = _poppler_goo_string_to_utf8(text);
}
new_span->color.red = colToDbl(span.getColor().r) * 65535;
new_span->color.green = colToDbl(span.getColor().g) * 65535;
new_span->color.blue = colToDbl(span.getColor().b) * 65535;
if (span.getFont()) {
// GfxFont sometimes does not have a family name but there
// is always a font name that can be used as fallback.
const GooString *font_name = span.getFont()->getFamily();
if (font_name) {
new_span->font_name = _poppler_goo_string_to_utf8(font_name);
} else if (span.getFont()->getName()) {
const GooString aux(*span.getFont()->getName());
new_span->font_name = _poppler_goo_string_to_utf8(&aux);
} else {
new_span->font_name = nullptr;
}
if (span.getFont()->isFixedWidth()) {
new_span->flags |= POPPLER_TEXT_SPAN_FIXED_WIDTH;
}
if (span.getFont()->isSerif()) {
new_span->flags |= POPPLER_TEXT_SPAN_SERIF;
}
if (span.getFont()->isItalic()) {
new_span->flags |= POPPLER_TEXT_SPAN_ITALIC;
}
if (span.getFont()->isBold()) {
new_span->flags |= POPPLER_TEXT_SPAN_BOLD;
}
/* isBold() can return false for some fonts whose weight is heavy */
switch (span.getFont()->getWeight()) {
case GfxFont::W500:
case GfxFont::W600:
case GfxFont::W700:
case GfxFont::W800:
case GfxFont::W900:
new_span->flags |= POPPLER_TEXT_SPAN_BOLD;
default:
break;
}
}
return new_span;
}
/**
* poppler_text_span_copy:
* @poppler_text_span: a #PopplerTextSpan
*
* Makes a copy of a text span.
*
* Return value: (transfer full): A new #PopplerTextSpan
*
* Since: 0.26
*/
PopplerTextSpan *poppler_text_span_copy(PopplerTextSpan *poppler_text_span)
{
PopplerTextSpan *new_span;
g_return_val_if_fail(poppler_text_span != nullptr, NULL);
new_span = g_slice_dup(PopplerTextSpan, poppler_text_span);
new_span->text = g_strdup(poppler_text_span->text);
if (poppler_text_span->font_name) {
new_span->font_name = g_strdup(poppler_text_span->font_name);
}
return new_span;
}
/**
* poppler_text_span_free:
* @poppler_text_span: A #PopplerTextSpan
*
* Frees a text span.
*
* Since: 0.26
*/
void poppler_text_span_free(PopplerTextSpan *poppler_text_span)
{
if (G_UNLIKELY(poppler_text_span == nullptr)) {
return;
}
g_free(poppler_text_span->text);
g_free(poppler_text_span->font_name);
g_slice_free(PopplerTextSpan, poppler_text_span);
}
/**
* poppler_text_span_is_fixed_width_font:
* @poppler_text_span: a #PopplerTextSpan
*
* Check wether a text span is meant to be rendered using a fixed-width font.
*
* Return value: Whether the span uses a fixed-width font.
*
* Since: 0.26
*/
gboolean poppler_text_span_is_fixed_width_font(PopplerTextSpan *poppler_text_span)
{
g_return_val_if_fail(poppler_text_span != nullptr, FALSE);
return (poppler_text_span->flags & POPPLER_TEXT_SPAN_FIXED_WIDTH);
}
/**
* poppler_text_span_is_serif_font:
* @poppler_text_span: a #PopplerTextSpan
*
* Check whether a text span is meant to be rendered using a serif font.
*
* Return value: Whether the span uses a serif font.
*
* Since: 0.26
*/
gboolean poppler_text_span_is_serif_font(PopplerTextSpan *poppler_text_span)
{
g_return_val_if_fail(poppler_text_span != nullptr, FALSE);
return (poppler_text_span->flags & POPPLER_TEXT_SPAN_SERIF);
}
/**
* poppler_text_span_is_bold_font:
* @poppler_text_span: a #PopplerTextSpan
*
* Check whether a text span is meant to be rendered using a bold font.
*
* Return value: Whether the span uses bold font.
*
* Since: 0.26
*/
gboolean poppler_text_span_is_bold_font(PopplerTextSpan *poppler_text_span)
{
g_return_val_if_fail(poppler_text_span != nullptr, FALSE);
return (poppler_text_span->flags & POPPLER_TEXT_SPAN_BOLD);
}
/**
* poppler_text_span_get_color:
* @poppler_text_span: a #PopplerTextSpan
* @color: (out): a return location for a #PopplerColor
*
* Obtains the color in which the text is to be rendered.
*
* Since: 0.26
*/
void poppler_text_span_get_color(PopplerTextSpan *poppler_text_span, PopplerColor *color)
{
g_return_if_fail(poppler_text_span != nullptr);
g_return_if_fail(color != nullptr);
*color = poppler_text_span->color;
}
/**
* poppler_text_span_get_text:
* @poppler_text_span: a #PopplerTextSpan
*
* Obtains the text contained in the span.
*
* Return value: (transfer none): A string.
*
* Since: 0.26
*/
const gchar *poppler_text_span_get_text(PopplerTextSpan *poppler_text_span)
{
g_return_val_if_fail(poppler_text_span != nullptr, NULL);
return poppler_text_span->text;
}
/**
* poppler_text_span_get_font_name:
* @poppler_text_span: a #PopplerTextSpan
*
* Obtains the name of the font in which the span is to be rendered.
*
* Return value: (transfer none): A string containing the font name, or
* %NULL if a font is not defined.
*
* Since: 0.26
*/
const gchar *poppler_text_span_get_font_name(PopplerTextSpan *poppler_text_span)
{
g_return_val_if_fail(poppler_text_span != nullptr, NULL);
return poppler_text_span->font_name;
}
/**
* poppler_structure_element_get_text_spans:
* @poppler_structure_element: A #PopplerStructureElement
* @n_text_spans: (out): A pointer to the location where the number of elements in
* the returned array will be stored.
*
* Obtains the text enclosed by an element, as an array of #PopplerTextSpan
* structures. Each item in the list is a piece of text which share the same
* attributes, plus its attributes. The following example shows how to
* obtain and free the text spans of an element:
*
* <informalexample><programlisting>
* guint i, n_spans;
* PopplerTextSpan **text_spans =
* poppler_structure_element_get_text_spans (element, &n_spans);
* /<!-- -->* Use the text spans *<!-- -->/
* for (i = 0; i < n_spans; i++)
* poppler_text_span_free (text_spans[i]);
* g_free (text_spans);
* </programlisting></informalexample>
*
* Return value: (transfer full) (array length=n_text_spans) (element-type PopplerTextSpan):
* An array of #PopplerTextSpan elements.
*
* Since: 0.26
*/
PopplerTextSpan **poppler_structure_element_get_text_spans(PopplerStructureElement *poppler_structure_element, guint *n_text_spans)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), NULL);
g_return_val_if_fail(n_text_spans != nullptr, NULL);
g_return_val_if_fail(poppler_structure_element->elem != nullptr, NULL);
if (!poppler_structure_element->elem->isContent()) {
return nullptr;
}
const TextSpanArray spans(poppler_structure_element->elem->getTextSpans());
PopplerTextSpan **text_spans = g_new0(PopplerTextSpan *, spans.size());
size_t i = 0;
for (const TextSpan &s : spans) {
text_spans[i++] = text_span_poppler_text_span(s);
}
*n_text_spans = spans.size();
return text_spans;
}
/* General Layout Attributes */
/**
* poppler_structure_element_get_placement:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the placement type of the structure element.
*
* Return value: A #PopplerStructurePlacement value.
*
* Since: 0.26
*/
PopplerStructurePlacement poppler_structure_element_get_placement(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), EnumNameValue<PopplerStructurePlacement>::values[0].value);
return attr_to_enum<PopplerStructurePlacement>(poppler_structure_element);
}
/**
* poppler_structure_element_get_writing_mode:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the writing mode (writing direction) of the content associated
* with a structure element.
*
* Return value: A #PopplerStructureWritingMode value.
*
* Since: 0.26
*/
PopplerStructureWritingMode poppler_structure_element_get_writing_mode(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), EnumNameValue<PopplerStructureWritingMode>::values[0].value);
return attr_to_enum<PopplerStructureWritingMode>(poppler_structure_element);
}
static void convert_border_style(const Object *object, PopplerStructureBorderStyle *values)
{
g_assert(object != nullptr);
g_assert(values != nullptr);
if (object->isArray()) {
g_assert(object->arrayGetLength() == 4);
for (guint i = 0; i < 4; i++) {
Object item = object->arrayGet(i);
values[i] = name_to_enum<PopplerStructureBorderStyle>(&item);
}
} else {
values[0] = values[1] = values[2] = values[3] = name_to_enum<PopplerStructureBorderStyle>(object);
}
}
/**
* poppler_structure_element_get_border_style:
* @poppler_structure_element: A #PopplerStructureElement
* @border_styles: (out) (array fixed-size=4) (element-type PopplerStructureBorderStyle):
* An array of four #PopplerStructureBorderStyle elements.
*
* Obtains the border style of a structure element. The result values
* are in before-after-start-end ordering. For example, using Western
* left-to-right writing, that is top-bottom-left-right.
*
* Since: 0.26
*/
void poppler_structure_element_get_border_style(PopplerStructureElement *poppler_structure_element, PopplerStructureBorderStyle *border_styles)
{
g_return_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element));
g_return_if_fail(border_styles != nullptr);
convert_border_style(attr_value_or_default(poppler_structure_element, Attribute::BorderStyle), border_styles);
}
static inline void convert_doubles_array(const Object *object, gdouble **values, guint *n_values)
{
g_assert(object->isArray());
g_assert(n_values != nullptr);
g_assert(values != nullptr);
*n_values = object->arrayGetLength();
gdouble *doubles = g_new(gdouble, *n_values);
for (guint i = 0; i < *n_values; i++) {
doubles[i] = object->arrayGet(i).getNum();
}
values = &doubles;
}
static inline void convert_color(const Object *object, PopplerColor *color)
{
g_assert(color != nullptr);
g_assert(object->isArray() && object->arrayGetLength() != 3);
color->red = object->arrayGet(0).getNum() * 65535;
color->green = object->arrayGet(1).getNum() * 65535;
color->blue = object->arrayGet(2).getNum() * 65535;
}
/**
* poppler_structure_element_get_color:
* @poppler_structure_element: A #PopplerStructureElement
* @color: (out): A #PopplerColor.
*
* Obtains the color of the content contained in the element.
* If this attribute is not specified, the color for this element shall
* be the current text fill color in effect at the start of its associated content.
*
* Return value: %TRUE if a color is defined for the element,
* %FALSE otherwise.
*
* Since: 0.26
*/
gboolean poppler_structure_element_get_color(PopplerStructureElement *poppler_structure_element, PopplerColor *color)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), FALSE);
g_return_val_if_fail(color != nullptr, FALSE);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::Color);
if (value == nullptr) {
return FALSE;
}
convert_color(value, color);
return TRUE;
}
/**
* poppler_structure_element_get_background_color:
* @poppler_structure_element: A #PopplerStructureElement
* @color: (out): A #PopplerColor.
*
* Obtains the background color of the element. If this attribute is
* not specified, the element shall be treated as if it were transparent.
*
* Return value: %TRUE if a color is defined for the element,
* %FALSE otherwise.
*
* Since: 0.26
*/
gboolean poppler_structure_element_get_background_color(PopplerStructureElement *poppler_structure_element, PopplerColor *color)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), FALSE);
g_return_val_if_fail(color != nullptr, FALSE);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::BackgroundColor);
if (value == nullptr) {
return FALSE;
}
convert_color(value, color);
return TRUE;
}
/**
* poppler_structure_element_get_border_color:
* @poppler_structure_element: A #PopplerStructureElement
* @colors: (out) (array fixed-size=4) (element-type PopplerColor): An array
* of four #PopplerColor.
*
* Obtains the color of border around the element. The result values
* are in before-after-start-end ordering (for the typical Western
* left-to-right writing, that is top-bottom-left-right).
* If this attribute is not specified, the border color for this element shall
* be the current text fill color in effect at the start of its associated
* content.
*
* Return value: %TRUE if a color is defined for the element,
* %FALSE otherwise.
*
* Since: 0.26
*/
gboolean poppler_structure_element_get_border_color(PopplerStructureElement *poppler_structure_element, PopplerColor *colors)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), FALSE);
g_return_val_if_fail(colors != nullptr, FALSE);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::BorderColor);
if (value == nullptr) {
return FALSE;
}
g_assert(value->isArray());
if (value->arrayGetLength() == 4) {
// One color per side.
for (guint i = 0; i < 4; i++) {
Object item = value->arrayGet(i);
convert_color(&item, &colors[i]);
}
} else {
// Same color in all sides.
g_assert(value->arrayGetLength() == 3);
convert_color(value, &colors[0]);
colors[1] = colors[2] = colors[3] = colors[0];
}
return TRUE;
}
static inline void convert_double_or_4_doubles(const Object *object, gdouble *value)
{
g_assert(object != nullptr);
if (object->isArray()) {
g_assert(object->arrayGetLength() == 4);
for (guint i = 0; i < 4; i++) {
value[i] = object->arrayGet(i).getNum();
}
} else {
g_assert(object->isNum());
value[0] = value[1] = value[2] = value[3] = object->getNum();
}
}
/**
* poppler_structure_element_get_border_thickness:
* @poppler_structure_element: A #PopplerStructureElement
* @border_thicknesses: (out) (array fixed-size=4) (element-type gdouble):
* Array with the four values of border thicknesses.
*
* Obtains the thickness of the border of an element. The result values
* are in before-after-start-end ordering (for the typical Western
* left-to-right writing, that is top-bottom-left-right).
* A value of 0 indicates that the border shall not be drawn.
*
* Return value: %TRUE if the border thickness attribute is defined for
* the element, %FALSE otherwise.
*
* Since: 0.26
*/
gboolean poppler_structure_element_get_border_thickness(PopplerStructureElement *poppler_structure_element, gdouble *border_thicknesses)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), FALSE);
g_return_val_if_fail(border_thicknesses != nullptr, FALSE);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::BorderThickness);
if (value == nullptr) {
return FALSE;
}
convert_double_or_4_doubles(value, border_thicknesses);
return TRUE;
}
/**
* poppler_structure_element_get_padding:
* @poppler_structure_element: A #PopplerStructureElement
* @paddings: (out) (array fixed-size=4) (element-type gdouble):
* Padding for the four sides of the element.
*
* Obtains the padding of an element (space around it). The result
* values are in before-after-start-end ordering. For example using
* Western left-to-right writing, that is top-bottom-left-right.
*
* Since: 0.26
*/
void poppler_structure_element_get_padding(PopplerStructureElement *poppler_structure_element, gdouble *paddings)
{
g_return_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element));
g_return_if_fail(paddings != nullptr);
convert_double_or_4_doubles(attr_value_or_default(poppler_structure_element, Attribute::Padding), paddings);
}
/* Layout Attributes for block-level structure elements */
/**
* poppler_structure_element_get_space_before:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the amount of empty space before the block-level structure element.
*
* Return value: A positive value.
*
* Since: 0.26
*/
gdouble poppler_structure_element_get_space_before(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), NAN);
return attr_value_or_default(poppler_structure_element, Attribute::SpaceBefore)->getNum();
}
/**
* poppler_structure_element_get_space_after:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the amount of empty space after the block-level structure element.
*
* Return value: A positive value.
*
* Since: 0.26
*/
gdouble poppler_structure_element_get_space_after(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), NAN);
return attr_value_or_default(poppler_structure_element, Attribute::SpaceAfter)->getNum();
}
/**
* poppler_structure_element_get_start_indent:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the amount of indentation at the beginning of the block-level structure element.
*
* Return value: A numeric value.
*
* Since: 0.26
*/
gdouble poppler_structure_element_get_start_indent(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), NAN);
return attr_value_or_default(poppler_structure_element, Attribute::StartIndent)->getNum();
}
/**
* poppler_structure_element_get_end_indent:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the amount of indentation at the end of the block-level structure element.
*
* Return value: A numeric value.
*
* Since: 0.26
*/
gdouble poppler_structure_element_get_end_indent(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), NAN);
return attr_value_or_default(poppler_structure_element, Attribute::EndIndent)->getNum();
}
/**
* poppler_structure_element_get_text_indent:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the amount of indentation of the text contained in the block-level structure element.
*
* Return value: A numeric value.
*
* Since: 0.26
*/
gdouble poppler_structure_element_get_text_indent(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), NAN);
return attr_value_or_default(poppler_structure_element, Attribute::TextIndent)->getNum();
}
/**
* poppler_structure_element_get_text_align:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the text alignment mode of the text contained into a
* block-level structure element.
*
* Return value: A #PopplerStructureTextAlign value.
*
* Since: 0.26
*/
PopplerStructureTextAlign poppler_structure_element_get_text_align(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), EnumNameValue<PopplerStructureTextAlign>::values[0].value);
return attr_to_enum<PopplerStructureTextAlign>(poppler_structure_element);
}
/**
* poppler_structure_element_get_bounding_box:
* @poppler_structure_element: A #PopplerStructureElement
* @bounding_box: (out): A #PopplerRectangle.
*
* Obtains the size of the bounding box of a block-level structure element.
*
* Return value: %TRUE if a bounding box is defined for the element,
* %FALSE otherwise.
*
* Since: 0.26
*/
gboolean poppler_structure_element_get_bounding_box(PopplerStructureElement *poppler_structure_element, PopplerRectangle *bounding_box)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), FALSE);
g_return_val_if_fail(bounding_box != nullptr, FALSE);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::BBox);
if (value == nullptr) {
return FALSE;
}
gdouble dimensions[4];
convert_double_or_4_doubles(value, dimensions);
bounding_box->x1 = dimensions[0];
bounding_box->y1 = dimensions[1];
bounding_box->x2 = dimensions[2];
bounding_box->y2 = dimensions[3];
return TRUE;
}
/**
* poppler_structure_element_get_width:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the width of the block-level structure element. Note that for elements which do
* not specify a width, it has to be calculated, and in this case -1 is returned.
*
* Return value: A positive value if a width is defined, or -1
* if the width is to be calculated automatically.
*
* Since: 0.26
*/
gdouble poppler_structure_element_get_width(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), NAN);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::Width);
return value->isName("Auto") ? -1.0 : value->getNum();
}
/**
* poppler_structure_element_get_height:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the height of the block-level structure element. Note that for elements which do
* not specify a height, it has to be calculated, and in this case -1 is returned.
*
* Return value: A positive value if a width is defined, or -1
* if the height is to be calculated automatically.
*
* Since: 0.26
*/
gdouble poppler_structure_element_get_height(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), NAN);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::Height);
return value->isName("Auto") ? -1.0 : value->getNum();
}
/**
* poppler_structure_element_get_block_align:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the block-alignment mode of the block-level structure element.
*
* Return value: A #PopplerStructureBlockAlign value.
*
* Since: 0.26
*/
PopplerStructureBlockAlign poppler_structure_element_get_block_align(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), EnumNameValue<PopplerStructureBlockAlign>::values[0].value);
return attr_to_enum<PopplerStructureBlockAlign>(poppler_structure_element);
}
/**
* poppler_structure_element_get_inline_align:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the inline-alignment mode of the block-level structure element.
*
* Return value: A #PopplerStructureInlineAlign value.
*
* Since: 0.26
*/
PopplerStructureInlineAlign poppler_structure_element_get_inline_align(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_block(poppler_structure_element), EnumNameValue<PopplerStructureInlineAlign>::values[0].value);
return attr_to_enum<PopplerStructureInlineAlign>(poppler_structure_element);
}
/**
* poppler_structure_element_get_table_border_style:
* @poppler_structure_element: A #PopplerStructureElement
* @border_styles: (out) (array fixed-size=4) (element-type PopplerStructureBorderStyle):
* An array of four #PopplerStructureBorderStyle elements.
*
* Obtains the table cell border style of a block-level structure element. The result values
* are in before-after-start-end ordering. For example, using Western
* left-to-right writing, that is top-bottom-left-right.
*
* Since: 0.26
*/
void poppler_structure_element_get_table_border_style(PopplerStructureElement *poppler_structure_element, PopplerStructureBorderStyle *border_styles)
{
g_return_if_fail(poppler_structure_element_is_block(poppler_structure_element));
g_return_if_fail(border_styles != nullptr);
convert_border_style(attr_value_or_default(poppler_structure_element, Attribute::TBorderStyle), border_styles);
}
/**
* poppler_structure_element_get_table_padding:
* @poppler_structure_element: A #PopplerStructureElement
* @paddings: (out) (array fixed-size=4) (element-type gdouble):
* Padding for the four sides of the element.
*
* Obtains the padding between the table cell’s content rectangle and the
* surrounding border of a block-level structure element. The result
* values are in before-after-start-end ordering (for the typical
* Western left-to-right writing, that is top-bottom-left-right).
*
* Since: 0.26
*/
void poppler_structure_element_get_table_padding(PopplerStructureElement *poppler_structure_element, gdouble *paddings)
{
g_return_if_fail(poppler_structure_element_is_block(poppler_structure_element));
g_return_if_fail(paddings != nullptr);
convert_double_or_4_doubles(attr_value_or_default(poppler_structure_element, Attribute::TPadding), paddings);
}
/* Layout Attributes for inline-level structure elements */
/**
* poppler_structure_element_get_baseline_shift:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains how much the text contained in the inline-level structure element should be shifted,
* measuring from the baseline of the glyphs.
*
* Return value: A numeric value.
*
* Since: 0.26
*/
gdouble poppler_structure_element_get_baseline_shift(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_inline(poppler_structure_element), NAN);
return attr_value_or_default(poppler_structure_element, Attribute::BaselineShift)->getNum();
}
/**
* poppler_structure_element_get_line_height:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the line height for the text contained in the inline-level structure element.
* Note that for elements which do not specify a line height, it has to be calculated,
* and in this case -1 is returned.
*
* Return value: A positive value if a line height is defined, or -1
* if the height is to be calculated automatically.
*
* Since: 0.26
*/
gdouble poppler_structure_element_get_line_height(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_inline(poppler_structure_element), NAN);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::LineHeight);
return (value->isName("Normal") || value->isName("Auto")) ? -1.0 : value->getNum();
}
/**
* poppler_structure_element_get_text_decoration_color:
* @poppler_structure_element: A #PopplerStructureElement
* @color: (out): A #PopplerColor.
*
* Obtains the color of the text decoration for the text contained
* in the inline-level structure element.
* If this attribute is not specified, the color for this element shall be the current fill
* color in effect at the start of its associated content.
*
* Return value: %TRUE if a color is defined for the element,
* %FALSE otherwise.
*
* Since: 0.26
*/
gboolean poppler_structure_element_get_text_decoration_color(PopplerStructureElement *poppler_structure_element, PopplerColor *color)
{
g_return_val_if_fail(poppler_structure_element_is_inline(poppler_structure_element), FALSE);
g_return_val_if_fail(color != nullptr, FALSE);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::TextDecorationColor);
if (value == nullptr) {
return FALSE;
}
convert_color(value, color);
return FALSE;
}
/**
* poppler_structure_element_get_text_decoration_thickness:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the thickness of the text decoration for the text contained
* in the inline-level structure element.
* If this attribute is not specified, it shall be derived from the current
* stroke thickness in effect at the start of the element’s associated content.
*
* Return value: Thickness of the text decoration, or NAN if not defined.
*
* Since: 0.26
*/
gdouble poppler_structure_element_get_text_decoration_thickness(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_inline(poppler_structure_element), NAN);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::TextDecorationThickness);
return (value == nullptr) ? NAN : value->getNum();
}
/**
* poppler_structure_element_get_text_decoration_type:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the text decoration type of the text contained in the
* inline-level structure element.
*
* Return value: A #PopplerStructureTextDecoration value.
*
* Since: 0.26
*/
PopplerStructureTextDecoration poppler_structure_element_get_text_decoration_type(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_inline(poppler_structure_element), EnumNameValue<PopplerStructureTextDecoration>::values[0].value);
return attr_to_enum<PopplerStructureTextDecoration>(poppler_structure_element);
}
/**
* poppler_structure_element_get_ruby_align:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the alignment for the ruby text contained in a
* inline-level structure element.
*
* Return value: A #PopplerStructureRubyAlign value.
*
* Since: 0.26
*/
PopplerStructureRubyAlign poppler_structure_element_get_ruby_align(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_inline(poppler_structure_element), EnumNameValue<PopplerStructureRubyAlign>::values[0].value);
return attr_to_enum<PopplerStructureRubyAlign>(poppler_structure_element);
}
/**
* poppler_structure_element_get_ruby_position:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the position for the ruby text contained in a
* inline-level structure element.
*
* Return value: A #PopplerStructureRubyPosition value.
*
* Since: 0.26
*/
PopplerStructureRubyPosition poppler_structure_element_get_ruby_position(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_inline(poppler_structure_element), EnumNameValue<PopplerStructureRubyPosition>::values[0].value);
return attr_to_enum<PopplerStructureRubyPosition>(poppler_structure_element);
}
/**
* poppler_structure_element_get_glyph_orientation:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the glyph orientation for the text contained in a
* inline-level structure element.
*
* Return value: A #PopplerStructureGlyphOrientation value.
*
* Since: 0.26
*/
PopplerStructureGlyphOrientation poppler_structure_element_get_glyph_orientation(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_inline(poppler_structure_element), EnumNameValue<PopplerStructureGlyphOrientation>::values[0].value);
return attr_to_enum<PopplerStructureGlyphOrientation>(poppler_structure_element);
}
/* Column Attributes */
/**
* poppler_structure_element_get_column_count:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the number of columns used to lay out the content contained
* in the grouping element.
*
* Return value: Number of columns.
*
* Since: 0.26
*/
guint poppler_structure_element_get_column_count(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_is_grouping(poppler_structure_element), 0);
return static_cast<guint>(attr_value_or_default(poppler_structure_element, Attribute::ColumnCount)->getInt());
}
/**
* poppler_structure_element_get_column_gaps:
* @poppler_structure_element: A #PopplerStructureElement
* @n_values: (out): Size of the returned array.
*
* Obtains the size of the gaps in between adjacent columns. Returns an
* array of elements: the first one is the size of the gap in between
* columns 1 and 2, second is the size between columns 2 and 3, and so on.
*
* For elements which use a single column, %NULL is returned and @n_values
* is set to zero.
*
* If the attribute is undefined, %NULL is returned and @n_values is set
* to a non-zero value.
*
* The array with the results is allocated by the function. When it is
* not needed anymore, be sure to call g_free() on it.
*
* Return value: (transfer full) (array length=n_values) (element-type gdouble):
* Array containing the values for the column gaps, or %NULL if the
* array is empty or the attribute is not defined.
*
* Since: 0.26
*/
gdouble *poppler_structure_element_get_column_gaps(PopplerStructureElement *poppler_structure_element, guint *n_values)
{
g_return_val_if_fail(poppler_structure_element_is_grouping(poppler_structure_element), NULL);
g_return_val_if_fail(n_values != nullptr, NULL);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::ColumnGap);
if (value == nullptr) {
*n_values = static_cast<guint>(-1);
return nullptr;
}
gdouble *result = nullptr;
convert_doubles_array(value, &result, n_values);
return result;
}
/**
* poppler_structure_element_get_column_widths:
* @poppler_structure_element: A #PopplerStructureElement
* @n_values: (out): Size of the returned array.
*
* Obtains an array with the widths of the columns.
*
* The array with the results is allocated by the function. When it is
* not needed anymore, be sure to call g_free() on it.
*
* Return value: (transfer full) (array length=n_values) (element-type gdouble):
* Array containing widths of the columns, or %NULL if the attribute
* is not defined.
*
* Since: 0.26
*/
gdouble *poppler_structure_element_get_column_widths(PopplerStructureElement *poppler_structure_element, guint *n_values)
{
g_return_val_if_fail(poppler_structure_element_is_grouping(poppler_structure_element), NULL);
g_return_val_if_fail(n_values != nullptr, NULL);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::ColumnWidths);
if (value == nullptr) {
return nullptr;
}
gdouble *result = nullptr;
convert_doubles_array(value, &result, n_values);
return result;
}
/* List Attribute */
/**
* poppler_structure_element_get_list_numbering:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the list numbering style for list items.
*
* Return value: A #PopplerStructureListNumbering value.
*
* Since: 0.26
*/
PopplerStructureListNumbering poppler_structure_element_get_list_numbering(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_get_kind(poppler_structure_element) == POPPLER_STRUCTURE_ELEMENT_LIST_ITEM, EnumNameValue<PopplerStructureListNumbering>::values[0].value);
return attr_to_enum<PopplerStructureListNumbering>(poppler_structure_element);
}
/* PrintField Attributes */
/**
* poppler_structure_element_get_form_role:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the role of a form structure element that is part of a form, or is
* a form field. This hints how the control for the element is intended
* to be rendered.
*
* Return value: A #PopplerStructureFormRole value.
*
* Since: 0.26
*/
PopplerStructureFormRole poppler_structure_element_get_form_role(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_get_kind(poppler_structure_element) == POPPLER_STRUCTURE_ELEMENT_FORM, EnumNameValue<PopplerStructureFormRole>::values[0].value);
/*
* The Role attribute can actually be undefined.
*/
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::Role);
if (value == nullptr) {
return POPPLER_STRUCTURE_FORM_ROLE_UNDEFINED;
}
return name_to_enum<PopplerStructureFormRole>(value);
}
/**
* poppler_structure_element_get_form_state:
* @poppler_structure_element: A #PopplerStructureElement
*
* For a structure element that is a form field, obtains in which state
* the associated control is expected to be rendered.
*
* Return value: A #PopplerStructureFormState value.
*
* Since: 0.26
*/
PopplerStructureFormState poppler_structure_element_get_form_state(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_get_kind(poppler_structure_element) == POPPLER_STRUCTURE_ELEMENT_FORM, EnumNameValue<PopplerStructureFormState>::values[0].value);
return attr_to_enum<PopplerStructureFormState>(poppler_structure_element);
}
/**
* poppler_structure_element_get_form_description:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the textual description of the form element. Note that the
* description is for informative purposes, and it is not intended
* to be rendered. For example, assistive technologies may use the
* description field to provide an alternate way of presenting an
* element to the user.
*
* The returned string is allocated by the function. When it is
* not needed anymore, be sure to call g_free() on it.
*
* Return value: (transfer full): A string, or %NULL if the attribute
* is not defined.
*
* Since: 0.26
*/
gchar *poppler_structure_element_get_form_description(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_get_kind(poppler_structure_element) == POPPLER_STRUCTURE_ELEMENT_FORM, NULL);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::Desc);
if (value == nullptr) {
return nullptr;
}
if (value->isString()) {
return _poppler_goo_string_to_utf8(value->getString());
}
if (value->isName()) {
return g_strdup(value->getName());
}
g_assert_not_reached();
return nullptr;
}
/* Table Attributes */
/**
* poppler_structure_element_get_table_row_span:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the number of rows the table element spans to.
*
* Return value: A positive, non-zero value.
*
* Since: 0.26
*/
guint poppler_structure_element_get_table_row_span(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_get_kind(poppler_structure_element) == POPPLER_STRUCTURE_ELEMENT_TABLE, 0);
return static_cast<guint>(attr_value_or_default(poppler_structure_element, Attribute::RowSpan)->getInt());
}
/**
* poppler_structure_element_get_table_column_span:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the number of columns the table element spans to.
*
* Return value: A positive, non-zero value.
*
* Since: 0.26
*/
guint poppler_structure_element_get_table_column_span(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_get_kind(poppler_structure_element) == POPPLER_STRUCTURE_ELEMENT_TABLE, 0);
return static_cast<guint>(attr_value_or_default(poppler_structure_element, Attribute::ColSpan)->getInt());
}
/**
* poppler_structure_element_get_table_headers:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains an array with the names of the table column headers. This is only
* useful for table header row elements.
*
* The array with the results is allocated by the function. The number
* of items in the returned array can be obtained with g_strv_length().
* The returned value must be freed using g_strfreev().
*
* Return value: (transfer full) (array zero-terminated=1) (element-type gchar*):
* Zero-terminated array of strings with the table header names,
* or %NULL if the attribute is not defined.
*
* Since: 0.26
*/
gchar **poppler_structure_element_get_table_headers(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_get_kind(poppler_structure_element) == POPPLER_STRUCTURE_ELEMENT_TABLE, NULL);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::Headers);
if (value == nullptr) {
return nullptr;
}
g_assert(value->isArray());
const guint n_values = value->arrayGetLength();
gchar **result = g_new0(gchar *, n_values + 1);
for (guint i = 0; i < n_values; i++) {
Object item = value->arrayGet(i);
if (item.isString()) {
result[i] = _poppler_goo_string_to_utf8(item.getString());
} else if (item.isName()) {
result[i] = g_strdup(item.getName());
} else {
g_assert_not_reached();
}
}
return result;
}
/**
* poppler_structure_element_get_table_scope:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the scope of a table structure element.
*
* Return value: A #PopplerStructureTableScope value.
*
* Since: 0.26
*/
PopplerStructureTableScope poppler_structure_element_get_table_scope(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(poppler_structure_element_get_kind(poppler_structure_element) == POPPLER_STRUCTURE_ELEMENT_TABLE, EnumNameValue<PopplerStructureTableScope>::values[0].value);
return attr_to_enum<PopplerStructureTableScope>(poppler_structure_element);
}
/**
* poppler_structure_element_get_table_summary:
* @poppler_structure_element: A #PopplerStructureElement
*
* Obtains the textual summary of the contents of the table element. Note that
* the summary is meant for informative purposes, and it is not intended
* to be rendered. For example, assistive technologies may use the
* description field to provide an alternate way of presenting an element
* to the user, or a document indexer may want to scan it for additional
* keywords.
*
* The returned string is allocated by the function. When it is
* not needed anymore, be sure to call g_free() on it.
*
* Return value: (transfer full): A string, or %NULL if the attribute
* is not defined.
*
* Since: 0.26
*/
gchar *poppler_structure_element_get_table_summary(PopplerStructureElement *poppler_structure_element)
{
g_return_val_if_fail(POPPLER_IS_STRUCTURE_ELEMENT(poppler_structure_element), NULL);
const Object *value = attr_value_or_default(poppler_structure_element, Attribute::Summary);
if (value == nullptr) {
return nullptr;
}
if (value->isString()) {
return _poppler_goo_string_to_utf8(value->getString());
}
if (value->isName()) {
return g_strdup(value->getName());
}
g_assert_not_reached();
return nullptr;
}
|