This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 0c39d1adbaeb40591a13cbf965d773374fb8194b (commit) from 4d91a70e678339b10b0ed4b35ba9a18ccc84fa67 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/0c39d1adbaeb40591a13cbf965d773374fb81...
commit 0c39d1adbaeb40591a13cbf965d773374fb8194b Author: Cyril Hrubis metan@ucw.cz Date: Sun Jan 1 17:57:21 2012 +0100
Text: More fixes for freetype.
* Do not use bearing for first letter in string.
* Specify only one of w/h when loading font (yield in much better glyph bitmaps)
diff --git a/include/text/GP_Font.h b/include/text/GP_Font.h index 201595e..4975ed2 100644 --- a/include/text/GP_Font.h +++ b/include/text/GP_Font.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -188,4 +188,9 @@ GP_GlyphBitmap *GP_GetGlyphBitmap(const GP_FontFace *font, int c); */ GP_FontFace *GP_FontFaceLoad(const char *path, uint32_t width, uint32_t height);
+/* + * Free the font face memory. + */ +void GP_FontFaceFree(GP_FontFace *self); + #endif /* TEXT_GP_FONT_H */ diff --git a/libs/text/GP_Font.c b/libs/text/GP_Font.c index a4439f9..f153edc 100644 --- a/libs/text/GP_Font.c +++ b/libs/text/GP_Font.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -60,3 +60,9 @@ GP_GlyphBitmap *GP_GetGlyphBitmap(const GP_FontFace *font, int c)
return (GP_GlyphBitmap*)(font->glyphs + offset); } + +void GP_FontFaceFree(GP_FontFace *self) +{ + free(self->glyphs); + free(self); +} diff --git a/libs/text/GP_Text.gen.c.t b/libs/text/GP_Text.gen.c.t index 286d3a7..22498af 100644 --- a/libs/text/GP_Text.gen.c.t +++ b/libs/text/GP_Text.gen.c.t @@ -41,8 +41,11 @@ static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl for (j = 0; j < glyph->height; j++) { for (i = 0; i < glyph->width; i++) { uint8_t bit = (glyph->bitmap[i/8 + j * bpp]) & (0x80>>(i%8)); - + unsigned int x_start = x + (i + glyph->bearing_x) * x_mul; + + if (p == str) + x_start -= glyph->bearing_x * x_mul;
if (!bit) continue; @@ -56,6 +59,9 @@ static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl } x += glyph->advance_x * x_mul + style->char_xspace; + + if (p == str) + x -= glyph->bearing_x * x_mul; } }
@@ -108,6 +114,9 @@ static void text_draw_8BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl unsigned int x_start = x + (i + glyph->bearing_x) * x_mul; + if (p == str) + x_start -= glyph->bearing_x * x_mul; + if (!gray) continue;
@@ -119,8 +128,11 @@ static void text_draw_8BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl
y += style->pixel_ymul + style->pixel_yspace; } - + x += glyph->advance_x * x_mul + style->char_xspace; + + if (p == str) + x -= glyph->bearing_x * x_mul; } }
diff --git a/libs/text/GP_TextMetric.c b/libs/text/GP_TextMetric.c index ae746df..737d61d 100644 --- a/libs/text/GP_TextMetric.c +++ b/libs/text/GP_TextMetric.c @@ -19,7 +19,7 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -28,21 +28,50 @@
extern GP_TextStyle GP_DefaultStyle;
-/* - * Returns glyph width from the basepoint to the end of the glyph bitmap. - */ -static unsigned int glyph_width(const GP_TextStyle *style, char ch) +static const GP_GlyphBitmap *get_glyph(const GP_TextStyle *style, int c) { - unsigned int pixel_multiplier = style->pixel_xmul + style->pixel_xspace; - const GP_GlyphBitmap *glyph = GP_GetGlyphBitmap(style->font, ch); + const GP_GlyphBitmap *glyph = GP_GetGlyphBitmap(style->font, c);
if (glyph == NULL) glyph = GP_GetGlyphBitmap(style->font, ' '); + + return glyph; +} + +static unsigned int get_pixel_multiplier(const GP_TextStyle *style) +{ + return style->pixel_xmul + style->pixel_xspace; +} + +/* + * Returns glyph width from the basepoint to the end of the glyph bitmap. + */ +static unsigned int glyph_width(const GP_TextStyle *style, int c) +{ + unsigned int pixel_multiplier = get_pixel_multiplier(style); + const GP_GlyphBitmap *glyph = get_glyph(style, c);
return (glyph->width + glyph->bearing_x) * pixel_multiplier; }
/* + * Returns size of the glyph but doesn't count bearing. + * + * Note that the bearing may be negative (typical case is letter 'j' or most of + * the italic glyphs). So in order not to draw out of the text bouding box, + * first glyph ignores bearing_x and draws beginning of the glyph bitmap on the + * starting basepoint. + * + */ +static unsigned int first_glyph_width(const GP_TextStyle *style, int c) +{ + unsigned int pixel_multiplier = get_pixel_multiplier(style); + const GP_GlyphBitmap *glyph = get_glyph(style, c); + + return glyph->width * pixel_multiplier; +} + +/* * Returns space that is added after the glyph. * * Eg. the advance minus glyph width. @@ -51,11 +80,8 @@ static unsigned int glyph_width(const GP_TextStyle *style, char ch) */ static unsigned int glyph_space(const GP_TextStyle *style, char ch) { - unsigned int pixel_multiplier = style->pixel_xmul + style->pixel_xspace; - const GP_GlyphBitmap *glyph = GP_GetGlyphBitmap(style->font, ch); - - if (glyph == NULL) - glyph = GP_GetGlyphBitmap(style->font, ' '); + unsigned int pixel_multiplier = get_pixel_multiplier(style); + const GP_GlyphBitmap *glyph = get_glyph(style, ch); return (glyph->advance_x - glyph->width - glyph->bearing_x) * pixel_multiplier + style->char_xspace; @@ -97,7 +123,14 @@ unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str) if (str == NULL || str[0] == '0') return 0;
- for (i = 0; str[i] != '0'; i++) { + len += first_glyph_width(style, str[0]); + + if (str[1] == '0') + return len; + + len += glyph_space(style, str[0]); + + for (i = 1; str[i] != '0'; i++) { len += glyph_width(style, str[i]);
if (str[i+1] != '0') diff --git a/tests/SDL/fileview.c b/tests/SDL/fileview.c index f468750..d1c8008 100644 --- a/tests/SDL/fileview.c +++ b/tests/SDL/fileview.c @@ -19,7 +19,7 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -215,7 +215,7 @@ int main(int argc, char *argv[])
if (argc > 2) - font = GP_FontFaceLoad(argv[2], 12, 17); + font = GP_FontFaceLoad(argv[2], 0, 16);
if (!read_file_head(argv[1])) return 1; diff --git a/tests/SDL/fonttest.c b/tests/SDL/fonttest.c index ef1b39d..6bbc913 100644 --- a/tests/SDL/fonttest.c +++ b/tests/SDL/fonttest.c @@ -19,7 +19,7 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -229,7 +229,7 @@ int main(int argc, char *argv[])
if (argc > 1) { fprintf(stderr, "nLoading font '%s'n", argv[1]); - font = GP_FontFaceLoad(argv[1], 12, 16); + font = GP_FontFaceLoad(argv[1], 0, 16); }
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { diff --git a/tests/SDL/textaligntest.c b/tests/SDL/textaligntest.c index 26c3028..a58e670 100644 --- a/tests/SDL/textaligntest.c +++ b/tests/SDL/textaligntest.c @@ -19,7 +19,7 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -143,7 +143,7 @@ int main(int argc, char *argv[]) GP_SetDebugLevel(10);
if (argc > 1) - font = GP_FontFaceLoad(argv[1], 12, 16); + font = GP_FontFaceLoad(argv[1], 0, 16); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError());
-----------------------------------------------------------------------
Summary of changes: include/text/GP_Font.h | 7 ++++- libs/text/GP_Font.c | 8 +++++- libs/text/GP_Text.gen.c.t | 16 ++++++++++- libs/text/GP_TextMetric.c | 59 +++++++++++++++++++++++++++++++++++---------- tests/SDL/fileview.c | 4 +- tests/SDL/fonttest.c | 4 +- tests/SDL/textaligntest.c | 4 +- 7 files changed, 79 insertions(+), 23 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.