Merge branch 'master' of github.com:wmvanvliet/Chimara
authorP. F. Chimento <philip.chimento@gmail.com>
Sat, 15 Jan 2011 12:10:07 +0000 (13:10 +0100)
committerP. F. Chimento <philip.chimento@gmail.com>
Sat, 15 Jan 2011 12:10:07 +0000 (13:10 +0100)
libchimara/chimara-if.c
libchimara/style.c
player/style.css
tests/Makefile.am
tests/plugin-loader.c
tests/test-userstyle.c [new file with mode: 0644]

index efbd5297c41dcd008fc874da3c4e2e1f59db7c85..4e8c1d9490b4fcbc38f0e471703a2fcc35fd5c29 100644 (file)
@@ -125,6 +125,17 @@ chimara_if_stopped(ChimaraGlk *glk)
        priv->interpreter = CHIMARA_IF_INTERPRETER_NONE;
 }
 
+static void
+chimara_if_char_input(ChimaraGlk *glk, guint32 win_rock, guint keysym)
+{
+       CHIMARA_IF_USE_PRIVATE(glk, priv);
+       g_assert(priv->input == NULL);
+
+       gchar outbuf[6];
+       gint outbuflen = g_unichar_to_utf8(gdk_keyval_to_unicode(keysym), outbuf);
+       priv->input = g_strndup(outbuf, outbuflen);
+}
+
 static void
 chimara_if_line_input(ChimaraGlk *glk, guint32 win_rock, gchar *input)
 {
@@ -161,6 +172,7 @@ chimara_if_init(ChimaraIF *self)
        /* Connect to signals of ChimaraGlk parent */
        g_signal_connect(self, "stopped", G_CALLBACK(chimara_if_stopped), NULL);
        g_signal_connect(self, "waiting", G_CALLBACK(chimara_if_waiting), NULL);
+       g_signal_connect(self, "char-input", G_CALLBACK(chimara_if_char_input), NULL);
        g_signal_connect(self, "line-input", G_CALLBACK(chimara_if_line_input), NULL);
        g_signal_connect(self, "text-buffer-output", G_CALLBACK(chimara_if_text_buffer_output), NULL);
 }
index 74a64378c9b16d2012ad88a1ab8ed3834ebc5718..2e2b80c898c73fb54bd31aeccf3659dbf2d1157e 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <string.h>
+#include <math.h>
 #include "chimara-glk-private.h"
 #include "glk.h"
 #include "style.h"
@@ -214,6 +215,7 @@ gtk_text_tag_copy(GtkTextTag *tag)
                _COPY_FLAG (invisible_set);
                _COPY_FLAG (editable_set);
                _COPY_FLAG (language_set);
+               _COPY_FLAG (scale_set);
        #undef _COPY_FLAG
 
        /* Copy the data that was added manually */
@@ -319,12 +321,12 @@ style_init(ChimaraGlk *glk)
 
        tag = gtk_text_tag_new("header");
        //g_object_set(tag, "font-desc", default_font_desc, "size-points", 18.0, "weight", PANGO_WEIGHT_BOLD, NULL);
-       g_object_set(tag, "size-points", 18.0, "weight", PANGO_WEIGHT_BOLD, NULL);
+       g_object_set(tag, "weight", PANGO_WEIGHT_BOLD, NULL);
        g_hash_table_insert(default_text_buffer_styles, "header", tag);
 
        tag = gtk_text_tag_new("subheader");
        //g_object_set(tag, "font-desc", default_font_desc, "size-points", 14.0, "weight", PANGO_WEIGHT_BOLD, NULL);
-       g_object_set(tag, "size-points", 14.0, "weight", PANGO_WEIGHT_BOLD, NULL);
+       g_object_set(tag, "weight", PANGO_WEIGHT_BOLD, NULL);
        g_hash_table_insert(default_text_buffer_styles, "subheader", tag);
 
        tag = gtk_text_tag_new("alert");
