ucw.cz
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
List overview
Download
Gfxprim
January 2012
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
gfxprim@ucw.cz
2 participants
41 discussions
Start a n
N
ew thread
[repo.or.cz] gfxprim.git branch master updated: 0c39d1adbaeb40591a13cbf965d773374fb8194b
by metan
01 Jan '12
01 Jan '12
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/0c39d1adbaeb40591a13cbf965d773374fb8…
commit 0c39d1adbaeb40591a13cbf965d773374fb8194b Author: Cyril Hrubis <metan(a)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(a)ucw.cz> * + * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)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(a)ucw.cz> * + * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)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(a)gmail.com> * * * - * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)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(a)gmail.com> * * * - * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)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(a)gmail.com> * * * - * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)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(a)gmail.com> * * * - * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)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(a)gmail.com if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive no reply. -- gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
0
0
← Newer
1
2
3
4
5
Older →
Jump to page:
1
2
3
4
5
Results per page:
10
25
50
100
200