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 11237152b73f0794cd98e0de4c20ce180ac19535 (commit) via 6cdc1275dfebee03fcc18a35db7097d9bc81bac2 (commit) via e6bba64ea14e9b8beb74ead24a54a61be48afacf (commit) from 33fd79bc8b7affb6ba6c72092670f4821ea29979 (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/11237152b73f0794cd98e0de4c20ce180ac19...
commit 11237152b73f0794cd98e0de4c20ce180ac19535 Author: Cyril Hrubis metan@ucw.cz Date: Sat Apr 6 21:54:07 2013 +0200
demos: py_simple: Add font style example.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/py_simple/font_style.py b/demos/py_simple/font_style.py new file mode 100755 index 0000000..47d8e2c --- /dev/null +++ b/demos/py_simple/font_style.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +import sys + +import gfxprim.core as core +import gfxprim.gfx as gfx +import gfxprim.backends as backends +import gfxprim.input as input +import gfxprim.text as text + +def redraw(win): + c = win.context + + black = c.RGBToPixel(0, 0, 0) + white = c.RGBToPixel(0xff, 0xff, 0xff) + + c.gfx.Fill(black) + + align = text.C.ALIGN_CENTER | text.C.VALIGN_CENTER + style = text.TextStyle(text.DefaultProportionalFont, 0, 0, 1, 1, 1) + + spacing = 20 + y = 20 + + while y < c.h: + y += text.TextHeight(style) + spacing + c.text.Text(style, c.w//2, y, align, white, black, "Lorem Ipsum Dolor Sit Amet.") + + style.pixel_xspace += 1 + style.pixel_yspace += 1 + style.pixel_xmul += 1 + style.pixel_ymul += 1 + + win.Flip() + + +def main(): + # Create X11 window + win = backends.BackendX11Init(None, 0, 0, 800, 600, "Fonts", 0) + assert(win) + + redraw(win) + + # Event loop + while True: + ev = win.WaitEvent() + + if (ev.type == input.EV_KEY and ev.val.val == input.KEY_ESC): + sys.exit(0) + elif (ev.type == input.EV_SYS): + if (ev.code == input.EV_SYS_QUIT): + sys.exit(0) + if (ev.code == input.EV_SYS_RESIZE): + win.ResizeAck() + redraw(win) + +if __name__ == '__main__': + main()
http://repo.or.cz/w/gfxprim.git/commit/6cdc1275dfebee03fcc18a35db7097d9bc81b...
commit 6cdc1275dfebee03fcc18a35db7097d9bc81bac2 Author: Cyril Hrubis metan@ucw.cz Date: Sat Apr 6 21:52:57 2013 +0200
pywrap: text: Add wrappers for GP_TextStyle.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/pylib/gfxprim/text/__init__.py b/pylib/gfxprim/text/__init__.py index 85b149a..2561900 100644 --- a/pylib/gfxprim/text/__init__.py +++ b/pylib/gfxprim/text/__init__.py @@ -12,7 +12,7 @@ from . import C
def _init(module): "Extend context with text submodule" - + from ..utils import extend, add_swig_getmethod, add_swig_setmethod from ..core import Context as _context
@@ -34,7 +34,9 @@ def _init(module): '^GP_[A-Z0-9_]*$', ] import_members(c_text, C, include=const_regexes, sub=strip_GP) - + + import_members(c_text, module, sub=strip_GP) + for name in ['Text']: extend_submodule(TextSubmodule, name, c_text.__getattribute__('GP_' + name))
diff --git a/pylib/gfxprim/text/text.i b/pylib/gfxprim/text/text.i index 49335bc..485c31c 100644 --- a/pylib/gfxprim/text/text.i +++ b/pylib/gfxprim/text/text.i @@ -4,6 +4,7 @@ %{ #include "text/GP_Text.h" #include "text/GP_Font.h" +#include "core/GP_Debug.h" %}
%import ../core/core.i @@ -14,5 +15,31 @@ %include "GP_Font.h" %include "GP_DefaultFont.h" %include "GP_TextMetric.h" -%include "GP_TextStyle.h"
+/* GP_TextStyle wrappers */ +%extend GP_TextStyle { + ~GP_TextStyle() { + GP_DEBUG(2, "[wrapper] GP_TextStyleFree (%p)", $self); + free($self); + } + GP_TextStyle(const struct GP_FontFace *font, int xspace, int yspace, + int xmul, int ymul, int spacing) { + GP_TextStyle *style = malloc(sizeof(GP_TextStyle)); + + GP_DEBUG(2, "[wrapper] GP_TextStyleAlloc (%p)", style); + + if (style == NULL) + return NULL; + + style->font = font; + style->pixel_xspace = xspace; + style->pixel_yspace = yspace; + style->pixel_xmul = xmul; + style->pixel_ymul = ymul; + style->char_xspace = spacing; + + return style; + } +} + +%include "GP_TextStyle.h"
http://repo.or.cz/w/gfxprim.git/commit/e6bba64ea14e9b8beb74ead24a54a61be48af...
commit e6bba64ea14e9b8beb74ead24a54a61be48afacf Author: Cyril Hrubis metan@ucw.cz Date: Sat Apr 6 21:25:21 2013 +0200
lib: text: Assert that style->font is not NULL.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/text/GP_TextMetric.c b/libs/text/GP_TextMetric.c index 45371fe..26b26f8 100644 --- a/libs/text/GP_TextMetric.c +++ b/libs/text/GP_TextMetric.c @@ -108,6 +108,16 @@ static unsigned int first_glyph_width(const GP_TextStyle *style, int c) return multiply_width(style, glyph->advance_x - glyph->bearing_x); }
+static const GP_TextStyle *assert_style(const GP_TextStyle *style) +{ + if (style == NULL) + style = &GP_DefaultStyle; + + GP_ASSERT(style->font != NULL); + + return style; +} + /* * Returns text width. * @@ -129,8 +139,7 @@ unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str) { unsigned int i, len;
- if (style == NULL) - style = &GP_DefaultStyle; + style = assert_style(style);
if (str == NULL || str[0] == '0') return 0; @@ -158,8 +167,7 @@ unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str) */ GP_Size GP_TextMaxWidth(const GP_TextStyle *style, unsigned int len) { - if (style == NULL) - style = &GP_DefaultStyle; + style = assert_style(style);
if (len == 0) return 0; @@ -174,9 +182,8 @@ GP_Size GP_TextMaxWidth(const GP_TextStyle *style, unsigned int len) GP_Size GP_TextMaxStrWidth(const GP_TextStyle *style, const char *str, unsigned int len) { - if (style == NULL) - style = &GP_DefaultStyle; - + style = assert_style(style); + if (len == 0 || str == NULL) return 0;
@@ -193,9 +200,8 @@ static unsigned int multiply_height(const GP_TextStyle *style, unsigned int h)
GP_Size GP_TextHeight(const GP_TextStyle *style) { - if (style == NULL) - style = &GP_DefaultStyle; - + style = assert_style(style); + unsigned int height = style->font->ascend + style->font->descend;
return multiply_height(style, height); @@ -203,17 +209,14 @@ GP_Size GP_TextHeight(const GP_TextStyle *style)
GP_Size GP_TextAscent(const GP_TextStyle *style) { - if (style == NULL) - style = &GP_DefaultStyle; + style = assert_style(style);
- return multiply_height(style, style->font->ascend); }
GP_Size GP_TextDescent(const GP_TextStyle *style) { - if (style == NULL) - style = &GP_DefaultStyle; + style = assert_style(style);
return multiply_height(style, style->font->descend); }
-----------------------------------------------------------------------
Summary of changes: demos/py_simple/font_style.py | 58 ++++++++++++++++++++++++++++++++++++++++ libs/text/GP_TextMetric.c | 33 ++++++++++++---------- pylib/gfxprim/text/__init__.py | 6 +++- pylib/gfxprim/text/text.i | 29 +++++++++++++++++++- 4 files changed, 108 insertions(+), 18 deletions(-) create mode 100755 demos/py_simple/font_style.py
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.