From f48b9f7443529be18342be69bd2a84510e597a66 Mon Sep 17 00:00:00 2001 From: martin-s Date: Sun, 8 Jan 2006 20:28:41 +0000 Subject: [PATCH] Fixed labelling with non-ascii chars git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@75 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/src/display.c | 10 ++++++++-- .../src/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c | 11 ++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/navit/src/display.c b/navit/src/display.c index bd534f6..75cb399 100644 --- a/navit/src/display.c +++ b/navit/src/display.c @@ -215,6 +215,7 @@ label_line(struct graphics *gr, struct graphics_gc *fg, struct graphics_gc *bg, int i,x,y,tl; double dx,dy,l; struct point p_t; + char *utf8; tl=strlen(label)*400; for (i = 0 ; i < count-1 ; i++) { @@ -241,7 +242,9 @@ label_line(struct graphics *gr, struct graphics_gc *fg, struct graphics_gc *bg, #if 0 printf("display_text: '%s', %d, %d, %d, %d %d\n", label, x, y, dx*0x10000/l, dy*0x10000/l, l); #endif - gr->draw_text(gr, fg, bg, font, label, &p_t, dx*0x10000/l, dy*0x10000/l); + utf8=g_convert(label, -1, "utf8", "iso8859-1", NULL, NULL, NULL); + gr->draw_text(gr, fg, bg, font, utf8, &p_t, dx*0x10000/l, dy*0x10000/l); + g_free(utf8); } } } @@ -250,6 +253,7 @@ void display_labels(struct display_list *list, struct graphics *gr, struct graphics_gc *fg, struct graphics_gc *bg, struct graphics_font *font) { struct point p; + char *utf8; while (list) { if (list->label) { switch (list->type) { @@ -260,7 +264,9 @@ display_labels(struct display_list *list, struct graphics *gr, struct graphics_g case 3: p.x=list->p[0].x+3; p.y=list->p[0].y+10; - gr->draw_text(gr, fg, bg, font, list->label, &p, 0x10000, 0); + utf8=g_convert(list->label, -1, "utf8", "iso8859-1", NULL, NULL, NULL); + gr->draw_text(gr, fg, bg, font, utf8, &p, 0x10000, 0); + g_free(utf8); break; } } diff --git a/navit/src/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c b/navit/src/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c index 903148c..55b9f01 100644 --- a/navit/src/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c +++ b/navit/src/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c @@ -73,6 +73,7 @@ static struct graphics_font *font_new(struct graphics *gr, int size) return NULL; } FT_Set_Char_Size(font->face, 0, size, 300, 300); + FT_Select_Charmap(font->face, FT_ENCODING_UNICODE); return font; } @@ -237,10 +238,13 @@ display_text_render(char *text, struct graphics_font *font, int dx, int dy, int FT_Matrix matrix; FT_Vector pen; FT_UInt glyph_index; - int n,len=strlen(text); - struct text_render *ret=g_malloc(sizeof(*ret)+len*sizeof(struct text_glyph *)); + int n,len; + struct text_render *ret; struct text_glyph *curr; + wchar_t wtext[1024]; + len=mbstowcs(wtext, text, 1024); + ret=g_malloc(sizeof(*ret)+len*sizeof(struct text_glyph *)); ret->glyph_count=len; matrix.xx = dx; @@ -253,12 +257,13 @@ display_text_render(char *text, struct graphics_font *font, int dx, int dy, int x <<= 6; y <<= 6; FT_Set_Transform( font->face, &matrix, &pen ); + for ( n = 0; n < len; n++ ) { - glyph_index = FT_Get_Char_Index(font->face, text[n]); + glyph_index = FT_Get_Char_Index(font->face, wtext[n]); FT_Load_Glyph(font->face, glyph_index, FT_LOAD_DEFAULT ); FT_Render_Glyph(font->face->glyph, ft_render_mode_normal ); -- 2.7.4