1
Upstream: http://bugzilla.gnome.org/show_bug.cgi?id=54926
2
Description: Fix bold font handling.
4
diff -Nur -x '*.orig' -x '*~' vte-0.19.4/src/vte.c vte-0.19.4.new/src/vte.c
5
--- vte-0.19.4/src/vte.c 2008-12-13 14:49:02.000000000 -0800
6
+++ vte-0.19.4.new/src/vte.c 2009-02-10 16:14:36.000000000 -0800
8
_vte_draw_get_char_width (
12
+ columns, cell->attr.bold) >
13
terminal->char_width * columns) {
17
_vte_draw_get_char_width (
21
+ columns, cell->attr.bold) >
22
terminal->char_width * columns) {
26
vte_terminal_unichar_is_local_graphic(VteTerminal *terminal, vteunistr c)
28
return vte_unichar_is_local_graphic (c) &&
29
- !_vte_draw_has_char (terminal->pvt->draw, c);
30
+ !_vte_draw_has_char (terminal->pvt->draw, c, FALSE);
37
if (_vte_draw_char(terminal->pvt->draw, &request,
38
- &color, VTE_DRAW_OPAQUE)) {
39
+ &color, VTE_DRAW_OPAQUE, FALSE)) {
40
/* We were able to draw with actual fonts. */
43
@@ -9761,15 +9761,16 @@
44
color.green = fg->green;
45
_vte_draw_text(terminal->pvt->draw,
47
- &color, VTE_DRAW_OPAQUE);
49
+ &color, VTE_DRAW_OPAQUE, bold);
50
+ /* handle fonts that lack a bold face by double-striking */
51
+ if (bold && !_vte_draw_has_bold(terminal->pvt->draw)) {
52
/* Take a step to the right. */
53
for (i = 0; i < n; i++) {
56
_vte_draw_text(terminal->pvt->draw,
58
- &color, VTE_DRAW_OPAQUE);
59
+ &color, VTE_DRAW_OPAQUE, FALSE);
60
/* Now take a step back. */
61
for (i = 0; i < n; i++) {
63
@@ -10634,7 +10635,7 @@
64
cursor_width = item.columns * width;
65
if (cell && cell->c != 0) {
66
gint cw = _vte_draw_get_char_width (terminal->pvt->draw,
67
- cell->c, cell->attr.columns);
68
+ cell->c, cell->attr.columns, cell->attr.bold);
69
cursor_width = MAX(cursor_width, cw);
70
cursor_width += cell->attr.bold; /* for pseudo-bolding */
72
diff -Nur -x '*.orig' -x '*~' vte-0.19.4/src/vtedraw.c vte-0.19.4.new/src/vtedraw.c
73
--- vte-0.19.4/src/vtedraw.c 2008-12-11 19:31:52.000000000 -0800
74
+++ vte-0.19.4.new/src/vtedraw.c 2009-02-10 16:14:36.000000000 -0800
79
-_vte_draw_get_char_width (struct _vte_draw *draw, vteunistr c, int columns)
80
+_vte_draw_get_char_width (struct _vte_draw *draw, vteunistr c, int columns,
85
if (draw->impl->get_char_width)
86
- width = draw->impl->get_char_width (draw, c, columns);
87
+ width = draw->impl->get_char_width (draw, c, columns, bold);
90
_vte_draw_get_text_metrics (draw, &width, NULL, NULL);
96
+_vte_draw_has_bold (struct _vte_draw *draw)
98
+ if (draw->impl->has_bold)
99
+ return draw->impl->has_bold (draw);
105
_vte_draw_text (struct _vte_draw *draw,
106
struct _vte_draw_text_request *requests, gsize n_requests,
107
- GdkColor *color, guchar alpha)
108
+ GdkColor *color, guchar alpha, gboolean bold)
110
g_return_if_fail (draw->started == TRUE);
111
g_return_if_fail (draw->impl->draw_text != NULL);
112
@@ -341,43 +351,44 @@
113
g_string_append_unichar (string, requests[n].c);
115
str = g_string_free (string, FALSE);
116
- g_printerr ("draw_text (\"%s\", len=%"G_GSIZE_FORMAT", color=(%d,%d,%d,%d))\n",
117
+ g_printerr ("draw_text (\"%s\", len=%"G_GSIZE_FORMAT", color=(%d,%d,%d,%d), %s)\n",
118
str, n_requests, color->red, color->green, color->blue,
120
+ alpha, bold ? "bold" : "normal");
124
- draw->impl->draw_text (draw, requests, n_requests, color, alpha);
125
+ draw->impl->draw_text (draw, requests, n_requests, color, alpha, bold);
129
_vte_draw_char (struct _vte_draw *draw,
130
struct _vte_draw_text_request *request,
131
- GdkColor *color, guchar alpha)
132
+ GdkColor *color, guchar alpha, gboolean bold)
136
_vte_debug_print (VTE_DEBUG_DRAW,
137
- "draw_char ('%c', color=(%d,%d,%d,%d))\n",
138
+ "draw_char ('%c', color=(%d,%d,%d,%d), %s)\n",
140
color->red, color->green, color->blue,
142
+ alpha, bold ? "bold" : "normal");
144
- has_char =_vte_draw_has_char (draw, request->c);
145
+ has_char =_vte_draw_has_char (draw, request->c, bold);
147
- _vte_draw_text (draw, request, 1, color, alpha);
148
+ _vte_draw_text (draw, request, 1, color, alpha, bold);
153
-_vte_draw_has_char (struct _vte_draw *draw, vteunistr c)
154
+_vte_draw_has_char (struct _vte_draw *draw, vteunistr c, gboolean bold)
156
gboolean has_char = TRUE;
158
- _vte_debug_print (VTE_DEBUG_DRAW, "draw_has_char ('0x%04X')\n", c);
159
+ _vte_debug_print (VTE_DEBUG_DRAW, "draw_has_char ('0x%04X', %s)\n", c,
160
+ bold ? "bold" : "normal");
162
if (draw->impl->has_char)
163
- has_char = draw->impl->has_char (draw, c);
164
+ has_char = draw->impl->has_char (draw, c, bold);
168
diff -Nur -x '*.orig' -x '*~' vte-0.19.4/src/vtedraw.h vte-0.19.4.new/src/vtedraw.h
169
--- vte-0.19.4/src/vtedraw.h 2008-12-11 19:30:57.000000000 -0800
170
+++ vte-0.19.4.new/src/vtedraw.h 2009-02-10 16:14:36.000000000 -0800
172
const PangoFontDescription *,
173
VteTerminalAntiAlias);
174
void (*get_text_metrics)(struct _vte_draw *, gint *, gint *, gint *);
175
- int (*get_char_width)(struct _vte_draw *, vteunistr c, int columns);
176
+ int (*get_char_width)(struct _vte_draw *, vteunistr c, int columns,
178
+ gboolean (*has_bold)(struct _vte_draw *);
179
void (*draw_text)(struct _vte_draw *,
180
- struct _vte_draw_text_request *, gsize,
181
- GdkColor *, guchar);
182
- gboolean (*has_char)(struct _vte_draw *, vteunistr);
183
+ struct _vte_draw_text_request *, gsize,
184
+ GdkColor *, guchar, gboolean);
185
+ gboolean (*has_char)(struct _vte_draw *, vteunistr, gboolean);
186
void (*draw_rectangle)(struct _vte_draw *,
187
gint, gint, gint, gint,
189
@@ -151,15 +153,18 @@
190
VteTerminalAntiAlias anti_alias);
191
void _vte_draw_get_text_metrics(struct _vte_draw *draw,
192
gint *width, gint *height, gint *ascent);
193
-int _vte_draw_get_char_width(struct _vte_draw *draw, vteunistr c, int columns);
194
+int _vte_draw_get_char_width(struct _vte_draw *draw, vteunistr c, int columns,
197
void _vte_draw_text(struct _vte_draw *draw,
198
struct _vte_draw_text_request *requests, gsize n_requests,
199
- GdkColor *color, guchar alpha);
200
+ GdkColor *color, guchar alpha, gboolean);
201
gboolean _vte_draw_char(struct _vte_draw *draw,
202
struct _vte_draw_text_request *request,
203
- GdkColor *color, guchar alpha);
204
-gboolean _vte_draw_has_char(struct _vte_draw *draw, vteunistr c);
205
+ GdkColor *color, guchar alpha, gboolean bold);
206
+gboolean _vte_draw_has_char(struct _vte_draw *draw, vteunistr c, gboolean bold);
207
+gboolean _vte_draw_has_bold(struct _vte_draw *draw);
210
void _vte_draw_fill_rectangle(struct _vte_draw *draw,
211
gint x, gint y, gint width, gint height,
212
diff -Nur -x '*.orig' -x '*~' vte-0.19.4/src/vtepangocairo.c vte-0.19.4.new/src/vtepangocairo.c
213
--- vte-0.19.4/src/vtepangocairo.c 2008-12-11 19:47:29.000000000 -0800
214
+++ vte-0.19.4.new/src/vtepangocairo.c 2009-02-10 16:16:58.000000000 -0800
217
struct _vte_pangocairo_data {
218
struct font_info *font;
219
+ struct font_info *font_bold;
220
cairo_pattern_t *bg_pattern;
224
VteTerminalAntiAlias antialias)
226
struct _vte_pangocairo_data *data = draw->impl_data;
227
+ PangoFontDescription *bolddesc = NULL;
229
+ if (data->font_bold != data->font)
230
+ font_info_destroy (data->font_bold);
231
font_info_destroy (data->font);
232
data->font = font_info_create_for_widget (draw->widget, fontdesc, antialias);
234
+ /* calculate bold font desc */
235
+ bolddesc = pango_font_description_copy (fontdesc);
237
+ pango_font_description_set_weight (bolddesc, PANGO_WEIGHT_BOLD);
239
+ data->font_bold = font_info_create_for_widget (draw->widget, bolddesc, antialias);
240
+ pango_font_description_free (bolddesc);
242
+ /* Decide if we should keep this bold font face, per bug 54926:
243
+ * - reject bold font if it is not within 10% of normal font width
245
+ if ( abs((data->font_bold->width * 100 / data->font->width) - 100) > 10 ) {
246
+ g_warning(_("bold font too wide (%d not within 10%% of normal width %d), falling back to double-strike"),
247
+ data->font_bold->width, data->font->width);
248
+ font_info_destroy (data->font_bold);
249
+ data->font_bold = data->font;
253
+ g_warning(_("can not create bold font"));
254
+ data->font_bold = data->font;
259
@@ -934,17 +961,26 @@
263
-_vte_pangocairo_get_char_width (struct _vte_draw *draw, vteunistr c, int columns)
264
+_vte_pangocairo_get_char_width (struct _vte_draw *draw, vteunistr c, int columns,
267
struct _vte_pangocairo_data *data = draw->impl_data;
268
struct unistr_info *uinfo;
270
g_return_val_if_fail (data->font != NULL, 0);
272
- uinfo = font_info_get_unistr_info (data->font, c);
273
+ uinfo = font_info_get_unistr_info (bold ? data->font_bold : data->font, c);
278
+_vte_pangocairo_has_bold (struct _vte_draw *draw)
280
+ struct _vte_pangocairo_data *data = draw->impl_data;
282
+ return (data->font != data->font_bold);
286
set_source_color_alpha (cairo_t *cr,
287
const GdkColor *color,
288
@@ -960,15 +996,16 @@
290
_vte_pangocairo_draw_text (struct _vte_draw *draw,
291
struct _vte_draw_text_request *requests, gsize n_requests,
292
- GdkColor *color, guchar alpha)
293
+ GdkColor *color, guchar alpha, gboolean bold)
295
struct _vte_pangocairo_data *data = draw->impl_data;
297
cairo_scaled_font_t *last_scaled_font = NULL;
299
cairo_glyph_t cr_glyphs[MAX_RUN_LENGTH];
300
+ struct font_info *font = bold ? data->font_bold : data->font;
302
- g_return_if_fail (data->font != NULL);
303
+ g_return_if_fail (font != NULL);
305
set_source_color_alpha (data->cr, color, alpha);
306
cairo_set_operator (data->cr, CAIRO_OPERATOR_OVER);
308
for (i = 0; i < n_requests; i++) {
309
vteunistr c = requests[i].c;
310
int x = requests[i].x;
311
- int y = requests[i].y + data->font->ascent;
312
- struct unistr_info *uinfo = font_info_get_unistr_info (data->font, c);
313
+ int y = requests[i].y + font->ascent;
314
+ struct unistr_info *uinfo = font_info_get_unistr_info (font, c);
315
union unistr_font_info *ufi = &uinfo->ufi;
317
switch (uinfo->coverage) {
318
@@ -1024,14 +1061,15 @@
322
-_vte_pangocairo_draw_has_char (struct _vte_draw *draw, vteunistr c)
323
+_vte_pangocairo_draw_has_char (struct _vte_draw *draw, vteunistr c,
326
struct _vte_pangocairo_data *data = draw->impl_data;
327
struct unistr_info *uinfo;
329
g_return_val_if_fail (data->font != NULL, FALSE);
331
- uinfo = font_info_get_unistr_info (data->font, c);
332
+ uinfo = font_info_get_unistr_info (bold ? data->font_bold : data->font, c);
333
return !uinfo->has_unknown_chars;
336
@@ -1080,6 +1118,7 @@
337
_vte_pangocairo_set_text_font,
338
_vte_pangocairo_get_text_metrics,
339
_vte_pangocairo_get_char_width,
340
+ _vte_pangocairo_has_bold,
341
_vte_pangocairo_draw_text,
342
_vte_pangocairo_draw_has_char,
343
_vte_pangocairo_draw_rectangle,