
#include <gtk/gtk.h>
#include <glib/gprintf.h> /* g_sprintf */

#define STRONG_VERTICAL 1

static void
set_label_angle (GtkWidget *label, gdouble angle, gboolean vertical)
{
  PangoLayout *layout;
  PangoContext *context;
  //PangoGravity gravity;

if (vertical) {
    layout = gtk_label_get_layout (GTK_LABEL (label));
    context = pango_layout_get_context (layout);
    //gravity = pango_context_get_base_gravity (context);

#ifndef STRONG_VERTICAL
    pango_context_set_base_gravity (context, PANGO_GRAVITY_AUTO);
#else
    pango_context_set_base_gravity (context, PANGO_GRAVITY_VERTICAL);
#endif
  }

#if 0
  gtk_orientable_set_orientation (GTK_ORIENTABLE (vbox), GTK_ORIENTATION_VERTICAL);
#endif

#ifndef STRONG_VERTICAL
  gtk_label_set_angle (GTK_LABEL (label), angle);
#else
  if (vertical == FALSE) {
    gtk_label_set_angle (GTK_LABEL (label), angle);
  } else {
    if ((GTK_LABEL (label))->layout) {
      g_object_unref ((GTK_LABEL (label))->layout);
      (GTK_LABEL (label))->layout = NULL;
    }
    gtk_widget_queue_resize (label);
  }
#endif
}

int main (int argc, char* argv[])
{
  GtkWidget *window;
  GtkWidget *vbox;
  GtkWidget *label;
  const gchar *str1 = "\xe3\x82\xa2\xe3\x83\x97\xe3\x83\xaa\xe3\x82\xb1\xe3\x83\xbc\xe3\x82\xb7\xe3\x83\xa7\xe3\x83\xb3";
  //const gchar *str1 = "Application";
  const gchar *str2 = "\xe6\x9c\x88";
  const gchar *str3 = "\xe6\x97\xa5";
  const gchar *str4 = "\xe6\x9c\xa8";
  gchar buf[255];

  gtk_init (&argc, &argv);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  g_sprintf (buf, "%s 10%s21%s (%s) 01:21", str1, str2, str3, str4);

  label = gtk_label_new (NULL);
  gtk_label_set_text_with_mnemonic (GTK_LABEL (label), buf);

  gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);

  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);

  gtk_window_set_default_size (GTK_WINDOW (window), 500, 400);

  gtk_widget_show_all (window);

  //set_label_angle (label, 270.0, FALSE);
  set_label_angle (label, 0.0, TRUE);
  //set_label_angle (label, 0.0, FALSE);

  gtk_main ();
  return 0;
}
