ratpoison-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RP] i18n patch(using XFontSet)


From: rubikitch
Subject: Re: [RP] i18n patch(using XFontSet)
Date: Thu Jun 3 06:07:17 2004

From: rubikitch <address@hidden>
Subject: [RP] i18n patch(using XFontSet)
Date: Wed, 02 Jun 2004 06:29:06 +0900 (JST)

> Hi, I wrote ratpoison-i18n patch.
> Ratpoison uses XFontStruct though Xlib supports i18n feature.
> So ratpoison cannot draw multi-byte characters including Chines,
> Japanese, and Korean. I'm Japanese and Japanese window title is often used,
> but ratpoison draw unreadable string.
The previous one does not work, sorry. Try this one.

Regards,
--
rubikitch

diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/actions.c 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/actions.c
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/actions.c        2004-04-19 
06:22:08.000000000 +0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/actions.c     
2004-05-22 21:36:34.000000000 +0900
@@ -1883,7 +1883,7 @@
   for(i=0; license_text[i]; i++)
   {
     XDrawString (dpy, s->help_window, s->normal_gc,
-                x, y + defaults.font->max_bounds.ascent,
+                x, y + font_ascent,
                 license_text[i], strlen (license_text[i]));
 
     y += FONT_HEIGHT (defaults.font);
@@ -1938,19 +1938,19 @@
       XGrabKeyboard (dpy, s->help_window, False, GrabModeSync, GrabModeAsync, 
CurrentTime);
 
       XDrawString (dpy, s->help_window, s->normal_gc,
-                   10, y + defaults.font->max_bounds.ascent,
+                   10, y + font_ascent,
                    "ratpoison key bindings", strlen ("ratpoison key 
bindings"));
 
       y += FONT_HEIGHT (defaults.font) * 2;
 
       XDrawString (dpy, s->help_window, s->normal_gc,
-                   10, y + defaults.font->max_bounds.ascent,
+                   10, y + font_ascent,
                    "Command key: ", strlen ("Command key: "));
 
       keysym_name = keysym_to_string (prefix_key.sym, prefix_key.state);
       XDrawString (dpy, s->help_window, s->normal_gc,
                    10 + XTextWidth (defaults.font, "Command key: ", strlen 
("Command key: ")),
-                   y + defaults.font->max_bounds.ascent,
+                   y + font_ascent,
                    keysym_name, strlen (keysym_name));
       free (keysym_name);
 
@@ -1965,7 +1965,7 @@
              keysym_name = keysym_to_string (map->actions[i].key, 
map->actions[i].state);
 
              XDrawString (dpy, s->help_window, s->normal_gc,
-                          x, y + defaults.font->max_bounds.ascent,
+                          x, y + font_ascent,
                           keysym_name, strlen (keysym_name));
 
              if (XTextWidth (defaults.font, keysym_name, strlen (keysym_name)) 
> max_width)
@@ -1976,7 +1976,7 @@
          else
            {
              XDrawString (dpy, s->help_window, s->normal_gc,
-                          x, y + defaults.font->max_bounds.ascent,
+                          x, y + font_ascent,
                           map->actions[i].data, strlen (map->actions[i].data));
 
              if (XTextWidth (defaults.font, map->actions[i].data, strlen 
(map->actions[i].data)) > max_width)
@@ -2296,12 +2296,11 @@
   gv.function = GXcopy;
   gv.line_width = 1;
   gv.subwindow_mode = IncludeInferiors;
-  gv.font = defaults.font->fid;
   XFreeGC (dpy, s->normal_gc);
   s->normal_gc = XCreateGC(dpy, s->root, 
                           GCForeground | GCBackground 
                           | GCFunction | GCLineWidth
-                          | GCSubwindowMode | GCFont, &gv);
+                          | GCSubwindowMode, &gv);
 }
 
 static void
@@ -2319,7 +2318,7 @@
 char *
 cmd_deffont (int interactive, char *data)
 {
-  XFontStruct *font;
+  XFontSet font;
 
   if (data == NULL) return NULL;
 
@@ -2330,6 +2329,7 @@
       return NULL;
     }
 
+  set_extents_of_fontset(font);
   /* Save the font as the default. */
   XFreeFont (dpy, defaults.font);
   defaults.font = font;
@@ -3405,7 +3405,7 @@
              /* Display the frame's number inside the window. */
              XDrawString (dpy, wins[i], s->normal_gc, 
                           defaults.bar_x_padding, 
-                          defaults.bar_y_padding + 
defaults.font->max_bounds.ascent,
+                          defaults.bar_y_padding + font_ascent,
                           num, strlen (num));
 
              free (num);
diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/bar.c 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/bar.c
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/bar.c    2004-02-27 16:29:37.000000000 
+0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/bar.c 2004-05-22 
21:30:54.000000000 +0900
@@ -316,7 +316,7 @@
        {
          XDrawString (dpy, s->bar_window, s->normal_gc,
                       defaults.bar_x_padding,
-                      defaults.bar_y_padding + defaults.font->max_bounds.ascent
+                      defaults.bar_y_padding + font_ascent
                       +  line_no * line_height,
                       msg + start, i - start);
          line_no++;
@@ -327,7 +327,7 @@
   /* Print the last line. */
   XDrawString (dpy, s->bar_window, s->normal_gc,
               defaults.bar_x_padding,
-              defaults.bar_y_padding + defaults.font->max_bounds.ascent
+              defaults.bar_y_padding + font_ascent
               +  line_no * line_height,
               msg + start, strlen (msg) - start);
 
diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/data.h 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/data.h
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/data.h   2004-04-04 15:12:11.000000000 
+0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/data.h        
2004-05-22 16:09:55.000000000 +0900
@@ -212,7 +212,7 @@
   int padding_top;
   int padding_bottom;
 
-  XFontStruct *font;
+  XFontSet font;
 
   int wait_for_key_cursor;
 
diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/globals.c 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/globals.c
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/globals.c        2004-04-19 
06:32:56.000000000 +0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/globals.c     
2004-05-22 21:51:18.000000000 +0900
@@ -28,6 +28,8 @@
 int rat_y;
 int rat_visible = 1;           /* rat is visible by default */
 
+int font_ascent, font_descent, font_width;
+
 Atom wm_name;
 Atom wm_state;
 Atom wm_change_state;
diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/globals.h 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/globals.h
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/globals.h        2004-04-19 
06:33:04.000000000 +0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/globals.h     
2004-05-22 21:51:18.000000000 +0900
@@ -23,8 +23,8 @@
 
 #include "data.h"
 
-#define FONT_HEIGHT(f) ((f)->max_bounds.ascent + (f)->max_bounds.descent)
-#define MAX_FONT_WIDTH(f) ((f)->max_bounds.width)
+#define FONT_HEIGHT(f) (font_ascent + font_descent)
+#define MAX_FONT_WIDTH(f) (font_width)
 
 #define WIN_EVENTS (StructureNotifyMask | PropertyChangeMask | 
ColormapChangeMask | FocusChangeMask)
 /* EMPTY is used when a frame doesn't contain a window, or a window
@@ -63,6 +63,8 @@
 
 extern struct rp_defaults defaults;
 
+extern int font_ascent, font_descent, font_width;
+
 /* The prefix key also known as the command character under screen. */
 extern struct rp_key prefix_key;
 
diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/input.c 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/input.c
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/input.c  2004-04-19 05:49:34.000000000 
+0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/input.c       
2004-05-22 21:30:54.000000000 +0900
@@ -304,13 +304,13 @@
 
   XDrawString (dpy, s->input_window, s->normal_gc, 
               defaults.bar_x_padding, 
-              defaults.bar_y_padding + defaults.font->max_bounds.ascent,
+              defaults.bar_y_padding + font_ascent,
               line->prompt, 
               strlen (line->prompt));
  
   XDrawString (dpy, s->input_window, s->normal_gc, 
               defaults.bar_x_padding + prompt_width,
-              defaults.bar_y_padding + defaults.font->max_bounds.ascent,
+              defaults.bar_y_padding + font_ascent,
               line->buffer, 
               line->length);
 
diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/main.c 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/main.c
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/main.c   2004-04-04 15:31:19.000000000 
+0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/main.c        
2004-05-23 00:39:33.000000000 +0900
@@ -454,6 +454,17 @@
   free (prefix);
 }
 
+void
+set_extents_of_fontset(XFontSet font)
+{
+  XFontSetExtents *extent;
+  extent = XExtentsOfFontSet(font);
+  font_ascent = extent->max_logical_extent.height * 9 / 10;
+  font_descent = extent->max_logical_extent.height / 5;
+  font_width = extent->max_logical_extent.width;
+}
+
+
 static void
 init_defaults ()
 {
@@ -483,6 +494,7 @@
       fprintf (stderr, "ratpoison: Cannot load font %s.\n", "9x15bold");
       exit (EXIT_FAILURE);
     }
+  set_extents_of_fontset(defaults.font);
 
   defaults.wait_for_key_cursor = 1;
 
@@ -511,7 +523,7 @@
   char *alt_rcfile = NULL;
 
   myargv = argv;
-
+  setlocale(LC_CTYPE, "");
   /* Parse the arguments */
   while (1)
     {
@@ -712,3 +724,21 @@
   XCloseDisplay (dpy);
 }
 
+XFontSet XLoadQueryFontSet(Display *disp, const char *fontset_name)
+{
+  XFontSet fontset;
+  int  missing_charset_count;
+  char **missing_charset_list;
+  char *def_string;
+
+  fontset = XCreateFontSet(disp, fontset_name,
+                           &missing_charset_list, &missing_charset_count,
+                           &def_string);
+  if (missing_charset_count) {
+#if 0
+    fprintf(stderr, "Missing charsets in FontSet(%s) creation.\n", 
fontset_name);
+#endif
+    XFreeStringList(missing_charset_list);
+  }
+  return fontset;
+}
diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/manage.c 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/manage.c
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/manage.c 2004-04-19 06:11:19.000000000 
+0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/manage.c      
2004-05-23 00:36:17.000000000 +0900
@@ -213,33 +213,29 @@
 static char *
 get_wmname (Window w)
 {
-  Atom actual_type;
-  int actual_format;
-  int status;
-  unsigned long n;
-  unsigned long bytes_after;
   unsigned char *name = NULL;
   char *ret;
-
-  status = XGetWindowProperty (dpy, w, wm_name, 0L, 100L, False, 
-                              XA_STRING, &actual_type, &actual_format, 
-                              &n, &bytes_after, &name);
-
-  PRINT_DEBUG (("XGetWindowProperty: %d %ld %d %ld %ld '%s'\n", status, 
actual_type, 
-               actual_format, n, bytes_after, name));
-
-  if (status != Success || name == NULL)
-    {
-      PRINT_DEBUG (("I can't get the WMName.\n"));
-      return NULL;
-    }
-
-  if (n == 0)
-    {
-      PRINT_DEBUG (("I can't get the WMName.\n"));
-      XFree (name);
-      return NULL;
-    }
+  XTextProperty text_prop;
+  int n;
+  char** cl;
+
+  if (XGetWMName(dpy, w, &text_prop) != 0) {
+    if (text_prop.encoding == XA_STRING) {
+      name = (char *)text_prop.value;
+    } else {
+      XmbTextPropertyToTextList(dpy, &text_prop, &cl, &n);
+      if (cl) {
+        name = strdup(cl[0]);
+        XFreeStringList(cl);
+      } else {
+        PRINT_DEBUG (("I can't get the WMName.\n"));
+        return NULL;
+      }
+    }
+  } else {
+    PRINT_DEBUG (("I can't get the WMName.\n"));
+    return NULL;
+  }
 
   PRINT_DEBUG (("WM_NAME: '%s'\n", name));
 
diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/ratpoison.h 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/ratpoison.h
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/ratpoison.h      2004-02-27 
16:29:37.000000000 +0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/ratpoison.h   
2004-05-22 21:38:47.000000000 +0900
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <X11/Xlib.h>
+#include <X11/Xlocale.h>
 #include <fcntl.h>
 
 /* Some systems don't define the close-on-exec flag in fcntl.h */
@@ -100,4 +101,11 @@
 char *xvsprintf (char *fmt, va_list ap);
 int str_comp (char *s1, char *s2, int len);
 
+#define XLoadQueryFont XLoadQueryFontSet
+XFontSet XLoadQueryFontSet(Display *, const char *);
+#define XFreeFont XFreeFontSet
+void set_extents_of_fontset (XFontSet font);
+#define XTextWidth XmbTextEscapement
+#define XDrawString(d,w,gc,x,y,s,l)  
XmbDrawString(d,w,defaults.font,gc,x,y,s,l)
+
 #endif /* ! _RATPOISON_H */
diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/screen.c 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/screen.c
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/screen.c 2004-02-27 18:25:24.000000000 
+0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/screen.c      
2004-05-22 21:36:34.000000000 +0900
@@ -276,10 +276,9 @@
   gv.function = GXcopy;
   gv.line_width = 1;
   gv.subwindow_mode = IncludeInferiors;
-  gv.font = defaults.font->fid;
   s->normal_gc = XCreateGC(dpy, s->root, 
                           GCForeground | GCBackground | GCFunction 
-                          | GCLineWidth | GCSubwindowMode | GCFont, 
+                          | GCLineWidth | GCSubwindowMode, 
                           &gv);
 
   /* Create the program bar window. */
diff -u /tmp/ratpoison-1.3.0-rc2-beta1/src/split.c 
/home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/split.c
--- /tmp/ratpoison-1.3.0-rc2-beta1/src/split.c  2004-02-27 18:29:36.000000000 
+0900
+++ /home/rubikitch/compile/ratpoison-1.3.0-rc2-beta1/src/split.c       
2004-05-22 21:30:54.000000000 +0900
@@ -942,7 +942,7 @@
 
   XDrawString (dpy, s->frame_window, s->normal_gc,
               defaults.bar_x_padding,
-              defaults.bar_y_padding + defaults.font->max_bounds.ascent,
+              defaults.bar_y_padding + font_ascent,
               msg, strlen (msg));
 }
 



reply via email to

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