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 4d91a70e678339b10b0ed4b35ba9a18ccc84fa67 (commit) from 584415285129a73670aa799560d765a94707850e (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/4d91a70e678339b10b0ed4b35ba9a18ccc84f...
commit 4d91a70e678339b10b0ed4b35ba9a18ccc84fa67 Author: Cyril Hrubis metan@ucw.cz Date: Sat Dec 24 23:52:50 2011 +0100
Text: Fix FreeType font loading.
The font metadata are not correct compute the text ascender and descender from the glyphs while we load them.
diff --git a/libs/text/GP_FreeType.c b/libs/text/GP_FreeType.c index a041a45..a66999a 100644 --- a/libs/text/GP_FreeType.c +++ b/libs/text/GP_FreeType.c @@ -85,8 +85,6 @@ GP_FontFace *GP_FontFaceLoad(const char *path, uint32_t width, uint32_t height)
font->glyph_bitmap_format = GP_FONT_BITMAP_8BPP; font->charset = GP_CHARSET_7BIT; - font->ascend = face->ascender>>6; - font->descend = -(face->descender>>6);
/* Count glyph data size */ unsigned int i; @@ -134,6 +132,8 @@ GP_FontFace *GP_FontFaceLoad(const char *path, uint32_t width, uint32_t height) font->max_glyph_width = 0; font->max_glyph_advance = 0; + font->ascend = 0; + font->descend = 0;
for (i = 0x20; i < 0x7f; i++) { FT_UInt glyph_idx = FT_Get_Char_Index(face, i); @@ -163,11 +163,21 @@ GP_FontFace *GP_FontFaceLoad(const char *path, uint32_t width, uint32_t height) glyph_bitmap->bearing_y = glyph->bitmap_top; glyph_bitmap->advance_x = (glyph->advance.x + 32)>>6;
+ int16_t width = glyph_bitmap->bearing_x + glyph_bitmap->width; + int16_t ascend = glyph_bitmap->bearing_y; + int16_t descend = glyph_bitmap->height - ascend; + + if (font->ascend < ascend) + font->ascend = ascend; + + if (font->descend < descend) + font->descend = descend; + if (font->max_glyph_advance < glyph_bitmap->advance_x) font->max_glyph_advance = glyph_bitmap->advance_x;
- if (font->max_glyph_width < glyph_bitmap->bearing_x + glyph_bitmap->width) - font->max_glyph_width = glyph_bitmap->bearing_x + glyph_bitmap->width; + if (font->max_glyph_width < width) + font->max_glyph_width = width;
int x, y; diff --git a/libs/text/GP_Text.gen.c.t b/libs/text/GP_Text.gen.c.t index b76b345..286d3a7 100644 --- a/libs/text/GP_Text.gen.c.t +++ b/libs/text/GP_Text.gen.c.t @@ -44,10 +44,12 @@ static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl unsigned int x_start = x + (i + glyph->bearing_x) * x_mul;
- if (bit) - for (k = 0; k < style->pixel_ymul; k++) - GP_HLine(context, x_start, x_start + style->pixel_xmul - 1, - y - (glyph->bearing_y - style->font->ascend) * y_mul, fg); + if (!bit) + continue; + + for (k = 0; k < style->pixel_ymul; k++) + GP_HLine(context, x_start, x_start + style->pixel_xmul - 1, + y - (glyph->bearing_y - style->font->ascend) * y_mul, fg); }
y += style->pixel_ymul + style->pixel_yspace; @@ -105,6 +107,9 @@ static void text_draw_8BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl uint8_t gray = glyph->bitmap[i + j * glyph->width]; unsigned int x_start = x + (i + glyph->bearing_x) * x_mul; + + if (!gray) + continue;
for (k = 0; k < style->pixel_ymul; k++) GP_HLine(context, x_start, x_start + style->pixel_xmul - 1, diff --git a/tests/SDL/fileview.c b/tests/SDL/fileview.c index db23a72..f468750 100644 --- a/tests/SDL/fileview.c +++ b/tests/SDL/fileview.c @@ -215,7 +215,7 @@ int main(int argc, char *argv[])
if (argc > 2) - font = GP_FontFaceLoad(argv[2], 17, 23); + font = GP_FontFaceLoad(argv[2], 12, 17);
if (!read_file_head(argv[1])) return 1; diff --git a/tests/SDL/fonttest.c b/tests/SDL/fonttest.c index fdcf622..ef1b39d 100644 --- a/tests/SDL/fonttest.c +++ b/tests/SDL/fonttest.c @@ -137,7 +137,7 @@ void redraw_screen(void) 16, SPACING*i + 16, GP_TextWidth(&style, test_string), GP_FontHeight(style.font), - red_pixel); + dark_gray_pixel);
GP_RectXYWH(&context, 15, SPACING*i + 15, @@ -146,7 +146,7 @@ void redraw_screen(void) blue_pixel);
GP_Text(&context, &style, 16, SPACING*i + 16, align, - white_pixel, red_pixel, test_string); + white_pixel, dark_gray_pixel, test_string); style.pixel_xmul = 2; style.pixel_ymul = 2; @@ -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], 13, 19); + font = GP_FontFaceLoad(argv[1], 12, 16); }
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { diff --git a/tests/SDL/textaligntest.c b/tests/SDL/textaligntest.c index b3cead6..26c3028 100644 --- a/tests/SDL/textaligntest.c +++ b/tests/SDL/textaligntest.c @@ -30,21 +30,19 @@ #include "GP.h" #include "GP_SDL.h"
-/* the display */ SDL_Surface *display = NULL; GP_Context context;
-/* precomputed color pixels in display format */ static GP_Pixel black_pixel, red_pixel, yellow_pixel, green_pixel, blue_pixel, darkgray_pixel;
-/* draw using proportional font? */ -static int flag_proportional = 0; +static int font_flag = 0;
-/* center of the screen */ static int X = 640; static int Y = 480;
+GP_FontFace *font = NULL; + void redraw_screen(void) { SDL_LockSurface(display); @@ -57,19 +55,17 @@ void redraw_screen(void)
GP_TextStyle style = GP_DEFAULT_TEXT_STYLE;
- if (flag_proportional) + switch (font_flag) { + case 0: style.font = &GP_DefaultProportionalFont; - else + break; + case 1: style.font = &GP_DefaultConsoleFont; - - style.pixel_xspace = 4; - style.pixel_yspace = 4; - - //GP_BoxCenteredText(&context, &style, 0, 0, X, Y, - // "Hello world!", darkgray_pixel); - - style.pixel_xspace = 0; - style.pixel_yspace = 0; + break; + case 2: + style.font = font; + break; + }
GP_Text(&context, &style, X/2, Y/2, GP_ALIGN_LEFT|GP_VALIGN_BELOW, yellow_pixel, black_pixel, "bottom left"); @@ -98,7 +94,15 @@ void event_loop(void) case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_SPACE: - flag_proportional = !flag_proportional; + font_flag += 1; + + if (font) { + if (font_flag >= 3) + font_flag = 0; + } else { + if (font_flag >= 2) + font_flag = 0; + } break; case SDLK_x: context.x_swap = !context.x_swap; @@ -134,15 +138,18 @@ void print_instructions(void) printf(" R ................... reverse X and Yn"); }
-int main(void) +int main(int argc, char *argv[]) { - /* Initialize SDL */ + GP_SetDebugLevel(10); + + if (argc > 1) + font = GP_FontFaceLoad(argv[1], 12, 16); + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError()); return 1; }
- /* Create a window with a software back surface */ display = SDL_SetVideoMode(X, Y, 0, SDL_SWSURFACE); if (display == NULL) { fprintf(stderr, "Could not open display: %sn", SDL_GetError()); @@ -151,14 +158,11 @@ int main(void)
print_instructions();
- /* Set up a clipping rectangle to test proper clipping of pixels */ SDL_Rect clip_rect = {10, 10, X-10, Y-10}; SDL_SetClipRect(display, &clip_rect);
- /* Initialize a GP context from the SDL display */ GP_SDL_ContextFromSurface(&context, display);
- /* Load colors suitable for the display */ black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, &context); red_pixel = GP_ColorToContextPixel(GP_COL_RED, &context); blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, &context);
-----------------------------------------------------------------------
Summary of changes: libs/text/GP_FreeType.c | 18 ++++++++++++--- libs/text/GP_Text.gen.c.t | 13 ++++++++--- tests/SDL/fileview.c | 2 +- tests/SDL/fonttest.c | 6 ++-- tests/SDL/textaligntest.c | 50 ++++++++++++++++++++++++-------------------- 5 files changed, 54 insertions(+), 35 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.