Changeset 1062
- Timestamp:
- Sep 19, 2006, 2:02:59 AM (14 years ago)
- Location:
- libcaca/trunk/cucul
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/cucul.h
r1058 r1062 210 210 int cucul_render_canvas(cucul_canvas_t *, cucul_font_t *, void *, 211 211 unsigned int, unsigned int, unsigned int); 212 int cucul_render_glyph(cucul_font_t *, unsigned int, void *, unsigned int);213 212 int cucul_free_font(cucul_font_t *); 214 213 /* @} */ -
libcaca/trunk/cucul/font.c
r1059 r1062 494 494 } 495 495 496 /** \brief Render a single glyph onto an image buffer497 *498 * This function renders the given character on an image buffer using a499 * specific font. The pixel format is fixed (8 bits per pixel).500 *501 * The required buffer size can be computed using cucul_get_font_width()502 * and cucul_get_font_height().503 *504 * This function never fails.505 *506 * \param f The font, as returned by cucul_load_font()507 * \param ch The character to render508 * \param buf The image buffer509 * \param stride width of the destination buffer510 * \return This function always returns 0.511 */512 int cucul_render_glyph(cucul_font_t *f, unsigned int ch, void *buf,513 unsigned int stride)514 {515 unsigned int b, y;516 struct glyph_info *g;517 uint8_t *glyph = NULL;518 519 /* Find the Unicode block where our glyph lies */520 for(b = 0; b < f->header.blocks; b++)521 {522 if(ch < f->block_list[b].start)523 {524 b = f->header.blocks;525 break;526 }527 if(ch < f->block_list[b].stop) {528 break;529 }530 }531 532 /* Glyph not in font? Skip it. */533 if(b == f->header.blocks)534 return 0;535 536 if(f->header.bpp != 8)537 glyph = malloc(f->header.width * f->header.height);538 539 g = &f->glyph_list[f->block_list[b].index540 + ch - f->block_list[b].start];541 542 /* Step 1: unpack glyph */543 switch(f->header.bpp)544 {545 case 8:546 glyph = f->font_data + g->data_offset;547 break;548 case 4:549 unpack_glyph4(glyph, f->font_data + g->data_offset,550 g->width * g->height);551 break;552 case 2:553 unpack_glyph2(glyph, f->font_data + g->data_offset,554 g->width * g->height);555 break;556 case 1:557 unpack_glyph1(glyph, f->font_data + g->data_offset,558 g->width * g->height);559 break;560 }561 562 /* Step 2: render glyph */563 for(y = 0; y < g->height; y++)564 memcpy((uint8_t*)buf + y * stride, glyph + y * g->width, g->width);565 566 if(f->header.bpp != 8)567 free(glyph);568 569 return 0;570 }571 572 496 /* 573 497 * The libcaca font format, version 1
Note: See TracChangeset
for help on using the changeset viewer.