vte r2371 - in trunk: . src
- From: behdad svn gnome org
- To: svn-commits-list gnome org
- Subject: vte r2371 - in trunk: . src
- Date: Thu, 12 Feb 2009 05:33:15 +0000 (UTC)
Author: behdad
Date: Thu Feb 12 05:33:15 2009
New Revision: 2371
URL: http://svn.gnome.org/viewvc/vte?rev=2371&view=rev
Log:
2009-02-12 Behdad Esfahbod <behdad gnome org>
Bug 54926 â Should try bold version of font before pseudo-bolding
Patch from Kees Cook <kees outflux net>
* src/vte.c (_vte_invalidate_cell), (_vte_invalidate_cursor_once),
(vte_terminal_unichar_is_local_graphic),
(vte_terminal_draw_graphic), (vte_terminal_draw_cells),
(vte_terminal_draw_rows), (vte_terminal_paint_cursor):
* src/vtedraw.c (_vte_draw_get_char_width), (_vte_draw_text),
(_vte_draw_char), (_vte_draw_has_char):
* src/vtedraw.h:
* src/vtepangocairo.c (_vte_pangocairo_set_text_font),
(_vte_pangocairo_get_char_width), (_vte_pangocairo_has_bold),
(_vte_pangocairo_draw_text), (_vte_pangocairo_draw_has_char):
* src/vteskel.c:
Try bold font before pseudo-bolding.
Modified:
trunk/ChangeLog
trunk/src/vte.c
trunk/src/vtedraw.c
trunk/src/vtedraw.h
trunk/src/vtepangocairo.c
trunk/src/vteskel.c
Modified: trunk/src/vte.c
==============================================================================
--- trunk/src/vte.c (original)
+++ trunk/src/vte.c Thu Feb 12 05:33:15 2009
@@ -724,7 +724,7 @@
_vte_draw_get_char_width (
terminal->pvt->draw,
cell->c,
- columns) >
+ columns, cell->attr.bold) >
terminal->char_width * columns) {
columns++;
}
@@ -781,7 +781,7 @@
_vte_draw_get_char_width (
terminal->pvt->draw,
cell->c,
- columns) >
+ columns, cell->attr.bold) >
terminal->char_width * columns) {
columns++;
}
@@ -8856,10 +8856,10 @@
return FALSE;
}
static gboolean
-vte_terminal_unichar_is_local_graphic(VteTerminal *terminal, vteunistr c)
+vte_terminal_unichar_is_local_graphic(VteTerminal *terminal, vteunistr c, gboolean bold)
{
return vte_unichar_is_local_graphic (c) &&
- !_vte_draw_has_char (terminal->pvt->draw, c);
+ !_vte_draw_has_char (terminal->pvt->draw, c, bold);
}
static void
@@ -8946,7 +8946,8 @@
vte_terminal_draw_graphic(VteTerminal *terminal, vteunistr c,
gint fore, gint back, gboolean draw_default_bg,
gint x, gint y,
- gint column_width, gint columns, gint row_height)
+ gint column_width, gint columns, gint row_height,
+ gboolean bold)
{
gboolean ret;
gint xcenter, xright, ycenter, ybottom, i, j, draw;
@@ -8974,7 +8975,7 @@
}
if (_vte_draw_char(terminal->pvt->draw, &request,
- &color, VTE_DRAW_OPAQUE)) {
+ &color, VTE_DRAW_OPAQUE, bold)) {
/* We were able to draw with actual fonts. */
return TRUE;
}
@@ -9767,20 +9768,7 @@
color.green = fg->green;
_vte_draw_text(terminal->pvt->draw,
items, n,
- &color, VTE_DRAW_OPAQUE);
- if (bold) {
- /* Take a step to the right. */
- for (i = 0; i < n; i++) {
- items[i].x++;
- }
- _vte_draw_text(terminal->pvt->draw,
- items, n,
- &color, VTE_DRAW_OPAQUE);
- /* Now take a step back. */
- for (i = 0; i < n; i++) {
- items[i].x--;
- }
- }
+ &color, VTE_DRAW_OPAQUE, bold);
for (i = 0; i < n; i++) {
/* Deadjust for the border. */
items[i].x -= VTE_PAD_WIDTH;
@@ -10311,7 +10299,7 @@
j = i + items[0].columns;
/* If this is a graphics character, draw it locally. */
- if (vte_terminal_unichar_is_local_graphic(terminal, cell->c)) {
+ if (vte_terminal_unichar_is_local_graphic(terminal, cell->c, cell->attr.bold)) {
if (vte_terminal_draw_graphic(terminal,
items[0].c,
fore, back,
@@ -10320,7 +10308,8 @@
items[0].y,
column_width,
items[0].columns,
- row_height)) {
+ row_height,
+ cell->attr.bold)) {
i = j;
continue;
}
@@ -10363,7 +10352,7 @@
FALSE,
&nfore, &nback);
/* Graphic characters must be drawn individually. */
- if (vte_terminal_unichar_is_local_graphic(terminal, cell->c)) {
+ if (vte_terminal_unichar_is_local_graphic(terminal, cell->c, cell->attr.bold)) {
if (vte_terminal_draw_graphic(terminal,
cell->c,
nfore, nback,
@@ -10372,7 +10361,8 @@
y,
column_width,
cell->attr.columns,
- row_height)) {
+ row_height,
+ cell->attr.bold)) {
j += cell->attr.columns;
continue;
@@ -10640,9 +10630,8 @@
cursor_width = item.columns * width;
if (cell && cell->c != 0) {
gint cw = _vte_draw_get_char_width (terminal->pvt->draw,
- cell->c, cell->attr.columns);
+ cell->c, cell->attr.columns, cell->attr.bold);
cursor_width = MAX(cursor_width, cw);
- cursor_width += cell->attr.bold; /* for pseudo-bolding */
}
selected = vte_cell_is_selected(terminal, col, drow, NULL);
@@ -10691,7 +10680,7 @@
&color,
VTE_DRAW_OPAQUE);
- if (!vte_terminal_unichar_is_local_graphic(terminal, item.c) ||
+ if (!vte_terminal_unichar_is_local_graphic(terminal, item.c, cell ? cell->attr.bold : FALSE) ||
!vte_terminal_draw_graphic(terminal,
item.c,
fore, back,
@@ -10700,7 +10689,8 @@
item.y,
width,
item.columns,
- height)) {
+ height,
+ cell ? cell->attr.bold : FALSE)) {
gboolean hilite = FALSE;
if (cell && terminal->pvt->show_match) {
hilite = vte_cell_is_between(col, row,
Modified: trunk/src/vtedraw.c
==============================================================================
--- trunk/src/vtedraw.c (original)
+++ trunk/src/vtedraw.c Thu Feb 12 05:33:15 2009
@@ -312,12 +312,13 @@
}
int
-_vte_draw_get_char_width (struct _vte_draw *draw, vteunistr c, int columns)
+_vte_draw_get_char_width (struct _vte_draw *draw, vteunistr c, int columns,
+ gboolean bold)
{
int width = 0;
if (draw->impl->get_char_width)
- width = draw->impl->get_char_width (draw, c, columns);
+ width = draw->impl->get_char_width (draw, c, columns, bold);
if (width == 0)
_vte_draw_get_text_metrics (draw, &width, NULL, NULL);
@@ -328,7 +329,7 @@
void
_vte_draw_text (struct _vte_draw *draw,
struct _vte_draw_text_request *requests, gsize n_requests,
- GdkColor *color, guchar alpha)
+ GdkColor *color, guchar alpha, gboolean bold)
{
g_return_if_fail (draw->started == TRUE);
g_return_if_fail (draw->impl->draw_text != NULL);
@@ -341,43 +342,59 @@
g_string_append_unichar (string, requests[n].c);
}
str = g_string_free (string, FALSE);
- g_printerr ("draw_text (\"%s\", len=%"G_GSIZE_FORMAT", color=(%d,%d,%d,%d))\n",
+ g_printerr ("draw_text (\"%s\", len=%"G_GSIZE_FORMAT", color=(%d,%d,%d,%d), %s)\n",
str, n_requests, color->red, color->green, color->blue,
- alpha);
+ alpha, bold ? "bold" : "normal");
g_free (str);
}
- draw->impl->draw_text (draw, requests, n_requests, color, alpha);
+ draw->impl->draw_text (draw, requests, n_requests, color, alpha, bold);
+
+ /* handle fonts that lack a bold face by double-striking */
+ if (bold && !(draw->impl->has_bold && draw->impl->has_bold (draw))) {
+ int i;
+
+ /* Take a step to the right. */
+ for (i = 0; i < n_requests; i++) {
+ requests[i].x++;
+ }
+ draw->impl->draw_text (draw, requests, n_requests, color, alpha, FALSE);
+ /* Now take a step back. */
+ for (i = 0; i < n_requests; i++) {
+ requests[i].x--;
+ }
+ }
}
gboolean
_vte_draw_char (struct _vte_draw *draw,
struct _vte_draw_text_request *request,
- GdkColor *color, guchar alpha)
+ GdkColor *color, guchar alpha, gboolean bold)
{
gboolean has_char;
_vte_debug_print (VTE_DEBUG_DRAW,
- "draw_char ('%c', color=(%d,%d,%d,%d))\n",
+ "draw_char ('%c', color=(%d,%d,%d,%d), %s)\n",
request->c,
color->red, color->green, color->blue,
- alpha);
+ alpha, bold ? "bold" : "normal");
- has_char =_vte_draw_has_char (draw, request->c);
+ has_char =_vte_draw_has_char (draw, request->c, bold);
if (has_char)
- _vte_draw_text (draw, request, 1, color, alpha);
+ _vte_draw_text (draw, request, 1, color, alpha, bold);
return has_char;
}
gboolean
-_vte_draw_has_char (struct _vte_draw *draw, vteunistr c)
+_vte_draw_has_char (struct _vte_draw *draw, vteunistr c, gboolean bold)
{
gboolean has_char = TRUE;
- _vte_debug_print (VTE_DEBUG_DRAW, "draw_has_char ('0x%04X')\n", c);
+ _vte_debug_print (VTE_DEBUG_DRAW, "draw_has_char ('0x%04X', %s)\n", c,
+ bold ? "bold" : "normal");
if (draw->impl->has_char)
- has_char = draw->impl->has_char (draw, c);
+ has_char = draw->impl->has_char (draw, c, bold);
return has_char;
}
Modified: trunk/src/vtedraw.h
==============================================================================
--- trunk/src/vtedraw.h (original)
+++ trunk/src/vtedraw.h Thu Feb 12 05:33:15 2009
@@ -87,11 +87,13 @@
const PangoFontDescription *,
VteTerminalAntiAlias);
void (*get_text_metrics)(struct _vte_draw *, gint *, gint *, gint *);
- int (*get_char_width)(struct _vte_draw *, vteunistr c, int columns);
+ int (*get_char_width)(struct _vte_draw *, vteunistr c, int columns,
+ gboolean);
+ gboolean (*has_bold)(struct _vte_draw *);
void (*draw_text)(struct _vte_draw *,
- struct _vte_draw_text_request *, gsize,
- GdkColor *, guchar);
- gboolean (*has_char)(struct _vte_draw *, vteunistr);
+ struct _vte_draw_text_request *, gsize,
+ GdkColor *, guchar, gboolean);
+ gboolean (*has_char)(struct _vte_draw *, vteunistr, gboolean);
void (*draw_rectangle)(struct _vte_draw *,
gint, gint, gint, gint,
GdkColor *, guchar);
@@ -151,15 +153,17 @@
VteTerminalAntiAlias anti_alias);
void _vte_draw_get_text_metrics(struct _vte_draw *draw,
gint *width, gint *height, gint *ascent);
-int _vte_draw_get_char_width(struct _vte_draw *draw, vteunistr c, int columns);
+int _vte_draw_get_char_width(struct _vte_draw *draw, vteunistr c, int columns,
+ gboolean bold);
void _vte_draw_text(struct _vte_draw *draw,
struct _vte_draw_text_request *requests, gsize n_requests,
- GdkColor *color, guchar alpha);
+ GdkColor *color, guchar alpha, gboolean);
gboolean _vte_draw_char(struct _vte_draw *draw,
struct _vte_draw_text_request *request,
- GdkColor *color, guchar alpha);
-gboolean _vte_draw_has_char(struct _vte_draw *draw, vteunistr c);
+ GdkColor *color, guchar alpha, gboolean bold);
+gboolean _vte_draw_has_char(struct _vte_draw *draw, vteunistr c, gboolean bold);
+
void _vte_draw_fill_rectangle(struct _vte_draw *draw,
gint x, gint y, gint width, gint height,
Modified: trunk/src/vtepangocairo.c
==============================================================================
--- trunk/src/vtepangocairo.c (original)
+++ trunk/src/vtepangocairo.c Thu Feb 12 05:33:15 2009
@@ -786,6 +786,7 @@
struct _vte_pangocairo_data {
struct font_info *font;
+ struct font_info *font_bold;
cairo_pattern_t *bg_pattern;
cairo_t *cr;
@@ -945,9 +946,27 @@
VteTerminalAntiAlias antialias)
{
struct _vte_pangocairo_data *data = draw->impl_data;
+ PangoFontDescription *bolddesc = NULL;
+ if (data->font_bold != data->font)
+ font_info_destroy (data->font_bold);
font_info_destroy (data->font);
data->font = font_info_create_for_widget (draw->widget, fontdesc, antialias);
+
+ /* calculate bold font desc */
+ bolddesc = pango_font_description_copy (fontdesc);
+ pango_font_description_set_weight (bolddesc, PANGO_WEIGHT_BOLD);
+
+ data->font_bold = font_info_create_for_widget (draw->widget, bolddesc, antialias);
+ pango_font_description_free (bolddesc);
+
+ /* Decide if we should keep this bold font face, per bug 54926:
+ * - reject bold font if it is not within 10% of normal font width
+ */
+ if ( abs((data->font_bold->width * 100 / data->font->width) - 100) > 10 ) {
+ font_info_destroy (data->font_bold);
+ data->font_bold = data->font;
+ }
}
static void
@@ -965,17 +984,26 @@
static int
-_vte_pangocairo_get_char_width (struct _vte_draw *draw, vteunistr c, int columns)
+_vte_pangocairo_get_char_width (struct _vte_draw *draw, vteunistr c, int columns,
+ gboolean bold)
{
struct _vte_pangocairo_data *data = draw->impl_data;
struct unistr_info *uinfo;
g_return_val_if_fail (data->font != NULL, 0);
- uinfo = font_info_get_unistr_info (data->font, c);
+ uinfo = font_info_get_unistr_info (bold ? data->font_bold : data->font, c);
return uinfo->width;
}
+static gboolean
+_vte_pangocairo_has_bold (struct _vte_draw *draw)
+{
+ struct _vte_pangocairo_data *data = draw->impl_data;
+
+ return (data->font != data->font_bold);
+}
+
static void
set_source_color_alpha (cairo_t *cr,
const GdkColor *color,
@@ -991,15 +1019,16 @@
static void
_vte_pangocairo_draw_text (struct _vte_draw *draw,
struct _vte_draw_text_request *requests, gsize n_requests,
- GdkColor *color, guchar alpha)
+ GdkColor *color, guchar alpha, gboolean bold)
{
struct _vte_pangocairo_data *data = draw->impl_data;
gsize i;
cairo_scaled_font_t *last_scaled_font = NULL;
int n_cr_glyphs = 0;
cairo_glyph_t cr_glyphs[MAX_RUN_LENGTH];
+ struct font_info *font = bold ? data->font_bold : data->font;
- g_return_if_fail (data->font != NULL);
+ g_return_if_fail (font != NULL);
set_source_color_alpha (data->cr, color, alpha);
cairo_set_operator (data->cr, CAIRO_OPERATOR_OVER);
@@ -1007,8 +1036,8 @@
for (i = 0; i < n_requests; i++) {
vteunistr c = requests[i].c;
int x = requests[i].x;
- int y = requests[i].y + data->font->ascent;
- struct unistr_info *uinfo = font_info_get_unistr_info (data->font, c);
+ int y = requests[i].y + font->ascent;
+ struct unistr_info *uinfo = font_info_get_unistr_info (font, c);
union unistr_font_info *ufi = &uinfo->ufi;
switch (uinfo->coverage) {
@@ -1055,14 +1084,15 @@
}
static gboolean
-_vte_pangocairo_draw_has_char (struct _vte_draw *draw, vteunistr c)
+_vte_pangocairo_draw_has_char (struct _vte_draw *draw, vteunistr c,
+ gboolean bold)
{
struct _vte_pangocairo_data *data = draw->impl_data;
struct unistr_info *uinfo;
g_return_val_if_fail (data->font != NULL, FALSE);
- uinfo = font_info_get_unistr_info (data->font, c);
+ uinfo = font_info_get_unistr_info (bold ? data->font_bold : data->font, c);
return !uinfo->has_unknown_chars;
}
@@ -1111,6 +1141,7 @@
_vte_pangocairo_set_text_font,
_vte_pangocairo_get_text_metrics,
_vte_pangocairo_get_char_width,
+ _vte_pangocairo_has_bold,
_vte_pangocairo_draw_text,
_vte_pangocairo_draw_has_char,
_vte_pangocairo_draw_rectangle,
Modified: trunk/src/vteskel.c
==============================================================================
--- trunk/src/vteskel.c (original)
+++ trunk/src/vteskel.c Thu Feb 12 05:33:15 2009
@@ -78,6 +78,7 @@
NULL, /* set_text_font */
_vte_skel_get_text_metrics,
NULL, /* get_char_width */
+ NULL, /* has_bold */
_vte_skel_draw_text,
NULL, /* draw_has_char */
NULL, /* draw_rectangle */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]