0aa4db282bccbcc031d3d4f9dccae2a6450d6b96
[rodin/chimara.git] / libchimara / style.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "chimara-glk-private.h"
4 #include "glk.h"
5 #include "style.h"
6 #include "magic.h"
7 #include "stream.h"
8 #include "strio.h"
9
10 extern GPrivate *glk_data_key;
11
12 static gboolean style_accept(GScanner *scanner, GTokenType token);
13 static gboolean style_accept_style_selector(GScanner *scanner, ChimaraGlk *glk);
14 static gboolean style_accept_style_hint(GScanner *scanner, GtkTextTag *current_tag);
15 static void style_add_tag_to_textbuffer(gpointer key, gpointer tag, gpointer tag_table);
16 static void style_copy_tag_to_textbuffer(gpointer key, gpointer tag, gpointer target_table);
17 static void text_tag_to_attr_list(GtkTextTag *tag, PangoAttrList *list);
18 GtkTextTag* gtk_text_tag_copy(GtkTextTag *tag);
19
20 /**
21  * glk_set_style:
22  * @styl: The style to apply
23  *
24  * Changes the style of the current output stream. @styl should be one of the
25  * <code>style_</code> constants. However, any value is actually legal; if the 
26  * interpreter does not recognize the style value, it will treat it as 
27  * %style_Normal.
28  * <note><para>
29  *  This policy allows for the future definition of styles without breaking old
30  *  Glk libraries.
31  * </para></note>
32  */
33 void
34 glk_set_style(glui32 styl)
35 {
36         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
37         g_return_if_fail(glk_data->current_stream != NULL);
38         glk_set_style_stream(glk_data->current_stream, styl);
39 }
40
41 static const gchar* TAG_NAMES[] = {
42         "default",
43         "normal",
44         "emphasized",
45         "preformatted",
46         "header",
47         "subheader",
48         "alert",
49         "note",
50         "block-quote",
51         "input",
52         "user1",
53         "user2",
54         "hyperlink",
55         "pager"
56 };
57
58 static const gchar* GLK_TAG_NAMES[] = {
59         "glk-normal",
60         "glk-emphasized",
61         "glk-preformatted",
62         "glk-header",
63         "glk-subheader",
64         "glk-alert",
65         "glk-note",
66         "glk-block-quote",
67         "glk-input",
68         "glk-user1",
69         "glk-user2"
70 };
71
72 const gchar**
73 style_get_tag_names()
74 {
75         return TAG_NAMES;
76 }
77
78 /* Internal function: mapping from style enum to tag name */
79 static const gchar*
80 get_tag_name(glui32 style)
81 {
82         if(style >= CHIMARA_NUM_STYLES) {
83                 WARNING("Unsupported style");
84                 return "normal";
85         } else {
86                 return (gchar*) TAG_NAMES[style];
87         }
88 }
89
90 /* Internal function: mapping from glk style enum to tag name */
91 static const gchar*
92 get_glk_tag_name(glui32 style)
93 {
94         if(style >= style_NUMSTYLES) {
95                 WARNING("Unsupported style");
96                 return "normal";
97         } else {
98                 return (gchar*) GLK_TAG_NAMES[style];
99         }
100 }
101
102 /** 
103  * glk_set_style_stream:
104  * @str: Output stream to change the style of
105  * @styl: The style to apply
106  *
107  * This changes the style of the stream @str. See glk_set_style().
108  */
109 void
110 glk_set_style_stream(strid_t str, glui32 styl) {
111         if(str->window == NULL)
112                 return;
113
114         flush_window_buffer(str->window);
115         str->style = (gchar*) get_tag_name(styl);
116         str->glk_style = (gchar*) get_glk_tag_name(styl);
117 }
118
119 /* Internal function: call this to initialize the layout of the 'more' prompt. */
120 void
121 style_init_more_prompt(winid_t win)
122 {
123         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
124
125         win->pager_layout = gtk_widget_create_pango_layout(win->widget, "More");
126         pango_layout_set_attributes(win->pager_layout, glk_data->pager_attr_list);
127 }
128
129 /* Internal function: call this to initialize the default styles to a textbuffer. */
130 void
131 style_init_textbuffer(GtkTextBuffer *buffer)
132 {
133         g_return_if_fail(buffer != NULL);
134
135         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
136
137         /* Place the default text tags in the textbuffer's tag table */
138         g_hash_table_foreach(glk_data->styles->text_buffer, style_add_tag_to_textbuffer, gtk_text_buffer_get_tag_table(buffer));
139
140         /* Copy the override text tags to the textbuffers's tag table */
141         g_hash_table_foreach(glk_data->glk_styles->text_buffer, style_copy_tag_to_textbuffer, gtk_text_buffer_get_tag_table(buffer));
142 }
143
144
145 /* Internal function: call this to initialize the default styles to a textgrid. */
146 void
147 style_init_textgrid(GtkTextBuffer *buffer)
148 {
149         g_return_if_fail(buffer != NULL);
150         
151         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
152
153         /* Place the default text tags in the textbuffer's tag table */
154         g_hash_table_foreach(glk_data->styles->text_grid, style_add_tag_to_textbuffer, gtk_text_buffer_get_tag_table(buffer));
155
156         /* Copy the current text tags to the textbuffers's tag table */
157         g_hash_table_foreach(glk_data->glk_styles->text_grid, style_copy_tag_to_textbuffer, gtk_text_buffer_get_tag_table(buffer));
158 }
159
160 /* Internal function used to iterate over the default text tag table, applying them to a textbuffer */
161 static void
162 style_add_tag_to_textbuffer(gpointer key, gpointer tag, gpointer tag_table)
163 {
164         g_return_if_fail(key != NULL);
165         g_return_if_fail(tag != NULL);
166         g_return_if_fail(tag_table != NULL);
167
168         gtk_text_tag_table_add(tag_table, tag);
169 }
170
171 /* Internal function used to iterate over a style table, copying it */
172 static void
173 style_copy_tag_to_textbuffer(gpointer key, gpointer tag, gpointer target_table)
174 {
175         g_return_if_fail(key != NULL);
176         g_return_if_fail(tag != NULL);
177         g_return_if_fail(target_table != NULL);
178
179         gtk_text_tag_table_add(target_table, gtk_text_tag_copy( GTK_TEXT_TAG(tag) ));
180 }
181
182 /* Internal function that copies a text tag */
183 GtkTextTag *
184 gtk_text_tag_copy(GtkTextTag *tag)
185 {
186         GtkTextTag *copy;
187
188         g_return_val_if_fail(tag != NULL, NULL);
189
190         copy = gtk_text_tag_new(tag->name);
191         gtk_text_attributes_copy_values(tag->values, copy->values);
192         
193         #define _COPY_FLAG(flag) copy->flag = tag->flag
194                 _COPY_FLAG (bg_color_set);
195                 _COPY_FLAG (bg_color_set);
196                 _COPY_FLAG (bg_stipple_set);
197                 _COPY_FLAG (fg_color_set);
198                 _COPY_FLAG (fg_stipple_set);
199                 _COPY_FLAG (justification_set);
200                 _COPY_FLAG (left_margin_set);
201                 _COPY_FLAG (indent_set);
202                 _COPY_FLAG (rise_set);
203                 _COPY_FLAG (strikethrough_set);
204                 _COPY_FLAG (right_margin_set);
205                 _COPY_FLAG (pixels_above_lines_set);
206                 _COPY_FLAG (pixels_below_lines_set);
207                 _COPY_FLAG (pixels_inside_wrap_set);
208                 _COPY_FLAG (tabs_set);
209                 _COPY_FLAG (underline_set);
210                 _COPY_FLAG (wrap_mode_set);
211                 _COPY_FLAG (bg_full_height_set);
212                 _COPY_FLAG (invisible_set);
213                 _COPY_FLAG (editable_set);
214                 _COPY_FLAG (language_set);
215         #undef _COPY_FLAG
216
217         /* Copy the data that was added manually */
218         gpointer reverse_color = g_object_get_data( G_OBJECT(tag), "reverse_color" );
219
220         if(reverse_color)
221                 g_object_set_data( G_OBJECT(copy), "reverse_color", reverse_color );
222
223         return copy;
224 }
225
226 /* Internal function that constructs the default styles */
227 void
228 style_init(ChimaraGlk *glk)
229 {
230         CHIMARA_GLK_USE_PRIVATE(glk, priv);
231         
232         GHashTable *default_text_grid_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
233         GHashTable *default_text_buffer_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
234         GHashTable *glk_text_grid_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
235         GHashTable *glk_text_buffer_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
236         GtkTextTag *tag;
237
238         PangoFontDescription *default_font_desc = pango_font_description_from_string("Serif");
239         PangoFontDescription *monospace_font_desc = pango_font_description_from_string("Monospace");
240         
241         /* Initialise the default styles for a text grid */
242         tag = gtk_text_tag_new("default");
243         g_object_set(tag, "font-desc", monospace_font_desc, NULL);
244         g_hash_table_insert(default_text_grid_styles, "default", tag);
245
246         tag = gtk_text_tag_new("normal");
247         //g_object_set(tag, "font-desc", monospace_font_desc, NULL);
248         g_hash_table_insert(default_text_grid_styles, "normal", tag);
249
250         tag = gtk_text_tag_new("emphasized");
251         //g_object_set(tag, "font-desc", monospace_font_desc, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
252         g_object_set(tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
253         g_hash_table_insert(default_text_grid_styles, "emphasized", tag);
254
255         tag = gtk_text_tag_new("preformatted");
256         g_object_set(tag, "font-desc", monospace_font_desc, NULL);
257         g_hash_table_insert(default_text_grid_styles, "preformatted", tag);
258
259         tag = gtk_text_tag_new("header");
260         //g_object_set(tag, "font-desc", monospace_font_desc, "weight", PANGO_WEIGHT_BOLD, NULL);
261         g_object_set(tag, "weight", PANGO_WEIGHT_BOLD, NULL);
262         g_hash_table_insert(default_text_grid_styles, "header", tag);
263
264         tag = gtk_text_tag_new("subheader");
265         //g_object_set(tag, "font-desc", monospace_font_desc, "weight", PANGO_WEIGHT_BOLD, NULL);
266         g_object_set(tag, "weight", PANGO_WEIGHT_BOLD, NULL);
267         g_hash_table_insert(default_text_grid_styles, "subheader", tag);
268
269         tag = gtk_text_tag_new("alert");
270         //g_object_set(tag, "font-desc", monospace_font_desc, "foreground", "#aa0000", "weight", PANGO_WEIGHT_BOLD, NULL);
271         g_object_set(tag, "foreground", "#aa0000", "weight", PANGO_WEIGHT_BOLD, NULL);
272         g_hash_table_insert(default_text_grid_styles, "alert", tag);
273
274         tag = gtk_text_tag_new("note");
275         //g_object_set(tag, "font-desc", monospace_font_desc, "foreground", "#aaaa00", "weight", PANGO_WEIGHT_BOLD, NULL);
276         g_object_set(tag, "foreground", "#aaaa00", "weight", PANGO_WEIGHT_BOLD, NULL);
277         g_hash_table_insert(default_text_grid_styles, "note", tag);
278
279         tag = gtk_text_tag_new("block-quote");
280         //g_object_set(tag, "font-desc", monospace_font_desc, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
281         g_object_set(tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
282         g_hash_table_insert(default_text_grid_styles, "block-quote", tag);
283
284         tag = gtk_text_tag_new("input");
285         //g_object_set(tag, "font-desc", monospace_font_desc, NULL);
286         g_hash_table_insert(default_text_grid_styles, "input", tag);
287
288         tag = gtk_text_tag_new("user1");
289         //g_object_set(tag, "font-desc", monospace_font_desc, NULL);
290         g_hash_table_insert(default_text_grid_styles, "user1", tag);
291
292         tag = gtk_text_tag_new("user2");
293         //g_object_set(tag, "font-desc", monospace_font_desc, NULL);
294         g_hash_table_insert(default_text_grid_styles, "user2", tag);
295
296         tag = gtk_text_tag_new("hyperlink");
297         g_object_set(tag, "foreground", "#0000ff", "underline", PANGO_UNDERLINE_SINGLE, "underline-set", TRUE, NULL);
298         g_hash_table_insert(default_text_grid_styles, "hyperlink", tag);
299
300         /* Initialise the default styles for a text buffer */
301         tag = gtk_text_tag_new("default");
302         g_object_set(tag, "font-desc", default_font_desc, NULL);
303         g_hash_table_insert(default_text_buffer_styles, "default", tag);
304
305         tag = gtk_text_tag_new("normal");
306         //g_object_set(tag, "font-desc", default_font_desc, NULL);
307         g_hash_table_insert(default_text_buffer_styles, "normal", tag);
308
309         tag = gtk_text_tag_new("emphasized");
310         //g_object_set(tag, "font-desc", default_font_desc, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
311         g_object_set(tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
312         g_hash_table_insert(default_text_buffer_styles, "emphasized", tag);
313
314         tag = gtk_text_tag_new("preformatted");
315         g_object_set(tag, "font-desc", monospace_font_desc, NULL);
316         g_hash_table_insert(default_text_buffer_styles, "preformatted", tag);
317
318         tag = gtk_text_tag_new("header");
319         //g_object_set(tag, "font-desc", default_font_desc, "size-points", 18.0, "weight", PANGO_WEIGHT_BOLD, NULL);
320         g_object_set(tag, "size-points", 18.0, "weight", PANGO_WEIGHT_BOLD, NULL);
321         g_hash_table_insert(default_text_buffer_styles, "header", tag);
322
323         tag = gtk_text_tag_new("subheader");
324         //g_object_set(tag, "font-desc", default_font_desc, "size-points", 14.0, "weight", PANGO_WEIGHT_BOLD, NULL);
325         g_object_set(tag, "size-points", 14.0, "weight", PANGO_WEIGHT_BOLD, NULL);
326         g_hash_table_insert(default_text_buffer_styles, "subheader", tag);
327
328         tag = gtk_text_tag_new("alert");
329         //g_object_set(tag, "font-desc", default_font_desc, "foreground", "#aa0000", "weight", PANGO_WEIGHT_BOLD, NULL);
330         g_object_set(tag, "foreground", "#aa0000", "weight", PANGO_WEIGHT_BOLD, NULL);
331         g_hash_table_insert(default_text_buffer_styles, "alert", tag);
332
333         tag = gtk_text_tag_new("note");
334         //g_object_set(tag, "font-desc", default_font_desc, "foreground", "#aaaa00", "weight", PANGO_WEIGHT_BOLD, NULL);
335         g_object_set(tag, "foreground", "#aaaa00", "weight", PANGO_WEIGHT_BOLD, NULL);
336         g_hash_table_insert(default_text_buffer_styles, "note", tag);
337
338         tag = gtk_text_tag_new("block-quote");
339         //g_object_set(tag, "font-desc", default_font_desc, "justification", GTK_JUSTIFY_CENTER, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
340         g_object_set(tag, "justification", GTK_JUSTIFY_CENTER, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
341         g_hash_table_insert(default_text_buffer_styles, "block-quote", tag);
342
343         tag = gtk_text_tag_new("input");
344         //g_object_set(tag, "font-desc", default_font_desc, NULL);
345         g_hash_table_insert(default_text_buffer_styles, "input", tag);
346
347         tag = gtk_text_tag_new("user1");
348         //g_object_set(tag, "font-desc", default_font_desc, NULL);
349         g_hash_table_insert(default_text_buffer_styles, "user1", tag);
350
351         tag = gtk_text_tag_new("user2");
352         //g_object_set(tag, "font-desc", default_font_desc, NULL);
353         g_hash_table_insert(default_text_buffer_styles, "user2", tag);
354
355         tag = gtk_text_tag_new("hyperlink");
356         //g_object_set(tag, "font-desc", default_font_desc, "foreground", "#0000ff", "underline", PANGO_UNDERLINE_SINGLE, "underline-set", TRUE, NULL);
357         g_object_set(tag, "foreground", "#0000ff", "underline", PANGO_UNDERLINE_SINGLE, "underline-set", TRUE, NULL);
358         g_hash_table_insert(default_text_buffer_styles, "hyperlink", tag);
359
360         GtkTextTag *pager_tag = gtk_text_tag_new("pager");
361         g_object_set(pager_tag, "font-desc", default_font_desc, "foreground", "#ffffff", "background", "#000000", NULL);
362         g_hash_table_insert(default_text_buffer_styles, "pager", pager_tag);
363         text_tag_to_attr_list(pager_tag, priv->pager_attr_list);
364
365         pango_font_description_free(default_font_desc);
366         pango_font_description_free(monospace_font_desc);
367         
368         priv->styles->text_grid = default_text_grid_styles;
369         priv->styles->text_buffer = default_text_buffer_styles;
370
371
372         /* Initialize the GLK styles to empty tags */
373         int i;
374         for(i=0; i<style_NUMSTYLES; i++) {
375                 tag = gtk_text_tag_new(GLK_TAG_NAMES[i]);
376                 g_hash_table_insert(glk_text_grid_styles, (gchar*) GLK_TAG_NAMES[i], tag);
377                 g_hash_table_insert(glk_text_buffer_styles, (gchar*) GLK_TAG_NAMES[i], tag);
378         }
379
380         priv->glk_styles->text_grid = glk_text_grid_styles;
381         priv->glk_styles->text_buffer = glk_text_buffer_styles;
382
383 }
384
385 /* Reset style tables to the library's internal defaults */
386 void
387 reset_default_styles(ChimaraGlk *glk)
388 {
389         /* TODO: write this function */
390 }
391
392 /* Copy the default styles to the current styles
393  FIXME: This function is temporary and will not be needed later on */
394 void
395 copy_default_styles_to_current_styles(ChimaraGlk *glk)
396 {
397         /*
398         CHIMARA_GLK_USE_PRIVATE(glk, priv);
399         g_hash_table_foreach(priv->styles->text_grid, style_table_copy, priv->glk_styles->text_grid);
400         g_hash_table_foreach(priv->styles->text_buffer, style_table_copy, priv->glk_styles->text_buffer);
401
402         GtkTextTag *pager_tag = GTK_TEXT_TAG( g_hash_table_lookup(priv->styles->text_buffer, "pager") );
403         text_tag_to_attr_list(pager_tag, priv->pager_attr_list);
404         */
405 }
406
407 /* Create the CSS file scanner */
408 GScanner *
409 create_css_file_scanner(void)
410 {
411         GScanner *scanner = g_scanner_new(NULL);
412         scanner->config->cset_identifier_first = G_CSET_a_2_z G_CSET_A_2_Z "#";
413         scanner->config->cset_identifier_nth = G_CSET_a_2_z G_CSET_A_2_Z "-_" G_CSET_DIGITS;
414         scanner->config->symbol_2_token = TRUE;
415         scanner->config->cpair_comment_single = NULL;
416         scanner->config->scan_float = FALSE;
417         return scanner;
418 }
419
420 /* Run the scanner over the CSS file, overriding the default styles */
421 void
422 scan_css_file(GScanner *scanner, ChimaraGlk *glk)
423 {
424         CHIMARA_GLK_USE_PRIVATE(glk, priv);
425
426         while( g_scanner_peek_next_token(scanner) != G_TOKEN_EOF) {
427                 if( !style_accept_style_selector(scanner, glk) )
428                         break;
429         }
430
431         g_scanner_destroy(scanner);
432
433         /* Update the pager prompt to the new style */
434         GtkTextTag *pager_tag = GTK_TEXT_TAG( g_hash_table_lookup(priv->styles->text_buffer, "pager") );
435         text_tag_to_attr_list(pager_tag, priv->pager_attr_list);
436 }
437
438 /* Internal function: parses a token */
439 static gboolean
440 style_accept(GScanner *scanner, GTokenType token)
441 {
442         GTokenType next = g_scanner_get_next_token(scanner);
443         if(next != token) {
444                 g_scanner_unexp_token(scanner, token, NULL, NULL, NULL, "CSS Error", 1);
445                 return FALSE;
446         }
447         return TRUE;
448 }
449
450 /* Internal function: parses a style selector */
451 static gboolean
452 style_accept_style_selector(GScanner *scanner, ChimaraGlk *glk)
453 {
454         CHIMARA_GLK_USE_PRIVATE(glk, priv);
455
456         GtkTextTag *current_tag;
457         gchar *field;
458         GTokenType token = g_scanner_get_next_token(scanner);
459         GTokenValue value = g_scanner_cur_value(scanner);
460
461         if(
462                 token != G_TOKEN_IDENTIFIER ||
463                 ( strcmp(value.v_identifier, "buffer") && strcmp(value.v_identifier, "grid") )
464         ) {
465                 g_scanner_error(scanner, "CSS Error: buffer/grid expected");
466                 return FALSE;
467         }
468
469         field = g_strdup(value.v_identifier);
470
471         /* Parse the tag name to change */
472         if( g_scanner_peek_next_token(scanner) == '{') {
473                 style_accept(scanner, '{');
474                 if( !strcmp(field, "buffer") )
475                         current_tag = g_hash_table_lookup(priv->styles->text_buffer, "default");
476                 else
477                         current_tag = g_hash_table_lookup(priv->styles->text_grid, "default");
478         } else {
479                 if( !style_accept(scanner, '.') )
480                         return FALSE;
481
482                 token = g_scanner_get_next_token(scanner);
483                 value = g_scanner_cur_value(scanner);
484
485                 if(token != G_TOKEN_IDENTIFIER) {
486                         g_scanner_error(scanner, "CSS Error: style selector expected");
487                         return FALSE;
488                 }
489
490                 if( !strcmp(field, "buffer") )
491                         current_tag = g_hash_table_lookup(priv->styles->text_buffer, value.v_identifier);
492                 else
493                         current_tag = g_hash_table_lookup(priv->styles->text_grid, value.v_identifier);
494
495                 if(current_tag == NULL) {
496                         g_scanner_error(scanner, "CSS Error: invalid style identifier");
497                         return FALSE;
498                 }
499
500                 if( !style_accept(scanner, '{') )
501                         return FALSE;
502         }
503
504         while( g_scanner_peek_next_token(scanner) != '}') {
505                 if( !style_accept_style_hint(scanner, current_tag) )
506                         return FALSE;
507         }
508                 
509         if( !style_accept(scanner, '}') )
510                 return FALSE;
511
512         return TRUE;
513 }
514
515 /* Internal function: parses a style hint */
516 static gboolean
517 style_accept_style_hint(GScanner *scanner, GtkTextTag *current_tag)
518 {
519         GTokenType token = g_scanner_get_next_token(scanner);
520         GTokenValue value = g_scanner_cur_value(scanner);
521         gchar *hint;
522
523         if(token != G_TOKEN_IDENTIFIER) {
524                 g_scanner_error(scanner, "CSS Error: style hint expected");
525                 return FALSE;
526         }
527
528         hint = g_strdup(value.v_identifier);
529
530         if( !style_accept(scanner, ':') )
531                 return FALSE;
532
533         token = g_scanner_get_next_token(scanner);
534         value = g_scanner_cur_value(scanner);
535
536         if( !strcmp(hint, "font-family") ) {
537                 if(token != G_TOKEN_STRING) {
538                         g_scanner_error(scanner, "CSS Error: string expected");
539                         return FALSE;
540                 }
541                 g_object_set(current_tag, "family", value.v_string, "family-set", TRUE, NULL);
542         }
543         else if( !strcmp(hint, "font-weight") ) {
544                 if(token != G_TOKEN_IDENTIFIER) {
545                         g_scanner_error(scanner, "CSS Error: bold/normal expected");
546                         return FALSE;
547                 }
548
549                 if( !strcmp(value.v_identifier, "bold") )
550                         g_object_set(current_tag, "weight", PANGO_WEIGHT_BOLD, "weight-set", TRUE, NULL);
551                 else if( !strcmp(value.v_identifier, "normal") )
552                         g_object_set(current_tag, "weight", PANGO_WEIGHT_NORMAL, "weight-set", TRUE, NULL);
553                 else {
554                         g_scanner_error(scanner, "CSS Error: bold/normal expected");
555                         return FALSE;
556                 }
557         }
558         else if( !strcmp(hint, "font-style") ) {
559                 if(token != G_TOKEN_IDENTIFIER) {
560                         g_scanner_error(scanner, "CSS Error: italic/normal expected");
561                         return FALSE;
562                 }
563
564                 if( !strcmp(value.v_identifier, "italic") )
565                         g_object_set(current_tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
566                 else if( !strcmp(value.v_identifier, "normal") )
567                         g_object_set(current_tag, "style", PANGO_STYLE_NORMAL, "style-set", TRUE, NULL);
568                 else {
569                         g_scanner_error(scanner, "CSS Error: italic/normal expected");
570                         return FALSE;
571                 }
572         }
573         else if( !strcmp(hint, "font-size") ) {
574                 if(token == G_TOKEN_INT) 
575                         g_object_set(current_tag, "size-points", (float)value.v_int, "size-set", TRUE, NULL);
576                 else if(token == G_TOKEN_FLOAT)
577                         g_object_set(current_tag, "size-points", value.v_float, "size-set", TRUE, NULL);
578                 else {
579                         g_scanner_error(scanner, "CSS Error: integer or float expected");
580                         return FALSE;
581                 }
582         }
583         else if( !strcmp(hint, "color") ) {
584                 if(token != G_TOKEN_IDENTIFIER) {
585                         g_scanner_error(scanner, "CSS Error: hex color expected");
586                         return FALSE;
587                 }
588
589                 g_object_set(current_tag, "foreground", value.v_identifier, "foreground-set", TRUE, NULL);
590         }
591         else if( !strcmp(hint, "background-color") ) {
592                 if(token != G_TOKEN_IDENTIFIER) {
593                         g_scanner_error(scanner, "CSS Error: hex color expected");
594                         return FALSE;
595                 }
596                 g_object_set(current_tag, "background", value.v_identifier, "background-set", TRUE, NULL);
597         }
598         else if( !strcmp(hint, "text-align") ) {
599                 if(token != G_TOKEN_IDENTIFIER) {
600                         g_scanner_error(scanner, "CSS Error: left/right/center expected");
601                         return FALSE;
602                 }
603                 
604                 if( !strcmp(value.v_identifier, "left") )
605                         g_object_set(current_tag, "justification", GTK_JUSTIFY_LEFT, "justification-set", TRUE, NULL);
606                 else if( !strcmp(value.v_identifier, "right") )
607                         g_object_set(current_tag, "justification", GTK_JUSTIFY_RIGHT, "justification-set", TRUE, NULL);
608                 else if( !strcmp(value.v_identifier, "center") )
609                         g_object_set(current_tag, "justification", GTK_JUSTIFY_CENTER, "justification-set", TRUE, NULL);
610                 else {
611                         g_scanner_error(scanner, "CSS Error: left/right/center expected");
612                         return FALSE;
613                 }
614         }
615         else if( !strcmp(hint, "margin-left") ) {
616                 if(token != G_TOKEN_INT) {
617                         g_scanner_error(scanner, "CSS Error: integer expected");
618                         return FALSE;
619                 }
620                 g_object_set(current_tag, "left-margin", value.v_int, "left-margin-set", TRUE, NULL);
621         }
622         else if( !strcmp(hint, "margin-right") ) {
623                 if(token != G_TOKEN_INT) {
624                         g_scanner_error(scanner, "CSS Error: integer expected");
625                         return FALSE;
626                 }
627                 g_object_set(current_tag, "right-margin", value.v_int, "right-margin-set", TRUE, NULL);
628         }
629         else if( !strcmp(hint, "margin-top") ) {
630                 if(token != G_TOKEN_INT) {
631                         g_scanner_error(scanner, "CSS Error: integer expected");
632                         return FALSE;
633                 }
634                 g_object_set(current_tag, "pixels-above-lines", value.v_int, "pixels-above-lines-set", TRUE, NULL);
635         }
636         else if( !strcmp(hint, "margin-bottom") ) {
637                 if(token != G_TOKEN_INT) {
638                         g_scanner_error(scanner, "CSS Error: integer expected");
639                         return FALSE;
640                 }
641                 g_object_set(current_tag, "pixels-below-lines", value.v_int, "pixels-below-lines-set", TRUE, NULL);
642         }
643                 
644         else {
645                 g_scanner_error(scanner, "CSS Error: invalid style hint %s", hint);
646                 return FALSE;
647         }
648
649         if( !style_accept(scanner, ';') )
650                 return FALSE;
651
652         return TRUE;
653 }
654
655 /* Internal function: parses a glk color to a #hex-value */
656 static void
657 glkcolor_to_hex(glui32 val, gchar *buffer)
658 {
659         g_return_if_fail(buffer != NULL);
660
661         sprintf(buffer, "#%02X%02X%02X",
662                 ((val & 0xff0000) >> 16),
663                 ((val & 0x00ff00) >> 8),
664                 (val & 0x0000ff)
665         );
666 }
667
668 /* Internal function: parses a glk color to a GdkColor */
669 void
670 glkcolor_to_gdkcolor(glui32 val, GdkColor *color)
671 {
672         color->red = 256 * ((val & 0xff0000) >> 16);
673         color->green = 256 * ((val & 0x00ff00) >> 8);
674         color->blue = 256 * (val & 0x0000ff);
675 }
676
677 /* Internal function: parses a GdkColor to a glk color */
678 static glui32
679 gdkcolor_to_glkcolor(GdkColor *color)
680 {
681         g_return_val_if_fail(color != NULL, 0);
682         return (glui32) color->pixel;
683 }
684
685 /* Internal function: changes a GTK tag to correspond with the given style. */
686 static void
687 apply_stylehint_to_tag(GtkTextTag *tag, GtkTextTag *default_tag, glui32 wintype, glui32 hint, glsi32 val)
688 {
689         g_return_if_fail(tag != NULL);
690
691         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
692         GObject *tag_object = G_OBJECT(tag);
693
694         gint reverse_color = GPOINTER_TO_INT( g_object_get_data(tag_object, "reverse-color") );
695
696         int i = 0;
697         gchar color[20];
698         switch(hint) {
699         case stylehint_Indentation:
700                 g_object_set(tag_object, "left-margin", 5*val, "left-margin-set", TRUE, NULL);
701                 g_object_set(tag_object, "right-margin", 5*val, "right-margin-set", TRUE, NULL);
702                 break;
703         
704         case stylehint_ParaIndentation:
705                 g_object_set(tag_object, "indent", 5*val, "indent-set", TRUE, NULL);
706                 break;
707
708         case stylehint_Justification:
709                 switch(val) {
710                         case stylehint_just_LeftFlush:  i = GTK_JUSTIFY_LEFT; break;
711                         case stylehint_just_LeftRight:  i = GTK_JUSTIFY_FILL; break;
712                         case stylehint_just_Centered:   i = GTK_JUSTIFY_CENTER; break;
713                         case stylehint_just_RightFlush: i = GTK_JUSTIFY_RIGHT; break;
714                         default: 
715                                 WARNING("Unknown justification");
716                                 i = GTK_JUSTIFY_LEFT;
717                 }
718                 g_object_set(tag_object, "justification", i, "justification-set", TRUE, NULL);
719                 break;
720
721         case stylehint_Weight:
722                 switch(val) {
723                         case -1: i = PANGO_WEIGHT_LIGHT; break;
724                         case  0: i = PANGO_WEIGHT_NORMAL; break;
725                         case  1: i = PANGO_WEIGHT_BOLD; break;
726                         default: WARNING("Unknown font weight");
727                 }
728                 g_object_set(tag_object, "weight", i, "weight-set", TRUE, NULL);
729                 break;
730
731         case stylehint_Size:
732                 g_object_set(tag_object, "size", 14+(2*val), "size-set", TRUE, NULL);
733                 break;
734
735         case stylehint_Oblique:
736                 g_object_set(tag_object, "style", val ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL, "style-set", TRUE, NULL);
737                 break;
738
739         case stylehint_Proportional:
740         {
741                 gchar *font_family;
742                 GtkTextTag *font_tag = g_hash_table_lookup(
743                     wintype == wintype_TextBuffer? glk_data->styles->text_buffer : glk_data->styles->text_grid,
744                     val? "normal" : "preformatted");
745                 g_object_get(font_tag, "family", &font_family, NULL);
746                 g_object_set(tag_object, "family", font_family, "family-set", TRUE, NULL);
747                 g_free(font_family);
748         }
749                 break;
750
751         case stylehint_TextColor:
752                 glkcolor_to_hex(val, color);
753
754                 if(!reverse_color)
755                         g_object_set(tag_object, "foreground", color, "foreground-set", TRUE, NULL);
756                 else
757                         g_object_set(tag_object, "background", color, "background-set", TRUE, NULL);
758
759                 break;
760
761         case stylehint_BackColor:
762                 glkcolor_to_hex(val, color);
763
764                 if(!reverse_color)
765                         g_object_set(tag_object, "background", color, "background-set", TRUE, NULL);
766                 else
767                         g_object_set(tag_object, "foreground", color, "background-set", TRUE, NULL);
768
769                 break;
770
771         case stylehint_ReverseColor:
772                 if(reverse_color != val) {
773                         /* Flip the fore- and background colors */
774                         GdkColor* foreground_color;
775                         GdkColor* background_color;
776                         gint f_set, b_set, df_set, db_set = 0;
777                         g_object_get(tag_object, "foreground-set", &f_set, "background-set", &b_set, NULL);
778                         g_object_get(default_tag, "foreground-set", &df_set, "background-set", &db_set, NULL);
779
780                         if(f_set)
781                                 g_object_get(tag_object, "foreground-gdk", &foreground_color, NULL);
782                         else if(df_set)
783                                 g_object_get(default_tag, "foreground-gdk", &foreground_color, NULL);
784                         if(b_set)
785                                 g_object_get(tag_object, "background-gdk", &background_color, NULL);
786                         else if(db_set)
787                                 g_object_get(default_tag, "background-gdk", &background_color, NULL);
788
789                         if(b_set || db_set)
790                                 g_object_set(tag_object, "foreground-gdk", background_color, NULL);
791                         else
792                                 g_object_set(tag_object, "foreground", "#ffffff", NULL);
793
794                         if(f_set || df_set)
795                                 g_object_set(tag_object, "background-gdk", foreground_color, NULL);
796                         else
797                                 g_object_set(tag_object, "background", "#000000", NULL);
798
799                         g_object_set_data( tag_object, "reverse-color", GINT_TO_POINTER(val != 0) );
800                 }
801                 break;
802
803         default:
804                 WARNING("Unknown style hint");
805         }
806 }
807
808 /* Internal function: queries a text tag for the value of a given style hint */
809 static gint
810 query_tag(GtkTextTag *tag, glui32 wintype, glui32 hint)
811 {
812         gint intval;
813         GdkColor *colval;
814
815         g_return_val_if_fail(tag != NULL, 0);
816
817         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
818
819         switch(hint) {
820         case stylehint_Indentation:
821                 g_object_get(tag, "left_margin", &intval, NULL);
822                 return intval/5;
823         
824         case stylehint_ParaIndentation:
825                 g_object_get(tag, "indent", &intval, NULL);
826                 return intval/5;
827
828         case stylehint_Justification:
829                 g_object_get(tag, "justification", &intval, NULL);
830                 switch(intval) {
831                         case GTK_JUSTIFY_LEFT: return stylehint_just_LeftFlush;
832                         case GTK_JUSTIFY_FILL: return stylehint_just_LeftRight;
833                         case GTK_JUSTIFY_CENTER: return stylehint_just_Centered;
834                         case GTK_JUSTIFY_RIGHT: return stylehint_just_RightFlush;
835                         default: 
836                                 WARNING("Unknown justification");
837                                 return stylehint_just_LeftFlush;
838                 }
839
840         case stylehint_Weight:
841                 g_object_get(tag, "weight", &intval, NULL);
842                 switch(intval) {
843                         case PANGO_WEIGHT_LIGHT: return -1;
844                         case PANGO_WEIGHT_NORMAL: return 0;
845                         case PANGO_WEIGHT_BOLD: return 1;
846                         default: WARNING("Unknown font weight"); return 0;
847                 }
848
849         case stylehint_Size:
850                 g_object_get(tag, "size", &intval, NULL);
851                 return (intval/2)-14;
852
853         case stylehint_Oblique:
854                 g_object_get(tag, "style", &intval , NULL);
855                 return intval == PANGO_STYLE_ITALIC ? 1 : 0;
856
857         case stylehint_Proportional:
858                 /* Use pango_font_family_is_monospace()? */
859         {
860                 gchar *font_family, *query_font_family;
861                 GtkTextTag *font_tag = g_hash_table_lookup(
862                     wintype == wintype_TextBuffer? glk_data->styles->text_buffer : glk_data->styles->text_grid,
863                     "preformatted");
864                 g_object_get(font_tag, "family", &font_family, NULL);
865                 g_object_get(tag, "family", &query_font_family, NULL);
866                 gint retval = strcmp(font_family, query_font_family)? 0 : 1;
867                 g_free(font_family);
868                 g_free(query_font_family);
869                 return retval;
870         }
871
872         case stylehint_TextColor:
873                 g_object_get(tag, "foreground-gdk", &colval, NULL);
874                 return gdkcolor_to_glkcolor(colval);
875
876         case stylehint_BackColor:
877                 g_object_get(tag, "background-gdk", &colval, NULL);
878                 return gdkcolor_to_glkcolor(colval);
879
880         case stylehint_ReverseColor:
881                 return GPOINTER_TO_INT( g_object_get_data(G_OBJECT(tag), "reverse_color") );
882
883         default:
884                 WARNING("Unknown style hint");
885         }
886         
887         return 0;
888 }
889
890 /**
891  * glk_stylehint_set:
892  * @wintype: The window type to set a style hint on, or %wintype_AllTypes.
893  * @styl: The style to set a hint for.
894  * @hint: The type of style hint, one of the <code>stylehint_</code> constants.
895  * @val: The style hint. The meaning of this depends on @hint.
896  *
897  * Sets a hint about the appearance of one style for a particular type of 
898  * window. You can also set @wintype to %wintype_AllTypes, which sets a hint for 
899  * all types of window.
900  * <note><para>
901  *  There is no equivalent constant to set a hint for all styles of a single 
902  *  window type.
903  * </para></note>
904  */
905 void
906 glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint, glsi32 val)
907 {
908         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
909
910         GtkTextTag *to_change, *default_tag;
911         if(wintype == wintype_TextBuffer || wintype == wintype_AllTypes) {
912                 to_change = g_hash_table_lookup( glk_data->glk_styles->text_buffer, get_glk_tag_name(styl) );
913                 default_tag = g_hash_table_lookup( glk_data->styles->text_buffer, get_tag_name(styl) );
914                 apply_stylehint_to_tag(to_change, default_tag, wintype_TextBuffer, hint, val);
915         }
916
917         if(wintype == wintype_TextGrid || wintype == wintype_AllTypes) {
918                 to_change = g_hash_table_lookup( glk_data->glk_styles->text_grid, get_glk_tag_name(styl) );
919                 default_tag = g_hash_table_lookup( glk_data->styles->text_grid, get_tag_name(styl) );
920                 apply_stylehint_to_tag(to_change, default_tag, wintype_TextGrid, hint, val);
921         }
922 }
923
924 /**
925  * glk_stylehint_clear:
926  * @wintype: The window type to set a style hint on, or %wintype_AllTypes.
927  * @styl: The style to set a hint for.
928  * @hint: The type of style hint, one of the <code>stylehint_</code> constants.
929  *
930  * Clears a hint about the appearance of one style for a particular type of 
931  * window to its default value. You can also set @wintype to %wintype_AllTypes, 
932  * which clears a hint for all types of window.
933  * <note><para>
934  *  There is no equivalent constant to reset a hint for all styles of a single 
935  *  window type.
936  * </para></note>
937  */
938 void
939 glk_stylehint_clear(glui32 wintype, glui32 styl, glui32 hint)
940 {
941         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
942         GtkTextTag *tag;
943
944         switch(wintype) {
945         case wintype_TextBuffer:
946                 tag = g_hash_table_lookup( glk_data->glk_styles->text_buffer, get_glk_tag_name(styl) );
947                 if(tag) {
948                         glk_stylehint_set( wintype, styl, hint, query_tag(tag, wintype, hint) );
949                 }
950                 break;
951         case wintype_TextGrid:
952                 tag = g_hash_table_lookup( glk_data->glk_styles->text_grid, get_glk_tag_name(styl) );
953                 if(tag) {
954                         glk_stylehint_set( wintype, styl, hint, query_tag(tag, wintype, hint) );
955                 }
956         default:
957                 return;
958         }
959 }
960
961 /**
962  * glk_style_distinguish:
963  * @win: The window in which the styles are to be distinguished.
964  * @styl1: The first style to be distinguished from the second style.
965  * @styl2: The second style to be distinguished from the first style.
966  * 
967  * Decides whether two styles are visually distinguishable in the given window.
968  * The exact meaning of this is left for the library to determine.
969  * <note><title>Chimara</title><para>
970  *   Currently, all styles of one window are assumed to be mutually
971  *   distinguishable.
972  * </para></note>
973  * 
974  * Returns: %TRUE (1) if the two styles are visually distinguishable. If they 
975  * are not, it returns %FALSE (0).
976  */
977 glui32
978 glk_style_distinguish(winid_t win, glui32 styl1, glui32 styl2)
979 {
980         /* FIXME */
981         return styl1 != styl2;
982 }
983
984 /**
985  * glk_style_measure:
986  * @win: The window from which to take the style.
987  * @styl: The style to perform the measurement on.
988  * @hint: The stylehint to measure.
989  * @result: Address to write the result to.
990  * 
991  * Tries to test an attribute of one style in the given window @win. The library
992  * may not be able to determine the attribute; if not, this returns %FALSE (0).
993  * If it can, it returns %TRUE (1) and stores the value in the location pointed
994  * at by @result. 
995  * <note><para>
996  *   As usual, it is legal for @result to be %NULL, although fairly pointless.
997  * </para></note>
998  *
999  * The meaning of the value depends on the hint which was tested:
1000  * <variablelist>
1001  * <varlistentry>
1002  *   <term>%stylehint_Indentation, %stylehint_ParaIndentation</term>
1003  *   <listitem><para>The indentation and paragraph indentation. These are in a
1004  *   metric which is platform-dependent.</para>
1005  *   <note><para>Most likely either characters or pixels.</para></note>
1006  *   </listitem>
1007  * </varlistentry>
1008  * <varlistentry>
1009  *   <term>%stylehint_Justification</term>
1010  *   <listitem><para>One of the constants %stylehint_just_LeftFlush,
1011  *   %stylehint_just_LeftRight, %stylehint_just_Centered, or
1012  *   %stylehint_just_RightFlush.</para></listitem>
1013  * </varlistentry>
1014  * <varlistentry>
1015  *   <term>%stylehint_Size</term>
1016  *   <listitem><para>The font size. Again, this is in a platform-dependent
1017  *   metric.</para>
1018  *   <note><para>Pixels, points, or simply 1 if the library does not support
1019  *   varying font sizes.</para></note>
1020  *   </listitem>
1021  * </varlistentry>
1022  * <varlistentry>
1023  *   <term>%stylehint_Weight</term>
1024  *   <listitem><para>1 for heavy-weight fonts (boldface), 0 for normal weight,
1025  *   and -1 for light-weight fonts.</para></listitem>
1026  * </varlistentry>
1027  * <varlistentry>
1028  *   <term>%stylehint_Oblique</term>
1029  *   <listitem><para>1 for oblique fonts (italic), or 0 for normal angle.</para>
1030  *   </listitem>
1031  * </varlistentry>
1032  * <varlistentry>
1033  *   <term>%stylehint_Proportional</term>
1034  *   <listitem><para>1 for proportional-width fonts, or 0 for fixed-width.
1035  *   </para></listitem>
1036  * </varlistentry>
1037  * <varlistentry>
1038  *   <term>%stylehint_TextColor, %stylehint_BackColor</term>
1039  *   <listitem><para>These are values from 0x00000000 to 0x00FFFFFF, encoded as
1040  *   described in <link 
1041  *   linkend="chimara-Suggesting-the-Appearance-of-Styles">Suggesting the
1042  *   Appearance of Styles</link>.</para></listitem>
1043  * </varlistentry>
1044  * <varlistentry>
1045  *   <term>%stylehint_ReverseColor</term>
1046  *   <listitem><para>0 for normal printing, 1 if the foreground and background
1047  *   colors are reversed.</para></listitem>
1048  * </varlistentry>
1049  * </variablelist>
1050  * 
1051  * Returns: TRUE upon successul retrieval, otherwise FALSE.
1052  */
1053 glui32
1054 glk_style_measure(winid_t win, glui32 styl, glui32 hint, glui32 *result)
1055 {
1056         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
1057         GtkTextTag *tag;
1058
1059         switch(win->type) {
1060         case wintype_TextBuffer:
1061                 tag = g_hash_table_lookup( glk_data->glk_styles->text_buffer, get_glk_tag_name(styl) );
1062                 if(result)
1063                         *result = query_tag(tag, win->type, hint);
1064                 break;
1065         case wintype_TextGrid:
1066                 tag = g_hash_table_lookup( glk_data->glk_styles->text_grid, get_glk_tag_name(styl) );
1067                 if(result)
1068                         *result = query_tag(tag, win->type, hint);
1069         default:
1070                 return FALSE;
1071         }
1072
1073         return TRUE;
1074 }
1075
1076 /* Internal function returning the current default font for a window type
1077  * This can be used later for size calculations. Only wintype_TextGrid and wintype_TextBuffer are
1078  * supported for now */
1079 PangoFontDescription *
1080 get_current_font(guint32 wintype)
1081 {
1082         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
1083         GtkTextTag *normal;
1084
1085         switch(wintype) {
1086         case wintype_TextGrid:
1087                 normal = g_hash_table_lookup(glk_data->styles->text_grid, "normal");
1088                 break;
1089         case wintype_TextBuffer:
1090                 normal = g_hash_table_lookup(glk_data->styles->text_buffer, "normal");
1091                 break;
1092         default:
1093                 return NULL;
1094         }
1095
1096         PangoFontDescription *font;
1097         g_object_get( G_OBJECT(normal), "font-desc", &font, NULL );
1098
1099         return font;
1100 }
1101
1102 /* Internal function copying the attributes of a text tag to a pango attribute list */
1103 static void
1104 text_tag_to_attr_list(GtkTextTag *tag, PangoAttrList *list)
1105 {
1106         gboolean set;
1107         GdkColor *foreground, *background;
1108         gchar *string;
1109         PangoFontDescription *font_desc;
1110         gboolean strikethrough;
1111         PangoUnderline underline;
1112
1113         g_object_get(tag, "foreground-set", &set, "foreground-gdk", &foreground, NULL);
1114         if(set) {
1115                 pango_attr_list_insert(
1116                         list,
1117                         pango_attr_foreground_new(foreground->red, foreground->green, foreground->blue)
1118                 );
1119         }
1120         g_object_get(tag, "background-set", &set, "background-gdk", &background, NULL);
1121         if(set) {
1122                 pango_attr_list_insert(
1123                         list,
1124                         pango_attr_background_new(background->red, background->green, background->blue)
1125                 );
1126         }
1127         g_object_get(tag, "language-set", &set, "language", &string, NULL);
1128         if(set) {
1129                 pango_attr_list_insert(
1130                         list,
1131                         pango_attr_language_new( pango_language_from_string(string) )
1132                 );
1133         }
1134
1135         /* Font description updates the following properties simultaniously:
1136          * family, style, weight, variant, stretch, size
1137          */
1138         g_object_get(tag, "font-desc", &font_desc, NULL);
1139         pango_attr_list_insert(
1140                 list,
1141                 pango_attr_font_desc_new(font_desc)
1142         );
1143
1144         g_object_get(tag, "strikethrough-set", &set, "strikethrough", &strikethrough, NULL);
1145         if(set) {
1146                 pango_attr_list_insert(
1147                         list,
1148                         pango_attr_strikethrough_new(strikethrough)
1149                 );
1150         }
1151         g_object_get(tag, "underline-set", &set, "underline", &underline, NULL);
1152         if(set) {
1153                 pango_attr_list_insert(
1154                         list,
1155                         pango_attr_underline_new(underline)
1156                 );
1157         }
1158 }
1159
1160 /* Update pager and reverse video tags */
1161 void
1162 style_update(ChimaraGlk *glk)
1163 {
1164         CHIMARA_GLK_USE_PRIVATE(glk, priv);
1165
1166         GtkTextTag *pager_tag = GTK_TEXT_TAG( g_hash_table_lookup(priv->styles->text_buffer, "pager") );
1167         text_tag_to_attr_list(pager_tag, priv->pager_attr_list);
1168 }