After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 54926 - Should try bold version of font before pseudo-bolding
Should try bold version of font before pseudo-bolding
Status: RESOLVED FIXED
Product: vte
Classification: Core
Component: general
unspecified
Other All
: Normal minor
: ---
Assigned To: VTE Maintainers
VTE Maintainers
Depends on:
Blocks:
 
 
Reported: 2001-05-19 00:10 UTC by Ralph Deeb
Modified: 2009-02-12 05:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
vte-xft-locking-with-font.patch (8.34 KB, patch)
2008-06-22 01:44 UTC, Kees Cook
none Details | Review
vte-xft-bold-font-selection.patch (5.63 KB, patch)
2008-06-22 01:45 UTC, Kees Cook
none Details | Review
vte-has_bold_font.patch (3.74 KB, patch)
2008-06-22 01:45 UTC, Kees Cook
needs-work Details | Review
vte-choose-bold.patch (10.83 KB, patch)
2008-06-22 01:51 UTC, Kees Cook
needs-work Details | Review
vte-xft-draw-bold.patch (1.55 KB, patch)
2008-06-22 01:51 UTC, Kees Cook
none Details | Review
vte-xft-locked-font-fixes.patch (4.12 KB, patch)
2008-06-22 17:51 UTC, Kees Cook
none Details | Review
support bold fonts (9.78 KB, patch)
2008-11-22 19:08 UTC, Kees Cook
none Details | Review
support bold fonts and double-strike (11.04 KB, patch)
2009-01-27 17:35 UTC, Kees Cook
needs-work Details | Review
selective font bolding with fallback to double-strike (11.23 KB, patch)
2009-02-11 00:46 UTC, Kees Cook
none Details | Review
selective font bolding with fallback to double-strike (11.65 KB, patch)
2009-02-12 03:45 UTC, Kees Cook
none Details | Review
selective font bolding with fallback to double-strike (14.12 KB, patch)
2009-02-12 05:20 UTC, Kees Cook
committed Details | Review

Description Ralph Deeb 2001-05-19 00:10:14 UTC
gnome-terminal doesn't attempt to use the bold version of the terminal font
to indicate bold on the console.  It simply repaints the same unbolded font
offset by one pixel, which results in making the bold sections of the
console unreadable when using certain fonts that don't lend themselves to
this sort of "pseudo-bolding" (for instance, when glyphs contain a lot of
1-pixel spaces and those get covered up in pseudo-bolding).  These fonts
already have a bold version, and that version should be used before trying
pseudo-bolding.  gnome-terminal should only fall back to pseudo-bolding if
a bold version of the selected font is unavailable.
Comment 1 Havoc Pennington 2002-02-14 03:15:56 UTC
libzvt issue
Comment 2 Havoc Pennington 2002-03-09 21:46:49 UTC
This may be fixable on the gnome-terminal level as well, 
gnome-terminal could pass in a bold font, using 
the information from the font selector.
Comment 3 Ilmari Vacklin 2006-07-16 02:29:58 UTC
Any progress on this? Move to libzvt or gnome-terminal or both?
Comment 4 Behdad Esfahbod 2006-07-16 03:24:17 UTC
Main problem with trying bold fonts first is that they typically have wider glyphs and wider metrics, so creeping them into the cell array may make them look /very/ bad.
Comment 5 Ilmari Vacklin 2006-07-16 03:47:37 UTC
Does that apply to monospaced fonts? For an example, bold Consolas looks great in XTerm.
Comment 6 Behdad Esfahbod 2006-07-16 05:31:27 UTC
(In reply to comment #5)
> Does that apply to monospaced fonts?

It does.  There was this bug about that, in the context of syntax highlighting (using bold faces) in gedit with monospaced fonts.

> For an example, bold Consolas looks great in XTerm.

That's probably a bitmap font.
Comment 7 Ilmari Vacklin 2006-07-16 05:51:00 UTC
> > Does that apply to monospaced fonts?
> 
> It does.  There was this bug about that, in the context of syntax
> highlighting (using bold faces) in gedit with monospaced fonts.

Ah. I'll dig that up then.

> > For an example, bold Consolas looks great in XTerm.
> 
> That's probably a bitmap font.

No, it's purely vector. It's MS's monospace font for Vista. I'd give a link but I don't know about the legality.

Thanks for your replies. 
Comment 8 Chris Wilson 2007-02-06 12:05:56 UTC
xterm has a separate bold font and uses char_width=MAX(normal, bold).
Comment 9 Kees Cook 2008-06-22 01:43:36 UTC
I've implemented bold font handling.  It required a certain level of refactoring, so I've split up the patches:

vte-xft-locking-with-font.patch    - xft: move font locking into the font struct
vte-xft-bold-font-selection.patch  - xft: perform bold font choosing
vte-has_bold_font.patch            - core: add "has_bold_font" logic
vte-choose-bold.patch              - core: request bold font when available
vte-xft-draw-bold.patch            - xft: draw with bold font when bold requested
Comment 10 Kees Cook 2008-06-22 01:44:35 UTC
Created attachment 113185 [details] [review]
vte-xft-locking-with-font.patch
Comment 11 Kees Cook 2008-06-22 01:45:12 UTC
Created attachment 113186 [details] [review]
vte-xft-bold-font-selection.patch
Comment 12 Kees Cook 2008-06-22 01:45:38 UTC
Created attachment 113187 [details] [review]
vte-has_bold_font.patch
Comment 13 Kees Cook 2008-06-22 01:51:04 UTC
Created attachment 113188 [details] [review]
vte-choose-bold.patch
Comment 14 Kees Cook 2008-06-22 01:51:25 UTC
Created attachment 113189 [details] [review]
vte-xft-draw-bold.patch
Comment 15 Kees Cook 2008-06-22 15:14:26 UTC
Hmmm.  Something is wrong with the font locking change.  I'm seeing crashes, but haven't narrowed down the cause yet.  It's crashing here, with a NULL deref, so I assume I wrecked the array management somehow:

  • #0 _vte_xft_get_char_width
    at /root/kees/src/vte-0.16.13/./src/vtexft.c line 303
  • #1 _vte_draw_get_char_width
    at /root/kees/src/vte-0.16.13/./src/vtedraw.c line 324
  • #2 _vte_invalidate_cell
    at /root/kees/src/vte-0.16.13/./src/vte.c line 650

I'll keep digging -- maybe I shouldn't have refactored it to begin with :)
Comment 16 Kees Cook 2008-06-22 15:43:25 UTC
Steps to reproduce:
 1) close all gnome-terminals
 2) open one, then another
 3) close the latter one
 4) type into the first -- crash

