font renderers in gdk



Hey all,

spurred by raster's comments about FnLib and anti-aliased fonts, I've
hacked a font renderer abstraction into gdk.

The GdkFont's private data now includes a pointer the GdkFontRenderer,
a pointer to renderer specific data, and doesn't know anything about
XFontStructs (or X Display's for that matter).  Now, all operations
involving fonts get dispatched to a font renderer through a vtable
shown below:

struct _GdkFontRendererVtable
{
  gint		(*GetAPIVersion)(GdkFontRenderer *);
  const gchar*	(*GetName)(GdkFontRenderer *);
  const gchar*	(*GetVendor)(GdkFontRenderer *);
  const gchar*	(*GetVersion)(GdkFontRenderer *);
  const gchar*	(*GetBlurb)(GdkFontRenderer *);
  gint		(*CountFonts)(GdkFontRenderer *);
  gint		(*ListFonts)(GdkFontRenderer *, const gchar **font_specs);
  GdkFont*	(*LoadFont)(GdkFontRenderer *, const gchar *font_spec, gint is_fontset);
  void		(*DestroyFont)(GdkFontRenderer *, GdkFont *font);
  void		(*RenderString)(GdkFontRenderer *, GdkDrawable *,
				GdkFont *font,
				GdkGC *gc,
				const gchar *string,
				gint length, gint x, gint y);
  void		(*GetAscentDescent)(GdkFontRenderer *, GdkFont *font, gint *ascent, gint *descent);
  gint		(*GetAdvancement)(GdkFontRenderer *, GdkFont *font, gchar *character, gint length);
  gint		(*GetMaxAdvancement)(GdkFontRenderer *, GdkFont *font);
  gint		(*StringWidth)(GdkFontRenderer *, GdkFont *font,
			       const gchar *string, gint length);
  gint		(*FontEqual)(GdkFontRenderer *, GdkFont *fonta, GdkFont *fontb);
};

No changes were made to the gdk api.

The function gdk_font_load now checks if the font_name begins with
"font:" or "fontset:".  If it does, it dispatches through a list of
registered font renderers until it finds one that actually knows about
the font.  If it doesn't begin with one of those two strings (such as
in the case of XLFD's), it uses the default font renderer, which is
uses XFontStructs/XFontSets.

Using the URL scheme, you can either specify a font renderer, or the
font code will discover one for you that can handle the font.  The two
ways of specifying a font are (for example):

font://Raster's FnLib Renderer/VeryCoolFont

and

font:/VeryCoolFont

In the first case, if the font renderer named is not present, the load
would fail.  In the second case the load would fail only if no font
renderer knew about a font called "VeryCoolFont."

attributes, such as point-size, weight, slant, etc. would be given as
arguments in the URL, as in:

font:/VeryCoolFont?point-size=24&weight=bold&slant=italic

Mind you, this format isn't set in stone...  In fact, no code has been
written to parse it.  It's merely a suggestion (with some holes.
Like, how do you express a fontset?)  Any thoughts?

The X font renderer is compiled into gdk (but doesn't necessarily have
to be -- the discovery code will eventually find shared libraries that
conform to the API above and automatically register them).  With it, I
can run testgtk without a problem.  I'm in the process of writing a
renderer for the free Type1 Rasterizer, t1lib (which does antialiased
fonts.)  By following this API, Raster could write a renderer for
FnLib that would allow gdk to transparently use his 24 bit fonts.  Or
someone could write a truetype font renderer or something.

Would you guys be interested in something like this?  Do you think the
Gdk guys would be (are there any gdk guys on this list?)  If anyone is
interested in diff's to the gtk+ tip, let me know.

Chris



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