ref: 6477491bab369fc4218eee234f2e9b7aaa3677ef
parent: 299c7f1973c97de2dc5dfdb66d392c2c98973f74
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sat Aug 3 15:53:46 EDT 2013
ps: cache scaled fonts Ideally it should have been more efficient to replace "fontlookup setfont" with "selectfont"; according to Adobe documents selectfont should cache fonts but ghostscript's implementation does not, at least for OTF files. So we do our own caching in fontlookup.
--- a/ps.c
+++ b/ps.c
@@ -53,10 +53,36 @@
"/rgb {255 div 3 1 roll 255 div 3 1 roll 255 div 3 1 roll setrgbcolor} bind def\n"
"/done {/lastpage where {pop lastpage} if} def\n"
"\n"
+ "% caching fonts returned from findfont in fncache\n"
+ "/fncache 7 array def\n"
+ "/fncidx 0 def\n"
+ "/fontlookup {\n"
+ " /fsize exch def\n"
+ " /fname exch def\n"
+ " /font null def\n"
+ " fncache {\n"
+ " /ent exch def\n"
+ " ent null eq not {\n"
+ " ent 0 get fname eq {\n"
+ " /font ent 1 get def\n"
+ " } if\n"
+ " } if\n"
+ " } forall\n"
+ " font null eq {\n"
+ " /font fname findfont def\n"
+ " fncache fncidx [fname font] put\n"
+ " /fncidx fncidx 1 add def\n"
+ " fncidx fncache length ge {\n"
+ " /fncidx 0 def\n"
+ " } if\n"
+ " } if\n"
+ " font fsize scalefont\n"
+ "} bind def\n"
"/f {\n"
" /font exch def /ptsize exch def\n"
" ptsize scaling div /size exch def\n"
- " font findfont size scalefont setfont\n"
+ " % to disable caching: font findfont size scalefont setfont\n"
+ " font size fontlookup setfont\n"
" linewidth ptsize mul scaling 10 mul div setlinewidth\n"
"} bind def\n"
"\n"