/src/freetype/src/bdf/bdfdrivr.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 882 lines · 612 code · 198 blank · 72 comment · 133 complexity · 6aa349dc9713a43163d841935443c175 MD5 · raw file

  1. /* bdfdrivr.c
  2. FreeType font driver for bdf files
  3. Copyright (C) 2001-2008, 2011 by
  4. Francesco Zappa Nardelli
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. */
  21. #include <ft2build.h>
  22. #include FT_INTERNAL_DEBUG_H
  23. #include FT_INTERNAL_STREAM_H
  24. #include FT_INTERNAL_OBJECTS_H
  25. #include FT_BDF_H
  26. #include FT_TRUETYPE_IDS_H
  27. #include FT_SERVICE_BDF_H
  28. #include FT_SERVICE_XFREE86_NAME_H
  29. #include "bdf.h"
  30. #include "bdfdrivr.h"
  31. #include "bdferror.h"
  32. /*************************************************************************/
  33. /* */
  34. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  35. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  36. /* messages during execution. */
  37. /* */
  38. #undef FT_COMPONENT
  39. #define FT_COMPONENT trace_bdfdriver
  40. typedef struct BDF_CMapRec_
  41. {
  42. FT_CMapRec cmap;
  43. FT_ULong num_encodings; /* ftobjs.h: FT_CMap->clazz->size */
  44. BDF_encoding_el* encodings;
  45. } BDF_CMapRec, *BDF_CMap;
  46. FT_CALLBACK_DEF( FT_Error )
  47. bdf_cmap_init( FT_CMap bdfcmap,
  48. FT_Pointer init_data )
  49. {
  50. BDF_CMap cmap = (BDF_CMap)bdfcmap;
  51. BDF_Face face = (BDF_Face)FT_CMAP_FACE( cmap );
  52. FT_UNUSED( init_data );
  53. cmap->num_encodings = face->bdffont->glyphs_used;
  54. cmap->encodings = face->en_table;
  55. return BDF_Err_Ok;
  56. }
  57. FT_CALLBACK_DEF( void )
  58. bdf_cmap_done( FT_CMap bdfcmap )
  59. {
  60. BDF_CMap cmap = (BDF_CMap)bdfcmap;
  61. cmap->encodings = NULL;
  62. cmap->num_encodings = 0;
  63. }
  64. FT_CALLBACK_DEF( FT_UInt )
  65. bdf_cmap_char_index( FT_CMap bdfcmap,
  66. FT_UInt32 charcode )
  67. {
  68. BDF_CMap cmap = (BDF_CMap)bdfcmap;
  69. BDF_encoding_el* encodings = cmap->encodings;
  70. FT_ULong min, max, mid; /* num_encodings */
  71. FT_UShort result = 0; /* encodings->glyph */
  72. min = 0;
  73. max = cmap->num_encodings;
  74. while ( min < max )
  75. {
  76. FT_ULong code;
  77. mid = ( min + max ) >> 1;
  78. code = encodings[mid].enc;
  79. if ( charcode == code )
  80. {
  81. /* increase glyph index by 1 -- */
  82. /* we reserve slot 0 for the undefined glyph */
  83. result = encodings[mid].glyph + 1;
  84. break;
  85. }
  86. if ( charcode < code )
  87. max = mid;
  88. else
  89. min = mid + 1;
  90. }
  91. return result;
  92. }
  93. FT_CALLBACK_DEF( FT_UInt )
  94. bdf_cmap_char_next( FT_CMap bdfcmap,
  95. FT_UInt32 *acharcode )
  96. {
  97. BDF_CMap cmap = (BDF_CMap)bdfcmap;
  98. BDF_encoding_el* encodings = cmap->encodings;
  99. FT_ULong min, max, mid; /* num_encodings */
  100. FT_UShort result = 0; /* encodings->glyph */
  101. FT_ULong charcode = *acharcode + 1;
  102. min = 0;
  103. max = cmap->num_encodings;
  104. while ( min < max )
  105. {
  106. FT_ULong code; /* same as BDF_encoding_el.enc */
  107. mid = ( min + max ) >> 1;
  108. code = encodings[mid].enc;
  109. if ( charcode == code )
  110. {
  111. /* increase glyph index by 1 -- */
  112. /* we reserve slot 0 for the undefined glyph */
  113. result = encodings[mid].glyph + 1;
  114. goto Exit;
  115. }
  116. if ( charcode < code )
  117. max = mid;
  118. else
  119. min = mid + 1;
  120. }
  121. charcode = 0;
  122. if ( min < cmap->num_encodings )
  123. {
  124. charcode = encodings[min].enc;
  125. result = encodings[min].glyph + 1;
  126. }
  127. Exit:
  128. if ( charcode > 0xFFFFFFFFUL )
  129. {
  130. FT_TRACE1(( "bdf_cmap_char_next: charcode 0x%x > 32bit API" ));
  131. *acharcode = 0;
  132. /* XXX: result should be changed to indicate an overflow error */
  133. }
  134. else
  135. *acharcode = (FT_UInt32)charcode;
  136. return result;
  137. }
  138. FT_CALLBACK_TABLE_DEF
  139. const FT_CMap_ClassRec bdf_cmap_class =
  140. {
  141. sizeof ( BDF_CMapRec ),
  142. bdf_cmap_init,
  143. bdf_cmap_done,
  144. bdf_cmap_char_index,
  145. bdf_cmap_char_next,
  146. NULL, NULL, NULL, NULL, NULL
  147. };
  148. static FT_Error
  149. bdf_interpret_style( BDF_Face bdf )
  150. {
  151. FT_Error error = BDF_Err_Ok;
  152. FT_Face face = FT_FACE( bdf );
  153. FT_Memory memory = face->memory;
  154. bdf_font_t* font = bdf->bdffont;
  155. bdf_property_t* prop;
  156. char* strings[4] = { NULL, NULL, NULL, NULL };
  157. size_t nn, len, lengths[4];
  158. face->style_flags = 0;
  159. prop = bdf_get_font_property( font, (char *)"SLANT" );
  160. if ( prop && prop->format == BDF_ATOM &&
  161. prop->value.atom &&
  162. ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ||
  163. *(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) )
  164. {
  165. face->style_flags |= FT_STYLE_FLAG_ITALIC;
  166. strings[2] = ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' )
  167. ? (char *)"Oblique"
  168. : (char *)"Italic";
  169. }
  170. prop = bdf_get_font_property( font, (char *)"WEIGHT_NAME" );
  171. if ( prop && prop->format == BDF_ATOM &&
  172. prop->value.atom &&
  173. ( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) )
  174. {
  175. face->style_flags |= FT_STYLE_FLAG_BOLD;
  176. strings[1] = (char *)"Bold";
  177. }
  178. prop = bdf_get_font_property( font, (char *)"SETWIDTH_NAME" );
  179. if ( prop && prop->format == BDF_ATOM &&
  180. prop->value.atom && *(prop->value.atom) &&
  181. !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
  182. strings[3] = (char *)(prop->value.atom);
  183. prop = bdf_get_font_property( font, (char *)"ADD_STYLE_NAME" );
  184. if ( prop && prop->format == BDF_ATOM &&
  185. prop->value.atom && *(prop->value.atom) &&
  186. !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
  187. strings[0] = (char *)(prop->value.atom);
  188. len = 0;
  189. for ( len = 0, nn = 0; nn < 4; nn++ )
  190. {
  191. lengths[nn] = 0;
  192. if ( strings[nn] )
  193. {
  194. lengths[nn] = ft_strlen( strings[nn] );
  195. len += lengths[nn] + 1;
  196. }
  197. }
  198. if ( len == 0 )
  199. {
  200. strings[0] = (char *)"Regular";
  201. lengths[0] = ft_strlen( strings[0] );
  202. len = lengths[0] + 1;
  203. }
  204. {
  205. char* s;
  206. if ( FT_ALLOC( face->style_name, len ) )
  207. return error;
  208. s = face->style_name;
  209. for ( nn = 0; nn < 4; nn++ )
  210. {
  211. char* src = strings[nn];
  212. len = lengths[nn];
  213. if ( src == NULL )
  214. continue;
  215. /* separate elements with a space */
  216. if ( s != face->style_name )
  217. *s++ = ' ';
  218. ft_memcpy( s, src, len );
  219. /* need to convert spaces to dashes for */
  220. /* add_style_name and setwidth_name */
  221. if ( nn == 0 || nn == 3 )
  222. {
  223. size_t mm;
  224. for ( mm = 0; mm < len; mm++ )
  225. if ( s[mm] == ' ' )
  226. s[mm] = '-';
  227. }
  228. s += len;
  229. }
  230. *s = 0;
  231. }
  232. return error;
  233. }
  234. FT_CALLBACK_DEF( void )
  235. BDF_Face_Done( FT_Face bdfface ) /* BDF_Face */
  236. {
  237. BDF_Face face = (BDF_Face)bdfface;
  238. FT_Memory memory;
  239. if ( !face )
  240. return;
  241. memory = FT_FACE_MEMORY( face );
  242. bdf_free_font( face->bdffont );
  243. FT_FREE( face->en_table );
  244. FT_FREE( face->charset_encoding );
  245. FT_FREE( face->charset_registry );
  246. FT_FREE( bdfface->family_name );
  247. FT_FREE( bdfface->style_name );
  248. FT_FREE( bdfface->available_sizes );
  249. FT_FREE( face->bdffont );
  250. }
  251. FT_CALLBACK_DEF( FT_Error )
  252. BDF_Face_Init( FT_Stream stream,
  253. FT_Face bdfface, /* BDF_Face */
  254. FT_Int face_index,
  255. FT_Int num_params,
  256. FT_Parameter* params )
  257. {
  258. FT_Error error = BDF_Err_Ok;
  259. BDF_Face face = (BDF_Face)bdfface;
  260. FT_Memory memory = FT_FACE_MEMORY( face );
  261. bdf_font_t* font = NULL;
  262. bdf_options_t options;
  263. FT_UNUSED( num_params );
  264. FT_UNUSED( params );
  265. FT_UNUSED( face_index );
  266. FT_TRACE2(( "BDF driver\n" ));
  267. if ( FT_STREAM_SEEK( 0 ) )
  268. goto Exit;
  269. options.correct_metrics = 1; /* FZ XXX: options semantics */
  270. options.keep_unencoded = 1;
  271. options.keep_comments = 0;
  272. options.font_spacing = BDF_PROPORTIONAL;
  273. error = bdf_load_font( stream, memory, &options, &font );
  274. if ( error == BDF_Err_Missing_Startfont_Field )
  275. {
  276. FT_TRACE2(( " not a BDF file\n" ));
  277. goto Fail;
  278. }
  279. else if ( error )
  280. goto Exit;
  281. /* we have a bdf font: let's construct the face object */
  282. face->bdffont = font;
  283. {
  284. bdf_property_t* prop = NULL;
  285. FT_TRACE4(( " number of glyphs: allocated %d (used %d)\n",
  286. font->glyphs_size,
  287. font->glyphs_used ));
  288. FT_TRACE4(( " number of unencoded glyphs: allocated %d (used %d)\n",
  289. font->unencoded_size,
  290. font->unencoded_used ));
  291. bdfface->num_faces = 1;
  292. bdfface->face_index = 0;
  293. bdfface->face_flags = FT_FACE_FLAG_FIXED_SIZES |
  294. FT_FACE_FLAG_HORIZONTAL |
  295. FT_FACE_FLAG_FAST_GLYPHS;
  296. prop = bdf_get_font_property( font, "SPACING" );
  297. if ( prop && prop->format == BDF_ATOM &&
  298. prop->value.atom &&
  299. ( *(prop->value.atom) == 'M' || *(prop->value.atom) == 'm' ||
  300. *(prop->value.atom) == 'C' || *(prop->value.atom) == 'c' ) )
  301. bdfface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
  302. /* FZ XXX: TO DO: FT_FACE_FLAGS_VERTICAL */
  303. /* FZ XXX: I need a font to implement this */
  304. prop = bdf_get_font_property( font, "FAMILY_NAME" );
  305. if ( prop && prop->value.atom )
  306. {
  307. if ( FT_STRDUP( bdfface->family_name, prop->value.atom ) )
  308. goto Exit;
  309. }
  310. else
  311. bdfface->family_name = 0;
  312. if ( ( error = bdf_interpret_style( face ) ) != 0 )
  313. goto Exit;
  314. /* the number of glyphs (with one slot for the undefined glyph */
  315. /* at position 0 and all unencoded glyphs) */
  316. bdfface->num_glyphs = font->glyphs_size + 1;
  317. bdfface->num_fixed_sizes = 1;
  318. if ( FT_NEW_ARRAY( bdfface->available_sizes, 1 ) )
  319. goto Exit;
  320. {
  321. FT_Bitmap_Size* bsize = bdfface->available_sizes;
  322. FT_Short resolution_x = 0, resolution_y = 0;
  323. FT_MEM_ZERO( bsize, sizeof ( FT_Bitmap_Size ) );
  324. bsize->height = (FT_Short)( font->font_ascent + font->font_descent );
  325. prop = bdf_get_font_property( font, "AVERAGE_WIDTH" );
  326. if ( prop )
  327. bsize->width = (FT_Short)( ( prop->value.l + 5 ) / 10 );
  328. else
  329. bsize->width = (FT_Short)( bsize->height * 2/3 );
  330. prop = bdf_get_font_property( font, "POINT_SIZE" );
  331. if ( prop )
  332. /* convert from 722.7 decipoints to 72 points per inch */
  333. bsize->size =
  334. (FT_Pos)( ( prop->value.l * 64 * 7200 + 36135L ) / 72270L );
  335. else
  336. bsize->size = bsize->width << 6;
  337. prop = bdf_get_font_property( font, "PIXEL_SIZE" );
  338. if ( prop )
  339. bsize->y_ppem = (FT_Short)prop->value.l << 6;
  340. prop = bdf_get_font_property( font, "RESOLUTION_X" );
  341. if ( prop )
  342. resolution_x = (FT_Short)prop->value.l;
  343. prop = bdf_get_font_property( font, "RESOLUTION_Y" );
  344. if ( prop )
  345. resolution_y = (FT_Short)prop->value.l;
  346. if ( bsize->y_ppem == 0 )
  347. {
  348. bsize->y_ppem = bsize->size;
  349. if ( resolution_y )
  350. bsize->y_ppem = bsize->y_ppem * resolution_y / 72;
  351. }
  352. if ( resolution_x && resolution_y )
  353. bsize->x_ppem = bsize->y_ppem * resolution_x / resolution_y;
  354. else
  355. bsize->x_ppem = bsize->y_ppem;
  356. }
  357. /* encoding table */
  358. {
  359. bdf_glyph_t* cur = font->glyphs;
  360. unsigned long n;
  361. if ( FT_NEW_ARRAY( face->en_table, font->glyphs_size ) )
  362. goto Exit;
  363. face->default_glyph = 0;
  364. for ( n = 0; n < font->glyphs_size; n++ )
  365. {
  366. (face->en_table[n]).enc = cur[n].encoding;
  367. FT_TRACE4(( " idx %d, val 0x%lX\n", n, cur[n].encoding ));
  368. (face->en_table[n]).glyph = (FT_Short)n;
  369. if ( cur[n].encoding == font->default_char )
  370. {
  371. if ( n < FT_UINT_MAX )
  372. face->default_glyph = (FT_UInt)n;
  373. else
  374. FT_TRACE1(( "BDF_Face_Init:"
  375. " idx %d is too large for this system\n", n ));
  376. }
  377. }
  378. }
  379. /* charmaps */
  380. {
  381. bdf_property_t *charset_registry = 0, *charset_encoding = 0;
  382. FT_Bool unicode_charmap = 0;
  383. charset_registry =
  384. bdf_get_font_property( font, "CHARSET_REGISTRY" );
  385. charset_encoding =
  386. bdf_get_font_property( font, "CHARSET_ENCODING" );
  387. if ( charset_registry && charset_encoding )
  388. {
  389. if ( charset_registry->format == BDF_ATOM &&
  390. charset_encoding->format == BDF_ATOM &&
  391. charset_registry->value.atom &&
  392. charset_encoding->value.atom )
  393. {
  394. const char* s;
  395. if ( FT_STRDUP( face->charset_encoding,
  396. charset_encoding->value.atom ) ||
  397. FT_STRDUP( face->charset_registry,
  398. charset_registry->value.atom ) )
  399. goto Exit;
  400. /* Uh, oh, compare first letters manually to avoid dependency */
  401. /* on locales. */
  402. s = face->charset_registry;
  403. if ( ( s[0] == 'i' || s[0] == 'I' ) &&
  404. ( s[1] == 's' || s[1] == 'S' ) &&
  405. ( s[2] == 'o' || s[2] == 'O' ) )
  406. {
  407. s += 3;
  408. if ( !ft_strcmp( s, "10646" ) ||
  409. ( !ft_strcmp( s, "8859" ) &&
  410. !ft_strcmp( face->charset_encoding, "1" ) ) )
  411. unicode_charmap = 1;
  412. }
  413. {
  414. FT_CharMapRec charmap;
  415. charmap.face = FT_FACE( face );
  416. charmap.encoding = FT_ENCODING_NONE;
  417. /* initial platform/encoding should indicate unset status? */
  418. charmap.platform_id = TT_PLATFORM_APPLE_UNICODE;
  419. charmap.encoding_id = TT_APPLE_ID_DEFAULT;
  420. if ( unicode_charmap )
  421. {
  422. charmap.encoding = FT_ENCODING_UNICODE;
  423. charmap.platform_id = TT_PLATFORM_MICROSOFT;
  424. charmap.encoding_id = TT_MS_ID_UNICODE_CS;
  425. }
  426. error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL );
  427. #if 0
  428. /* Select default charmap */
  429. if ( bdfface->num_charmaps )
  430. bdfface->charmap = bdfface->charmaps[0];
  431. #endif
  432. }
  433. goto Exit;
  434. }
  435. }
  436. /* otherwise assume Adobe standard encoding */
  437. {
  438. FT_CharMapRec charmap;
  439. charmap.face = FT_FACE( face );
  440. charmap.encoding = FT_ENCODING_ADOBE_STANDARD;
  441. charmap.platform_id = TT_PLATFORM_ADOBE;
  442. charmap.encoding_id = TT_ADOBE_ID_STANDARD;
  443. error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL );
  444. /* Select default charmap */
  445. if ( bdfface->num_charmaps )
  446. bdfface->charmap = bdfface->charmaps[0];
  447. }
  448. }
  449. }
  450. Exit:
  451. return error;
  452. Fail:
  453. BDF_Face_Done( bdfface );
  454. return BDF_Err_Unknown_File_Format;
  455. }
  456. FT_CALLBACK_DEF( FT_Error )
  457. BDF_Size_Select( FT_Size size,
  458. FT_ULong strike_index )
  459. {
  460. bdf_font_t* bdffont = ( (BDF_Face)size->face )->bdffont;
  461. FT_Select_Metrics( size->face, strike_index );
  462. size->metrics.ascender = bdffont->font_ascent << 6;
  463. size->metrics.descender = -bdffont->font_descent << 6;
  464. size->metrics.max_advance = bdffont->bbx.width << 6;
  465. return BDF_Err_Ok;
  466. }
  467. FT_CALLBACK_DEF( FT_Error )
  468. BDF_Size_Request( FT_Size size,
  469. FT_Size_Request req )
  470. {
  471. FT_Face face = size->face;
  472. FT_Bitmap_Size* bsize = face->available_sizes;
  473. bdf_font_t* bdffont = ( (BDF_Face)face )->bdffont;
  474. FT_Error error = BDF_Err_Invalid_Pixel_Size;
  475. FT_Long height;
  476. height = FT_REQUEST_HEIGHT( req );
  477. height = ( height + 32 ) >> 6;
  478. switch ( req->type )
  479. {
  480. case FT_SIZE_REQUEST_TYPE_NOMINAL:
  481. if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) )
  482. error = BDF_Err_Ok;
  483. break;
  484. case FT_SIZE_REQUEST_TYPE_REAL_DIM:
  485. if ( height == ( bdffont->font_ascent +
  486. bdffont->font_descent ) )
  487. error = BDF_Err_Ok;
  488. break;
  489. default:
  490. error = BDF_Err_Unimplemented_Feature;
  491. break;
  492. }
  493. if ( error )
  494. return error;
  495. else
  496. return BDF_Size_Select( size, 0 );
  497. }
  498. FT_CALLBACK_DEF( FT_Error )
  499. BDF_Glyph_Load( FT_GlyphSlot slot,
  500. FT_Size size,
  501. FT_UInt glyph_index,
  502. FT_Int32 load_flags )
  503. {
  504. BDF_Face bdf = (BDF_Face)FT_SIZE_FACE( size );
  505. FT_Face face = FT_FACE( bdf );
  506. FT_Error error = BDF_Err_Ok;
  507. FT_Bitmap* bitmap = &slot->bitmap;
  508. bdf_glyph_t glyph;
  509. int bpp = bdf->bdffont->bpp;
  510. FT_UNUSED( load_flags );
  511. if ( !face || glyph_index >= (FT_UInt)face->num_glyphs )
  512. {
  513. error = BDF_Err_Invalid_Argument;
  514. goto Exit;
  515. }
  516. /* index 0 is the undefined glyph */
  517. if ( glyph_index == 0 )
  518. glyph_index = bdf->default_glyph;
  519. else
  520. glyph_index--;
  521. /* slot, bitmap => freetype, glyph => bdflib */
  522. glyph = bdf->bdffont->glyphs[glyph_index];
  523. bitmap->rows = glyph.bbx.height;
  524. bitmap->width = glyph.bbx.width;
  525. if ( glyph.bpr > INT_MAX )
  526. FT_TRACE1(( "BDF_Glyph_Load: too large pitch %d is truncated\n",
  527. glyph.bpr ));
  528. bitmap->pitch = (int)glyph.bpr; /* same as FT_Bitmap.pitch */
  529. /* note: we don't allocate a new array to hold the bitmap; */
  530. /* we can simply point to it */
  531. ft_glyphslot_set_bitmap( slot, glyph.bitmap );
  532. switch ( bpp )
  533. {
  534. case 1:
  535. bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
  536. break;
  537. case 2:
  538. bitmap->pixel_mode = FT_PIXEL_MODE_GRAY2;
  539. break;
  540. case 4:
  541. bitmap->pixel_mode = FT_PIXEL_MODE_GRAY4;
  542. break;
  543. case 8:
  544. bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
  545. bitmap->num_grays = 256;
  546. break;
  547. }
  548. slot->format = FT_GLYPH_FORMAT_BITMAP;
  549. slot->bitmap_left = glyph.bbx.x_offset;
  550. slot->bitmap_top = glyph.bbx.ascent;
  551. slot->metrics.horiAdvance = glyph.dwidth << 6;
  552. slot->metrics.horiBearingX = glyph.bbx.x_offset << 6;
  553. slot->metrics.horiBearingY = glyph.bbx.ascent << 6;
  554. slot->metrics.width = bitmap->width << 6;
  555. slot->metrics.height = bitmap->rows << 6;
  556. /*
  557. * XXX DWIDTH1 and VVECTOR should be parsed and
  558. * used here, provided such fonts do exist.
  559. */
  560. ft_synthesize_vertical_metrics( &slot->metrics,
  561. bdf->bdffont->bbx.height << 6 );
  562. Exit:
  563. return error;
  564. }
  565. /*
  566. *
  567. * BDF SERVICE
  568. *
  569. */
  570. static FT_Error
  571. bdf_get_bdf_property( BDF_Face face,
  572. const char* prop_name,
  573. BDF_PropertyRec *aproperty )
  574. {
  575. bdf_property_t* prop;
  576. FT_ASSERT( face && face->bdffont );
  577. prop = bdf_get_font_property( face->bdffont, prop_name );
  578. if ( prop )
  579. {
  580. switch ( prop->format )
  581. {
  582. case BDF_ATOM:
  583. aproperty->type = BDF_PROPERTY_TYPE_ATOM;
  584. aproperty->u.atom = prop->value.atom;
  585. break;
  586. case BDF_INTEGER:
  587. if ( prop->value.l > 0x7FFFFFFFL || prop->value.l < ( -1 - 0x7FFFFFFFL ) )
  588. {
  589. FT_TRACE1(( "bdf_get_bdf_property:"
  590. " too large integer 0x%x is truncated\n" ));
  591. }
  592. aproperty->type = BDF_PROPERTY_TYPE_INTEGER;
  593. aproperty->u.integer = (FT_Int32)prop->value.l;
  594. break;
  595. case BDF_CARDINAL:
  596. if ( prop->value.ul > 0xFFFFFFFFUL )
  597. {
  598. FT_TRACE1(( "bdf_get_bdf_property:"
  599. " too large cardinal 0x%x is truncated\n" ));
  600. }
  601. aproperty->type = BDF_PROPERTY_TYPE_CARDINAL;
  602. aproperty->u.cardinal = (FT_UInt32)prop->value.ul;
  603. break;
  604. default:
  605. goto Fail;
  606. }
  607. return 0;
  608. }
  609. Fail:
  610. return BDF_Err_Invalid_Argument;
  611. }
  612. static FT_Error
  613. bdf_get_charset_id( BDF_Face face,
  614. const char* *acharset_encoding,
  615. const char* *acharset_registry )
  616. {
  617. *acharset_encoding = face->charset_encoding;
  618. *acharset_registry = face->charset_registry;
  619. return 0;
  620. }
  621. static const FT_Service_BDFRec bdf_service_bdf =
  622. {
  623. (FT_BDF_GetCharsetIdFunc)bdf_get_charset_id,
  624. (FT_BDF_GetPropertyFunc) bdf_get_bdf_property
  625. };
  626. /*
  627. *
  628. * SERVICES LIST
  629. *
  630. */
  631. static const FT_ServiceDescRec bdf_services[] =
  632. {
  633. { FT_SERVICE_ID_BDF, &bdf_service_bdf },
  634. { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_BDF },
  635. { NULL, NULL }
  636. };
  637. FT_CALLBACK_DEF( FT_Module_Interface )
  638. bdf_driver_requester( FT_Module module,
  639. const char* name )
  640. {
  641. FT_UNUSED( module );
  642. return ft_service_list_lookup( bdf_services, name );
  643. }
  644. FT_CALLBACK_TABLE_DEF
  645. const FT_Driver_ClassRec bdf_driver_class =
  646. {
  647. {
  648. FT_MODULE_FONT_DRIVER |
  649. FT_MODULE_DRIVER_NO_OUTLINES,
  650. sizeof ( FT_DriverRec ),
  651. "bdf",
  652. 0x10000L,
  653. 0x20000L,
  654. 0,
  655. 0, /* FT_Module_Constructor */
  656. 0, /* FT_Module_Destructor */
  657. bdf_driver_requester
  658. },
  659. sizeof ( BDF_FaceRec ),
  660. sizeof ( FT_SizeRec ),
  661. sizeof ( FT_GlyphSlotRec ),
  662. BDF_Face_Init,
  663. BDF_Face_Done,
  664. 0, /* FT_Size_InitFunc */
  665. 0, /* FT_Size_DoneFunc */
  666. 0, /* FT_Slot_InitFunc */
  667. 0, /* FT_Slot_DoneFunc */
  668. #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
  669. ft_stub_set_char_sizes,
  670. ft_stub_set_pixel_sizes,
  671. #endif
  672. BDF_Glyph_Load,
  673. 0, /* FT_Face_GetKerningFunc */
  674. 0, /* FT_Face_AttachFunc */
  675. 0, /* FT_Face_GetAdvancesFunc */
  676. BDF_Size_Request,
  677. BDF_Size_Select
  678. };
  679. /* END */