At a glance, I think this is due to _vte_xft_get_char_width needing to check both the normal and bold font sizes and the locked font arrays aren't fully initialized.
Comment 17 Kees Cook 2008-06-22 17:51:01 UTC
Created attachment 113214 [details] [review]
vte-xft-locked-font-fixes.patch

This seems to fix the crashes I was seeing before.  At the very least, they are memory leak clean ups from the original refactoring of the font locking code.
Comment 18 James Strandboge 2008-07-16 15:58:36 UTC
Tried Kees' patches and they work well for me. vte is stable and my fixed width font is bolded rather than pseudo-bolded.
Comment 19 Behdad Esfahbod 2008-08-05 09:44:18 UTC
Should be fixed in more than just Xft.  Chris, feel like hacking on this?
Comment 20 Kees Cook 2008-08-05 17:05:29 UTC
It certainly should be fixed in more than just Xft.  I didn't want to do too much more work on this problem unless it's approach was going to be "approved".  Since the framework allows for other backends to declare that they don't support real bolding, the patches as-they-are should work for now.
Comment 22 Christian Persch 2008-11-22 12:30:05 UTC
Setting patch statuses; the xft backend is gone on trunk.
Comment 23 Kees Cook 2008-11-22 19:08:50 UTC
Created attachment 123225 [details] [review]
support bold fonts

