| 1 |
%this is xqhints.mf - the original name of that file was hints.mf, it was |
| 2 |
%renamed for the reason of significance. |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
% hints.mf --- an attempt at PostScript Type-1 Hints in METAFONT for use |
| 8 |
% with PS2MF. |
| 9 |
% |
| 10 |
% Copyright (c) 1992 I. Lee Hetherington, all rights reserved. I have |
| 11 |
% not yet decided on what copyright restrictions I will place here. |
| 12 |
% Probably something like TeX's copyright. I think the GNU copyleft |
| 13 |
% is far too extreme. |
| 14 |
% |
| 15 |
% The general scheme for hint implementation is apply vertical (hstem) |
| 16 |
% and horizontal (vstem) hints separately. For each direction, we |
| 17 |
% first collect the stems in a sorted list. At this point we reject |
| 18 |
% overlapping or duplicate stems. When we first need to use the |
| 19 |
% hints, we make sure that piecewise linear transformations are |
| 20 |
% computed. These METAFONT transformations depend on the stem or |
| 21 |
% inter-stem region a particular x- or y-coordinate falls in. These |
| 22 |
% transformations are easily computed once the stems specified in |
| 23 |
% character space are placed in pixel space. This stem placement is |
| 24 |
% more complicated in the vertical direction because of the BlueValues |
| 25 |
% font-level hints. |
| 26 |
% |
| 27 |
% Currently the implemented hints are BlueValues, OtherBlues, |
| 28 |
% BlueScale, BlueShift, BlueFuzz, hstem, hstem3, vstem, vstem3, `Hint |
| 29 |
% Replacement', and `Flex'. The hints FamilyBlues, FamilyOtherBlues |
| 30 |
% are not implemented as we only apply hints at the font and character |
| 31 |
% level, not across an entire font family. The hints StdHW, StdVW, |
| 32 |
% StemSnapH, and StemSnapV are not implemented. It would probably not |
| 33 |
% be very difficult to add these. The ForceBold, LanguageGroup, |
| 34 |
% RndStemUp, and ExpansionFactor are also not implemented. |
| 35 |
% |
| 36 |
% Hint replacement ignores previous stem hints unless the same stem |
| 37 |
% was used previously. In this case, the stem is placed the same as |
| 38 |
% it was before. If after replacement a single stem is respecified |
| 39 |
% without the other original stems, we can place it as it was placed |
| 40 |
% before. However, *both* edges of the stem must be identical. This |
| 41 |
% may now be irrelevant since stems are placed independently now |
| 42 |
% (except in the case of hstem3 and vstem3, of course). |
| 43 |
% |
| 44 |
% I make no claim to that these hints have exactly the same effect as |
| 45 |
% Adobe PostScript font rasterizer. The hints and their interactions |
| 46 |
% can be quite complicated. The hint implementation in this file is |
| 47 |
% based solely on my interpretation of their effects given their |
| 48 |
% description in the book "Adobe Type 1 Font Format, Version 1.1". |
| 49 |
% |
| 50 |
% There is certainly room for improvement: both with respect to hint |
| 51 |
% effects and implementation efficiency. Running METAFONT can take |
| 52 |
% quite a while. I've made some attempt at caching placement results |
| 53 |
% using METAFONT vector to reduce redundant computation. One |
| 54 |
% improvement I can think of is replacing the stem gathering and |
| 55 |
% sorting (h_insert and v_insert) with C code in PS2MF. Another is |
| 56 |
% predetermining which stems are effected by the blue values. Most of |
| 57 |
% the other placement/transformation opertions need to be done in |
| 58 |
% METAFONT because these operations are dependent on device resolution |
| 59 |
% and magnification. |
| 60 |
% |
| 61 |
% I welcome comments, suggestions, fixes, and improvements. I plan on |
| 62 |
% commenting this code more when I get a chance. The comments are |
| 63 |
% pretty sparse at the moment. |
| 64 |
% |
| 65 |
% If you want to disable the hint mechanism, specify `hinting:=0' |
| 66 |
% before this file is included. METAFONT will run much faster but |
| 67 |
% will produce inconsistent stem widths at low resolutions. At higher |
| 68 |
% resolutions these hints are much less important. |
| 69 |
% |
| 70 |
% 1.0 beta 3/30/92 I. Lee Hetherington ([email protected]) |
| 71 |
|
| 72 |
if unknown hinting: hinting := 1; fi |
| 73 |
|
| 74 |
% expansion and slanting (same as `xscaled expansion slanted slanting') |
| 75 |
if unknown expansion: expansion := 1; fi |
| 76 |
if unknown slanting: slanting := 0; fi |
| 77 |
|
| 78 |
% make sure character space units are defined |
| 79 |
if unknown FX#: FX# := 0.001pt#; fi |
| 80 |
if unknown FY#: FY# := 0.001pt#; fi |
| 81 |
FX# := FX# * expansion; % incorporate expansion here so hints know about it |
| 82 |
u# := FX#; |
| 83 |
v# := FY#; |
| 84 |
define_pixels(u,v,FX,FY); |
| 85 |
|
| 86 |
boolean debug; debug := false; |
| 87 |
|
| 88 |
% like round but rounds to the nearest half |
| 89 |
def roundhalf(expr x) = (round(x+0.5)-0.5) enddef; |
| 90 |
|
| 91 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 92 |
% horizontal (vstem) hints |
| 93 |
|
| 94 |
extra_beginchar := extra_beginchar & "h_init;numeric h[][]sc;"; |
| 95 |
|
| 96 |
% initialize structures |
| 97 |
def h_init = |
| 98 |
numeric h.r,h[]s,h[]p,h[]pc; |
| 99 |
boolean h.triple; |
| 100 |
transform h[]t; |
| 101 |
h.r := 1; |
| 102 |
h.triple := false; |
| 103 |
enddef; |
| 104 |
|
| 105 |
% insert new stem into sorted list |
| 106 |
% requires that stems don't overlap |
| 107 |
% toss duplicates |
| 108 |
def h_insert(expr a, b) = |
| 109 |
boolean flag; flag:=false; % temporary flag to exit loop |
| 110 |
if h.r = 1: % no stems thus far |
| 111 |
h[1]s := a; |
| 112 |
h[2]s := b; |
| 113 |
h.r := 3; |
| 114 |
elseif a > h[h.r-1]s: % at end |
| 115 |
h[h.r]s := a; |
| 116 |
h[h.r+1]s := b; |
| 117 |
h.r := h.r + 2; |
| 118 |
else: % we need to search for location and shift elements |
| 119 |
for i = 1 step 2 until h.r-2: |
| 120 |
exitif ((h[i]s >= a) and (h[i]s <= b)) or |
| 121 |
((h[i+1]s >= a) and (h[i+1]s <= b)); |
| 122 |
if a < h[i]s: |
| 123 |
% insert here, so shift remaining elements up by two |
| 124 |
for j = h.r-1 downto i: |
| 125 |
h[j+2]s := h[j]s; |
| 126 |
endfor |
| 127 |
h[i]s := a; |
| 128 |
h[i+1]s := b; |
| 129 |
h.r := h.r + 2; |
| 130 |
flag := true; |
| 131 |
fi |
| 132 |
exitif flag; |
| 133 |
endfor |
| 134 |
fi |
| 135 |
enddef; |
| 136 |
|
| 137 |
% horizontal stem width (for vstem's) |
| 138 |
def hsw(expr a,b) = max(1, round(abs(a-b)*u)) enddef; |
| 139 |
|
| 140 |
% place stems in pixel space |
| 141 |
def h_place = |
| 142 |
if h.triple: |
| 143 |
h2p - h1p = vsw(h1s, h2s) - 1; |
| 144 |
h4p - h3p = vsw(h3s, h4s) - 1; |
| 145 |
h6p - h5p = vsw(h5s, h6s) - 1; |
| 146 |
if unknown h[h1s][h2s]sc: % cached? |
| 147 |
h3p - h2p = h5p - h4p; |
| 148 |
h1p = roundhalf(h1p - (0.5[h1p,h2p] - 0.5[h1s,h2s]*u)); |
| 149 |
h3p = roundhalf(h3p - (0.5[h3p,h4p] - 0.5[h3s,h4s]*u)); |
| 150 |
h[h1s][h2s]sc := h1p; |
| 151 |
h[h3s][h4s]sc := h3p; |
| 152 |
h[h5s][h6s]sc := h5p; |
| 153 |
else: |
| 154 |
h1p = h[h1s][h2s]sc; |
| 155 |
h3p = h[h3s][h4s]sc; |
| 156 |
h5p = h[h5s][h6s]sc; |
| 157 |
fi |
| 158 |
elseif h.r > 1: |
| 159 |
for i = 1 step 2 until h.r-2: |
| 160 |
h[i+1]p - h[i]p = hsw(h[i]s,h[i+1]s) - 1; |
| 161 |
if unknown h[h[i]s][h[i+1]s]sc: % cached? |
| 162 |
h[i]p = roundhalf(h[i]p - (0.5[h[i]p,h[i+1]p] - 0.5[h[i]s,h[i+1]s]*u)); |
| 163 |
h[h[i]s][h[i+1]s]sc := h[i]p; |
| 164 |
else: |
| 165 |
h[i]p = h[h[i]s][h[i+1]s]sc; |
| 166 |
fi |
| 167 |
endfor |
| 168 |
fi |
| 169 |
if debug: |
| 170 |
for i = 1 upto h.r-1: |
| 171 |
message "h" & decimal(i) & ": " & decimal(h[i]s) & |
| 172 |
" (" & decimal(h[i]p) & ")"; |
| 173 |
endfor |
| 174 |
fi |
| 175 |
enddef; |
| 176 |
|
| 177 |
% build separate transformations for each region |
| 178 |
def h_transforms = |
| 179 |
if unknown h1p: h_place; fi |
| 180 |
if h.r = 1: h[0]t := identity xscaled u; |
| 181 |
else: |
| 182 |
% first region (not stem) |
| 183 |
h[0]t := identity shifted (-h[1]s,0) |
| 184 |
xscaled u |
| 185 |
shifted (h[1]p,0); |
| 186 |
% last region (not stem) |
| 187 |
h[h.r-1]t := identity shifted (-h[h.r-1]s,0) |
| 188 |
xscaled u |
| 189 |
shifted (h[h.r-1]p,0); |
| 190 |
% other regions |
| 191 |
for i = 1 upto h.r - 2: |
| 192 |
h[i]t := identity shifted (-h[i]s,0) |
| 193 |
xscaled |
| 194 |
(if h[i+1]p = h[i]p: 0 |
| 195 |
else: ((h[i+1]p - h[i]p) / (h[i+1]s - h[i]s)) fi) |
| 196 |
shifted (h[i]p,0); |
| 197 |
endfor |
| 198 |
fi |
| 199 |
if debug: |
| 200 |
for i = 0 upto h.r-1: |
| 201 |
show xxpart h[i]t; |
| 202 |
endfor |
| 203 |
fi |
| 204 |
enddef; |
| 205 |
|
| 206 |
% find region according to x-coordinate |
| 207 |
def h_region(expr x) = |
| 208 |
if h.r = 1: 0 |
| 209 |
elseif x < h[1]s: 0 |
| 210 |
elseif x >= h[h.r-1]s: (h.r - 1) |
| 211 |
else: |
| 212 |
for i = 2 upto h.r-1: |
| 213 |
if x < h[i]s: (i - 1) fi |
| 214 |
exitif (x < h[i]s); |
| 215 |
endfor |
| 216 |
fi |
| 217 |
enddef; |
| 218 |
|
| 219 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 220 |
% vertical (hstem) hints with support for BlueValues, OtherBlueValues, |
| 221 |
% BlueScale, BlueShift, and BlueFuzz |
| 222 |
|
| 223 |
extra_beginchar := extra_beginchar & "v_init;numeric v[][]sc;"; |
| 224 |
|
| 225 |
% initialize structures |
| 226 |
def v_init = |
| 227 |
numeric v.r,v[]s,v[]p,v[]pc; |
| 228 |
boolean v.triple; |
| 229 |
transform v[]t; |
| 230 |
v.r := 1; |
| 231 |
v.triple := false; |
| 232 |
enddef; |
| 233 |
|
| 234 |
% insert new stem into sorted list |
| 235 |
% requires that stems don't overlap |
| 236 |
def v_insert(expr a, b) = |
| 237 |
boolean flag; flag:=false; % temporary flag to exit loop |
| 238 |
if v.r = 1: % no stems thus far |
| 239 |
v[1]s := a; |
| 240 |
v[2]s := b; |
| 241 |
v.r := 3; |
| 242 |
elseif a > v[v.r-1]s: % at end |
| 243 |
v[v.r]s := a; |
| 244 |
v[v.r+1]s := b; |
| 245 |
v.r := v.r + 2; |
| 246 |
else: % we need to search for location and shift elements |
| 247 |
for i = 1 step 2 until v.r-2: |
| 248 |
exitif ((v[i]s >= a) and (v[i]s <= b)) or |
| 249 |
((v[i+1]s >= a) and (v[i+1]s <= b)); |
| 250 |
if a < v[i]s: |
| 251 |
% insert here, so shift remaining elements up by two |
| 252 |
for j = v.r-1 downto i: |
| 253 |
v[j+2]s := v[j]s; |
| 254 |
endfor |
| 255 |
v[i]s := a; |
| 256 |
v[i+1]s := b; |
| 257 |
v.r := v.r + 2; |
| 258 |
flag := true; |
| 259 |
fi |
| 260 |
exitif flag; |
| 261 |
endfor |
| 262 |
fi |
| 263 |
enddef; |
| 264 |
|
| 265 |
% Blue stuff |
| 266 |
boolean suppress; % suppress overshoot |
| 267 |
suppress := v < blue_scale; |
| 268 |
|
| 269 |
def find_bot_blue(expr y) = |
| 270 |
numeric blue.pos, blue.over; |
| 271 |
for i = 1 upto bot_blues.n: |
| 272 |
exitif known blue.pos; |
| 273 |
if (y >= bot_blues[i]o - blue_fuzz) and (y <= bot_blues[i]p): |
| 274 |
blue.pos := bot_blues[i]p; |
| 275 |
blue.over := bot_blues[i]o; |
| 276 |
fi |
| 277 |
endfor |
| 278 |
enddef; |
| 279 |
|
| 280 |
def find_top_blue(expr y) = |
| 281 |
numeric blue.pos, blue.over; |
| 282 |
for i = 1 upto top_blues.n: |
| 283 |
exitif known blue.pos; |
| 284 |
if (y >= top_blues[i]p) and (y <= top_blues[i]o + blue_fuzz): |
| 285 |
blue.pos := top_blues[i]p; |
| 286 |
blue.over := top_blues[i]o; |
| 287 |
fi |
| 288 |
endfor |
| 289 |
enddef; |
| 290 |
|
| 291 |
% vertical stem width (for hstem's) |
| 292 |
def vsw(expr a,b) = max(1, round(abs(a-b)*v)) enddef; |
| 293 |
|
| 294 |
% place stems in pixel space paying attention to blue stuff |
| 295 |
% (currently ignore v.triple) |
| 296 |
% CHECK CACHING IN HERE. MIGHT NOT NEED TO DO BLUE STUFF SO OFTEN |
| 297 |
def v_place = |
| 298 |
if v.triple: % ignore blue stuff for hstem3 |
| 299 |
v2p - v1p = vsw(v1s, v2s) - 1; |
| 300 |
v4p - v3p = vsw(v3s, v4s) - 1; |
| 301 |
v6p - v5p = vsw(v5s, v6s) - 1; |
| 302 |
if unknown v[v1s][v2s]sc: % cached? |
| 303 |
v3p - v2p = v5p - v4p; |
| 304 |
v1p = roundhalf(v1p - (0.5[v1p,v2p] - 0.5[v1s,v2s]*v)); |
| 305 |
v3p = roundhalf(v3p - (0.5[v3p,v4p] - 0.5[v3s,v4s]*v)); |
| 306 |
v[v1s][v2s]sc := v1p; |
| 307 |
v[v3s][v4s]sc := v3p; |
| 308 |
v[v5s][v6s]sc := v5p; |
| 309 |
else: |
| 310 |
v1p = v[v1s][v2s]sc; |
| 311 |
v3p = v[v3s][v4s]sc; |
| 312 |
v5p = v[v5s][v6s]sc; |
| 313 |
fi |
| 314 |
elseif v.r > 1: |
| 315 |
for i = 1 step 2 until v.r-2: |
| 316 |
find_bot_blue(v[i]s); |
| 317 |
if known blue.pos: |
| 318 |
% position according to blue values |
| 319 |
if suppress: |
| 320 |
v[i]p = roundhalf(blue.pos * v); |
| 321 |
else: |
| 322 |
v[i]p = roundhalf(blue.pos * v) - |
| 323 |
max(if v[i]s <= blue.pos-blue_shift: 1 else: 0 fi, |
| 324 |
round((blue.pos - if v[i]s < blue.over: blue.over |
| 325 |
else: v[i]s fi)*v)); |
| 326 |
fi |
| 327 |
v[i+1]p = v[i]p + vsw(v[i]s,v[i+1]s) - 1; |
| 328 |
fi |
| 329 |
find_top_blue(v[i+1]s); |
| 330 |
if known blue.pos: |
| 331 |
% position according to blue values |
| 332 |
if suppress: |
| 333 |
v[i+1]p := roundhalf(blue.pos * v); |
| 334 |
else: |
| 335 |
v[i+1]p := roundhalf(blue.pos * v) + |
| 336 |
max(if v[i+1]s >= blue.pos+blue_shift: 1 else: 0 fi, |
| 337 |
round((if v[i+1]s > blue.over: blue.over |
| 338 |
else: v[i+1]s fi - blue.pos)*v)); |
| 339 |
fi |
| 340 |
% Note that it is possible for the top of a stem to be fall in a |
| 341 |
% top zone and the bottom to fall in a bottom zone. Therefore, only |
| 342 |
% set v[i]p (bottom) if it wasn't set previously. |
| 343 |
if unknown v[i]p: v[i]p := v[i+1]p - (vsw(v[i]s,v[i+1]s) - 1); fi |
| 344 |
fi |
| 345 |
endfor |
| 346 |
% place remaining stems if not under blue control |
| 347 |
for i = 1 step 2 until v.r-2: |
| 348 |
if unknown v[i]p: |
| 349 |
v[i+1]p = v[i]p + vsw(v[i]s,v[i+1]s) - 1; |
| 350 |
if unknown v[v[i]s][v[i+1]s]sc: % cached? |
| 351 |
v[i]p = roundhalf(v[i]p - (0.5[v[i]p,v[i+1]p] - 0.5[v[i]s,v[i+1]s]*v)); |
| 352 |
v[v[i]s][v[i+1]s]sc := v[i]p; |
| 353 |
else: |
| 354 |
v[i]p = v[v[i]s][v[i+1]s]sc; |
| 355 |
fi |
| 356 |
fi |
| 357 |
endfor |
| 358 |
fi |
| 359 |
if debug: |
| 360 |
for i = 1 upto v.r-1: |
| 361 |
message "v" & decimal(i) & ": " & decimal(v[i]s) & |
| 362 |
" (" & decimal(v[i]p) & ")"; |
| 363 |
endfor |
| 364 |
fi |
| 365 |
enddef; |
| 366 |
|
| 367 |
% build separate transformations for each region |
| 368 |
def v_transforms = |
| 369 |
if unknown v1p: v_place; fi |
| 370 |
if v.r = 1: v[0]t := identity yscaled v; |
| 371 |
else: |
| 372 |
% first region (not stem) |
| 373 |
v[0]t := identity shifted (0,-v[1]s) |
| 374 |
yscaled v |
| 375 |
shifted (0,v[1]p); |
| 376 |
% last region (not stem) |
| 377 |
v[v.r-1]t := identity shifted (0,-v[v.r-1]s) |
| 378 |
yscaled v |
| 379 |
shifted (0,v[v.r-1]p); |
| 380 |
% other regions |
| 381 |
for i = 1 upto v.r - 2: |
| 382 |
v[i]t := identity shifted (0,-v[i]s) |
| 383 |
yscaled |
| 384 |
(if v[i+1]p = v[i]p: 0 |
| 385 |
else: ((v[i+1]p - v[i]p) / (v[i+1]s - v[i]s)) fi) |
| 386 |
shifted (0,v[i]p); |
| 387 |
endfor |
| 388 |
fi |
| 389 |
if debug: |
| 390 |
for i = 0 upto v.r-1: |
| 391 |
show yypart v[i]t; |
| 392 |
endfor |
| 393 |
fi |
| 394 |
enddef; |
| 395 |
|
| 396 |
% find region according to y-coordinate |
| 397 |
def v_region(expr y) = |
| 398 |
if v.r = 1: 0 |
| 399 |
elseif y < v[1]s: 0 |
| 400 |
elseif y >= v[v.r-1]s: (v.r - 1) |
| 401 |
else: |
| 402 |
for i = 2 upto v.r-1: |
| 403 |
if y < v[i]s: |
| 404 |
(i - 1) |
| 405 |
fi |
| 406 |
exitif (y < v[i]s); |
| 407 |
endfor |
| 408 |
fi |
| 409 |
enddef; |
| 410 |
|
| 411 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 412 |
% actual pair (point) and path transformations |
| 413 |
|
| 414 |
% transform a pair (point) to pixel space, caching x and y coordinates |
| 415 |
% separately for future use |
| 416 |
def hv_pixel(expr p) = |
| 417 |
if unknown h[xpart p]pc: |
| 418 |
hide(h[xpart p]pc := xpart(p transformed h[h_region(xpart p)]t)) |
| 419 |
fi |
| 420 |
if unknown v[ypart p]pc: |
| 421 |
hide(v[ypart p]pc := ypart(p transformed v[v_region(ypart p)]t)) |
| 422 |
fi |
| 423 |
(h[xpart p]pc, v[ypart p]pc) |
| 424 |
enddef; |
| 425 |
|
| 426 |
% do the region-dependent tranformation on a point or path |
| 427 |
def hv_transform(expr p) = |
| 428 |
if unknown v0t: hide(v_transforms) fi |
| 429 |
if unknown h0t: hide(h_transforms) fi |
| 430 |
if pair p: hv_pixel(p) |
| 431 |
else: % path |
| 432 |
for i = 0 upto length p - 1: |
| 433 |
hv_pixel(point i of p) .. controls |
| 434 |
hv_pixel(postcontrol i of p) and hv_pixel(precontrol i+1 of p) .. |
| 435 |
endfor |
| 436 |
hv_pixel(point (length p) of p) |
| 437 |
fi |
| 438 |
enddef; |
| 439 |
|
| 440 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 441 |
% proofing stuff -- display stem hints on proof sheets |
| 442 |
|
| 443 |
% Mark a vstem specified in character space. Note that the hints aren't known |
| 444 |
% at this time so they can't be applied to the stem. |
| 445 |
def mark_vstem(expr a,b) = |
| 446 |
one := h + 20; |
| 447 |
two := -d - 20; |
| 448 |
aa := round(a*u); |
| 449 |
bb := round(b*u); |
| 450 |
proofrule((aa,two),(aa,one)); proofrule((bb,two),(bb,one)); |
| 451 |
if proofing>3: |
| 452 |
screenrule((aa,two),(aa,one)); screenrule((bb,two),(bb,one)); fi |
| 453 |
enddef; |
| 454 |
|
| 455 |
% Mark a hstem specified in character space. Note that the hints aren't known |
| 456 |
% at this time so they can't be applied to the stem. |
| 457 |
def mark_hstem(expr a,b) = |
| 458 |
one := -20; |
| 459 |
two := w + 20; |
| 460 |
aa := round(a*v); |
| 461 |
bb := round(b*v); |
| 462 |
proofrule((one,aa),(two,aa)); proofrule((one,bb),(two,bb)); |
| 463 |
if proofing>3: |
| 464 |
screenrule((one,aa),(two,aa)); screenrule((one,bb),(two,bb)); fi |
| 465 |
enddef; |
| 466 |
|
| 467 |
% Mark blue value ranges. |
| 468 |
def mark_blues = |
| 469 |
for i = 1 upto top_blues.n: |
| 470 |
one := -30; |
| 471 |
two := w + 30; |
| 472 |
aa := round(top_blues[i]o*v); |
| 473 |
bb := round(top_blues[i]p*v); |
| 474 |
proofrule((one,aa),(two,aa)); proofrule((one-10,bb),(two+10,bb)); |
| 475 |
if proofing>3: |
| 476 |
screenrule((one,aa),(two,aa)); screenrule((one,bb),(two,bb)); fi |
| 477 |
endfor |
| 478 |
for i = 1 upto bot_blues.n: |
| 479 |
one := -30; |
| 480 |
two := w + 30; |
| 481 |
aa := round(bot_blues[i]o*v); |
| 482 |
bb := round(bot_blues[i]p*v); |
| 483 |
proofrule((one,aa),(two,aa)); proofrule((one-10,bb),(two+10,bb)); |
| 484 |
if proofing>3: |
| 485 |
screenrule((one,aa),(two,aa)); screenrule((one,bb),(two,bb)); fi |
| 486 |
endfor |
| 487 |
enddef; |
| 488 |
extra_beginchar := extra_beginchar & "mark_blues;"; |
| 489 |
|
| 490 |
|
| 491 |
numeric subpath_label; subpath_label := ASCII "a"; |
| 492 |
extra_beginchar := extra_beginchar & |
| 493 |
"subpath_label:=ASCII " & ditto & "a" & ditto & ";"; |
| 494 |
|
| 495 |
% Mark path points. If p is a pair (point) then it is a control point. |
| 496 |
% Control points are only plotted if proofing > 2, but they are left |
| 497 |
% unlabelled. |
| 498 |
def mark_points(expr p) = |
| 499 |
if path p: |
| 500 |
for i = 0 upto length p: |
| 501 |
makelabel(char(subpath_label) & decimal(i), point i of p); |
| 502 |
endfor |
| 503 |
if proofing > 2: % plot control points too |
| 504 |
for i = 1 upto length p - 1: |
| 505 |
makelabel("", postcontrol i of p); |
| 506 |
makelabel("", precontrol i of p); |
| 507 |
endfor |
| 508 |
makelabel("", postcontrol 0 of p); |
| 509 |
makelabel("", precontrol (length p - 1) of p); |
| 510 |
fi |
| 511 |
subpath_label:=subpath_label+1; |
| 512 |
elseif (pair p) and (proofing>2): makelabel("", p) |
| 513 |
fi |
| 514 |
enddef; |
| 515 |
|
| 516 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 517 |
% macros used in character descriptions |
| 518 |
|
| 519 |
% store hint commands in this string for future incorporation |
| 520 |
string delayed_hints; delayed_hints:=""; |
| 521 |
|
| 522 |
% specify delayed hints |
| 523 |
def dh(expr s) = |
| 524 |
if hinting>0: hide(delayed_hints := delayed_hints & s & ";") fi |
| 525 |
enddef; |
| 526 |
|
| 527 |
% incorporate delayed hints |
| 528 |
def ih = |
| 529 |
if hinting>0: hide(h_init; v_init; scantokens delayed_hints; |
| 530 |
delayed_hints:="") fi |
| 531 |
enddef; |
| 532 |
|
| 533 |
% vertical stem hint |
| 534 |
def vs(expr a,b) = |
| 535 |
if hinting>0: hide(h_insert(a,b); if proofing>0: mark_vstem(a,b); fi) fi |
| 536 |
enddef; |
| 537 |
|
| 538 |
% vstem3 indicator |
| 539 |
def vst = if hinting>0: hide(h.triple:=true) fi enddef; |
| 540 |
|
| 541 |
% horizontal stem hint |
| 542 |
def hs(expr a,b) = |
| 543 |
if hinting>0: hide(v_insert(a,b); if proofing>0: mark_hstem(a,b); fi) fi |
| 544 |
enddef; |
| 545 |
|
| 546 |
% hstem3 indicator |
| 547 |
def hst = if hinting>0: hide(v.triple:=true) fi enddef; |
| 548 |
|
| 549 |
% apply hints |
| 550 |
def ah(expr p) = |
| 551 |
hide(if proofing>0: |
| 552 |
if hinting>0: mark_points(hv_transform(p)); |
| 553 |
else: mark_points(p xscaled u yscaled v); fi |
| 554 |
fi) |
| 555 |
if hinting>0: hv_transform(p) |
| 556 |
else: (p xscaled u yscaled v) fi |
| 557 |
enddef; |
| 558 |
|
| 559 |
% line to |
| 560 |
def lt(expr a,b) = |
| 561 |
-- (a,b) |
| 562 |
enddef; |
| 563 |
|
| 564 |
% line to (after hint replacement) |
| 565 |
def lth(expr a,b) = |
| 566 |
-- ih ah((a,b) |
| 567 |
enddef; |
| 568 |
|
| 569 |
% curve to |
| 570 |
def ct(expr a,b,c,d,e,f) = |
| 571 |
.. controls (a,b) and (c,d) .. (e,f) |
| 572 |
enddef; |
| 573 |
|
| 574 |
% curve to (after hint replacement) |
| 575 |
def cth(expr a,b,c,d,e,f) = |
| 576 |
.. controls ah((a,b)) and ih ah((c,d)) .. ah((e,f) |
| 577 |
enddef; |
| 578 |
|
| 579 |
% flex |
| 580 |
def fl(expr rx,ry,ax,ay,bx,by,cx,cy,dx,dy,ex,ey,fx,fy,height) = |
| 581 |
if (abs((rx,ry) - (cx,cy))*u >= 0.01*height): % use curves |
| 582 |
ct(ax,ay,bx,by,cx,cy) |
| 583 |
ct(dx,dy,ex,ey,fx,fy) |
| 584 |
else: |
| 585 |
lt(fx,fy) % replace curves with line |
| 586 |
fi |
| 587 |
enddef; |
| 588 |
|
| 589 |
% flex (after hint replacement) |
| 590 |
def flh(expr rx,ry,ax,ay,bx,by,cx,cy,dx,dy,ex,ey,fx,fy,height) = |
| 591 |
if (abs((rx,ry) - (cx,cy))*u >= 0.01*height): % use curves |
| 592 |
cth(ax,ay,bx,by,cx,cy) |
| 593 |
ct(dx,dy,ex,ey,fx,fy) |
| 594 |
else: |
| 595 |
lth(fx,fy) % replace curves with line |
| 596 |
fi |
| 597 |
enddef; |
| 598 |
|
| 599 |
% close path |
| 600 |
def cp = -- cycle enddef; |
| 601 |
|
| 602 |
% Draw by filling and stroking the path (helps greatly with small sizes). |
| 603 |
% We specify slanting here but not expansion because that's already been |
| 604 |
% incorporated. |
| 605 |
def dr expr c = |
| 606 |
addto currentpicture contour (c slanted slanting) withpen pencircle; |
| 607 |
enddef; |
| 608 |
|
| 609 |
picture chp[]; |
| 610 |
|
| 611 |
% seac (standard encoding accented character) use previously created |
| 612 |
% pictures. When specifying accent shift, use slanting to correctly |
| 613 |
% position accent. |
| 614 |
def seac(expr achar,bchar,adx,ady) = |
| 615 |
currentpicture := chp[bchar] + |
| 616 |
chp[achar] shifted ((adx*u, ady*v) slanted slanting); |
| 617 |
enddef; |
| 618 |
|
| 619 |
% non-zero winding rule for filling instead of default positive rule |
| 620 |
def nonzerowinding = cull currentpicture dropping (0,0); enddef; |
| 621 |
extra_endchar := extra_endchar & "nonzerowinding;"; |
| 622 |
|
| 623 |
turningcheck := 0; % no checking because directions are known |
| 624 |
|
| 625 |
autorounding := smoothing := 0; % we're doing hints ourselves |