ratpoison-devel
[Top][All Lists]
Advanced

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

[RP] i18n patch(using XFontSet)


From: rubikitch
Subject: [RP] i18n patch(using XFontSet)
Date: Tue Jun 1 14:30:01 2004

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.

This patch uses XFontSet instead of XFontStruct. This enables us to draw
multi-byte characters. Remember to deffont in .ratpoisonrc.
e.x.
deffont -paw-fixed-medium-r-normal--16-150-75-75-c-*-*-*

This patch is for ratpoison-1.3.0-rc2-beta1.
It is also available at
http://www.rubyist.net/~rubikitch/computer/ratpoison/i18n.patch

Regards,
--
rubikitch

Diffs between 1.1 and current workfile(s):

--- actions.c   2004/05/21 18:53:09     1.1
+++ actions.c   2004/05/22 12:36:34
@@ -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);
--- bar.c       2004/05/21 18:53:09     1.1
+++ bar.c       2004/05/22 12:30:54
@@ -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);
 
--- input.c     2004/05/21 18:53:09     1.1
+++ input.c     2004/05/22 12:30:54
@@ -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);
 
--- main.c      2004/05/21 18:53:09     1.1
+++ main.c      2004/05/22 15:39:33
@@ -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;
+}
--- manage.c    2004/05/21 18:53:09     1.1
+++ manage.c    2004/05/22 15:36:17
@@ -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));
 
--- ratpoison.h 2004/05/21 18:53:09     1.1
+++ ratpoison.h 2004/05/22 12:38:47
@@ -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 */
--- screen.c    2004/05/21 18:53:09     1.1
+++ screen.c    2004/05/22 12:36:34
@@ -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. */
--- split.c     2004/05/21 18:53:09     1.1
+++ split.c     2004/05/22 12:30:54
@@ -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));
 }
 

End of diffs.



reply via email to

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