@@ -732,7 +734,24 @@ apply_stylehint_to_tag(GtkTextTag *tag, GtkTextTag *default_tag, glui32 wintype,
                break;
 
        case stylehint_Size:
-               g_object_set(tag_object, "size", 14+(2*val), "size-set", TRUE, NULL);
+               {
+                       gdouble scale = PANGO_SCALE_MEDIUM;
+                       switch(val) {
+                               case -3: scale = PANGO_SCALE_XX_SMALL; break;
+                               case -2: scale = PANGO_SCALE_X_SMALL; break;
+                               case -1: scale = PANGO_SCALE_SMALL; break;
+                               case  0: scale = PANGO_SCALE_MEDIUM; break;
+                               case  1: scale = PANGO_SCALE_LARGE; break;
+                               case  2: scale = PANGO_SCALE_X_LARGE; break;
+                               case  3: scale = PANGO_SCALE_XX_LARGE; break;
+                               default:
+                                       /* We follow Pango's convention of having each magnification
+                                       step be a scaling of 1.2 */
+                                       scale = pow(1.2, (double)val);
+                       }
+                       g_printerr("Setting tag to %f\n", scale);
+                       g_object_set(tag_object, "scale", scale, "scale-set", TRUE, NULL);
+               }
                break;
 
        case stylehint_Oblique:
@@ -744,7 +763,7 @@ apply_stylehint_to_tag(GtkTextTag *tag, GtkTextTag *default_tag, glui32 wintype,
                gchar *font_family;
                GtkTextTag *font_tag = g_hash_table_lookup(
                    wintype == wintype_TextBuffer? glk_data->styles->text_buffer : glk_data->styles->text_grid,
-                   val? "normal" : "preformatted");
+                   val? "default" : "preformatted");
                g_object_get(font_tag, "family", &font_family, NULL);
                g_object_set(tag_object, "family", font_family, "family-set", TRUE, NULL);
                g_free(font_family);
@@ -813,6 +832,7 @@ static gint
 query_tag(GtkTextTag *tag, glui32 wintype, glui32 hint)
 {
        gint intval;
+       gdouble doubleval;
        GdkColor *colval;
 
        g_return_val_if_fail(tag != NULL, 0);
@@ -850,8 +870,8 @@ query_tag(GtkTextTag *tag, glui32 wintype, glui32 hint)
                }
 
        case stylehint_Size:
-               g_object_get(tag, "size", &intval, NULL);
-               return (intval/2)-14;
+               g_object_get(tag, "scale", &doubleval, NULL);
+               return (gint)round(log(doubleval) / log(1.2));
 
        case stylehint_Oblique:
                g_object_get(tag, "style", &intval , NULL);
@@ -1083,21 +1103,21 @@ PangoFontDescription *
 get_current_font(guint32 wintype)
 {
        ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
-       GtkTextTag *normal;
+       GtkTextTag *tag;
 
        switch(wintype) {
        case wintype_TextGrid:
-               normal = g_hash_table_lookup(glk_data->styles->text_grid, "normal");
+               tag = g_hash_table_lookup(glk_data->styles->text_grid, "default");
                break;
        case wintype_TextBuffer:
-               normal = g_hash_table_lookup(glk_data->styles->text_buffer, "normal");
+               tag = g_hash_table_lookup(glk_data->styles->text_buffer, "default");
                break;
        default:
                return NULL;
        }
 
        PangoFontDescription *font;
-       g_object_get( G_OBJECT(normal), "font-desc", &font, NULL );
+       g_object_get( G_OBJECT(tag), "font-desc", &font, NULL );
 
        return font;
 }
index 7f0d1fc477e5a7e8e9d1b27434c3af33b69c02c2..b012c767bfbe91d5b0f7f9c613942246c426eba8 100644 (file)
  * background-color (#hex-value)
  * text-align (left/right/center)
  */
-grid.normal {
-       font-size: 10;
+grid {
+       font-size: 14;
+}
+
+buffer {
+       font-size: 14;
 }
 
 grid.user1 {
@@ -34,18 +38,12 @@ grid.user1 {
        background-color: #ffffff;
 }
 
-buffer.normal {
-       font-size: 10;
-}
-
 buffer.header {
-       font-size: 14;
        font-weight: bold;
        text-align: center;
 }
 
 buffer.subheader {
-       font-size: 12;
        font-weight: bold;
 }
 
index 0300609191e20023fe7ba45c99594dd6fcff52bf..5a55db20e75c0a57e615c2a82b56cfaf9cd92381 100644 (file)
@@ -29,7 +29,8 @@ test_close_SOURCES = test-close.c
 test_close_CFLAGS = @TEST_CFLAGS@ $(AM_CFLAGS)
 test_close_LDADD = @TEST_LIBS@ $(top_builddir)/libchimara/libchimara.la
 
-noinst_LTLIBRARIES = first.la model.la gridtest.la splittest.la multiwin.la styletest.la
+noinst_LTLIBRARIES = first.la model.la gridtest.la splittest.la multiwin.la \
+       styletest.la test-userstyle.la
 
 first_la_SOURCES = first.c
 first_la_LDFLAGS = $(TEST_PLUGIN_LIBTOOL_FLAGS)
@@ -48,3 +49,6 @@ multiwin_la_LDFLAGS = $(TEST_PLUGIN_LIBTOOL_FLAGS)
 
 styletest_la_SOURCES = styletest.c
 styletest_la_LDFLAGS = $(TEST_PLUGIN_LIBTOOL_FLAGS)
+
+test_userstyle_la_SOURCES = test-userstyle.c
+test_userstyle_la_LDFLAGS = $(TEST_PLUGIN_LIBTOOL_FLAGS)
index cb7189240a5d222a8351120c62f0fff355f94a5b..766305df5216a28a0d9eaf864ff1fcab4accbc17 100644 (file)
@@ -60,6 +60,7 @@ create_window(void)
     gtk_widget_set_size_request(window, 400, 400);
     g_signal_connect(window, "delete-event", G_CALLBACK(quit), NULL);
        glk = chimara_glk_new();
+       g_object_ref(glk);
        g_signal_connect(glk, "stopped", G_CALLBACK(gtk_main_quit), NULL);
        gtk_container_add(GTK_CONTAINER(window), glk);
 }
@@ -95,6 +96,7 @@ main(int argc, char *argv[])
 
        chimara_glk_stop(CHIMARA_GLK(glk));
        chimara_glk_wait(CHIMARA_GLK(glk));
+       g_object_unref(glk);
 
        return 0;
 }
diff --git a/tests/test-userstyle.c b/tests/test-userstyle.c
new file mode 100644 (file)
index 0000000..4f7b5f6
--- /dev/null
@@ -0,0 +1,25 @@
+#include <libchimara/glk.h>
+
+winid_t mainwin;
+
+void 
+glk_main(void)
+{
+       /* Create user style before creating windows */
+       glk_stylehint_set(wintype_AllTypes, style_User1, stylehint_Size, -1);
+       glk_stylehint_set(wintype_AllTypes, style_User2, stylehint_Size, +1);
+       
+       mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
+       if(!mainwin)
+               return;
+       glk_set_window(mainwin);
+
+       glk_set_style(style_User1);
+       glk_put_string("This text is in User1 and slightly smaller");
+       glk_set_style(style_Normal);
+       glk_put_string(".\n");
+       glk_set_style(style_User2);
+       glk_put_string("This text is in User2 and slightly larger");
+       glk_set_style(style_Normal);
+       glk_put_string(".\n");
+}