Re: A more CTL friendly gnome_font_get_width_utf8_sized() ?



On Fri, 2004-06-04 at 15:28, Sayamindu Dasgupta wrote:
> Hi,
> Since we are on the topic of making Pango and gnome-print better
> integrated, I think gnome_font_get_width_utf8_sized() (libgnomeprint/
> gnome-font.c: line 716) should be updated so that it handles complex
> scripts properly.
> 
> Currently, it just adds up the glyph widths of all the code points
> present in the text passed to it. This is OK for English, but as soon as
> one moves into scripts where codepoint:glyph ratio is not always 1:1, it
> makes stuff look really ugly.

The way that you do this with gnome-print and my Pango patch is that
you call pango_layout_get_extents() ... an example from the docs is:

===
static void
draw_hello_world (GnomePrintContext *gpc,
                  double             page_width,
                  double             page_height)
{
  PangoLayout *layout = gnome_print_pango_create_layout (gpc);
  int pango_width, pango_height;
  double width, height;

  pango_layout_set_text (layout, "Hello World");

  pango_layout_get_size (layout, &pango_width, &pango_height);
  width = (double) pango_width / PANGO_SCALE;
  height = (double) pango_height / PANGO_SCALE;

  gnome_print_moveto (gpc,
	             (page_width - width) / 2,
                     (page_width - height)/ 2);
  gnome_print_pango_layout (gpc, layout);

  g_object_unref (layout);
}
===

Your query brings up a couple of questions in my mind:

 * Should we make gnome_print_show(), etc, use the Pango
   code to get proper CTL behavior?
  
   My suggestion: No. The GnomeFont API is intertwined with the
   current drawing functions and changing what they do would
   just break current apps.

 * Should we have some convenience functions for drawing / measuring
   strings separate from the current API that don't require creating
   a layout?

   My suggestion: No. Creating a layout is pretty convenient, and
   it's pretty common to want to measure *and* draw at the same
   time, or set a wrap width, or... so it's clearer just to have
   one API. We don't have any convenience APIs to bypass creating
   a layout for GDK.

 * Should we have something similar to pango_layout_get_size_pixels()
   that returns a double width/height rather than fixed-point
   Pango units.

   My suggestion: No. (But I'm less sure about this one). Having
   this in the gnome-print API strikes me as rather a strange place
   for it, and there are lots of places where Pango units surface in the
   Pango API; I'm not sure where you would stop adding convenience
   wrappers.

> IIRC, gnome_font_get_width_utf8() is used quite extensively to determine
> line break positions in GtkHTML 3.0.

> I am not very familiar with the Pango API, but I think the new
> libgnomeprint API should make line breaking easier with
> pango_layout_set_width() and pango_layout_set_wrap(). That should
> probably eliminate the need for gnome_font_get_width_utf8_sized().

Unfortunately, making GtkHTML use PangoLayout is not at all easy, and
probably not something that can be done in the short term.

Still, we should be able to do as well for the gnome-print/Pango backend
as GtkHTML does for the GDK backend onscreen currently. Which is pretty
much good enough for Indic scripts.

Regards,
						Owen

Attachment: signature.asc
Description: This is a digitally signed message part



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