From 7165793ff96775208faffa42e3cb14a96749dfa1 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 17 Sep 2006 00:02:31 +0000 Subject: [PATCH] * Fixed cucul_render_glyph(). There is no way this could have ever possibly worked properly. --- caca/driver_gl.c | 8 ++------ cucul/cucul.h | 3 +-- cucul/font.c | 41 +++++++++++++++++++++-------------------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/caca/driver_gl.c b/caca/driver_gl.c index a269960..91053af 100644 --- a/caca/driver_gl.c +++ b/caca/driver_gl.c @@ -569,9 +569,7 @@ void gl_generate_glyph(uint32_t c, uint32_t tid, caca_display_t *dp) { uint8_t *glyph8 = calloc(dp->drv.p->font_width*dp->drv.p->font_height, 1); uint8_t *glyph32 = calloc(16*16*4, 1); - cucul_render_glyph(dp->drv.p->f, c, - glyph8, dp->drv.p->font_width, dp->drv.p->font_height); - + cucul_render_glyph(dp->drv.p->f, c, glyph8, dp->drv.p->font_width); /* Convert resulting 8bbp glyph to 32bits, 16x16*/ for(s=0;s<(dp->drv.p->font_height<=16?dp->drv.p->font_height:16);s++) { @@ -603,9 +601,7 @@ void gl_generate_unicode_glyph(uint32_t c, uint32_t tid, caca_display_t *dp) { uint8_t *glyph8 = calloc(dp->drv.p->font_width*dp->drv.p->font_height, 1); uint8_t *glyph32 = calloc(16*16*4, 1); - cucul_render_glyph(dp->drv.p->f, c, - glyph8, dp->drv.p->font_width, dp->drv.p->font_height); - + cucul_render_glyph(dp->drv.p->f, c, glyph8, dp->drv.p->font_width); /* Convert resulting 8bbp glyph to 32bits, 16x16*/ for(s=0;s<(dp->drv.p->font_height<=16?dp->drv.p->font_height:16);s++) { diff --git a/cucul/cucul.h b/cucul/cucul.h index 4b5c39f..58f215e 100644 --- a/cucul/cucul.h +++ b/cucul/cucul.h @@ -208,8 +208,7 @@ unsigned int cucul_get_font_width(cucul_font_t *); unsigned int cucul_get_font_height(cucul_font_t *); int cucul_render_canvas(cucul_canvas_t *, cucul_font_t *, void *, unsigned int, unsigned int, unsigned int); -int cucul_render_glyph(cucul_font_t *, unsigned int, void *, - unsigned int, unsigned int); +int cucul_render_glyph(cucul_font_t *, unsigned int, void *, unsigned int); int cucul_free_font(cucul_font_t *); /* @} */ diff --git a/cucul/font.c b/cucul/font.c index 35bd680..7e0589d 100644 --- a/cucul/font.c +++ b/cucul/font.c @@ -447,34 +447,26 @@ int cucul_render_canvas(cucul_canvas_t *cv, cucul_font_t *f, /** \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. * * \param f The font, as returned by cucul_load_font() * \param ch The character to render * \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; - uint8_t *glyph = buffer; - - + uint8_t *glyph; /* Find the Unicode block where our glyph lies */ 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) 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]; @@ -515,10 +510,16 @@ int cucul_render_glyph(cucul_font_t *f, unsigned int ch, void *buffer, g->width * g->height); 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