Here is the patch reworked for the pangocairo backend.  Note that I haven't tested this yet, but I wanted to get something into the tracker so this bug doesn't continue to age.  :)
Comment 24 Tobias Wolf 2009-01-20 20:12:44 UTC
This patch causes problems with some fonts. See bug #567856
Comment 25 Kees Cook 2009-01-20 23:04:38 UTC
This may be hard to test without the actual font.  I wouldn't expect this patch to break fonts without a bold face (it explicitly uses the non-bold bold when the bold font isn't available -- the old behavior).
Comment 26 Tobias Wolf 2009-01-21 00:08:47 UTC
I removed the patch from the Ubuntu package and it’s back to normal. Dunno.
Comment 27 Behdad Esfahbod 2009-01-21 03:16:30 UTC
(In reply to comment #25)
> This may be hard to test without the actual font.  I wouldn't expect this patch
> to break fonts without a bold face (it explicitly uses the non-bold bold when
> the bold font isn't available -- the old behavior).

This is why:

+	*width  = MAX(data->font->width, data->font_bold->width);
Comment 28 Kees Cook 2009-01-21 19:08:27 UTC
If the fonts are the same (neither bold), why would this be any different?
Comment 29 Kees Cook 2009-01-21 19:45:46 UTC
e.g.:
$ fc-match 'Sans'
DejaVuSans.ttf: "DejaVu Sans" "Book"
$ fc-match 'Sans:style=Bold'
DejaVuSans-Bold.ttf: "DejaVu Sans" "Bold"
$ fc-match 'Pragmata'
pragmata.ttf: "Pragmata" "Medium"
$ fc-match 'Pragmata:style=Bold'
pragmata.ttf: "Pragmata" "Medium"
Comment 30 Behdad Esfahbod 2009-01-27 07:11:37 UTC
You get the same font indeed, but with FreeType pseudo-bolding, which increases the font width.
Comment 31 Chris Jones 2009-01-27 10:24:30 UTC
Isn't it quite likely that whether the bolding is freetype's pseudo-bolding, or use of a separate bold font, that it will be wider? (and for that matter, shouldn't the current double-stamping method make it wider too?)

Could the kerning/tracking of the bold font be reduced to compensate? The current upstream method of bolding can make fonts illegible below a certain size, so one has to wonder if trading off the spacing for legibility is the better compromise.
Comment 32 Kees Cook 2009-01-27 17:35:00 UTC
Created attachment 127339 [details] [review]
support bold fonts and double-strike

I realize I had dropped the double-strike completely, which isn't appropriate.  This patch restores the double-strike behavior when there is no bold font available.

Behdad: how can we detect the FT pseudo-bolding of a font and either get rid of it in favor of the old-style double-strike, or compensate in some other way?
Comment 33 Behdad Esfahbod 2009-02-05 18:22:40 UTC
I think the way this should work is:

1. Decide whether to use a bold font or double-strike
2. Do that.

Step 1 happens like this:

  - If the computed cell width of the bold font is more than 110% of the width of the normal font, use double-strike, otherwise use the bold font.

In any case, use the width of the normal font as the cell width regardless.

Now, there's also this factor that we may want to use in our decision-making process:

  - If the family name of the normal and the bold fonts is not the same, use the double-strike.


behdad
Comment 34 Kees Cook 2009-02-11 00:46:57 UTC
Created attachment 128428 [details] [review]
selective font bolding with fallback to double-strike

This patch disregards bold fonts that exceed a 10% difference in cell width, causing a fallback to double-strike mode.  Tests show it falling back correctly for the commercial font that lacked a bold face, and correctly using a bold face for fonts that support one.

e.g.:
(gnome-terminal:24091): Vte-WARNING **: bold font too wide (12 not within 10% of normal width 10), falling back to double-strike
Comment 35 Behdad Esfahbod 2009-02-12 02:01:54 UTC
Thanks for the update.  A few points before it can go in:

  - No warning please.

  - In a few places you pass FALSE for the bold parameter.  It should really come from the real cell being drawn.  It's plain wrong otherwise.

  - I like to see the double-strike moved to the pangocairo layer.

Thanks
behdad
Comment 36 Kees Cook 2009-02-12 03:45:19 UTC
Created attachment 128514 [details] [review]
selective font bolding with fallback to double-strike

- warning in vteskel.c eliminated (if there are others, I could not find them; please advise).

- the FALSE passed for the bold parameters comes from the graphics-drawing code; I did not see any bold attribute associated with those actions, so I used "FALSE" (which also match the original behavior, which had no knowledge of bold for those actions).  I am open to suggestions for handling it in a different way.

- I disagree about the location of double-strike: it needs to be done by the top-level vte for backends that don't support it (yes, there is only one currently, but it is a generally useful routine to keep at the top-level, as it was originally).  This is why the vte backend gained the has_bold() capability to report up the chain.
Comment 37 Behdad Esfahbod 2009-02-12 03:52:41 UTC
(In reply to comment #36)
> Created an attachment (id=128514) [edit]
> selective font bolding with fallback to double-strike

Thanks.

> - warning in vteskel.c eliminated (if there are others, I could not find them;
> please advise).
> 
> - the FALSE passed for the bold parameters comes from the graphics-drawing
> code; I did not see any bold attribute associated with those actions, so I used
> "FALSE" (which also match the original behavior, which had no knowledge of bold
> for those actions).  I am open to suggestions for handling it in a different
> way.

Well, in the original code it didn't matter as the "bold" variant and normal font had the same coverage.  It's not necessarily true anymore.  You need to add a "bold" parameter to the functions that are calling with FALSE now and pass the proper cell attribute to those functions.

> - I disagree about the location of double-strike: it needs to be done by the
> top-level vte for backends that don't support it (yes, there is only one
> currently, but it is a generally useful routine to keep at the top-level, as it
> was originally).  This is why the vte backend gained the has_bold() capability
> to report up the chain.

Well, doesn't matter that much, but for the sake of abstraction it should be moved to vtedraw for the least.  It's not the widget's business really.  We're actually very close to removing the vtedraw abstraction and hardcode the single backend at hand.

With these addressed, I'll go ahead and commit the patch :).

Thanks again,
behdad


Comment 38 Kees Cook 2009-02-12 05:20:28 UTC
Created attachment 128527 [details] [review]
selective font bolding with fallback to double-strike

This passes bold information from cells in all places they're available, and moves double-striking into vtedraw.  Tests look ok for bold and non-bold fonts, as before.

Should I add a ChangeLog commit?  I don't want to miss out on attribution for a nearly 8 year old bug.  :)
Comment 39 Behdad Esfahbod 2009-02-12 05:33:49 UTC
Committed with proper attribution.  Thanks!

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.