--- np2/x11/gtk2/gtk_font.c 2005/02/26 13:32:14 1.3 +++ np2/x11/gtk2/gtk_font.c 2012/01/23 04:54:47 1.9 @@ -1,5 +1,3 @@ -/* $Id: gtk_font.c,v 1.3 2005/02/26 13:32:14 monaka Exp $ */ - /* * Copyright (c) 2004 NONAKA Kimihiro * All rights reserved. @@ -12,8 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -81,8 +77,9 @@ fontmng_create(int size, UINT type, cons gchar *fontname_utf8; int fontalign; int allocsize; - GdkColormap *colormap; + GdkColormap *cmap; GdkColor color; + gboolean rv; if (size < 0) { size = -size; @@ -94,7 +91,7 @@ fontmng_create(int size, UINT type, cons } g_snprintf(buf, sizeof(buf), "%s %s %s %d", - fontface ? (char *)fontface : fontname, + fontface ? (const char *)fontface : fontname, (type & FDAT_BOLD) ? "bold" : "medium", (type & FDAT_PROPORTIONAL) ? "" : "", size); @@ -108,12 +105,13 @@ fontmng_create(int size, UINT type, cons return NULL; } - colormap = gtk_widget_get_colormap(GTK_WIDGET(main_window)); - color.red = color.green = color.blue = 0; - if (gdk_color_alloc(colormap, &color) == 0) { - fnt.black_pixel = 0; - } else { + cmap = gtk_widget_get_colormap(GTK_WIDGET(main_window)); + memset(&color, 0, sizeof(color)); + rv = gdk_colormap_alloc_color(cmap, &color, FALSE, FALSE); + if (rv) { fnt.black_pixel = color.pixel; + } else { + fnt.black_pixel = 0; } fnt.layout = gtk_widget_create_pango_layout(main_window, NULL); @@ -152,7 +150,7 @@ fontmng_destroy(void *hdl) if (fnt) { if (fnt->backsurf) - gdk_pixmap_unref(fnt->backsurf); + g_object_unref(fnt->backsurf); if (fnt->layout) g_object_unref(fnt->layout); if (fnt->desc) @@ -162,11 +160,9 @@ fontmng_destroy(void *hdl) } static void -setfdathead(FNTMNG fhdl, FNTDAT fdat, const gchar *str, int len) +setfdathead(FNTMNG fhdl, FNTDAT fdat, const char *str, int len) { - UNUSED(str); - fdat->width = fhdl->rect.width; fdat->height = fhdl->rect.height; fdat->pitch = fhdl->size; @@ -176,14 +172,14 @@ setfdathead(FNTMNG fhdl, FNTDAT fdat, co } static void -getlength1(FNTMNG fhdl, FNTDAT fdat, const gchar *str, int len) +getlength1(FNTMNG fhdl, FNTDAT fdat, const char *str, int len) { setfdathead(fhdl, fdat, str, len); } static void -getfont1(FNTMNG fhdl, FNTDAT fdat, const gchar *str, int len) +getfont1(FNTMNG fhdl, FNTDAT fdat, const char *str, int len) { GdkImage *img; @@ -212,7 +208,7 @@ getfont1(FNTMNG fhdl, FNTDAT fdat, const p++; } } - gdk_image_destroy(img); + g_object_unref(img); } else { memset(fdat + 1, 0, fdat->width * fdat->height); } @@ -223,32 +219,22 @@ fontmng_getsize(void *hdl, const char *s { FNTMNG fhdl = (FNTMNG)hdl; _FNTDAT fdat; - UINT8 buf[4]; + char buf[4]; int width; int len; - if ((fhdl == NULL) || (str == NULL)) + if ((fhdl == NULL) || (str == NULL)) { return FAILURE; + } width = 0; - buf[2] = '\0'; for (;;) { - buf[0] = *str++; - if ((((buf[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c && *str != '\0') { - buf[1] = *str++; - len = 2; - } else if (buf[0] >= 0xa1 && buf[1] <= 0xdf) { - buf[1] = buf[0]; - buf[0] = 0x8e; - len = 1; - } else if (buf[0]) { - buf[1] = '\0'; - len = 1; - } else { - break; + while ((len = milstr_charsize(str)) != 0) { + memcpy(buf, str, len * sizeof(char)); + buf[len] = '\0'; + getlength1(fhdl, &fdat, buf, len); + width += fdat.pitch; } - getlength1(fhdl, &fdat, buf, len); - width += fdat.pitch; } if (pt) { pt->x = width; @@ -262,35 +248,25 @@ fontmng_getdrawsize(void *hdl, const cha { FNTMNG fhdl = (FNTMNG)hdl; _FNTDAT fdat; - UINT8 buf[4]; + char buf[4]; int width; int len; int posx; - if ((hdl == NULL) || (str == NULL)) + if ((hdl == NULL) || (str == NULL)) { return FAILURE; + } width = 0; posx = 0; - buf[2] = '\0'; for (;;) { - buf[0] = *str++; - if ((((buf[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c && *str != '\0') { - buf[1] = *str++; - len = 2; - } else if (buf[0] >= 0xa1 && buf[0] <= 0xdf) { - buf[1] = buf[0]; - buf[0] = 0x8e; - len = 1; - } else if (buf[0]) { - buf[1] = '\0'; - len = 1; - } else { - break; + while ((len = milstr_charsize(str)) != 0) { + memcpy(buf, str, len * sizeof(char)); + buf[len] = '\0'; + getlength1(fhdl, &fdat, buf, len); + width = posx + max(fdat.width, fdat.pitch); + posx += fdat.pitch; } - getlength1(fhdl, &fdat, buf, len); - width = posx + max(fdat.width, fdat.pitch); - posx += fdat.pitch; } if (pt) { pt->x = width; @@ -304,7 +280,7 @@ fontmng_get(void *hdl, const char *str) { FNTMNG fhdl = (FNTMNG)hdl; FNTDAT fdat = (FNTDAT)(fhdl + 1); - UINT8 buf[4]; + char buf[4]; gchar *utf8; int len; @@ -312,24 +288,15 @@ fontmng_get(void *hdl, const char *str) return NULL; } - if (((((str[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c) && (str[1] != '\0')) { - codecnv_sjistoeuc(buf, 4, str, 2); - len = 2; - } else if ((UINT8)str[0] >= 0xa1 && (UINT8)str[0] <= 0xdf) { - buf[0] = 0x8e; - buf[1] = str[0]; - buf[2] = '\0'; - len = 1; - } else { - buf[0] = str[0]; - buf[1] = '\0'; - len = 1; - } - utf8 = g_locale_to_utf8(buf, -1, NULL, NULL, NULL); - if (utf8) { - getfont1(fhdl, fdat, utf8, len); - g_free(utf8); - return fdat; + while ((len = milstr_charsize(str)) != 0) { + memcpy(buf, str, len * sizeof(char)); + buf[len] = '\0'; + utf8 = g_locale_to_utf8(buf, -1, NULL, NULL, NULL); + if (utf8) { + getfont1(fhdl, fdat, utf8, len); + g_free(utf8); + } + str += len; } - return NULL; + return fdat; }