n-t-roff / heirloom-doctools

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

TTF Font fails in troff #33

Closed arcfide closed 8 years ago

arcfide commented 8 years ago

I am attempting to use the following font:

http://dyalog.com/uploads/files/download.php?file=fonts_and_keyboards/Apl385.ttf

It fails during ghostscript interpretation with the following error:

cat test.ms | refer -e -sAD -p biblio.db | tbl | troff -ms | dpost | ps2pdf -sPAPERSIZE=letter - - > test.pdf
Error: /typecheck in --readonly--
Operand stack:
   CharStrings   --dict:772/772(L)--   dot
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1983
  1   3   %oparray_pop   1982   1   3   %oparray_pop   1966   1   3   %oparray_pop   1852   1   3       %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1203/1684(ro)(G)--   --dict:0/20(G)--   --dict:160/200(L)--   --dict:7/11(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.19: Unrecoverable error, exit code 1
Makefile:4: recipe for target 'test.pdf' failed
make: *** [test.pdf] Error 1

I used the following test document:

.do xflag 3
.mediasize letter
.hylang en_US
.lc_ctype en_US.UTF-8
.fp 1 R Apl385 ttf
.TL
Test Document
.AU
Aaron W. Hsu
awhsu@indiana.edu
.AI
Indiana University, USA
.NH
Problem Statement
.LP
This document fails to compile correctly
when I attempt to use the APL385 Unicode fixed-width font.

This is on a Slackware-current system running the latest checkout from git.

saper commented 8 years ago

Incidentally I am using this very font in all my xterm and putty windows :)

is this font known to Ghostscript? Usually Ghostscript uses its own font directory and there is a Fontmap file.

n-t-roff commented 8 years ago

I get the same error message, even after adding the font to ghostscript's Fontmap. It does not look like a heirloom-doctools problem, but rather like a ghostscript issue. Does anyone else has an idea?

arcfide commented 8 years ago

I found an issue with a similiar error report in Ghostscript, but the ghostscript maintainers complained that the issue wasn't with Ghostscript, but with the program that generated the code.

http://ghostscript.com/pipermail/gs-bugs/2011-May/019599.html

Furthermore, I can confirm that it doesn't matter whether Ghostsript has the font in the Fontmap, because I took the FreeMono otf font and I was able to use that without problems, even without it being in the Fontmap.

arcfide commented 8 years ago

I can also confirm that I've just tested this with another TTF font derived from the FreeMono otf font that works just fine. However, both the Apl385 and Apl333 fonts don't work. I have also tried it with the SImPL_medium_APL TTF font and that works fine. It is only the Apl385 and Apl333 fonts that don't seem to be working.

n-t-roff commented 8 years ago

Of course it works with other ttf/otf fonts. I have no idea what the problem is with the Apl fonts. I'll ask the groff list.

lemzwerg commented 8 years ago

The font given in the link above is invalid. It contains a glyph named "Ano" – note the trailing space in the glyph name, which is not allowed. I guess this makes heirloom output wrong code which GhostScript doesn't like.

n-t-roff commented 8 years ago

Thank you very much for this information!

(So maybe a kludge could be to ignore invalid invalid glyph names. I'll have a look...)

arcfide commented 8 years ago

I can confirm that this was indeed the problem. Actually, there are two glyphs in Apl385.ttf which cause the problem, Ano and dot product. By removing the space from each of these using fontforge, I was able to get things to render just fine, and Ghostscript and Heirloom doctools troff now handle them fine. I'm going to throw this up the chain on the font developer's for this font.

arcfide commented 8 years ago

Also, I'm tagging @mkromberg and @jayfoad about this, in case they can see it.

saper commented 8 years ago

The following sed(1) script removes the broken definition of "dot product":

/dot product 732 def/d
s/\/dot product//

so the following pipeline should be producing the desired effect:

cat test.ms | refer -e -sAD -p biblio.db | tbl | troff -ms | dpost | sed -e '/dot product 732 def/d;s/\/dot product//' | ps2pdf
saper commented 8 years ago

Actually I came to conclusion that dpost(1) should have been more careful when creating font definitions in PostScript.

34 should fix the problem

saper commented 8 years ago

OTF specification mentions only "PostScript glyph names" but it does not require them to be containing specific characters. Type 42 format spec says that the /CharStrings dictionary keys and values can be generated by the PostScript language, so it is okay to use PostScript code to create a non-standard key name.

arcfide commented 8 years ago

Thanks for the quick response on this issue.