+ bool needshack = underlined && !pangoOk;
+ char *hackstring = NULL;
+
+ if (needshack)
+ {
+ // a PangoLayout which has leading/trailing spaces with underlined font
+ // is not correctly drawn by this pango version: Pango won't underline the spaces.
+ // This can be a problem; e.g. wxHTML rendering of underlined text relies on
+ // this behaviour. To workaround this problem, we use a special hack here
+ // suggested by pango maintainer Behdad Esfahbod: we prepend and append two
+ // empty space characters and give them a dummy colour attribute.
+ // This will force Pango to underline the leading/trailing spaces, too.
+
+ // need to realloc the string to prepend & append our special characters
+ hackstring = (char*)malloc((datalen+7)*sizeof(char));
+
+ // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
+ strcpy(hackstring, "\342\200\214");
+
+ // copy the user string
+ memcpy(&hackstring[3], data, datalen);
+
+ // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
+ strcpy(&hackstring[datalen+3], "\342\200\214");
+
+ // the special characters that we added require 6 additional bytes:
+ datalen += 6;
+
+ pango_layout_set_text(m_layout, hackstring, datalen);
+ }
+ else
+ {
+ pango_layout_set_text(m_layout, data, datalen);
+ }
+
+ if (underlined)
+ {
+ PangoAttrList *attrs = pango_attr_list_new();
+ PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
+ a->start_index = 0;
+ a->end_index = datalen;
+ pango_attr_list_insert(attrs, a);
+
+ if (needshack)
+ {
+ // dummy colour for the leading space
+ a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
+ a->start_index = 0;
+ a->end_index = 1;
+ pango_attr_list_insert(attrs, a);
+
+ // dummy colour for the trailing space
+ a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
+ a->start_index = datalen - 1;
+ a->end_index = datalen;
+ pango_attr_list_insert(attrs, a);
+ }
+
+ pango_layout_set_attributes(m_layout, attrs);
+ pango_attr_list_unref(attrs);
+ }
+
+ int w,h;
+
+ if (fabs(m_scaleY - 1.0) > 0.00001)