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

Liberation ttf font "space" character missing #88

Open mircea3 opened 5 years ago

mircea3 commented 5 years ago

Given the following test file:

.fp 1 R LiberationSans-Regular ttf
a b

The postscript output shows a missing ("box") character between the letters 'a' and 'b'. Manually editing the postscript file seems to fix the problem:

...
/.null 1 def
/nonmarkingreturn 2 def
/space 3 def              <-- insert this line
/uni00A0 3 def
/exclam 4 def
...

I am not sure whether the problem would be in the software, the font file, etc. The font comes from package fonts-liberation (or ttf-liberation) on Debian.

reffort commented 5 years ago

The TrueType implementation is limited. One of those limitations is that the glyphs are expected to have PostScript names, but names are not required by the TrueType specification. This limitation is actually documented in section 2.1 of the User's Manual. However, the significance is not emphasized: If the characters do not have PostScript names, they will not be found. (Some alternate names are supported, though.)

The PostScript name for the space character is "space", but in Liberation Sans it is named "uni00A0" (as shown in your example), which results in the missing space glyph. The hyphen-minus and semicolon are similarly affected. These are base PostScript glyphs, and the normal practice is to give them the standard PostScript names. Liberation Sans does not do that for these three. However, the other base glyphs do have the standard names.

It is possible to remap the non-space characters using .ftr:

.ftr R -\[uni00AD]
.ftr R ;\[uni037E]

But the only way I know of to fix the space character is to change the glyph name in the font file, using a font editor like FontForge.

A Rube Goldberg-style workaround might be to set .fspacewidth R 274 in the document (to get the correct space size) and then send the PostScript file through sed 's/\/uni00A0/\/space/g'.

It would take considerable effort to fix the TrueType anomalies. I think this is something worth doing, but until it happens my recommendation is to not use TrueType fonts at all--especially non-professionally designed free ones--unless they have been checked for compatibility first.

mircea3 commented 5 years ago

Thank you for the useful information. (I deleted one comment because of a silly mistake.)

reffort commented 5 years ago

.ftr is a long request name, so long names need to be enabled with .do xflag 3 near the beginning of the document. Other than that, I'm not aware of any issues with it.