|
|
@@ -493,82 +493,6 @@ int cucul_render_canvas(cucul_canvas_t *cv, cucul_font_t *f, |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
/** \brief Render a single glyph onto an image buffer |
|
|
|
* |
|
|
|
* This function renders the given character on an image buffer using a |
|
|
|
* specific font. The pixel format is fixed (8 bits per pixel). |
|
|
|
* |
|
|
|
* The required buffer size can be computed using cucul_get_font_width() |
|
|
|
* and cucul_get_font_height(). |
|
|
|
* |
|
|
|
* This function never fails. |
|
|
|
* |
|
|
|
* \param f The font, as returned by cucul_load_font() |
|
|
|
* \param ch The character to render |
|
|
|
* \param buf The image buffer |
|
|
|
* \param stride width of the destination buffer |
|
|
|
* \return This function always returns 0. |
|
|
|
*/ |
|
|
|
int cucul_render_glyph(cucul_font_t *f, unsigned int ch, void *buf, |
|
|
|
unsigned int stride) |
|
|
|
{ |
|
|
|
unsigned int b, y; |
|
|
|
struct glyph_info *g; |
|
|
|
uint8_t *glyph = NULL; |
|
|
|
|
|
|
|
/* Find the Unicode block where our glyph lies */ |
|
|
|
for(b = 0; b < f->header.blocks; b++) |
|
|
|
{ |
|
|
|
if(ch < f->block_list[b].start) |
|
|
|
{ |
|
|
|
b = f->header.blocks; |
|
|
|
break; |
|
|
|
} |
|
|
|
if(ch < f->block_list[b].stop) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* Glyph not in font? Skip it. */ |
|
|
|
if(b == f->header.blocks) |
|
|
|
return 0; |
|
|
|
|
|
|
|
if(f->header.bpp != 8) |
|
|
|
glyph = malloc(f->header.width * f->header.height); |
|
|
|
|
|
|
|
g = &f->glyph_list[f->block_list[b].index |
|
|
|
+ ch - f->block_list[b].start]; |
|
|
|
|
|
|
|
/* Step 1: unpack glyph */ |
|
|
|
switch(f->header.bpp) |
|
|
|
{ |
|
|
|
case 8: |
|
|
|
glyph = f->font_data + g->data_offset; |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
unpack_glyph4(glyph, f->font_data + g->data_offset, |
|
|
|
g->width * g->height); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
unpack_glyph2(glyph, f->font_data + g->data_offset, |
|
|
|
g->width * g->height); |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
unpack_glyph1(glyph, f->font_data + g->data_offset, |
|
|
|
g->width * g->height); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
/* Step 2: render glyph */ |
|
|
|
for(y = 0; y < g->height; y++) |
|
|
|
memcpy((uint8_t*)buf + y * stride, glyph + y * g->width, g->width); |
|
|
|
|
|
|
|
if(f->header.bpp != 8) |
|
|
|
free(glyph); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* The libcaca font format, version 1 |
|
|
|
* ---------------------------------- |
|
|
|