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 ea35af9019e34da61945dd72615c57d3e303a743 (commit) via 0f58139e80e4a6da1385034144d9f67e146ff6b8 (commit) from 36f12d07e7626a423264eca355c4000fc392dbf6 (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/ea35af9019e34da61945dd72615c57d3e303a...
commit ea35af9019e34da61945dd72615c57d3e303a743 Author: Cyril Hrubis metan@ucw.cz Date: Sat Jan 21 17:42:13 2012 +0100
input: Add rough key even ascii conversion.
diff --git a/libs/input/GP_Event.c b/libs/input/GP_Event.c index 129f1ee..022e744 100644 --- a/libs/input/GP_Event.c +++ b/libs/input/GP_Event.c @@ -263,6 +263,47 @@ void GP_EventPushAbs(uint32_t x, uint32_t y, uint32_t pressure, event_put(&cur_state); }
+static char keys_to_ascii[] = { + 0x00, 0x1b, '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', '-', '=', 0x08, 't', 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', 'o', 'p', '(', ')', 'n', 0x00, + 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + ''', '`', 0x00, '', 'z', 'x', 'c', 'v', 'b', 'n', + 'm', ',', '.', '/', 0x00, '*', 0x00, ' ', 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, '7', '8', '9', '-', '4', '5', '6', '+', '1', + '2', '3', '0', '.' +}; + +static char keys_to_ascii_s[] = { + 0x00, 0x1b, '!', '@', '#', '$', '%', '^', '&', '*', + '(', ')', '_', '+', 0x08, 't', 'Q', 'W', 'E', 'R', + 'T', 'Y', 'U', 'I', 'O', 'P', '(', ')', 'n', 0x00, + 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', + '"', '~', 0x00, '|', 'Z', 'X', 'C', 'V', 'B', 'N', + 'M', '<', '>', '?', 0x00, '*', 0x00, ' ', 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, '7', '8', '9', '-', '4', '5', '6', '+', '1', + '2', '3', '0', '.' +}; + +/* + * Fills key ascii value accordingly to keys pressed. + */ +static void key_to_ascii(GP_Event *ev) +{ + ev->val.key.ascii = 0; + + if (GP_EventGetKey(ev, GP_KEY_LEFT_SHIFT) || + GP_EventGetKey(ev, GP_KEY_RIGHT_SHIFT)) { + if (ev->val.key.key < sizeof(keys_to_ascii_s)) + ev->val.key.ascii = keys_to_ascii_s[ev->val.key.key]; + } else { + if (ev->val.key.key < sizeof(keys_to_ascii)) + ev->val.key.ascii = keys_to_ascii[ev->val.key.key]; + } +} + void GP_EventPushKey(uint32_t key, uint8_t code, struct timeval *time) { switch (code) { @@ -283,7 +324,7 @@ void GP_EventPushKey(uint32_t key, uint8_t code, struct timeval *time) cur_state.type = GP_EV_KEY; cur_state.code = code; cur_state.val.key.key = key; - //TODO cur_state.val.key.ascii + key_to_ascii(&cur_state); set_time(time);
http://repo.or.cz/w/gfxprim.git/commit/0f58139e80e4a6da1385034144d9f67e146ff...
commit 0f58139e80e4a6da1385034144d9f67e146ff6b8 Author: Cyril Hrubis metan@ucw.cz Date: Tue Jan 17 19:40:13 2012 +0100
text: Fix glyph metric computation.
Fix GP_TextWidth() count correctly for the first and last letter in the string.
+ Far more fixes and edhancements.
diff --git a/include/text/GP_Font.h b/include/text/GP_Font.h index 0bce212..3612873 100644 --- a/include/text/GP_Font.h +++ b/include/text/GP_Font.h @@ -173,6 +173,21 @@ static inline unsigned int GP_FontMaxWidth(const GP_FontFace *font) return font->max_glyph_width; }
+static inline unsigned int GP_FontMaxAdvanceX(const GP_FontFace *font) +{ + return font->max_glyph_advance; +} + +static inline const char *GP_FontFamily(const GP_FontFace *font) +{ + return font->family_name; +} + +static inline const char *GP_FontStyle(const GP_FontFace *font) +{ + return font->style_name; +} + /* * Returns glyph count for charset. */ diff --git a/libs/text/GP_DefaultFont.c b/libs/text/GP_DefaultFont.c index d2faa49..52b6608 100644 --- a/libs/text/GP_DefaultFont.c +++ b/libs/text/GP_DefaultFont.c @@ -219,8 +219,8 @@ static int8_t default_console_glyphs[] = { };
struct GP_FontFace GP_DefaultConsoleFont = { - .family_name = "gfxprim", - .style_name = "mono", + .family_name = "Gfxprim", + .style_name = "Mono", .charset = GP_CHARSET_7BIT, .ascend = 9, .descend = 2, @@ -425,8 +425,8 @@ static uint8_t default_proportional_glyphs[] = { };
struct GP_FontFace GP_DefaultProportionalFont = { - .family_name = "gfxprim", - .style_name = "proportional", + .family_name = "Gfxprim", + .style_name = "Proportional", .charset = GP_CHARSET_7BIT, .ascend = 9, .descend = 2, diff --git a/libs/text/GP_TextMetric.c b/libs/text/GP_TextMetric.c index 737d61d..45371fe 100644 --- a/libs/text/GP_TextMetric.c +++ b/libs/text/GP_TextMetric.c @@ -38,84 +38,96 @@ static const GP_GlyphBitmap *get_glyph(const GP_TextStyle *style, int c) return glyph; }
-static unsigned int get_pixel_multiplier(const GP_TextStyle *style) +static unsigned int multiply_width(const GP_TextStyle *style, unsigned int w) { - return style->pixel_xmul + style->pixel_xspace; + return w * style->pixel_xmul + (w - 1) * style->pixel_xspace; }
/* - * Returns glyph width from the basepoint to the end of the glyph bitmap. + * Returns glyph advance. */ -static unsigned int glyph_width(const GP_TextStyle *style, int c) +static unsigned int glyph_advance_x(const GP_TextStyle *style, int ch) { - unsigned int pixel_multiplier = get_pixel_multiplier(style); - const GP_GlyphBitmap *glyph = get_glyph(style, c); + const GP_GlyphBitmap *glyph = get_glyph(style, ch);
- return (glyph->width + glyph->bearing_x) * pixel_multiplier; + return multiply_width(style, glyph->advance_x); }
/* - * 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. - * + * Return maximal glyph advance for a character from str. */ -static unsigned int first_glyph_width(const GP_TextStyle *style, int c) +static unsigned int max_glyph_advance_x(const GP_TextStyle *style, + const char *str) { - unsigned int pixel_multiplier = get_pixel_multiplier(style); - const GP_GlyphBitmap *glyph = get_glyph(style, c); + unsigned int max = 0, i;
- return glyph->width * pixel_multiplier; + for (i = 0; str[i] != '0'; i++) + max = GP_MAX(max, glyph_advance_x(style, str[i])); + + return max; }
/* - * Returns space that is added after the glyph. - * - * Eg. the advance minus glyph width. - * - * TODO: kerning + * Returns _SINGLE_ glyph size, not including the bearing_x and including space + * occupied by the glyph bitmap if the bitmap width overflows glyph advance_x. */ -static unsigned int glyph_space(const GP_TextStyle *style, char ch) +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, ch); + unsigned int size, advance; - return (glyph->advance_x - glyph->width - glyph->bearing_x) - * pixel_multiplier + style->char_xspace; + const GP_GlyphBitmap *glyph = get_glyph(style, c); + + advance = multiply_width(style, glyph->advance_x - glyph->bearing_x); + size = multiply_width(style, glyph->width); + + return (size > advance) ? size : advance; }
/* - * Returns maximal character width for a given string. + * Returns size occupied by the last glyph. Here we take advance_x into account. */ -static unsigned int max_glyph_width(const GP_TextStyle *style, const char *str) +static unsigned int last_glyph_width(const GP_TextStyle *style, int c) { - unsigned int max = 0, i; - - for (i = 0; str[i] != '0'; i++) - max = GP_MAX(max, glyph_width(style, str[i])); + unsigned int size, advance; + + const GP_GlyphBitmap *glyph = get_glyph(style, c); + + advance = multiply_width(style, glyph->advance_x); + size = multiply_width(style, glyph->width + glyph->bearing_x);
- return max; + return (size > advance) ? size : advance; }
/* - * Return maximal character space after an glyph. + * Returns first glyph width, that is and advance minus the bearing_x. */ -static unsigned int max_glyph_space(const GP_TextStyle *style, const char *str) +static unsigned int first_glyph_width(const GP_TextStyle *style, int c) { - unsigned int max = 0, i; - - for (i = 0; str[i] != '0'; i++) - max = GP_MAX(max, glyph_space(style, str[i])); + const GP_GlyphBitmap *glyph = get_glyph(style, c);
- return max; + return multiply_width(style, glyph->advance_x - glyph->bearing_x); }
+/* + * Returns text width. + * + * There are two problems with text width it's start and it's end. + * + * At the start the first letter may have bearing_x negative, making it + * overflow out of the bouding box and even in case it's possitive the returned + * size would be slightly bigger. This one is easy to fix. + * + * The end of the string is problematic too, some of the glyphs may have + * advance smaller than sum of the bitmap width and bearing_x that way we would + * return slightly less than is the actuall size of the text bouding box. The + * other problem is that the advance is usually grater than the glyph space (as + * the exact size of the glyph itself without advance before and space after is + * not known), so we likely return some more pixels than is needed, but that's + * the joy of life. + */ unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str) { - unsigned int i, len = 0; + unsigned int i, len;
if (style == NULL) style = &GP_DefaultStyle; @@ -123,93 +135,85 @@ unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str) if (str == NULL || str[0] == '0') return 0;
- len += first_glyph_width(style, str[0]); - - if (str[1] == '0') - return len; - - len += glyph_space(style, str[0]); + /* special case, one letter */ + if (str[1] == '0') { + return glyph_width(style, str[0]); + }
- for (i = 1; str[i] != '0'; i++) { - len += glyph_width(style, str[i]); + /* first letter */ + len = first_glyph_width(style, str[0]) + style->char_xspace; + + /* middle letters */ + for (i = 1; str[i+1] != '0'; i++) + len += glyph_advance_x(style, str[i]) + style->char_xspace;
- if (str[i+1] != '0') - len += glyph_space(style, str[i]); - } + /* last letter */ + len += last_glyph_width(style, str[i]);
return len; }
+/* + * Return max advance now. We will do something better maybe. + */ GP_Size GP_TextMaxWidth(const GP_TextStyle *style, unsigned int len) { - unsigned int glyph_width; - //TODO: ! - unsigned int space_width = style->char_xspace; - if (style == NULL) style = &GP_DefaultStyle;
- glyph_width = style->font->max_glyph_width - * (style->pixel_xmul + style->pixel_xspace); - if (len == 0) return 0;
- return len * glyph_width + (len - 1) * space_width; + return multiply_width(style, len * style->font->max_glyph_advance) + + (len - 1) * style->char_xspace; }
+/* + * Here too. + */ GP_Size GP_TextMaxStrWidth(const GP_TextStyle *style, const char *str, unsigned int len) { - unsigned int space_width; - unsigned int glyph_width; - if (style == NULL) style = &GP_DefaultStyle; - space_width = max_glyph_space(style, str); - if (len == 0 || str == NULL) return 0;
- glyph_width = max_glyph_width(style, str); + return len * max_glyph_advance_x(style, str) + + (len - 1) * style->char_xspace; +} + +/* Ascend, Descend, Height -- far easier */
- return len * glyph_width + (len - 1) * space_width; +static unsigned int multiply_height(const GP_TextStyle *style, unsigned int h) +{ + return h * style->pixel_ymul + (h - 1) * style->pixel_yspace; }
GP_Size GP_TextHeight(const GP_TextStyle *style) { - unsigned int h; - if (style == NULL) style = &GP_DefaultStyle; + + unsigned int height = style->font->ascend + style->font->descend;
- h = style->font->ascend + style->font->descend; - - return h * style->pixel_ymul + - (h - 1) * style->pixel_yspace; + return multiply_height(style, height); }
GP_Size GP_TextAscent(const GP_TextStyle *style) { - unsigned int h; - if (style == NULL) style = &GP_DefaultStyle;
- h = style->font->ascend; - return h * style->pixel_ymul + (h - 1) * style->pixel_yspace; + return multiply_height(style, style->font->ascend); }
GP_Size GP_TextDescent(const GP_TextStyle *style) { - unsigned int h; - if (style == NULL) style = &GP_DefaultStyle;
- h = style->font->descend; - - return h * style->pixel_ymul + (h - 1) * style->pixel_yspace; + return multiply_height(style, style->font->descend); } diff --git a/tests/SDL/fonttest.c b/tests/SDL/fonttest.c index ec9f93a..2fdf194 100644 --- a/tests/SDL/fonttest.c +++ b/tests/SDL/fonttest.c @@ -83,9 +83,12 @@ static void print_character_metadata(const GP_FontFace *font, int c)
static void print_font_properties(const GP_FontFace *font) { - fprintf(stderr, "Font properties:n"); + fprintf(stderr, "Font '%s %s' properties:n", + GP_FontFamily(font), GP_FontStyle(font)); fprintf(stderr, " Height: ascend: %d, descend: %dn", GP_FontAscend(font), GP_FontDescend(font)); + fprintf(stderr, " Max advance_x: %un", + GP_FontMaxAdvanceX(font)); fprintf(stderr, " Glyph bitmap format: %sn", glyph_bitmap_format_name(font->glyph_bitmap_format)); fprintf(stderr, " Bounding box width: %d, heigth: %dn", @@ -155,9 +158,13 @@ void redraw_screen(void) style.pixel_ymul = 2; style.pixel_yspace = 1;
- GP_Text(&context, &style, 34, SPACING*i + 44, align, + GP_Text(&context, &style, 34, SPACING * i + 44, align, white_pixel, black_pixel, test_string);
+ GP_RectXYWH(&context, 33, SPACING * i + 43, + GP_TextWidth(&style, test_string) + 1, + GP_TextHeight(&style) + 1, dark_gray_pixel); + style.pixel_xmul = 4; style.pixel_ymul = 2; style.pixel_xspace = 1;
-----------------------------------------------------------------------
Summary of changes: include/text/GP_Font.h | 15 ++++ libs/input/GP_Event.c | 43 +++++++++++- libs/text/GP_DefaultFont.c | 8 +- libs/text/GP_TextMetric.c | 172 ++++++++++++++++++++++--------------------- tests/SDL/fonttest.c | 11 +++- 5 files changed, 158 insertions(+), 91 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.