libdrawtext
changeset 4:17fed026b24b
done with the unicode sample
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Fri, 16 Sep 2011 08:31:06 +0300 |
parents | fe0c54e574ae |
children | 095ff7ca4e74 |
files | examples/Makefile examples/unicode/Makefile examples/unicode/unicode.c src/utf8.c |
diffstat | 4 files changed, 46 insertions(+), 23 deletions(-) [+] |
line diff
1.1 --- a/examples/Makefile Thu Sep 15 23:32:39 2011 +0300 1.2 +++ b/examples/Makefile Fri Sep 16 08:31:06 2011 +0300 1.3 @@ -1,15 +1,24 @@ 1.4 -fonts = fonts/FreeSerif.ttf fonts/klingon.ttf 1.5 +fonts = fonts/linux-libertine.ttf fonts/klingon.ttf fonts/sazanami-mincho.ttf 1.6 1.7 .PHONY: all 1.8 all: $(fonts) 1.9 cd simple; $(MAKE) 1.10 + cd unicode; $(MAKE) 1.11 1.12 -fonts/FreeSerif.ttf: 1.13 +fonts/linux-libertine.ttf: 1.14 mkdir -p fonts 1.15 - wget http://ftp.gnu.org/gnu/freefont/freefont-ttf-20100919.tar.gz 1.16 - tar xzvf freefont-ttf-20100919.tar.gz 1.17 - rm -f freefont-ttf-20100919.tar.gz 1.18 - cp freefont-20100919/FreeSerif.ttf $@ 1.19 + wget http://downloads.sourceforge.net/project/linuxlibertine/linuxlibertine/5.1.3-2/LinLibertineTTF_5.1.3_2011_06_21.tgz 1.20 + mkdir -p linlibertine 1.21 + cd linlibertine; tar xzvf ../LinLibertineTTF_5.1.3_2011_06_21.tgz 1.22 + rm -f LinLibertineTTF_5.1.3_2011_06_21.tgz 1.23 + cp linlibertine/LinLibertine_R.ttf $@ 1.24 + 1.25 +fonts/sazanami-mincho.ttf: 1.26 + mkdir -p fonts 1.27 + wget -O sazanami-20040629.tar.bz2 'http://sourceforge.jp/frs/redir.php?m=iij&f=/efont/10087/sazanami-20040629.tar.bz2' 1.28 + tar xjvf sazanami-20040629.tar.bz2 1.29 + rm -f sazanami-20040629.tar.bz2 1.30 + cp sazanami-20040629/sazanami-mincho.ttf $@ 1.31 1.32 fonts/klingon.ttf: 1.33 mkdir -p fonts
2.1 --- a/examples/unicode/Makefile Thu Sep 15 23:32:39 2011 +0300 2.2 +++ b/examples/unicode/Makefile Fri Sep 16 08:31:06 2011 +0300 2.3 @@ -6,7 +6,7 @@ 2.4 LDFLAGS = -L. -ldrawtext $(libgl) 2.5 2.6 lib_so = libdrawtext.so 2.7 -fonts = serif.ttf klingon.ttf 2.8 +fonts = serif.ttf cjk.ttf klingon.ttf 2.9 2.10 ifeq ($(shell uname -s), Darwin) 2.11 libgl = -framework OpenGL -framework GLUT 2.12 @@ -21,7 +21,11 @@ 2.13 rm -f $@ 2.14 ln -s $< $@ 2.15 2.16 -serif.ttf: ../fonts/FreeSerif.ttf 2.17 +serif.ttf: ../fonts/linux-libertine.ttf 2.18 + rm -f $@ 2.19 + ln -s $< $@ 2.20 + 2.21 +cjk.ttf: ../fonts/sazanami-mincho.ttf 2.22 rm -f $@ 2.23 ln -s $< $@ 2.24
3.1 --- a/examples/unicode/unicode.c Thu Sep 15 23:32:39 2011 +0300 3.2 +++ b/examples/unicode/unicode.c Fri Sep 16 08:31:06 2011 +0300 3.3 @@ -20,40 +20,47 @@ 3.4 /* XXX fonts are represented by the opaque struct dtx_font type, so you 3.5 * need to create at least one with dtx_open_font (see main). 3.6 */ 3.7 -struct dtx_font *freeserif, *klingon; 3.8 +struct dtx_font *fntmain, *fntcjk, *fntklingon; 3.9 3.10 -#define FONT_SIZE 24 3.11 +#define FONT_SZ 24 3.12 3.13 int main(int argc, char **argv) 3.14 { 3.15 glutInit(&argc, argv); 3.16 glutInitWindowSize(512, 384); 3.17 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 3.18 - glutCreateWindow("libdrawtext example: simple"); 3.19 + glutCreateWindow("libdrawtext example: unicode"); 3.20 3.21 glutDisplayFunc(disp); 3.22 glutReshapeFunc(reshape); 3.23 glutKeyboardFunc(keyb); 3.24 3.25 /* XXX dtx_open_font opens a font file and returns a pointer to dtx_font */ 3.26 - if(!(freeserif = dtx_open_font("serif.ttf", 0))) { 3.27 + if(!(fntmain = dtx_open_font("serif.ttf", 0))) { 3.28 return 1; 3.29 } 3.30 - dtx_prepare_range(freeserif, FONT_SIZE, 0, 256); /* prepare ASCII */ 3.31 - dtx_prepare_range(freeserif, FONT_SIZE, 0x0370, 0x0400); /* greek */ 3.32 - dtx_prepare_range(freeserif, FONT_SIZE, 0x4e00, 0x9fc0); /* kanji */ 3.33 + dtx_prepare_range(fntmain, FONT_SZ, 0, 256); /* ASCII */ 3.34 + dtx_prepare_range(fntmain, FONT_SZ, 0x370, 0x400); /* greek */ 3.35 + dtx_prepare_range(fntmain, FONT_SZ, 0x400, 0x500); /* cyrilic */ 3.36 3.37 - if(!(klingon = dtx_open_font("klingon.ttf", 0))) { 3.38 + if(!(fntcjk = dtx_open_font("cjk.ttf", 0))) { 3.39 return 1; 3.40 } 3.41 - dtx_prepare_range(klingon, FONT_SIZE, 0xf8d0, 0xf900); 3.42 + dtx_prepare_range(fntcjk, FONT_SZ, 0x4e00, 0x9fc0); /* kanji */ 3.43 + 3.44 + if(!(fntklingon = dtx_open_font("klingon.ttf", 0))) { 3.45 + return 1; 3.46 + } 3.47 + dtx_prepare_range(fntklingon, FONT_SZ, 0xf8d0, 0xf900); /* klingon */ 3.48 3.49 glutMainLoop(); 3.50 return 0; 3.51 } 3.52 3.53 -const char *ascii_text = "Hello world!"; 3.54 +/* various UTF-8 strings */ 3.55 +const char *english_text = "Hello world!"; 3.56 const char *greek_text = "\xce\x9a\xce\xbf\xcf\x8d\xcf\x81\xce\xb1\xcf\x83\xce\xb7"; 3.57 +const char *russian_text = "\xd0\xa0\xd0\xb0\xd1\x81\xd1\x86\xd0\xb2\xd0\xb5\xd1\x82\xd0\xb0\xd0\xbb\xd0\xb8 \xd1\x8f\xd0\xb1\xd0\xbb\xd0\xbe\xd0\xbd\xd0\xb8 \xd0\xb8 \xd0\xb3\xd1\x80\xd1\x83\xd1\x88\xd0\xb8"; 3.58 const char *kanji_text = "\xe4\xb9\x97\xe4\xba\xac"; 3.59 const char *klingon_text = "\xef\xa3\xa3\xef\xa3\x9d\xef\xa3\x93\xef\xa3\x98\xef\xa3\x9d\xef\xa3\xa2\xef\xa3\xa1\xef\xa3\x9d\xef\xa3\x99"; 3.60 3.61 @@ -65,21 +72,26 @@ 3.62 glMatrixMode(GL_MODELVIEW); 3.63 glLoadIdentity(); 3.64 3.65 - dtx_use_font(freeserif, FONT_SIZE); 3.66 + dtx_use_font(fntmain, FONT_SZ); 3.67 3.68 glTranslatef(-200, 150, 0); 3.69 /* XXX call dtx_string to draw utf-8 text. 3.70 * any transformations and the current color apply 3.71 */ 3.72 - dtx_string(ascii_text); 3.73 + dtx_string(english_text); 3.74 3.75 glTranslatef(0, -40, 0); 3.76 dtx_string(greek_text); 3.77 3.78 glTranslatef(0, -40, 0); 3.79 + dtx_string(russian_text); 3.80 + 3.81 + dtx_use_font(fntcjk, FONT_SZ); 3.82 + 3.83 + glTranslatef(0, -40, 0); 3.84 dtx_string(kanji_text); 3.85 3.86 - dtx_use_font(klingon, FONT_SIZE); 3.87 + dtx_use_font(fntklingon, FONT_SZ); 3.88 3.89 glTranslatef(0, -40, 0); 3.90 dtx_string(klingon_text);