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)
{
/* 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);
}
#include <stdio.h>
#include <string.h>
+#include <math.h>
#include "chimara-glk-private.h"
#include "glk.h"
#include "style.h"
_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 */
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");
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:
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);
query_tag(GtkTextTag *tag, glui32 wintype, glui32 hint)
{
gint intval;
+ gdouble doubleval;
GdkColor *colval;
g_return_val_if_fail(tag != NULL, 0);
}
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);
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;
}
--- /dev/null
+#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");
+}