gdft.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. /********************************************/
  2. /* gd interface to freetype library */
  3. /* */
  4. /* John Ellson ellson@graphviz.org */
  5. /********************************************/
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <math.h>
  10. #include "gd.h"
  11. #include "gdhelpers.h"
  12. #ifndef MSWIN32
  13. #include <unistd.h>
  14. #else
  15. #include <io.h>
  16. #ifndef R_OK
  17. # define R_OK 04 /* Needed in Windows */
  18. #endif
  19. #endif
  20. #ifdef WIN32
  21. #define access _access
  22. #ifndef R_OK
  23. #define R_OK 2
  24. #endif
  25. #endif
  26. /* number of antialised colors for indexed bitmaps */
  27. /* overwrite Windows GDI define in case of windows build */
  28. #ifdef NUMCOLORS
  29. #undef NUMCOLORS
  30. #endif
  31. #define NUMCOLORS 8
  32. char *
  33. gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist,
  34. double ptsize, double angle, int x, int y, char *string)
  35. {
  36. /* 2.0.6: valid return */
  37. return gdImageStringFT (im, brect, fg, fontlist, ptsize, angle, x, y, string);
  38. }
  39. #ifndef HAVE_LIBFREETYPE
  40. char *
  41. gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
  42. double ptsize, double angle, int x, int y, char *string,
  43. gdFTStringExtraPtr strex)
  44. {
  45. return "libgd was not built with FreeType font support\n";
  46. }
  47. char *
  48. gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
  49. double ptsize, double angle, int x, int y, char *string)
  50. {
  51. return "libgd was not built with FreeType font support\n";
  52. }
  53. #else
  54. #include "gdcache.h"
  55. #include <ft2build.h>
  56. #include FT_FREETYPE_H
  57. #include FT_GLYPH_H
  58. /* number of fonts cached before least recently used is replaced */
  59. #define FONTCACHESIZE 6
  60. /* number of antialias color lookups cached */
  61. #define TWEENCOLORCACHESIZE 32
  62. /*
  63. * Line separation as a factor of font height.
  64. * No space between if LINESPACE = 1.00
  65. * Line separation will be rounded up to next pixel row.
  66. */
  67. #define LINESPACE 1.05
  68. /*
  69. * The character (space) used to separate alternate fonts in the
  70. * fontlist parameter to gdImageStringFT. 2.0.18: space was a oor choice for this.
  71. */
  72. #define LISTSEPARATOR ";"
  73. /*
  74. * DEFAULT_FONTPATH and PATHSEPARATOR are host type dependent and
  75. * are normally set by configure in config.h. These are just
  76. * some last resort values that might match some Un*x system
  77. * if building this version of gd separate from graphviz.
  78. */
  79. #ifndef DEFAULT_FONTPATH
  80. #if defined(__APPLE__) || (defined(__MWERKS__) && defined(macintosh))
  81. #define DEFAULT_FONTPATH "/usr/share/fonts/truetype:/System/Library/Fonts:/Library/Fonts"
  82. #else
  83. #define DEFAULT_FONTPATH "/usr/share/fonts/truetype"
  84. #endif
  85. #endif
  86. #ifndef PATHSEPARATOR
  87. #define PATHSEPARATOR ":"
  88. #endif
  89. #ifndef TRUE
  90. #define FALSE 0
  91. #define TRUE !FALSE
  92. #endif
  93. #ifndef MAX
  94. #define MAX(a,b) ((a)>(b)?(a):(b))
  95. #endif
  96. #ifndef MIN
  97. #define MIN(a,b) ((a)<(b)?(a):(b))
  98. #endif
  99. typedef struct
  100. {
  101. char *fontlist; /* key */
  102. FT_Library *library;
  103. FT_Face face;
  104. FT_Bool have_char_map_unicode, have_char_map_big5, have_char_map_sjis, have_char_map_apple_roman;
  105. gdCache_head_t *glyphCache;
  106. } font_t;
  107. typedef struct
  108. {
  109. char *fontlist; /* key */
  110. int preferred_map;
  111. FT_Library *library;
  112. } fontkey_t;
  113. typedef struct
  114. {
  115. int pixel; /* key */
  116. int bgcolor; /* key */
  117. int fgcolor; /* key *//* -ve means no antialias */
  118. gdImagePtr im; /* key */
  119. int tweencolor;
  120. } tweencolor_t;
  121. typedef struct
  122. {
  123. int pixel; /* key */
  124. int bgcolor; /* key */
  125. int fgcolor; /* key *//* -ve means no antialias */
  126. gdImagePtr im; /* key */
  127. } tweencolorkey_t;
  128. /********************************************************************
  129. * gdTcl_UtfToUniChar is borrowed from Tcl ...
  130. */
  131. /*
  132. * tclUtf.c --
  133. *
  134. * Routines for manipulating UTF-8 strings.
  135. *
  136. * Copyright (c) 1997-1998 Sun Microsystems, Inc.
  137. *
  138. * See the file "license.terms" for information on usage and redistribution
  139. * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  140. *
  141. * SCCS: @(#) tclUtf.c 1.25 98/01/28 18:02:43
  142. */
  143. /*
  144. *---------------------------------------------------------------------------
  145. *
  146. * gdTcl_UtfToUniChar --
  147. *
  148. * Extract the Tcl_UniChar represented by the UTF-8 string. Bad
  149. * UTF-8 sequences are converted to valid Tcl_UniChars and processing
  150. * continues. Equivalent to Plan 9 chartorune().
  151. *
  152. * The caller must ensure that the source buffer is long enough that
  153. * this routine does not run off the end and dereference non-existent
  154. * memory looking for trail bytes. If the source buffer is known to
  155. * be '\0' terminated, this cannot happen. Otherwise, the caller
  156. * should call Tcl_UtfCharComplete() before calling this routine to
  157. * ensure that enough bytes remain in the string.
  158. *
  159. * Results:
  160. * *chPtr is filled with the Tcl_UniChar, and the return value is the
  161. * number of bytes from the UTF-8 string that were consumed.
  162. *
  163. * Side effects:
  164. * None.
  165. *
  166. *---------------------------------------------------------------------------
  167. */
  168. #ifdef JISX0208
  169. #include "jisx0208.h"
  170. #endif
  171. extern int any2eucjp (char *, char *, unsigned int);
  172. /* Persistent font cache until explicitly cleared */
  173. /* Fonts can be used across multiple images */
  174. /* 2.0.16: thread safety (the font cache is shared) */
  175. gdMutexDeclare(gdFontCacheMutex);
  176. static gdCache_head_t *fontCache = NULL;
  177. static FT_Library library;
  178. #define Tcl_UniChar int
  179. #define TCL_UTF_MAX 3
  180. static int gdTcl_UtfToUniChar (char *str, Tcl_UniChar * chPtr)
  181. /* str is the UTF8 next character pointer */
  182. /* chPtr is the int for the result */
  183. {
  184. int byte;
  185. /* HTML4.0 entities in decimal form, e.g. &#197; */
  186. byte = *((unsigned char *) str);
  187. if (byte == '&') {
  188. int i, n = 0;
  189. byte = *((unsigned char *) (str + 1));
  190. if (byte == '#') {
  191. byte = *((unsigned char *) (str + 2));
  192. if (byte == 'x' || byte == 'X') {
  193. for (i = 3; i < 8; i++) {
  194. byte = *((unsigned char *) (str + i));
  195. if (byte >= 'A' && byte <= 'F')
  196. byte = byte - 'A' + 10;
  197. else if (byte >= 'a' && byte <= 'f')
  198. byte = byte - 'a' + 10;
  199. else if (byte >= '0' && byte <= '9')
  200. byte = byte - '0';
  201. else
  202. break;
  203. n = (n * 16) + byte;
  204. }
  205. } else {
  206. for (i = 2; i < 8; i++) {
  207. byte = *((unsigned char *) (str + i));
  208. if (byte >= '0' && byte <= '9') {
  209. n = (n * 10) + (byte - '0');
  210. } else {
  211. break;
  212. }
  213. }
  214. }
  215. if (byte == ';') {
  216. *chPtr = (Tcl_UniChar) n;
  217. return ++i;
  218. }
  219. }
  220. }
  221. /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */
  222. byte = *((unsigned char *) str);
  223. #ifdef JISX0208
  224. if (0xA1 <= byte && byte <= 0xFE) {
  225. int ku, ten;
  226. ku = (byte & 0x7F) - 0x20;
  227. ten = (str[1] & 0x7F) - 0x20;
  228. if ((ku < 1 || ku > 92) || (ten < 1 || ten > 94)) {
  229. *chPtr = (Tcl_UniChar) byte;
  230. return 1;
  231. }
  232. *chPtr = (Tcl_UniChar) UnicodeTbl[ku - 1][ten - 1];
  233. return 2;
  234. } else
  235. #endif /* JISX0208 */
  236. if (byte < 0xC0) {
  237. /* Handles properly formed UTF-8 characters between
  238. * 0x01 and 0x7F. Also treats \0 and naked trail
  239. * bytes 0x80 to 0xBF as valid characters representing
  240. * themselves.
  241. */
  242. *chPtr = (Tcl_UniChar) byte;
  243. return 1;
  244. } else if (byte < 0xE0) {
  245. if ((str[1] & 0xC0) == 0x80) {
  246. /* Two-byte-character lead-byte followed by a trail-byte. */
  247. *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (str[1] & 0x3F));
  248. return 2;
  249. }
  250. /*
  251. * A two-byte-character lead-byte not followed by trail-byte
  252. * represents itself.
  253. */
  254. *chPtr = (Tcl_UniChar) byte;
  255. return 1;
  256. } else if (byte < 0xF0) {
  257. if (((str[1] & 0xC0) == 0x80) && ((str[2] & 0xC0) == 0x80)) {
  258. /* Three-byte-character lead byte followed by two trail bytes. */
  259. *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F));
  260. return 3;
  261. }
  262. /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */
  263. *chPtr = (Tcl_UniChar) byte;
  264. return 1;
  265. }
  266. #if TCL_UTF_MAX > 3
  267. else {
  268. int ch, total, trail;
  269. total = totalBytes[byte];
  270. trail = total - 1;
  271. if (trail > 0) {
  272. ch = byte & (0x3F >> trail);
  273. do {
  274. str++;
  275. if ((*str & 0xC0) != 0x80) {
  276. *chPtr = byte;
  277. return 1;
  278. }
  279. ch <<= 6;
  280. ch |= (*str & 0x3F);
  281. trail--;
  282. } while (trail > 0);
  283. *chPtr = ch;
  284. return total;
  285. }
  286. }
  287. #endif
  288. *chPtr = (Tcl_UniChar) byte;
  289. return 1;
  290. }
  291. /********************************************************************/
  292. /* font cache functions */
  293. static int fontTest (void *element, void *key)
  294. {
  295. font_t *a = (font_t *) element;
  296. fontkey_t *b = (fontkey_t *) key;
  297. if (strcmp (a->fontlist, b->fontlist) == 0) {
  298. switch (b->preferred_map) {
  299. case gdFTEX_Unicode:
  300. if (a->have_char_map_unicode) {
  301. return 1;
  302. }
  303. break;
  304. case gdFTEX_Shift_JIS:
  305. if (a->have_char_map_sjis) {
  306. return 1;
  307. }
  308. break;
  309. case gdFTEX_Big5:
  310. if (a->have_char_map_sjis) {
  311. return 1;
  312. }
  313. break;
  314. }
  315. }
  316. return 0;
  317. }
  318. static void *fontFetch (char **error, void *key)
  319. {
  320. font_t *a;
  321. fontkey_t *b = (fontkey_t *) key;
  322. int n;
  323. int font_found = 0;
  324. unsigned short platform, encoding;
  325. char *fontsearchpath, *fontlist;
  326. char fullname[MAXPATHLEN], cur_dir[MAXPATHLEN];
  327. char *name, *path=NULL, *dir;
  328. char *strtok_ptr;
  329. FT_Error err;
  330. FT_CharMap found = 0;
  331. FT_CharMap charmap;
  332. a = (font_t *) gdPMalloc(sizeof(font_t));
  333. a->fontlist = gdPEstrdup(b->fontlist);
  334. a->library = b->library;
  335. /*
  336. * Search the pathlist for any of a list of font names.
  337. */
  338. fontsearchpath = getenv ("GDFONTPATH");
  339. if (!fontsearchpath) {
  340. fontsearchpath = DEFAULT_FONTPATH;
  341. }
  342. fontlist = gdEstrdup(a->fontlist);
  343. /*
  344. * Must use gd_strtok_r becasuse strtok() isn't thread safe
  345. */
  346. for (name = gd_strtok_r (fontlist, LISTSEPARATOR, &strtok_ptr); name; name = gd_strtok_r (0, LISTSEPARATOR, &strtok_ptr)) {
  347. char *strtok_ptr_path;
  348. /* make a fresh copy each time - strtok corrupts it. */
  349. path = gdEstrdup (fontsearchpath);
  350. /* if name is an absolute filename then test directly */
  351. #ifdef NETWARE
  352. if (*name == '/' || (name[0] != 0 && strstr(name, ":/"))) {
  353. #else
  354. if (*name == '/' || (name[0] != 0 && name[1] == ':' && (name[2] == '/' || name[2] == '\\'))) {
  355. #endif
  356. snprintf(fullname, sizeof(fullname) - 1, "%s", name);
  357. if (access(fullname, R_OK) == 0) {
  358. font_found++;
  359. break;
  360. }
  361. }
  362. for (dir = gd_strtok_r (path, PATHSEPARATOR, &strtok_ptr_path); dir;
  363. dir = gd_strtok_r (0, PATHSEPARATOR, &strtok_ptr_path)) {
  364. if (!strcmp(dir, ".")) {
  365. TSRMLS_FETCH();
  366. #if HAVE_GETCWD
  367. dir = VCWD_GETCWD(cur_dir, MAXPATHLEN);
  368. #elif HAVE_GETWD
  369. dir = VCWD_GETWD(cur_dir);
  370. #endif
  371. if (!dir) {
  372. continue;
  373. }
  374. }
  375. #define GD_CHECK_FONT_PATH(ext) \
  376. snprintf(fullname, sizeof(fullname) - 1, "%s/%s%s", dir, name, ext); \
  377. if (access(fullname, R_OK) == 0) { \
  378. font_found++; \
  379. break; \
  380. } \
  381. GD_CHECK_FONT_PATH("");
  382. GD_CHECK_FONT_PATH(".ttf");
  383. GD_CHECK_FONT_PATH(".pfa");
  384. GD_CHECK_FONT_PATH(".pfb");
  385. GD_CHECK_FONT_PATH(".dfont");
  386. }
  387. gdFree(path);
  388. path = NULL;
  389. if (font_found) {
  390. break;
  391. }
  392. }
  393. if (path) {
  394. gdFree(path);
  395. }
  396. gdFree(fontlist);
  397. if (!font_found) {
  398. gdPFree(a->fontlist);
  399. gdPFree(a);
  400. *error = "Could not find/open font";
  401. return NULL;
  402. }
  403. err = FT_New_Face (*b->library, fullname, 0, &a->face);
  404. if (err) {
  405. gdPFree(a->fontlist);
  406. gdPFree(a);
  407. *error = "Could not read font";
  408. return NULL;
  409. }
  410. /* FIXME - This mapping stuff is incomplete - where is the spec? */
  411. /* EAM - It's worse than that. It's pointless to match character encodings here.
  412. * As currently written, the stored a->face->charmap only matches one of
  413. * the actual charmaps and we cannot know at this stage if it is the right
  414. * one. We should just skip all this stuff, and check in gdImageStringFTEx
  415. * if some particular charmap is preferred and if so whether it is held in
  416. * one of the a->face->charmaps[0..num_charmaps].
  417. * And why is it so bad not to find any recognized charmap? The user may
  418. * still know what mapping to use, even if we do not. In that case we can
  419. * just use the map in a->face->charmaps[num_charmaps] and be done with it.
  420. */
  421. for (n = 0; n < a->face->num_charmaps; n++) {
  422. charmap = a->face->charmaps[n];
  423. platform = charmap->platform_id;
  424. encoding = charmap->encoding_id;
  425. /* Whatever is the last value is what should be set */
  426. a->have_char_map_unicode = 0;
  427. a->have_char_map_big5 = 0;
  428. a->have_char_map_sjis = 0;
  429. a->have_char_map_apple_roman = 0;
  430. /* EAM DEBUG - Newer versions of libfree2 make it easier by defining encodings */
  431. #if (defined(FREETYPE_MAJOR) && ((FREETYPE_MAJOR == 2 && ((FREETYPE_MINOR == 1 && FREETYPE_PATCH >= 3) || FREETYPE_MINOR > 1) || FREETYPE_MAJOR > 2)))
  432. if (charmap->encoding == FT_ENCODING_MS_SYMBOL
  433. || charmap->encoding == FT_ENCODING_ADOBE_CUSTOM
  434. || charmap->encoding == FT_ENCODING_ADOBE_STANDARD) {
  435. a->have_char_map_unicode = 1;
  436. found = charmap;
  437. a->face->charmap = charmap;
  438. return (void *)a;
  439. }
  440. #endif /* Freetype 2.1.3 or better */
  441. /* EAM DEBUG */
  442. if ((platform == 3 && encoding == 1) /* Windows Unicode */
  443. || (platform == 3 && encoding == 0) /* Windows Symbol */
  444. || (platform == 2 && encoding == 1) /* ISO Unicode */
  445. || (platform == 0))
  446. { /* Apple Unicode */
  447. a->have_char_map_unicode = 1;
  448. found = charmap;
  449. if (b->preferred_map == gdFTEX_Unicode) {
  450. break;
  451. }
  452. } else if (platform == 3 && encoding == 4) { /* Windows Big5 */
  453. a->have_char_map_big5 = 1;
  454. found = charmap;
  455. if (b->preferred_map == gdFTEX_Big5) {
  456. break;
  457. }
  458. } else if (platform == 3 && encoding == 2) { /* Windows Sjis */
  459. a->have_char_map_sjis = 1;
  460. found = charmap;
  461. if (b->preferred_map == gdFTEX_Shift_JIS) {
  462. break;
  463. }
  464. } else if ((platform == 1 && encoding == 0) /* Apple Roman */
  465. || (platform == 2 && encoding == 0))
  466. { /* ISO ASCII */
  467. a->have_char_map_apple_roman = 1;
  468. found = charmap;
  469. if (b->preferred_map == gdFTEX_MacRoman) {
  470. break;
  471. }
  472. }
  473. }
  474. if (!found) {
  475. gdPFree(a->fontlist);
  476. gdPFree(a);
  477. *error = "Unable to find a CharMap that I can handle";
  478. return NULL;
  479. }
  480. /* 2.0.5: we should actually return this */
  481. a->face->charmap = found;
  482. return (void *) a;
  483. }
  484. static void fontRelease (void *element)
  485. {
  486. font_t *a = (font_t *) element;
  487. FT_Done_Face (a->face);
  488. gdPFree(a->fontlist);
  489. gdPFree((char *) element);
  490. }
  491. /********************************************************************/
  492. /* tweencolor cache functions */
  493. static int tweenColorTest (void *element, void *key)
  494. {
  495. tweencolor_t *a = (tweencolor_t *) element;
  496. tweencolorkey_t *b = (tweencolorkey_t *) key;
  497. return (a->pixel == b->pixel && a->bgcolor == b->bgcolor && a->fgcolor == b->fgcolor && a->im == b->im);
  498. }
  499. /*
  500. * Computes a color in im's color table that is part way between
  501. * the background and foreground colors proportional to the gray
  502. * pixel value in the range 0-NUMCOLORS. The fg and bg colors must already
  503. * be in the color table for palette images. For truecolor images the
  504. * returned value simply has an alpha component and gdImageAlphaBlend
  505. * does the work so that text can be alpha blended across a complex
  506. * background (TBB; and for real in 2.0.2).
  507. */
  508. static void * tweenColorFetch (char **error, void *key)
  509. {
  510. tweencolor_t *a;
  511. tweencolorkey_t *b = (tweencolorkey_t *) key;
  512. int pixel, npixel, bg, fg;
  513. gdImagePtr im;
  514. a = (tweencolor_t *) gdMalloc (sizeof (tweencolor_t));
  515. pixel = a->pixel = b->pixel;
  516. bg = a->bgcolor = b->bgcolor;
  517. fg = a->fgcolor = b->fgcolor;
  518. im = a->im = b->im;
  519. /* if fg is specified by a negative color idx, then don't antialias */
  520. if (fg < 0) {
  521. if ((pixel + pixel) >= NUMCOLORS) {
  522. a->tweencolor = -fg;
  523. } else {
  524. a->tweencolor = bg;
  525. }
  526. } else {
  527. npixel = NUMCOLORS - pixel;
  528. if (im->trueColor) {
  529. /* 2.0.1: use gdImageSetPixel to do the alpha blending work,
  530. * or to just store the alpha level. All we have to do here
  531. * is incorporate our knowledge of the percentage of this
  532. * pixel that is really "lit" by pushing the alpha value
  533. * up toward transparency in edge regions.
  534. */
  535. a->tweencolor = gdTrueColorAlpha(
  536. gdTrueColorGetRed(fg),
  537. gdTrueColorGetGreen(fg),
  538. gdTrueColorGetBlue(fg),
  539. gdAlphaMax - (gdTrueColorGetAlpha (fg) * pixel / NUMCOLORS));
  540. } else {
  541. a->tweencolor = gdImageColorResolve(im,
  542. (pixel * im->red[fg] + npixel * im->red[bg]) / NUMCOLORS,
  543. (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS,
  544. (pixel * im->blue[fg] + npixel * im->blue[bg]) / NUMCOLORS);
  545. }
  546. }
  547. return (void *) a;
  548. }
  549. static void tweenColorRelease (void *element)
  550. {
  551. gdFree((char *) element);
  552. }
  553. /* draw_bitmap - transfers glyph bitmap to GD image */
  554. static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
  555. {
  556. unsigned char *pixel = NULL;
  557. int *tpixel = NULL;
  558. int x, y, row, col, pc, pcr;
  559. tweencolor_t *tc_elem;
  560. tweencolorkey_t tc_key;
  561. /* copy to image, mapping colors */
  562. tc_key.fgcolor = fg;
  563. tc_key.im = im;
  564. /* Truecolor version; does not require the cache */
  565. if (im->trueColor) {
  566. for (row = 0; row < bitmap.rows; row++) {
  567. pc = row * bitmap.pitch;
  568. pcr = pc;
  569. y = pen_y + row;
  570. /* clip if out of bounds */
  571. /* 2.0.16: clipping rectangle, not image bounds */
  572. if ((y > im->cy2) || (y < im->cy1)) {
  573. continue;
  574. }
  575. for (col = 0; col < bitmap.width; col++, pc++) {
  576. int level;
  577. if (bitmap.pixel_mode == ft_pixel_mode_grays) {
  578. /* Scale to 128 levels of alpha for gd use.
  579. * alpha 0 is opacity, so be sure to invert at the end
  580. */
  581. level = (bitmap.buffer[pc] * gdAlphaMax / (bitmap.num_grays - 1));
  582. } else if (bitmap.pixel_mode == ft_pixel_mode_mono) {
  583. /* 2.0.5: mode_mono fix from Giuliano Pochini */
  584. level = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07))) ? gdAlphaTransparent : gdAlphaOpaque;
  585. } else {
  586. return "Unsupported ft_pixel_mode";
  587. }
  588. if (level == 0) /* if background */
  589. continue;
  590. if ((fg >= 0) && (im->trueColor)) {
  591. /* Consider alpha in the foreground color itself to be an
  592. * upper bound on how opaque things get, when truecolor is
  593. * available. Without truecolor this results in far too many
  594. * color indexes.
  595. */
  596. level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax;
  597. }
  598. level = gdAlphaMax - level;
  599. x = pen_x + col;
  600. /* clip if out of bounds */
  601. /* 2.0.16: clip to clipping rectangle, Matt McNabb */
  602. if ((x > im->cx2) || (x < im->cx1)) {
  603. continue;
  604. }
  605. /* get pixel location in gd buffer */
  606. tpixel = &im->tpixels[y][x];
  607. if (fg < 0) {
  608. if (level < (gdAlphaMax / 2)) {
  609. *tpixel = -fg;
  610. }
  611. } else {
  612. if (im->alphaBlendingFlag) {
  613. *tpixel = gdAlphaBlend(*tpixel, (level << 24) + (fg & 0xFFFFFF));
  614. } else {
  615. *tpixel = (level << 24) + (fg & 0xFFFFFF);
  616. }
  617. }
  618. }
  619. }
  620. return (char *) NULL;
  621. }
  622. /* Non-truecolor case, restored to its more or less original form */
  623. for (row = 0; row < bitmap.rows; row++) {
  624. int pcr;
  625. pc = row * bitmap.pitch;
  626. pcr = pc;
  627. if (bitmap.pixel_mode==ft_pixel_mode_mono) {
  628. pc *= 8; /* pc is measured in bits for monochrome images */
  629. }
  630. y = pen_y + row;
  631. /* clip if out of bounds */
  632. if (y >= im->sy || y < 0) {
  633. continue;
  634. }
  635. for (col = 0; col < bitmap.width; col++, pc++) {
  636. if (bitmap.pixel_mode == ft_pixel_mode_grays) {
  637. /*
  638. * Round to NUMCOLORS levels of antialiasing for
  639. * index color images since only 256 colors are
  640. * available.
  641. */
  642. tc_key.pixel = ((bitmap.buffer[pc] * NUMCOLORS) + bitmap.num_grays / 2) / (bitmap.num_grays - 1);
  643. } else if (bitmap.pixel_mode == ft_pixel_mode_mono) {
  644. tc_key.pixel = ((bitmap.buffer[pc / 8] << (pc % 8)) & 128) ? NUMCOLORS : 0;
  645. /* 2.0.5: mode_mono fix from Giuliano Pochini */
  646. tc_key.pixel = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07))) ? NUMCOLORS : 0;
  647. } else {
  648. return "Unsupported ft_pixel_mode";
  649. }
  650. if (tc_key.pixel > 0) { /* if not background */
  651. x = pen_x + col;
  652. /* clip if out of bounds */
  653. if (x >= im->sx || x < 0) {
  654. continue;
  655. }
  656. /* get pixel location in gd buffer */
  657. pixel = &im->pixels[y][x];
  658. if (tc_key.pixel == NUMCOLORS) {
  659. /* use fg color directly. gd 2.0.2: watch out for
  660. * negative indexes (thanks to David Marwood).
  661. */
  662. *pixel = (fg < 0) ? -fg : fg;
  663. } else {
  664. /* find antialised color */
  665. tc_key.bgcolor = *pixel;
  666. tc_elem = (tweencolor_t *) gdCacheGet(tc_cache, &tc_key);
  667. *pixel = tc_elem->tweencolor;
  668. }
  669. }
  670. }
  671. }
  672. return (char *) NULL;
  673. }
  674. static int
  675. gdroundupdown (FT_F26Dot6 v1, int roundup)
  676. {
  677. return (!roundup) ? v1 >> 6 : (v1 + 63) >> 6;
  678. }
  679. void gdFontCacheShutdown()
  680. {
  681. gdMutexLock(gdFontCacheMutex);
  682. if (fontCache) {
  683. gdCacheDelete(fontCache);
  684. fontCache = NULL;
  685. FT_Done_FreeType(library);
  686. }
  687. gdMutexUnlock(gdFontCacheMutex);
  688. }
  689. void gdFreeFontCache()
  690. {
  691. gdFontCacheShutdown();
  692. }
  693. void gdFontCacheMutexSetup()
  694. {
  695. gdMutexSetup(gdFontCacheMutex);
  696. }
  697. void gdFontCacheMutexShutdown()
  698. {
  699. gdMutexShutdown(gdFontCacheMutex);
  700. }
  701. int gdFontCacheSetup(void)
  702. {
  703. if (fontCache) {
  704. /* Already set up */
  705. return 0;
  706. }
  707. if (FT_Init_FreeType(&library)) {
  708. return -1;
  709. }
  710. fontCache = gdCacheCreate (FONTCACHESIZE, fontTest, fontFetch, fontRelease);
  711. return 0;
  712. }
  713. /********************************************************************/
  714. /* gdImageStringFT - render a utf8 string onto a gd image */
  715. char *
  716. gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
  717. double ptsize, double angle, int x, int y, char *string)
  718. {
  719. return gdImageStringFTEx(im, brect, fg, fontlist, ptsize, angle, x, y, string, 0);
  720. }
  721. char *
  722. gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, double ptsize, double angle, int x, int y, char *string, gdFTStringExtraPtr strex)
  723. {
  724. FT_BBox bbox, glyph_bbox;
  725. FT_Matrix matrix;
  726. FT_Vector pen, delta, penf;
  727. FT_Face face;
  728. FT_Glyph image;
  729. FT_GlyphSlot slot;
  730. FT_Bool use_kerning;
  731. FT_UInt glyph_index, previous;
  732. double sin_a = sin (angle);
  733. double cos_a = cos (angle);
  734. int len, i = 0, ch;
  735. int x1 = 0, y1 = 0;
  736. font_t *font;
  737. fontkey_t fontkey;
  738. char *next;
  739. char *tmpstr = NULL;
  740. int render = (im && (im->trueColor || (fg <= 255 && fg >= -255)));
  741. FT_BitmapGlyph bm;
  742. /* 2.0.13: Bob Ostermann: don't force autohint, that's just for testing freetype and doesn't look as good */
  743. int render_mode = FT_LOAD_DEFAULT;
  744. int m, mfound;
  745. /* Now tuneable thanks to Wez Furlong */
  746. double linespace = LINESPACE;
  747. /* 2.0.6: put this declaration with the other declarations! */
  748. /*
  749. * make a new tweenColorCache on every call
  750. * because caching colormappings between calls
  751. * is not safe. If the im-pointer points to a
  752. * brand new image, the cache gives out bogus
  753. * colorindexes. -- 27.06.2001 <krisku@arrak.fi>
  754. */
  755. gdCache_head_t *tc_cache;
  756. /* Tuneable horizontal and vertical resolution in dots per inch */
  757. int hdpi, vdpi;
  758. if (strex && ((strex->flags & gdFTEX_LINESPACE) == gdFTEX_LINESPACE)) {
  759. linespace = strex->linespacing;
  760. }
  761. tc_cache = gdCacheCreate(TWEENCOLORCACHESIZE, tweenColorTest, tweenColorFetch, tweenColorRelease);
  762. /***** initialize font library and font cache on first call ******/
  763. gdMutexLock(gdFontCacheMutex);
  764. if (!fontCache) {
  765. if (gdFontCacheSetup() != 0) {
  766. gdCacheDelete(tc_cache);
  767. gdMutexUnlock(gdFontCacheMutex);
  768. return "Failure to initialize font library";
  769. }
  770. }
  771. /*****/
  772. /* 2.0.12: allow explicit specification of the preferred map;
  773. * but we still fall back if it is not available.
  774. */
  775. m = gdFTEX_Unicode;
  776. if (strex && (strex->flags & gdFTEX_CHARMAP)) {
  777. m = strex->charmap;
  778. }
  779. /* get the font (via font cache) */
  780. fontkey.fontlist = fontlist;
  781. fontkey.library = &library;
  782. fontkey.preferred_map = m;
  783. font = (font_t *) gdCacheGet (fontCache, &fontkey);
  784. if (!font) {
  785. gdCacheDelete(tc_cache);
  786. gdMutexUnlock(gdFontCacheMutex);
  787. return fontCache->error;
  788. }
  789. face = font->face; /* shortcut */
  790. slot = face->glyph; /* shortcut */
  791. /*
  792. * Added hdpi and vdpi to support images at non-screen resolutions, i.e. 300 dpi TIFF,
  793. * or 100h x 50v dpi FAX format. 2.0.23.
  794. * 2004/02/27 Mark Shackelford, mark.shackelford@acs-inc.com
  795. */
  796. hdpi = GD_RESOLUTION;
  797. vdpi = GD_RESOLUTION;
  798. if (strex && (strex->flags & gdFTEX_RESOLUTION)) {
  799. hdpi = strex->hdpi;
  800. vdpi = strex->vdpi;
  801. }
  802. if (FT_Set_Char_Size(face, 0, (FT_F26Dot6) (ptsize * 64), hdpi, vdpi)) {
  803. gdCacheDelete(tc_cache);
  804. gdMutexUnlock(gdFontCacheMutex);
  805. return "Could not set character size";
  806. }
  807. matrix.xx = (FT_Fixed) (cos_a * (1 << 16));
  808. matrix.yx = (FT_Fixed) (sin_a * (1 << 16));
  809. matrix.xy = -matrix.yx;
  810. matrix.yy = matrix.xx;
  811. penf.x = penf.y = 0; /* running position of non-rotated string */
  812. pen.x = pen.y = 0; /* running position of rotated string */
  813. bbox.xMin = bbox.xMax = bbox.yMin = bbox.yMax = 0;
  814. use_kerning = FT_HAS_KERNING (face);
  815. previous = 0;
  816. if (fg < 0) {
  817. render_mode |= FT_LOAD_MONOCHROME;
  818. }
  819. /* Try all three types of maps, but start with the specified one */
  820. mfound = 0;
  821. for (i = 0; i < 3; i++) {
  822. switch (m) {
  823. case gdFTEX_Unicode:
  824. if (font->have_char_map_unicode) {
  825. mfound = 1;
  826. }
  827. break;
  828. case gdFTEX_Shift_JIS:
  829. if (font->have_char_map_sjis) {
  830. mfound = 1;
  831. }
  832. break;
  833. case gdFTEX_Big5:
  834. /* This was the 'else' case, we can't really 'detect' it */
  835. mfound = 1;
  836. break;
  837. }
  838. if (mfound) {
  839. break;
  840. }
  841. m++;
  842. m %= 3;
  843. }
  844. if (!mfound) {
  845. /* No character set found! */
  846. gdMutexUnlock(gdFontCacheMutex);
  847. return "No character set found";
  848. }
  849. #ifndef JISX0208
  850. if (font->have_char_map_sjis) {
  851. #endif
  852. tmpstr = (char *) gdMalloc(BUFSIZ);
  853. any2eucjp(tmpstr, string, BUFSIZ);
  854. next = tmpstr;
  855. #ifndef JISX0208
  856. } else {
  857. next = string;
  858. }
  859. #endif
  860. i = 0;
  861. while (*next) {
  862. ch = *next;
  863. /* carriage returns */
  864. if (ch == '\r') {
  865. penf.x = 0;
  866. x1 = (int)(- penf.y * sin_a + 32) / 64;
  867. y1 = (int)(- penf.y * cos_a + 32) / 64;
  868. pen.x = pen.y = 0;
  869. previous = 0; /* clear kerning flag */
  870. next++;
  871. continue;
  872. }
  873. /* newlines */
  874. if (ch == '\n') {
  875. if (!*(++next)) break;
  876. /* 2.0.13: reset penf.x. Christopher J. Grayce */
  877. penf.x = 0;
  878. penf.y -= (long)(face->size->metrics.height * linespace);
  879. penf.y = (penf.y - 32) & -64; /* round to next pixel row */
  880. x1 = (int)(- penf.y * sin_a + 32) / 64;
  881. y1 = (int)(- penf.y * cos_a + 32) / 64;
  882. pen.x = pen.y = 0;
  883. previous = 0; /* clear kerning flag */
  884. continue;
  885. }
  886. /* EAM DEBUG */
  887. #if (defined(FREETYPE_MAJOR) && ((FREETYPE_MAJOR == 2 && ((FREETYPE_MINOR == 1 && FREETYPE_PATCH >= 3) || FREETYPE_MINOR > 1) || FREETYPE_MAJOR > 2)))
  888. if (font->face->family_name && font->face->charmap->encoding &&
  889. font->face->charmap->encoding == FT_ENCODING_MS_SYMBOL && strcmp(font->face->family_name, "Symbol") == 0) {
  890. /* I do not know the significance of the constant 0xf000.
  891. * It was determined by inspection of the character codes
  892. * stored in Microsoft font symbol.
  893. * Added by Pierre (pajoye@php.net):
  894. * Convert to the Symbol glyph range only for a Symbol family member
  895. */
  896. len = gdTcl_UtfToUniChar (next, &ch);
  897. ch |= 0xf000;
  898. next += len;
  899. } else
  900. #endif /* Freetype 2.1 or better */
  901. /* EAM DEBUG */
  902. switch (m) {
  903. case gdFTEX_Unicode:
  904. if (font->have_char_map_unicode) {
  905. /* use UTF-8 mapping from ASCII */
  906. len = gdTcl_UtfToUniChar(next, &ch);
  907. next += len;
  908. }
  909. break;
  910. case gdFTEX_Shift_JIS:
  911. if (font->have_char_map_sjis) {
  912. unsigned char c;
  913. int jiscode;
  914. c = *next;
  915. if (0xA1 <= c && c <= 0xFE) {
  916. next++;
  917. jiscode = 0x100 * (c & 0x7F) + ((*next) & 0x7F);
  918. ch = (jiscode >> 8) & 0xFF;
  919. jiscode &= 0xFF;
  920. if (ch & 1) {
  921. jiscode += 0x40 - 0x21;
  922. } else {
  923. jiscode += 0x9E - 0x21;
  924. }
  925. if (jiscode >= 0x7F) {
  926. jiscode++;
  927. }
  928. ch = (ch - 0x21) / 2 + 0x81;
  929. if (ch >= 0xA0) {
  930. ch += 0x40;
  931. }
  932. ch = (ch << 8) + jiscode;
  933. } else {
  934. ch = c & 0xFF; /* don't extend sign */
  935. }
  936. if (*next) next++;
  937. }
  938. break;
  939. case gdFTEX_Big5: {
  940. /*
  941. * Big 5 mapping:
  942. * use "JIS-8 half-width katakana" coding from 8-bit characters. Ref:
  943. * ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/japan.inf-032092.sjs
  944. */
  945. ch = (*next) & 0xFF; /* don't extend sign */
  946. next++;
  947. if (ch >= 161 /* first code of JIS-8 pair */
  948. && *next) { /* don't advance past '\0' */
  949. /* TBB: Fix from Kwok Wah On: & 255 needed */
  950. ch = (ch * 256) + ((*next) & 255);
  951. next++;
  952. }
  953. }
  954. break;
  955. }
  956. /* set rotation transform */
  957. FT_Set_Transform(face, &matrix, NULL);
  958. /* Convert character code to glyph index */
  959. glyph_index = FT_Get_Char_Index(face, ch);
  960. /* retrieve kerning distance and move pen position */
  961. if (use_kerning && previous && glyph_index) {
  962. FT_Get_Kerning(face, previous, glyph_index, ft_kerning_default, &delta);
  963. pen.x += (int)(delta.x * cos_a);
  964. pen.y -= (int)(delta.x * sin_a);
  965. penf.x += delta.x;
  966. }
  967. if (brect) { /* only if need brect */
  968. /* load glyph image into the slot (erase previous one) */
  969. if (FT_Load_Glyph(face, glyph_index, render_mode | FT_LOAD_IGNORE_TRANSFORM)) {
  970. if (tmpstr) {
  971. gdFree(tmpstr);
  972. }
  973. gdCacheDelete(tc_cache);
  974. gdMutexUnlock(gdFontCacheMutex);
  975. return "Problem loading glyph";
  976. }
  977. /* transform glyph image */
  978. if (FT_Get_Glyph(slot, &image)) {
  979. if (tmpstr) {
  980. gdFree(tmpstr);
  981. }
  982. gdCacheDelete(tc_cache);
  983. gdMutexUnlock(gdFontCacheMutex);
  984. return "Problem loading glyph";
  985. }
  986. FT_Glyph_Get_CBox(image, ft_glyph_bbox_gridfit, &glyph_bbox);
  987. glyph_bbox.xMin += penf.x;
  988. glyph_bbox.yMin += penf.y;
  989. glyph_bbox.xMax += penf.x;
  990. glyph_bbox.yMax += penf.y;
  991. if (ch == ' ') { /* special case for trailing space */
  992. glyph_bbox.xMax += slot->metrics.horiAdvance;
  993. }
  994. if (!i) { /* if first character, init BB corner values */
  995. bbox.xMin = glyph_bbox.xMin;
  996. bbox.yMin = glyph_bbox.yMin;
  997. bbox.xMax = glyph_bbox.xMax;
  998. bbox.yMax = glyph_bbox.yMax;
  999. } else {
  1000. if (bbox.xMin > glyph_bbox.xMin) {
  1001. bbox.xMin = glyph_bbox.xMin;
  1002. }
  1003. if (bbox.yMin > glyph_bbox.yMin) {
  1004. bbox.yMin = glyph_bbox.yMin;
  1005. }
  1006. if (bbox.xMax < glyph_bbox.xMax) {
  1007. bbox.xMax = glyph_bbox.xMax;
  1008. }
  1009. if (bbox.yMax < glyph_bbox.yMax) {
  1010. bbox.yMax = glyph_bbox.yMax;
  1011. }
  1012. }
  1013. i++;
  1014. }
  1015. /* increment (unrotated) pen position */
  1016. penf.x += slot->metrics.horiAdvance;
  1017. if (render) {
  1018. if (!brect || angle != 0) {
  1019. /* reload the rotated glyph (for bbox we needed FT_LOAD_IGNORE_TRANSFORM - bbox is rotated later) */
  1020. FT_Done_Glyph(image);
  1021. /* load glyph image into the slot (erase previous one) */
  1022. if (FT_Load_Glyph(face, glyph_index, render_mode)) {
  1023. if (tmpstr) {
  1024. gdFree(tmpstr);
  1025. }
  1026. gdCacheDelete(tc_cache);
  1027. gdMutexUnlock(gdFontCacheMutex);
  1028. return "Problem loading glyph";
  1029. }
  1030. /* transform glyph image */
  1031. if (FT_Get_Glyph(slot, &image)) {
  1032. if (tmpstr) {
  1033. gdFree(tmpstr);
  1034. }
  1035. gdCacheDelete(tc_cache);
  1036. gdMutexUnlock(gdFontCacheMutex);
  1037. return "Problem loading glyph";
  1038. }
  1039. }
  1040. if (image->format != ft_glyph_format_bitmap && FT_Glyph_To_Bitmap(&image, ft_render_mode_normal, 0, 1)) {
  1041. FT_Done_Glyph(image);
  1042. if (tmpstr) {
  1043. gdFree(tmpstr);
  1044. }
  1045. gdCacheDelete(tc_cache);
  1046. gdMutexUnlock(gdFontCacheMutex);
  1047. return "Problem rendering glyph";
  1048. }
  1049. /* now, draw to our target surface */
  1050. bm = (FT_BitmapGlyph) image;
  1051. gdft_draw_bitmap(tc_cache, im, fg, bm->bitmap, x + x1 + ((pen.x + 31) >> 6) + bm->left, y + y1 + ((pen.y + 31) >> 6) - bm->top);
  1052. }
  1053. /* record current glyph index for kerning */
  1054. previous = glyph_index;
  1055. /* increment pen position */
  1056. pen.x += image->advance.x >> 10;
  1057. pen.y -= image->advance.y >> 10;
  1058. FT_Done_Glyph(image);
  1059. }
  1060. if (brect) { /* only if need brect */
  1061. /* For perfect rounding, must get sin(a + pi/4) and sin(a - pi/4). */
  1062. double d1 = sin (angle + 0.78539816339744830962);
  1063. double d2 = sin (angle - 0.78539816339744830962);
  1064. /* rotate bounding rectangle (at 0, 0) */
  1065. brect[0] = (int) (bbox.xMin * cos_a - bbox.yMin * sin_a);
  1066. brect[1] = (int) (bbox.xMin * sin_a + bbox.yMin * cos_a);
  1067. brect[2] = (int) (bbox.xMax * cos_a - bbox.yMin * sin_a);
  1068. brect[3] = (int) (bbox.xMax * sin_a + bbox.yMin * cos_a);
  1069. brect[4] = (int) (bbox.xMax * cos_a - bbox.yMax * sin_a);
  1070. brect[5] = (int) (bbox.xMax * sin_a + bbox.yMax * cos_a);
  1071. brect[6] = (int) (bbox.xMin * cos_a - bbox.yMax * sin_a);
  1072. brect[7] = (int) (bbox.xMin * sin_a + bbox.yMax * cos_a);
  1073. /* scale, round and offset brect */
  1074. brect[0] = x + gdroundupdown(brect[0], d2 > 0);
  1075. brect[1] = y - gdroundupdown(brect[1], d1 < 0);
  1076. brect[2] = x + gdroundupdown(brect[2], d1 > 0);
  1077. brect[3] = y - gdroundupdown(brect[3], d2 > 0);
  1078. brect[4] = x + gdroundupdown(brect[4], d2 < 0);
  1079. brect[5] = y - gdroundupdown(brect[5], d1 > 0);
  1080. brect[6] = x + gdroundupdown(brect[6], d1 < 0);
  1081. brect[7] = y - gdroundupdown(brect[7], d2 < 0);
  1082. }
  1083. if (tmpstr) {
  1084. gdFree(tmpstr);
  1085. }
  1086. gdCacheDelete(tc_cache);
  1087. gdMutexUnlock(gdFontCacheMutex);
  1088. return (char *) NULL;
  1089. }
  1090. #endif /* HAVE_LIBFREETYPE */