/* 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);

  /* This font has problems in 2 pairs of texts. */
  font_desc = pango_font_description_from_string ("Bitstream Vera Sans 10");

  /* These 2 only have problems in one pair of texts. */
  /*font_desc = pango_font_description_from_string ("Bitstream Sera Serif");*/
  /*font_desc = pango_font_description_from_string ("Nimbus Sans L");*/

  /* This one doesn't have problems. */
  /*font_desc = pango_font_description_from_string ("URW Palladio L");*/

  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);
#if 1
  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);
#endif

  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;
}

