Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#11163) Xaw I18N patch
Home

[Freeciv-Dev] (PR#11163) Xaw I18N patch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11163) Xaw I18N patch
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Tue, 23 Nov 2004 14:37:58 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=11163 >

> [jdorje - Tue Nov 23 22:02:48 2004]:
> 
> In fact it doesn't work for me.  Both Polish and Hungarian nations have 
> their leader names drawn incorrectly in the nation selection dialog.

I mistakenly patched Freeciv instead of Freeciv.in. Try this patch instead.

Index: client/gui-xaw/chatline.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/chatline.c,v
retrieving revision 1.24
diff -u -r1.24 chatline.c
--- client/gui-xaw/chatline.c   10 Aug 2004 01:40:32 -0000      1.24
+++ client/gui-xaw/chatline.c   23 Nov 2004 22:37:07 -0000
@@ -77,36 +77,9 @@
    *
    * Now uses window's font size and width.  Assumes fixed-width font.  --jjm
    */
-  static int m_width=0;
-
-  Dimension windowwth;
-  int maxlinelen;
   String theoutput;
   char *newout, *rmcr, *astring2 = mystrdup(astring);
 
-  if (!m_width) {
-    /* Sometimes XtVaGetValues has garbage for the XtNfont; see PR#6452.
-     * In this case it's safest if the value is initialized to NULL. */
-    XFontStruct *out_font = NULL;
-
-    XtVaGetValues(outputwindow_text, XtNfont, &out_font, NULL);
-    if (out_font)
-      m_width=XTextWidth(out_font, "M", 1);
-    else
-      m_width=10;
-  }
-
-  XtVaGetValues(outputwindow_text, XtNwidth, &windowwth, NULL);
-  maxlinelen=(windowwth/m_width)-1;
-  if (maxlinelen<32) maxlinelen=32;
-
-  freelog(LOG_DEBUG, "m_width %d windowwth %d maxlinelen %d",
-         m_width, (int)windowwth, maxlinelen);
-
-  if (strlen(astring2) > maxlinelen) {
-    wordwrap_string(astring2, maxlinelen);
-  }
-  
   XtVaGetValues(outputwindow_text, XtNstring, &theoutput, NULL);
   newout=fc_malloc(strlen(astring2)+strlen(theoutput)+2);
   sprintf(newout, "%s\n%s", theoutput, astring2);
Index: client/gui-xaw/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/graphics.c,v
retrieving revision 1.53
diff -u -r1.53 graphics.c
--- client/gui-xaw/graphics.c   27 Jul 2004 17:53:37 -0000      1.53
+++ client/gui-xaw/graphics.c   23 Nov 2004 22:37:07 -0000
@@ -93,10 +93,12 @@
   XColor face;
   int have_face;
   const char *motto = freeciv_motto();
+  XFontSetExtents *exts;
 
   /* metrics */
 
-  lin=main_font_struct->ascent+main_font_struct->descent;
+  exts = XExtentsOfFontSet(main_font_set);
+  lin = exts->max_logical_extent.height;
 
   /* get colors */
 
@@ -115,9 +117,10 @@
 
   y=intro_gfx_sprite->height-(2*lin);
 
-  w=XTextWidth(main_font_struct, motto, strlen(motto));
+  w = XmbTextEscapement(main_font_set, motto, strlen(motto));
   XSetForeground(display, font_gc, face.pixel);
-  XDrawString(display, intro_gfx_sprite->pixmap, font_gc, 
+  XmbDrawString(display, intro_gfx_sprite->pixmap,
+             main_font_set, font_gc, 
              tot/2-w/2, y, 
              motto, strlen(motto));
 
@@ -126,15 +129,18 @@
   radar_gfx_sprite=load_gfxfile(minimap_intro_filename);
   tot=radar_gfx_sprite->width;
 
-  y=radar_gfx_sprite->height-(lin+((int)(1.5*main_font_struct->descent)));
+  y = radar_gfx_sprite->height - (lin +
+      1.5 * (exts->max_logical_extent.height + exts->max_logical_extent.y));
 
-  w=XTextWidth(main_font_struct, word_version(), strlen(word_version()));
+  w = XmbTextEscapement(main_font_set, word_version(), strlen(word_version()));
   XSetForeground(display, font_gc, colors_standard[COLOR_STD_BLACK]);
-  XDrawString(display, radar_gfx_sprite->pixmap, font_gc, 
+  XmbDrawString(display, radar_gfx_sprite->pixmap,
+             main_font_set, font_gc, 
              (tot/2-w/2)+1, y+1, 
              word_version(), strlen(word_version()));
   XSetForeground(display, font_gc, colors_standard[COLOR_STD_WHITE]);
-  XDrawString(display, radar_gfx_sprite->pixmap, font_gc, 
+  XmbDrawString(display, radar_gfx_sprite->pixmap,
+             main_font_set, font_gc, 
              tot/2-w/2, y, 
              word_version(), strlen(word_version()));
 
@@ -143,12 +149,14 @@
   my_snprintf(s, sizeof(s), "%d.%d.%d%s",
              MAJOR_VERSION, MINOR_VERSION,
              PATCH_VERSION, VERSION_LABEL);
-  w=XTextWidth(main_font_struct, s, strlen(s));
+  w = XmbTextEscapement(main_font_set, s, strlen(s));
   XSetForeground(display, font_gc, colors_standard[COLOR_STD_BLACK]);
-  XDrawString(display, radar_gfx_sprite->pixmap, font_gc, 
+  XmbDrawString(display, radar_gfx_sprite->pixmap,
+             main_font_set, font_gc, 
              (tot/2-w/2)+1, y+1, s, strlen(s));
   XSetForeground(display, font_gc, colors_standard[COLOR_STD_WHITE]);
-  XDrawString(display, radar_gfx_sprite->pixmap, font_gc, 
+  XmbDrawString(display, radar_gfx_sprite->pixmap,
+             main_font_set, font_gc, 
              tot/2-w/2, y, s, strlen(s));
 
   /* free colors */
Index: client/gui-xaw/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v
retrieving revision 1.96
diff -u -r1.96 gui_main.c
--- client/gui-xaw/gui_main.c   13 Nov 2004 09:26:52 -0000      1.96
+++ client/gui-xaw/gui_main.c   23 Nov 2004 22:37:07 -0000
@@ -175,10 +175,10 @@
 
 /* overall font GC                                    */
 GC font_gc;
-XFontStruct *main_font_struct;
+XFontSet main_font_set;
 /* productions font GC                                */
 GC prod_font_gc;
-XFontStruct *prod_font_struct;
+XFontSet prod_font_set;
 
 Widget toplevel, main_form, menu_form, below_menu_form, left_column_form;
 Widget bottom_form;
@@ -276,7 +276,7 @@
   parse_options(argc, argv);
 
   /* include later - pain to see the warning at every run */
-  /* XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL); */
+  XtSetLanguageProc(NULL, NULL, NULL);
   
   toplevel = XtVaAppInitialize(
               &app_context,               /* Application context */
@@ -342,32 +342,55 @@
 
   {
     XGCValues values;
+    char **missing_charset_list_return;
+    int missing_charset_count_return;
+    char *def_string_return;
 
     values.graphics_exposures = False;
     civ_gc = XCreateGC(display, root_window, GCGraphicsExposures, &values);
 
-    main_font_struct=XLoadQueryFont(display, city_names_font);
-    if(main_font_struct==0) {
-      freelog(LOG_FATAL, _("Failed loading font: %s"), city_names_font);
+    free(city_names_font);
+    city_names_font = mystrdup("-*-*-*-*-*--14-*");
+
+    free(city_productions_font_name);
+    city_productions_font_name = mystrdup("-*-*-*-*-*--14-*");
+
+    main_font_set = XCreateFontSet(display, city_names_font,
+       &missing_charset_list_return,
+       &missing_charset_count_return,
+       &def_string_return);
+    if(!main_font_set) {
+      freelog(LOG_FATAL, _("Unable to open fontset: %s"),
+         city_names_font);
       exit(EXIT_FAILURE);
     }
+    for(i = 0; i < missing_charset_count_return; i++) {
+      freelog(LOG_ERROR, _("Font for charset %s is lacking"),
+         missing_charset_list_return[i]);
+    }
     values.foreground = colors_standard[COLOR_STD_WHITE];
     values.background = colors_standard[COLOR_STD_BLACK];
-    values.font = main_font_struct->fid;
     font_gc= XCreateGC(display, root_window, 
-                      GCForeground|GCBackground|GCFont|GCGraphicsExposures, 
+                      GCForeground|GCBackground|GCGraphicsExposures, 
                       &values);
 
-    prod_font_struct=XLoadQueryFont(display, city_productions_font_name);
-    if(prod_font_struct==0) {
-      freelog(LOG_FATAL, _("Failed loading font: %s"), 
city_productions_font_name);
+    prod_font_set = XCreateFontSet(display, city_productions_font_name,
+       &missing_charset_list_return,
+       &missing_charset_count_return,
+       &def_string_return);
+    if(!prod_font_set) {
+      freelog(LOG_FATAL, _("Unable to open fontset: %s"),
+         city_productions_font_name);
       exit(EXIT_FAILURE);
     }
+    for(i = 0; i < missing_charset_count_return; i++) {
+      freelog(LOG_ERROR, _("Font for charset %s is lacking"),
+         missing_charset_list_return[i]);
+    }
     values.foreground = colors_standard[COLOR_STD_WHITE];
     values.background = colors_standard[COLOR_STD_BLACK];
-    values.font = prod_font_struct->fid;
     prod_font_gc= XCreateGC(display, root_window,
-                           
GCForeground|GCBackground|GCFont|GCGraphicsExposures,
+                           GCForeground|GCBackground|GCGraphicsExposures,
                            &values);
 
     values.line_width = BORDER_WIDTH;
Index: client/gui-xaw/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.h,v
retrieving revision 1.14
diff -u -r1.14 gui_main.h
--- client/gui-xaw/gui_main.h   8 Mar 2004 02:24:35 -0000       1.14
+++ client/gui-xaw/gui_main.h   23 Nov 2004 22:37:07 -0000
@@ -56,8 +56,8 @@
 extern Window       root_window;
 extern Widget       inputline_text;
 extern Widget       outputwindow_text;
-extern XFontStruct *main_font_struct;
-extern XFontStruct *prod_font_struct;
+extern XFontSet     main_font_set;
+extern XFontSet     prod_font_set;
 extern XtAppContext app_context;
 
 #endif  /* FC__GUI_MAIN_H */
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.185
diff -u -r1.185 mapview.c
--- client/gui-xaw/mapview.c    17 Nov 2004 19:26:50 -0000      1.185
+++ client/gui-xaw/mapview.c    23 Nov 2004 22:37:08 -0000
@@ -667,20 +667,22 @@
 Draw at x = left of string, y = top of string.
 **************************************************************************/
 static void draw_shadowed_string(struct canvas *pcanvas,
-                                XFontStruct * font, GC font_gc,
+                                XFontSet fontset, GC font_gc,
                                 enum color_std foreground,
                                 enum color_std shadow,
                                 int x, int y, const char *string)
 {
   size_t len = strlen(string);
 
-  y += font->ascent;
+  y -= XExtentsOfFontSet(fontset)->max_logical_extent.y;
 
   XSetForeground(display, font_gc, colors_standard[shadow]);
-  XDrawString(display, pcanvas->pixmap, font_gc, x + 1, y + 1, string, len);
+  XmbDrawString(display, pcanvas->pixmap, fontset, font_gc,
+      x + 1, y + 1, string, len);
 
   XSetForeground(display, font_gc, colors_standard[foreground]);
-  XDrawString(display, pcanvas->pixmap, font_gc, x, y, string, len);
+  XmbDrawString(display, pcanvas->pixmap, fontset, font_gc,
+      x, y, string, len);
 }
 
 /****************************************************************************
@@ -701,6 +703,8 @@
   char buffer[512], buffer2[512];
   enum color_std color;
   int w, w2;
+  XFontSetExtents *main_exts = XExtentsOfFontSet(main_font_set);
+  XFontSetExtents *prod_exts = XExtentsOfFontSet(prod_font_set);
 
   canvas_x += NORMAL_TILE_WIDTH / 2;
   canvas_y += NORMAL_TILE_HEIGHT;
@@ -708,41 +712,41 @@
   get_city_mapview_name_and_growth(pcity, buffer, sizeof(buffer),
                                   buffer2, sizeof(buffer2), &color);
 
-  w = XTextWidth(main_font_struct, buffer, strlen(buffer));
+  w = XmbTextEscapement(main_font_set, buffer, strlen(buffer));
   if (buffer2[0] != '\0') {
     /* HACK: put a character's worth of space between the two strings. */
-    w += XTextWidth(main_font_struct, "M", 1);
+    w += XmbTextEscapement(main_font_set, "M", 1);
   }
-  w2 = XTextWidth(main_font_struct, buffer2, strlen(buffer2));
+  w2 = XmbTextEscapement(main_font_set, buffer2, strlen(buffer2));
 
-  draw_shadowed_string(pcanvas, main_font_struct, font_gc,
+  draw_shadowed_string(pcanvas, main_font_set, font_gc,
                       COLOR_STD_WHITE, COLOR_STD_BLACK,
                       canvas_x - (w + w2) / 2,
                       canvas_y, buffer);
 
-  draw_shadowed_string(pcanvas, prod_font_struct, prod_font_gc, color,
+  draw_shadowed_string(pcanvas, prod_font_set, prod_font_gc, color,
                       COLOR_STD_BLACK,
                       canvas_x - (w + w2) / 2 + w,
                       canvas_y, buffer2);
 
   *width = w + w2;
-  *height = main_font_struct->ascent + main_font_struct->descent;
+  *height = main_exts->max_logical_extent.height;
 
   if (draw_city_productions && (pcity->owner == game.player_idx)) {
     if (draw_city_names) {
-      canvas_y += main_font_struct->ascent + main_font_struct->descent;
+      canvas_y += main_exts->max_logical_extent.height;
     }
 
     get_city_mapview_production(pcity, buffer, sizeof(buffer));
-    w = XTextWidth(prod_font_struct, buffer, strlen(buffer));
+    w = XmbTextEscapement(prod_font_set, buffer, strlen(buffer));
 
-    draw_shadowed_string(pcanvas, prod_font_struct, prod_font_gc,
+    draw_shadowed_string(pcanvas, prod_font_set, prod_font_gc,
                         COLOR_STD_WHITE, COLOR_STD_BLACK,
                         canvas_x - w / 2,
                         canvas_y, buffer);
 
     *width = MAX(*width, w);
-    *height += prod_font_struct->ascent + prod_font_struct->descent;
+    *height += prod_exts->max_logical_extent.height;
   }
 }
 
Index: data/Freeciv.in
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/Freeciv.in,v
retrieving revision 1.3
diff -u -r1.3 Freeciv.in
--- data/Freeciv.in     7 Nov 2004 22:36:17 -0000       1.3
+++ data/Freeciv.in     23 Nov 2004 22:37:09 -0000
@@ -14,6 +14,9 @@
 !Freeciv*server:                              localhost
 !Freeciv*metaserver:                          
http://meta.freeciv.org/metaserver/
 
+Freeciv*international: True
+Freeciv*fontSet: -*-*-*-*-*--14-*
+
 !
 ! Default colors, by widget type
 !
@@ -1572,7 +1575,7 @@
 
 Freeciv*reportcitylistlabel.justify:            left
 Freeciv*reportcitylistlabel.width:              600
-Freeciv*reportcitylistlabel.font:               6x13
+!Freeciv*reportcitylistlabel.font:              6x13
 Freeciv*reportcitylistlabel.borderWidth:        1
 Freeciv*reportcitylistlabel.resizable:          True
 Freeciv*reportcitylistlabel.top:                chainTop
@@ -1596,7 +1599,7 @@
 Freeciv*reportcityviewport.right:               chainRight
 Freeciv*reportcityviewport.fromVert:            reportcitylistlabel
 
-Freeciv*reportcitylist.font:                6x13
+!Freeciv*reportcitylist.font:               6x13
 Freeciv*reportcitylist.forceColumns:        true
 Freeciv*reportcitylist.defaultColumns:      1
 Freeciv*reportcitylist.verticalList:        true

[Prev in Thread] Current Thread [Next in Thread]