4 #include "chimara-glk-private.h"
11 extern GPrivate *glk_data_key;
13 static gboolean style_accept(GScanner *scanner, GTokenType token);
14 static gboolean style_accept_style_selector(GScanner *scanner);
15 static gboolean style_accept_style_hint(GScanner *scanner, GtkTextTag *current_tag);
16 static void style_add_tag_to_textbuffer(gpointer key, gpointer tag, gpointer tag_table);
17 static void style_table_copy(gpointer key, gpointer tag, gpointer target_table);
18 GtkTextTag* gtk_text_tag_copy(GtkTextTag *tag);
22 * @styl: The style to apply
24 * Changes the style of the current output stream. @styl should be one of the
25 * <code>style_</code> constants listed above. However, any value is actually
26 * legal; if the interpreter does not recognize the style value, it will treat
27 * it as %style_Normal.
29 * This policy allows for the future definition of styles without breaking old
34 glk_set_style(glui32 styl)
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);
41 static const gchar* TAG_NAMES[] = {
55 /* Internal function: mapping from style enum to tag name */
57 get_tag_name(glui32 style)
59 if(style >= style_NUMSTYLES) {
60 WARNING("Unsupported style");
63 return (gchar*) TAG_NAMES[style];
68 * glk_set_style_stream:
69 * @str: Output stream to change the style of
70 * @styl: The style to apply
72 * This changes the style of the stream @str. See glk_set_style().
75 glk_set_style_stream(strid_t str, glui32 styl) {
76 if(str->window == NULL)
79 flush_window_buffer(str->window);
80 str->style = get_tag_name(styl);
83 /* Internal function: call this to initialize the default styles to a textbuffer. */
85 style_init_textbuffer(GtkTextBuffer *buffer)
87 g_return_if_fail(buffer != NULL);
89 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
90 if( G_UNLIKELY(!glk_data->style_initialized) ) {
94 /* Copy the current text tags to the textbuffer's tag table */
95 g_hash_table_foreach(glk_data->current_styles->text_buffer, style_add_tag_to_textbuffer, gtk_text_buffer_get_tag_table(buffer));
98 /* Internal function: call this to initialize the default styles to a textgrid. */
100 style_init_textgrid(GtkTextBuffer *buffer)
102 g_return_if_fail(buffer != NULL);
104 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
105 if( G_UNLIKELY(!glk_data->style_initialized) ) {
109 /* Copy the current text tags to the textgrid's tag table */
110 g_hash_table_foreach(glk_data->current_styles->text_grid, style_add_tag_to_textbuffer, gtk_text_buffer_get_tag_table(buffer));
113 /* Internal function used to iterate over the default text tag table, applying them to a textbuffer */
115 style_add_tag_to_textbuffer(gpointer key, gpointer tag, gpointer tag_table)
117 gtk_text_tag_table_add( tag_table, gtk_text_tag_copy(tag) );
120 /* Internal function used to iterate over a style table, copying it */
122 style_table_copy(gpointer key, gpointer tag, gpointer target_table)
124 g_return_if_fail(key != NULL);
125 g_return_if_fail(tag != NULL);
126 g_return_if_fail(target_table != NULL);
128 g_hash_table_insert(target_table, key, gtk_text_tag_copy( GTK_TEXT_TAG(tag) ));
131 /* Internal function that copies a text tag */
133 gtk_text_tag_copy(GtkTextTag *tag)
137 g_return_val_if_fail(tag != NULL, NULL);
139 copy = gtk_text_tag_new(tag->name);
140 gtk_text_attributes_copy_values(tag->values, copy->values);
142 #define _COPY_FLAG(flag) copy->flag = tag->flag
143 _COPY_FLAG (bg_color_set);
144 _COPY_FLAG (bg_color_set);
145 _COPY_FLAG (bg_stipple_set);
146 _COPY_FLAG (fg_color_set);
147 _COPY_FLAG (fg_stipple_set);
148 _COPY_FLAG (justification_set);
149 _COPY_FLAG (left_margin_set);
150 _COPY_FLAG (indent_set);
151 _COPY_FLAG (rise_set);
152 _COPY_FLAG (strikethrough_set);
153 _COPY_FLAG (right_margin_set);
154 _COPY_FLAG (pixels_above_lines_set);
155 _COPY_FLAG (pixels_below_lines_set);
156 _COPY_FLAG (pixels_inside_wrap_set);
157 _COPY_FLAG (tabs_set);
158 _COPY_FLAG (underline_set);
159 _COPY_FLAG (wrap_mode_set);
160 _COPY_FLAG (bg_full_height_set);
161 _COPY_FLAG (invisible_set);
162 _COPY_FLAG (editable_set);
163 _COPY_FLAG (language_set);
166 /* Copy the data that was added manually */
167 gpointer reverse_color = g_object_get_data( G_OBJECT(tag), "reverse_color" );
170 g_object_set_data( G_OBJECT(copy), "reverse_color", reverse_color );
175 /* Internal function that reads the default styles from a CSS file */
179 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
180 GHashTable *default_text_grid_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
181 GHashTable *default_text_buffer_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
182 GHashTable *current_text_grid_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
183 GHashTable *current_text_buffer_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
186 /* Initialise the default styles for a text grid */
187 tag = gtk_text_tag_new("normal");
188 g_object_set(tag, "font-desc", glk_data->monospace_font_desc, NULL);
189 g_hash_table_insert(default_text_grid_styles, "normal", tag);
191 tag = gtk_text_tag_new("emphasized");
192 g_object_set(tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
193 g_hash_table_insert(default_text_grid_styles, "emphasized", tag);
195 tag = gtk_text_tag_new("preformatted");
196 g_object_set(tag, "font-desc", glk_data->monospace_font_desc, NULL);
197 g_hash_table_insert(default_text_grid_styles, "preformatted", tag);
199 tag = gtk_text_tag_new("header");
200 g_object_set(tag, "weight", PANGO_WEIGHT_BOLD, NULL);
201 g_hash_table_insert(default_text_grid_styles, "header", tag);
203 tag = gtk_text_tag_new("subheader");
204 g_object_set(tag, "weight", PANGO_WEIGHT_BOLD, NULL);
205 g_hash_table_insert(default_text_grid_styles, "subheader", tag);
207 tag = gtk_text_tag_new("alert");
208 g_object_set(tag, "foreground", "#aa0000", "weight", PANGO_WEIGHT_BOLD, NULL);
209 g_hash_table_insert(default_text_grid_styles, "alert", tag);
211 tag = gtk_text_tag_new("note");
212 g_object_set(tag, "foreground", "#aaaa00", "weight", PANGO_WEIGHT_BOLD, NULL);
213 g_hash_table_insert(default_text_grid_styles, "note", tag);
215 tag = gtk_text_tag_new("block-quote");
216 g_object_set(tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
217 g_hash_table_insert(default_text_grid_styles, "block-quote", tag);
219 g_hash_table_insert(default_text_grid_styles, "input", gtk_text_tag_new("input"));
220 g_hash_table_insert(default_text_grid_styles, "user1", gtk_text_tag_new("user1"));
221 g_hash_table_insert(default_text_grid_styles, "user2", gtk_text_tag_new("user2"));
223 tag = gtk_text_tag_new("hyperlink");
224 g_object_set(tag, "foreground", "#0000ff", "underline", PANGO_UNDERLINE_SINGLE, "underline-set", TRUE, NULL);
225 g_hash_table_insert(default_text_grid_styles, "hyperlink", tag);
227 /* Tags for the textbuffer */
228 tag = gtk_text_tag_new("normal");
229 g_object_set(tag, "font-desc", glk_data->default_font_desc, NULL);
230 g_hash_table_insert(default_text_buffer_styles, "normal", tag);
232 tag = gtk_text_tag_new("emphasized");
233 g_object_set(tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
234 g_hash_table_insert(default_text_buffer_styles, "emphasized", tag);
236 tag = gtk_text_tag_new("preformatted");
237 g_object_set(tag, "font-desc", glk_data->monospace_font_desc, NULL);
238 g_hash_table_insert(default_text_buffer_styles, "preformatted", tag);
240 tag = gtk_text_tag_new("header");
241 g_object_set(tag, "size-points", 18.0, "weight", PANGO_WEIGHT_BOLD, NULL);
242 g_hash_table_insert(default_text_buffer_styles, "header", tag);
244 tag = gtk_text_tag_new("subheader");
245 g_object_set(tag, "size-points", 14.0, "weight", PANGO_WEIGHT_BOLD, NULL);
246 g_hash_table_insert(default_text_buffer_styles, "subheader", tag);
248 tag = gtk_text_tag_new("alert");
249 g_object_set(tag, "foreground", "#aa0000", "weight", PANGO_WEIGHT_BOLD, NULL);
250 g_hash_table_insert(default_text_buffer_styles, "alert", tag);
252 tag = gtk_text_tag_new("note");
253 g_object_set(tag, "foreground", "#aaaa00", "weight", PANGO_WEIGHT_BOLD, NULL);
254 g_hash_table_insert(default_text_buffer_styles, "note", tag);
256 tag = gtk_text_tag_new("block-quote");
257 g_object_set(tag, "justification", GTK_JUSTIFY_CENTER, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
258 g_hash_table_insert(default_text_buffer_styles, "block-quote", tag);
260 g_hash_table_insert(default_text_buffer_styles, "input", gtk_text_tag_new("input"));
261 g_hash_table_insert(default_text_buffer_styles, "user1", gtk_text_tag_new("user1"));
262 g_hash_table_insert(default_text_buffer_styles, "user2", gtk_text_tag_new("user2"));
264 tag = gtk_text_tag_new("hyperlink");
265 g_object_set(tag, "foreground", "#0000ff", "underline", PANGO_UNDERLINE_SINGLE, "underline-set", TRUE, NULL);
266 g_hash_table_insert(default_text_buffer_styles, "hyperlink", tag);
268 glk_data->default_styles->text_grid = default_text_grid_styles;
269 glk_data->default_styles->text_buffer = default_text_buffer_styles;
271 /* Create the CSS file scanner */
272 GScanner *scanner = g_scanner_new(NULL);
274 int f = open(glk_data->css_file, O_RDONLY);
277 g_scanner_input_file(scanner, f);
278 scanner->input_name = glk_data->css_file;
279 scanner->config->cset_identifier_first = G_CSET_a_2_z G_CSET_A_2_Z "#";
280 scanner->config->cset_identifier_nth = G_CSET_a_2_z G_CSET_A_2_Z "-_" G_CSET_DIGITS;
281 scanner->config->symbol_2_token = TRUE;
282 scanner->config->cpair_comment_single = NULL;
283 scanner->config->scan_float = FALSE;
285 /* Run the scanner over the CSS file, overriding defaults */
286 while( g_scanner_peek_next_token(scanner) != G_TOKEN_EOF) {
287 if( !style_accept_style_selector(scanner) )
291 g_scanner_destroy(scanner);
294 g_warning("Could not find CSS file");
296 /* Set the current style to a copy of the default style */
297 g_hash_table_foreach(default_text_grid_styles, style_table_copy, current_text_grid_styles);
298 g_hash_table_foreach(default_text_buffer_styles, style_table_copy, current_text_buffer_styles);
299 glk_data->current_styles->text_grid = current_text_grid_styles;
300 glk_data->current_styles->text_buffer = current_text_buffer_styles;
302 glk_data->style_initialized = TRUE;
305 /* Internal function: parses a token */
307 style_accept(GScanner *scanner, GTokenType token)
309 GTokenType next = g_scanner_get_next_token(scanner);
311 g_scanner_unexp_token(scanner, token, NULL, NULL, NULL, "CSS Error", 1);
318 /* Internal function: parses a style selector */
320 style_accept_style_selector(GScanner *scanner)
322 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
324 GtkTextTag *current_tag;
326 GTokenType token = g_scanner_get_next_token(scanner);
327 GTokenValue value = g_scanner_cur_value(scanner);
330 token != G_TOKEN_IDENTIFIER ||
331 ( strcmp(value.v_identifier, "buffer") && strcmp(value.v_identifier, "grid") )
333 g_scanner_error(scanner, "CSS Error: buffer/grid expected");
337 field = g_strdup(value.v_identifier);
339 if( !style_accept(scanner, '.') )
342 token = g_scanner_get_next_token(scanner);
343 value = g_scanner_cur_value(scanner);
345 if(token != G_TOKEN_IDENTIFIER) {
346 g_scanner_error(scanner, "CSS Error: style selector expected");
350 if( !strcmp(field, "buffer") )
351 current_tag = g_hash_table_lookup(glk_data->default_styles->text_buffer, value.v_identifier);
353 current_tag = g_hash_table_lookup(glk_data->default_styles->text_grid, value.v_identifier);
355 if(current_tag == NULL) {
356 g_scanner_error(scanner, "CSS Error: invalid style identifier");
360 if( !style_accept(scanner, '{') )
363 while( g_scanner_peek_next_token(scanner) != '}') {
364 if( !style_accept_style_hint(scanner, current_tag) )
368 if( !style_accept(scanner, '}') )
374 /* Internal function: parses a style hint */
376 style_accept_style_hint(GScanner *scanner, GtkTextTag *current_tag)
378 GTokenType token = g_scanner_get_next_token(scanner);
379 GTokenValue value = g_scanner_cur_value(scanner);
382 if(token != G_TOKEN_IDENTIFIER) {
383 g_scanner_error(scanner, "CSS Error: style hint expected");
387 hint = g_strdup(value.v_identifier);
389 if( !style_accept(scanner, ':') )
392 token = g_scanner_get_next_token(scanner);
393 value = g_scanner_cur_value(scanner);
395 if( !strcmp(hint, "font-family") ) {
396 if(token != G_TOKEN_STRING) {
397 g_scanner_error(scanner, "CSS Error: string expected");
400 g_object_set(current_tag, "family", value.v_string, "family-set", TRUE, NULL);
402 else if( !strcmp(hint, "font-weight") ) {
403 if(token != G_TOKEN_IDENTIFIER) {
404 g_scanner_error(scanner, "CSS Error: bold/normal expected");
408 if( !strcmp(value.v_identifier, "bold") )
409 g_object_set(current_tag, "weight", PANGO_WEIGHT_BOLD, "weight-set", TRUE, NULL);
410 else if( !strcmp(value.v_identifier, "normal") )
411 g_object_set(current_tag, "weight", PANGO_WEIGHT_NORMAL, "weight-set", TRUE, NULL);
413 g_scanner_error(scanner, "CSS Error: bold/normal expected");
417 else if( !strcmp(hint, "font-style") ) {
418 if(token != G_TOKEN_IDENTIFIER) {
419 g_scanner_error(scanner, "CSS Error: italic/normal expected");
423 if( !strcmp(value.v_identifier, "italic") )
424 g_object_set(current_tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
425 else if( !strcmp(value.v_identifier, "normal") )
426 g_object_set(current_tag, "style", PANGO_STYLE_NORMAL, "style-set", TRUE, NULL);
428 g_scanner_error(scanner, "CSS Error: italic/normal expected");
432 else if( !strcmp(hint, "font-size") ) {
433 if(token == G_TOKEN_INT)
434 g_object_set(current_tag, "size-points", (float)value.v_int, "size-set", TRUE, NULL);
435 else if(token == G_TOKEN_FLOAT)
436 g_object_set(current_tag, "size-points", value.v_float, "size-set", TRUE, NULL);
438 g_scanner_error(scanner, "CSS Error: integer or float expected");
442 else if( !strcmp(hint, "color") ) {
443 if(token != G_TOKEN_IDENTIFIER) {
444 g_scanner_error(scanner, "CSS Error: hex color expected");
448 g_object_set(current_tag, "foreground", value.v_identifier, "foreground-set", TRUE, NULL);
450 else if( !strcmp(hint, "background-color") ) {
451 if(token != G_TOKEN_IDENTIFIER) {
452 g_scanner_error(scanner, "CSS Error: hex color expected");
455 g_object_set(current_tag, "background", value.v_identifier, "background-set", TRUE, NULL);
457 else if( !strcmp(hint, "text-align") ) {
458 if(token != G_TOKEN_IDENTIFIER) {
459 g_scanner_error(scanner, "CSS Error: left/right/center expected");
463 if( !strcmp(value.v_identifier, "left") )
464 g_object_set(current_tag, "justification", GTK_JUSTIFY_LEFT, "justification-set", TRUE, NULL);
465 else if( !strcmp(value.v_identifier, "right") )
466 g_object_set(current_tag, "justification", GTK_JUSTIFY_RIGHT, "justification-set", TRUE, NULL);
467 else if( !strcmp(value.v_identifier, "center") )
468 g_object_set(current_tag, "justification", GTK_JUSTIFY_CENTER, "justification-set", TRUE, NULL);
470 g_scanner_error(scanner, "CSS Error: left/right/center expected");
474 else if( !strcmp(hint, "margin-left") ) {
475 if(token != G_TOKEN_INT) {
476 g_scanner_error(scanner, "CSS Error: integer expected");
479 g_object_set(current_tag, "left-margin", value.v_int, "left-margin-set", TRUE, NULL);
481 else if( !strcmp(hint, "margin-right") ) {
482 if(token != G_TOKEN_INT) {
483 g_scanner_error(scanner, "CSS Error: integer expected");
486 g_object_set(current_tag, "right-margin", value.v_int, "right-margin-set", TRUE, NULL);
488 else if( !strcmp(hint, "margin-top") ) {
489 if(token != G_TOKEN_INT) {
490 g_scanner_error(scanner, "CSS Error: integer expected");
493 g_object_set(current_tag, "pixels-above-lines", value.v_int, "pixels-above-lines-set", TRUE, NULL);
495 else if( !strcmp(hint, "margin-bottom") ) {
496 if(token != G_TOKEN_INT) {
497 g_scanner_error(scanner, "CSS Error: integer expected");
500 g_object_set(current_tag, "pixels-below-lines", value.v_int, "pixels-below-lines-set", TRUE, NULL);
504 g_scanner_error(scanner, "CSS Error: invalid style hint %s", hint);
508 if( !style_accept(scanner, ';') )
514 /* Internal function: parses a glk color to a #hex-value */
516 color_format(glui32 val, gchar *buffer)
518 g_return_if_fail(buffer != NULL);
520 sprintf(buffer, "#%02X%02X%02X",
521 ((val & 0xff0000) >> 16),
522 ((val & 0x00ff00) >> 8),
527 /* Internal function: parses a GdkColor to a glk color */
529 color_parse_gdk(GdkColor *color)
531 g_return_val_if_fail(color != NULL, 0);
532 return (glui32) color->pixel;
535 /* Internal function: changes a GTK tag to correspond with the given style. */
537 apply_stylehint_to_tag(GtkTextTag *tag, glui32 hint, glsi32 val)
539 g_return_if_fail(tag != NULL);
541 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
542 GObject *tag_object = G_OBJECT(tag);
544 gint reverse_color = GPOINTER_TO_INT( g_object_get_data(tag_object, "reverse-color") );
549 case stylehint_Indentation:
550 g_object_set(tag_object, "left-margin", 5*val, "left-margin-set", TRUE, NULL);
551 g_object_set(tag_object, "right-margin", 5*val, "right-margin-set", TRUE, NULL);
554 case stylehint_ParaIndentation:
555 g_object_set(tag_object, "indent", 5*val, "indent-set", TRUE, NULL);
558 case stylehint_Justification:
560 case stylehint_just_LeftFlush: i = GTK_JUSTIFY_LEFT; break;
561 case stylehint_just_LeftRight: i = GTK_JUSTIFY_FILL; break;
562 case stylehint_just_Centered: i = GTK_JUSTIFY_CENTER; break;
563 case stylehint_just_RightFlush: i = GTK_JUSTIFY_RIGHT; break;
565 WARNING("Unknown justification");
566 i = GTK_JUSTIFY_LEFT;
568 g_object_set(tag_object, "justification", i, "justification-set", TRUE, NULL);
571 case stylehint_Weight:
573 case -1: i = PANGO_WEIGHT_LIGHT; break;
574 case 0: i = PANGO_WEIGHT_NORMAL; break;
575 case 1: i = PANGO_WEIGHT_BOLD; break;
576 default: WARNING("Unknown font weight");
578 g_object_set(tag_object, "weight", i, "weight-set", TRUE, NULL);
582 g_object_set(tag_object, "size", 14+(2*val), "size-set", TRUE, NULL);
585 case stylehint_Oblique:
586 g_object_set(tag_object, "style", val ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL, "style-set", TRUE, NULL);
589 case stylehint_Proportional:
590 g_object_set(tag_object, "font-desc", val ? glk_data->default_font_desc : glk_data->monospace_font_desc, NULL);
593 case stylehint_TextColor:
594 color_format(val, color);
597 g_object_set(tag_object, "foreground", color, "foreground-set", TRUE, NULL);
599 g_object_set(tag_object, "background", color, "background-set", TRUE, NULL);
603 case stylehint_BackColor:
604 color_format(val, color);
607 g_object_set(tag_object, "background", color, "background-set", TRUE, NULL);
609 g_object_set(tag_object, "foreground", color, "background-set", TRUE, NULL);
613 case stylehint_ReverseColor:
614 if(reverse_color != val) {
615 /* Flip the fore- and background colors */
616 GdkColor* foreground_color;
617 GdkColor* background_color;
618 gint f_set, b_set = 0;
619 g_object_get(tag_object, "foreground-set", &f_set, "background-set", &b_set, NULL);
622 g_object_get(tag_object, "foreground-gdk", &foreground_color, NULL);
624 g_object_get(tag_object, "background-gdk", &background_color, NULL);
627 g_object_set(tag_object, "foreground-gdk", background_color, NULL);
629 g_object_set(tag_object, "foreground", "#ffffff", NULL);
632 g_object_set(tag_object, "background-gdk", foreground_color, NULL);
634 g_object_set(tag_object, "background", "#000000", NULL);
636 g_object_set_data( tag_object, "reverse-color", GINT_TO_POINTER(val != 0) );
641 WARNING("Unknown style hint");
644 /*Internal function: queries a text tag for the value of a given style hint */
646 query_tag(GtkTextTag *tag, glui32 hint)
652 g_return_val_if_fail(tag != NULL, 0);
654 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
657 case stylehint_Indentation:
658 g_object_get(tag, "left_margin", &intval, NULL);
662 case stylehint_ParaIndentation:
663 g_object_get(tag, "indent", &intval, NULL);
667 case stylehint_Justification:
668 g_object_get(tag, "justification", &intval, NULL);
670 case GTK_JUSTIFY_LEFT: return stylehint_just_LeftFlush; break;
671 case GTK_JUSTIFY_FILL: return stylehint_just_LeftRight; break;
672 case GTK_JUSTIFY_CENTER: return stylehint_just_Centered; break;
673 case GTK_JUSTIFY_RIGHT: return stylehint_just_RightFlush; break;
675 WARNING("Unknown justification");
676 return stylehint_just_LeftFlush;
680 case stylehint_Weight:
681 g_object_get(tag, "weight", &intval, NULL);
683 case PANGO_WEIGHT_LIGHT: return -1; break;
684 case PANGO_WEIGHT_NORMAL: return 0; break;
685 case PANGO_WEIGHT_BOLD: return 1; break;
686 default: WARNING("Unknown font weight"); return 0;
691 g_object_get(tag, "size", &intval, NULL);
692 return (intval/2)-14;
695 case stylehint_Oblique:
696 g_object_get(tag, "style", &intval , NULL);
697 return intval == PANGO_STYLE_ITALIC ? 1 : 0;
700 case stylehint_Proportional:
701 g_object_get(tag, "font-desc", &objval, NULL);
702 return objval == (GObject *)glk_data->monospace_font_desc ? 0 : 1;
705 case stylehint_TextColor:
706 g_object_get(tag, "foreground-gdk", &colval, NULL);
707 return color_parse_gdk(colval);
710 case stylehint_BackColor:
711 g_object_get(tag, "background-gdk", &colval, NULL);
712 return color_parse_gdk(colval);
715 case stylehint_ReverseColor:
716 return GPOINTER_TO_INT( g_object_get_data(G_OBJECT(tag), "reverse_color") );
720 WARNING("Unknown style hint");
728 * @wintype: The window type to set a style hint on, or %wintype_AllTypes.
729 * @styl: The style to set a hint for.
730 * @hint: The type of style hint, one of the <code>stylehint_</code> constants.
731 * @val: The style hint. The meaning of this depends on @hint.
733 * Sets a hint about the appearance of one style for a particular type of
734 * window. You can also set wintype to %wintype_AllTypes, which sets a hint for
735 * all types of window.
737 * There is no equivalent constant to set a hint for all styles of a single
742 glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint, glsi32 val)
744 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
746 if( G_UNLIKELY(!glk_data->style_initialized) ) {
750 GtkTextTag *to_change;
751 if(wintype == wintype_TextBuffer || wintype == wintype_AllTypes) {
752 to_change = g_hash_table_lookup( glk_data->current_styles->text_buffer, get_tag_name(styl) );
753 apply_stylehint_to_tag(to_change, hint, val);
756 if(wintype == wintype_TextGrid || wintype == wintype_AllTypes) {
757 to_change = g_hash_table_lookup( glk_data->current_styles->text_grid, get_tag_name(styl) );
758 apply_stylehint_to_tag(to_change, hint, val);
763 * glk_stylehint_clear:
764 * @wintype: The window type to set a style hint on, or %wintype_AllTypes.
765 * @styl: The style to set a hint for.
766 * @hint: The type of style hint, one of the <code>stylehint_</code> constants.
768 * Resets a hint about the appearance of one style for a particular type of
769 * window to it's default value. You can also set wintype to %wintype_AllTypes, which resets a hint for
770 * all types of window.
772 * There is no equivalent constant to reset a hint for all styles of a single
777 glk_stylehint_clear(glui32 wintype, glui32 styl, glui32 hint)
779 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
783 case wintype_TextBuffer:
784 tag = g_hash_table_lookup( glk_data->default_styles->text_buffer, get_tag_name(styl) );
785 glk_stylehint_set( wintype, styl, hint, query_tag(tag, hint) );
787 case wintype_TextGrid:
788 tag = g_hash_table_lookup( glk_data->default_styles->text_grid, get_tag_name(styl) );
789 glk_stylehint_set( wintype, styl, hint, query_tag(tag, hint) );
796 * glk_style_distinguish:
797 * @win: The window in which the styles are to be distinguished.
798 * @styl1: The first style to be distinguished from the second style.
799 * @styl2: The second styel to be distinguished from the first style.
801 * Returns: TRUE if the two styles are visually distinguishable in the given window.
802 * If they are not, it returns FALSE.
805 glk_style_distinguish(winid_t win, glui32 styl1, glui32 styl2)
807 return styl1 != styl2;
812 * @win: The window from which to take the style.
813 * @styl: The style to perform the measurement on.
814 * @hint: The stylehint to measure.
815 * @result: Address to write the result to.
817 * This function can be used to query the current value of a particular style hint.
818 * Returns: TRUE upon successul retrievel, otherwise FALSE.
821 glk_style_measure(winid_t win, glui32 styl, glui32 hint, glui32 *result)
823 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
827 case wintype_TextBuffer:
828 tag = g_hash_table_lookup( glk_data->current_styles->text_buffer, get_tag_name(styl) );
829 *result = query_tag(tag, hint);
831 case wintype_TextGrid:
832 tag = g_hash_table_lookup( glk_data->current_styles->text_grid, get_tag_name(styl) );
833 *result = query_tag(tag, hint);
841 /* Internal function returning the current default font for a window type
842 * This can be used later for size calculations. Only wintype_TextGrid and wintype_TextBuffer are
843 * supported for now */
844 PangoFontDescription*
845 get_current_font(guint32 wintype)
847 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
850 if( G_UNLIKELY(!glk_data->style_initialized) ) {
855 case wintype_TextGrid:
856 normal = g_hash_table_lookup(glk_data->current_styles->text_grid, "normal");
858 case wintype_TextBuffer:
859 normal = g_hash_table_lookup(glk_data->current_styles->text_buffer, "normal");
865 PangoFontDescription *font;
866 g_object_get( G_OBJECT(normal), "font-desc", &font, NULL );