Merge branch 'master' of ssh://git.stderr.nl/projects/chimara/chimara
[projects/chimara/chimara.git] / libchimara / style.c
index f94407152dec4b71c1e235af088fe9d0944101d0..dc0d4bb942acb13d4e73ddbeeca3bac7131e1f4f 100644 (file)
@@ -1120,19 +1120,21 @@ get_current_font(guint32 wintype)
        text_tag_to_attr_list( g_hash_table_lookup(styles, "default"), list );
        PangoAttrIterator *it = pango_attr_list_get_iterator(list);
        pango_attr_iterator_get_font(it, font, NULL, NULL);
+       pango_attr_iterator_destroy(it);
 
        text_tag_to_attr_list( g_hash_table_lookup(styles, "normal"), list );
        it = pango_attr_list_get_iterator(list);
        pango_attr_iterator_get_font(it, font, NULL, NULL);
+       pango_attr_iterator_destroy(it);
 
        text_tag_to_attr_list( g_hash_table_lookup(glk_styles, "glk-normal"), list );
        it = pango_attr_list_get_iterator(list);
        pango_attr_iterator_get_font(it, font, NULL, NULL);
+       pango_attr_iterator_destroy(it);
 
        /* Make a copy of the family, preventing it's destruction at the end of this function. */
        pango_font_description_set_family( font, pango_font_description_get_family(font) );
 
-       pango_attr_iterator_destroy(it);
        pango_attr_list_unref(list);
 
        return font;
@@ -1270,3 +1272,44 @@ style_stream_colors(strid_t str, GdkColor **foreground, GdkColor **background)
                        g_object_get(str->window->zcolor, "background-gdk", background, NULL);
        }
 }
+
+/* Apply styles to a segment of text in a GtkTextBuffer
+ */
+void
+style_apply(winid_t win, GtkTextIter *start, GtkTextIter *end)
+{
+       GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
+       GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
+
+       GtkTextTag *default_tag = gtk_text_tag_table_lookup(tags, "default");
+       GtkTextTag *style_tag = gtk_text_tag_table_lookup(tags, win->window_stream->style);
+       GtkTextTag *glk_style_tag = gtk_text_tag_table_lookup(tags, win->window_stream->glk_style);
+
+       // Player's style overrides
+       gtk_text_buffer_apply_tag(buffer, style_tag, start, end);
+
+       // GLK Program's style overrides
+       gtk_text_buffer_apply_tag(buffer, glk_style_tag, start, end);
+
+       // Default style
+       gtk_text_buffer_apply_tag(buffer, default_tag, start, end);
+
+       // Link style overrides
+       if(win->window_stream->hyperlink_mode) {
+               GtkTextTag *link_style_tag = gtk_text_tag_table_lookup(tags, "hyperlink");
+               GtkTextTag *link_tag = win->current_hyperlink->tag;
+               gtk_text_buffer_apply_tag(buffer, link_style_tag, start, end);
+               gtk_text_buffer_apply_tag(buffer, link_tag, start, end);
+       }
+
+       // GLK Program's style overrides using garglk_set_zcolors()
+       if(win->zcolor != NULL) {
+               gtk_text_buffer_apply_tag(buffer, win->zcolor, start, end);
+       }
+
+       // GLK Program's style overrides using garglk_set_reversevideo()
+       if(win->zcolor_reversed != NULL) {
+               gtk_text_buffer_apply_tag(buffer, win->zcolor_reversed, start, end);
+       }
+}
+