Re: Device-independent text layout
- From: Damon Chaplin <damon karuna uklinux net>
- To: Behdad Esfahbod <behdad cs toronto edu>
- Cc: gtk-i18n-list gnome org
- Subject: Re: Device-independent text layout
- Date: Wed, 10 May 2006 19:16:54 +0100
On Wed, 2006-05-10 at 19:04 +0100, Damon Chaplin wrote:
> On Wed, 2006-05-10 at 12:12 -0400, Behdad Esfahbod wrote:
> > On Wed, 10 May 2006, Owen Taylor wrote:
> >
> > > (Poor rounding can make very small errors into big problems, so you
> > > might want to investigate that...)
> >
> > Exactly. And I've been fixing some bugs in this area recently
> > [1]. Damon, please test with Pango HEAD, and if you still have
> > problems, helps if you attach code.
>
> Here's a simple test case. It shows the same text at a few different
> scales, and rotated. Several of the layouts are different for me. (I've
> just updated pango & cairo.)
Oops. I set the font options on the cairo_t rather than the PangoContext
again. Here's a new version.
Damon
/* Compile with:
gcc `pkg-config --cflags --libs gtk+-2.0` test-pango-cairo.c
*/
#include <gtk/gtk.h>
static void
show_text (cairo_t *cr, double x, double y, double scale, double rotation)
{
PangoLayout *layout;
PangoContext *context;
PangoFontDescription *font_desc;
cairo_font_options_t *font_options;
cairo_save (cr);
cairo_translate (cr, x, y);
cairo_scale (cr, scale, scale);
cairo_rotate (cr, rotation);
layout = pango_cairo_create_layout (cr);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
context = pango_layout_get_context (layout);
pango_cairo_context_set_font_options (context, font_options);
cairo_font_options_destroy (font_options);
pango_layout_set_width (layout, 184320);
pango_layout_set_text (layout,
"This is a very long paragraph that will need to be wrapped over several lines so we can see what happens to line-breaking as the view is zoomed in and out.", -1);
font_desc = pango_font_description_from_string ("Sans 10");
pango_layout_set_font_description (layout, font_desc);
pango_font_description_free (font_desc);
pango_cairo_show_layout (cr, layout);
g_object_unref (layout);
cairo_restore (cr);
}
gboolean
on_expose_event (GtkWidget *window, GdkEvent *event, gpointer data)
{
cairo_t *cr;
cr = gdk_cairo_create (window->window);
show_text (cr, 20, 20, 1.0, 0.0);
show_text (cr, 220, 20, 0.7, 0.0);
show_text (cr, 400, 20, 0.5, 0.0);
show_text (cr, 560, 20, 0.3, 0.0);
show_text (cr, 700, 20, 0.2, 0.0);
show_text (cr, 120, 220, 1.0, 0.8);
show_text (cr, 320, 220, 0.7, 0.8);
show_text (cr, 490, 220, 0.5, 0.8);
show_text (cr, 640, 220, 0.3, 0.8);
show_text (cr, 770, 220, 0.2, 0.8);
cairo_destroy (cr);
return TRUE;
}
int
main (int argc, char *argv[])
{
GtkWidget *window, *darea;
gtk_set_locale ();
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
g_signal_connect (window, "expose-event", G_CALLBACK (on_expose_event),
NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]