1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188
|
/* ===EmacsMode: -*- Mode: C; tab-width:4; c-basic-offset: 4; -*- === */
/* ===FileName: ===
Copyright (c) 1998 Go Watanabe, All rights reserved.
Copyright (c) 1998 Kazushi (Jam) Marukawa, All rights reserved.
Copyright (c) 1998 Takuya SHIOZAKI, All rights reserved.
Copyright (c) 1998 X-TrueType Server Project, All rights reserved.
===Notice
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Major Release ID: X-TrueType Server Version 1.3 [Aoi MATSUBARA Release 3]
Notice===
*/
/* $XFree86: xc/extras/X-TrueType/xttfuncs.c,v 1.17 2003/02/17 03:59:22 dawes Exp $ */
#include "xttversion.h"
static char const * const releaseID =
_XTT_RELEASE_NAME;
/*
X-TrueType Server -- invented by Go Watanabe.
This Version includes the follow feautures:
JAMPATCHs:
written by Kazushi (Jam) Marukawa.
CodeConv:
Moduled CodeConv:
TTCap:
written by Takuya SHIOZAKI.
*/
#ifndef FONTMODULE
#include <X11/Xos.h>
#endif
#include <X11/X.h>
#include "fntfilst.h"
#include "xttcommon.h"
#include "xttcap.h"
#include "xttcconv.h"
#include "xttstruct.h"
/*
* Any bit blitters are not included in FreeType 1.x.
* Because bitmap glyph is visible for client aplictions and
* FreeType is not provide any text renderers.
*/
#include "xttblit.h"
/*
* macros
*/
#ifndef ABS
#define ABS(a) (((a)<0)?-(a):(a))
#endif
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
#define FLOOR64(x) ((x) & -64)
#define CEIL64(x) (((x) + 64 - 1) & -64)
#define XTT_PROPORTIONAL_SPACING 1
#define XTT_MONOSPACED 0
#define XTT_CONSTANT_SPACING -1
#define IS_TT_Matrix_Unit(matrix) \
(((matrix).xx == 65536) && ((matrix).yx == 0) && \
((matrix).xy == 0 ) && ((matrix).yy == 65536))
/*
* prototypes
*/
/* from lib/font/fontfile/defaults.c */
extern void
FontDefaultFormat(int *bit, int *byte, int *glyph, int *scan);
/* from lib/font/fontfile/renderers.c */
extern Bool
FontFileRegisterRenderer(FontRendererPtr renderer);
/* from lib/font/util/format.c */
extern int
CheckFSFormat(fsBitmapFormat format, fsBitmapFormatMask fmask,
int *bit_order, int *byte_order, int *scan,
int *glyph, int *image);
/* from lib/font/util/fontaccel.c */
extern void
FontComputeInfoAccelerators(FontInfoPtr pFontInfo);
static int FreeType_InitCount = 0;
static TT_Engine engine;
struct xtt_char_width {
int pixel; /* pixel */
int raw; /* 1000 pixel */
};
static int
FreeType_Init(void)
{
dprintf((stderr, "FreeTypeInit\n"));
if (FreeType_InitCount == 0) {
if (TT_Init_FreeType(&engine)) {
fprintf(stderr, "freetype: Could not create engine instance\n");
return -1;
}
if (TT_Init_SBit_Extension(engine))
fprintf(stderr, "freetype: This engine is not provided sbit extension\n");
}
FreeType_InitCount++;
return 0;
}
static int
FreeType_Deinit(void)
{
dprintf((stderr, "FreeTypeDeInit\n"));
if (FreeType_InitCount <= 0) {
return -1;
}
if (--FreeType_InitCount == 0) {
if (TT_Done_FreeType(engine) < 0) {
return -1;
}
}
return 0;
}
static FreeTypeFaceInfo *faceTable = NULL;
static int faceTableCount = 0;
static int
FreeType_OpenFace(FreeTypeOpenFaceHints const *refHints)
{
int i, error, num;
TT_Face face;
TT_Face_Properties prop;
TT_Glyph glyph;
TT_SBit_Image* sbit;
FreeTypeFaceInfoPtr ptr;
dprintf((stderr,
"FreeType_OpenFace: %s %s %s\n",
refHints->fontName, refHints->familyName, refHints->ttFontName));
if ((error = TT_Open_Face(engine, refHints->ttFontName, &face))) {
fprintf(stderr, "freetype: can't open face: %s\n", refHints->ttFontName);
return -1;
}
if ((error = TT_Get_Face_Properties(face, &prop))) {
TT_Close_Face(face);
fprintf(stderr, "freetype: can't get face property.\n");
return -1;
}
if ( refHints->ttcno ) {
TT_Close_Face(face);
if ( refHints->ttcno<0 || refHints->ttcno>=prop.num_Faces ) {
fprintf(stderr, "Bad face collection:%d\n", refHints->ttcno);
return -1;
}
if ((error = TT_Open_Collection(engine, refHints->ttFontName,
refHints->ttcno, &face))) {
fprintf(stderr, "Can't Open face collection:%d\n",
refHints->ttcno);
return -1;
}
}
dprintf((stderr, "Select Collection %d\n", refHints->ttcno));
/* check !! */
for (i = 0; i < faceTableCount; i++) {
if (strcmp(faceTable[i].fontName, refHints->fontName) == 0 &&
faceTable[i].ttcno == refHints->ttcno) {
/* reopen */
if (faceTable[i].flag) {
if ((error = TT_Get_Face_Properties(face, &prop))) {
TT_Close_Face(face);
fprintf(stderr, "freetype: can't get face property.\n");
return -1;
}
if ((num = TT_Get_CharMap_Count(face)) < 0) {
TT_Close_Face(face);
fprintf(stderr, "freetype: can't get charmap count.\n");
return -1;
}
if ((error = TT_New_Glyph(face, &glyph))) {
TT_Close_Face(face);
fprintf(stderr, "freetype: can't get new glyph.\n");
return -1;
}
{
/* check and initialize support stuffs for sbit extesion */
TT_EBLC eblc; /* fake */
if (!TT_Get_Face_Bitmaps(face, &eblc)) {
if ((error = TT_New_SBit_Image(&sbit))) {
TT_Close_Face(face);
fprintf(stderr,
"freetype: can't get new sbit image.\n");
return -1;
}
} else
sbit = NULL;
}
faceTable[i].face = face;
faceTable[i].ttcno = refHints->ttcno;
faceTable[i].prop = prop;
faceTable[i].glyph = glyph;
faceTable[i].sbit = sbit;
faceTable[i].mapnum = num;
faceTable[i].flag = 0;
} else
TT_Close_Face(face);
faceTable[i].refCount++;
return i;
}
}
dprintf((stderr, "No Face. Make New Face\n"));
if (!(ptr = (FreeTypeFaceInfoPtr)
xrealloc(faceTable, (faceTableCount+1) * sizeof(*ptr)))){
fprintf(stderr, "xrealloc: can't alloc memory for fonttable\n");
return -1;
}
if ((error = TT_Get_Face_Properties(face, &prop))) {
TT_Close_Face(face);
fprintf(stderr, "freetype: can't get face property.\n");
return -1;
}
if ((num = TT_Get_CharMap_Count(face)) < 0) {
TT_Close_Face(face);
fprintf(stderr, "freetype: can't get charmap count.\n");
return -1;
}
if ((error = TT_New_Glyph(face, &glyph))) {
TT_Close_Face(face);
fprintf(stderr, "freetype: can't get new glyph.\n");
return -1;
}
{
/* check support stuff for sbit extesion */
TT_EBLC eblc; /* use only for checking the stuff */
if (!TT_Get_Face_Bitmaps(face, &eblc)) {
if ((error = TT_New_SBit_Image(&sbit))) {
TT_Close_Face(face);
fprintf(stderr, "freetype: can't get new sbit image.\n");
return -1;
}
} else
sbit = NULL;
}
faceTable = ptr;
faceTable[faceTableCount].fontName = xstrdup(refHints->fontName);
faceTable[faceTableCount].ttcno = refHints->ttcno;
faceTable[faceTableCount].refCount = 1;
faceTable[faceTableCount].face = face;
faceTable[faceTableCount].prop = prop;
faceTable[faceTableCount].glyph = glyph;
faceTable[faceTableCount].sbit = sbit;
faceTable[faceTableCount].mapnum = num;
faceTable[faceTableCount].flag = 0;
i = faceTableCount++;
return i;
}
static int
FreeType_CloseFace(int index)
{
dprintf((stderr, "FreeType_CloseFace: %d\n", index));
if (index < faceTableCount) {
if (faceTable[index].refCount <= 0) {
fprintf(stderr, "FreeType_CloseFace: bad index\n");
return -1;
}
if (--faceTable[index].refCount == 0) {
TT_Done_Glyph(faceTable[index].glyph);
if (faceTable[index].sbit)
TT_Done_SBit_Image(faceTable[index].sbit);
TT_Close_Face(faceTable[index].face);
faceTable[index].flag = -1;
}
return 0;
}
fprintf(stderr, "FreeType_CloseFace: bad index\n");
return -1;
}
static void
convertNothing(FreeTypeFont *ft, unsigned char *p, int size)
{
}
static void
convertBitOrder(FreeTypeFont *ft, unsigned char *p, int size)
{
extern void
BitOrderInvert(register unsigned char *buf, register int nbytes);
BitOrderInvert(p, size);
}
static void
convertByteOrder(FreeTypeFont *ft, unsigned char *p, int size)
{
extern void TwoByteSwap(register unsigned char *buf, register int nbytes);
extern void FourByteSwap(register unsigned char *buf, register int nbytes);
if (ft->pFont->bit != ft->pFont->byte) {
switch (ft->pFont->scan) {
case 1:
break;
case 2:
TwoByteSwap(p, size);
case 4:
FourByteSwap(p, size);
}
}
}
static void
convertBitByteOrder(FreeTypeFont *ft, unsigned char *p, int size)
{
convertBitOrder(ft, p, size);
convertByteOrder(ft, p, size);
}
static int
FreeType_OpenFont(FreeTypeFont *ft,
FontScalablePtr vals, int glyph,
FreeTypeOpenFaceHints const *refHints)
{
int mapID, fid, error, result;
FreeTypeFaceInfo *fi;
TT_Instance instance;
double base_size;
int num_faces = 0, linesize;
base_size = hypot(vals->point_matrix[2], vals->point_matrix[3]);
result = Successful;
fid = -1;
if (FreeType_Init()< 0) {
result = AllocError;
goto abort;
}
if ((ft->fid = fid = FreeType_OpenFace(refHints)) < 0) {
result = BadFontName;
goto deinitQuit;
}
fi = &faceTable[fid];
if (!codeconv_search_code_converter(refHints->charsetName,
fi->face, fi->mapnum,
refHints->refListPropRecVal,
&ft->codeConverterInfo,
&mapID)) {
fprintf(stderr,
"FreeType_OpenFont: don't match charset %s\n",
refHints->charsetName);
result = BadFontName;
goto deinitQuit;
}
TT_Get_CharMap(fi->face, mapID, &ft->charmap);
/* create instance */
if ((error = TT_New_Instance(fi->face, &instance))) {
result = BadFontName;
goto deinitQuit;
}
/* set resolution of instance */
if ((error = TT_Set_Instance_Resolutions(instance,
(int)vals->x, (int)vals->y))) {
result = BadFontName;
goto doneInstQuit;
}
{
int flRotated = 0, flStretched = 0;
if (vals->point_matrix[1] != 0 || vals->point_matrix[2] != 0)
flRotated = flStretched = 1;
else if (vals->point_matrix[0] != vals->point_matrix[3])
flStretched = 1;
else if (ft->scaleWidth != 1.0)
flStretched = 1;
TT_Set_Instance_Transform_Flags(instance, flRotated, flStretched);
/*
* The size depend on the height, not the width.
* So use point_matrix[3].
*/
if ((error = TT_Set_Instance_CharSize(instance,
base_size *64))) {
result = BadFontName;
goto doneInstQuit;
}
/* set matrix */
ft->matrix.xx =
ft->scaleWidth *
vals->point_matrix[0] / base_size * 65536;
ft->matrix.xy =
ft->scaleWidth *
vals->point_matrix[2] / base_size * 65536;
ft->matrix.yx =
vals->point_matrix[1] / base_size * 65536;
ft->matrix.yy =
vals->point_matrix[3] / base_size * 65536;
dprintf((stderr, "matrix: %x %x %x %x\n",
ft->matrix.xx,
ft->matrix.yx,
ft->matrix.xy,
ft->matrix.yy));
}
ft->instance = instance;
TT_Get_Instance_Metrics(instance, &ft->imetrics);
num_faces = fi->prop.num_Faces;
if (num_faces == 0) {
num_faces = 1;
}
if ((fi->prop.num_Glyphs / num_faces) > 256) {
linesize = 128;
} else {
linesize = 16;
}
if ((ft->cache = FontCacheOpenCache((void *)(long) linesize)) == NULL) {
result = AllocError;
goto doneInstQuit;
}
return result;
doneInstQuit:
TT_Done_Instance(instance);
deinitQuit:
if (fid>=0)
FreeType_CloseFace(fid);
FreeType_Deinit();
abort:
return result;
}
static void
FreeType_CloseFont(FontPtr pFont)
{
FreeTypeFont *ft = (FreeTypeFont*) pFont->fontPrivate;
dprintf((stderr, "FreeType_CloseFont: %x\n", pFont));
TT_Done_Instance(ft->instance);
FontCacheCloseCache(ft->cache);
FreeType_CloseFace(ft->fid);
FreeType_Deinit();
codeconv_free_code_converter(&ft->codeConverterInfo);
xfree(ft);
xfree(pFont->info.props);
}
static char nochardat;
static CharInfoRec nocharinfo = {/*metrics*/{0,0,0,0,0,0},
/*bits*/&nochardat};
/*
* Pseudo enbolding similar as Microsoft Windows.
* It is useful but poor.
*/
static void
make_up_bold_bitmap(TT_Raster_Map *map)
{
int x, y;
char *p = (char *)map->bitmap;
for (y=0; y<map->rows; y++) {
char lsb = 0;
for (x=0; x<map->cols; x++) {
char tmp = *p<<7;
*p |= (*p>>1) | lsb;
lsb = tmp;
p++;
}
}
}
/* font cache private area */
struct fc_tt_private {
int shift;
};
static void
fc_tt_private_dispose(void *f_private)
{
if ( f_private )
xfree(f_private);
}
static struct fc_entry_vfuncs fc_tt_vfuncs = {
&fc_tt_private_dispose /* f_private_dispose */
};
#define FC_TT_INIT_PRIVATE(entry) \
{ \
(entry)->f_private = xalloc(sizeof(struct fc_tt_private)); \
memset((entry)->f_private, 0, sizeof(struct fc_tt_private)); \
}
#define FC_TT_PRIVATE(entry) ((struct fc_tt_private *)((entry)->f_private))
#define FC_TT_SETVFUNC(entry) ((void)((entry)->vfuncs=&fc_tt_vfuncs))
/* calculate glyph metric from glyph index */
static xCharInfo *
get_metrics(FreeTypeFont *ft, int c, struct xtt_char_width char_width)
{
FreeTypeFaceInfo *fi = &faceTable[ft->fid];
FontCacheEntryPtr entry;
CharInfoPtr charInfo;
int width, ascent, descent;
int lbearing, rbearing;
TT_Glyph_Metrics metrics;
TT_BBox* bbox = &metrics.bbox;
/*
* Check invalid char index.
*/
if ( c < 0 ) {
charInfo = &nocharinfo;
goto next;
}
if (!FontCacheSearchEntry(ft->cache, c, &entry)) {
if (!ft->isVeryLazy) {
/*
* load sbit's metrics.
* load outline's metrics if fails now.
* But it is better that we are able to select
* another way, i.e. load NULL glyph if fails.
*/
if ( fi->sbit &&
IS_TT_Matrix_Unit(ft->matrix) &&
ft->isEmbeddedBitmap ) {
if ( TT_Load_Glyph_Bitmap(fi->face, ft->instance, c,
fi->sbit) ) {
fi->sbit->map.size = 0;
} else {
metrics.bbox = fi->sbit->metrics.bbox;
metrics.bearingX = fi->sbit->metrics.horiBearingX;
metrics.bearingY = fi->sbit->metrics.horiBearingY;
metrics.advance = fi->sbit->metrics.horiAdvance;
}
} else
if ( fi->sbit )
fi->sbit->map.size = 0;
if ( (!fi->sbit) || (!fi->sbit->map.size) ) {
/* load outline's metrics */
TT_Load_Glyph(ft->instance, fi->glyph, c, ft->flag);
TT_Get_Glyph_Metrics(fi->glyph, &metrics);
{
TT_Outline outline;
TT_Get_Glyph_Outline(fi->glyph, &outline);
outline.dropout_mode = 2;
TT_Transform_Outline(&outline, &ft->matrix);
TT_Get_Outline_BBox(&outline, bbox);
}
}
} else {
/*
* very lazy method,
* parse the htmx field in TrueType font.
*/
TT_Vector p0, p1, p2, p3;
{
/* horizontal */
TT_Short leftBearing = 0;
TT_UShort advance = 0;
TT_Get_Face_Metrics(fi->face, c, c,
&leftBearing, &advance,
NULL, NULL);
bbox->xMax = metrics.advance =
TT_MulFix( advance, ft->imetrics.x_scale );
bbox->xMin = metrics.bearingX =
TT_MulFix( leftBearing, ft->imetrics.x_scale );
}
{
/* vertical */
TT_Header *pH = fi->prop.header;
bbox->yMin = TT_MulFix( pH->yMin,
ft->imetrics.y_scale );
bbox->yMax = TT_MulFix( pH->yMax,
ft->imetrics.y_scale );
}
p0.x = p2.x = bbox->xMin;
p1.x = p3.x = bbox->xMax;
p0.y = p1.y = bbox->yMin;
p2.y = p3.y = bbox->yMax;
TT_Transform_Vector(&p0.x, &p0.y, &ft->matrix);
TT_Transform_Vector(&p1.x, &p1.y, &ft->matrix);
TT_Transform_Vector(&p2.x, &p2.y, &ft->matrix);
TT_Transform_Vector(&p3.x, &p3.y, &ft->matrix);
#if 0
fprintf(stderr,
"(%.1f %.1f) (%.1f %.1f)"
"(%.1f %.1f) (%.1f %.1f)\n",
p0.x / 64.0, p0.y / 64.0,
p1.x / 64.0, p1.y / 64.0,
p2.x / 64.0, p2.y / 64.0,
p3.x / 64.0, p3.y / 64.0);
#endif
bbox->xMin = MIN(p0.x, MIN(p1.x, MIN(p2.x, p3.x)));
bbox->xMax = MAX(p0.x, MAX(p1.x, MAX(p2.x, p3.x)));
bbox->yMin = MIN(p0.y, MIN(p1.y, MIN(p2.y, p3.y)));
bbox->yMax = MAX(p0.y, MAX(p1.y, MAX(p2.y, p3.y)));
{
TT_SBit_Strike strike;
/*
* We use TTCap but it is naive.
* It has better provide another calculation way.
*/
double sbit_scale = ft->scaleBitmap;
TT_Pos bbox_width = bbox->xMax - bbox->xMin;
TT_Pos add_width;
/* parse sbit entry */
if (!TT_Get_SBit_Strike(fi->face, ft->instance, &strike)) {
TT_SBit_Range* range = strike.sbit_ranges;
TT_SBit_Range* limit = range + strike.num_ranges;
while((range<limit) &&
(range->first_glyph <= c) &&
(c <= range->last_glyph ))
range++;
if (range<limit) {
add_width = bbox_width * (sbit_scale - 1);
bbox->xMin -= add_width / 2;
bbox->xMax += add_width / 2;
}
}
}
}
/*
* Use floor64 and ceil64 to calulate exectly since values might
* be minus.
*/
ascent = FLOOR64(bbox->yMax + 32) / 64;
descent = CEIL64(-bbox->yMin - 32) / 64;
lbearing = FLOOR64(bbox->xMin + 32) / 64;
rbearing = FLOOR64(bbox->xMax + 32) / 64 + (ft->isDoubleStrike?1:0);
width = FLOOR64((int)floor(metrics.advance * ft->scaleBBoxWidth
* ft->pixel_width_unit_x + .5) + 32) / 64;
if ((entry = FontCacheGetEntry()) == NULL) {
charInfo = &nocharinfo;
fprintf(stderr, "get_metrics: can't get cache entry\n");
goto next;
}
FC_TT_SETVFUNC(entry);
FC_TT_INIT_PRIVATE(entry);
charInfo = &entry->charInfo;
/* monospaced */
if ( char_width.pixel && width) {
/* XXX */
FC_TT_PRIVATE(entry)->shift = (char_width.pixel - width) / 2;
/* Shift to "correct" position. */
lbearing += FC_TT_PRIVATE(entry)->shift;
rbearing += FC_TT_PRIVATE(entry)->shift;
/* when char_width < 0 ??? */
/* It is always lbearing < rbeaing */
if (rbearing - lbearing <= char_width.pixel) {
if (lbearing < 0) {
rbearing -= lbearing;
FC_TT_PRIVATE(entry)->shift -= lbearing;
lbearing = 0;
}
if (rbearing > char_width.pixel) {
lbearing -=
(rbearing - char_width.pixel);
FC_TT_PRIVATE(entry)->shift -=
(rbearing - char_width.pixel);
rbearing = char_width.pixel;
}
}
width = char_width.pixel;
}
charInfo->metrics.leftSideBearing = lbearing;
charInfo->metrics.rightSideBearing = rbearing;
charInfo->metrics.ascent = ascent;
charInfo->metrics.descent = descent;
charInfo->metrics.characterWidth = width;
charInfo->metrics.attributes =
(char_width.raw ? char_width.raw :
(unsigned short)(short)(floor(1000 * metrics.advance / 64.
/ ft->pixel_size)));
FontCacheInsertEntry(ft->cache, c, entry);
} else {
charInfo = &entry->charInfo;
}
next:
return &charInfo->metrics;
}
/* unify get_glyph_prop and get_glyph_const */
static CharInfoPtr
get_glyph(FreeTypeFont *ft, int c, int spacing)
{
FreeTypeFaceInfo *fi = &faceTable[ft->fid];
FontCacheEntryPtr entry;
CharInfoPtr charInfo;
TT_Outline outline;
int width, height, descent, lbearing;
int glyph = ft->pFont->glyph;
int bytes;
/*
* Check invalid char index.
*/
if ( c < 0 ) {
charInfo = &nocharinfo;
goto next;
}
if (FontCacheSearchEntry(ft->cache, c, &entry)) {
if (entry->charInfo.bits != NULL) {
return &entry->charInfo;
}
}
if (entry == NULL) {
struct xtt_char_width char_width;
/* Make charInfo */
if ( spacing == XTT_MONOSPACED ) {
char_width.pixel = ft->pFont->info.maxbounds.characterWidth;
char_width.raw = ft->pFont->info.maxbounds.attributes;
} else
char_width.pixel = char_width.raw = 0;
get_metrics(ft, c, char_width);
/* Retry to get it created in get_metrics(). */
if (!FontCacheSearchEntry(ft->cache, c, &entry)) {
charInfo = &nocharinfo;
fprintf(stderr, "get_glyph: can't get cache entry\n");
goto next;
}
}
charInfo = &entry->charInfo;
{
if (fi->sbit && IS_TT_Matrix_Unit(ft->matrix) &&
ft->isEmbeddedBitmap) {
if (TT_Load_Glyph_Bitmap(fi->face, ft->instance, c, fi->sbit))
fi->sbit->map.size = 0;
} else {
if (fi->sbit)
fi->sbit->map.size = 0;
}
/*
* load outline if fails now.
* But it is better that we are able to select
* another way, i.e. load NULL glyph if fails.
*/
if ((!fi->sbit) || (!fi->sbit->map.size)) {
TT_Load_Glyph(ft->instance, fi->glyph, c, ft->flag);
TT_Get_Glyph_Outline(fi->glyph, &outline);
outline.dropout_mode = 2;
TT_Transform_Outline(&outline, &ft->matrix);
}
/*
* set glyph metrics for drawing a character.
*/
/* prepare to shift */
lbearing = 0;
switch (spacing) {
case XTT_CONSTANT_SPACING:
/* Make maxbounds bitmap and draw character on it */
lbearing = ft->pFont->info.maxbounds.leftSideBearing;
descent = ft->pFont->info.maxbounds.descent;
width = ft->pFont->info.maxbounds.rightSideBearing - lbearing;
height = ft->pFont->info.maxbounds.ascent + descent;
/* Write charInfo->metrics as constant charcell */
charInfo->metrics = ft->pFont->info.maxbounds;
break;
case XTT_MONOSPACED:
/* shift */
lbearing -= FC_TT_PRIVATE(entry)->shift;
case XTT_PROPORTIONAL_SPACING:
default:
/* Make just fit bitmap and draw character on it */
lbearing += charInfo->metrics.leftSideBearing;
descent = charInfo->metrics.descent;
width = charInfo->metrics.rightSideBearing -
charInfo->metrics.leftSideBearing;
height = charInfo->metrics.ascent + descent;
break;
}
ft->map.rows = height;
bytes = (width + 7) / 8;
/* alignment */
bytes = (bytes + (glyph) - 1) & -glyph;
ft->map.cols = bytes;
ft->map.width = width;
ft->map.flow = TT_Flow_Down;
ft->map.size = ft->map.rows * ft->map.cols;
if (!FontCacheGetBitmap(entry, ft->map.size)) {
charInfo = &nocharinfo;
fprintf(stderr, "can't get glyph image area\n");
goto next;
}
ft->map.bitmap = charInfo->bits;
if ( ft->map.bitmap == NULL ) goto next;
/*
* draw a sbit or an outline glyph
*/
if (fi->sbit && fi->sbit->map.size &&
IS_TT_Matrix_Unit(ft->matrix) && ft->isEmbeddedBitmap)
/*
* Metrics on sbits are already cropped.
* And the parameters, ?_offset, on XTT_Get_SBit_Bitmap are
* different from TT_Get_Glyph_Bitmap's one.
*/
XTT_Get_SBit_Bitmap(&ft->map, fi->sbit, -lbearing, descent);
else {
TT_Translate_Outline(&outline, -lbearing * 64, descent * 64);
TT_Get_Outline_Bitmap(engine, &outline, &ft->map);
}
if (ft->isDoubleStrike)
make_up_bold_bitmap(&ft->map);
(*ft->convert)(ft, ft->map.bitmap, ft->map.size);
}
next:
return charInfo;
}
int
FreeTypeGetGlyphs (FontPtr pFont,
unsigned long count,
unsigned char *chars,
FontEncoding encoding,
unsigned long *pCount,
CharInfoPtr *glyphs)
{
FreeTypeFont *ft = (FreeTypeFont*) pFont->fontPrivate;
CharInfoPtr *glyphsBase = glyphs;
int spacing = 0;
int i,nullbits,ncmark;
dprintf((stderr, "FreeTypeGetGlyphs: %p %d\n", pFont, count));
switch(ft->spacing) {
case 'p':
spacing = XTT_PROPORTIONAL_SPACING;
break;
case 'm':
spacing = XTT_MONOSPACED;
break;
case 'c':
spacing = XTT_CONSTANT_SPACING;
break;
}
while (count--) {
unsigned int c1=0, c2;
*glyphs = &nocharinfo;
switch (encoding) {
case Linear8Bit:
case TwoD8Bit:
c1 = *chars++;
dprintf((stderr, "%04x\n", c1));
break;
case Linear16Bit:
case TwoD16Bit:
c1 = *chars++;
c2 = *chars++;
dprintf((stderr, "code: %02x%02x", c1,c2));
if (c1 >= pFont->info.firstRow &&
c1 <= pFont->info.lastRow &&
c2 >= pFont->info.firstCol &&
c2 <= pFont->info.lastCol) {
c1 = (c1<<8|c2);
} else {
dprintf((stderr, ", out of range. We use nocharinfo.\n"));
*glyphs = &nocharinfo;
goto next;
}
break;
default:
goto next;
}
c1 = ft->codeConverterInfo.ptrCodeConverter(c1);
dprintf((stderr, " ->%04x\n ->", c1));
c1 = TT_Char_Index(ft->charmap, c1);
dprintf((stderr, "%d\n", c1));
*glyphs = get_glyph(ft, c1, spacing);
next:
#if 1
/* fallback for XAA */
if ( *glyphs == &nocharinfo ) {
dprintf((stderr, "nocharinfo causes a server crash. Instead We use .notdef glyph.\n"));
*glyphs = get_glyph(ft, 0, spacing);
}
#endif
glyphs++;
}
*pCount = glyphs - glyphsBase;
/*
(pci)->bits == NULL crashes the Server when gHeight is not zero.
So we must check each value of (pci)->bits. Since operation of
cash intervenes, this "for () loop" *MUST* be independent of
the upper "while () loop".
Dec.26,2002 Chisato Yamauchi
*/
dprintf((stderr, "AddressCheckBegin *pCount=%d\n",*pCount));
nullbits=0;
ncmark=-1;
for ( i=0 ; i<*pCount ; i++ ) {
/* Marking nocharinfo */
if ( glyphsBase[i] == &nocharinfo ) {
if ( ncmark == -1 ) ncmark=i;
}
else {
dprintf((stderr,"[%d]:%x\n",i,glyphsBase[i]->bits));
if ( glyphsBase[i]->bits == NULL ) {
glyphsBase[i]->metrics.ascent=0;
glyphsBase[i]->metrics.descent=0;
nullbits++;
}
/*
The XFree86 sometimes allocates memory with the value of maxbounds.ascent
and maxbounds.descent.
So (*glyphs)->ascent must not become larger than maxbounds.ascent.
This is the same also about descent.
*/
if ( pFont->info.maxbounds.ascent < glyphsBase[i]->metrics.ascent ) {
dprintf((stderr, " Invalid ascent : maxbounds.ascent=%d metrics.ascent=%d [corrected]\n",
pFont->info.maxbounds.ascent,glyphsBase[i]->metrics.ascent));
glyphsBase[i]->metrics.ascent = pFont->info.maxbounds.ascent;
}
if ( pFont->info.maxbounds.descent < glyphsBase[i]->metrics.descent ) {
dprintf((stderr, " Invalid descent : maxbounds.descent=%d metrics.descent=%d [corrected]\n",
pFont->info.maxbounds.descent,glyphsBase[i]->metrics.descent));
glyphsBase[i]->metrics.descent = pFont->info.maxbounds.descent;
}
}
}
#if 1
/* Never return an address outside cache(for XAA). */
if ( ncmark != -1 ) *pCount = ncmark;
#endif
dprintf((stderr, "AddressCheckEnd i=%d nullbits=%d\n",i,nullbits));
return Successful;
}
int
FreeTypeGetMetrics (FontPtr pFont,
unsigned long count,
unsigned char *chars,
FontEncoding encoding,
unsigned long *pCount,
xCharInfo **glyphs)
{
FreeTypeFont *ft = (FreeTypeFont*) pFont->fontPrivate;
xCharInfo **glyphsBase = glyphs;
unsigned int c=0,c2;
int i;
/*dprintf((stderr, "FreeTypeGetMetrics: %d\n", count));*/
if (ft->spacing == 'm' || ft->spacing == 'p') {
struct xtt_char_width char_width;
if (ft->spacing == 'm') {
char_width.pixel = ft->pFont->info.maxbounds.characterWidth;
char_width.raw = ft->pFont->info.maxbounds.attributes;
} else
char_width.pixel = char_width.raw = 0;
while (count--) {
*glyphs = &(&nocharinfo)->metrics;
switch (encoding) {
case Linear8Bit:
case TwoD8Bit:
c = *chars++;
break;
case Linear16Bit:
case TwoD16Bit:
c = *chars++;
c2 = *chars++;
if (c >= pFont->info.firstRow &&
c <= pFont->info.lastRow &&
c2 >= pFont->info.firstCol &&
c2 <= pFont->info.lastCol) {
c = (c<<8|c2);
} else {
*glyphs = &(&nocharinfo)->metrics;
goto next;
}
break;
default:
goto next;
}
/* dprintf((stderr, "code: %04x ->", c));*/
c = ft->codeConverterInfo.ptrCodeConverter(c);
/* dprintf((stderr, "%04x\n", c));*/
*glyphs = get_metrics(ft, TT_Char_Index(ft->charmap, c),
char_width);
next:
#if 1
/* fallback */
if ( *glyphs == &(&nocharinfo)->metrics ) {
dprintf((stderr, "nocharinfo -> Instead We use .notdef glyph.\n"));
*glyphs = get_metrics(ft, 0, char_width);
}
#endif
glyphs++;
}
*pCount = glyphs - glyphsBase;
/*
The XFree86 sometimes allocates memory with the value of maxbounds.ascent
and maxbounds.descent.
So (*glyphs)->ascent must not become larger than maxbounds.ascent.
This is the same also about descent.
*/
for ( i=0 ; i<*pCount ; i++ ) {
if ( pFont->info.maxbounds.ascent < glyphsBase[i]->ascent ) {
dprintf((stderr, " Invalid ascent : maxbounds.ascent=%d metrics.ascent=%d [corrected]\n",
pFont->info.maxbounds.ascent,glyphsBase[i]->ascent));
glyphsBase[i]->ascent = pFont->info.maxbounds.ascent;
}
if ( pFont->info.maxbounds.descent < glyphsBase[i]->descent ) {
dprintf((stderr, " Invalid descent : maxbounds.descent=%d metrics.descent=%d [corrected]\n",
pFont->info.maxbounds.descent,glyphsBase[i]->descent));
glyphsBase[i]->descent = pFont->info.maxbounds.descent;
}
}
} else { /* -c- */
switch (encoding) {
case Linear8Bit:
case TwoD8Bit:
while (count--) {
chars++; chars++;
*glyphs++ = &pFont->info.maxbounds;
}
break;
case Linear16Bit:
case TwoD16Bit:
while (count--) {
chars++; chars++;
*glyphs++ = &pFont->info.maxbounds;
}
break;
}
*pCount = glyphs - glyphsBase;
}
return Successful;
}
void
FreeTypeUnloadFont(FontPtr pFont)
{
dprintf((stderr, "FreeTypeUnloadFont: %x\n", pFont));
FreeType_CloseFont(pFont);
}
#ifdef USE_XLFD_AUTO_CONTROL
struct {
char *name;
int sign;
} slantinfo[] = {
{ "o", 1 },
{ "ro", -1 }
};
#endif /* USE_XLFD_AUTO_CONTROL - obsoleted. */
static void
adjust_min_max(minc, maxc, tmp)
xCharInfo *minc, *maxc, *tmp;
{
#define MINMAX(field,ci) \
if (minc->field > (ci)->field) \
minc->field = (ci)->field; \
if (maxc->field < (ci)->field) \
maxc->field = (ci)->field;
MINMAX(ascent, tmp);
MINMAX(descent, tmp);
MINMAX(leftSideBearing, tmp);
MINMAX(rightSideBearing, tmp);
MINMAX(characterWidth, tmp);
if ((INT16)minc->attributes > (INT16)tmp->attributes)
minc->attributes = tmp->attributes;
if ((INT16)maxc->attributes < (INT16)tmp->attributes)
maxc->attributes = tmp->attributes;
#undef MINMAX
}
void
freetype_compute_bounds(FreeTypeFont *ft,
FontInfoPtr pinfo,
FontScalablePtr vals,
struct xtt_char_width char_width)
{
int row, col;
short c;
xCharInfo minchar, maxchar, *tmpchar = NULL;
int overlap, maxOverlap;
long swidth = 0;
long total_width = 0;
int num_chars = 0;
minchar.ascent = minchar.descent =
minchar.leftSideBearing = minchar.rightSideBearing =
minchar.characterWidth = minchar.attributes = 32767;
maxchar.ascent = maxchar.descent =
maxchar.leftSideBearing = maxchar.rightSideBearing =
maxchar.characterWidth = maxchar.attributes = -32767;
maxOverlap = -32767;
for (row = pinfo->firstRow; row <= pinfo->lastRow; row++) {
for (col = pinfo->firstCol; col <= pinfo->lastCol; col++) {
c = row<<8|col;
#if 0
fprintf(stderr, "comp_bounds: %x ->", c);
#endif
c = ft->codeConverterInfo.ptrCodeConverter(c);
#if 0
fprintf(stderr, "%x\n", c);
#endif
if (c) {
tmpchar =
get_metrics(ft, TT_Char_Index(ft->charmap, c),
char_width);
}
if (!tmpchar || !tmpchar->characterWidth)
continue;
adjust_min_max(&minchar, &maxchar, tmpchar);
overlap = tmpchar->rightSideBearing - tmpchar->characterWidth;
if (maxOverlap < overlap)
maxOverlap = overlap;
num_chars++;
swidth += ABS(tmpchar->characterWidth);
total_width += tmpchar->characterWidth;
}
}
if (num_chars > 0) {
swidth = (swidth * 10.0 + num_chars / 2.0) / num_chars;
if (total_width < 0)
swidth = -swidth;
vals->width = swidth;
} else
vals->width = 0;
if(char_width.pixel) {
maxchar.characterWidth = char_width.pixel;
minchar.characterWidth = char_width.pixel;
}
pinfo->maxbounds = maxchar;
pinfo->minbounds = minchar;
pinfo->ink_maxbounds = maxchar;
pinfo->ink_minbounds = minchar;
pinfo->maxOverlap = maxOverlap;
}
/*
* restrict code range
*
* boolean for the numeric zone:
* results = results & (ranges[0] | ranges[1] | ... ranges[nranges-1])
*/
static void
restrict_code_range(unsigned short *refFirstCol,
unsigned short *refFirstRow,
unsigned short *refLastCol,
unsigned short *refLastRow,
fsRange const *ranges, int nRanges)
{
if (nRanges) {
int minCol = 256, minRow = 256, maxCol = -1, maxRow = -1;
fsRange const *r = ranges;
int i;
for (i=0; i<nRanges; i++) {
if (r->min_char_high != r->max_char_high) {
minCol = 0x00;
maxCol = 0xff;
} else {
if (minCol > r->min_char_low)
minCol = r->min_char_low;
if (maxCol < r->max_char_low)
maxCol = r->max_char_low;
}
if (minRow > r->min_char_high)
minRow = r->min_char_high;
if (maxRow < r->max_char_high)
maxRow = r->max_char_high;
r++;
}
if (minCol > *refLastCol)
*refFirstCol = *refLastCol;
else if (minCol > *refFirstCol)
*refFirstCol = minCol;
if (maxCol < *refFirstCol)
*refLastCol = *refFirstCol;
else if (maxCol < *refLastCol)
*refLastCol = maxCol;
if (minRow > *refLastRow) {
*refFirstRow = *refLastRow;
*refFirstCol = *refLastCol;
} else if (minRow > *refFirstRow)
*refFirstRow = minRow;
if (maxRow < *refFirstRow) {
*refLastRow = *refFirstRow;
*refLastCol = *refFirstCol;
} else if (maxRow < *refLastRow)
*refLastRow = maxRow;
}
}
static void
restrict_code_range_by_str(unsigned short *refFirstCol,
unsigned short *refFirstRow,
unsigned short *refLastCol,
unsigned short *refLastRow,
char const *str)
{
int nRanges = 0;
fsRange *ranges = NULL;
char const *p, *q;
p = q = str;
for (;;) {
int minpoint=0, maxpoint=65535;
long val;
/* skip comma and/or space */
while (',' == *p || isspace(*p))
p++;
/* begin point */
if ('-' != *p) {
val = strtol(p, (char **)&q, 0);
if (p == q)
/* end or illegal */
break;
if (val<0 || val>65535) {
/* out of zone */
break;
}
minpoint = val;
p=q;
}
/* skip space */
while (isspace(*p))
p++;
if (',' != *p && '\0' != *p) {
/* contiune */
if ('-' == *p)
/* hyphon */
p++;
else
/* end or illegal */
break;
/* skip space */
while (isspace(*p))
p++;
val = strtol(p, (char **)&q, 0);
if (p != q) {
if (val<0 || val>65535)
break;
maxpoint = val;
} else if (',' != *p && '\0' != *p)
/* end or illegal */
break;
p=q;
} else
/* comma - single code */
maxpoint = minpoint;
if (minpoint>maxpoint) {
int tmp;
tmp = minpoint;
minpoint = maxpoint;
maxpoint = tmp;
}
/* add range */
#if 0
fprintf(stderr, "zone: 0x%04X - 0x%04X\n", minpoint, maxpoint);
fflush(stderr);
#endif
nRanges++;
ranges = (fsRange *)xrealloc(ranges, nRanges*sizeof(*ranges));
if (NULL == ranges)
break;
{
fsRange *r = ranges+nRanges-1;
r->min_char_low = minpoint & 0xff;
r->max_char_low = maxpoint & 0xff;
r->min_char_high = (minpoint>>8) & 0xff;
r->max_char_high = (maxpoint>>8) & 0xff;
}
}
if (ranges) {
restrict_code_range(refFirstCol, refFirstRow, refLastCol, refLastRow,
ranges, nRanges);
xfree(ranges);
}
}
int
FreeTypeOpenScalable (fpe, ppFont, flags, entry, fileName, vals,
format, fmask, non_cachable_font)
FontPathElementPtr fpe;
FontPtr *ppFont;
int flags;
FontEntryPtr entry;
char *fileName;
FontScalablePtr vals;
fsBitmapFormat format;
fsBitmapFormatMask fmask;
FontPtr non_cachable_font; /* We don't do licensing */
{
int result = Successful;
int i;
FontPtr pFont;
FontInfoPtr pinfo;
FreeTypeFont *ft;
int ret, bit, byte, glyph, scan, image;
char xlfdName[MAXFONTNAMELEN];
char familyname[MAXFONTNAMELEN];
char charset[MAXFONTNAMELEN], slant[MAXFONTNAMELEN];
int spacing = 'r'; /* avoid 'uninitialized variable using' warning */
/* XXX: To avoid gcc to embed memset function implicitly, we need to
store strings to fixed-size array indirectly with using strcpy. */
char const *copyright_string_default =
"Copyright Notice is not available or not able to read yet.";
#define MAXCOPYRIGHTLEN 256
char copyright_string[MAXCOPYRIGHTLEN + 1];
SDynPropRecValList listPropRecVal;
FreeTypeOpenFaceHints hints;
char *dynStrTTFileName = NULL;
char *dynStrRealFileName = NULL;
SPropRecValContainer contRecValue;
int setwidth_value = 0;
double base_width, base_height;
dprintf((stderr,
"\n+FreeTypeOpenScalable(%x, %x, %x, %x, %s, %x, %x, %x, %x)\n",
fpe, ppFont, flags, entry, fileName, vals,
format, fmask, non_cachable_font));
strcpy(copyright_string, copyright_string_default);
#ifdef DUMP
DumpFontPathElement(fpe);
DumpFontEntry(entry);
DumpFontScalable(vals);
#endif
hints.isProp = False;
hints.fontName = fileName;
hints.charsetName = charset;
hints.familyName = familyname;
hints.refListPropRecVal = &listPropRecVal;
hints.ttcno = 0;
if (SPropRecValList_new(&listPropRecVal)) {
result = AllocError;
goto quit;
}
{
int len = strlen(fileName);
char *capHead = NULL;
{
/* font cap */
char *p1=NULL, *p2=NULL;
if (NULL != (p1=strrchr(fileName, '/')))
if (NULL != (p2=strrchr(p1, ':'))) {
/* colon exist in the right side of slash. */
int dirLen = p1-fileName+1;
int baseLen = fileName+len - p2 -1;
dynStrRealFileName = (char *)xalloc(dirLen+baseLen+1);
memcpy(dynStrRealFileName, fileName, dirLen);
strcpy(dynStrRealFileName+dirLen, p2+1);
capHead = p1+1;
} else
dynStrRealFileName = xstrdup(fileName);
else
dynStrRealFileName = xstrdup(fileName);
} /* font cap */
hints.ttFontName = dynStrRealFileName;
{
/* font cap */
if (capHead)
if (SPropRecValList_add_by_font_cap(&listPropRecVal,
capHead)) {
result = BadFontPath;
goto quit;
}
}
}
{
char *p = entry->name.name, *p1=NULL;
for (i=0; i<13; i++) {
if (*p) {
p1 = p + 1;
if (!(p = strchr(p1,'-'))) p = strchr(p1, '\0');
}
switch (i) {
case 0: /* foundry */
break;
case 1: /* family */
strncpy(familyname, p1, p-p1);
familyname[p-p1] = '\0';
break;
case 2: /* weight */
break;
case 3: /* slant */
strncpy(slant, p1, p-p1);
slant[p-p1] = '\0';
break;
case 4: /* setwidth */
setwidth_value = 0;
#if 0
/* Oops, polymorphic XLFD parser is not implemented! */
if ( '-' != *p1 ) {
/* polymorphic setwidth */
/* 500 = normal width */
/* 1000 = double width */
char *endptr;
setwidth_value = strtol(p1, &endptr, 10);
if ( '-' != *endptr )
setwidth_value = 0;
if ( setwidth_value>1000 )
setwidth_value=1000;
}
break;
#endif
case 5: /* additional style */
case 6: /* pixel size */
case 7: /* point size */
case 8: /* res x */
case 9: /* res y */
break;
case 10: /* spacing */
spacing = tolower(*p1);
break;
case 11: /* avarage width */
break;
case 12: /* charset */
strcpy(charset, p1);
/* eliminate zone description */
{
char *p2;
if (NULL != (p2 = strchr(charset, '[')))
*p2 = '\0';
}
}
}
}
dprintf((stderr, "charset: %s spacing: %d slant: %s\n",
charset, spacing, slant));
/* get face number from Property File directly */
if ( SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"FaceNumber"))
hints.ttcno = SPropContainer_value_int(contRecValue);
/* slant control */
if (SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"AutoItalic")) {
vals->pixel_matrix[2] +=
vals->pixel_matrix[0] * SPropContainer_value_dbl(contRecValue);
vals->point_matrix[2] +=
vals->point_matrix[0] * SPropContainer_value_dbl(contRecValue);
vals->pixel_matrix[3] +=
vals->pixel_matrix[1] * SPropContainer_value_dbl(contRecValue);
vals->point_matrix[3] +=
vals->point_matrix[1] * SPropContainer_value_dbl(contRecValue);
}
#ifdef USE_XLFD_AUTO_CONTROL
else
for (i=0; i<sizeof(slantinfo)/sizeof(slantinfo[0]); i++) {
if (!mystrcasecmp(slant, slantinfo[i].name)) {
vals->pixel_matrix[2] +=
vals->pixel_matrix[0] * slantinfo[i].sign * 0.5;
vals->point_matrix[2] +=
vals->point_matrix[0] * slantinfo[i].sign * 0.5;
vals->pixel_matrix[3] +=
vals->pixel_matrix[1] * slantinfo[i].sign * 0.5;
vals->point_matrix[3] +=
vals->point_matrix[1] * slantinfo[i].sign * 0.5;
break;
}
}
#endif /* USE_XLFD_AUTO_CONTROL - obsoleted. */
/* Reject ridiculously small font sizes that will blow up the math */
if ((base_width = hypot(vals->pixel_matrix[0], vals->pixel_matrix[1])) < 1.0 ||
(base_height = hypot(vals->pixel_matrix[2], vals->pixel_matrix[3])) < 1.0) {
fprintf(stderr, "too small font\n");
result = BadFontName;
goto quit;
}
/* set up default values */
FontDefaultFormat(&bit, &byte, &glyph, &scan);
/* get any changes made from above */
ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
if (ret != Successful) {
result = ret;
goto quit;
}
/* allocate font struct */
if (!(pFont = CreateFontRec())) {
result = AllocError;
goto quit;
}
/* allocate private font data */
if ((ft = (FreeTypeFont *)xalloc(sizeof(*ft))) == NULL) {
DestroyFontRec(pFont);
result = AllocError;
goto quit;
}
/* init private font data */
memset(ft, 0, sizeof(*ft));
ft->pixel_size = base_height;
ft->pixel_width_unit_x = vals->pixel_matrix[0]/base_height;
/* hinting control */
ft->flag = TTLOAD_DEFAULT;
if (SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"Hinting"))
/* if not true, turn off hinting
* some broken truetype font cannot get bitmaps when
* hinting is applied */
if (!SPropContainer_value_bool(contRecValue))
ft->flag = TTLOAD_SCALE_GLYPH;
/* scaling */
ft->scaleWidth = 1.0;
if (SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"ScaleWidth")) {
/* Scaling to Width */
double scaleWidth = SPropContainer_value_dbl(contRecValue);
if (scaleWidth<=0.0) {
fprintf(stderr, "ScaleWitdh needs plus.\n");
return -1;
}
ft->scaleWidth = scaleWidth;
}
if ( setwidth_value ) {
ft->scaleWidth *= (double)setwidth_value / 500.0;
}
ft->scaleBBoxWidth = 1.0;
if (SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"ScaleBBoxWidth")) {
/* Scaling to Bounding Box Width */
double scaleBBoxWidth = SPropContainer_value_dbl(contRecValue);
if (scaleBBoxWidth<=0.0) {
fprintf(stderr, "ScaleBBoxWitdh needs plus.\n");
return -1;
}
ft->scaleBBoxWidth = scaleBBoxWidth;
}
ft->scaleBBoxWidth *= ft->scaleWidth;
ft->isDoubleStrike = False;
if (SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"DoubleStrike")) {
/* Set or Reset Auto Bold Flag */
if (SPropContainer_value_bool(contRecValue))
ft->isDoubleStrike = True;
}
ft->spacing = spacing;
#if True /* obsoleted ->->-> */
if (SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"ForceProportional"))
ft->spacing = SPropContainer_value_bool(contRecValue)?'p':'c';
else
#endif /* <-<-<- obsoleted */
if (SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"ForceSpacing")) {
char *strSpace = SPropContainer_value_str(contRecValue);
Bool err = False;
if (1 != strlen(strSpace))
err = True;
else
switch (strSpace[0]) {
case 'p':
case 'm':
case 'c':
ft->spacing = strSpace[0];
break;
default:
err = True;
}
if (err) {
xfree(ft);
DestroyFontRec(pFont);
result = BadFontName;
goto quit;
}
}
/* very lazy metrics */
ft->isVeryLazy = False;
if (SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"VeryLazyMetrics"))
#if 0
if (NULL == getenv("NOVERYLAZY"))
/* If NOVERYLAZY is defined, the vl option is ignored. */
#endif
ft->isVeryLazy = SPropContainer_value_bool(contRecValue);
/* embedded bitmap */
ft->isEmbeddedBitmap = True;
if (SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"EmbeddedBitmap"))
ft->isEmbeddedBitmap = SPropContainer_value_bool(contRecValue);
if ((ret = FreeType_OpenFont(ft, vals, glyph, &hints))
!= Successful) {
xfree(ft);
DestroyFontRec(pFont);
result = BadFontName;
goto quit;
}
ft->scaleBitmap = 1.0;
if((ft->isVeryLazy) &&
SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"VeryLazyBitmapWidthScale")) {
/* Scaling to Bitmap Bounding Box Width */
double scaleBitmapWidth = SPropContainer_value_dbl(contRecValue);
if (scaleBitmapWidth<=0.0) {
fprintf(stderr, "ScaleBitmapWitdh needs plus.\n");
return -1;
}
ft->scaleBitmap = scaleBitmapWidth;
}
ft->pFont = pFont;
if (bit == MSBFirst) {
if (byte == LSBFirst) {
ft->convert = convertNothing;
} else {
ft->convert = convertByteOrder;
}
} else {
if (byte == LSBFirst) {
ft->convert = convertBitOrder;
} else {
ft->convert = convertBitByteOrder;
}
}
/* Fill in font record. Data format filled in by reader. */
pFont->format = format;
pFont->bit = bit;
pFont->byte = byte;
pFont->glyph = glyph;
pFont->scan = scan;
pFont->get_metrics = FreeTypeGetMetrics;
pFont->get_glyphs = FreeTypeGetGlyphs;
pFont->unload_font = FreeTypeUnloadFont;
pFont->unload_glyphs = NULL;
pFont->refcnt = 0;
pFont->fontPrivate = (unsigned char *)ft;
/* set ColInfo */
pinfo = &pFont->info;
pinfo->firstCol = ft->codeConverterInfo.refCharSetInfo->firstCol;
pinfo->firstRow = ft->codeConverterInfo.refCharSetInfo->firstRow;
pinfo->lastCol = ft->codeConverterInfo.refCharSetInfo->lastCol;
pinfo->lastRow = ft->codeConverterInfo.refCharSetInfo->lastRow;
pinfo->defaultCh = ft->codeConverterInfo.refCharSetInfo->defaultCh;
/* restriction of the code range */
{
if (SPropRecValList_search_record(&listPropRecVal,
&contRecValue,
"CodeRange")) {
restrict_code_range_by_str(&pinfo->firstCol, &pinfo->firstRow,
&pinfo->lastCol, &pinfo->lastRow,
SPropContainer_value_str(contRecValue));
}
restrict_code_range(&pinfo->firstCol, &pinfo->firstRow,
&pinfo->lastCol, &pinfo->lastRow,
vals->ranges, vals->nranges);
}
pinfo->allExist = 0;
pinfo->drawDirection = LeftToRight;
pinfo->cachable = 1;
pinfo->anamorphic = False; /* XXX ? */
pFont->info.inkMetrics = 0;
pFont->info.allExist = 0;
pFont->info.maxOverlap = 0;
pFont->info.pad = (short)0xf0f0; /* 0, 0xf0f0 ??? */
{
/*
* calculate exact bounding box
*/
int raw_ascent, raw_descent, raw_width; /* RAW */
int lsb, rsb, desc, asc;
double newlsb, newrsb, newdesc, newasc;
double point[2];
double scale;
struct xtt_char_width char_width = {0,0};
/*
* X11's values are not same as TrueType values.
* lsb is same.
* rsb is not same. X's rsb is xMax.
* asc is same.
* desc is negative.
*
* NOTE THAT:
* `prop' is instance of TT_Face_Properties, and
* get by using TT_Get_Face_Properties().
* Thus, `prop' applied no transformation.
*/
asc = faceTable[ft->fid].prop.horizontal->Ascender;
desc = -(faceTable[ft->fid].prop.horizontal->Descender);
lsb = faceTable[ft->fid].prop.horizontal->min_Left_Side_Bearing;
rsb = faceTable[ft->fid].prop.horizontal->xMax_Extent;
if (rsb == 0)
rsb = faceTable[ft->fid].prop.horizontal->advance_Width_Max;
raw_width = faceTable[ft->fid].prop.horizontal->advance_Width_Max;
raw_ascent = faceTable[ft->fid].prop.horizontal->Ascender;
raw_descent = -(faceTable[ft->fid].prop.horizontal->Descender);
/*
* Apply scaleBBoxWidth.
*/
lsb = (int)floor(lsb * ft->scaleBBoxWidth);
rsb = (int)floor(rsb * ft->scaleBBoxWidth + 0.5);
raw_width = raw_width * ft->scaleBBoxWidth;
#define TRANSFORM_POINT(matrix, x, y, dest) \
((dest)[0] = (matrix)[0] * (x) + (matrix)[2] * (y), \
(dest)[1] = (matrix)[1] * (x) + (matrix)[3] * (y))
#define CHECK_EXTENT(lsb, rsb, desc, asc, data) \
((lsb) > (data)[0] ? (lsb) = (data)[0] : 0 , \
(rsb) < (data)[0] ? (rsb) = (data)[0] : 0, \
(-desc) > (data)[1] ? (desc) = -(data)[1] : 0 , \
(asc) < (data)[1] ? (asc) = (data)[1] : 0)
/* Compute new extents for this glyph */
TRANSFORM_POINT(vals->pixel_matrix, lsb, -desc, point);
newlsb = point[0];
newrsb = newlsb;
newdesc = -point[1];
newasc = -newdesc;
TRANSFORM_POINT(vals->pixel_matrix, lsb, asc, point);
CHECK_EXTENT(newlsb, newrsb, newdesc, newasc, point);
TRANSFORM_POINT(vals->pixel_matrix, rsb, -desc, point);
CHECK_EXTENT(newlsb, newrsb, newdesc, newasc, point);
TRANSFORM_POINT(vals->pixel_matrix, rsb, asc, point);
CHECK_EXTENT(newlsb, newrsb, newdesc, newasc, point);
/*
* TrueType font is scaled. So we made scaling value.
*/
scale = 1.0 / faceTable[ft->fid].prop.header->Units_Per_EM;
/* ???: lsb = (int)floor(newlsb * scale); */
lsb = (int)floor(newlsb * scale + 0.5);
rsb = (int)floor(newrsb * scale + 0.5);
desc = (int)ceil(newdesc * scale - 0.5);
asc = (int)floor(newasc * scale + 0.5);
/*
* raw_* for are differs.
*/
raw_width *= base_width * 1000. * scale / base_height;
raw_ascent *= 1000. * scale;
raw_descent *= 1000. * scale;
/*
* Get sbit line metrics.
* This line metrics returns the line metrics of font file,
* but not X's font as you want.
*/
if (IS_TT_Matrix_Unit(ft->matrix) &&
faceTable[ft->fid].sbit && ft->isEmbeddedBitmap)
{
TT_SBit_Strike strike;
TT_UFWord adv_width_max =
faceTable[ft->fid].prop.horizontal->advance_Width_Max;
int scaleBBoxWidth = ft->scaleBBoxWidth;
int sbit_lsb, sbit_rsb, sbit_desc, sbit_asc;
if (TT_Get_SBit_Strike(faceTable[ft->fid].face, ft->instance,
&strike))
faceTable[ft->fid].sbit->map.size = 0;
else {
sbit_lsb = (int)floor(strike.hori.min_origin_SB
* scaleBBoxWidth);
/* XXX: It is not correct value */
sbit_rsb = MAX((int)floor(strike.hori.max_width
* scaleBBoxWidth + .5),
(int)floor((adv_width_max * scale
- strike.hori.min_advance_SB)
* scaleBBoxWidth + .5));
sbit_desc = strike.hori.min_after_BL * -1;
sbit_asc = strike.hori.max_before_BL;
/* We set line metrics as bellow */
lsb = MIN(lsb, sbit_lsb);
rsb = MAX(rsb, sbit_rsb);
desc = MAX(desc, sbit_desc);
asc = MAX(asc, sbit_asc);
dprintf((stderr, "outline: lsb %d, rsb %d, desc %d, asc %d\n",
lsb, rsb, desc, asc));
dprintf((stderr, "sbit: lsb %d, rsb %d, desc %d, asc %d\n",
sbit_lsb, sbit_rsb, sbit_desc, sbit_asc));
}
}
/* ComputeBounds */
if (ft->spacing == 'c' || ft->spacing == 'm') { /* constant width */
int width =
faceTable[ft->fid].prop.horizontal->advance_Width_Max
* ft->scaleBBoxWidth;
/* width: all widths are identical */
width = (int)floor(width * vals->pixel_matrix[0] * scale + 0.5);
/* AVERAGE_WIDTH ... 1/10 pixel unit */
vals->width = width * 10;
if (ft->spacing == 'c') { /* constant charcell */
/* Use same maxbounds and minbounds to make fast. */
pFont->info.maxbounds.leftSideBearing = lsb;
pFont->info.maxbounds.rightSideBearing = rsb;
pFont->info.maxbounds.characterWidth = width;
pFont->info.maxbounds.ascent = asc;
pFont->info.maxbounds.descent = desc;
pFont->info.maxbounds.attributes = raw_width;
pFont->info.minbounds = pFont->info.maxbounds;
} else { /* monospaced */
static const struct em_index {
char* registry;
unsigned index;
} em_indexarray[] = {
{"ascii", 0x4d},
{"iso8859", 0x4d},
{"iso646", 0x4d},
{"jisx0201", 0x4d},
{"koi8", 0x4d}
};
unsigned i=0;
#define CodeConv(x) ft->codeConverterInfo.ptrCodeConverter(x)
#define NUM_EM_ARRAY sizeof(em_indexarray)/sizeof(struct em_index)
/* calculate pedantic way */
for(;i<NUM_EM_ARRAY;i++) {
if (!strncasecmp(em_indexarray[i].registry,
charset,
strlen(em_indexarray[i].registry))) {
short c;
xCharInfo *em_char;
/* get em-square */
c = CodeConv(em_indexarray[i].index);
if (c) {
em_char =
get_metrics(ft,
TT_Char_Index(ft->charmap, c),
char_width);
char_width.pixel = em_char->characterWidth;
char_width.raw = em_char->attributes;
freetype_compute_bounds(ft, pinfo, vals,
char_width);
goto OK;
}
}
}
/* Use different maxbounds and minbounds
to let X check metrics. */
pFont->info.maxbounds.leftSideBearing = 0;
pFont->info.maxbounds.rightSideBearing = rsb;
pFont->info.maxbounds.characterWidth = width;
pFont->info.maxbounds.ascent = asc;
pFont->info.maxbounds.descent = desc;
pFont->info.maxbounds.attributes = raw_width;
pFont->info.minbounds.leftSideBearing = lsb;
pFont->info.minbounds.rightSideBearing = 0;
pFont->info.minbounds.characterWidth = width;
pFont->info.minbounds.ascent = asc;
pFont->info.minbounds.descent = desc;
pFont->info.minbounds.attributes = 0;
}
pFont->info.ink_maxbounds = pFont->info.maxbounds;
pFont->info.ink_minbounds = pFont->info.minbounds;
pFont->info.maxOverlap = rsb - width;
} else { /* proportional */
freetype_compute_bounds(ft, pinfo, vals, char_width);
}
OK:
/* set ascent/descent */
pFont->info.fontAscent = asc;
pFont->info.fontDescent = desc;
/* set name for property */
strncpy(xlfdName, vals->xlfdName, sizeof(xlfdName));
FontParseXLFDName(xlfdName, vals, FONT_XLFD_REPLACE_VALUE);
dprintf((stderr, "name: %s\n", xlfdName));
{
/* set copyright notice */
char* name_string;
unsigned short name_len, copyright_len;
int i, n;
unsigned short platform, encoding, language, id;
for (n=0;n<faceTable[ft->fid].prop.num_Names;n++) {
if (TT_Get_Name_ID(faceTable[ft->fid].face,
n, &platform, &encoding, &language, &id) ||
TT_Get_Name_String(faceTable[ft->fid].face,
n, &name_string, &name_len))
continue;
if (id != 0) /* not copyright */
continue;
if ((platform == 1) && /* Macintosh script */
(encoding == 0) && /* Roman */
((language == 0) || /* English */
(language == 1041))) { /* broken (Canon FontGallay) */
copyright_len = MIN(name_len, MAXCOPYRIGHTLEN);
memcpy(copyright_string, name_string, copyright_len);
/* name_string may NOT be null terminated */
copyright_string[copyright_len] = '\0';
break;
}
if (((platform == 3) && /* Microsoft */
((encoding == 0) || (encoding == 1)) &&
((language & 0x3FF) == 0x009)) /* English */ ||
((platform == 0) && /* Apple Unicode */
(encoding == 0))) { /* Default semantics */
/* It is 2-byte aligned */
name_len = MIN(name_len, MAXCOPYRIGHTLEN * 2);
copyright_len = 0;
for (i=1;i<name_len;i+=2) {
copyright_string[copyright_len++] = name_string[i];
}
copyright_string[copyright_len] = '\0';
break;
}
}
}
/* set properties */
freetype_compute_props(&pFont->info, vals,
raw_width, raw_ascent, raw_descent,
xlfdName,
copyright_string);
}
/* Set the pInfo flags */
/* Properties set by FontComputeInfoAccelerators:
pInfo->noOverlap;
pInfo->terminalFont;
pInfo->constantMetrics;
pInfo->constantWidth;
pInfo->inkInside;
*/
FontComputeInfoAccelerators(pinfo);
#ifdef DUMP
DumpFont(pFont);
#endif
*ppFont = pFont;
result = Successful;
quit:
if (dynStrTTFileName)
xfree(dynStrTTFileName);
if (dynStrRealFileName)
xfree(dynStrRealFileName);
return result;
}
int
FreeTypeGetInfoScalable(fpe, pFontInfo, entry, fontName, fileName, vals)
FontPathElementPtr fpe;
FontInfoPtr pFontInfo;
FontEntryPtr entry;
FontNamePtr fontName;
char *fileName;
FontScalablePtr vals;
{
FontPtr pfont;
int flags = 0;
long format = 0;
long fmask = 0;
int ret;
dprintf((stderr, "FreeTypeGetInfoScalable\n"));
ret = FreeTypeOpenScalable(fpe, &pfont, flags, entry,
fileName, vals, format, fmask, 0);
if (ret != Successful)
return ret;
*pFontInfo = pfont->info;
pfont->info.props = NULL;
pfont->info.isStringProp = NULL;
FreeType_CloseFont(pfont);
return Successful;
}
static FontRendererRec renderers[] =
{
{
".ttf", 4,
(int (*)()) 0, FreeTypeOpenScalable,
(int (*)()) 0, FreeTypeGetInfoScalable,
0, CAP_MATRIX | CAP_CHARSUBSETTING
},
{
".ttc", 4,
(int (*)()) 0, FreeTypeOpenScalable,
(int (*)()) 0, FreeTypeGetInfoScalable,
0, CAP_MATRIX | CAP_CHARSUBSETTING
},
{
".TTF", 4,
(int (*)()) 0, FreeTypeOpenScalable,
(int (*)()) 0, FreeTypeGetInfoScalable,
0, CAP_MATRIX | CAP_CHARSUBSETTING
},
{
".TTC", 4,
(int (*)()) 0, FreeTypeOpenScalable,
(int (*)()) 0, FreeTypeGetInfoScalable,
0, CAP_MATRIX | CAP_CHARSUBSETTING
}
};
int
XTrueTypeRegisterFontFileFunctions()
{
int i;
/* make standard prop */
freetype_make_standard_props();
/* reset */
/* register */
for (i=0;i<sizeof(renderers)/sizeof(renderers[0]);i++) {
/* If the user has both the FreeType and the X-TT backends
linked in, he probably wants X-TT to be used for TrueType
fonts. */
FontFilePriorityRegisterRenderer(renderers + i, +10);
}
return 0;
}
/* end of file */
|