5 extern GPrivate *glk_data_key;
7 static gboolean style_accept(GScanner *scanner, GTokenType token);
8 static gboolean style_accept_style_selector(GScanner *scanner);
9 static gboolean style_accept_style_hint(GScanner *scanner, GtkTextTag *current_tag);
10 static void style_add_tag_to_textbuffer(gpointer key, gpointer tag, gpointer tag_table);
11 static void style_table_copy(gpointer key, gpointer tag, gpointer target_table);
12 GtkTextTag* gtk_text_tag_copy(GtkTextTag *tag);
16 * @styl: The style to apply
18 * Changes the style of the current output stream. @styl should be one of the
19 * <code>style_</code> constants listed above. However, any value is actually
20 * legal; if the interpreter does not recognize the style value, it will treat
21 * it as %style_Normal.
23 * This policy allows for the future definition of styles without breaking old
28 glk_set_style(glui32 styl)
30 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
31 g_return_if_fail(glk_data->current_stream != NULL);
32 glk_set_style_stream(glk_data->current_stream, styl);
35 static const gchar* TAG_NAMES[] = {
49 /* Internal function: mapping from style enum to tag name */
51 get_tag_name(glui32 style)
53 if(style >= style_NUMSTYLES) {
54 WARNING("Unsupported style");
57 return (gchar*) TAG_NAMES[style];
62 * glk_set_style_stream:
63 * @str: Output stream to change the style of
64 * @styl: The style to apply
66 * This changes the style of the stream @str. See glk_set_style().
69 glk_set_style_stream(strid_t str, glui32 styl) {
70 if(str->window == NULL)
73 flush_window_buffer(str->window);
74 str->style = get_tag_name(styl);
77 /* Internal function: call this to initialize the default styles to a textbuffer. */
79 style_init_textbuffer(GtkTextBuffer *buffer)
81 g_return_if_fail(buffer != NULL);
83 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
84 if( G_UNLIKELY(!glk_data->style_initialized) ) {
88 /* Copy the current text tags to the textbuffer's tag table */
89 g_hash_table_foreach(glk_data->current_styles->text_buffer, style_add_tag_to_textbuffer, gtk_text_buffer_get_tag_table(buffer));
92 /* Internal function: call this to initialize the default styles to a textgrid. */
94 style_init_textgrid(GtkTextBuffer *buffer)
96 g_return_if_fail(buffer != NULL);
98 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
99 if( G_UNLIKELY(!glk_data->style_initialized) ) {
103 /* Copy the current text tags to the textgrid's tag table */
104 g_hash_table_foreach(glk_data->current_styles->text_grid, style_add_tag_to_textbuffer, gtk_text_buffer_get_tag_table(buffer));
107 /* Internal function used to iterate over the default text tag table, applying them to a textbuffer */
109 style_add_tag_to_textbuffer(gpointer key, gpointer tag, gpointer tag_table)
111 gtk_text_tag_table_add( tag_table, gtk_text_tag_copy(tag) );
114 /* Internal function used to iterate over a style table, copying it */
116 style_table_copy(gpointer key, gpointer tag, gpointer target_table)
118 g_return_if_fail(key != NULL);
119 g_return_if_fail(tag != NULL);
120 g_return_if_fail(target_table != NULL);
122 g_hash_table_insert(target_table, key, gtk_text_tag_copy( GTK_TEXT_TAG(tag) ));
125 /* Internal function that copies a text tag */
127 gtk_text_tag_copy(GtkTextTag *tag)
131 g_return_val_if_fail(tag != NULL, NULL);
133 copy = gtk_text_tag_new(tag->name);
134 gtk_text_attributes_copy_values(tag->values, copy->values);
136 #define _COPY_FLAG(flag) copy->flag = tag->flag
137 _COPY_FLAG (bg_color_set);
138 _COPY_FLAG (bg_color_set);
139 _COPY_FLAG (bg_stipple_set);
140 _COPY_FLAG (fg_color_set);
141 _COPY_FLAG (fg_stipple_set);
142 _COPY_FLAG (justification_set);
143 _COPY_FLAG (left_margin_set);
144 _COPY_FLAG (indent_set);
145 _COPY_FLAG (rise_set);
146 _COPY_FLAG (strikethrough_set);
147 _COPY_FLAG (right_margin_set);
148 _COPY_FLAG (pixels_above_lines_set);
149 _COPY_FLAG (pixels_below_lines_set);
150 _COPY_FLAG (pixels_inside_wrap_set);
151 _COPY_FLAG (tabs_set);
152 _COPY_FLAG (underline_set);
153 _COPY_FLAG (wrap_mode_set);
154 _COPY_FLAG (bg_full_height_set);
155 _COPY_FLAG (invisible_set);
156 _COPY_FLAG (editable_set);
157 _COPY_FLAG (language_set);
160 /* Copy the data that was added manually */
161 gpointer reverse_color = g_object_get_data( G_OBJECT(tag), "reverse_color" );
164 g_object_set_data( G_OBJECT(copy), "reverse_color", reverse_color );
169 /* Internal function that reads the default styles from a CSS file */
173 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
174 GHashTable *default_text_grid_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
175 GHashTable *default_text_buffer_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
176 GHashTable *current_text_grid_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
177 GHashTable *current_text_buffer_styles = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
180 /* Initialise the default styles for a text grid */
181 tag = gtk_text_tag_new("normal");
182 g_object_set(tag, "font-desc", glk_data->monospace_font_desc, NULL);
183 g_hash_table_insert(default_text_grid_styles, "normal", tag);
185 tag = gtk_text_tag_new("emphasized");
186 g_object_set(tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
187 g_hash_table_insert(default_text_grid_styles, "emphasized", tag);
189 tag = gtk_text_tag_new("preformatted");
190 g_object_set(tag, "font-desc", glk_data->monospace_font_desc, NULL);
191 g_hash_table_insert(default_text_grid_styles, "preformatted", tag);
193 tag = gtk_text_tag_new("header");
194 g_object_set(tag, "weight", PANGO_WEIGHT_BOLD, NULL);
195 g_hash_table_insert(default_text_grid_styles, "header", tag);
197 tag = gtk_text_tag_new("subheader");
198 g_object_set(tag, "weight", PANGO_WEIGHT_BOLD, NULL);
199 g_hash_table_insert(default_text_grid_styles, "subheader", tag);
201 tag = gtk_text_tag_new("alert");
202 g_object_set(tag, "foreground", "#aa0000", "weight", PANGO_WEIGHT_BOLD, NULL);
203 g_hash_table_insert(default_text_grid_styles, "alert", tag);
205 tag = gtk_text_tag_new("note");
206 g_object_set(tag, "foreground", "#aaaa00", "weight", PANGO_WEIGHT_BOLD, NULL);
207 g_hash_table_insert(default_text_grid_styles, "note", tag);
209 tag = gtk_text_tag_new("block-quote");
210 g_object_set(tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
211 g_hash_table_insert(default_text_grid_styles, "block-quote", tag);
213 g_hash_table_insert(default_text_grid_styles, "input", gtk_text_tag_new("input"));
214 g_hash_table_insert(default_text_grid_styles, "user1", gtk_text_tag_new("user1"));
215 g_hash_table_insert(default_text_grid_styles, "user2", gtk_text_tag_new("user2"));
217 tag = gtk_text_tag_new("hyperlink");
218 g_object_set(tag, "foreground", "#0000ff", "underline", PANGO_UNDERLINE_SINGLE, "underline-set", TRUE, NULL);
219 g_hash_table_insert(default_text_grid_styles, "hyperlink", tag);
221 /* Tags for the textbuffer */
222 tag = gtk_text_tag_new("normal");
223 g_object_set(tag, "font-desc", glk_data->default_font_desc, NULL);
224 g_hash_table_insert(default_text_buffer_styles, "normal", tag);
226 tag = gtk_text_tag_new("emphasized");
227 g_object_set(tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
228 g_hash_table_insert(default_text_buffer_styles, "emphasized", tag);
230 tag = gtk_text_tag_new("preformatted");
231 g_object_set(tag, "font-desc", glk_data->monospace_font_desc, NULL);
232 g_hash_table_insert(default_text_buffer_styles, "preformatted", tag);
234 tag = gtk_text_tag_new("header");
235 g_object_set(tag, "size-points", 18.0, "weight", PANGO_WEIGHT_BOLD, NULL);
236 g_hash_table_insert(default_text_buffer_styles, "header", tag);
238 tag = gtk_text_tag_new("subheader");
239 g_object_set(tag, "size-points", 14.0, "weight", PANGO_WEIGHT_BOLD, NULL);
240 g_hash_table_insert(default_text_buffer_styles, "subheader", tag);
242 tag = gtk_text_tag_new("alert");
243 g_object_set(tag, "foreground", "#aa0000", "weight", PANGO_WEIGHT_BOLD, NULL);
244 g_hash_table_insert(default_text_buffer_styles, "alert", tag);
246 tag = gtk_text_tag_new("note");
247 g_object_set(tag, "foreground", "#aaaa00", "weight", PANGO_WEIGHT_BOLD, NULL);
248 g_hash_table_insert(default_text_buffer_styles, "note", tag);
250 tag = gtk_text_tag_new("block-quote");
251 g_object_set(tag, "justification", GTK_JUSTIFY_CENTER, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
252 g_hash_table_insert(default_text_buffer_styles, "block-quote", tag);
254 g_hash_table_insert(default_text_buffer_styles, "input", gtk_text_tag_new("input"));
255 g_hash_table_insert(default_text_buffer_styles, "user1", gtk_text_tag_new("user1"));
256 g_hash_table_insert(default_text_buffer_styles, "user2", gtk_text_tag_new("user2"));
258 tag = gtk_text_tag_new("hyperlink");
259 g_object_set(tag, "foreground", "#0000ff", "underline", PANGO_UNDERLINE_SINGLE, "underline-set", TRUE, NULL);
260 g_hash_table_insert(default_text_buffer_styles, "hyperlink", tag);
262 glk_data->default_styles->text_grid = default_text_grid_styles;
263 glk_data->default_styles->text_buffer = default_text_buffer_styles;
265 /* Create the CSS file scanner */
266 GScanner *scanner = g_scanner_new(NULL);
268 int f = open(glk_data->css_file, O_RDONLY);
271 g_scanner_input_file(scanner, f);
272 scanner->input_name = glk_data->css_file;
273 scanner->config->cset_identifier_first = G_CSET_a_2_z G_CSET_A_2_Z "#";
274 scanner->config->cset_identifier_nth = G_CSET_a_2_z G_CSET_A_2_Z "-_" G_CSET_DIGITS;
275 scanner->config->symbol_2_token = TRUE;
276 scanner->config->cpair_comment_single = NULL;
277 scanner->config->scan_float = FALSE;
279 /* Run the scanner over the CSS file, overriding defaults */
280 while( g_scanner_peek_next_token(scanner) != G_TOKEN_EOF) {
281 if( !style_accept_style_selector(scanner) )
285 g_scanner_destroy(scanner);
288 g_warning("Could not find CSS file");
290 /* Set the current style to a copy of the default style */
291 g_hash_table_foreach(default_text_grid_styles, style_table_copy, current_text_grid_styles);
292 g_hash_table_foreach(default_text_buffer_styles, style_table_copy, current_text_buffer_styles);
293 glk_data->current_styles->text_grid = current_text_grid_styles;
294 glk_data->current_styles->text_buffer = current_text_buffer_styles;
296 glk_data->style_initialized = TRUE;
299 /* Internal function: parses a token */
301 style_accept(GScanner *scanner, GTokenType token)
303 GTokenType next = g_scanner_get_next_token(scanner);
305 g_scanner_unexp_token(scanner, token, NULL, NULL, NULL, "CSS Error", 1);
312 /* Internal function: parses a style selector */
314 style_accept_style_selector(GScanner *scanner)
316 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
318 GtkTextTag *current_tag;
320 GTokenType token = g_scanner_get_next_token(scanner);
321 GTokenValue value = g_scanner_cur_value(scanner);
324 token != G_TOKEN_IDENTIFIER ||
325 ( strcmp(value.v_identifier, "buffer") && strcmp(value.v_identifier, "grid") )
327 g_scanner_error(scanner, "CSS Error: buffer/grid expected");
331 field = g_strdup(value.v_identifier);
333 if( !style_accept(scanner, '.') )
336 token = g_scanner_get_next_token(scanner);
337 value = g_scanner_cur_value(scanner);
339 if(token != G_TOKEN_IDENTIFIER) {
340 g_scanner_error(scanner, "CSS Error: style selector expected");
344 if( !strcmp(field, "buffer") )
345 current_tag = g_hash_table_lookup(glk_data->default_styles->text_buffer, value.v_identifier);
347 current_tag = g_hash_table_lookup(glk_data->default_styles->text_grid, value.v_identifier);
349 if(current_tag == NULL) {
350 g_scanner_error(scanner, "CSS Error: invalid style identifier");
354 if( !style_accept(scanner, '{') )
357 while( g_scanner_peek_next_token(scanner) != '}') {
358 if( !style_accept_style_hint(scanner, current_tag) )
362 if( !style_accept(scanner, '}') )
368 /* Internal function: parses a style hint */
370 style_accept_style_hint(GScanner *scanner, GtkTextTag *current_tag)
372 GTokenType token = g_scanner_get_next_token(scanner);
373 GTokenValue value = g_scanner_cur_value(scanner);
376 if(token != G_TOKEN_IDENTIFIER) {
377 g_scanner_error(scanner, "CSS Error: style hint expected");
381 hint = g_strdup(value.v_identifier);
383 if( !style_accept(scanner, ':') )
386 token = g_scanner_get_next_token(scanner);
387 value = g_scanner_cur_value(scanner);
389 if( !strcmp(hint, "font-family") ) {
390 if(token != G_TOKEN_STRING) {
391 g_scanner_error(scanner, "CSS Error: string expected");
394 g_object_set(current_tag, "family", value.v_string, "family-set", TRUE, NULL);
396 else if( !strcmp(hint, "font-weight") ) {
397 if(token != G_TOKEN_IDENTIFIER) {
398 g_scanner_error(scanner, "CSS Error: bold/normal expected");
402 if( !strcmp(value.v_identifier, "bold") )
403 g_object_set(current_tag, "weight", PANGO_WEIGHT_BOLD, "weight-set", TRUE, NULL);
404 else if( !strcmp(value.v_identifier, "normal") )
405 g_object_set(current_tag, "weight", PANGO_WEIGHT_NORMAL, "weight-set", TRUE, NULL);
407 g_scanner_error(scanner, "CSS Error: bold/normal expected");
411 else if( !strcmp(hint, "font-style") ) {
412 if(token != G_TOKEN_IDENTIFIER) {
413 g_scanner_error(scanner, "CSS Error: italic/normal expected");
417 if( !strcmp(value.v_identifier, "italic") )
418 g_object_set(current_tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
419 else if( !strcmp(value.v_identifier, "normal") )
420 g_object_set(current_tag, "style", PANGO_STYLE_NORMAL, "style-set", TRUE, NULL);
422 g_scanner_error(scanner, "CSS Error: italic/normal expected");
426 else if( !strcmp(hint, "font-size") ) {
427 if(token == G_TOKEN_INT)
428 g_object_set(current_tag, "size-points", (float)value.v_int, "size-set", TRUE, NULL);
429 else if(token == G_TOKEN_FLOAT)
430 g_object_set(current_tag, "size-points", value.v_float, "size-set", TRUE, NULL);
432 g_scanner_error(scanner, "CSS Error: integer or float expected");
436 else if( !strcmp(hint, "color") ) {
437 if(token != G_TOKEN_IDENTIFIER) {
438 g_scanner_error(scanner, "CSS Error: hex color expected");
442 g_object_set(current_tag, "foreground", value.v_identifier, "foreground-set", TRUE, NULL);
444 else if( !strcmp(hint, "background-color") ) {
445 if(token != G_TOKEN_IDENTIFIER) {
446 g_scanner_error(scanner, "CSS Error: hex color expected");
449 g_object_set(current_tag, "background", value.v_identifier, "background-set", TRUE, NULL);
451 else if( !strcmp(hint, "text-align") ) {
452 if(token != G_TOKEN_IDENTIFIER) {
453 g_scanner_error(scanner, "CSS Error: left/right/center expected");
457 if( !strcmp(value.v_identifier, "left") )
458 g_object_set(current_tag, "justification", GTK_JUSTIFY_LEFT, "justification-set", TRUE, NULL);
459 else if( !strcmp(value.v_identifier, "right") )
460 g_object_set(current_tag, "justification", GTK_JUSTIFY_RIGHT, "justification-set", TRUE, NULL);
461 else if( !strcmp(value.v_identifier, "center") )
462 g_object_set(current_tag, "justification", GTK_JUSTIFY_CENTER, "justification-set", TRUE, NULL);
464 g_scanner_error(scanner, "CSS Error: left/right/center expected");
468 else if( !strcmp(hint, "margin-left") ) {
469 if(token != G_TOKEN_INT) {
470 g_scanner_error(scanner, "CSS Error: integer expected");
473 g_object_set(current_tag, "left-margin", value.v_int, "left-margin-set", TRUE, NULL);
475 else if( !strcmp(hint, "margin-right") ) {
476 if(token != G_TOKEN_INT) {
477 g_scanner_error(scanner, "CSS Error: integer expected");
480 g_object_set(current_tag, "right-margin", value.v_int, "right-margin-set", TRUE, NULL);
482 else if( !strcmp(hint, "margin-top") ) {
483 if(token != G_TOKEN_INT) {
484 g_scanner_error(scanner, "CSS Error: integer expected");
487 g_object_set(current_tag, "pixels-above-lines", value.v_int, "pixels-above-lines-set", TRUE, NULL);
489 else if( !strcmp(hint, "margin-bottom") ) {
490 if(token != G_TOKEN_INT) {
491 g_scanner_error(scanner, "CSS Error: integer expected");
494 g_object_set(current_tag, "pixels-below-lines", value.v_int, "pixels-below-lines-set", TRUE, NULL);
498 g_scanner_error(scanner, "CSS Error: invalid style hint %s", hint);
502 if( !style_accept(scanner, ';') )
508 /* Internal function: parses a glk color to a #hex-value */
510 color_format(glui32 val, gchar *buffer)
512 g_return_if_fail(buffer != NULL);
514 sprintf(buffer, "#%02X%02X%02X",
515 ((val & 0xff0000) >> 16),
516 ((val & 0x00ff00) >> 8),
521 /* Internal function: parses a GdkColor to a glk color */
523 color_parse_gdk(GdkColor *color)
525 g_return_val_if_fail(color != NULL, 0);
526 return (glui32) color->pixel;
529 /* Internal function: changes a GTK tag to correspond with the given style. */
531 apply_stylehint_to_tag(GtkTextTag *tag, glui32 hint, glsi32 val)
533 g_return_if_fail(tag != NULL);
535 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
536 GObject *tag_object = G_OBJECT(tag);
538 gint reverse_color = GPOINTER_TO_INT( g_object_get_data(tag_object, "reverse-color") );
543 case stylehint_Indentation:
544 g_object_set(tag_object, "left-margin", 5*val, "left-margin-set", TRUE, NULL);
545 g_object_set(tag_object, "right-margin", 5*val, "right-margin-set", TRUE, NULL);
548 case stylehint_ParaIndentation:
549 g_object_set(tag_object, "indent", 5*val, "indent-set", TRUE, NULL);
552 case stylehint_Justification:
554 case stylehint_just_LeftFlush: i = GTK_JUSTIFY_LEFT; break;
555 case stylehint_just_LeftRight: i = GTK_JUSTIFY_FILL; break;
556 case stylehint_just_Centered: i = GTK_JUSTIFY_CENTER; break;
557 case stylehint_just_RightFlush: i = GTK_JUSTIFY_RIGHT; break;
559 WARNING("Unknown justification");
560 i = GTK_JUSTIFY_LEFT;
562 g_object_set(tag_object, "justification", i, "justification-set", TRUE, NULL);
565 case stylehint_Weight:
567 case -1: i = PANGO_WEIGHT_LIGHT; break;
568 case 0: i = PANGO_WEIGHT_NORMAL; break;
569 case 1: i = PANGO_WEIGHT_BOLD; break;
570 default: WARNING("Unknown font weight");
572 g_object_set(tag_object, "weight", i, "weight-set", TRUE, NULL);
576 g_object_set(tag_object, "size", 14+(2*val), "size-set", TRUE, NULL);
579 case stylehint_Oblique:
580 g_object_set(tag_object, "style", val ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL, "style-set", TRUE, NULL);
583 case stylehint_Proportional:
584 g_object_set(tag_object, "font-desc", val ? glk_data->default_font_desc : glk_data->monospace_font_desc, NULL);
587 case stylehint_TextColor:
588 color_format(val, color);
591 g_object_set(tag_object, "foreground", color, "foreground-set", TRUE, NULL);
593 g_object_set(tag_object, "background", color, "background-set", TRUE, NULL);
597 case stylehint_BackColor:
598 color_format(val, color);
601 g_object_set(tag_object, "background", color, "background-set", TRUE, NULL);
603 g_object_set(tag_object, "foreground", color, "background-set", TRUE, NULL);
607 case stylehint_ReverseColor:
608 if(reverse_color != val) {
609 /* Flip the fore- and background colors */
610 GdkColor* foreground_color;
611 GdkColor* background_color;
612 gint f_set, b_set = 0;
613 g_object_get(tag_object, "foreground-set", &f_set, "background-set", &b_set, NULL);
616 g_object_get(tag_object, "foreground-gdk", &foreground_color, NULL);
618 g_object_get(tag_object, "background-gdk", &background_color, NULL);
621 g_object_set(tag_object, "foreground-gdk", background_color, NULL);
623 g_object_set(tag_object, "foreground", "#ffffff", NULL);
626 g_object_set(tag_object, "background-gdk", foreground_color, NULL);
628 g_object_set(tag_object, "background", "#000000", NULL);
630 g_object_set_data( tag_object, "reverse-color", GINT_TO_POINTER(val != 0) );
635 WARNING("Unknown style hint");
638 /*Internal function: queries a text tag for the value of a given style hint */
640 query_tag(GtkTextTag *tag, glui32 hint)
646 g_return_val_if_fail(tag != NULL, 0);
648 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
651 case stylehint_Indentation:
652 g_object_get(tag, "left_margin", &intval, NULL);
656 case stylehint_ParaIndentation:
657 g_object_get(tag, "indent", &intval, NULL);
661 case stylehint_Justification:
662 g_object_get(tag, "justification", &intval, NULL);
664 case GTK_JUSTIFY_LEFT: return stylehint_just_LeftFlush; break;
665 case GTK_JUSTIFY_FILL: return stylehint_just_LeftRight; break;
666 case GTK_JUSTIFY_CENTER: return stylehint_just_Centered; break;
667 case GTK_JUSTIFY_RIGHT: return stylehint_just_RightFlush; break;
669 WARNING("Unknown justification");
670 return stylehint_just_LeftFlush;
674 case stylehint_Weight:
675 g_object_get(tag, "weight", &intval, NULL);
677 case PANGO_WEIGHT_LIGHT: return -1; break;
678 case PANGO_WEIGHT_NORMAL: return 0; break;
679 case PANGO_WEIGHT_BOLD: return 1; break;
680 default: WARNING("Unknown font weight"); return 0;
685 g_object_get(tag, "size", &intval, NULL);
686 return (intval/2)-14;
689 case stylehint_Oblique:
690 g_object_get(tag, "style", &intval , NULL);
691 return intval == PANGO_STYLE_ITALIC ? 1 : 0;
694 case stylehint_Proportional:
695 g_object_get(tag, "font-desc", &objval, NULL);
696 return objval == (GObject *)glk_data->monospace_font_desc ? 0 : 1;
699 case stylehint_TextColor:
700 g_object_get(tag, "foreground-gdk", &colval, NULL);
701 return color_parse_gdk(colval);
704 case stylehint_BackColor:
705 g_object_get(tag, "background-gdk", &colval, NULL);
706 return color_parse_gdk(colval);
709 case stylehint_ReverseColor:
710 return GPOINTER_TO_INT( g_object_get_data(G_OBJECT(tag), "reverse_color") );
714 WARNING("Unknown style hint");
722 * @wintype: The window type to set a style hint on, or %wintype_AllTypes.
723 * @styl: The style to set a hint for.
724 * @hint: The type of style hint, one of the <code>stylehint_</code> constants.
725 * @val: The style hint. The meaning of this depends on @hint.
727 * Sets a hint about the appearance of one style for a particular type of
728 * window. You can also set wintype to %wintype_AllTypes, which sets a hint for
729 * all types of window.
731 * There is no equivalent constant to set a hint for all styles of a single
736 glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint, glsi32 val)
738 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
740 if( G_UNLIKELY(!glk_data->style_initialized) ) {
744 GtkTextTag *to_change;
745 if(wintype == wintype_TextBuffer || wintype == wintype_AllTypes) {
746 to_change = g_hash_table_lookup( glk_data->current_styles->text_buffer, get_tag_name(styl) );
747 apply_stylehint_to_tag(to_change, hint, val);
750 if(wintype == wintype_TextGrid || wintype == wintype_AllTypes) {
751 to_change = g_hash_table_lookup( glk_data->current_styles->text_grid, get_tag_name(styl) );
752 apply_stylehint_to_tag(to_change, hint, val);
757 * glk_stylehint_clear:
758 * @wintype: The window type to set a style hint on, or %wintype_AllTypes.
759 * @styl: The style to set a hint for.
760 * @hint: The type of style hint, one of the <code>stylehint_</code> constants.
762 * Resets a hint about the appearance of one style for a particular type of
763 * window to it's default value. You can also set wintype to %wintype_AllTypes, which resets a hint for
764 * all types of window.
766 * There is no equivalent constant to reset a hint for all styles of a single
771 glk_stylehint_clear(glui32 wintype, glui32 styl, glui32 hint)
773 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
777 case wintype_TextBuffer:
778 tag = g_hash_table_lookup( glk_data->default_styles->text_buffer, get_tag_name(styl) );
779 glk_stylehint_set( wintype, styl, hint, query_tag(tag, hint) );
781 case wintype_TextGrid:
782 tag = g_hash_table_lookup( glk_data->default_styles->text_grid, get_tag_name(styl) );
783 glk_stylehint_set( wintype, styl, hint, query_tag(tag, hint) );
790 * glk_style_distinguish:
791 * @win: The window in which the styles are to be distinguished.
792 * @styl1: The first style to be distinguished from the second style.
793 * @styl2: The second styel to be distinguished from the first style.
795 * Returns: TRUE if the two styles are visually distinguishable in the given window.
796 * If they are not, it returns FALSE.
799 glk_style_distinguish(winid_t win, glui32 styl1, glui32 styl2)
801 return styl1 != styl2;
806 * @win: The window from which to take the style.
807 * @styl: The style to perform the measurement on.
808 * @hint: The stylehint to measure.
809 * @result: Address to write the result to.
811 * This function can be used to query the current value of a particular style hint.
812 * Returns: TRUE upon successul retrievel, otherwise FALSE.
815 glk_style_measure(winid_t win, glui32 styl, glui32 hint, glui32 *result)
817 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
821 case wintype_TextBuffer:
822 tag = g_hash_table_lookup( glk_data->current_styles->text_buffer, get_tag_name(styl) );
823 *result = query_tag(tag, hint);
825 case wintype_TextGrid:
826 tag = g_hash_table_lookup( glk_data->current_styles->text_grid, get_tag_name(styl) );
827 *result = query_tag(tag, hint);
835 /* Internal function returning the current default font for a window type
836 * This can be used later for size calculations. Only wintype_TextGrid and wintype_TextBuffer are
837 * supported for now */
838 PangoFontDescription*
839 get_current_font(guint32 wintype)
841 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
844 if( G_UNLIKELY(!glk_data->style_initialized) ) {
849 case wintype_TextGrid:
850 normal = g_hash_table_lookup(glk_data->current_styles->text_grid, "normal");
852 case wintype_TextBuffer:
853 normal = g_hash_table_lookup(glk_data->current_styles->text_buffer, "normal");
859 PangoFontDescription *font;
860 g_object_get( G_OBJECT(normal), "font-desc", &font, NULL );