| version 1.3, 2005/02/26 13:32:14 | version 1.8, 2011/01/15 18:43:13 | 
| Line 1 | Line 1 | 
 | /*      $Id$    */ |  | 
 |  |  | 
 | /* | /* | 
 | * Copyright (c) 2004 NONAKA Kimihiro | * Copyright (c) 2004 NONAKA Kimihiro | 
 | * All rights reserved. | * All rights reserved. | 
| Line 12 | Line 10 | 
 | * 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | 
 | *    notice, this list of conditions and the following disclaimer in the | *    notice, this list of conditions and the following disclaimer in the | 
 | *    documentation and/or other materials provided with the distribution. | *    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 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 
 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
| Line 81  fontmng_create(int size, UINT type, cons | Line 77  fontmng_create(int size, UINT type, cons | 
 | gchar *fontname_utf8; | gchar *fontname_utf8; | 
 | int fontalign; | int fontalign; | 
 | int allocsize; | int allocsize; | 
| GdkColormap *colormap; | GdkColormap *cmap; | 
 | GdkColor color; | GdkColor color; | 
 |  | gboolean rv; | 
 |  |  | 
 | if (size < 0) { | if (size < 0) { | 
 | size = -size; | size = -size; | 
| Line 108  fontmng_create(int size, UINT type, cons | Line 105  fontmng_create(int size, UINT type, cons | 
 | return NULL; | return NULL; | 
 | } | } | 
 |  |  | 
| colormap = gtk_widget_get_colormap(GTK_WIDGET(main_window)); | cmap = gtk_widget_get_colormap(GTK_WIDGET(main_window)); | 
| color.red = color.green = color.blue = 0; | memset(&color, 0, sizeof(color)); | 
| if (gdk_color_alloc(colormap, &color) == 0) { | rv = gdk_colormap_alloc_color(cmap, &color, FALSE, FALSE); | 
| fnt.black_pixel = 0; | if (rv) { | 
| } else { |  | 
 | fnt.black_pixel = color.pixel; | fnt.black_pixel = color.pixel; | 
 |  | } else { | 
 |  | fnt.black_pixel = 0; | 
 | } | } | 
 |  |  | 
 | fnt.layout = gtk_widget_create_pango_layout(main_window, NULL); | fnt.layout = gtk_widget_create_pango_layout(main_window, NULL); | 
| Line 152  fontmng_destroy(void *hdl) | Line 150  fontmng_destroy(void *hdl) | 
 |  |  | 
 | if (fnt) { | if (fnt) { | 
 | if (fnt->backsurf) | if (fnt->backsurf) | 
| gdk_pixmap_unref(fnt->backsurf); | g_object_unref(fnt->backsurf); | 
 | if (fnt->layout) | if (fnt->layout) | 
 | g_object_unref(fnt->layout); | g_object_unref(fnt->layout); | 
 | if (fnt->desc) | if (fnt->desc) | 
| Line 162  fontmng_destroy(void *hdl) | Line 160  fontmng_destroy(void *hdl) | 
 | } | } | 
 |  |  | 
 | static void | 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->width = fhdl->rect.width; | 
 | fdat->height = fhdl->rect.height; | fdat->height = fhdl->rect.height; | 
 | fdat->pitch = fhdl->size; | fdat->pitch = fhdl->size; | 
| Line 176  setfdathead(FNTMNG fhdl, FNTDAT fdat, co | Line 172  setfdathead(FNTMNG fhdl, FNTDAT fdat, co | 
 | } | } | 
 |  |  | 
 | static void | 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); | setfdathead(fhdl, fdat, str, len); | 
 | } | } | 
 |  |  | 
 | static void | static void | 
| getfont1(FNTMNG fhdl, FNTDAT fdat, const gchar *str, int len) | getfont1(FNTMNG fhdl, FNTDAT fdat, const char *str, int len) | 
 | { | { | 
 | GdkImage *img; | GdkImage *img; | 
 |  |  | 
| Line 212  getfont1(FNTMNG fhdl, FNTDAT fdat, const | Line 208  getfont1(FNTMNG fhdl, FNTDAT fdat, const | 
 | p++; | p++; | 
 | } | } | 
 | } | } | 
| gdk_image_destroy(img); | g_object_unref(img); | 
 | } else { | } else { | 
 | memset(fdat + 1, 0, fdat->width * fdat->height); | memset(fdat + 1, 0, fdat->width * fdat->height); | 
 | } | } | 
| Line 223  fontmng_getsize(void *hdl, const char *s | Line 219  fontmng_getsize(void *hdl, const char *s | 
 | { | { | 
 | FNTMNG fhdl = (FNTMNG)hdl; | FNTMNG fhdl = (FNTMNG)hdl; | 
 | _FNTDAT fdat; | _FNTDAT fdat; | 
| UINT8 buf[4]; | char buf[4]; | 
 | int width; | int width; | 
 | int len; | int len; | 
 |  |  | 
| if ((fhdl == NULL) || (str == NULL)) | if ((fhdl == NULL) || (str == NULL)) { | 
 | return FAILURE; | return FAILURE; | 
 |  | } | 
 |  |  | 
 | width = 0; | width = 0; | 
 | buf[2] = '\0'; |  | 
 | for (;;) { | for (;;) { | 
| buf[0] = *str++; | while ((len = milstr_charsize(str)) != 0) { | 
| if ((((buf[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c && *str != '\0') { | memcpy(buf, str, len * sizeof(char)); | 
| buf[1] = *str++; | buf[len] = '\0'; | 
| len = 2; | getlength1(fhdl, &fdat, buf, len); | 
| } else if (buf[0] >= 0xa1 && buf[1] <= 0xdf) { | width += fdat.pitch; | 
| buf[1] = buf[0]; |  | 
| buf[0] = 0x8e; |  | 
| len = 1; |  | 
| } else if (buf[0]) { |  | 
| buf[1] = '\0'; |  | 
| len = 1; |  | 
| } else { |  | 
| break; |  | 
 | } | } | 
 | getlength1(fhdl, &fdat, buf, len); |  | 
 | width += fdat.pitch; |  | 
 | } | } | 
 | if (pt) { | if (pt) { | 
 | pt->x = width; | pt->x = width; | 
| Line 262  fontmng_getdrawsize(void *hdl, const cha | Line 248  fontmng_getdrawsize(void *hdl, const cha | 
 | { | { | 
 | FNTMNG fhdl = (FNTMNG)hdl; | FNTMNG fhdl = (FNTMNG)hdl; | 
 | _FNTDAT fdat; | _FNTDAT fdat; | 
| UINT8 buf[4]; | char buf[4]; | 
 | int width; | int width; | 
 | int len; | int len; | 
 | int posx; | int posx; | 
 |  |  | 
| if ((hdl == NULL) || (str == NULL)) | if ((hdl == NULL) || (str == NULL)) { | 
 | return FAILURE; | return FAILURE; | 
 |  | } | 
 |  |  | 
 | width = 0; | width = 0; | 
 | posx = 0; | posx = 0; | 
 | buf[2] = '\0'; |  | 
 | for (;;) { | for (;;) { | 
| buf[0] = *str++; | while ((len = milstr_charsize(str)) != 0) { | 
| if ((((buf[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c && *str != '\0') { | memcpy(buf, str, len * sizeof(char)); | 
| buf[1] = *str++; | buf[len] = '\0'; | 
| len = 2; | getlength1(fhdl, &fdat, buf, len); | 
| } else if (buf[0] >= 0xa1 && buf[0] <= 0xdf) { | width = posx + max(fdat.width, fdat.pitch); | 
| buf[1] = buf[0]; | posx += fdat.pitch; | 
| buf[0] = 0x8e; |  | 
| len = 1; |  | 
| } else if (buf[0]) { |  | 
| buf[1] = '\0'; |  | 
| len = 1; |  | 
| } else { |  | 
| break; |  | 
 | } | } | 
 | getlength1(fhdl, &fdat, buf, len); |  | 
 | width = posx + max(fdat.width, fdat.pitch); |  | 
 | posx += fdat.pitch; |  | 
 | } | } | 
 | if (pt) { | if (pt) { | 
 | pt->x = width; | pt->x = width; | 
| Line 304  fontmng_get(void *hdl, const char *str) | Line 280  fontmng_get(void *hdl, const char *str) | 
 | { | { | 
 | FNTMNG fhdl = (FNTMNG)hdl; | FNTMNG fhdl = (FNTMNG)hdl; | 
 | FNTDAT fdat = (FNTDAT)(fhdl + 1); | FNTDAT fdat = (FNTDAT)(fhdl + 1); | 
| UINT8 buf[4]; | char buf[4]; | 
 | gchar *utf8; | gchar *utf8; | 
 | int len; | int len; | 
 |  |  | 
| Line 312  fontmng_get(void *hdl, const char *str) | Line 288  fontmng_get(void *hdl, const char *str) | 
 | return NULL; | return NULL; | 
 | } | } | 
 |  |  | 
| if (((((str[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c) && (str[1] != '\0')) { | while ((len = milstr_charsize(str)) != 0) { | 
| codecnv_sjistoeuc(buf, 4, str, 2); | memcpy(buf, str, len * sizeof(char)); | 
| len = 2; | buf[len] = '\0'; | 
| } else if ((UINT8)str[0] >= 0xa1 && (UINT8)str[0] <= 0xdf) { | utf8 = g_locale_to_utf8(buf, -1, NULL, NULL, NULL); | 
| buf[0] = 0x8e; | if (utf8) { | 
| buf[1] = str[0]; | getfont1(fhdl, fdat, utf8, len); | 
| buf[2] = '\0'; | g_free(utf8); | 
| len = 1; | } | 
| } else { | str += len; | 
| 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; |  | 
 | } | } | 
| return NULL; | return fdat; | 
 | } | } |