Bug#531036: Working patch for #531036 (ratmenu: doesn't support multibyte/UTF-8 characters)

2010-03-17 Thread Axel Beckert
tags 531036 + patch
kthxbye

Hi,

while the ratmen UTF-8 patch doesn't apply using patch, it does apply
quite well manually.

Here's a new, applying and working patch including changelog entries,
etc. To ease the upgrade for me from this version to the one hopefully
you will release soon, I gave my version the number 2.3.19+utf8 while
I do expect the next version to be 2.3.20:

diff -ru ratmenu-2.3.19/debian/changelog ratmenu-2.3.19+utf8/debian/changelog
--- ratmenu-2.3.19/debian/changelog 2009-12-03 08:27:55.0 +0100
+++ ratmenu-2.3.19+utf8/debian/changelog2010-03-17 22:46:13.0 
+0100
@@ -1,3 +1,12 @@
+ratmenu (2.3.19+utf8) unstable; urgency=low
+
+  [Axel Beckert]
+  * Port UTF-8 patch for ratmen
+(http://www.rubyist.net/~rubikitch/computer/ratmen/i18n.patch) to
+ratmenu.
+
+ -- Axel Beckert   Wed, 17 Mar 2010 22:45:00 +0100
+
 ratmenu (2.3.19) unstable; urgency=low
 
   * debian/control: version debhelper depends (lintian
diff -ru ratmenu-2.3.19/ratmenu.c ratmenu-2.3.19+utf8/ratmenu.c
--- ratmenu-2.3.19/ratmenu.c2008-09-28 03:44:52.0 +0200
+++ ratmenu-2.3.19+utf8/ratmenu.c   2010-03-17 22:38:02.0 +0100
@@ -67,12 +67,16 @@
 #include 
 #include 
 #include 
+#include 
 
 char version[] = "@(#) ratmenu version 2.3";
 
 #define FONT "9x15bold"
 #defineMenuMask (ExposureMask|StructureNotifyMask|KeyPressMask)
 #define CTL(c) (c - '`')
+#define XTextWidth XmbTextEscapement
+#define XLoadQueryFont XLoadQueryFontSet
+XFontSet XLoadQueryFontSet(Display *, const char *);
 
 Display *dpy;  /* lovely X stuff */
 int screen;
@@ -85,7 +89,8 @@
 char *bgcname = NULL;
 Colormap dcmap;
 XColor color;
-XFontStruct *font;
+XFontSet font;
+short font__ascent, font__descent;
 Atom wm_protocols;
 Atom wm_delete_window;
 int g_argc;/* for XSetWMProperties to use */
@@ -125,6 +130,24 @@
 void xresources(void);
 void defaults(void);
 
+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 /* && debug */) {
+fprintf(stderr, "Missing charsets in FontSet(%s) creation.\n", 
fontset_name);
+XFreeStringList(missing_charset_list);
+  }
+  return fontset;
+}
+
+
 /* main --- crack arguments, set up X stuff, run the main menu loop */
 
 int
@@ -134,10 +157,13 @@
char *cp;
XGCValues gv;
unsigned long mask;
+   XFontSetExtents *extent;
 
g_argc = argc;
g_argv = argv;
 
+   setlocale(LC_CTYPE, "");
+
/* set default label name */
if ((cp = strrchr(argv[0], '/')) == NULL)
labelname = argv[0];
@@ -235,13 +261,15 @@
fprintf(stderr, "%s: fatal: cannot load font %s\n", progname, 
fontname);
exit(1);
}
+   extent = XExtentsOfFontSet(font);
+   font__ascent = extent->max_logical_extent.height * 4 / 5;
+   font__descent = extent->max_logical_extent.height / 5;
 
gv.foreground = fg^bg;
gv.background = bg;
-   gv.font = font->fid;
gv.function = GXxor;
gv.line_width = 0;
-   mask = GCForeground | GCBackground | GCFunction | GCFont | GCLineWidth;
+   mask = GCForeground | GCBackground | GCFunction | GCLineWidth;
 
root = RootWindow(dpy, screen);
gc = XCreateGC(dpy, root, mask, &gv);
@@ -313,7 +341,7 @@
}
wide = dx;
 
-   high = font->ascent + font->descent + 1;
+   high = font__ascent + font__descent + 1;
visible = dpyheight / high;
if (visible > numitems) { visible = numitems; }
dy = visible * high;
@@ -501,8 +529,8 @@
} else {/* align == right */
tx = wide - XTextWidth(font, labels[j], 
strlen(labels[j]));
}
-ty = i*high + font->ascent + 1;
-XDrawString(dpy, menuwin, gc, tx, ty, labels[j], 
strlen(labels[j]));
+ty = i*high + font__ascent + 1;
+XmbDrawString(dpy, menuwin, font, gc, tx, ty, labels[j], 
strlen(labels[j]));
}
XFillRectangle(dpy, menuwin, gc, 0, 0, wide, high); 
 }
