# HG changeset patch # User John Tsiombikas # Date 1363579586 -7200 # Node ID 9fd4bf11cc1e467afea2d70272000aa7c0762dca # Parent e0eb231ca9edc782e7d3c004313f37df8eedeb9e# Parent aca73aa1944f478d385f428e67727e3a9f4b0aa2 merged diff -r e0eb231ca9ed -r 9fd4bf11cc1e examples/Makefile --- a/examples/Makefile Mon Aug 27 05:04:19 2012 +0300 +++ b/examples/Makefile Mon Mar 18 06:06:26 2013 +0200 @@ -12,6 +12,7 @@ cd linlibertine; tar xzvf ../LinLibertineTTF_5.1.3_2011_06_21.tgz rm -f LinLibertineTTF_5.1.3_2011_06_21.tgz cp linlibertine/LinLibertine_R.ttf $@ + rm -rf linlibertine fonts/sazanami-mincho.ttf: mkdir -p fonts @@ -19,6 +20,7 @@ tar xjvf sazanami-20040629.tar.bz2 rm -f sazanami-20040629.tar.bz2 cp sazanami-20040629/sazanami-mincho.ttf $@ + rm -rf sazanami-20040629 fonts/klingon.ttf: mkdir -p fonts @@ -26,3 +28,4 @@ unzip -o tlh_2D00_pIqaD_2D00_US.zip rm -f tlh_2D00_pIqaD_2D00_US.zip cp tlh-pIqaD-US/pIqaD.ttf $@ + rm -rf tlh-pIqaD-US diff -r e0eb231ca9ed -r 9fd4bf11cc1e libdrawtext.sln --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libdrawtext.sln Mon Mar 18 06:06:26 2013 +0200 @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdrawtext", "libdrawtext.vcproj", "{F6241CAB-984D-457D-A7EA-E66A57889490}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F6241CAB-984D-457D-A7EA-E66A57889490}.Debug|Win32.ActiveCfg = Debug|Win32 + {F6241CAB-984D-457D-A7EA-E66A57889490}.Debug|Win32.Build.0 = Debug|Win32 + {F6241CAB-984D-457D-A7EA-E66A57889490}.Release|Win32.ActiveCfg = Release|Win32 + {F6241CAB-984D-457D-A7EA-E66A57889490}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff -r e0eb231ca9ed -r 9fd4bf11cc1e libdrawtext.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libdrawtext.vcproj Mon Mar 18 06:06:26 2013 +0200 @@ -0,0 +1,185 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r e0eb231ca9ed -r 9fd4bf11cc1e src/drawgl.c --- a/src/drawgl.c Mon Aug 27 05:04:19 2012 +0300 +++ b/src/drawgl.c Mon Mar 18 06:06:26 2013 +0200 @@ -16,11 +16,18 @@ along with this program. If not, see . */ #ifndef NO_OPENGL +#include #include #include #include +#ifndef _MSC_VER +#include +#else +#include +#endif + #ifdef TARGET_IPHONE #include #else @@ -117,9 +124,31 @@ dtx_flush(); } +static const char *put_char(const char *str, float *pos_x, float *pos_y, int *should_flush) +{ + struct dtx_glyphmap *gmap; + float px, py; + int code = dtx_utf8_char_code(str); + str = dtx_utf8_next_char((char*)str); + + if(buf_mode == DTX_LBF && code == '\n') { + *should_flush = 1; + } + + px = *pos_x; + py = *pos_y; + + if((gmap = dtx_proc_char(code, pos_x, pos_y))) { + int idx = code - gmap->cstart; + + set_glyphmap_texture(gmap); + add_glyph(gmap->glyphs + idx, px, py); + } + return str; +} + void dtx_string(const char *str) { - struct dtx_glyphmap *gmap; int should_flush = buf_mode == DTX_NBF; float pos_x = 0.0f; float pos_y = 0.0f; @@ -129,23 +158,7 @@ } while(*str) { - float px, py; - int code = dtx_utf8_char_code(str); - str = dtx_utf8_next_char((char*)str); - - if(buf_mode == DTX_LBF && code == '\n') { - should_flush = 1; - } - - px = pos_x; - py = pos_y; - - if((gmap = dtx_proc_char(code, &pos_x, &pos_y))) { - int idx = code - gmap->cstart; - - set_glyphmap_texture(gmap); - add_glyph(gmap->glyphs + idx, px, py); - } + str = put_char(str, &pos_x, &pos_y, &should_flush); } if(should_flush) { @@ -153,6 +166,32 @@ } } +void dtx_printf(const char *fmt, ...) +{ + va_list ap; + int buf_size; + char *buf, tmp; + + if(!dtx_font) { + return; + } + + va_start(ap, fmt); + buf_size = vsnprintf(&tmp, 0, fmt, ap); + va_end(ap); + + if(buf_size == -1) { + buf_size = 512; + } + + buf = alloca(buf_size + 1); + va_start(ap, fmt); + vsnprintf(buf, buf_size + 1, fmt, ap); + va_end(ap); + + dtx_string(buf); +} + static void qvertex(struct vertex *v, float x, float y, float s, float t) { v->x = x; diff -r e0eb231ca9ed -r 9fd4bf11cc1e src/drawtext.h --- a/src/drawtext.h Mon Aug 27 05:04:19 2012 +0300 +++ b/src/drawtext.h Mon Mar 18 06:06:26 2013 +0200 @@ -116,6 +116,8 @@ /* draws a utf-8 string starting at the origin. \n \r and \t are handled appropriately. */ void dtx_string(const char *str); +void dtx_printf(const char *fmt, ...); + /* render any pending glyphs (see dtx_draw_buffering) */ void dtx_flush(void); diff -r e0eb231ca9ed -r 9fd4bf11cc1e src/drawtext_impl.h --- a/src/drawtext_impl.h Mon Aug 27 05:04:19 2012 +0300 +++ b/src/drawtext_impl.h Mon Mar 18 06:06:26 2013 +0200 @@ -61,7 +61,7 @@ #define fperror(str) \ - fprintf(stderr, "%s: %s: %s\n", __func__, (str), strerror(errno)) + fprintf(stderr, "%s: %s: %s\n", __FUNCTION__, (str), strerror(errno)) int dtx_gl_init(void); diff -r e0eb231ca9ed -r 9fd4bf11cc1e src/font.c --- a/src/font.c Mon Aug 27 05:04:19 2012 +0300 +++ b/src/font.c Mon Mar 18 06:06:26 2013 +0200 @@ -331,12 +331,12 @@ if(line[0] == '#') { struct glyph *g; - int c; - float x, y, xsz, ysz, res; + int c, res; + float x, y, xsz, ysz; res = sscanf(line + 1, "%d: %fx%f+%f+%f\n", &c, &xsz, &ysz, &x, &y); if(res != 5) { - fprintf(stderr, "%s: invalid glyph info line\n", __func__); + fprintf(stderr, "%s: invalid glyph info line\n", __FUNCTION__); goto err; } @@ -362,14 +362,14 @@ switch(hdr_lines) { case 0: if(0[line] != 'P' || 1[line] != '6') { - fprintf(stderr, "%s: invalid file format (magic)\n", __func__); + fprintf(stderr, "%s: invalid file format (magic)\n", __FUNCTION__); goto err; } break; case 1: if(sscanf(line, "%d %d", &gmap->xsz, &gmap->ysz) != 2) { - fprintf(stderr, "%s: invalid file format (dim)\n", __func__); + fprintf(stderr, "%s: invalid file format (dim)\n", __FUNCTION__); goto err; } break; @@ -379,7 +379,7 @@ char *endp; max_pixval = strtol(line, &endp, 10); if(endp == line) { - fprintf(stderr, "%s: invalid file format (maxval)\n", __func__); + fprintf(stderr, "%s: invalid file format (maxval)\n", __FUNCTION__); goto err; } } @@ -442,7 +442,7 @@ int res; if(!(fp = fopen(fname, "wb"))) { - fprintf(stderr, "%s: failed to open file: %s: %s\n", __func__, fname, strerror(errno)); + fprintf(stderr, "%s: failed to open file: %s: %s\n", __FUNCTION__, fname, strerror(errno)); return -1; } res = dtx_save_glyphmap_stream(fp, gmap);