[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][TOP]
librsvg patch
あかがきと申します。
お初です。
librsvg の日本語表示パッチなどを作ってみたので投稿します。
kochi-mincho dyna wadalab watanabe
などのフォントで表示ができてます。
kochi-mincho以外は半角文字の表示が変ですが...
パッチのなかに GB2312 とか BIG5 とかでてきてますが、
まったく試験していません。
等、ごく適当なものですがもんでいただけると幸いです。
diff -uNr librsvg-1.0.0.orig/rsvg-ft.c librsvg-1.0.0/rsvg-ft.c
--- librsvg-1.0.0.orig/rsvg-ft.c Thu Mar 29 03:44:42 2001
+++ librsvg-1.0.0/rsvg-ft.c Wed May 9 16:59:18 2001
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
-
+ほげ漢字
rsvg-ft.c: Basic functions for freetype/libart integration.
Copyright (C) 2000 Eazel, Inc.
@@ -28,6 +28,10 @@
#include <stdlib.h>
#include <math.h>
+#include <locale.h>
+#include <iconv.h>
+#include <langinfo.h>
+
#include <freetype/freetype.h>
#include <libart_lgpl/art_misc.h>
@@ -92,6 +96,7 @@
int refcnt;
RsvgFTCtx *ctx;
FT_Face face;
+ char* conv;
};
struct _RsvgFTFontCacheEntry {
@@ -372,9 +377,38 @@
result = NULL;
else {
result = g_new (RsvgFTFont, 1);
+ result->conv=NULL;
result->refcnt = 1;
result->ctx = ctx;
result->face = face;
+ if(!face->charmap){
+ int i;
+ for(i=0;i<face->num_charmaps;i++){
+ switch(face->charmaps[i]->encoding){
+ case ft_encoding_sjis:
+ FT_Select_Charmap(face,face->charmaps[i]->encoding);
+ result->conv="SJIS";
+ return result;
+ case ft_encoding_gb2312:
+ FT_Select_Charmap(face,face->charmaps[i]->encoding);
+ result->conv="GB2312";
+ return result;
+ case ft_encoding_big5:
+ FT_Select_Charmap(face,face->charmaps[i]->encoding);
+ result->conv="BIG5";
+ return result;
+ case ft_encoding_wansung:
+ FT_Select_Charmap(face,face->charmaps[i]->encoding);
+ result->conv="KSC5636";
+ return result;
+ case ft_encoding_johab:
+ FT_Select_Charmap(face,face->charmaps[i]->encoding);
+ result->conv="JOHAB";
+ return result;
+ default:
+ }
+ }
+ }
}
return result;
}
@@ -821,6 +855,7 @@
int pixel_underline_position, pixel_underline_thickness;
int wclength;
wchar_t *wcstr;
+ iconv_t ict;
g_return_val_if_fail (ctx != NULL, NULL);
g_return_val_if_fail (str != NULL, NULL);
@@ -866,7 +901,6 @@
init_x = affine[4];
init_y = affine[5];
n_glyphs = 0;
-
/* Alloc max length of wide char */
wcstr = g_new0 (wchar_t, length);
wclength = mbstowcs (wcstr, str, length);
@@ -883,34 +917,56 @@
wcstr[i] = (unsigned char) str[i];
}
}
-
+
+ if(font->conv){
+ ict=iconv_open(font->conv,nl_langinfo(CODESET));
+ }
+
for (i = 0; i < length; i++) {
- RsvgFTGlyph *glyph;
+ RsvgFTGlyph *glyph=NULL;
+ wchar_t wc=0;
- glyph_index = FT_Get_Char_Index (font->face, wcstr[i]);
-
- /* FIXME bugzilla.eazel.com 2775: Need a better way to deal
- * with unknown characters.
- *
- * The following is just a band aid fix.
- */
- if (glyph_index == 0) {
- glyph_index = FT_Get_Char_Index (font->face, '?');
- }
+ if(font->conv){
+ char buffer[10];
+ char *inbuf=NULL,*outbuf=NULL;
+ size_t in=0;
+ size_t out=0;
+ int ret=0;
+ char tmp[10];
+ FT_Encoding enc;
+
+ ret=wctomb(tmp,wcstr[i]);
+ tmp[ret]=0;
+ inbuf=tmp;
+ in=strlen(tmp);
+ outbuf=buffer;
+ out=sizeof(buffer);
+ if(in==1)
+ wc=tmp[0];
+ else{
+ int j;
+ iconv(ict,&inbuf,&in,&outbuf,&out);
+ for(j=0;j<10-out;j++)
+ wc=wc<<8|(unsigned char)buffer[j];
+ }
+ glyph_index = FT_Get_Char_Index (font->face, wc);
+ if(!glyph_index){
+ int j;
+ for(j=0;(j<font->face->num_charmaps)&&(!glyph_index);j++){
+ FT_Set_Charmap(font->face,font->face->charmaps[j]);
+ glyph_index = FT_Get_Char_Index (font->face, wc);
+ }
+ }
+ }else
+ glyph_index = FT_Get_Char_Index (font->face, wcstr[i]);
if (last_glyph != 0 && glyph_index != 0) {
FT_Vector kern;
double kx, ky;
- /* note: ft_kerning_unscaled seems to do the
- right thing with non-trivial affine transformations.
- However, ft_kerning_default may be a better choice
- for straight text rendering. This probably needs
- a little more thought. */
FT_Get_Kerning (font->face, last_glyph, glyph_index,
ft_kerning_unscaled,
&kern);
-/* fprintf (stderr, "kern = (%ld, %ld)\n", kern.x, kern.y); */
kx = FT_TOFLOAT (kern.x);
ky = FT_TOFLOAT (kern.y);
glyph_affine[4] += glyph_affine[0] * kx +
@@ -918,64 +974,45 @@
glyph_affine[5] += glyph_affine[1] * kx +
glyph_affine[3] * ky;
}
- if (glyph_index != 0) {
+ if(glyph_index != 0){
last_glyph = glyph_index;
glyph = rsvg_ft_get_glyph_cached (ctx, fh, glyph_index,
- glyph_index,
- sx, sy, glyph_affine,
- glyph_xy + n_glyphs * 2);
-
- /* Evil hack to handle fonts that don't define glyphs
- * for ` ' characters. Ask for `-', zero the pixels, then
- * enter it in the cache under the glyph index of ` '
- *
- * (The reason that this is needed is that at least some
- * microsoft TrueType fonts give ` ' an index, but don't
- * give it an actual glyph definition. Presumably they
- * just use some kind of metric when spacing)
- */
- if (glyph == NULL && wcstr[i] == ' ') {
- cache_index = glyph_index;
- glyph_index = FT_Get_Char_Index (font->face, '-');
- if (glyph_index != 0) {
- glyph = rsvg_ft_get_glyph_cached (ctx, fh, cache_index,
- glyph_index, sx, sy,
- glyph_affine,
- glyph_xy + n_glyphs * 2);
- if (glyph != NULL) {
- memset (glyph->buf, 0, glyph->height * glyph->rowstride);
- }
- }
- }
-
- if (glyph != NULL) {
- glyphs[n_glyphs] = glyph;
-
- glyph_bbox.x0 = glyph_xy[n_glyphs * 2];
- glyph_bbox.y0 = glyph_xy[n_glyphs * 2 + 1];
- glyph_bbox.x1 = glyph_bbox.x0 + glyph->width;
- glyph_bbox.y1 = glyph_bbox.y0 + glyph->height;
+ glyph_index,
+ sx, sy, glyph_affine,
+ glyph_xy + n_glyphs * 2);
+ }
+
+ if (glyph != NULL) {
+ glyphs[n_glyphs] = glyph;
+
+ glyph_bbox.x0 = glyph_xy[n_glyphs * 2];
+ glyph_bbox.y0 = glyph_xy[n_glyphs * 2 + 1];
+ glyph_bbox.x1 = glyph_bbox.x0 + glyph->width;
+ glyph_bbox.y1 = glyph_bbox.y0 + glyph->height;
+
+ art_irect_union (&bbox, &bbox, &glyph_bbox);
+
+ glyph_affine[4] += glyph->xpen;
+ glyph_affine[5] += glyph->ypen;
+
+ n_glyphs++;
+ }else{
+ RsvgFTGlyph *g=NULL;
+ if(n_glyphs)
+ g=glyphs[n_glyphs-1];
+ if(g){
+ glyph_bbox.x0 += g->width;
+ glyph_bbox.x1 += g->width;
art_irect_union (&bbox, &bbox, &glyph_bbox);
-#ifdef VERBOSE
- g_print ("char '%c' bbox: (%d, %d) - (%d, %d)\n",
- str[i],
- glyph_bbox.x0, glyph_bbox.y0,
- glyph_bbox.x1, glyph_bbox.y1);
-#endif
-
- glyph_affine[4] += glyph->xpen;
- glyph_affine[5] += glyph->ypen;
-
- n_glyphs++;
+ glyph_affine[4] += g->xpen;
}
- } else {
- g_print ("no glyph loaded for character '%c'\n",
- str[i]);
}
}
+ if(font->conv)
+ iconv_close(ict);
xy[0] = bbox.x0;
xy[1] = bbox.y0;
diff -uNr librsvg-1.0.0.orig/test-ft-gtk.c librsvg-1.0.0/test-ft-gtk.c
--- librsvg-1.0.0.orig/test-ft-gtk.c Thu Mar 29 03:44:42 2001
+++ librsvg-1.0.0/test-ft-gtk.c Wed May 9 17:00:33 2001
@@ -416,7 +416,9 @@
gint font_width = 36;
gint font_height = 36;
- char *font_file_name = "/usr/share/fonts/default/Type1/n021003l.pfb";
+// char *font_file_name = "/usr/X11R6/lib/X11/fonts/truetype-ja/watanabe-mincho.ttf";
+// char *font_file_name = "/usr/X11R6/lib/X11/fonts/DynaLab-Kondara/DFGotP3.ttc";
+ char *font_file_name = "/usr/X11R6/lib/X11/fonts/truetype-ja/kochi-mincho.ttf";
char *add_font_file_name = NULL;
char *text_file_name = "rsvg-ft.c";
@@ -436,6 +438,7 @@
TestCtx *ctx;
gtk_init (&argc, &argv);
+ gtk_set_locale();
gdk_rgb_init ();