From 71b279783975e3542e172e23b37583583cb2482b Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 4 Jun 2012 13:42:47 +0200 Subject: load default interactive format font and colors from config file and also save them * pango attributes cannot be "cached" anymore and must be recreated every time the interactive format is configured --- .../gtk-experiment-transcript-formats.c | 67 +++++++++------------- 1 file changed, 28 insertions(+), 39 deletions(-) (limited to 'lib/gtk-experiment-widgets/gtk-experiment-transcript-formats.c') diff --git a/lib/gtk-experiment-widgets/gtk-experiment-transcript-formats.c b/lib/gtk-experiment-widgets/gtk-experiment-transcript-formats.c index 3898e30..d5b2f5e 100644 --- a/lib/gtk-experiment-widgets/gtk-experiment-transcript-formats.c +++ b/lib/gtk-experiment-widgets/gtk-experiment-transcript-formats.c @@ -203,47 +203,12 @@ gtk_experiment_transcript_set_interactive_format(GtkExperimentTranscript *trans, const gchar *format_str, gboolean with_markup) { - static PangoAttrList *default_attribs = NULL; - GtkExperimentTranscriptFormat *fmt = &trans->priv->interactive_format; - gchar *pattern; - gboolean res = TRUE; - if (default_attribs == NULL) { - PangoAttribute *attrib; - PangoFontDescription *font; - PangoColor color; - - default_attribs = pango_attr_list_new(); + gchar *pattern; + PangoAttribute *attrib; -#ifdef DEFAULT_INTERACTIVE_FORMAT_FONT - font = pango_font_description_from_string(DEFAULT_INTERACTIVE_FORMAT_FONT); - if (font != NULL) { - attrib = pango_attr_font_desc_new(font); - attrib->end_index = 1; - pango_attr_list_insert(default_attribs, attrib); - pango_font_description_free(font); - } -#endif -#ifdef DEFAULT_INTERACTIVE_FORMAT_FGCOLOR - if (pango_color_parse(&color, DEFAULT_INTERACTIVE_FORMAT_FGCOLOR)) { - attrib = pango_attr_foreground_new(color.red, - color.green, - color.blue); - attrib->end_index = 1; - pango_attr_list_insert(default_attribs, attrib); - } -#endif -#ifdef DEFAULT_INTERACTIVE_FORMAT_BGCOLOR - if (pango_color_parse(&color, DEFAULT_INTERACTIVE_FORMAT_BGCOLOR)) { - attrib = pango_attr_background_new(color.red, - color.green, - color.blue); - attrib->end_index = 1; - pango_attr_list_insert(default_attribs, attrib); - } -#endif - } + gboolean res = TRUE; gtk_experiment_transcript_free_format(fmt); fmt->regexp = NULL; @@ -260,10 +225,34 @@ gtk_experiment_transcript_set_interactive_format(GtkExperimentTranscript *trans, } /* else if (!with_markup) */ - fmt->attribs = pango_attr_list_copy(default_attribs); + fmt->attribs = pango_attr_list_new(); if (fmt->attribs == NULL) goto redraw; + if (trans->interactive_format.default_font != NULL) { + attrib = pango_attr_font_desc_new(trans->interactive_format.default_font); + attrib->end_index = 1; + pango_attr_list_insert(fmt->attribs, attrib); + } + if (trans->interactive_format.default_text_color != NULL) { + GdkColor *color = trans->interactive_format.default_text_color; + + attrib = pango_attr_foreground_new(color->red, + color->green, + color->blue); + attrib->end_index = 1; + pango_attr_list_insert(fmt->attribs, attrib); + } + if (trans->interactive_format.default_bg_color != NULL) { + GdkColor *color = trans->interactive_format.default_bg_color; + + attrib = pango_attr_background_new(color->red, + color->green, + color->blue); + attrib->end_index = 1; + pango_attr_list_insert(fmt->attribs, attrib); + } + pattern = g_strconcat("(", format_str, ")", NULL); fmt->regexp = g_regex_new(pattern, FORMAT_REGEX_COMPILE_FLAGS, 0, NULL); g_free(pattern); -- cgit v1.2.3