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 685223 - [PATCH] Add support for italic text
[PATCH] Add support for italic text
Status: RESOLVED FIXED
Product: vte
Classification: Core
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: VTE Maintainers
VTE Maintainers
[fixed-next]
Depends on:
Blocks:
 
 
Reported: 2012-10-01 15:52 UTC by Patrick Niklaus
Modified: 2014-04-06 18:15 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Patch to add italic support (14.94 KB, patch)
2012-10-01 15:52 UTC, Patrick Niklaus
none Details | Review
The updated patch. (19.84 KB, patch)
2012-10-03 21:49 UTC, Patrick Niklaus
none Details | Review
The updated patch. (19.84 KB, patch)
2012-10-03 22:08 UTC, Patrick Niklaus
none Details | Review
New version. (21.67 KB, patch)
2012-10-04 23:49 UTC, Patrick Niklaus
reviewed Details | Review

Description Patrick Niklaus 2012-10-01 15:52:44 UTC
Created attachment 225503 [details] [review]
Patch to add italic support

Hey,

this patch adds support for italic text (escape code 3) to vte. However, vte does not announce support for this yet. (I'm not sure how and where to change that)

Cheers,
Patrick
Comment 1 Christian Persch 2012-10-01 16:47:41 UTC
Thanks for the patch!

A few questions / comments:

* Do you require this for a specific application (if so, which one) ? 

* Does xterm implement this?

* Your patch treats italic and bold as exclusive properties, but I don't see why they couldn't be combined (so a cell could be bold *and* italic).

From ECMA 48:

8.3.117
SGR - SELECT GRAPHIC RENDITION
Notation: (Ps...)
Representation: CSI Ps... 06/13
Parameter default value: Ps = 0
SGR is used to establish one or more graphic rendition aspects for subsequent 
                         ^^^^^^^^^^^
text. The established
aspects remain in effect until the next occurrence of SGR in the data stream, depending on the setting of
the GRAPHIC RENDITION COMBINATION MODE (GRCM). Each graphic rendition aspect is
specified by a parameter value:

1 bold or increased intensity
2 faint, decreased intensity or second colour
3 italicized
[...]

So in this code:
+		case 3:
+			terminal->pvt->screen->defaults.attr.italic = 1;
+			terminal->pvt->screen->defaults.attr.bold   = 0;
+			terminal->pvt->screen->defaults.attr.half   = 0;

the last 2 lines shouldn't be there, I think, and the font code should handle bold+italic too...

* As for the other code that's now passing around cell->attr.bold and cell->attr.italic, maybe would be better to pass around the full cell->attr instead?
Comment 2 Patrick Niklaus 2012-10-01 18:20:57 UTC
Hey,

I actually just wanted to have italics support in vim like with rxvt-unicode.

The reason why I didn't allow both italic and bold, was that it would have required a third parameter or a heavy modification of the code. (and really italic-bold is a corner case for terminals) But you are right, passing the attr instead of bold/italic would really be the clean way to do it.

Actually I just discovered a strange bug. It seems the order of the attributes in VteCellAttr matters. Naturally I put italic right under bold, but that breaks the color palette. Does some code touch this struct with raw bit-access?

Anyway, I'm going to restructure the patch to address the issues you mentioned.

Best Regards,
Patrick
Comment 3 Christian Persch 2012-10-02 17:52:23 UTC
I don't think the order should matter; maybe a build problem?

You can add the guint italic:1 at the end of the struct, luckily there is exactly 1 bit free until it overflows 32 bits :-)
Comment 4 Behdad Esfahbod 2012-10-02 18:08:21 UTC
(In reply to comment #2)
> Actually I just discovered a strange bug. It seems the order of the attributes
> in VteCellAttr matters. Naturally I put italic right under bold, but that
> breaks the color palette. Does some code touch this struct with raw bit-access?

Did you update basic_cell to match?
Comment 5 Patrick Niklaus 2012-10-03 21:49:45 UTC
Created attachment 225724 [details] [review]
The updated patch.
Comment 6 Patrick Niklaus 2012-10-03 21:50:09 UTC
(In reply to comment #4)
> 
> Did you update basic_cell to match?

Thank you, this was causing the problem. :-)

I updated my patch to also support bold italic text. I had to do some larger changed in vtedraw.c and a few text style flags to vtedraw.h VTE_DRAW_(NORMAL|BOLD|ITALIC). The patch should now work as intended.

Cheers, Patrick
Comment 7 Patrick Niklaus 2012-10-03 22:08:37 UTC
Created attachment 225727 [details] [review]
The updated patch.

Just realized that I accidentally changed the threshold for the rejection of bold fonts.
Comment 8 Christian Persch 2012-10-04 13:11:42 UTC
There are a few code style problems with the patch (e.g. we don't use declarations in the middle of code blocks, since that doesn't work with C89), but that's minor. I worry a bit about doubling the number of fonts used unconditionally even if no italic is actually used... Behdad, is that a significant memory problem?

The most important problem however is that it simply doesn't work with our default TERM setting. I have to use TERM=rxvt-unicode for it to work; neither xterm nor xterm-256color works. However, we do have to figure out our TERM story anyway for the 256 color problem (fedora patching this downstream).
Comment 9 Behdad Esfahbod 2012-10-04 18:15:46 UTC
Doubling fonts shouldn't be a problem.  Fonts are fairly light-weight these days.
Comment 10 Patrick Niklaus 2012-10-04 23:49:01 UTC
Created attachment 225854 [details] [review]
New version.

Fixed some coding style problems, double-striking italic text should now also work better.
Comment 11 Christian Persch 2012-10-05 19:48:16 UTC
Review of attachment 225854 [details] [review]:

Thanks for the updated patch! Looking mostly good; just a few comments below.

First a general question: the bold fonts are checked against the non-bold variants to see if they're too wide; should we also check the italic non-bold font against the normal non-bold font to see if italic is too wide? And then implement fallback faux-italic by slanting?

::: src/vte.c
@@ +10117,3 @@
 		if (clear && (draw_default_bg || bg != defbg)) {
+			gint bold_offset = _vte_draw_has_bold(terminal->pvt->draw,
+									VTE_DRAW_BOLD) ? 0 : bold;

In case we decide to do fallback italic, this should use the style (ie potentially italic and/or bold) instead of just BOLD, I think:

gint bold_offset = _vte_draw_has_font_for_style(terminal->pvt->draw, style) ? 0 : (bold || italic)

(and compute style beforehand since it's now used twice in this func) ?

@@ +10524,3 @@
 				if (back != VTE_DEF_BG) {
+					gint bold_offset = _vte_draw_has_bold(terminal->pvt->draw,
+											VTE_DRAW_BOLD) ? 0 : bold;

Same comment here.

::: src/vterowdata.h
@@ +54,3 @@
 	guint32 fore: 9;	/* Index into color palette */
 	guint32 back: 9;	/* Index into color palette. */
 

Since the 32 bits are now full, delete the 

       /* unused; bug 499893
        guint32 protect: 1;
         */

        /* 30 bits */

comments at the end.

::: src/vteseq.c
@@ +2299,3 @@
+		case 3:
+			terminal->pvt->screen->defaults.attr.italic = 1;
+			break;

Need to also implement the sequence to turn italic off again, which is case 23 (as per ECMA 48).
Comment 12 Christian Persch 2012-10-06 21:33:17 UTC
I fixed the last two comments and pushed to vte-0-34 and vte-next branch.

The question from comment 11 remains however.

Also I noticed sth odd: when I set sth italic in vim (running under TERM=rxvt-unicode), it looks like it turns bold+italic instead of just italic...
Comment 13 Patrick Niklaus 2012-10-06 22:50:35 UTC
(In reply to comment #12)
> I fixed the last two comments and pushed to vte-0-34 and vte-next branch.
> 

Thank you very much. :-)

> The question from comment 11 remains however.
>

Personally I don't think a terminal should emulate every style of a font. Bold is a rather special case, because it can be easily emulated, most people don't notice the difference (compared to the real bold variant) and it is widely used.
That said, I have tested fonts with more than 10% size difference and up to 15% it still looks better IMHO to force the bold font in the normal-sized cell grid. (Observe for example Inconsolata with 14%)

> Also I noticed sth odd: when I set sth italic in vim (running under
> TERM=rxvt-unicode), it looks like it turns bold+italic instead of just
> italic...

I have tested vte-0-34 with gnome-terminal gnome-3-6 and can't observe this effect. What font are you using? With Inconsolata vim displays italic text correctly.
Comment 14 Christian Persch 2012-10-07 12:08:08 UTC
You're right, it works with Inconsolata but not with (default) "Monospace". Weird, but not a vte bug then.
Comment 15 Christian Persch 2012-10-08 19:55:01 UTC
Now we need to get the ncurses terminfo for 'vte' updated upstream so it includes the italic capability.