From 141ce091298a1364e2f6f56f71ad751931120188 Mon Sep 17 00:00:00 2001 From: Karl Ramm Date: Mon, 20 Apr 2009 23:51:04 +0000 Subject: Transliterate to UTF-16 and use XDrawText16. This leaves vast font issues, and selection issues, and bypasses #6 in favor of #33. --- zwgc/X_gram.c | 8 ++++---- zwgc/X_gram.h | 24 +++++++++++++----------- zwgc/xcut.c | 3 +++ zwgc/xshow.c | 21 +++++++++++++++++++-- 4 files changed, 39 insertions(+), 17 deletions(-) (limited to 'zwgc') diff --git a/zwgc/X_gram.c b/zwgc/X_gram.c index e486835..8b5d96a 100644 --- a/zwgc/X_gram.c +++ b/zwgc/X_gram.c @@ -431,7 +431,7 @@ x_gram_draw(Display *dpy, Window w, x_gram *gram, Region region) GC gc; XGCValues gcvals; xblock *xb; - XTextItem text; + XTextItem16 text; int startblock, endblock, startpixel = 0, endpixel = 0; gc = XCreateGC(dpy, w, 0, &gcvals); @@ -502,11 +502,11 @@ x_gram_draw(Display *dpy, Window w, x_gram *gram, Region region) if (XRectInRegion(region, xb->x1, xb->y1, xb->x2 - xb->x1, xb->y2 - xb->y1) != RectangleOut) { SetFG(dpy, gc, gram->bgcolor ^ xb->fgcolor); - text.chars = gram->text + xb->strindex; - text.nchars = xb->strlen; + text.chars = (XChar2b *)xb->wstr; + text.nchars = xb->wlen / 2; text.delta = 0; text.font = xb->fid; - XDrawText(dpy, w, gc, xb->x, xb->y, &text, 1); + XDrawText16(dpy, w, gc, xb->x, xb->y, &text, 1); } } diff --git a/zwgc/X_gram.h b/zwgc/X_gram.h index 62a1567..dfff8f1 100644 --- a/zwgc/X_gram.h +++ b/zwgc/X_gram.h @@ -24,12 +24,14 @@ #include "formatter.h" typedef struct _xblock { - unsigned long fgcolor; - Font fid; - int x,y; - int x1,y1,x2,y2; /* bounds of block. used for cut and paste. */ - int strindex; - int strlen; + unsigned long fgcolor; + Font fid; + int x,y; + int x1,y1,x2,y2; /* bounds of block. used for cut and paste. */ + int strindex; + int strlen; + char *wstr; + int wlen; } xblock; typedef struct _x_gram { @@ -46,11 +48,11 @@ typedef struct _x_gram { } x_gram; typedef struct _xauxblock { - int align; - XFontStruct *font; - char *str; - int len; - int width; + int align; + XFontStruct *font; + char *str; + int len; + int width; } xauxblock; typedef struct _xmode { diff --git a/zwgc/xcut.c b/zwgc/xcut.c index 6345713..b82d9a8 100644 --- a/zwgc/xcut.c +++ b/zwgc/xcut.c @@ -157,6 +157,7 @@ xdestroygram(Display *dpy, x_gram *gram) { struct timeval now; + int i; gettimeofday(&now,NULL); if ((gram->can_die.tv_sec == 0) || @@ -174,6 +175,8 @@ xdestroygram(Display *dpy, XDestroyWindow(dpy, w); delete_gram(gram); free(gram->text); + for (i=0; i < gram->numblocks; i++) + free(gram->blocks[i].wstr); free(gram->blocks); #ifdef CMU_ZWGCPLUS if (gram->notice) diff --git a/zwgc/xshow.c b/zwgc/xshow.c index 720d4c8..3521318 100644 --- a/zwgc/xshow.c +++ b/zwgc/xshow.c @@ -164,8 +164,9 @@ fixup_and_draw(Display *dpy, for (i = 0; i < lines[line].numblock; i++, block++) { chars += auxblocks[block].len; - ssize = XTextWidth(auxblocks[block].font, auxblocks[block].str, - auxblocks[block].len); + ssize = XTextWidth16(auxblocks[block].font, + (XChar2b *)blocks[block].wstr, + blocks[block].wlen / 2); auxblocks[block].width = ssize; ascent = auxblocks[block].font->ascent; descent = auxblocks[block].font->descent; @@ -394,6 +395,8 @@ xshow(Display *dpy, desctype *desc, int numstr, int numnl) char *style; int free_style = 0; int beepcount = 0; + char *notice_charset = var_get_variable("notice_charset"); + int i; lines = (xlinedesc *)malloc(sizeof(xlinedesc) * (numnl + 1)); @@ -508,6 +511,20 @@ xshow(Display *dpy, desctype *desc, int numstr, int numnl) auxblocks[nextblock].font = mode_to_font(dpy, style, &curmode); auxblocks[nextblock].str = desc->str; auxblocks[nextblock].len = desc->len; + i = ZTransliterate(desc->str, desc->len, + strcmp(notice_charset, "UNKNOWN") ? + notice_charset : "ISO-8859-1", + "UTF-16BE", + &blocks[nextblock].wstr, + &blocks[nextblock].wlen); + if (i) { + var_set_variable("error", strerror(i)); + blocks[nextblock].wlen = desc->len * 2; + blocks[nextblock].wstr = malloc(blocks[nextblock].wlen); + for (i = 0; i < desc->len; i++) + *(short *)&(blocks[nextblock].wstr[i * 2]) = htons((short)(unsigned char)desc->str[i]); + /* XXX */ + } if (curmode.expcolor) blocks[nextblock].fgcolor = curmode.color; else -- cgit v1.2.3