| 1 |
% This is the plain METAFONT base that's described in The METAFONTbook. |
| 2 |
% N.B.: Please change "base_version" whenever this file is modified! |
| 3 |
% And don't modify the file unless you change its name: |
| 4 |
% Everybody's "plain.mf" file should be the same, worldwide. |
| 5 |
|
| 6 |
% Unlimited copying and redistribution of this file are permitted as long |
| 7 |
% as this file is not modified. Modifications are permitted, but only if |
| 8 |
% the resulting file is not named plain.mf. |
| 9 |
|
| 10 |
string base_name, base_version; base_name="plain"; base_version="2.71"; |
| 11 |
|
| 12 |
message "Preloading the plain base, version "&base_version&": preliminaries,"; |
| 13 |
|
| 14 |
delimiters (); % this makes parentheses behave like parentheses |
| 15 |
def upto = step 1 until enddef; % syntactic sugar |
| 16 |
def downto = step -1 until enddef; |
| 17 |
def exitunless expr c = exitif not c enddef; |
| 18 |
let relax = \; % ignore the word `relax', as in TeX |
| 19 |
let \\ = \; % double relaxation is like single |
| 20 |
def ]] = ] ] enddef; % right brackets should be loners |
| 21 |
def -- = {curl 1}..{curl 1} enddef; |
| 22 |
def --- = .. tension infinity .. enddef; |
| 23 |
def ... = .. tension atleast 1 .. enddef; |
| 24 |
|
| 25 |
def gobble primary g = enddef; def killtext text t = enddef; |
| 26 |
primarydef g gobbled gg = enddef; |
| 27 |
def hide(text t) = exitif numeric begingroup t;endgroup; enddef; |
| 28 |
def ??? = hide(interim showstopping:=1; showdependencies) enddef; |
| 29 |
def stop expr s = message s; gobble readstring enddef; |
| 30 |
|
| 31 |
smoothing:=1; autorounding:=2; % this adjusts curves to the raster |
| 32 |
turningcheck:=2; % this will warn about a "strange path" |
| 33 |
granularity:=1; % this says that pixels are pixels |
| 34 |
|
| 35 |
def interact = % sets up to make "show" commands stop |
| 36 |
hide(showstopping:=1; tracingonline:=1) enddef; |
| 37 |
|
| 38 |
def loggingall = % puts tracing info into the log |
| 39 |
tracingcommands:=3; tracingedges:=2; tracingtitles:=1; tracingequations:=1; |
| 40 |
tracingcapsules:=1; tracingspecs:=1; tracingpens:=1; tracingchoices:=1; |
| 41 |
tracingstats:=1; tracingoutput:=1; tracingmacros:=1; tracingrestores:=1; |
| 42 |
enddef; |
| 43 |
|
| 44 |
def tracingall = % turns on every form of tracing |
| 45 |
tracingonline:=1; showstopping:=1; loggingall enddef; |
| 46 |
|
| 47 |
def tracingnone = % turns off every form of tracing |
| 48 |
tracingcommands:=0; tracingonline:=0; showstopping:=0; |
| 49 |
tracingedges:=0; tracingtitles:=0; tracingequations:=0; |
| 50 |
tracingcapsules:=0; tracingspecs:=0; tracingpens:=0; tracingchoices:=0; |
| 51 |
tracingstats:=0; tracingoutput:=0; tracingmacros:=0; tracingrestores:=0; |
| 52 |
enddef; |
| 53 |
|
| 54 |
message " basic constants and mathematical macros,"; |
| 55 |
|
| 56 |
% numeric constants |
| 57 |
newinternal eps,epsilon,infinity,_; |
| 58 |
eps := .00049; % this is a pretty small positive number |
| 59 |
epsilon := 1/256/256; % but this is the smallest |
| 60 |
infinity := 4095.99998; % and this is the largest |
| 61 |
_ := -1; % internal constant to make macros unreadable but shorter |
| 62 |
|
| 63 |
% pair constants |
| 64 |
pair right,left,up,down,origin; |
| 65 |
origin=(0,0); up=-down=(0,1); right=-left=(1,0); |
| 66 |
|
| 67 |
% path constants |
| 68 |
path quartercircle,halfcircle,fullcircle,unitsquare; |
| 69 |
quartercircle=(right{up}..(right+up)/sqrt2..up{left}) scaled .5; |
| 70 |
halfcircle=quartercircle & quartercircle rotated 90; |
| 71 |
fullcircle=halfcircle & halfcircle rotated 180 & cycle; |
| 72 |
unitsquare=(0,0)--(1,0)--(1,1)--(0,1)--cycle; |
| 73 |
|
| 74 |
% transform constants |
| 75 |
transform identity; |
| 76 |
for z=origin,right,up: z transformed identity = z; endfor |
| 77 |
|
| 78 |
% picture constants |
| 79 |
picture blankpicture,unitpixel; |
| 80 |
blankpicture=nullpicture; % `display blankpicture...' |
| 81 |
unitpixel=nullpicture; addto unitpixel contour unitsquare; |
| 82 |
|
| 83 |
% string constants |
| 84 |
string ditto; ditto = char 34; % ASCII double-quote mark |
| 85 |
|
| 86 |
% pen constants |
| 87 |
def capsule_def(suffix s) primary u = def s = u enddef enddef; |
| 88 |
capsule_def(pensquare) makepen(unitsquare shifted -(.5,.5)); |
| 89 |
capsule_def(penrazor) makepen((-.5,0)--(.5,0)--cycle); |
| 90 |
pen penspeck; penspeck=pensquare scaled eps; |
| 91 |
|
| 92 |
% nullary operators |
| 93 |
vardef whatever = save ?; ? enddef; |
| 94 |
|
| 95 |
% unary operators |
| 96 |
let abs = length; |
| 97 |
|
| 98 |
vardef round primary u = |
| 99 |
if numeric u: floor(u+.5) |
| 100 |
elseif pair u: (hround xpart u, vround ypart u) |
| 101 |
else: u fi enddef; |
| 102 |
|
| 103 |
vardef hround primary x = floor(x+.5) enddef; |
| 104 |
vardef vround primary y = floor(y.o_+.5)_o_ enddef; |
| 105 |
|
| 106 |
vardef ceiling primary x = -floor(-x) enddef; |
| 107 |
|
| 108 |
vardef byte primary s = |
| 109 |
if string s: ASCII fi s enddef; |
| 110 |
|
| 111 |
vardef dir primary d = right rotated d enddef; |
| 112 |
|
| 113 |
vardef unitvector primary z = z/abs z enddef; |
| 114 |
|
| 115 |
vardef inverse primary T = |
| 116 |
transform T_; T_ transformed T = identity; T_ enddef; |
| 117 |
|
| 118 |
vardef counterclockwise primary c = |
| 119 |
if turningcheck>0: |
| 120 |
interim autorounding:=0; |
| 121 |
if turningnumber c <= 0: reverse fi fi c enddef; |
| 122 |
|
| 123 |
vardef tensepath expr r = |
| 124 |
for k=0 upto length r - 1: point k of r --- endfor |
| 125 |
if cycle r: cycle else: point infinity of r fi enddef; |
| 126 |
|
| 127 |
% binary operators |
| 128 |
|
| 129 |
primarydef x mod y = (x-y*floor(x/y)) enddef; |
| 130 |
primarydef x div y = floor(x/y) enddef; |
| 131 |
primarydef w dotprod z = (xpart w * xpart z + ypart w * ypart z) enddef; |
| 132 |
|
| 133 |
primarydef x**y = if y=2: x*x else: takepower y of x fi enddef; |
| 134 |
def takepower expr y of x = |
| 135 |
if x>0: mexp(y*mlog x) |
| 136 |
elseif (x=0) and (y>0): 0 |
| 137 |
else: 1 |
| 138 |
if y=floor y: |
| 139 |
if y>=0: for n=1 upto y: *x endfor |
| 140 |
else: for n=_ downto y: /x endfor |
| 141 |
fi |
| 142 |
else: hide(errmessage "Undefined power: " & decimal x&"**"&decimal y) |
| 143 |
fi fi enddef; |
| 144 |
|
| 145 |
vardef direction expr t of p = |
| 146 |
postcontrol t of p - precontrol t of p enddef; |
| 147 |
|
| 148 |
vardef directionpoint expr z of p = |
| 149 |
a_:=directiontime z of p; |
| 150 |
if a_<0: errmessage("The direction doesn't occur"); fi |
| 151 |
point a_ of p enddef; |
| 152 |
|
| 153 |
secondarydef p intersectionpoint q = |
| 154 |
begingroup save x_,y_; (x_,y_)=p intersectiontimes q; |
| 155 |
if x_<0: errmessage("The paths don't intersect"); origin |
| 156 |
else: .5[point x_ of p, point y_ of q] fi endgroup |
| 157 |
enddef; |
| 158 |
|
| 159 |
tertiarydef p softjoin q = |
| 160 |
begingroup c_:=fullcircle scaled 2join_radius shifted point 0 of q; |
| 161 |
a_:=ypart(c_ intersectiontimes p); b_:=ypart(c_ intersectiontimes q); |
| 162 |
if a_<0:point 0 of p{direction 0 of p} else: subpath(0,a_) of p fi |
| 163 |
... if b_<0:{direction infinity of q}point infinity of q |
| 164 |
else: subpath(b_,infinity) of q fi endgroup enddef; |
| 165 |
newinternal join_radius,a_,b_; path c_; |
| 166 |
|
| 167 |
% special operators |
| 168 |
vardef incr suffix $ = $:=$+1; $ enddef; |
| 169 |
vardef decr suffix $ = $:=$-1; $ enddef; |
| 170 |
|
| 171 |
def reflectedabout(expr w,z) = % reflects about the line w..z |
| 172 |
transformed |
| 173 |
begingroup transform T_; |
| 174 |
w transformed T_ = w; z transformed T_ = z; |
| 175 |
xxpart T_ = -yypart T_; xypart T_ = yxpart T_; % T_ is a reflection |
| 176 |
T_ endgroup enddef; |
| 177 |
|
| 178 |
def rotatedaround(expr z, d) = % rotates d degrees around z |
| 179 |
shifted -z rotated d shifted z enddef; |
| 180 |
let rotatedabout = rotatedaround; % for roundabout people |
| 181 |
|
| 182 |
vardef min(expr u)(text t) = % t is a list of numerics, pairs, or strings |
| 183 |
save u_; setu_ u; for uu = t: if uu<u_: u_:=uu; fi endfor |
| 184 |
u_ enddef; |
| 185 |
|
| 186 |
vardef max(expr u)(text t) = % t is a list of numerics, pairs, or strings |
| 187 |
save u_; setu_ u; for uu = t: if uu>u_: u_:=uu; fi endfor |
| 188 |
u_ enddef; |
| 189 |
|
| 190 |
def setu_ primary u = |
| 191 |
if pair u: pair u_ elseif string u: string u_ fi; |
| 192 |
u_=u enddef; |
| 193 |
|
| 194 |
def flex(text t) = % t is a list of pairs |
| 195 |
hide(n_:=0; for z=t: z_[incr n_]:=z; endfor |
| 196 |
dz_:=z_[n_]-z_1) |
| 197 |
z_1 for k=2 upto n_-1: ...z_[k]{dz_} endfor ...z_[n_] enddef; |
| 198 |
newinternal n_; pair z_[],dz_; |
| 199 |
|
| 200 |
def superellipse(expr r,t,l,b,s)= |
| 201 |
r{up}...(s[xpart t,xpart r],s[ypart r,ypart t]){t-r}... |
| 202 |
t{left}...(s[xpart t,xpart l],s[ypart l,ypart t]){l-t}... |
| 203 |
l{down}...(s[xpart b,xpart l],s[ypart l,ypart b]){b-l}... |
| 204 |
b{right}...(s[xpart b,xpart r],s[ypart r,ypart b]){r-b}...cycle enddef; |
| 205 |
|
| 206 |
vardef interpath(expr a,p,q) = |
| 207 |
for t=0 upto length p-1: a[point t of p, point t of q] |
| 208 |
..controls a[postcontrol t of p, postcontrol t of q] |
| 209 |
and a[precontrol t+1 of p, precontrol t+1 of q] .. endfor |
| 210 |
if cycle p: cycle |
| 211 |
else: a[point infinity of p, point infinity of q] fi enddef; |
| 212 |
|
| 213 |
vardef solve@#(expr true_x,false_x)= % @#(true_x)=true, @#(false_x)=false |
| 214 |
tx_:=true_x; fx_:=false_x; |
| 215 |
forever: x_:=.5[tx_,fx_]; exitif abs(tx_-fx_)<=tolerance; |
| 216 |
if @#(x_): tx_ else: fx_ fi :=x_; endfor |
| 217 |
x_ enddef; % now x_ is near where @# changes from true to false |
| 218 |
newinternal tolerance, tx_,fx_,x_; tolerance:=.1; |
| 219 |
|
| 220 |
message " macros for converting from device-independent units to pixels,"; |
| 221 |
|
| 222 |
def fix_units = % define the conversion factors, given pixels_per_inch |
| 223 |
mm:=pixels_per_inch/25.4; cm:=pixels_per_inch/2.54; |
| 224 |
pt:=pixels_per_inch/72.27; pc:=pixels_per_inch/6.0225; |
| 225 |
dd:=1238/1157pt; cc:=12dd; |
| 226 |
bp:=pixels_per_inch/72; in:=pixels_per_inch; |
| 227 |
hppp:=pt; % horizontal pixels per point |
| 228 |
vppp:=aspect_ratio*hppp; % vertical pixels per point |
| 229 |
enddef; |
| 230 |
|
| 231 |
mm#=2.84528; pt#=1; dd#=1.07001; bp#=1.00375; |
| 232 |
cm#=28.45276; pc#=12; cc#=12.84010; in#=72.27; |
| 233 |
|
| 234 |
newinternal pixels_per_inch; % the given resolution |
| 235 |
newinternal blacker, o_correction; % device-oriented corrections |
| 236 |
|
| 237 |
def define_pixels(text t) = |
| 238 |
forsuffixes $=t: $:=$.#*hppp; endfor enddef; |
| 239 |
def define_whole_pixels(text t) = |
| 240 |
forsuffixes $=t: $:=hround($.#*hppp); endfor enddef; |
| 241 |
def define_whole_vertical_pixels(text t) = |
| 242 |
forsuffixes $=t: $:=vround($.#*hppp); endfor enddef; |
| 243 |
def define_good_x_pixels(text t) = |
| 244 |
forsuffixes $=t: $:=good.x($.#*hppp); endfor enddef; |
| 245 |
def define_good_y_pixels(text t) = |
| 246 |
forsuffixes $=t: $:=good.y($.#*hppp); endfor enddef; |
| 247 |
def define_blacker_pixels(text t) = |
| 248 |
forsuffixes $=t: $:=$.#*hppp+blacker; endfor enddef; |
| 249 |
def define_whole_blacker_pixels(text t) = |
| 250 |
forsuffixes $=t: $:=hround($.#*hppp+blacker); |
| 251 |
if $<=0: $:=1; fi endfor enddef; |
| 252 |
def define_whole_vertical_blacker_pixels(text t) = |
| 253 |
forsuffixes $=t: $:=vround($.#*hppp+blacker); |
| 254 |
if $<=0: $:=1_o_; fi endfor enddef; |
| 255 |
def define_corrected_pixels(text t) = |
| 256 |
forsuffixes $=t: $:=vround($.#*hppp*o_correction)+eps; endfor enddef; |
| 257 |
def define_horizontal_corrected_pixels(text t) = |
| 258 |
forsuffixes $=t: $:=hround($.#*hppp*o_correction)+eps; endfor enddef; |
| 259 |
|
| 260 |
def lowres_fix(text t) expr ratio = |
| 261 |
begingroup save min,max,first; |
| 262 |
forsuffixes $=t: if unknown min: min=max=first=$; min#=max#=$.#; |
| 263 |
elseif $.#<min#: min:=$; min#:=$.#; |
| 264 |
elseif $.#>max#: max:=$; max#:=$.#; fi endfor |
| 265 |
if max/min>ratio*max#/min#: forsuffixes $=t: $:=first; endfor fi |
| 266 |
endgroup enddef; |
| 267 |
|
| 268 |
message " macros and tables for various modes of operation,"; |
| 269 |
|
| 270 |
def mode_setup = |
| 271 |
warningcheck:=0; |
| 272 |
if unknown mode: mode=proof; fi |
| 273 |
numeric aspect_ratio; transform currenttransform; |
| 274 |
scantokens if string mode:("input "&mode) else: mode_name[mode] fi; |
| 275 |
if unknown mag: mag=1; fi |
| 276 |
if unknown aspect_ratio: aspect_ratio=1; fi |
| 277 |
displaying:=proofing; |
| 278 |
pixels_per_inch:=pixels_per_inch*mag; |
| 279 |
if aspect_ratio=1: let o_=\; let _o_=\ |
| 280 |
else: def o_=*aspect_ratio enddef; def _o_=/aspect_ratio enddef fi; |
| 281 |
fix_units; |
| 282 |
scantokens extra_setup; % the user's special last-minute adjustments |
| 283 |
currenttransform:= |
| 284 |
if unknown currenttransform: identity else: currenttransform fi |
| 285 |
yscaled aspect_ratio; |
| 286 |
clearit; |
| 287 |
pickup pencircle scaled (.4pt+blacker); |
| 288 |
warningcheck:=1; enddef; |
| 289 |
def smode = string mode; mode enddef; |
| 290 |
string extra_setup, mode_name[]; |
| 291 |
extra_setup=""; % usually there's nothing special to do |
| 292 |
newinternal displaying; % if positive, endchar will `showit' |
| 293 |
|
| 294 |
vardef magstep primary m = mexp(46.67432m) enddef; |
| 295 |
|
| 296 |
def mode_def suffix $ = |
| 297 |
$:=incr number_of_modes; |
| 298 |
mode_name[$]:=str$ & "_"; |
| 299 |
expandafter quote def scantokens mode_name[$] enddef; |
| 300 |
newinternal number_of_modes; |
| 301 |
|
| 302 |
% proof mode: for initial design of characters |
| 303 |
mode_def proof = |
| 304 |
proofing:=2; % yes, we're making full proofs |
| 305 |
fontmaking:=0; % no, we're not making a font |
| 306 |
tracingtitles:=1; % yes, show titles online |
| 307 |
pixels_per_inch:=2601.72; % that's 36 pixels per pt |
| 308 |
blacker:=0; % no additional blackness |
| 309 |
fillin:=0; % no compensation for fillin |
| 310 |
o_correction:=1; % no reduction in overshoot |
| 311 |
enddef; |
| 312 |
|
| 313 |
% smoke mode: for label-free proofs to mount on the wall |
| 314 |
mode_def smoke = |
| 315 |
proof_; % same as proof mode, except: |
| 316 |
proofing:=1; % yes, we're making unlabeled proofs |
| 317 |
extra_setup:=extra_setup&"grayfont black"; % with solid black pixels |
| 318 |
let makebox=maketicks; % make the boxes less obtrusive |
| 319 |
enddef; |
| 320 |
|
| 321 |
% lowres mode: for certain devices that print 200 pixels per inch |
| 322 |
mode_def lowres = |
| 323 |
proofing:=0; % no, we're not making proofs |
| 324 |
fontmaking:=1; % yes, we are making a font |
| 325 |
tracingtitles:=0; % no, don't show titles at all |
| 326 |
pixels_per_inch:=200; % that's the meaning of lowres |
| 327 |
blacker:=.65; % make pens a bit blacker |
| 328 |
fillin:=.2; % compensate for diagonal fillin |
| 329 |
o_correction:=.4; % but don't overshoot as much |
| 330 |
enddef; |
| 331 |
|
| 332 |
localfont:=lowres; % the mode most commonly used to make fonts |
| 333 |
|
| 334 |
% It is customary to input another file to supplement the PLAIN base. |
| 335 |
% This supplementary file adds analogous modes, corresponding to |
| 336 |
% local output devices, and it redefines `localfont' as appropriate. |
| 337 |
% The values of screen_rows and screen_cols should also be updated. |
| 338 |
% The auxiliary file should set base_version:=base_version&"/localname". |
| 339 |
% Remember that the present file PLAIN.MF should not be changed; |
| 340 |
% all local changes should be confined to a separate file. |
| 341 |
|
| 342 |
message " macros for drawing and filling,"; |
| 343 |
|
| 344 |
pen currentpen; |
| 345 |
path currentpen_path; |
| 346 |
picture currentpicture; |
| 347 |
transform currenttransform; |
| 348 |
def t_ = transformed currenttransform enddef; |
| 349 |
|
| 350 |
def fill expr c = addto_currentpicture contour c.t_ enddef; |
| 351 |
def addto_currentpicture = addto currentpicture enddef; |
| 352 |
def draw expr p = |
| 353 |
addto_currentpicture doublepath p.t_ withpen currentpen enddef; |
| 354 |
def filldraw expr c = fill counterclockwise c withpen currentpen enddef; |
| 355 |
def drawdot expr z = if unknown currentpen_path: def_pen_path_ fi |
| 356 |
addto_currentpicture contour |
| 357 |
currentpen_path shifted (z.t_) withpen penspeck enddef; |
| 358 |
def def_pen_path_ = |
| 359 |
hide(currentpen_path=tensepath makepath currentpen) enddef; |
| 360 |
|
| 361 |
def unfill expr c = fill c withweight _ enddef; |
| 362 |
def undraw expr p = draw p withweight _ enddef; |
| 363 |
def unfilldraw expr c = filldraw c withweight _ enddef; |
| 364 |
def undrawdot expr z = drawdot z withweight _ enddef; |
| 365 |
def erase text t = begingroup interim default_wt_:=_; |
| 366 |
cullit; t withweight _; cullit; endgroup enddef; |
| 367 |
newinternal default_wt_; default_wt_:=1; |
| 368 |
|
| 369 |
def cutdraw expr p = % caution: you may need autorounding=0 |
| 370 |
cutoff(point 0 of p, 180+angle direction 0 of p); |
| 371 |
cutoff(point infinity of p, angle direction infinity of p); |
| 372 |
culldraw p enddef; |
| 373 |
def culldraw expr p = addto pic_ doublepath p.t_ withpen currentpen; |
| 374 |
cull pic_ dropping(-infinity,0) withweight default_wt_; |
| 375 |
addto_currentpicture also pic_; pic_:=nullpicture; killtext enddef; |
| 376 |
vardef cutoff(expr z,theta) = |
| 377 |
interim autorounding := 0; interim smoothing := 0; |
| 378 |
addto pic_ doublepath z.t_ withpen currentpen; |
| 379 |
addto pic_ contour |
| 380 |
(cut_ scaled (1+max(-pen_lft,pen_rt,pen_top,-pen_bot)) |
| 381 |
rotated theta shifted z)t_; |
| 382 |
cull pic_ keeping (2,2) withweight -default_wt_; |
| 383 |
addto currentpicture also pic_; |
| 384 |
pic_:=nullpicture enddef; |
| 385 |
picture pic_; pic_:=nullpicture; |
| 386 |
path cut_; cut_ = ((0,_)--(1,_)--(1,1)--(0,1)--cycle) scaled 1.42; |
| 387 |
|
| 388 |
def pickup secondary q = |
| 389 |
if numeric q: numeric_pickup_ else: pen_pickup_ fi q enddef; |
| 390 |
def numeric_pickup_ primary q = |
| 391 |
if unknown pen_[q]: errmessage "Unknown pen"; clearpen |
| 392 |
else: currentpen:=pen_[q]; |
| 393 |
pen_lft:=pen_lft_[q]; |
| 394 |
pen_rt:=pen_rt_[q]; |
| 395 |
pen_top:=pen_top_[q]; |
| 396 |
pen_bot:=pen_bot_[q]; |
| 397 |
currentpen_path:=pen_path_[q] fi; enddef; |
| 398 |
def pen_pickup_ primary q = |
| 399 |
currentpen:=q yscaled aspect_ratio; |
| 400 |
pen_lft:=xpart penoffset down of currentpen; |
| 401 |
pen_rt:=xpart penoffset up of currentpen; |
| 402 |
pen_top:=(ypart penoffset left of currentpen)_o_; |
| 403 |
pen_bot:=(ypart penoffset right of currentpen)_o_; |
| 404 |
path currentpen_path; enddef; |
| 405 |
newinternal pen_lft,pen_rt,pen_top,pen_bot,pen_count_; |
| 406 |
|
| 407 |
vardef savepen = pen_[incr pen_count_]=currentpen; |
| 408 |
pen_lft_[pen_count_]=pen_lft; |
| 409 |
pen_rt_[pen_count_]=pen_rt; |
| 410 |
pen_top_[pen_count_]=pen_top; |
| 411 |
pen_bot_[pen_count_]=pen_bot; |
| 412 |
pen_path_[pen_count_]=currentpen_path; |
| 413 |
pen_count_ enddef; |
| 414 |
|
| 415 |
def clearpen = currentpen:=nullpen; |
| 416 |
pen_lft:=pen_rt:=pen_top:=pen_bot:=0; |
| 417 |
path currentpen_path; |
| 418 |
enddef; |
| 419 |
def clear_pen_memory = |
| 420 |
pen_count_:=0; |
| 421 |
numeric pen_lft_[],pen_rt_[],pen_top_[],pen_bot_[]; |
| 422 |
pen currentpen,pen_[]; |
| 423 |
path currentpen_path, pen_path_[]; |
| 424 |
enddef; |
| 425 |
|
| 426 |
vardef lft primary x = x + if pair x: (pen_lft,0) else: pen_lft fi enddef; |
| 427 |
vardef rt primary x = x + if pair x: (pen_rt,0) else: pen_rt fi enddef; |
| 428 |
vardef top primary y = y + if pair y: (0,pen_top) else: pen_top fi enddef; |
| 429 |
vardef bot primary y = y + if pair y: (0,pen_bot) else: pen_bot fi enddef; |
| 430 |
vardef good.x primary x = hround(x+pen_lft)-pen_lft enddef; |
| 431 |
vardef good.y primary y = vround(y+pen_top)-pen_top enddef; |
| 432 |
vardef good.lft primary z = save z_; pair z_; |
| 433 |
(z_+(pen_lft,0))t_=round((z+(pen_lft,0))t_); z_ enddef; |
| 434 |
vardef good.rt primary z = save z_; pair z_; |
| 435 |
(z_+(pen_rt,0))t_=round((z+(pen_rt,0))t_); z_ enddef; |
| 436 |
vardef good.top primary z = save z_; pair z_; |
| 437 |
(z_+(0,pen_top))t_=round((z+(0,pen_top))t_); z_ enddef; |
| 438 |
vardef good.bot primary z = save z_; pair z_; |
| 439 |
(z_+(0,pen_bot))t_=round((z+(0,pen_bot))t_); z_ enddef; |
| 440 |
|
| 441 |
vardef penpos@#(expr b,d) = |
| 442 |
(x@#r-x@#l,y@#r-y@#l)=(b,0) rotated d; |
| 443 |
x@#=.5(x@#l+x@#r); y@#=.5(y@#l+y@#r) enddef; |
| 444 |
|
| 445 |
def penstroke text t = |
| 446 |
forsuffixes e = l,r: path_.e:=t; endfor |
| 447 |
if cycle path_.l: cyclestroke_ |
| 448 |
else: fill path_.l -- reverse path_.r -- cycle fi enddef; |
| 449 |
def cyclestroke_ = |
| 450 |
begingroup interim turningcheck:=0; |
| 451 |
addto pic_ contour path_.l.t_ withweight 1; |
| 452 |
addto pic_ contour path_.r.t_ withweight _; |
| 453 |
cull pic_ dropping origin withweight default_wt_; |
| 454 |
addto_currentpicture also pic_; |
| 455 |
pic_:=nullpicture endgroup enddef; |
| 456 |
path path_.l,path_.r; |
| 457 |
|
| 458 |
message " macros for proof labels and rules,"; |
| 459 |
|
| 460 |
vardef makelabel@#(expr s,z) = % puts string s at point z |
| 461 |
if known z: special lcode_@# & s; |
| 462 |
numspecial xpart(z.t_); numspecial ypart(z.t_) fi enddef; |
| 463 |
string lcode_,lcode_.top,lcode_.lft,lcode_.rt,lcode_.bot, |
| 464 |
lcode_.top.nodot,lcode_.lft.nodot,lcode_.rt.nodot,lcode_.bot.nodot; |
| 465 |
lcode_.top=" 1"; lcode_.lft=" 2"; lcode_.rt=" 3"; lcode_.bot=" 4"; |
| 466 |
lcode_=" 0"; % change to " /" to avoid listing in overflow column |
| 467 |
lcode_.top.nodot=" 5"; lcode_.lft.nodot=" 6"; |
| 468 |
lcode_.rt.nodot=" 7"; lcode_.bot.nodot=" 8"; |
| 469 |
|
| 470 |
vardef labels@#(text t) = |
| 471 |
if proofing>1: forsuffixes $=t: |
| 472 |
makelabel@#(str$,z$); endfor |
| 473 |
fi enddef; |
| 474 |
vardef penlabels@#(text t) = |
| 475 |
if proofing>1: forsuffixes $$=l,,r: forsuffixes $=t: |
| 476 |
makelabel@#(str$.$$,z$.$$); endfor endfor |
| 477 |
fi enddef; |
| 478 |
|
| 479 |
def range expr x = numtok[x] enddef; |
| 480 |
def numtok suffix x=x enddef; |
| 481 |
tertiarydef m thru n = |
| 482 |
m for x=m+1 step 1 until n: , numtok[x] endfor enddef; |
| 483 |
|
| 484 |
def proofrule(expr w,z) = |
| 485 |
special "rule"; numspecial xpart w; numspecial ypart w; |
| 486 |
numspecial xpart z; numspecial ypart z enddef; |
| 487 |
def screenrule(expr w,z) = |
| 488 |
addto currentpicture doublepath w--z withpen rulepen enddef; |
| 489 |
pen rulepen; rulepen = pensquare scaled 2; |
| 490 |
|
| 491 |
def makegrid(text xlist,ylist) = |
| 492 |
xmin_ := min(xlist); xmax_ := max(xlist); |
| 493 |
ymin_ := min(ylist); ymax_ := max(ylist); |
| 494 |
for x=xlist: proofrule((x,ymin_), (x,ymax_)); endfor |
| 495 |
for y=ylist: proofrule((xmin_,y), (xmax_,y)); endfor |
| 496 |
enddef; |
| 497 |
|
| 498 |
vardef titlefont suffix $ = special "titlefont "&str$ enddef; |
| 499 |
vardef labelfont suffix $ = special "labelfont "&str$ enddef; |
| 500 |
vardef grayfont suffix $ = special "grayfont "&str$ enddef; |
| 501 |
vardef slantfont suffix $ = special "slantfont "&str$ enddef; |
| 502 |
def proofoffset primary z = % shifts proof output by z |
| 503 |
special "offset"; numspecial xpart z; numspecial ypart z enddef; |
| 504 |
vardef proofrulethickness expr x = |
| 505 |
special "rulethickness"; numspecial x enddef; |
| 506 |
|
| 507 |
message " macros for character and font administration,"; |
| 508 |
|
| 509 |
def beginchar(expr c,w_sharp,h_sharp,d_sharp) = |
| 510 |
begingroup |
| 511 |
charcode:=if known c: byte c else: 0 fi; |
| 512 |
charwd:=w_sharp; charht:=h_sharp; chardp:=d_sharp; |
| 513 |
w:=hround(charwd*hppp); h:=vround(charht*hppp); d:=vround(chardp*hppp); |
| 514 |
charic:=0; clearxy; clearit; clearpen; scantokens extra_beginchar; |
| 515 |
enddef; |
| 516 |
|
| 517 |
def italcorr expr x_sharp = if x_sharp>0: charic:=x_sharp fi enddef; |
| 518 |
|
| 519 |
def change_width = |
| 520 |
w:=w if w>charwd*hppp:- else:+ fi 1 enddef; |
| 521 |
|
| 522 |
def endchar = |
| 523 |
scantokens extra_endchar; |
| 524 |
if proofing>0: makebox(proofrule); fi |
| 525 |
chardx:=w; % desired width of the character in pixels |
| 526 |
shipit; |
| 527 |
if displaying>0: makebox(screenrule); showit; fi |
| 528 |
endgroup enddef; |
| 529 |
|
| 530 |
string extra_beginchar, extra_endchar; |
| 531 |
extra_beginchar=extra_endchar=""; |
| 532 |
|
| 533 |
def makebox(text r) = |
| 534 |
for y=0,h.o_,-d.o_: r((0,y),(w,y)); endfor % horizontals |
| 535 |
for x=0,w: r((x,-d.o_),(x,h.o_)); endfor % verticals |
| 536 |
if charic<>0: r((w+charic*hppp,h.o_),(w+charic*hppp,.5h.o_)); fi |
| 537 |
enddef; |
| 538 |
|
| 539 |
def maketicks(text r) = |
| 540 |
for y=0,h.o_,-d.o_: r((0,y),(10,y)); r((w-10,y),(w,y)); endfor |
| 541 |
for x=0,w: r((x,10-d.o_),(x,-d.o_)); r((x,h.o_-10),(x,h.o_)); endfor |
| 542 |
if charic<>0: r((w+charic*hppp,h.o_-10),(w+charic*hppp,h.o_)); fi |
| 543 |
enddef; |
| 544 |
|
| 545 |
def font_size expr x = designsize:=x enddef; |
| 546 |
def font_slant expr x = fontdimen 1: x enddef; |
| 547 |
def font_normal_space expr x = fontdimen 2: x enddef; |
| 548 |
def font_normal_stretch expr x = fontdimen 3: x enddef; |
| 549 |
def font_normal_shrink expr x = fontdimen 4: x enddef; |
| 550 |
def font_x_height expr x = fontdimen 5: x enddef; |
| 551 |
def font_quad expr x = fontdimen 6: x enddef; |
| 552 |
def font_extra_space expr x = fontdimen 7: x enddef; |
| 553 |
|
| 554 |
def font_identifier expr x = font_identifier_:=x enddef; |
| 555 |
def font_coding_scheme expr x = font_coding_scheme_:=x enddef; |
| 556 |
string font_identifier_, font_coding_scheme_; |
| 557 |
font_identifier_=font_coding_scheme_="UNSPECIFIED"; |
| 558 |
|
| 559 |
message "and a few last-minute items."; |
| 560 |
|
| 561 |
vardef z@#=(x@#,y@#) enddef; |
| 562 |
|
| 563 |
newinternal screen_rows, screen_cols, currentwindow; |
| 564 |
screen_rows:=400; % these values should be corrected, |
| 565 |
screen_cols:=500; % by reading in a separate file after PLAIN.MF |
| 566 |
|
| 567 |
def openit = openwindow currentwindow |
| 568 |
from origin to (screen_rows,screen_cols) at (-50,300) enddef; |
| 569 |
def showit = openit; let showit=showit_; showit enddef; % first time only |
| 570 |
def showit_ = display currentpicture inwindow currentwindow enddef; |
| 571 |
|
| 572 |
def clearxy = save x,y enddef; |
| 573 |
def clearit = currentpicture:=nullpicture enddef; |
| 574 |
def shipit = shipout currentpicture enddef; |
| 575 |
def cullit = cull currentpicture dropping (-infinity,0) enddef; |
| 576 |
|
| 577 |
def screenchars = % endchar should `showit' |
| 578 |
extra_endchar:=extra_endchar&"showit;" enddef; |
| 579 |
def screenstrokes = % every stroke should `showit' |
| 580 |
def addto_currentpicture text t= |
| 581 |
addto currentpicture t; showit enddef; enddef; |
| 582 |
def imagerules = % a box should be part of the character image |
| 583 |
extra_beginchar:=extra_beginchar & "makebox(screenrule);" enddef; |
| 584 |
def gfcorners = % `maketicks' should send rules to the GF file |
| 585 |
extra_setup:=extra_setup & "let makebox=maketicks;proofing:=1;" enddef; |
| 586 |
def nodisplays = % endchar shouldn't `showit' |
| 587 |
extra_setup:=extra_setup & "displaying:=0;" enddef; |
| 588 |
def notransforms = % currenttransform should not be used |
| 589 |
let t_ = \ enddef; |
| 590 |
|
| 591 |
let bye = end; outer end,bye; |
| 592 |
|
| 593 |
clear_pen_memory; % initialize the `savepen' mechanism |
| 594 |
mode_setup; % establish proof mode as the default |
| 595 |
numeric mode,mag; % but leave mode and mag undefined |