| 1 |
% render.ps - write font bitmaps and metric information to standard output. |
| 2 |
% Version 1.18. |
| 3 |
|
| 4 |
% ======================================================================== |
| 5 |
% |
| 6 |
% Copyright (c) 1993-2019 Paul Vojta |
| 7 |
% |
| 8 |
% Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 |
% of this software and associated documentation files (the "Software"), to |
| 10 |
% deal in the Software without restriction, including without limitation the |
| 11 |
% rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 12 |
% sell copies of the Software, and to permit persons to whom the Software is |
| 13 |
% furnished to do so, subject to the following conditions: |
| 14 |
% |
| 15 |
% The above copyright notice and this permission notice shall be included in |
| 16 |
% all copies or substantial portions of the Software. |
| 17 |
% |
| 18 |
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 |
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 |
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 |
% PAUL VOJTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 22 |
% IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 |
% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
% |
| 25 |
% ======================================================================== |
| 26 |
|
| 27 |
%%% |
| 28 |
% Usage: gs -DNODISPLAY -q -- render.ps fontname dlstring specinfo dpi |
| 29 |
% Then, it will read standard input to get: |
| 30 |
% pointsize |
| 31 |
% charset |
| 32 |
|
| 33 |
% Example: |
| 34 |
% % gs -DNODISPLAY -q -- render.ps Helvetica "(phvr.gsf) run" \ |
| 35 |
% > ".5 ExtendFont" 300 |
| 36 |
% GS> 10 |
| 37 |
% GS> 97 98 99 |
| 38 |
|
| 39 |
/TeXDict currentdict def % needed by dotlessj.pro |
| 40 |
|
| 41 |
%% |
| 42 |
% |
| 43 |
% Standard file definitions |
| 44 |
|
| 45 |
/.stdin where { pop } { /.stdin (%stdin) (r) file def } ifelse |
| 46 |
|
| 47 |
/bad-stdout false def |
| 48 |
/.stdout where |
| 49 |
{ pop } |
| 50 |
{ { /.stdout (%stdout) (w) file def } stopped |
| 51 |
{ /bad-stdout true def } |
| 52 |
if |
| 53 |
} ifelse |
| 54 |
|
| 55 |
/bad-stderr false def |
| 56 |
/.stderr where |
| 57 |
{ pop } |
| 58 |
{ { /.stderr (%stderr) (w) file def } stopped |
| 59 |
{ /bad-stderr true def } |
| 60 |
if |
| 61 |
} ifelse |
| 62 |
|
| 63 |
%% |
| 64 |
% |
| 65 |
% Define some routines first |
| 66 |
|
| 67 |
% (string) fatal - |
| 68 |
% Print string to stderr and quit. |
| 69 |
|
| 70 |
/fatal |
| 71 |
bad-stderr |
| 72 |
{{ |
| 73 |
(\nrender.ps: ) exch concatstrings |
| 74 |
print flush 1 .quit |
| 75 |
}} |
| 76 |
{{ |
| 77 |
(\nrender.ps: ) exch concatstrings |
| 78 |
.stderr exch writestring .stderr flushfile 1 .quit |
| 79 |
}} |
| 80 |
ifelse |
| 81 |
bind def |
| 82 |
|
| 83 |
% (string) brun - |
| 84 |
% Load a font in .pfb format. |
| 85 |
|
| 86 |
/brun |
| 87 |
{ |
| 88 |
(r) file false /PFBDecode filter cvx exec |
| 89 |
} |
| 90 |
bind def |
| 91 |
|
| 92 |
% (string) ttload font |
| 93 |
% Load a TrueType font (and leave it on the stack). |
| 94 |
|
| 95 |
/ttload |
| 96 |
{ |
| 97 |
FontOnStack |
| 98 |
{ |
| 99 |
(Cannot load more than one TrueType font!\n) fatal |
| 100 |
} if |
| 101 |
(r) file .loadttfont |
| 102 |
/FontOnStack true def |
| 103 |
} |
| 104 |
bind def |
| 105 |
|
| 106 |
/FontOnStack false def |
| 107 |
|
| 108 |
% (exec) getbbox - |
| 109 |
% Get bounding box of the executable object and save it in char-urx, |
| 110 |
% char-ury, etc. |
| 111 |
|
| 112 |
/getbbox |
| 113 |
{ |
| 114 |
gsave |
| 115 |
nulldevice |
| 116 |
erasepage |
| 117 |
newpath |
| 118 |
exec |
| 119 |
pathbbox % returns llx lly urx ury |
| 120 |
/char-ury exch ceiling cvi def |
| 121 |
/char-urx exch ceiling cvi def |
| 122 |
/char-lly exch floor cvi def |
| 123 |
/char-llx exch floor cvi def |
| 124 |
grestore |
| 125 |
} |
| 126 |
bind def |
| 127 |
|
| 128 |
% - drawfontbbox - |
| 129 |
% Draw the font's bbox. |
| 130 |
|
| 131 |
/drawfontbbox |
| 132 |
{ |
| 133 |
currentfont /FontBBox get |
| 134 |
dup dup 0 get exch 1 get currentfont /FontMatrix get transform moveto |
| 135 |
dup dup 0 get exch 3 get currentfont /FontMatrix get transform lineto |
| 136 |
dup dup 2 get exch 1 get currentfont /FontMatrix get transform lineto |
| 137 |
dup 2 get exch 3 get currentfont /FontMatrix get transform lineto |
| 138 |
} |
| 139 |
bind def |
| 140 |
|
| 141 |
% (exec) mkbboxdev - |
| 142 |
% Get bounding box of the executable object and make a device a few |
| 143 |
% pixels larger on each side. If pathbbox fails for the object, |
| 144 |
% then use the font's bbox. |
| 145 |
|
| 146 |
/mkbboxdev |
| 147 |
{ |
| 148 |
getbbox |
| 149 |
|
| 150 |
char-llx char-urx sub round 0 eq char-lly char-ury sub round 0 eq or |
| 151 |
{ |
| 152 |
{drawfontbbox} getbbox |
| 153 |
} |
| 154 |
if |
| 155 |
|
| 156 |
matrix |
| 157 |
char-urx char-llx sub 4 add % width |
| 158 |
dup /width exch def |
| 159 |
char-ury char-lly sub 4 add % height |
| 160 |
dup /height exch def |
| 161 |
<ff 00> |
| 162 |
makeimagedevice setdevice |
| 163 |
2 char-llx sub 2 char-lly sub translate |
| 164 |
} |
| 165 |
bind def |
| 166 |
|
| 167 |
%% |
| 168 |
% |
| 169 |
% These may be called by the "specinfo" string. |
| 170 |
|
| 171 |
/usefontbbox false def |
| 172 |
|
| 173 |
% These do things to a transformation array; called by entries in psfonts.map. |
| 174 |
% |
| 175 |
/ObliqueSlant {dup sin exch cos div neg} bind def |
| 176 |
/SlantFont {font-size mul add} def |
| 177 |
/ExtendFont {3 -1 roll mul exch} def |
| 178 |
/ReEncodeFont {/Encoding exch def} def |
| 179 |
|
| 180 |
% Define writeppmfile, if it's not provided, or if the symbol .stdout is not |
| 181 |
% available. |
| 182 |
|
| 183 |
/our-writeppmfile |
| 184 |
|
| 185 |
bad-stdout |
| 186 |
systemdict /writeppmfile known not |
| 187 |
or |
| 188 |
{{ |
| 189 |
(P4\n) print |
| 190 |
width =string cvs print |
| 191 |
( ) print |
| 192 |
height =string cvs print |
| 193 |
(\n) print |
| 194 |
|
| 195 |
width 7 add 8 div cvi string |
| 196 |
0 1 height 1 sub |
| 197 |
{ |
| 198 |
currentdevice exch 2 index copyscanlines |
| 199 |
print |
| 200 |
} |
| 201 |
for |
| 202 |
pop % discard string |
| 203 |
}} |
| 204 |
{{ |
| 205 |
.stdout currentdevice writeppmfile |
| 206 |
}} |
| 207 |
ifelse |
| 208 |
def |
| 209 |
|
| 210 |
|
| 211 |
%% |
| 212 |
% |
| 213 |
% Main program begins now. Just interpret it. |
| 214 |
|
| 215 |
% Get arguments. |
| 216 |
|
| 217 |
% |
| 218 |
% shellarguments is renamed as .shellarguments in gs-9.27 (early 2019) |
| 219 |
% The following works for gs-9.27 and gs-9.26 or older ones. |
| 220 |
% |
| 221 |
/.shellarguments where |
| 222 |
{ |
| 223 |
pop |
| 224 |
.shellarguments not |
| 225 |
{ |
| 226 |
(You must provide arguments to the shell!\n) fatal |
| 227 |
} |
| 228 |
if |
| 229 |
} |
| 230 |
if |
| 231 |
/shellarguments where |
| 232 |
{ |
| 233 |
pop |
| 234 |
shellarguments not |
| 235 |
{ |
| 236 |
(You must provide arguments to the shell!\n) fatal |
| 237 |
} |
| 238 |
if |
| 239 |
} |
| 240 |
if |
| 241 |
|
| 242 |
/dpi exch cvr def |
| 243 |
/specinfo exch def |
| 244 |
/dlstring exch def |
| 245 |
/fontname exch def |
| 246 |
|
| 247 |
% Return the gs version number to the calling program. |
| 248 |
|
| 249 |
(V ) print revision = |
| 250 |
|
| 251 |
% Open the font. |
| 252 |
|
| 253 |
dlstring () ne |
| 254 |
{ |
| 255 |
dlstring cvx exec |
| 256 |
} |
| 257 |
if |
| 258 |
|
| 259 |
FontOnStack not |
| 260 |
{ |
| 261 |
Fontmap fontname cvn known % Or: fontname cvn /Font resourcestatus? |
| 262 |
{ |
| 263 |
fontname cvlit findfont |
| 264 |
} |
| 265 |
{ |
| 266 |
FontDirectory fontname cvn known |
| 267 |
{ |
| 268 |
fontname cvlit findfont |
| 269 |
} |
| 270 |
{ |
| 271 |
revision 341 lt |
| 272 |
{ |
| 273 |
/defaultfontname fontname cvlit def |
| 274 |
} |
| 275 |
if |
| 276 |
|
| 277 |
{ fontname cvlit findfont } stopped |
| 278 |
{ |
| 279 |
(font ) fontname concatstrings |
| 280 |
( is not defined.\n) concatstrings |
| 281 |
fatal |
| 282 |
} |
| 283 |
if |
| 284 |
} |
| 285 |
ifelse |
| 286 |
} |
| 287 |
ifelse |
| 288 |
} |
| 289 |
if |
| 290 |
|
| 291 |
% Get arguments from stdin. Just leave the character list on the stack. |
| 292 |
|
| 293 |
/font-size |
| 294 |
.stdin 20 string readline pop cvr % get pointsize |
| 295 |
72.27 div dpi mul % let's work in (TeX) points |
| 296 |
def |
| 297 |
[ .stdin 1024 string readline pop cvx exec ] % character list |
| 298 |
|
| 299 |
% Define the font, and make it current. |
| 300 |
|
| 301 |
% Get the font. |
| 302 |
exch |
| 303 |
% Copy over the font dictionary to make it writable; |
| 304 |
% this makes ReEncodeFont easier, and is needed for dotless j processing. |
| 305 |
dup length 1 add dict begin |
| 306 |
{1 index /FID ne {def}{pop pop} ifelse} forall |
| 307 |
% Now do the transformations specified in psfonts.map. |
| 308 |
[ font-size 0 specinfo cvx exec 0 exch font-size 0 0 ] |
| 309 |
% End the current dictionary, and make it a font. |
| 310 |
/TargetFont currentdict end definefont |
| 311 |
% Apply the tranformation matrix and make the font current. |
| 312 |
exch makefont dup /TargetFont exch def setfont |
| 313 |
|
| 314 |
% If the font's bounding box is zero, then do not use it. |
| 315 |
|
| 316 |
usefontbbox |
| 317 |
{ currentfont /FontBBox get |
| 318 |
true exch {0 eq and} forall |
| 319 |
{/usefontbbox false def}if |
| 320 |
} |
| 321 |
if |
| 322 |
|
| 323 |
% If we are to use the font's bounding box, then get it and transform it. |
| 324 |
|
| 325 |
usefontbbox |
| 326 |
{ |
| 327 |
{drawfontbbox} mkbboxdev |
| 328 |
} |
| 329 |
if |
| 330 |
|
| 331 |
% Begin loop over characters. |
| 332 |
|
| 333 |
{ |
| 334 |
/charno exch def |
| 335 |
/charstring 1 string dup 0 charno put def |
| 336 |
/charwidth charstring stringwidth pop def |
| 337 |
|
| 338 |
% Get the character's bounding box. This also makes the device. |
| 339 |
usefontbbox not |
| 340 |
{ |
| 341 |
{ 0 0 moveto charstring true charpath } mkbboxdev |
| 342 |
} |
| 343 |
if |
| 344 |
|
| 345 |
% Print the metric info. |
| 346 |
(#^ ) print |
| 347 |
charno =string cvs print |
| 348 |
( ) print |
| 349 |
char-llx =string cvs print |
| 350 |
( ) print |
| 351 |
char-lly =string cvs print |
| 352 |
( ) print |
| 353 |
char-urx =string cvs print |
| 354 |
( ) print |
| 355 |
char-ury =string cvs print |
| 356 |
( ) print |
| 357 |
charwidth =string cvs print |
| 358 |
(\n) print |
| 359 |
|
| 360 |
% Now write the bitmap. |
| 361 |
erasepage 0 0 moveto |
| 362 |
charstring show |
| 363 |
our-writeppmfile |
| 364 |
} |
| 365 |
forall |