Re: Ghostscript/GhostPDL 9.22 Release Candidate 1

Knut Petersen <[email protected]> Tue, 19 Sep 2017 22:30:55 +0200
Newsgroups gmane.comp.gnu.lilypond.devel,gmane.comp.printing.ghostscript.devel
Message-ID <[email protected]>
Hi everybody!

>> So you aren't gaining any benefit from exploiting the Ghostscript bug
>> with the Lilypond output.
> But we are.  I hope that Masamichi-san (or Kurt?) can provide the
> details here in order to give you a better picture.
*
*Some technical details about our usage of the bug/feature we discuss.

*Our fonts*
**
The font family with the symbols used for notation is called emmentaler, it is provided in several design sizes.
To keep this short: Below I use 20 as the design size of the font and will not mention other sizes as they are handled identically.
Emmentaler fonts are otf fonts build from our own sources.
Every emmentaler font  contains more than 2*2^8 but less than 3*2^8 symbols.
There is also an  emmentaler-brace font, it is handled identically. To keep this short I will not mention emmentaler-brace again.

*Lilypond is used for single documents that are intended to be the final document*

If lilypond is used to write a document that is not intended to be included in other documents, it generates a postscript file and feeds that to ghostscript.Ghostscript does a good job, it constructs a font from the glyphs of our emmentaler font that contains only the glyphs actually used in the 
document, includes it in the generated pdf, and the result is a  pdf with as few font data as possible.

If lilypond is used to write a slightly different document, chances are very high that the font ghostscript constructs from the glyphs of our emmentaler font is different because different symbols are included.

*What happens if you include several  "final" pdfs in a *TeX document?*

If you include several pdfs generated as described above in a *TeX-generated pdf, all fonts from the lilypond pdfs are included. Probably all are different. If you  feed the  *TeX-pdf to ghostscript, ghostscript sees different fonts (although all are constructed from emmentaler glyphs). ghostscript 
never was able to merge those fonts, and it probably never will be able.

*We include thousands of lilypond-pdfs in a TeX document*

Now we plan to write a big TeX document with thousands of different pdfs. All are based on different lilypond source files, "lilypond --bigpdf"  is used. Lilypond generates postscript files and calls ghostscript, but the postscript files generated by lilypond are different:

  * Now every postscript file contains three encodings (an encoding cannot contain more than 256 glyphs) with glyphs from the emmentaler font ( LilyNoteHeadEncoding, LilyScriptEncoding and LilyOtherEncoding).  Every glyph of the emmentaler font is included in exactly one of the encodings.
  * For every glyph we define a command (e.g. "/noteheads.s2 {<6f> show} def").
  * We include font directorys, e.g.:

        FontDirectory /Emmentaler-20 known {
           /Emmentaler-20 findfont dup length dict copy begin
           /Encoding LilyNoteHeadEncoding def
           /Emmentaler-20-N currentdict definefont pop end
           /Emmentaler-20 findfont dup length dict copy begin
           /Encoding LilyScriptEncoding def
           /Emmentaler-20-S currentdict definefont pop end
           /Emmentaler-20 findfont dup length dict copy begin
           /Encoding LilyOtherEncoding def
           /Emmentaler-20-O currentdict definefont pop end
        } if

  *     We also define

        /magfontemmentaler-20mXVo-N { /Emmentaler-20-N 7.0292 output-scale div selectfont } bind def
        /magfontemmentaler-20mXVo-S { /Emmentaler-20-S 7.0292 output-scale div selectfont } bind def
        /magfontemmentaler-20mXVo-O { /Emmentaler-20-O 7.0292 output-scale div selectfont } bind def
        /helpEmmentaler-20 {
           gsave
           1 setgray
           /Emmentaler-20-N 0.001 selectfont 0 0 moveto <01> show
           /Emmentaler-20-S 0.001 selectfont 0 0 moveto <01> show
           /Emmentaler-20-O 0.001 selectfont 0 0 moveto <01> show
           grestore
        } def

  * Prior to any other output we execute helpEmmentaler-20 defined above.
  * To print a glyph we use constructs like the one below (here we do not use glyphshow but show ...)

        67.7411 -17.6139 moveto magfontemmentaler-20mXVo-N noteheads.s2

  * -dSubsetFonts=false is used.

This way ghostscript is persuaded to include three emmentaler fonts in the generated pdf, one for every encoding. And there is no subsetting. That means the pdfs are really big. But all the pdfs generated this way include three identical  fonts constructed by ghostscript from emmentaler glyphs.

Now the *TeX document is compiled to pdf. Thousands of big lilypond pdfs with all their fonts are included.

Finally the pdf generated by *TeX is fed to ghostscript. An old ghostscript or a ghostscript with the PDFDontUseFontObjectNum option enabled will output a pdf with all superfluous copies of the fonts removed.

Knut
_______________________________________________
lilypond-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-devel