completed the sbit cache, though it's still buggy :-( major reformatting of the cache subsystem (again) added substantial documentation too in header files
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
diff --git a/include/freetype/cache/ftcchunk.h b/include/freetype/cache/ftcchunk.h
index a36772c..c2ee555 100644
--- a/include/freetype/cache/ftcchunk.h
+++ b/include/freetype/cache/ftcchunk.h
@@ -58,11 +58,11 @@
#define FTC_MAX_CHUNK_SETS 16
- typedef struct FTC_ChunkRec_* FTC_Chunk;
+ typedef struct FTC_ChunkNodeRec_* FTC_ChunkNode;
typedef struct FTC_ChunkSetRec_* FTC_ChunkSet;
typedef struct FTC_Chunk_CacheRec_* FTC_Chunk_Cache;
- typedef struct FTC_ChunkRec_
+ typedef struct FTC_ChunkNodeRec_
{
FTC_CacheNodeRec root;
FTC_ChunkSet cset;
@@ -70,14 +70,21 @@
FT_UShort num_elements;
FT_Byte* elements;
- } FTC_ChunkRec;
+ } FTC_ChunkNodeRec;
+#define FTC_CHUNKNODE_TO_LRUNODE(x) ((FT_ListNode)(x))
+#define FTC_LRUNODE_TO_CHUNKNODE(x) ((FTC_ChunkNode)(x))
/*************************************************************************/
/* */
/* chunk set methods */
/* */
+ /* used to set "element_max", "element_count" and "element_size" */
+ typedef FT_Error (*FTC_ChunkSet_SizesFunc) ( FTC_ChunkSet cset,
+ FT_Pointer type );
+
+
typedef FT_Error (*FTC_ChunkSet_InitFunc) ( FTC_ChunkSet cset,
FT_Pointer type );
@@ -100,11 +107,12 @@
typedef struct FTC_ChunkSet_Class_
{
- FT_UInt cset_size;
+ FT_UInt cset_byte_size;
FTC_ChunkSet_InitFunc init;
FTC_ChunkSet_DoneFunc done;
FTC_ChunkSet_CompareFunc compare;
+ FTC_ChunkSet_SizesFunc sizes;
FTC_ChunkSet_NewNodeFunc new_node;
FTC_ChunkSet_SizeNodeFunc size_node;
@@ -119,11 +127,12 @@
FTC_Manager manager;
FT_Memory memory;
FTC_ChunkSet_Class* clazz;
- FT_UInt cset_index; /* index in parent cache */
+ FT_UInt cset_index; /* index in parent cache */
FT_UInt element_max; /* maximum number of elements */
FT_UInt element_size; /* element size in bytes */
FT_UInt element_count; /* number of elements per chunk */
+
FT_UInt num_chunks;
FTC_ChunkNode* chunks;
@@ -145,7 +154,7 @@
FTC_CacheRec root;
FT_Lru csets_lru; /* static chunk set lru list */
FTC_ChunkSet last_cset; /* small cache :-) */
-
+
} FTC_Chunk_CacheRec;
/*************************************************************************/
@@ -155,7 +164,7 @@
/* cache sub-system internals. */
/* */
- FT_EXPORT_FUNC( NV_Error )
+ FT_EXPORT_FUNC( FT_Error )
FTC_ChunkNode_Init( FTC_ChunkNode node,
FTC_ChunkSet cset,
FT_UInt index,
@@ -186,10 +195,7 @@
FT_EXPORT_DEF( FT_Error )
FTC_ChunkSet_New( FTC_Chunk_Cache cache,
FT_Pointer type,
- FT_UInt num_elements,
- FT_UInt element_size,
- FT_UInt chunk_size,
- FTC_ChunkSet *aset )
+ FTC_ChunkSet *aset );
FT_EXPORT_DEF( FT_Error )
diff --git a/include/freetype/cache/ftcglyph.h b/include/freetype/cache/ftcglyph.h
index b0a4ea7..ca70492 100644
--- a/include/freetype/cache/ftcglyph.h
+++ b/include/freetype/cache/ftcglyph.h
@@ -2,7 +2,7 @@
/* */
/* ftcglyph.h */
/* */
-/* FreeType glyph image (FT_Glyph) cache (specification). */
+/* FreeType abstract glyph cache (specification). */
/* */
/* Copyright 2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
@@ -24,6 +24,14 @@
/* For example, see `ftcimage.h' and `ftcimage.c' which */
/* implement a FT_Glyph cache based on this code. */
/* */
+ /* NOTE: for now, each glyph set is implemented as a static hash table */
+ /* it's be interesting to experiment with dynamic hashes to see */
+ /* if this improves performance or not (I don't know why but */
+ /* something tells me it won't ?!) */
+ /* */
+ /* in all cases, this change should not affect any derived */
+ /* glyph cache class.. */
+ /* */
/*************************************************************************/
@@ -147,7 +155,7 @@
{
FTC_CacheRec root;
FT_Lru gsets_lru; /* static sets lru list */
- FTC_GlyphSet last_gset; /* small cache :-) */
+ FTC_GlyphSet last_gset; /* small cache :o) */
} FTC_Glyph_CacheRec;
diff --git a/include/freetype/cache/ftcimage.h b/include/freetype/cache/ftcimage.h
new file mode 100644
index 0000000..f493339
--- /dev/null
+++ b/include/freetype/cache/ftcimage.h
@@ -0,0 +1,190 @@
+/***************************************************************************/
+/* */
+/* ftcimage.c */
+/* */
+/* FreeType Image cache (body). */
+/* */
+/* Each image cache really manages FT_Glyph objects :-) */
+/* */
+/* */
+/* Copyright 2000 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#ifndef FTCIMAGE_H
+#define FTCIMAGE_H
+
+
+#include <freetype/cache/ftcglyph.h>
+#include <freetype/ftglyph.h>
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** IMAGE CACHE OBJECT *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
+ /*************************************************************************/
+
+
+#define FTC_IMAGE_FORMAT( x ) ( (x) & 7 )
+
+ /*************************************************************************/
+ /* */
+ /* <Enum> */
+ /* FTC_Image_Type */
+ /* */
+ /* <Description> */
+ /* An enumeration used to list the types of glyph images found in a */
+ /* glyph image cache. */
+ /* */
+ /* <Fields> */
+ /* ftc_image_mono :: Monochrome bitmap glyphs. */
+ /* */
+ /* ftc_image_grays :: Anti-aliased bitmap glyphs. */
+ /* */
+ /* ftc_image_outline :: Scaled (and hinted) outline glyphs. */
+ /* */
+ /* ftc_master_outline :: Unscaled original outline glyphs. */
+ /* */
+ /* <Note> */
+ /* Other types may be defined in the future. */
+ /* */
+ typedef enum FTC_Image_Type_
+ {
+ ftc_image_format_bitmap = 0,
+ ftc_image_format_outline = 1,
+
+ ftc_image_flag_monochrome = 16,
+ ftc_image_flag_unhinted = 32,
+ ftc_image_flag_autohinted = 64,
+ ftc_image_flag_unscaled = 128,
+ ftc_image_flag_no_sbits = 256,
+
+ ftc_image_mono = ftc_image_format_bitmap |
+ ftc_image_flag_monochrome, /* monochrome bitmap */
+ ftc_image_grays = ftc_image_format_bitmap, /* anti-aliased bitmap */
+ ftc_image_outline = ftc_image_format_outline /* scaled outline */
+
+ } FTC_Image_Type;
+
+
+ /*************************************************************************/
+ /* */
+ /* <Struct> */
+ /* FTC_Image_Desc */
+ /* */
+ /* <Description> */
+ /* A simple structure used to describe a given glyph image category. */
+ /* */
+ /* <Fields> */
+ /* size :: An FTC_SizeRec used to describe the glyph's face & */
+ /* size. */
+ /* */
+ /* image_type :: The glyph image's type. */
+ /* */
+ typedef struct FTC_Image_Desc_
+ {
+ FTC_FontRec font;
+ FT_UInt image_type;
+
+ } FTC_Image_Desc;
+
+
+ /*************************************************************************/
+ /* */
+ /* <Type> */
+ /* FTC_Image_Cache */
+ /* */
+ /* <Description> */
+ /* A handle to an glyph image cache object. They are designed to */
+ /* hold many distinct glyph images, while not exceeding a certain */
+ /* memory threshold. */
+ /* */
+ typedef struct FTC_Image_CacheRec_* FTC_Image_Cache;
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FTC_Image_Cache_New */
+ /* */
+ /* <Description> */
+ /* Creates a new glyph image cache. */
+ /* */
+ /* <Input> */
+ /* manager :: The parent manager for the image cache. */
+ /* */
+ /* <Output> */
+ /* acache :: A handle to the new glyph image cache object. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_New( FTC_Manager manager,
+ FTC_Image_Cache* acache );
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FTC_Image_Cache_Lookup */
+ /* */
+ /* <Description> */
+ /* Retrieves a given glyph image from a glyph image cache. */
+ /* */
+ /* <Input> */
+ /* cache :: A handle to the source glyph image cache. */
+ /* */
+ /* desc :: A pointer to a glyph image descriptor. */
+ /* */
+ /* gindex :: The glyph index to retrieve. */
+ /* */
+ /* <Output> */
+ /* aglyph :: The corresponding FT_Glyph object. 0 in case of */
+ /* failure. */
+ /* */
+ /* <Return> */
+ /* error code, 0 means success */
+ /* */
+ /* <Note> */
+ /* the returned glyph is owned and manager by the glyph image cache. */
+ /* Never try to transform or discard it manually! You can however */
+ /* create a copy with FT_Glyph_Copy() and modify the new one. */
+ /* */
+ /* Because the glyph image cache limits the total amount of memory */
+ /* taken by the glyphs it holds, the returned glyph might disappear */
+ /* on a later invocation of this function! It's a cache after all... */
+ /* */
+ FT_EXPORT_DEF( FT_Error )
+ FTC_Image_Cache_Lookup( FTC_Image_Cache cache,
+ FTC_Image_Desc* desc,
+ FT_UInt gindex,
+ FT_Glyph* aglyph );
+
+
+
+#ifdef __cplusplus
+ }
+#endif
+
+
+#endif /* FTCIMAGE_H */
+
+
+/* END */
diff --git a/include/freetype/cache/ftcmanag.h b/include/freetype/cache/ftcmanag.h
index 0b13e34..ec899b9 100644
--- a/include/freetype/cache/ftcmanag.h
+++ b/include/freetype/cache/ftcmanag.h
@@ -73,7 +73,6 @@
#endif
- /* default values */
#define FTC_MAX_FACES_DEFAULT 2
#define FTC_MAX_SIZES_DEFAULT 4
#define FTC_MAX_BYTES_DEFAULT 200000 /* 200kByte by default! */
@@ -82,6 +81,40 @@
#define FTC_MAX_CACHES 16
+ /****************************************************************
+ *
+ * <Struct> FTC_ManagerRec
+ *
+ * <Description>
+ * the cache manager structure. Each cache manager is in
+ * charge of performing two tasks:
+ *
+ * <Fields>
+ * library :: handle to FreeType library instance
+ * faces_lru :: lru list of FT_Face objects in cache
+ * sizes_lru :: lru list of FT_Size objects in cache
+ *
+ * max_bytes :: maximum number of bytes to be allocated
+ * in the cache. this is only related to
+ * the byte size of the nodes cached by
+ * the manager.
+ *
+ * num_bytes :: current number of bytes allocated in
+ * the cache. only related to the byte size
+ * of cached nodes.
+ *
+ * num_nodes :: current number of nodes in the manager
+ *
+ * global_lru :: the global lru list of all cache nodes
+ *
+ * caches :: a table of installed/registered cache
+ * objects
+ *
+ * request_data :: user-provided data passed to the requester
+ * request_face :: user-provided function used to implement
+ * a mapping between abstract FTC_FaceIDs
+ * and real FT_Face objects..
+ */
typedef struct FTC_ManagerRec_
{
FT_Library library;
@@ -90,6 +123,7 @@
FT_ULong max_bytes;
FT_ULong num_bytes;
+ FT_UInt num_nodes;
FT_ListRec global_lru;
FTC_Cache caches[FTC_MAX_CACHES];
@@ -99,6 +133,31 @@
} FTC_ManagerRec;
+ /**********************************************************************
+ *
+ * <Function> FTC_Manager_Compress
+ *
+ * <Description>
+ * this function is used to check the state of the cache manager
+ * if its "num_bytes" field is greater than its "max_bytes"
+ * field, this function will flush as many old cache nodes as
+ * possible (ignoring cache nodes with a non-zero reference
+ * count).
+ *
+ * <input>
+ * manager :: handle to cache manager
+ *
+ * <note>
+ * client applications should not call this function directly.
+ * it is normally invoked by specific cache implementations.
+ *
+ * the reason this function is exported is to allow client-
+ * specific cache classes..
+ *
+ */
+ FT_EXPORT_DEF( void ) FTC_Manager_Compress( FTC_Manager manager );
+
+
/*************************************************************************/
/*************************************************************************/
/***** *****/
@@ -138,19 +197,56 @@
#define FTC_LIST_TO_CACHENODE( n ) ( (FTC_CacheNode)(n) )
- /* return the size in bytes of a given cache node */
+ /**********************************************************************
+ *
+ * <FuncType> FTC_CacheNode_SizeFunc
+ *
+ * <Description>
+ * a function used to compute the total size in bytes of a given
+ * cache node. It is used by the cache manager to compute the
+ * number of old nodes to flush when the cache is full..
+ *
+ * <Input>
+ * node :: handle to target cache node
+ * cache_data :: a generic pointer passed to the destructor.
+ */
typedef FT_ULong (*FTC_CacheNode_SizeFunc)( FTC_CacheNode node,
- FT_Pointer user );
-
- /* finalize a given cache node */
+ FT_Pointer cache_data );
+
+ /**********************************************************************
+ *
+ * <FuncType> FTC_CacheNode_DestroyFunc
+ *
+ * <Description>
+ * a function used to destroy a given cache node. It is called
+ * by the manager when the cache is full and old nodes need to
+ * be flushed out..
+ *
+ * <Input>
+ * node :: handle to target cache node
+ * cache_data :: a generic pointer passed to the destructor.
+ */
typedef void (*FTC_CacheNode_DestroyFunc)( FTC_CacheNode node,
- FT_Pointer user );
-
- /* This structure is used to provide functions to the cache manager. */
- /* It will use them to size and destroy cache nodes. Note that there */
- /* is no `init_node' because cache objects are entirely responsible */
- /* for the creation of new cache nodes. */
- /* */
+ FT_Pointer cache_data );
+
+ /**********************************************************************
+ *
+ * <Struct> FTC_CacheNode_Class
+ *
+ * <Description>
+ * a very simple structure used to describe a cache node's class
+ * to the cache manager
+ *
+ * <Fields>
+ * size_node :: a function used to size the node
+ * destroy_node :: a function used to destroy the node
+ *
+ * <Note>
+ * the cache node class doesn't include a "new_node" function
+ * because the cache manager never allocates cache node directly,
+ * it delegates this task to its cache objects..
+ *
+ */
typedef struct FTC_CacheNode_Class_
{
FTC_CacheNode_SizeFunc size_node;
@@ -168,10 +264,45 @@
/*************************************************************************/
+ /**********************************************************************
+ *
+ * <FuncType> FTC_Cache_InitFunc
+ *
+ * <Description>
+ * a function used to initialize a given cache object
+ *
+ * <Input>
+ * cache :: handle to new cache
+ */
typedef FT_Error (*FTC_Cache_InitFunc)( FTC_Cache cache );
+
+
+ /**********************************************************************
+ *
+ * <FuncType> FTC_Cache_DoneFunc
+ *
+ * <Description>
+ * a function used to finalize a given cache object
+ *
+ * <Input>
+ * cache :: handle to target cache
+ */
typedef void (*FTC_Cache_DoneFunc)( FTC_Cache cache );
+ /**********************************************************************
+ *
+ * <Struct> FTC_Cache_Class
+ *
+ * <Description>
+ * a structure used to describe a given cache object class to
+ * the cache manager.
+ *
+ * <Fields>
+ * cache_byte_size :: size of cache object in bytes
+ * init_cache :: cache object initializer
+ * done_cache :: cache object finalizer
+ */
struct FTC_Cache_Class_
{
FT_UInt cache_byte_size;
@@ -179,6 +310,23 @@
FTC_Cache_DoneFunc done_cache;
};
+
+ /**********************************************************************
+ *
+ * <Struct> FTC_CacheRec
+ *
+ * <Description>
+ * a structure used to describe an abstract cache object
+ *
+ * <Fields>
+ * manager :: handle to parent cache manager
+ * memory :: handle to memory manager
+ * clazz :: pointer to cache clazz
+ * node_clazz :: pointer to cache's node clazz
+ *
+ * cache_index :: index of cache in manager's table
+ * cache_data :: data passed to the cache node constructor/finalizer
+ */
typedef struct FTC_CacheRec_
{
FTC_Manager manager;
@@ -187,16 +335,11 @@
FTC_CacheNode_Class* node_clazz;
FT_UInt cache_index; /* in manager's table */
- FT_Pointer cache_user; /* passed to cache node methods */
+ FT_Pointer cache_data; /* passed to cache node methods */
} FTC_CacheRec;
- /* `Compress' the manager's data, i.e., get rid of old cache nodes */
- /* that are not referenced anymore in order to limit the total */
- /* memory used by the cache. */
- FT_EXPORT_DEF( void ) FTC_Manager_Compress( FTC_Manager manager );
-
#ifdef __cplusplus
}
diff --git a/include/freetype/cache/ftcsbits.h b/include/freetype/cache/ftcsbits.h
new file mode 100644
index 0000000..d9d8011
--- /dev/null
+++ b/include/freetype/cache/ftcsbits.h
@@ -0,0 +1,73 @@
+/***************************************************************************/
+/* */
+/* ftcsbits.h */
+/* */
+/* a small-bitmaps cache (specification). */
+/* */
+/* Copyright 2000 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+#ifndef FTCSBITS_H
+#define FTCSBITS_H
+
+#include <freetype/cache/ftcchunk.h>
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+ /* handle to small bitmap */
+ typedef struct FTC_SBitRec_* FTC_SBit;
+
+
+ /* handle to small bitmap cache */
+ typedef struct FTC_SBit_CacheRec_* FTC_SBit_Cache;
+
+
+ /* a compact structure used to hold a single small bitmap */
+ typedef struct FTC_SBitRec_
+ {
+ FT_Byte width;
+ FT_Byte height;
+ FT_Char left;
+ FT_Char top;
+
+ FT_Byte format;
+ FT_Char pitch;
+ FT_Char xadvance;
+ FT_Char yadvance;
+
+ FT_Byte* buffer;
+
+ } FTC_SBitRec;
+
+
+ FT_EXPORT_DEF( FT_Error )
+ FTC_SBit_Cache_New( FTC_Manager manager,
+ FTC_SBit_Cache *acache );
+
+
+ FT_EXPORT_DEF( FT_Error )
+ FTC_SBit_Cache_Lookup( FTC_SBit_Cache cache,
+ FTC_Image_Desc* desc,
+ FT_UInt gindex,
+ FTC_SBit *sbit );
+
+
+#ifdef __cplusplus
+ }
+#endif
+
+
+#endif /* FTCSBITS_H */
+
+/* END */
+
diff --git a/include/freetype/cache/ftlru.h b/include/freetype/cache/ftlru.h
index d514fd3..9e81681 100644
--- a/include/freetype/cache/ftlru.h
+++ b/include/freetype/cache/ftlru.h
@@ -72,7 +72,7 @@
typedef FT_Pointer FT_LruKey;
- /* an lru node -- node.root.data points to the element */
+ /* an lru node -- root.data points to the element */
typedef struct FT_LruNodeRec_
{
FT_ListNodeRec root;
@@ -80,6 +80,8 @@
} FT_LruNodeRec, *FT_LruNode;
+
+
/* forward declaration */
typedef struct FT_LruRec_* FT_Lru;
@@ -94,8 +96,8 @@
FT_LruNode node );
/* this method is used to finalize a given list element node */
- void (*done_element)( FT_Lru lru,
- FT_LruNode node );
+ void (*done_element)( FT_Lru lru,
+ FT_LruNode node );
/* If defined, this method is called when the list if full */
/* during the lookup process -- it is used to change the contents */
@@ -145,10 +147,11 @@
FT_Memory memory,
FT_Bool pre_alloc,
FT_Lru* alru );
-
- FT_EXPORT_DEF( void ) FT_Lru_Reset( FT_Lru lru );
-
- FT_EXPORT_DEF( void ) FT_Lru_Done( FT_Lru lru );
+
+ FT_EXPORT_DEF( void ) FT_Lru_Reset( FT_Lru lru );
+
+ FT_EXPORT_DEF( void ) FT_Lru_Done ( FT_Lru lru );
+
FT_EXPORT_DEF( FT_Error ) FT_Lru_Lookup_Node( FT_Lru lru,
FT_LruKey key,
@@ -157,7 +160,8 @@
FT_EXPORT_DEF( FT_Error ) FT_Lru_Lookup( FT_Lru lru,
FT_LruKey key,
FT_Pointer* aobject );
-
+
+
FT_EXPORT_DEF( void ) FT_Lru_Remove_Node( FT_Lru lru,
FT_LruNode node );
diff --git a/include/freetype/ftcache.h b/include/freetype/ftcache.h
index b7657e7..565598b 100644
--- a/include/freetype/ftcache.h
+++ b/include/freetype/ftcache.h
@@ -90,6 +90,11 @@
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
+ /* <Note> */
+ /* the face requester should not perform funny things on the returned */
+ /* face object, like creating a new FT_Size for it, or setting a */
+ /* transform through FT_Set_Transform !! */
+ /* */
typedef FT_Error (*FTC_Face_Requester)( FTC_FaceID face_id,
FT_Library library,
FT_Pointer request_data,
@@ -307,7 +312,7 @@
FTC_Font font,
FT_Face* aface,
FT_Size* asize );
-
+
/* a cache class is used to describe a unique cache type to the manager */
typedef struct FTC_Cache_Class_ FTC_Cache_Class;
@@ -321,153 +326,6 @@
FTC_Cache* acache );
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /***** *****/
- /***** IMAGE CACHE OBJECT *****/
- /***** *****/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
-
-#define FTC_IMAGE_FORMAT( x ) ( (x) & 7 )
-
- /*************************************************************************/
- /* */
- /* <Enum> */
- /* FTC_Image_Type */
- /* */
- /* <Description> */
- /* An enumeration used to list the types of glyph images found in a */
- /* glyph image cache. */
- /* */
- /* <Fields> */
- /* ftc_image_mono :: Monochrome bitmap glyphs. */
- /* */
- /* ftc_image_grays :: Anti-aliased bitmap glyphs. */
- /* */
- /* ftc_image_outline :: Scaled (and hinted) outline glyphs. */
- /* */
- /* ftc_master_outline :: Unscaled original outline glyphs. */
- /* */
- /* <Note> */
- /* Other types may be defined in the future. */
- /* */
- typedef enum FTC_Image_Type_
- {
- ftc_image_format_bitmap = 0,
- ftc_image_format_outline = 1,
-
- ftc_image_flag_monochrome = 16,
- ftc_image_flag_unhinted = 32,
- ftc_image_flag_autohinted = 64,
- ftc_image_flag_unscaled = 128,
- ftc_image_flag_no_sbits = 256,
-
- ftc_image_mono = ftc_image_format_bitmap |
- ftc_image_flag_monochrome, /* monochrome bitmap */
- ftc_image_grays = ftc_image_format_bitmap, /* anti-aliased bitmap */
- ftc_image_outline = ftc_image_format_outline /* scaled outline */
-
- } FTC_Image_Type;
-
-
- /*************************************************************************/
- /* */
- /* <Struct> */
- /* FTC_Image_Desc */
- /* */
- /* <Description> */
- /* A simple structure used to describe a given glyph image category. */
- /* */
- /* <Fields> */
- /* size :: An FTC_SizeRec used to describe the glyph's face & */
- /* size. */
- /* */
- /* image_type :: The glyph image's type. */
- /* */
- typedef struct FTC_Image_Desc_
- {
- FTC_FontRec font;
- FT_UInt image_type;
-
- } FTC_Image_Desc;
-
-
- /*************************************************************************/
- /* */
- /* <Type> */
- /* FTC_Image_Cache */
- /* */
- /* <Description> */
- /* A handle to an glyph image cache object. They are designed to */
- /* hold many distinct glyph images, while not exceeding a certain */
- /* memory threshold. */
- /* */
- typedef struct FTC_Image_CacheRec_* FTC_Image_Cache;
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FTC_Image_Cache_New */
- /* */
- /* <Description> */
- /* Creates a new glyph image cache. */
- /* */
- /* <Input> */
- /* manager :: The parent manager for the image cache. */
- /* */
- /* <Output> */
- /* acache :: A handle to the new glyph image cache object. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_New( FTC_Manager manager,
- FTC_Image_Cache* acache );
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* FTC_Image_Cache_Lookup */
- /* */
- /* <Description> */
- /* Retrieves a given glyph image from a glyph image cache. */
- /* */
- /* <Input> */
- /* cache :: A handle to the source glyph image cache. */
- /* */
- /* desc :: A pointer to a glyph image descriptor. */
- /* */
- /* gindex :: The glyph index to retrieve. */
- /* */
- /* <Output> */
- /* aglyph :: The corresponding FT_Glyph object. 0 in case of */
- /* failure. */
- /* */
- /* <Return> */
- /* error code, 0 means success */
- /* */
- /* <Note> */
- /* the returned glyph is owned and manager by the glyph image cache. */
- /* Never try to transform or discard it manually! You can however */
- /* create a copy with FT_Glyph_Copy() and modify the new one. */
- /* */
- /* Because the glyph image cache limits the total amount of memory */
- /* taken by the glyphs it holds, the returned glyph might disappear */
- /* on a later invocation of this function! It's a cache after all... */
- /* */
- FT_EXPORT_DEF( FT_Error )
- FTC_Image_Cache_Lookup( FTC_Image_Cache cache,
- FTC_Image_Desc* desc,
- FT_UInt gindex,
- FT_Glyph* aglyph );
-
-
#ifdef __cplusplus
}
#endif
diff --git a/src/cache/ftcache.c b/src/cache/ftcache.c
index 913dba4..f5cf47b 100644
--- a/src/cache/ftcache.c
+++ b/src/cache/ftcache.c
@@ -23,14 +23,18 @@
#include "ftlru.c"
#include "ftcmanag.c"
#include "ftcglyph.c"
+#include "ftcchunk.c"
#include "ftcimage.c"
+#include "ftcsbits.c"
#else
#include <cache/ftlru.c>
#include <cache/ftcmanag.c>
#include <cache/ftcglyph.c>
+#include <cache/ftcchunk.c>
#include <cache/ftcimage.c>
+#include <cache/ftcsbits.c>
#endif
diff --git a/src/cache/ftcchunk.c b/src/cache/ftcchunk.c
index 2dc5b24..c05a6f2 100644
--- a/src/cache/ftcchunk.c
+++ b/src/cache/ftcchunk.c
@@ -16,7 +16,7 @@
/***************************************************************************/
-#include <freetype/cache/ftcglyph.h>
+#include <freetype/cache/ftcchunk.h>
#include <freetype/fterrors.h>
#include <freetype/internal/ftobjs.h>
#include <freetype/internal/ftlist.h>
@@ -33,7 +33,7 @@
/* create a new chunk node, setting its cache index and ref count */
- FT_EXPORT_FUNC( NV_Error )
+ FT_EXPORT_FUNC( FT_Error )
FTC_ChunkNode_Init( FTC_ChunkNode node,
FTC_ChunkSet cset,
FT_UInt index,
@@ -41,22 +41,25 @@
{
FTC_Chunk_Cache cache = cset->cache;
FTC_CacheNode_Data* data = FTC_CACHENODE_TO_DATA_P( &node->root );
- NV_Error error = 0;
+ FT_Error error = 0;
data->cache_index = (FT_UShort) cache->root.cache_index;
data->ref_count = (FT_Short) 0;
node->cset_index = (FT_UShort) index;
- node->num_elements = (index+1 < cset->chunk_count)
- ? cset->chunk_size
- : cset->element_max - cset->chunk_count*index;
+ node->num_elements = (index+1 < cset->element_count)
+ ? cset->element_count * cset->element_size
+ : cset->element_max - cset->element_count*index;
if (alloc)
{
/* allocate elements array */
+ FT_Memory memory;
+
+
memory = cache->root.memory;
- error = MEM_ALLOC( cache->elements, cset->element_size *
- cset->element_count );
+ error = MEM_Alloc( node->elements, cset->element_size *
+ cset->element_count );
}
return error;
}
@@ -79,7 +82,7 @@
FTC_ChunkSet cset = node->cset;
- return cset->clazz->size_node( node, cset );
+ return cset->clazz->size_node( node );
}
@@ -102,9 +105,6 @@
FT_EXPORT_FUNC( FT_Error )
FTC_ChunkSet_New( FTC_Chunk_Cache cache,
FT_Pointer type,
- FT_UInt num_elements,
- FT_UInt element_size,
- FT_UInt chunk_size,
FTC_ChunkSet *aset )
{
FT_Error error;
@@ -121,19 +121,22 @@
*aset = 0;
- if ( ALLOC( set, clazz->cset_byte_size ) )
+ if ( ALLOC( cset, clazz->cset_byte_size ) )
goto Exit;
cset->cache = cache;
cset->manager = manager;
cset->memory = memory;
- cset->element_max = num_elements;
- cset->element_size = element_size;
- cset->element_count = chunk_size;
cset->clazz = clazz;
+ /* now compute element_max, element_count and element_size */
+ error = clazz->sizes( cset, type);
+ if (error)
+ goto Exit;
+
/* compute maximum number of nodes */
- cset->num_chunks = (num_elements + (chunk_size-1))/chunk_size;
+ cset->num_chunks = (cset->element_max +
+ cset->element_count - 1) / cset->element_count;
/* allocate chunk pointers table */
if ( ALLOC_ARRAY( cset->chunks, cset->num_chunks, FTC_ChunkNode ) )
@@ -165,7 +168,7 @@
FTC_Chunk_Cache cache = cset->cache;
FTC_Manager manager = cache->root.manager;
FT_List glyphs_lru = &manager->global_lru;
- FTC_ChunkNode* bucket = cset->chunk;
+ FTC_ChunkNode* bucket = cset->chunks;
FTC_ChunkNode* bucket_limit = bucket + cset->num_chunks;
FT_Memory memory = cache->root.memory;
@@ -181,6 +184,7 @@
lrunode = FTC_CHUNKNODE_TO_LRUNODE( node );
manager->num_bytes -= clazz->size_node( node );
+ manaher->num_nodes --;
FT_List_Remove( glyphs_lru, lrunode );
@@ -201,21 +205,21 @@
FTC_ChunkSet_Lookup_Node( FTC_ChunkSet cset,
FT_UInt glyph_index,
FTC_ChunkNode *anode,
- FTC_UInt *index )
+ FT_UInt *aindex )
{
- FTC_Glyph_Cache cache = cset->cache;
+ FTC_Chunk_Cache cache = cset->cache;
FTC_Manager manager = cache->root.manager;
FT_Error error = 0;
- FTC_GlyphSet_Class* clazz = cset->clazz;
+ FTC_ChunkSet_Class* clazz = cset->clazz;
*anode = 0;
- if (glyph_index >= cset->elements_max)
+ if (glyph_index >= cset->element_max)
error = FT_Err_Invalid_Argument;
else
{
- FT_UInt chunk_size = cset->chunk_size;
+ FT_UInt chunk_size = cset->element_count;
FT_UInt chunk_index = glyph_index/chunk_size;
FTC_ChunkNode* pnode = cset->chunks + chunk_index;
FTC_ChunkNode node = *pnode;
@@ -233,7 +237,8 @@
/* insert the node at the start the global LRU glyph list */
FT_List_Insert( &manager->global_lru, FTC_CHUNKNODE_TO_LRUNODE( node ) );
- manager->num_bytes += clazz->size_node( node, gset );
+ manager->num_bytes += clazz->size_node( node );
+ manager->num_nodes ++;
if (manager->num_bytes > manager->max_bytes)
{
@@ -287,7 +292,7 @@
{
/* good, now set the set index within the set object */
cset->cset_index = node - lru->nodes;
- node->root.data = set;
+ node->root.data = cset;
}
return error;
@@ -347,15 +352,8 @@
cache->root.node_clazz =
(FTC_CacheNode_Class*)&ftc_chunk_cache_node_class;
- /* The following is extremely important for ftc_destroy_glyph_image() */
- /* to work properly, as the second parameter that is sent to it */
- /* through the cache manager is `user_data' and must be set to */
- /* `cache' here. */
- /* */
- cache->root.cache_user = cache;
-
error = FT_Lru_New( &ftc_chunk_set_lru_class,
- FTC_MAX_GLYPH_CSETS,
+ FTC_MAX_CHUNK_SETS,
cache,
memory,
1, /* pre_alloc == TRUE */
diff --git a/src/cache/ftcglyph.c b/src/cache/ftcglyph.c
index 6f897c8..27ce5d2 100644
--- a/src/cache/ftcglyph.c
+++ b/src/cache/ftcglyph.c
@@ -50,9 +50,9 @@
/* Important: This function is called from the cache manager to */
/* destroy a given cache node during `cache compression'. The */
- /* second argument is always `cache.user_data'. Thus be */
+ /* second argument is always `cache.cache_data'. Thus be */
/* certain that the function FTC_Glyph_Cache_New() does indeed */
- /* set its `user_data' field correctly, otherwise bad things */
+ /* set its `cache_data' field correctly, otherwise bad things */
/* will happen! */
FT_EXPORT_FUNC( void ) FTC_GlyphNode_Destroy( FTC_GlyphNode node,
@@ -120,7 +120,7 @@
/*************************************************************************/
/*************************************************************************/
/***** *****/
- /***** GLYPH QUEUES *****/
+ /***** GLYPH SETS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
@@ -204,6 +204,7 @@
lrunode = FTC_GLYPHNODE_TO_LRUNODE( node );
manager->num_bytes -= clazz->size_node( node, gset );
+ manager->num_nodes --;
FT_List_Remove( glyphs_lru, lrunode );
@@ -273,6 +274,7 @@
FT_List_Insert( &manager->global_lru, FTC_GLYPHNODE_TO_LRUNODE( node ) );
manager->num_bytes += clazz->size_node( node, gset );
+ manager->num_nodes ++;
if (manager->num_bytes > manager->max_bytes)
{
@@ -365,7 +367,7 @@
/*************************************************************************/
/*************************************************************************/
/***** *****/
- /***** GLYPH IMAGE CACHE OBJECTS *****/
+ /***** GLYPH CACHE OBJECTS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
@@ -383,10 +385,10 @@
/* The following is extremely important for ftc_destroy_glyph_image() */
/* to work properly, as the second parameter that is sent to it */
- /* through the cache manager is `user_data' and must be set to */
+ /* through the cache manager is `cache_data' and must be set to */
/* `cache' here. */
/* */
- cache->root.cache_user = cache;
+ cache->root.cache_data = cache;
error = FT_Lru_New( &ftc_glyph_set_lru_class,
FTC_MAX_GLYPH_SETS,
diff --git a/src/cache/ftcimage.c b/src/cache/ftcimage.c
index 50d0a07..5d504e5 100644
--- a/src/cache/ftcimage.c
+++ b/src/cache/ftcimage.c
@@ -16,15 +16,36 @@
/***************************************************************************/
-#ifdef FT_FLAT_COMPILE
-# include "ftcimage.h"
-#else
-# include <cache/ftcimage.h>
-#endif
+#include <freetype/cache/ftcimage.h>
+#include <freetype/internal/ftmemory.h>
#include <string.h>
-#include <freetype/internal/ftmemory.h>
+
+ /* the FT_Glyph image "glyph node" type */
+ typedef struct FTC_GlyphImageRec_
+ {
+ FTC_GlyphNodeRec root;
+ FT_Glyph ft_glyph;
+
+ } FTC_GlyphImageRec, *FTC_GlyphImage;
+
+
+ /* the glyph image queue type */
+ typedef struct FTC_ImageSetRec_
+ {
+ FTC_GlyphSetRec root;
+ FTC_Image_Desc description;
+
+ } FTC_ImageSetRec, *FTC_ImageSet;
+
+
+ typedef struct FTC_Image_CacheRec_
+ {
+ FTC_Glyph_CacheRec root;
+
+ } FTC_Image_CacheRec;
+
/*************************************************************************/
@@ -180,7 +201,7 @@
/*************************************************************************/
/*************************************************************************/
/***** *****/
- /***** GLYPH IMAGE QUEUES *****/
+ /***** GLYPH IMAGE SETS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
diff --git a/src/cache/ftcimage.h b/src/cache/ftcimage.h
index fbb2406..f493339 100644
--- a/src/cache/ftcimage.h
+++ b/src/cache/ftcimage.h
@@ -4,6 +4,9 @@
/* */
/* FreeType Image cache (body). */
/* */
+/* Each image cache really manages FT_Glyph objects :-) */
+/* */
+/* */
/* Copyright 2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
@@ -23,34 +26,157 @@
#include <freetype/cache/ftcglyph.h>
#include <freetype/ftglyph.h>
-
#ifdef __cplusplus
extern "C" {
#endif
- /* the FT_Glyph image "glyph node" type */
- typedef struct FTC_GlyphImageRec_
- {
- FTC_GlyphNodeRec root;
- FT_Glyph ft_glyph;
-
- } FTC_GlyphImageRec, *FTC_GlyphImage;
-
- /* the glyph image queue type */
- typedef struct FTC_ImageSetRec_
+ /*************************************************************************/
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** IMAGE CACHE OBJECT *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
+ /*************************************************************************/
+
+
+#define FTC_IMAGE_FORMAT( x ) ( (x) & 7 )
+
+ /*************************************************************************/
+ /* */
+ /* <Enum> */
+ /* FTC_Image_Type */
+ /* */
+ /* <Description> */
+ /* An enumeration used to list the types of glyph images found in a */
+ /* glyph image cache. */
+ /* */
+ /* <Fields> */
+ /* ftc_image_mono :: Monochrome bitmap glyphs. */
+ /* */
+ /* ftc_image_grays :: Anti-aliased bitmap glyphs. */
+ /* */
+ /* ftc_image_outline :: Scaled (and hinted) outline glyphs. */
+ /* */
+ /* ftc_master_outline :: Unscaled original outline glyphs. */
+ /* */
+ /* <Note> */
+ /* Other types may be defined in the future. */
+ /* */
+ typedef enum FTC_Image_Type_
{
- FTC_GlyphSetRec root;
- FTC_Image_Desc description;
-
- } FTC_ImageSetRec, *FTC_ImageSet;
-
-
- typedef struct FTC_Image_CacheRec_
+ ftc_image_format_bitmap = 0,
+ ftc_image_format_outline = 1,
+
+ ftc_image_flag_monochrome = 16,
+ ftc_image_flag_unhinted = 32,
+ ftc_image_flag_autohinted = 64,
+ ftc_image_flag_unscaled = 128,
+ ftc_image_flag_no_sbits = 256,
+
+ ftc_image_mono = ftc_image_format_bitmap |
+ ftc_image_flag_monochrome, /* monochrome bitmap */
+ ftc_image_grays = ftc_image_format_bitmap, /* anti-aliased bitmap */
+ ftc_image_outline = ftc_image_format_outline /* scaled outline */
+
+ } FTC_Image_Type;
+
+
+ /*************************************************************************/
+ /* */
+ /* <Struct> */
+ /* FTC_Image_Desc */
+ /* */
+ /* <Description> */
+ /* A simple structure used to describe a given glyph image category. */
+ /* */
+ /* <Fields> */
+ /* size :: An FTC_SizeRec used to describe the glyph's face & */
+ /* size. */
+ /* */
+ /* image_type :: The glyph image's type. */
+ /* */
+ typedef struct FTC_Image_Desc_
{
- FTC_Glyph_CacheRec root;
-
- } FTC_Image_CacheRec;
+ FTC_FontRec font;
+ FT_UInt image_type;
+
+ } FTC_Image_Desc;
+
+
+ /*************************************************************************/
+ /* */
+ /* <Type> */
+ /* FTC_Image_Cache */
+ /* */
+ /* <Description> */
+ /* A handle to an glyph image cache object. They are designed to */
+ /* hold many distinct glyph images, while not exceeding a certain */
+ /* memory threshold. */
+ /* */
+ typedef struct FTC_Image_CacheRec_* FTC_Image_Cache;
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FTC_Image_Cache_New */
+ /* */
+ /* <Description> */
+ /* Creates a new glyph image cache. */
+ /* */
+ /* <Input> */
+ /* manager :: The parent manager for the image cache. */
+ /* */
+ /* <Output> */
+ /* acache :: A handle to the new glyph image cache object. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_New( FTC_Manager manager,
+ FTC_Image_Cache* acache );
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FTC_Image_Cache_Lookup */
+ /* */
+ /* <Description> */
+ /* Retrieves a given glyph image from a glyph image cache. */
+ /* */
+ /* <Input> */
+ /* cache :: A handle to the source glyph image cache. */
+ /* */
+ /* desc :: A pointer to a glyph image descriptor. */
+ /* */
+ /* gindex :: The glyph index to retrieve. */
+ /* */
+ /* <Output> */
+ /* aglyph :: The corresponding FT_Glyph object. 0 in case of */
+ /* failure. */
+ /* */
+ /* <Return> */
+ /* error code, 0 means success */
+ /* */
+ /* <Note> */
+ /* the returned glyph is owned and manager by the glyph image cache. */
+ /* Never try to transform or discard it manually! You can however */
+ /* create a copy with FT_Glyph_Copy() and modify the new one. */
+ /* */
+ /* Because the glyph image cache limits the total amount of memory */
+ /* taken by the glyphs it holds, the returned glyph might disappear */
+ /* on a later invocation of this function! It's a cache after all... */
+ /* */
+ FT_EXPORT_DEF( FT_Error )
+ FTC_Image_Cache_Lookup( FTC_Image_Cache cache,
+ FTC_Image_Desc* desc,
+ FT_UInt gindex,
+ FT_Glyph* aglyph );
+
#ifdef __cplusplus
diff --git a/src/cache/ftcmanag.c b/src/cache/ftcmanag.c
index fe4664a..e1a9412 100644
--- a/src/cache/ftcmanag.c
+++ b/src/cache/ftcmanag.c
@@ -54,7 +54,8 @@
{
/* destroy initial size object; it will be re-created later */
face = (FT_Face)node->root.data;
- FT_Done_Size( face->size );
+ if (face->size)
+ FT_Done_Size( face->size );
}
return error;
@@ -310,6 +311,7 @@
FT_Lru_Reset( manager->sizes_lru );
FT_Lru_Reset( manager->faces_lru );
}
+ /* FIXME: flush the caches ?? */
}
@@ -400,15 +402,23 @@
manager->num_bytes -= clazz->size_node( cache_node,
- cache->cache_user );
+ cache->cache_data );
- clazz->destroy_node( cache_node, cache->cache_user );
+ clazz->destroy_node( cache_node, cache->cache_data );
}
else
{
/* this should never happen! */
FT_ERROR(( "FTC_Manager_Compress: Cache Manager is corrupted!\n" ));
}
+
+ /* check, just in case of general corruption :-) */
+ if (manager->num_nodes <= 0)
+ {
+ FT_ERROR(( "FTC_Manager_Compress: invalid cache node count !!\n" ));
+ }
+ else
+ manager->num_nodes--;
}
node = prev;
}
diff --git a/src/cache/ftcsbits.c b/src/cache/ftcsbits.c
index ab897d8..281b48b 100644
--- a/src/cache/ftcsbits.c
+++ b/src/cache/ftcsbits.c
@@ -1,9 +1,29 @@
-#include <cache/ftcsbits.h>
+#include <freetype/cache/ftcsbits.h>
+#include <freetype/fterrors.h>
+
+#define FTC_SBITSET_ELEMENT_COUNT 16
+
+
+ typedef struct FTC_SBitSetRec_
+ {
+ FTC_ChunkSetRec root;
+ FTC_Image_Desc desc;
+
+ } FTC_SBitSetRec, *FTC_SBitSet;
+
+
+ typedef struct FTC_SBit_CacheRec_
+ {
+ FTC_Chunk_CacheRec root;
+
+ } FTC_SBit_CacheRec;
+
+
/*************************************************************************/
/*************************************************************************/
/***** *****/
- /***** GLYPH IMAGE NODES *****/
+ /***** SBIT CACHE NODES *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
@@ -20,10 +40,13 @@
for ( ; count > 0; sbit++, count-- )
FREE( sbit->buffer );
+ FREE( node->elements );
FREE( node );
}
+
+
static
FT_Error ftc_bitmap_copy( FT_Memory memory,
FT_Bitmap* source,
@@ -48,12 +71,12 @@
LOCAL_FUNC_X
FT_Error ftc_sbit_chunk_node_new( FTC_ChunkSet cset,
FT_UInt index,
- FTC_SBitChunk *anode )
+ FTC_ChunkNode *anode )
{
FT_Error error;
FT_Memory memory = cset->memory;
FTC_SBitSet sbitset = (FTC_SBitSet)cset;
- FTC_SBitChunk node = 0;
+ FTC_ChunkNode node = 0;
FT_Face face;
FT_Size size;
@@ -63,86 +86,96 @@
goto Exit;
/* init its inner fields */
- error = FTC_ChunkNode_Init( FTC_CHUNKNODE(node), cset, index, 1 );
+ error = FTC_ChunkNode_Init( node, cset, index, 1 );
if (error)
goto Exit;
- /* we will now load all glyph images */
+ /* we will now load all glyph images for this chunk */
error = FTC_Manager_Lookup_Size( cset->manager,
- &sbitset->description.font,
+ &sbitset->desc.font,
&face, &size );
if ( !error )
{
- FT_UInt glyph_index = index * cset->chunk_size;
+ FT_UInt glyph_index = index * cset->element_count;
FT_UInt load_flags = FT_LOAD_DEFAULT;
- FT_UInt image_type = sbitset->description.image_type;
+ FT_UInt image_type = sbitset->desc.image_type;
FT_UInt count = node->num_elements;
FTC_SBit sbit = (FTC_SBit)node->elements;
-
- if ( FTC_IMAGE_FORMAT( image_type ) == ftc_image_format_bitmap )
- {
- if ( image_type & ftc_image_flag_monochrome )
- load_flags |= FT_LOAD_MONOCHROME;
-
- /* disable embedded bitmaps loading if necessary */
- if ( image_type & ftc_image_flag_no_sbits )
- load_flags |= FT_LOAD_NO_BITMAP;
- }
- else if ( FTC_IMAGE_FORMAT( image_type ) == ftc_image_format_outline )
+ /* determine load flags, depending on the font description's */
+ /* image type.. */
{
- /* disable embedded bitmaps loading */
- load_flags |= FT_LOAD_NO_BITMAP;
+ if ( FTC_IMAGE_FORMAT( image_type ) == ftc_image_format_bitmap )
+ {
+ if ( image_type & ftc_image_flag_monochrome )
+ load_flags |= FT_LOAD_MONOCHROME;
- if ( image_type & ftc_image_flag_unscaled )
+ /* disable embedded bitmaps loading if necessary */
+ if ( image_type & ftc_image_flag_no_sbits )
+ load_flags |= FT_LOAD_NO_BITMAP;
+ }
+ else
{
- FT_ERROR(( "FTC_SBit_Cache: cannot load vector outlines in a"
+ FT_ERROR(( "FTC_SBit_Cache: cannot load scalable glyphs in a"
" sbit cache, please check your arguments !!\n" ));
- error = FT_Err_Bad_Argument;
+ error = FT_Err_Invalid_Argument;
goto Exit;
}
- }
- /* always render glyphs to bitmaps */
- load_flags |= FT_LOAD_RENDER;
+ /* always render glyphs to bitmaps */
+ load_flags |= FT_LOAD_RENDER;
- if ( image_type & ftc_image_flag_unhinted )
- load_flags |= FT_LOAD_NO_HINTING;
+ if ( image_type & ftc_image_flag_unhinted )
+ load_flags |= FT_LOAD_NO_HINTING;
- if ( image_type & ftc_image_flag_autohinted )
- load_flags |= FT_LOAD_FORCE_AUTOHINT;
+ if ( image_type & ftc_image_flag_autohinted )
+ load_flags |= FT_LOAD_FORCE_AUTOHINT;
+ }
/* load a chunk of small bitmaps in a row */
- for ( ; count > 0; count--, glyph_index++ )
+ for ( ; count > 0; count--, glyph_index++, sbit++ )
{
+ /* by default, indicates a "missing" glyph */
+ sbit->buffer = 0;
+
error = FT_Load_Glyph( face, glyph_index, load_flags );
if (!error)
{
FT_Int temp;
FT_GlyphSlot slot = face->glyph;
FT_Bitmap* bitmap = &slot->bitmap;
- FT_Int advance;
+ FT_Int xadvance, yadvance;
- /* check that our values fit in 8-bit containers !! */
-#define CHECK_SCHAR(d) ( temp = (FT_SChar)d, temp == d )
-#define CHECK_BYTE(d) ( temp = (FT_Byte) d, temp == d )
+ /* check that our values fit in 8-bit containers !! */
+ /* if this is not the case, our bitmap is too large */
+ /* and we will leave it as "missing" with sbit.buffer = 0 */
+
+#define CHECK_CHAR(d) ( temp = (FT_Char)d, temp == d )
+#define CHECK_BYTE(d) ( temp = (FT_Byte)d, temp == d )
- advance = (slot->metrics.horiAdvance+32) >> 6;
+ /* FIXME: add support for vertical layouts maybe.. */
+
+ /* horizontal advance in pixels */
+ xadvance = (slot->metrics.horiAdvance+32) >> 6;
+ yadvance = (slot->metrics.vertAdvance+32) >> 6;
if ( CHECK_BYTE ( bitmap->rows ) &&
CHECK_BYTE ( bitmap->width ) &&
- CHECK_SCHAR( bitmap->pitch ) &&
- CHECK_SCHAR( slot->bitmap_left ) &&
- CHECK_SCHAR( slot->bitmap_top ) &&
- CHECK_SCHAR( advance ) )
+ CHECK_CHAR ( bitmap->pitch ) &&
+ CHECK_CHAR ( slot->bitmap_left ) &&
+ CHECK_CHAR ( slot->bitmap_top ) &&
+ CHECK_CHAR ( xadvance ) &&
+ CHECK_CHAR ( yadvance ) )
{
- sbit->width = (FT_Byte) bitmap->width;
- sbit->height = (FT_Byte) bitmap->height;
- sbit->pitch = (FT_SChar)bitmap->pitch;
- sbit->left = (FT_SChar)slot->bitmap_left;
- sbit->top = (FT_SChar)slot->bitmap_top;
- sbit->advance = (FT_SChar)advance;
+ sbit->width = (FT_Byte) bitmap->width;
+ sbit->height = (FT_Byte) bitmap->rows;
+ sbit->pitch = (FT_Char) bitmap->pitch;
+ sbit->left = (FT_Char) slot->bitmap_left;
+ sbit->top = (FT_Char) slot->bitmap_top;
+ sbit->xadvance = (FT_Char) xadvance;
+ sbit->yadvance = (FT_Char) yadvance;
+ sbit->format = (FT_Byte) bitmap->pixel_mode;
/* grab the bitmap when possible */
if ( slot->flags & ft_glyph_own_bitmap )
@@ -157,8 +190,6 @@
}
}
}
- else
- sbit->buffer = 0;
}
/* ignore the errors that might have occured there */
@@ -179,46 +210,33 @@
/* this function is important because it is both part of */
- /* a FTC_ChunkSet_Class and a FTC_CacheNode_Class */
+ /* a FTC_ChunkSet_Class and a FTC_CacheNode_Class */
/* */
LOCAL_FUNC_X
- FT_ULong ftc_sbit_chunk_node_size( FTC_SBitChunk node )
+ FT_ULong ftc_sbit_chunk_node_size( FTC_ChunkNode node )
{
- FT_ULong size = 0;
- FT_Glyph glyph = node->ft_glyph;
+ FT_ULong size;
+ FTC_ChunkSet cset = node->cset;
+ FT_UInt count = node->num_elements;
+ FT_Int pitch;
+ FTC_SBit sbit = (FTC_SBit)node->elements;
+ size = sizeof (*node); /* the node itself */
+ size += cset->element_count * sizeof(FTC_SBitRec); /* the sbit recors */
- switch ( glyph->format )
+ for ( ; count > 0; count--, sbit++ )
{
- case ft_glyph_format_bitmap:
- {
- FT_BitmapGlyph bitg;
-
-
- bitg = (FT_BitmapGlyph)glyph;
- size = bitg->bitmap.rows * labs( bitg->bitmap.pitch ) +
- sizeof ( *bitg );
- }
- break;
-
- case ft_glyph_format_outline:
+ if (sbit->buffer)
{
- FT_OutlineGlyph outg;
-
-
- outg = (FT_OutlineGlyph)glyph;
- size = outg->outline.n_points *
- ( sizeof( FT_Vector ) + sizeof ( FT_Byte ) ) +
- outg->outline.n_contours * sizeof ( FT_Short ) +
- sizeof ( *outg );
+ pitch = sbit->pitch;
+ if (pitch < 0)
+ pitch = -pitch;
+
+ /* add the size of a given glyph image */
+ size += pitch * sbit->height;
}
- break;
-
- default:
- ;
}
- size += sizeof ( *node );
return size;
}
@@ -226,26 +244,47 @@
/*************************************************************************/
/*************************************************************************/
/***** *****/
- /***** GLYPH IMAGE QUEUES *****/
+ /***** SBIT CHUNK SETS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
LOCAL_FUNC_X
- FT_Error ftc_image_set_init( FTC_ImageSet iset,
- FTC_Image_Desc* type )
+ FT_Error ftc_sbit_chunk_set_sizes( FTC_ChunkSet cset,
+ FTC_Image_Desc* desc )
{
- iset->description = *type;
+ FT_Error error;
+ FT_Face face;
+
+ cset->element_count = FTC_SBITSET_ELEMENT_COUNT;
+ cset->element_size = sizeof(FTC_SBitRec);
+
+ /* lookup the FT_Face to obtain the number of glyphs */
+ error = FTC_Manager_Lookup_Face( cset->manager,
+ &desc->font, &face );
+ if (!error)
+ cset->element_max = face->num_glyphs;
+
+ return error;
+ }
+
+
+
+ LOCAL_FUNC_X
+ FT_Error ftc_sbit_chunk_set_init( FTC_SBitSet sset,
+ FTC_Image_Desc* type )
+ {
+ sset->desc = *type;
return 0;
}
LOCAL_FUNC_X
- FT_Bool ftc_image_set_compare( FTC_ImageSet iset,
- FTC_Image_Desc* type )
+ FT_Bool ftc_sbit_chunk_set_compare( FTC_SBitSet sset,
+ FTC_Image_Desc* type )
{
- return !memcmp( &iset->description, type, sizeof ( *type ) );
+ return !memcmp( &sset->desc, type, sizeof ( *type ) );
}
@@ -253,79 +292,83 @@
{
sizeof( FTC_ImageSetRec ),
- (FTC_ChunkSet_InitFunc) ftc_image_set_init,
- (FTC_ChunkSet_DoneFunc) 0,
- (FTC_ChunkSet_CompareFunc) ftc_image_set_compare,
+ (FTC_ChunkSet_InitFunc) ftc_sbit_chunk_set_init,
+ (FTC_ChunkSet_DoneFunc) 0,
+ (FTC_ChunkSet_CompareFunc) ftc_sbit_chunk_set_compare,
+ (FTC_ChunkSet_SizesFunc) ftc_sbit_chunk_set_sizes,
- (FTC_ChunkSet_NewNodeFunc) ftc_sbit_chunk_node_new,
- (FTC_ChunkSet_SizeNodeFunc) ftc_sbit_chunk_node_size,
- (FTC_ChunkSet_DestroyNodeFunc)ftc_sbit_chunk_node_destroy
+ (FTC_ChunkSet_NewNodeFunc) ftc_sbit_chunk_node_new,
+ (FTC_ChunkSet_SizeNodeFunc) ftc_sbit_chunk_node_size,
+ (FTC_ChunkSet_DestroyNodeFunc) ftc_sbit_chunk_node_destroy
};
/*************************************************************************/
/*************************************************************************/
/***** *****/
- /***** GLYPH IMAGE CACHE *****/
+ /***** SBITS CACHE *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
- FT_CPLUSPLUS( const FTC_Glyph_Cache_Class ) ftc_sbit_chunk_cache_class =
+ FT_CPLUSPLUS( const FTC_Chunk_Cache_Class ) ftc_sbit_cache_class =
{
{
- sizeof( FTC_Image_CacheRec ),
- (FTC_Cache_InitFunc) FTC_Glyph_Cache_Init,
- (FTC_Cache_DoneFunc) FTC_Glyph_Cache_Done
+ sizeof( FTC_SBit_CacheRec ),
+ (FTC_Cache_InitFunc) FTC_Chunk_Cache_Init,
+ (FTC_Cache_DoneFunc) FTC_Chunk_Cache_Done
},
(FTC_ChunkSet_Class*) &ftc_sbit_chunk_set_class
};
- FT_EXPORT_FUNC( FT_Error ) FTC_Image_Cache_New( FTC_Manager manager,
- FTC_Image_Cache* acache )
+ FT_EXPORT_FUNC( FT_Error )
+ FTC_SBit_Cache_New( FTC_Manager manager,
+ FTC_SBit_Cache* acache )
{
return FTC_Manager_Register_Cache(
manager,
- (FTC_Cache_Class*)&ftc_sbit_chunk_cache_class,
+ (FTC_Cache_Class*)&ftc_sbit_cache_class,
(FTC_Cache*)acache );
}
FT_EXPORT_DEF( FT_Error )
- FTC_Image_Cache_Lookup( FTC_Image_Cache cache,
- FTC_Image_Desc* desc,
- FT_UInt gindex,
- FT_Glyph* aglyph )
+ FTC_SBit_Cache_Lookup( FTC_SBit_Cache cache,
+ FTC_Image_Desc* desc,
+ FT_UInt gindex,
+ FTC_SBit *asbit )
{
FT_Error error;
- FTC_ChunkSet gset;
- FTC_GlyphNode node;
+ FTC_ChunkSet cset;
+ FTC_ChunkNode node;
+ FT_UInt cindex;
FTC_Manager manager;
- FTC_ImageSet img_set;
+ FTC_SBitSet sset;
+ FTC_SBit sbit;
/* check for valid `desc' delayed to FT_Lru_Lookup() */
- if ( !cache || !aglyph )
+ if ( !cache || !asbit )
return FT_Err_Invalid_Argument;
- *aglyph = 0;
- gset = cache->root.last_gset;
- img_set = (FTC_ImageSet)gset;
- if ( !gset || memcmp( &img_set->description, desc, sizeof ( *desc ) ) )
+ *asbit = 0;
+ cset = cache->root.last_cset;
+ sset = (FTC_SBitSet)cset;
+ if ( !cset || memcmp( &sset->desc, desc, sizeof ( *desc ) ) )
{
- error = FT_Lru_Lookup( cache->root.gsets_lru,
+ error = FT_Lru_Lookup( cache->root.csets_lru,
(FT_LruKey)desc,
- (FT_Pointer*)&gset );
- cache->root.last_gset = gset;
+ (FT_Pointer*)&cset );
+ cache->root.last_cset = cset;
if ( error )
goto Exit;
}
- error = FTC_ChunkSet_Lookup_Node( gset, gindex, &node );
+ error = FTC_ChunkSet_Lookup_Node( cset, gindex, &node, &cindex );
if ( error )
goto Exit;
@@ -333,12 +376,19 @@
manager = cache->root.root.manager;
if ( manager->num_bytes > manager->max_bytes )
{
- FTC_GlyphNode_Ref ( node );
+ FTC_ChunkNode_Ref ( node );
FTC_Manager_Compress( manager );
- FTC_GlyphNode_Unref ( node );
+ FTC_ChunkNode_Unref ( node );
}
- *aglyph = ((FTC_SBitChunk)node)->ft_glyph;
+ sbit = ((FTC_SBit)((FTC_ChunkNode)node)->elements) + cindex;
+ if (sbit->buffer == 0)
+ {
+ /* the glyph was missing, we return a NULL pointer !! */
+ sbit = 0;
+ }
+
+ *asbit = sbit;
Exit:
return error;
diff --git a/src/cache/ftcsbits.h b/src/cache/ftcsbits.h
deleted file mode 100644
index 9e395ec..0000000
--- a/src/cache/ftcsbits.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/***************************************************************************/
-/* */
-/* ftcsbits.h */
-/* */
-/* a small-bitmaps cache (specification). */
-/* */
-/* Copyright 2000 by */
-/* David Turner, Robert Wilhelm, and Werner Lemberg. */
-/* */
-/* This file is part of the FreeType project, and may only be used, */
-/* modified, and distributed under the terms of the FreeType project */
-/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
-/* this file you indicate that you have read the license and */
-/* understand and accept it fully. */
-/* */
-/***************************************************************************/
-
-#ifndef FTCSBITS_H
-#define FTCSBITS_H
-
-#include <freetype/cache/ftcchunk.h>
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
- /* handle to small bitmap */
- typedef struct FTC_SBitRec_* FTC_SBit;
-
-
- /* handle to small bitmap cache */
- typedef struct FTC_SBit_CacheRec_* FTC_SBit_Cache;
-
-
- /* format of small bitmaps */
- typedef enum FTC_SBit_Format_
- {
- ftc_sbit_format_mono = 0,
- ftc_sbit_format_aa256 = 1,
-
- } FTC_SBit_Format;
-
-
- /* a compact structure used to hold a single small bitmap */
- typedef struct FTC_SBitRec_
- {
- FT_Byte width;
- FT_Byte height;
- FT_SChar left;
- FT_SChar top;
-
- FT_Byte format;
- FT_SChar pitch;
- FT_SChar xadvance;
- FT_SChar yadvance;
-
- FT_Byte* buffer;
-
- } FTC_SBitRec;
-
-
- typedef struct FTC_SBitSetRec_
- {
- FTC_ChunkSetRec root;
- FTC_Image_Desc desc;
-
- } FTC_SBitSet;
-
-
- typedef struct FTC_SBit_CacheRec_
- {
- FTC_Chunk_CacheRec root;
-
- } FTC_SBit_CacheRec;
-
-
-
- FT_EXPORT_DEF( FT_Error )
- FTC_SBit_Cache_New( FTC_Manager manager,
- FTC_SBit_Cache *acache );
-
-
- FT_EXPORT_DEF( FT_Error )
- FTC_SBit_Cache_Lookup( FTC_SBit_Cache cache,
- FTC_Image_Desc* desc,
- FTC_SBit *sbit );
-
-
-#ifdef __cplusplus
- }
-#endif
-
-
-#endif /* FTCSBITS_H */
-
-/* END */
-