Changeset 1024 for libcaca/trunk/cucul/font.c
- Timestamp:
- Sep 16, 2006, 2:40:37 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/font.c
r961 r1024 446 446 } 447 447 448 /** \brief Render the given character onto given buffer 449 * 450 * This function renders the given character on an image buffer using a specific 451 * font. The pixel format is fixed (8 bits per pixel). 452 * 453 * The required buffer width can be computed using 454 * cucul_get_canvas_width() and cucul_get_font_width(). The required 455 * height can be computed using cucul_get_canvas_height() and 456 * cucul_get_font_height(). 457 * 458 * Glyphs that do not fit in the image buffer are currently not rendered at 459 * all. They may be cropped instead in future versions. 460 * 461 * This function never fails. 462 * 463 * \param f The font, as returned by cucul_load_font() 464 * \param ch The character to render 465 * \param buf The image buffer 466 * \param width The width (in pixels) of the image buffer 467 * \param height The height (in pixels) of the image buffer 468 * \return This function return 1 if glyph is succesfully renderer, 0 otherwise 469 */ 470 int cucul_render_glyph(cucul_font_t *f, unsigned int ch, void *buffer, 471 unsigned int width, unsigned int height) 472 { 473 unsigned int b; 474 struct glyph_info *g; 475 uint8_t *glyph = buffer; 476 477 478 479 /* Find the Unicode block where our glyph lies */ 480 for(b = 0; b < f->header.blocks; b++) 481 { 482 if(ch < f->block_list[b].start) 483 { 484 b = f->header.blocks; 485 break; 486 } 487 if(ch < f->block_list[b].stop) { 488 break; 489 } 490 } 491 492 /* Glyph not in font? Skip it. */ 493 if(b == f->header.blocks) 494 return 0; 495 496 g = &f->glyph_list[f->block_list[b].index 497 + ch - f->block_list[b].start]; 498 499 /* Step 1: unpack glyph */ 500 switch(f->header.bpp) 501 { 502 case 8: 503 glyph = f->font_data + g->data_offset; 504 break; 505 case 4: 506 unpack_glyph4(glyph, f->font_data + g->data_offset, 507 g->width * g->height); 508 break; 509 case 2: 510 unpack_glyph2(glyph, f->font_data + g->data_offset, 511 g->width * g->height); 512 break; 513 case 1: 514 unpack_glyph1(glyph, f->font_data + g->data_offset, 515 g->width * g->height); 516 break; 517 } 518 return 1; 519 } 520 521 522 448 523 /* 449 524 * The libcaca font format, version 1
Note: See TracChangeset
for help on using the changeset viewer.