| ... | ... |
@@ -137,32 +137,31 @@ class TextShape(Shape): |
| 137 | 137 |
|
| 138 | 138 |
# set font |
| 139 | 139 |
font = pango.FontDescription() |
| 140 |
- attrs = pango.AttrList() |
|
| 141 | 140 |
|
| 142 |
- # set font attributes |
|
| 141 |
+ # https://developer.gnome.org/pango/stable/PangoMarkupFormat.html |
|
| 142 |
+ markup = gobject.markup_escape_text(self.t) |
|
| 143 | 143 |
if self.pen.bold: |
| 144 |
- font.set_weight(pango.WEIGHT_BOLD) |
|
| 144 |
+ markup = '<b>' + markup + '</b>' |
|
| 145 | 145 |
if self.pen.italic: |
| 146 |
- font.set_style(pango.STYLE_ITALIC) |
|
| 146 |
+ markup = '<i>' + markup + '</i>' |
|
| 147 | 147 |
if self.pen.underline: |
| 148 |
- underline = pango.AttrUnderline(pango.UNDERLINE_SINGLE, 0, len(self.t)) |
|
| 149 |
- attrs.insert(underline) |
|
| 148 |
+ markup = '<span underline="single">' + markup + '</span>' |
|
| 150 | 149 |
if self.pen.strikethrough: |
| 151 |
- st = pango.AttrStrikethrough(True, 0, len(self.t)) |
|
| 152 |
- attrs.insert(st) |
|
| 150 |
+ markup = '<s>' + markup + '</s>' |
|
| 151 |
+ if self.pen.superscript: |
|
| 152 |
+ markup = '<sup><small>' + markup + '</small></sup>' |
|
| 153 |
+ if self.pen.subscript: |
|
| 154 |
+ markup = '<sub><small>' + markup + '</small></sub>' |
|
| 153 | 155 |
|
| 156 |
+ attrs, text, accel_char = pango.parse_markup(markup, u'\x00') |
|
| 154 | 157 |
layout.set_attributes(attrs) |
| 155 | 158 |
|
| 156 |
- fontsize = self.pen.fontsize |
|
| 157 |
- if self.pen.superscript or self.pen.subscript: |
|
| 158 |
- fontsize /= 1.5 |
|
| 159 |
- |
|
| 160 | 159 |
font.set_family(self.pen.fontname) |
| 161 |
- font.set_absolute_size(fontsize*pango.SCALE) |
|
| 160 |
+ font.set_absolute_size(self.pen.fontsize*pango.SCALE) |
|
| 162 | 161 |
layout.set_font_description(font) |
| 163 | 162 |
|
| 164 | 163 |
# set text |
| 165 |
- layout.set_text(self.t) |
|
| 164 |
+ layout.set_text(text) |
|
| 166 | 165 |
|
| 167 | 166 |
# cache it |
| 168 | 167 |
self.layout = layout |
| ... | ... |
@@ -195,10 +194,7 @@ class TextShape(Shape): |
| 195 | 194 |
else: |
| 196 | 195 |
assert 0 |
| 197 | 196 |
|
| 198 |
- if self.pen.superscript: |
|
| 199 |
- y = self.y - 1.5*height |
|
| 200 |
- else: |
|
| 201 |
- y = self.y - height + descent |
|
| 197 |
+ y = self.y - height + descent |
|
| 202 | 198 |
|
| 203 | 199 |
cr.move_to(x, y) |
| 204 | 200 |
|