+
+/* Update pager tag */
+void
+style_update(ChimaraGlk *glk)
+{
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+
+ GtkTextTag *pager_tag = GTK_TEXT_TAG( g_hash_table_lookup(priv->styles->text_buffer, "pager") );
+ text_tag_to_attr_list(pager_tag, priv->pager_attr_list);
+}
+
+/* Determine the current colors used to render the text for a given stream.
+ * This can be set in a number of places */
+static void
+style_cascade_colors(GtkTextTag *tag, GtkTextTag *glk_tag, GtkTextTag *default_tag, GdkColor **foreground, GdkColor **background)
+{
+ gboolean foreground_set = FALSE;
+ gboolean background_set = FALSE;
+ gint reverse_color;
+
+ // Default color
+ reverse_color = GPOINTER_TO_INT( g_object_get_data(G_OBJECT(default_tag), "reverse-color") );
+ g_object_get(default_tag, "foreground-set", &foreground_set, "background-set", &background_set, NULL);
+ if(foreground_set)
+ g_object_get(default_tag, "foreground-gdk", reverse_color ? background:foreground, NULL);
+ if(background_set)
+ g_object_get(default_tag, "background-gdk", reverse_color ? foreground:background, NULL);
+
+ // Player defined color
+ reverse_color = GPOINTER_TO_INT( g_object_get_data(G_OBJECT(tag), "reverse-color") );
+ g_object_get(tag, "foreground-set", &foreground_set, "background-set", &background_set, NULL);
+ if(foreground_set)
+ g_object_get(tag, "foreground-gdk", reverse_color ? background:foreground, NULL);
+ if(background_set)
+ g_object_get(tag, "background-gdk", reverse_color ? foreground:background, NULL);
+
+ // GLK defined color
+ reverse_color = GPOINTER_TO_INT( g_object_get_data(G_OBJECT(glk_tag), "reverse-color") );
+ g_object_get(glk_tag, "foreground-set", &foreground_set, "background-set", &background_set, NULL);
+ if(foreground_set)
+ g_object_get(glk_tag, "foreground-gdk", reverse_color ? background:foreground, NULL);
+ if(background_set)
+ g_object_get(glk_tag, "background-gdk", reverse_color ? foreground:background, NULL);
+
+}
+
+/* Determine the current colors used to render the text for a given stream.
+ * This can be set in a number of places */
+void
+style_stream_colors(strid_t str, GdkColor **foreground, GdkColor **background)
+{
+ VALID_STREAM(str, return);
+ g_return_if_fail(str->window != NULL);
+ g_return_if_fail(str->window->type != wintype_TextBuffer || str->window->type != wintype_TextGrid);
+
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(str->window->widget) );
+ GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
+ GtkTextTag* default_tag = gtk_text_tag_table_lookup(tags, "default");
+ GtkTextTag* tag = gtk_text_tag_table_lookup(tags, str->style);
+ GtkTextTag* glk_tag = gtk_text_tag_table_lookup(tags, str->glk_style);
+
+ style_cascade_colors(tag, glk_tag, default_tag, foreground, background);
+
+ gboolean foreground_set, background_set;
+
+ // Windows can have zcolors defined
+ if(str->window->zcolor) {
+ g_object_get(str->window->zcolor, "foreground-set", &foreground_set, "background-set", &background_set, NULL);
+ if(foreground_set)
+ g_object_get(str->window->zcolor, "foreground-gdk", foreground, NULL);
+ if(background_set)
+ g_object_get(str->window->zcolor, "background-gdk", background, NULL);
+ }
+}
+
+/* Apply styles to a segment of text in a GtkTextBuffer, combining multiple
+ * GtkTextTags.
+ */
+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);
+ }
+}
+