[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][TOP]

PATCH: gedit


たごうです.

gedit 0.9.4で日本語の表示と印刷 previewのためのパッチです.

--
Akira TAGOH :: at@xxxxxxxxx
               tagoh@xxxxxxxxxxx  / Japan GNOME Users Group
               tagoh@xxxxxxxxxxxx / GNOME-DB Project
               tagoh@xxxxxxxxxx   / Red Hat, Inc.
diff -ruN gedit-0.9.4.orig/src/prefs.c gedit-0.9.4/src/prefs.c
--- gedit-0.9.4.orig/src/prefs.c	Wed Feb  7 18:17:40 2001
+++ gedit-0.9.4/src/prefs.c	Wed Feb  7 18:56:51 2001
@@ -27,6 +27,7 @@
 
 #include <config.h>
 #include <gnome.h>
+#include <locale.h>
 
 #include "prefs.h"
 #include "view.h"
@@ -115,6 +116,7 @@
 gedit_prefs_load_settings (void)
 {
 	gchar * mdi_mode_string;
+	gchar *locale = setlocale (LC_CTYPE, "");
 	gedit_debug (DEBUG_PREFS, "");
 
 	if (!settings)
@@ -169,10 +171,19 @@
 	}
 #endif	
 
-	settings->use_fontset = FALSE;
+	if (g_strncasecmp (locale, "ja", 2) &&
+	    g_strncasecmp (locale, "ko", 2) &&
+	    g_strncasecmp (locale, "zh", 2))
+		settings->use_fontset = FALSE;
+	else
+		settings->use_fontset = TRUE;
 	settings->font = gnome_config_get_string ("font");
-	if (settings->font == NULL)
-		settings->font = g_strdup (DEFAULT_FONT);
+	if (settings->font == NULL) {
+		if (settings->use_fontset)
+			settings->font = g_strdup (DEFAULT_FONTSET);
+		else
+			settings->font = g_strdup (DEFAULT_FONT);
+	}
 	
 	if (mdi)
 		tab_pos (settings->tab_pos);
diff -ruN gedit-0.9.4.orig/src/print.c gedit-0.9.4/src/print.c
--- gedit-0.9.4.orig/src/print.c	Wed Feb  7 19:03:30 2001
+++ gedit-0.9.4/src/print.c	Wed Feb  7 23:03:24 2001
@@ -24,6 +24,9 @@
 
 #include <config.h>
 #include <gnome.h>
+#include <locale.h>
+#include <langinfo.h>
+#include <iconv.h>
 
 #include "print.h"
 #include "file.h"
@@ -600,6 +603,8 @@
 print_ps_line (PrintJobInfo * pji, gint line, gint first_line)
 {
 	gfloat y;
+	gchar *locale;
+	iconv_t fd;
 
 	gedit_debug (DEBUG_PRINT, "");
 
@@ -610,7 +615,23 @@
 		return;
 	
 	gnome_print_moveto (pji->pc, pji->margin_left, y);
-	print_show_iso8859_1 (pji->pc, pji->temp);
+	setlocale (LC_CTYPE, "");
+	locale = nl_langinfo (CODESET);
+	if (strlen (pji->temp) > 0 && (fd = iconv_open ("UTF-8", locale)) != (iconv_t)-1) {
+		gchar *pin, *pout, *utext;
+		gint ib, ob;
+
+		ib = strlen (pji->temp);
+		ob = ib * 3;
+		pin = pji->temp;
+		pout = utext = g_new0 (gchar, ob);
+		iconv (fd, &pin, &ib, &pout, &ob);
+		iconv_close (fd);
+		gnome_print_show_sized (pji->pc, utext, strlen (utext));
+		g_free (utext);
+	} else {
+		print_show_iso8859_1 (pji->pc, pji->temp);
+	}
 
 	if (settings->print_lines>0 && line%settings->print_lines==0 && first_line)
 	{
@@ -621,7 +642,21 @@
 
 		gnome_print_setfont (pji->pc, temp_font);
 		gnome_print_moveto (pji->pc, pji->margin_left - pji->margin_numbers, y);
-		print_show_iso8859_1 (pji->pc, number_text);
+		if ((fd = iconv_open ("UTF-8", locale)) != (iconv_t)-1) {
+			gchar *pin, *pout, *utext;
+			gint ib, ob;
+			
+			ib = strlen (number_text);
+			ob = ib * 3;
+			pin = number_text;
+			pout = utext = g_new0 (gchar, ob);
+			iconv (fd, &pin, &ib, &pout, &ob);
+			iconv_close (fd);
+			gnome_print_show_sized (pji->pc, utext, strlen (utext));
+			g_free (utext);
+		} else {
+			print_show_iso8859_1 (pji->pc, number_text);
+		}
 		g_free (number_text);
 		gtk_object_unref (GTK_OBJECT(temp_font));
 		print_setfont (pji);
@@ -696,8 +731,8 @@
 
 	pji->view = gedit_view_active();
 	pji->doc = doc;
-	pji->buffer_size = gtk_text_get_length(GTK_TEXT(pji->view->text));
 	pji->buffer = gedit_document_get_buffer (doc);
+	pji->buffer_size = strlen (pji->buffer);
 
 	if (doc->filename == NULL)
 		pji->filename = g_strdup (_("Untitled")); 
@@ -960,7 +995,9 @@
 	guchar* text2 = g_strdup_printf (_("Page: %i/%i"), page, pji->pages);
 	GnomeFont *font;
 	float x,y,len;
-	
+	gchar *locale;
+	iconv_t fd;
+
 	gedit_debug (DEBUG_PRINT, "");
 
 	font = gnome_font_new (GEDIT_PRINT_HEADER_FONT, 12);
@@ -971,14 +1008,46 @@
 	len = gnome_font_get_width_string (font, text1);
 	x = pji->page_width/2 - len/2;
 	gnome_print_moveto(pji->pc, x, y);
-	print_show_iso8859_1 (pji->pc, text1);
+
+	setlocale (LC_CTYPE, "");
+	locale = nl_langinfo (CODESET);
+	if ((fd = iconv_open ("UTF-8", locale)) != (iconv_t)-1) {
+		gchar *pin, *pout, *utext;
+		gint ib, ob;
+
+		ib = strlen (text1);
+		ob = ib * 3;
+		pin = text1;
+		pout = utext = g_new0 (gchar, ob);
+		iconv (fd, &pin, &ib, &pout, &ob);
+
+		gnome_print_show_sized (pji->pc, utext, strlen (utext));
+		g_free (utext);
+	} else {
+		print_show_iso8859_1 (pji->pc, text1);
+	}
 
 	/* Print the page/pages  */
 	y = pji->page_height - pji->margin_top - pji->header_height/4;
 	len = gnome_font_get_width_string (font, text2);
 	x = pji->page_width - len - 36;
 	gnome_print_moveto (pji->pc, x, y);
-	print_show_iso8859_1 (pji->pc, text2);
+	if (fd != (iconv_t)-1) {
+		gchar *pin, *pout, *utext;
+		gint ib, ob;
+
+		ib = strlen (text2);
+		ob = ib * 3;
+		pin = text2;
+		pout = utext = g_new0 (gchar, ob);
+		iconv (fd, &pin, &ib, &pout, &ob);
+
+		gnome_print_show_sized (pji->pc, utext, strlen (utext));
+		g_free (utext);
+		iconv_close (fd);
+	} else {
+		print_show_iso8859_1 (pji->pc, text2);
+	}
 
 	gtk_object_unref (GTK_OBJECT(font));
 	g_free (text1);