Fix stylehint size bug
authorPhilip Chimento <philip.chimento@gmail.com>
Wed, 5 Jan 2011 19:19:50 +0000 (14:19 -0500)
committerPhilip Chimento <philip.chimento@gmail.com>
Wed, 5 Jan 2011 19:19:50 +0000 (14:19 -0500)
The "size" stylehint should use the GtkTextTag "scale" property, not
the "size" property - this way, the relative size is independent of the
default font size. The bug was that the "size" property should be given
in Pango units, not points, but now the "size" property isn't used at
all.

libchimara/style.c
tests/test-userstyle.c

index 9779a37e2c474ebf9ad0c6022e88637ee41ff70b..f7bce7f9a625a0f6f503928e7f4d4e5b7067c811 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 */
@@ -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:
@@ -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);
index c3a32c465f75f3af6e381abf56fb5420b0f283c2..4f7b5f66087a41893b91df297db9e615da0a2481 100644 (file)
@@ -7,7 +7,7 @@ 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, 0);
+       glk_stylehint_set(wintype_AllTypes, style_User2, stylehint_Size, +1);
        
        mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
        if(!mainwin)
@@ -19,7 +19,7 @@ glk_main(void)
        glk_set_style(style_Normal);
        glk_put_string(".\n");
        glk_set_style(style_User2);
-       glk_put_string("This test is in User2 at normal size");
+       glk_put_string("This text is in User2 and slightly larger");
        glk_set_style(style_Normal);
        glk_put_string(".\n");
 }