|
@@ -447,34 +447,26 @@ int cucul_render_canvas(cucul_canvas_t *cv, cucul_font_t *f, |
|
|
|
|
|
|
|
|
/** \brief Render the given character onto given buffer |
|
|
/** \brief Render the given character onto given buffer |
|
|
* |
|
|
* |
|
|
* This function renders the given character on an image buffer using a specific |
|
|
|
|
|
* font. The pixel format is fixed (8 bits per pixel). |
|
|
|
|
|
|
|
|
* 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 width can be computed using |
|
|
|
|
|
* cucul_get_canvas_width() and cucul_get_font_width(). The required |
|
|
|
|
|
* height can be computed using cucul_get_canvas_height() and |
|
|
|
|
|
* cucul_get_font_height(). |
|
|
|
|
|
* |
|
|
|
|
|
* Glyphs that do not fit in the image buffer are currently not rendered at |
|
|
|
|
|
* all. They may be cropped instead in future versions. |
|
|
|
|
|
|
|
|
* The required buffer size can be computed using cucul_get_font_width() |
|
|
|
|
|
* and cucul_get_font_height(). |
|
|
* |
|
|
* |
|
|
* This function never fails. |
|
|
* This function never fails. |
|
|
* |
|
|
* |
|
|
* \param f The font, as returned by cucul_load_font() |
|
|
* \param f The font, as returned by cucul_load_font() |
|
|
* \param ch The character to render |
|
|
* \param ch The character to render |
|
|
* \param buf The image buffer |
|
|
* \param buf The image buffer |
|
|
* \param width The width (in pixels) of the image buffer |
|
|
|
|
|
* \param height The height (in pixels) of the image buffer |
|
|
|
|
|
* \return This function return 1 if glyph is succesfully renderer, 0 otherwise |
|
|
|
|
|
|
|
|
* \param pitch The pitch of the image buffer |
|
|
|
|
|
* \return This function always returns 0. |
|
|
*/ |
|
|
*/ |
|
|
int cucul_render_glyph(cucul_font_t *f, unsigned int ch, void *buffer, |
|
|
|
|
|
unsigned int width, unsigned int height) |
|
|
|
|
|
|
|
|
int cucul_render_glyph(cucul_font_t *f, unsigned int ch, void *buf, |
|
|
|
|
|
unsigned int stride) |
|
|
{ |
|
|
{ |
|
|
unsigned int b; |
|
|
|
|
|
|
|
|
unsigned int b, y; |
|
|
struct glyph_info *g; |
|
|
struct glyph_info *g; |
|
|
uint8_t *glyph = buffer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t *glyph; |
|
|
|
|
|
|
|
|
/* Find the Unicode block where our glyph lies */ |
|
|
/* Find the Unicode block where our glyph lies */ |
|
|
for(b = 0; b < f->header.blocks; b++) |
|
|
for(b = 0; b < f->header.blocks; b++) |
|
@@ -493,6 +485,9 @@ int cucul_render_glyph(cucul_font_t *f, unsigned int ch, void *buffer, |
|
|
if(b == f->header.blocks) |
|
|
if(b == f->header.blocks) |
|
|
return 0; |
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
if(f->header.bpp != 8) |
|
|
|
|
|
glyph = malloc(f->header.width * f->header.height); |
|
|
|
|
|
|
|
|
g = &f->glyph_list[f->block_list[b].index |
|
|
g = &f->glyph_list[f->block_list[b].index |
|
|
+ ch - f->block_list[b].start]; |
|
|
+ ch - f->block_list[b].start]; |
|
|
|
|
|
|
|
@@ -515,10 +510,16 @@ int cucul_render_glyph(cucul_font_t *f, unsigned int ch, void *buffer, |
|
|
g->width * g->height); |
|
|
g->width * g->height); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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 |
|
|
* The libcaca font format, version 1 |
|
|