Anoop wrote: > I am writing a program that prints the resistance value in bold red > colour. Please see the following snippet: > > final_result = g_markup_printf_escaped("<span foreground=\"red\" > weight=\"bold\" size=\"xx-large\"> %s±%.2f </span>",result,tolerance); > gtk_label_set_markup(GTK_LABEL(label_Output),final_result); > > where the variable "result" will contain something like 20KΩ and > tolerance will contain something like 0.25%. What I intend, is to print > "20KΩ±0.25%" in bold red. > But the problem is only 20K appears in bold and the remaining is not. > The problem vanishes once i decide to use the word "Ohms" instead of > symbol "Ω". Why is this so? Am I doing something wrong? How can I print > Ω in bold?
Looks like you've been running into character encoding trouble. As you found out yourself, everything works okay as long as you stick with standard 7-bit ASCII characters. The trouble starts when non-7-bit ASCII characters appear. g_markup_printf_escaped() requires its argument string being encoded in UTF-8 and not 8 bit ASCII (or ANSI), as you were probably doing. UTF-8 is a special encoding scheme for non-7-bit ASCII characters, supporting far more than the originally remaining 128 special characters, which are platform-specific anyway. While standard characters 0 - 127 are still being represented by single bytes, single byte values from 128 to 255 don't represent characters any more (as they do in 8-bit ASCII or ANSI). Instead, byte values between 128 and 255 denote UTF-8 encoded characters, which are made up of 2 to 4 bytes each. This encoding also includes some invalid byte combinations, which don't represent any valid UTF-8 character. That's apparently what happened in your string, causing the output to stop at the occurrance of the first invalid UTF-8 byte sequence. I think g_locale_to_utf8() is the function you need to use prior to handing the string to g_markup_printf_escaped(). Alternatively you might try to enter valid UTF-8 characters manually, perhaps by using an UTF-8-capable text editor. See: http://developer.gimp.org/api/2.0/glib/glib-Character-Set-Conversion.html#g-locale-to-utf8 http://developer.gimp.org/api/2.0/glib/glib-Simple-XML-Subset-Parser.html Besides, to use bold and colored texts in GtkLabels in general, gtk_label_set_markup() is the only function you need. g_markup_printf_escaped() is rather XML-specific and basically not needed for styled GtkLabels, except if you explcitly need the string escaped (made usable for XML). _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list