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