n-t-roff / heirloom-doctools

The Heirloom Documentation Tools: troff, nroff, and related utilities
http://n-t-roff.github.io/heirloom/doctools.html
Other
127 stars 23 forks source link

Kerning adjustment being performed on device control function \X'string' #90

Closed mircea3 closed 4 years ago

mircea3 commented 4 years ago

When using \X'string', if any of the characters in string have kerning pairs, the final text layout is affected. \Y does not have this issue. This may be more or less pronounced, depending on the font being used. For example, font "TexGyre Schola" has a kerning adjustment for the pair "et", meaning that \X'SetColor: ...' will affect the text positioning, if that particular font is active. The following example purposely uses characters which make the problem easier to notice:

.do xflag 3
.mediasize 100p 100p
.po 10p
.ll 40p
.\" example device control function with kerning pairs:
.ds T VAVA: WaWa
.\" PROBLEM:
\X'\*T'A \X'\*T'B \X'\*T'C\p
.\" OK:
\YTA \YTB \YTC\p
.
.\" verify \Z'string' is not affected by the fix:
.kern 0
VA Wa                \" kern off: reference
.br
.kern 1
VA Wa                \" kern on
.br
\Z'VA Wa'            \" same result
.br

The result can be seen in attached file kern_problem.pdf.

The following fix seems to solve this problem, hopefully without creating any new problems. In file troff/troff.d/t6.c, modify line 471:

- if (!kern || ismot(c) || ismot(e) || html)
+ if (!kern || ismot(c) || ismot(e) || html || iszbit(c) || iszbit(e))

The result after the fix can be seen in attached file kern_problem_after_fix.pdf.

The example input includes the line \Z'VA Wa' to verify that the fix does not break kerning in zero width/height text. Maybe there are other cases which would need testing.

n-t-roff commented 4 years ago

Thank you for reporting the issues you have found. Unfortunately I'm not even have the time to verify them. Would you like to prepare a pull request of your suggested fix? If no one complains I'd apply it.