@@ -528,8 +556,8 @@
} else {/* align == right */
tx = wide - XTextWidth(font, labels[i+off], 
strlen(labels[i+off]));
}
-   ty = i*high + font->ascent + 1;
-   XDrawString(dpy, menuwin, gc, tx, ty, labels[i+off], 
strlen(labels[i+off]));
+   ty = i*high + font__ascent + 1;
+   XmbDrawString(dpy, menuwin, font, gc, tx, ty, 
labels[i+off], strlen(labels[i+off]));
}
XFillRectangle(dpy, menuwin, gc, 0, (curitem-

Bug#531036: Working patch for #531036 (ratmenu: doesn't support multibyte/UTF-8 characters)

2010-03-17 Thread Mark Eichin
Appreciate the effort... except the resulting ratmenu doesn't actually
display those characters, against a Karmic X server (where the uxterm
example works fine.) XmbTextEscapement returns zero for the non-ASCII
string, even though def_string is empty and missing_charset_count is
zero...

I haven't dug into the relevant X sources yet, but offhand, is there
any locale, environment, or xrdb settings needed to demonstrate this?
(uxterm does display the characters for me in the example...)



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Bug#531036: Working patch for #531036 (ratmenu: doesn't support multibyte/UTF-8 characters)

2010-03-18 Thread Axel Beckert
Hi Mark,

Mark Eichin wrote:
> Appreciate the effort... except the resulting ratmenu doesn't actually
> display those characters, against a Karmic X server (where the uxterm
> example works fine.) XmbTextEscapement returns zero for the non-ASCII
> string, even though def_string is empty and missing_charset_count is
> zero...

Hrm, interesting.

> I haven't dug into the relevant X sources yet, but offhand, is there
> any locale, environment, or xrdb settings needed to demonstrate this?
> (uxterm does display the characters for me in the example...)

Did some more testing on different boxes. At least I have also some
corner case where it seems to fall back to a ISO8859-1 charset, but I
haven't found out yet why, just guesses.

Cases where it works fine for me:

* Locally on my EeePC running Sid i386 and only few selected fonts
  installed. This is where I use it primarily.
* Remotely from my EeePC running Sid i386 and only few fonts installed
  to my ThinkPad running Lenny amd64 and quite some fonts installed
* Locally on my ThinkPad running Lenny amd64 and quite some fonts
  installed.
* Remotely from my EeeBox running Sid kfreebsd-i386 and tons of fonts
  installed to my ThinkPad running Lenny amd64 and quite some fonts
  installed.

Where it does not work for me:

* Remotely from a Xen DomU running Sid amd64 and IIRC nearly no fonts
  installed to my workstation running Lenny amd64 and quite some fonts
  installed.
* Remotely from a Xen DomU running Sid amd64 and IIRC nearly no fonts
  installed to my ThinkPad running Lenny amd64 and quite some fonts
  installed.

At least in the last combination, opening a remote uxterm and then
letting echo those characters works, too, though.

So I can only reproduce the non-functioning remotely on a virtual
machine which doesn't have a local X.

My current guess: There are some fonts on the Xen DomU missing (and
uxterm is maybe able to use remote fonts from the Lenny boxes). Since
it works fine on my 64-bit Thinkpad with Lenny, I don't expect a
64-bit issue.

Nevertheless: Is your Karmic 64-bit?

Will test it on some more boxes during the next days to get some more
samples for better guessing in which cases it works and in which not.
Plan: Test it with one karmic test box at work and with Xnest or
Xephyr on the Sid amd64 Xen DomU where it is currently not working for
me, to have a local display I can display remotely. Install some more
fonts on the Sid amd64 Xen DomU.

Regards, Axel
-- 
 ,''`.  |  Axel Beckert , http://people.debian.org/~abe/
: :' :  |  Debian Developer, ftp.ch.debian.org Admin
`. `'   |  1024D: F067 EA27 26B9 C3FC 1486  202E C09E 1D89 9593 0EDE
  `-|  4096R: 2517 B724 C5F6 CA99 5329  6E61 2FF9 CD59 6126 16B5



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Bug#531036: 2nd re: Bug#531036: Working patch for #531036 (ratmenu: doesn't support multibyte/UTF-8 characters)

2010-03-18 Thread Mark Eichin
Explicitly setting LANG=en_US.UTF-8 helped, and installing more
fonts (xfonts-terminus in particular) improved things further (didn't
work by itself, $LANG really is critical to Xmb* working, it appears.)

Now that I can actually demonstrate it, I'm happy to push the change
out, should show up soon.



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Bug#531036: 2nd re: Bug#531036: Working patch for #531036 (ratmenu: doesn't support multibyte/UTF-8 characters)

2010-03-18 Thread Axel Beckert
On Thu, Mar 18, 2010 at 12:46:18AM -0400, Mark Eichin wrote:
> I haven't dug into the relevant X sources yet, but offhand, is there
> any locale, environment, or xrdb settings needed to demonstrate this?
> (uxterm does display the characters for me in the example...)

Forgot to answer that question:


I'm sure xrdb doesn't have an incfluence here. But locale/environment
was the right guess, although different than I have expected (ssh doesn't
seem to pass the $LANG environment variable by default:

All those boxes have LANG=en_US.UTF-8, except the Sid amd64 Xen DomU
which still has LANG=en_US.ISO-8859-15. (Should change that. :-)

If I set LANG=en_US.UTF-8 there, too, it works remotely from there, too:

env LANG=en_US.UTF-8 ratmenu -font 
'-misc-fixed-medium-r-*-*-13-*-*-*-*-60-iso10646-1' `perl -le 'print map chr, 
226, 152, 186, 226, 134, 146'` 'echo bla'

So now I have no more case where it doesn't work. ;-)

Can you check your environment?

Regards, Axel
-- 
Axel Beckert - a...@deuxchevaux.org, a...@noone.org - http://noone.org/abe/



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org