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

Re: Gtk2 kanji antialiasing



On Thu, May 02, 2002 at 11:51:56PM +0200, Tomasz Wegrzanowski wrote:
> I'm trying to get antialiasing working here with kanji.
> I think I installed every japanese font that was available
> in Debian.

I've been trying to get this to work for a long time.  When I received
your message, I let it sit in my mailbox until tonight when I spent a
few more hours on it.  I think I just figured it out!


When GDK_USE_XFT=1, Gtk... well, uses Xft. :)
Xft, AFAIK, only uses fonts that can be antialiased.  This means
TrueType (or Type1, but I don't see many of those fonts around).
All of those xfonts-* packages you installed don't help.

The Debian package 'msttcorefonts' has some good fonts (including the
Verdana font I use in my examples below), though they are from Microsoft
aren't really free. :(

There are two paths to take:

1) Make GTK use a Unicode font that has all of the glyphs.
2) Make Xft use multiple fonts simultaneously to render the text.

If you try to option 1, you need a TrueType font that covers both western
and CJK (a common acronym for Chinese, Japanese, and Korean) fonts.
These fonts are very rare.  The above-mentioned Microsoft fonts don't
cover CJK.  However, there is one that is publically available!  It's
called Bitstream Cyberbit.  There is some issue with the license so you
can't find it easily, but you can find it on the Netscape i18n pages
somewhere.

If you make GTK use that font, everything just works.  You can even make
GTK use it only for the text boxes by putting this in your ~/.gtkrc-2.0:

gtk-font-name = "Verdana 11"  # or whatever font you would like for gtk
style "textfont"
{
        font_name="Bitstream Cyberbit 12"
}
class "GtkTextView" style "textfont"
class "GtkEntry" style "textfont"


For option 2, you need the ttf-xtt-* Japanese fonts installed.
Xft knows about those fonts and it knows about your other TrueType fonts
(like the Microsoft ones) but it doesn't know to use them together.

GTK uses the Xft alias "sans" by default, so you can add something like
this to your ~/.xftconfig (you no longer need the above hack in your
~/.gtkrc-2.0):

match
	any family == "sans"
edit
        family += "verdana";
	family =+ "kochi mincho";
	size = 11;

If you do this and then run gtk-demo, you'll see the Japanese alongside
the English.  (kochi mincho appears to not render in some sizes, so be
careful when you adjust the font size.)

sugoi! :)


PS.  The attached program can be compiled with
	gcc -o fs fs.c `pkg-config --cflags --libs gtk+-2.0`
and lets you browse the fonts that GTK 2.0 is aware of.

-- 
      Evan Martin
martine@cs.washington.edu
  http://neugierig.org
/* vim: set ts=4 sw=4 : */

#include <gtk/gtk.h>

int main(int argc, char* argv[]) {
	GtkWidget *dlg;

	gtk_init(&argc, &argv);
	dlg = gtk_font_selection_dialog_new("Select font");
	gtk_dialog_run(GTK_DIALOG(dlg));
	return 0;
}


Reply to: