home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume38 / lout / part09 < prev    next >
Encoding:
Text File  |  1993-08-11  |  73.3 KB  |  1,952 lines

  1. Newsgroups: comp.sources.misc
  2. From: jeff@joyce.cs.su.oz.au (Jeff Kingston)
  3. Subject: v38i077:  lout - Lout document formatting system, v2.05, Part09/35
  4. Message-ID: <1993Aug8.180827.11639@sparky.sterling.com>
  5. X-Md4-Signature: 5079abfb16dc52d5c9589db1a1928bcc
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Sun, 8 Aug 1993 18:08:27 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: jeff@joyce.cs.su.oz.au (Jeff Kingston)
  12. Posting-number: Volume 38, Issue 77
  13. Archive-name: lout/part09
  14. Environment: UNIX
  15. Supersedes: lout: Volume 37, Issue 99-128
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  doc/tr.impl/s3.0 include/eq z37.c
  22. # Wrapped by kent@sparky on Sun Aug  8 12:29:23 1993
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 9 (of 35)."'
  26. if test -f 'doc/tr.impl/s3.0' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'doc/tr.impl/s3.0'\"
  28. else
  29.   echo shar: Extracting \"'doc/tr.impl/s3.0'\" \(378 characters\)
  30.   sed "s/^X//" >'doc/tr.impl/s3.0' <<'END_OF_FILE'
  31. X@Section
  32. X    @Title { Definitions }
  33. X@Begin
  34. X@PP
  35. XThe need to provide a means of packaging useful pieces of code for easy
  36. Xrepeated use was recognised in the very earliest programming
  37. Xlanguages.  This need is even more acute in document formatting, if that
  38. Xis possible, because the majority of users are not programmers and do
  39. Xnot understand the code they invoke.
  40. X@BeginSubSections
  41. END_OF_FILE
  42.   if test 378 -ne `wc -c <'doc/tr.impl/s3.0'`; then
  43.     echo shar: \"'doc/tr.impl/s3.0'\" unpacked with wrong size!
  44.   fi
  45.   # end of 'doc/tr.impl/s3.0'
  46. fi
  47. if test -f 'include/eq' -a "${1}" != "-c" ; then 
  48.   echo shar: Will not clobber existing file \"'include/eq'\"
  49. else
  50.   echo shar: Extracting \"'include/eq'\" \(35552 characters\)
  51.   sed "s/^X//" >'include/eq' <<'END_OF_FILE'
  52. X
  53. X###############################################################################
  54. X#                                                                             #
  55. X#  Lout @Eq package for equation formatting (Version 2.0)                     #
  56. X#                                                                             #
  57. X#  Version 1.0 by Jeffrey H. Kingston, December 1990.                         #
  58. X#  Version 2.0 by Jeffrey H. Kingston, 22 December 1992.                      #
  59. X#                                                                             #
  60. X#  This package makes extensive use of the Adobe Systems Symbol font, and     #
  61. X#  it assumes that the font has not been recoded.  It could be rewritten      #
  62. X#  using the @Char symbol to be made independent of any recoding, but since   #
  63. X#  there seems no reason to ever recode this font, I haven't bothered.        #
  64. X#                                                                             #
  65. X#  See "Eq - a Lout package for typesetting mathematics" for user             #
  66. X#  information.  Acknowledgement:  the @Eq language is based closely on       #
  67. X#  the Eqn language of B. W. Kernighan and L. L. Cherry; the spacing rules    #
  68. X#  are similar to those of the TeX system by D. E. Knuth.                     #
  69. X#                                                                             #
  70. X###############################################################################
  71. X
  72. Xexport    "`" "``" "```" bin rel punct non vctr big
  73. X
  74. X    space exclam universal numbersign existential percent
  75. X    ampersand suchthat parenleft parenright asteriskmath
  76. X    plus comma minus period slash zero one two three four
  77. X    five six seven eight nine colon semicolon less equal
  78. X    greater question congruent Alpha Beta Chi Delta Epsilon
  79. X    Phi Gamma Eta Iota thetaone Kappa Lambda Mu Nu Omicron
  80. X    Pi Theta Rho Sigma Tau Upsilon sigmaone Omega Xi Psi Zeta
  81. X    bracketleft therefore bracketright perpendicular underscore
  82. X    radicalex alpha beta chi delta epsilon phi gamma eta iota
  83. X    phione kappa lambda mu nu omicron pi theta rho sigma tau
  84. X    upsilon omegaone omega xi psi zeta braceleft bar braceright
  85. X    similar Upsilonone minute lessequal fraction infinity florin
  86. X    club diamond heart spade arrowboth arrowleft arrowup
  87. X    arrowright arrowdown degree plusminus second greaterequal
  88. X    multiply proportional partialdiff bullet divide notequal
  89. X    equivalence approxequal ellipsis arrowvertex arrowhorizex
  90. X    carriagereturn aleph Ifraktur Rfraktur weierstrass
  91. X    circlemultiply circleplus emptyset intersection union
  92. X    propersuperset reflexsuperset notsubset propersubset
  93. X    reflexsubset element notelement angle gradient registerserif
  94. X    copyrightserif trademarkserif product radical dotmath
  95. X    logicalnot logicaland logicalor arrowdblboth arrowdblleft
  96. X    arrowdblup arrowdblright arrowdbldown lozenge angleleft
  97. X    registersans copyrightsans trademarksans summation parenlefttp
  98. X    parenleftex parenleftbt bracketlefttp bracketleftex
  99. X    bracketleftbt bracelefttp braceleftmid braceleftbt braceex
  100. X    angleright integral integraltp integralex integralbt
  101. X    parenrighttp parenrightex parenrightbt bracketrighttp
  102. X    bracketrightex bracketrightbt bracerighttp bracerightmid
  103. X    bracerightbt
  104. X
  105. X    hbar Re Im partial infty prime nabla surd top bot dbar
  106. X    triangle backslash forall exists neg circle square
  107. X
  108. X    "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"
  109. X
  110. X    sum prod coprod int oint bcap bcup bvee bwedge bodot botimes
  111. X    boplus buplus
  112. X
  113. X    "+" "-" "+-" "-+" setminus cdot times "*" circ div cap cup uplus
  114. X    sqcap sqcup triangleleft triangleright wr bigcirc bigtriangleup
  115. X    bigtriangledown vee wedge oplus ominus otimes oslash odot dagger
  116. X    daggerdbl amalg
  117. X
  118. X    "<" ">" "=" "<=" prec preceq "<<" subset subseteq sqsubseteq
  119. X    in vdash smile frown ">=" succ succeq ">>" supset supseteq
  120. X    sqsupseteq ni dashv mid parallel "==" "~" "-~" asymp "~~"
  121. X    "=~" bowtie propto models doteq perp notsub notin "!=" not
  122. X    "<->" "<--" "-->" up down "<=>" "<==" "==>" dblup dbldown
  123. X    ":" "::" ":="
  124. X
  125. X    lpar blpar rpar brpar lbrack blbrack rbrack brbrack lbrace blbrace
  126. X    rbrace brbrace lfloor blfloor rfloor brfloor lceil blceil
  127. X    rceil brceil langle blangle rangle brangle
  128. X
  129. X    ";" "," col
  130. X    
  131. X    "!" "?" "%" "(" ")" "[" "]"
  132. X
  133. X    arccos arcsin arctan arg cos cosh cot coth csc deg det dim exp
  134. X    gcd hom inf ker lg lim liminf limsup ln log max min Pr sec sin
  135. X    sinh supr tan tanh mod ldots cdots vdots ddots del grad
  136. X    "..." "'" empty
  137. X    
  138. X    sup sub supp on frac half third over from to widefrom wideto
  139. X    dot dotdot hat tilde vec dyad overbar underbar sqrt root above
  140. X    labove cabove rabove mabove nextcol matrix
  141. X
  142. Xdef @Eq                  
  143. X   body @Body
  144. X@Begin
  145. X
  146. X   def @SkewGap  { 0.05f  }
  147. X   def @SupGap   { 0.40fk }
  148. X   def @ThinGap  { 0.15v  }
  149. X   def @MedGap   { 0.20v  }
  150. X   def @ThickGap { 0.25v  }
  151. X   def @ColGap   { 0.8f   }
  152. X   def @RowGap   { 0.5f   }
  153. X   def @FontRed  { 0.7f   }
  154. X   def @FontInc  { 1.3f   }
  155. X
  156. X   def "`"       { &@ThinGap  }
  157. X   def "``"      { &@MedGap   }
  158. X   def "```"     { &@ThickGap }
  159. X
  160. X   def bin    right x { ``  x ``  }
  161. X   def rel    right x { ``` x ``` }
  162. X   def punct    right x {     x `   }
  163. X   def non    right x { 0c @Break x }
  164. X   def big    right x { @FontInc @Font 0c @Space @FontInc @Break x }
  165. X
  166. X   def @Base    right x { Base @Font x }
  167. X   def @Smaller right x { @FontRed @Font 0c @Space     0.2f @Break x }
  168. X   def @Sym     right x { {Symbol Base} @Font x }
  169. X
  170. X   def @HLine
  171. X      named line { "0.05 ft setlinewidth" }
  172. X   {  
  173. X      { "0 0 moveto xsize 0 lineto" line "stroke" } @Graphic {}
  174. X   }
  175. X
  176. X   def @VLine
  177. X   {
  178. X      "0 0 moveto 0 ysize lineto 0.05 ft setlinewidth stroke" @Graphic {}
  179. X   }
  180. X
  181. X   def vctr
  182. X      right x
  183. X   { @OneRow {   -180d @Rotate { /0.5wo 180d @Rotate { / @OneRow @OneCol x  } }
  184. X           ^/      @OneRow { /0.5wo      @OneRow { @OneRow @OneCol x ^/ } }
  185. X         }
  186. X   }
  187. X
  188. X   ###################################################################
  189. X   #                                                                 #
  190. X   #   Full names                                                    #
  191. X   #                                                                 #
  192. X   #   These symbols and their names are taken directly from the     #
  193. X   #   Adobe Systems Inc. Symbol font (see PostScript Language       #
  194. X   #   Reference Manual, pp. 256-257).  The only differences are:    #
  195. X   #                                                                 #
  196. X   #      Adobe:  theta1        Eq:  thetaone                        #
  197. X   #              sigma1             sigmaone                        #
  198. X   #              phi1               phione                          #
  199. X   #              omega1             omegaone                        #
  200. X   #                                                                 #
  201. X   #   These were needed since Lout identifiers do not have digits.  #
  202. X   #                                                                 #
  203. X   ###################################################################
  204. X
  205. X   def space           { @Sym "\040"  }
  206. X   def exclam          { @Sym "\041"  }
  207. X   def universal       { @Sym "\042"  }
  208. X   def numbersign      { @Sym "\043"  }
  209. X   def existential     { @Sym "\044"  }
  210. X   def percent         { @Sym "\045"  }
  211. X   def ampersand       { @Sym "\046"  }
  212. X   def suchthat        { @Sym "\047"  }
  213. X   def parenleft       { @Sym "\050"  }
  214. X   def parenright      { @Sym "\051"  }
  215. X   def asteriskmath    { @Sym "\052"  }
  216. X   def plus            { @Sym "+"     }
  217. X   def comma           { @Sym "\054"  }
  218. X   def minus           { @Sym "-"     }
  219. X   def period          { @Sym "\056"  }
  220. X   def slash           { @Sym "\057"  }
  221. X   def zero            { @Sym "\060"  }
  222. X   def one             { @Sym "\061"  }
  223. X   def two             { @Sym "\062"  }
  224. X   def three           { @Sym "\063"  }
  225. X   def four            { @Sym "\064"  }
  226. X   def five            { @Sym "\065"  }
  227. X   def six             { @Sym "\066"  }
  228. X   def seven           { @Sym "\067"  }
  229. X   def eight           { @Sym "\070"  }
  230. X   def nine            { @Sym "\071"  }
  231. X   def colon           { @Sym "\072"  }
  232. X   def semicolon       { @Sym "\073"  }
  233. X   def less            { @Sym "\074"  }
  234. X   def equal           { @Sym "\075"  }
  235. X   def greater         { @Sym "\076"  }
  236. X   def question        { @Sym "\077"  }
  237. X   def congruent       { @Sym "\100"  }
  238. X   def Alpha           { @Sym "\101"  }
  239. X   def Beta            { @Sym "\102"  }
  240. X   def Chi             { @Sym "\103"  }
  241. X   def Delta           { @Sym "\104"  }
  242. X   def Epsilon         { @Sym "\105"  }
  243. X   def Phi             { @Sym "\106"  }
  244. X   def Gamma           { @Sym "\107"  }
  245. X   def Eta             { @Sym "\110"  }
  246. X   def Iota            { @Sym "\111"  }
  247. X   def thetaone        { @Sym "\112"  }
  248. X   def Kappa           { @Sym "\113"  }
  249. X
  250. X   def Lambda          { @Sym "\114"  }
  251. X   def Mu              { @Sym "\115"  }
  252. X   def Nu              { @Sym "\116"  }
  253. X   def Omicron         { @Sym "\117"  }
  254. X   def Pi              { @Sym "\120"  }
  255. X   def Theta           { @Sym "\121"  }
  256. X   def Rho             { @Sym "\122"  }
  257. X   def Sigma           { @Sym "\123"  }
  258. X   def Tau             { @Sym "\124"  }
  259. X   def Upsilon         { @Sym "\125"  }
  260. X   def sigmaone        { @Sym "\126"  }
  261. X   def Omega           { @Sym "\127"  }
  262. X   def Xi              { @Sym "\130"  }
  263. X   def Psi             { @Sym "\131"  }
  264. X   def Zeta            { @Sym "\132"  }
  265. X   def bracketleft     { @Sym "\133"  }
  266. X   def therefore       { @Sym "\134"  }
  267. X   def bracketright    { @Sym "\135"  }
  268. X   def perpendicular   { @Sym "\136"  }
  269. X   def underscore      { @Sym "\137"  }
  270. X   def radicalex       { @Sym "\140"  }
  271. X   def alpha           { @Sym "\141"  }
  272. X   def beta            { @Sym "\142"  }
  273. X   def chi             { @Sym "\143"  }
  274. X   def delta           { @Sym "\144"  }
  275. X   def epsilon         { @Sym "\145"  }
  276. X   def phi             { @Sym "\146"  }
  277. X   def gamma           { @Sym "\147"  }
  278. X   def eta             { @Sym "\150"  }
  279. X   def iota            { @Sym "\151"  }
  280. X   def phione          { @Sym "\152"  }
  281. X   def kappa           { @Sym "\153"  }
  282. X   def lambda          { @Sym "\154"  }
  283. X   def mu              { @Sym "\155"  }
  284. X   def nu              { @Sym "\156"  }
  285. X
  286. X   def omicron         { @Sym "\157"  }
  287. X   def pi              { @Sym "\160"  }
  288. X   def theta           { @Sym "\161"  }
  289. X   def rho             { @Sym "\162"  }
  290. X   def sigma           { @Sym "\163"  }
  291. X   def tau             { @Sym "\164"  }
  292. X   def upsilon         { @Sym "\165"  }
  293. X   def omegaone        { @Sym "\166"  }
  294. X   def omega           { @Sym "\167"  }
  295. X   def xi              { @Sym "\170"  }
  296. X   def psi             { @Sym "\171"  }
  297. X   def zeta            { @Sym "\172"  }
  298. X   def braceleft       { @Sym "\173"  }
  299. X   def bar             { @Sym "\174"  }
  300. X   def braceright      { @Sym "\175"  }
  301. X   def similar         { @Sym "\176"  }
  302. X   def Upsilonone      { @Sym "\241"  }
  303. X   def minute          { @Sym "\242"  }
  304. X   def lessequal       { @Sym "\243"  }
  305. X   def fraction        { @Sym "\244"  }
  306. X   def infinity        { @Sym "\245"  }
  307. X   def florin          { @Sym "\246"  }
  308. X   def club            { @Sym "\247"  }
  309. X   def diamond         { @Sym "\250"  }
  310. X   def heart           { @Sym "\251"  }
  311. X   def spade           { @Sym "\252"  }
  312. X   def arrowboth       { @Sym "\253"  }
  313. X   def arrowleft       { @Sym "\254"  }
  314. X   def arrowup         { @Sym "\255"  }
  315. X   def arrowright      { @Sym "\256"  }
  316. X   def arrowdown       { @Sym "\257"  }
  317. X   def degree          { @Sym "\260"  }
  318. X   def plusminus       { @Sym "\261"  }
  319. X   def second          { @Sym "\262"  }
  320. X   def greaterequal    { @Sym "\263"  }
  321. X
  322. X   def multiply        { @Sym "\264"  }
  323. X   def proportional    { @Sym "\265"  }
  324. X   def partialdiff     { @Sym "\266"  }
  325. X   def bullet          { @Sym "\267"  }
  326. X   def divide          { @Sym "\270"  }
  327. X   def notequal        { @Sym "\271"  }
  328. X   def equivalence     { @Sym "\272"  }
  329. X   def approxequal     { @Sym "\273"  }
  330. X   def ellipsis        { @Sym "\274"  }
  331. X   def arrowvertex     { @Sym "\275"  }
  332. X   def arrowhorizex    { @Sym "\276"  }
  333. X   def carriagereturn  { @Sym "\277"  }
  334. X   def aleph           { @Sym "\300"  }
  335. X   def Ifraktur        { @Sym "\301"  }
  336. X   def Rfraktur        { @Sym "\302"  }
  337. X   def weierstrass     { @Sym "\303"  }
  338. X   def circlemultiply  { @Sym "\304"  }
  339. X   def circleplus      { @Sym "\305"  }
  340. X   def emptyset        { @Sym "\306"  }
  341. X   def intersection    { @Sym "\307"  }
  342. X   def union           { @Sym "\310"  }
  343. X   def propersuperset  { @Sym "\311"  }
  344. X   def reflexsuperset  { @Sym "\312"  }
  345. X   def notsubset       { @Sym "\313"  }
  346. X   def propersubset    { @Sym "\314"  }
  347. X   def reflexsubset    { @Sym "\315"  }
  348. X   def element         { @Sym "\316"  }
  349. X   def notelement      { @Sym "\317"  }
  350. X   def angle           { @Sym "\320"  }
  351. X   def gradient        { @Sym "\321"  }
  352. X   def registerserif   { @Sym "\322"  }
  353. X   def copyrightserif  { @Sym "\323"  }
  354. X   def trademarkserif  { @Sym "\324"  }
  355. X   def product         { @Sym "\325"  }
  356. X   def radical         { @Sym "\326"  }
  357. X   def dotmath         { @Sym "\327"  }
  358. X
  359. X   def logicalnot      { @Sym "\330"  }
  360. X   def logicaland      { @Sym "\331"  }
  361. X   def logicalor       { @Sym "\332"  }
  362. X   def arrowdblboth    { @Sym "\333"  }
  363. X   def arrowdblleft    { @Sym "\334"  }
  364. X   def arrowdblup      { @Sym "\335"  }
  365. X   def arrowdblright   { @Sym "\336"  }
  366. X   def arrowdbldown    { @Sym "\337"  }
  367. X   def lozenge         { @Sym "\340"  }
  368. X   def angleleft       { @Sym "\341"  }
  369. X   def registersans    { @Sym "\342"  }
  370. X   def copyrightsans   { @Sym "\343"  }
  371. X   def trademarksans   { @Sym "\344"  }
  372. X   def summation       { @Sym "\345"  }
  373. X   def parenlefttp     { @Sym "\346"  }
  374. X   def parenleftex     { @Sym "\347"  }
  375. X   def parenleftbt     { @Sym "\350"  }
  376. X   def bracketlefttp   { @Sym "\351"  }
  377. X   def bracketleftex   { @Sym "\352"  }
  378. X   def bracketleftbt   { @Sym "\353"  }
  379. X   def bracelefttp     { @Sym "\354"  }
  380. X   def braceleftmid    { @Sym "\355"  }
  381. X   def braceleftbt     { @Sym "\356"  }
  382. X   def braceex         { @Sym "\357"  }
  383. X   def angleright      { @Sym "\361"  }
  384. X   def integral        { @Sym "\362"  }
  385. X   def integraltp      { @Sym "\363"  }
  386. X   def integralex      { @Sym "\364"  }
  387. X   def integralbt      { @Sym "\365"  }
  388. X   def parenrighttp    { @Sym "\366"  }
  389. X   def parenrightex    { @Sym "\367"  }
  390. X   def parenrightbt    { @Sym "\370"  }
  391. X   def bracketrighttp  { @Sym "\371"  }
  392. X   def bracketrightex  { @Sym "\372"  }
  393. X   def bracketrightbt  { @Sym "\373"  }
  394. X   def bracerighttp    { @Sym "\374"  }
  395. X   def bracerightmid   { @Sym "\375"  }
  396. X   def bracerightbt    { @Sym "\376"  }
  397. X
  398. X
  399. X   ###################################################################
  400. X   #                                                                 #
  401. X   #   Short names                                                   #
  402. X   #                                                                 #
  403. X   #   These symbols, their names, and their spacing, are based on   #
  404. X   #   the list in Appendix F of Donald E. Knuth's The TeXBook.      #
  405. X   #                                                                 #
  406. X   #   Group 1 (lowercase Greek letters):  see full names above      #
  407. X   #   Group 2 (uppercase Greek letters):  see full names above      #
  408. X   #   Group 3 (calligraphic capitals):    not provided by Eq        #
  409. X   #                                                                 #
  410. X   ###################################################################
  411. X
  412. X   ###################################################################
  413. X   #                                                                 #
  414. X   #   Group 4 (miscellaneous Ord symbols)                           #
  415. X   #                                                                 #
  416. X   #   Not all of Knuth's symbols are available.  The four suits     #
  417. X   #   (heartsuit, etc.), have definitions above.                    #
  418. X   #                                                                 #
  419. X   ###################################################################
  420. X
  421. X   def hbar         { @OneCol { &0.1f @Base "-" ^/0.25fo h }    }
  422. X   def Re           { Rfraktur                    }
  423. X   def Im           { Ifraktur                    }
  424. X   def partial      { partialdiff                }
  425. X   def infty        { infinity                    }
  426. X   def prime        {  minute                        }
  427. X  #def emptyset     { defined above                }
  428. X   def nabla        { gradient                    }
  429. X   def surd         { radical                    }
  430. X   def top          { 180d @Rotate perpendicular        }
  431. X   def bot          { perpendicular                }
  432. X   def dbar         { @Base "||"                             }
  433. X  #def angle        { defined above                }
  434. X   def backslash    { "\\"                    }
  435. X   def forall       { universal                    }
  436. X   def exists       { existential                }
  437. X   def neg          { logicalnot                }
  438. X
  439. X   def circle       { @HContract @VContract
  440. X              { "xsize ysize 2 div moveto"
  441. X            "xsize 2 div ysize 2 div xsize 2 div 0 360 arc"
  442. X            "0.04 ft setlinewidth stroke"
  443. X              }
  444. X              @Graphic { 0.7f @Wide 0.3f @High ^/ 0.3f @High }
  445. X            }
  446. X
  447. X   def square       { @HContract @VContract
  448. X              { "0 0 moveto xsize 0 lineto xsize ysize lineto"
  449. X            "0 ysize lineto closepath"
  450. X            "0.04 ft setlinewidth stroke"
  451. X              }
  452. X              @Graphic { 0.6f @Wide 0.3f @High ^/ 0.3f @High }
  453. X            }
  454. X
  455. X   def triangle     { @HContract @VContract
  456. X              { "0 0 moveto xsize 0 lineto"
  457. X                "xsize 2 div ysize lineto closepath"
  458. X            "0.04 ft setlinewidth stroke"
  459. X              }
  460. X              @Graphic
  461. X              { 0.3f @Wide 0.3f @High ^| ^/
  462. X                0.3f @Wide 0.3f @High
  463. X              }
  464. X            }
  465. X
  466. X   ###################################################################
  467. X   #                                                                 #
  468. X   #   Group 5 (digits)                                              #
  469. X   #                                                                 #
  470. X   ###################################################################
  471. X
  472. X   def "0" { zero            }
  473. X   def "1" { one             }
  474. X   def "2" { two             }
  475. X   def "3" { three           }
  476. X   def "4" { four            }
  477. X   def "5" { five            }
  478. X   def "6" { six             }
  479. X   def "7" { seven           }
  480. X   def "8" { eight           }
  481. X   def "9" { nine            }
  482. X
  483. X
  484. X   ###################################################################
  485. X   #                                                                 #
  486. X   #   Group 6 ("Large" operators)                                   #
  487. X   #                                                                 #
  488. X   #   Knuth's large operators automatically change size depending   #
  489. X   #   on whether the equation is display or inline.  Eq does not    #
  490. X   #   do this; instead, the `big' operator must be used.            #
  491. X   #                                                                 #
  492. X   ###################################################################
  493. X
  494. X   def sum    { summation                    }
  495. X   def prod    { product                    }
  496. X   def coprod    { 180d @Rotate vctr product            }
  497. X   def int    { 1.3f @Font vctr integral            }
  498. X   def oint    { @OneCol { vctr degree |0.015fo int }        }
  499. X   def bcap    { 1.3f @Font intersection            }
  500. X   def bcup    { 1.3f @Font union                }
  501. X   def bvee    { 1.3f @Font logicalor                }
  502. X   def bwedge    { 1.3f @Font logicaland                }
  503. X   def bodot    { & 1.3f @Font @HContract { circle /0io &0.5rt dotmath } }
  504. X   def botimes    { 1.3f @Font circlemultiply            }
  505. X   def boplus    { 1.3f @Font circleplus                }
  506. X   def buplus    { & 1.3f @Font @HContract { &0.5rt 0.7f @Font plus ^/0.2fo union } }
  507. X
  508. X   ###################################################################
  509. X   #                                                                 #
  510. X   #   Group 7 (binary operations)                                   #
  511. X   #                                                                 #
  512. X   #   All of Knuth's symbols are available except \star, \diamond   #
  513. X   #   and \bullet; a few have been given more mnemonic names.       #
  514. X   #                                                                 #
  515. X   ###################################################################
  516. X
  517. X   def "+"        { bin plus                }
  518. X   def "-"        { bin minus                }
  519. X   def "+-"        { bin plusminus                }
  520. X   def "-+"        { bin 180d @Rotate plusminus        }
  521. X   def setminus        { bin backslash                }
  522. X   def cdot        { bin dotmath                }
  523. X   def times        { bin multiply                }
  524. X   def "*"        { bin asteriskmath            }
  525. X  #def diamond        { name used above            }
  526. X   def circ        { bin circle                }
  527. X  #def bullet        { name used above            }
  528. X   def div        { bin divide                }
  529. X   def cap        { bin intersection            }
  530. X   def cup        { bin union                }
  531. X   def uplus        { bin @OneRow @HContract { &0.5rt 0.7f @Font plus ^/0.2fo union}}
  532. X   def sqcap        { bin
  533. X              { @HContract @VContract
  534. X                {    "0 0 moveto 0 ysize lineto xsize ysize lineto"
  535. X                "xsize 0 lineto"
  536. X                "0.04 ft setlinewidth stroke"
  537. X                }
  538. X                @Graphic
  539. X                {    0.3f @Wide 0.3f @High ^| ^/
  540. X                0.3f @Wide 0.3f @High
  541. X                }
  542. X              }
  543. X            }
  544. X   def sqcup        { 180d @Rotate sqcap            }
  545. X   def triangleleft    { bin 90d @Rotate 0.8f @Font triangle    }
  546. X   def triangleright    { bin "-90d" @Rotate 0.8f @Font triangle}
  547. X   def wr        { bin vctr {90d @Rotate similar}    }
  548. X   def bigcirc        { bin 1.2f @Font circle            }
  549. X   def bigtriangleup    { bin 1.2f @Font triangle        }
  550. X   def bigtriangledown    { bin 180d @Rotate 1.2f @Font triangle    }
  551. X   def vee        { bin logicalor                }
  552. X   def wedge        { bin logicaland            }
  553. X   def oplus        { bin circleplus            }
  554. X   def ominus        { bin @OneRow @HContract { circle /0io &0.5rt minus}}
  555. X   def otimes        { bin circlemultiply            }
  556. X   def oslash        {`vctr 60d @Rotate @HContract {circle/0io &0.5rt minus`}}
  557. X   def odot        { bin @OneRow @HContract {circle/0io &0.5rt dotmath}}
  558. X   def dagger        { bin @Base @Char "dagger"        }
  559. X   def daggerdbl    { bin @Base @Char "daggerdbl"        }
  560. X   def amalg        { bin 180d @Rotate vctr product        }
  561. X
  562. X   ###################################################################
  563. X   #                                                                 #
  564. X   #   Group 8 (relations)                                           #
  565. X   #                                                                 #
  566. X   #   All Knuth's operators are available, but many have been       #
  567. X   #   given different, more mnemonic names.  Also included is       #
  568. X   #   a not operator for negating the relations.                    #
  569. X   #                                                                 #
  570. X   ###################################################################
  571. X
  572. X   def "<"        { rel less                }
  573. X   def ">"        { rel greater                }
  574. X   def "="        { rel equal                }
  575. X   def "<="        { rel lessequal                }
  576. X   def prec        { rel { 0.45f @Font "-90d" @Rotate
  577. X                { parenrighttp ^| parenlefttp }
  578. X                  }
  579. X            }
  580. X   def preceq        { rel { @OneRow non prec /0.1f minus }    }
  581. X   def "<<"        { rel {less less}            }
  582. X   def subset        { rel propersubset            }
  583. X   def subseteq        { rel reflexsubset            }
  584. X   def sqsubseteq    { rel @HContract @VContract
  585. X              {    { "xsize 0 moveto"
  586. X                  "0 0 lineto"
  587. X                  "0 ysize lineto"
  588. X                  "xsize ysize lineto"
  589. X                  "0.04 ft setlinewidth stroke"
  590. X                }
  591. X                @Graphic
  592. X                { 0.5f @Wide 0.25f @High ^/
  593. X                  0.25f @High
  594. X                }
  595. X                /0.1f minus
  596. X              }
  597. X            }
  598. X
  599. X   def in        { rel element                }
  600. X   def vdash        { rel vctr{"-90d" @Rotate perpendicular}}
  601. X   def smile        { rel vctr 90d @Rotate parenleft    }
  602. X   def frown        { rel vctr 90d @Rotate parenright    }
  603. X
  604. X   def ">="        { rel greaterequal            }
  605. X   def succ        { rel { 0.45f @Font 90d @Rotate
  606. X                    { parenrighttp ^| parenlefttp }
  607. X                  }
  608. X            }
  609. X   def succeq        { rel { @OneRow non succ /0.1f minus }    }
  610. X   def ">>"        { rel {greater greater}            }
  611. X   def supset        { rel propersuperset            }
  612. X   def supseteq        { rel reflexsuperset            }
  613. X   def sqsupseteq    { rel @HContract @VContract
  614. X              {    { "0 0 moveto xsize 0 lineto"
  615. X                  "xsize ysize lineto"
  616. X                  "0 ysize lineto"
  617. X                  "0.04 ft setlinewidth stroke"
  618. X                }
  619. X                @Graphic
  620. X                { 0.5f @Wide 0.25f @High ^/
  621. X                  0.25f @High
  622. X                }
  623. X                /0.1f minus
  624. X              }
  625. X            }
  626. X   def ni        { rel 180d @Rotate element        }
  627. X   def dashv        { rel vctr {90d @Rotate perpendicular}    }
  628. X   def mid        { rel @Base "|"                }
  629. X   def parallel        { rel @Base "||"            }
  630. X
  631. X   def "=="        { rel equivalence            }
  632. X   def "~"        { rel similar                }
  633. X   def "-~"        { rel @OneRow{similar^/0.07f/0.07f minus}}
  634. X   def asymp        { rel 0.7f @Font @OneRow
  635. X                  { 90d @Rotate parenleft ^/0.008f
  636. X                  /0.008f 90d @Rotate parenright }
  637. X            }
  638. X   def "~~"        { rel approxequal            }
  639. X   def "=~"        { rel congruent                }
  640. X   def bowtie        { rel{non triangleright non triangleleft}}
  641. X   def propto        { rel proportional            }
  642. X   def models        { rel{@Base vctr "|" &0.05fo vctr equal}}
  643. X   def doteq        { rel @OneRow @HContract {&0.5rt dotmath^/0.15f equal}}
  644. X   def perp        { rel perpendicular            }
  645. X
  646. X   def notsub        { rel notsubset                }
  647. X   def notin        { rel notelement            }
  648. X   def "!="        { rel notequal                }
  649. X
  650. X   def "<->"        { rel arrowboth                }
  651. X   def "<--"        { rel arrowleft                }
  652. X   def "-->"        { rel arrowright            }
  653. X   def up        { rel arrowup                }
  654. X   def down        { rel arrowdown                }
  655. X   def "<=>"        { rel arrowdblboth            }
  656. X   def "<=="        { rel arrowdblleft            }
  657. X   def "==>"        { rel arrowdblright            }
  658. X   def dblup        { rel arrowdblup            }
  659. X   def dbldown        { rel arrowdbldown            }
  660. X
  661. X   def ":"        { rel colon                }
  662. X   def "::"        { rel @OneCol {colon ` colon}        }
  663. X   def ":="        { rel { colon{ //0.05fo equal} }    }
  664. X
  665. X   def not right x    { @HContract {@OneCol x /0co &0.5rt slash}}
  666. X
  667. X
  668. X   ###################################################################
  669. X   #                                                                 #
  670. X   #   Groups 11 and 12 - openings and closings.                     #
  671. X   #                                                                 #
  672. X   ###################################################################
  673. X
  674. X   def lpar    { parenleft        }
  675. X   def rpar    { parenright        }
  676. X   def lbrack    { bracketleft        }
  677. X   def rbrack    { bracketright        }
  678. X   def lbrace    { braceleft        }
  679. X   def rbrace    { braceright        }
  680. X   def lfloor    { bracketleftbt        }
  681. X   def rfloor    { bracketrightbt    }
  682. X   def lceil    { bracketlefttp        }
  683. X   def rceil    { bracketrighttp    }
  684. X   def langle    { angleleft        }
  685. X   def rangle    { angleright        }
  686. X
  687. X   def blpar    { @OneRow {parenlefttp    ^/ parenleftex    / parenleftbt   } }
  688. X   def brpar    { @OneRow {parenrighttp   ^/ parenrightex   / parenrightbt  } }
  689. X   def blbrack    { @OneRow {bracketlefttp  ^/ bracketleftex  / bracketleftbt } }
  690. X   def brbrack    { @OneRow {bracketrighttp ^/ bracketrightex / bracketrightbt} }
  691. X   def blbrace    { @OneRow {bracelefttp    ^/ braceleftmid   / braceleftbt   } }
  692. X   def brbrace    { @OneRow {bracerighttp   ^/ bracerightmid  / bracerightbt  } }
  693. X   def blfloor    { @OneRow {bracketleftex  ^/ bracketleftex  / bracketleftbt } }
  694. X   def brfloor    { @OneRow {bracketrightex ^/ bracketrightex / bracketrightbt} }
  695. X   def blceil    { @OneRow {bracketlefttp  ^/ bracketleftex  / bracketleftex } }
  696. X   def brceil    { @OneRow {bracketrighttp ^/ bracketrightex / bracketrightex} }
  697. X   def blangle    { @HContract @VContract
  698. X          { "xsize 0 moveto"
  699. X            "0 ysize 2 div lineto"
  700. X            "xsize ysize lineto"
  701. X            "0.04 ft setlinewidth stroke"
  702. X              }
  703. X              @Graphic { 0.5f @Wide 2f @High ^/ 2f @High }
  704. X        }
  705. X   def brangle    { @HContract @VContract
  706. X          { "0 0 moveto"
  707. X            "xsize ysize 2 div lineto"
  708. X            "0 ysize lineto"
  709. X            "0.04 ft setlinewidth stroke"
  710. X              }
  711. X              @Graphic { 0.5f @Wide 2f @High ^/ 2f @High }
  712. X        }
  713. X
  714. X
  715. X   ###################################################################
  716. X   #                                                                 #
  717. X   #   Group 13 - punctuation.                                       #
  718. X   #                                                                 #
  719. X   ###################################################################
  720. X
  721. X   def ";"     { punct semicolon     }
  722. X   def ","     { punct comma         }
  723. X   def col     { punct colon         }
  724. X
  725. X
  726. X   ###################################################################
  727. X   #                                                                 #
  728. X   #   Additional short symbols (Knuth p. 132)                       #
  729. X   #                                                                 #
  730. X   ###################################################################
  731. X
  732. X   def "!" { exclam          }
  733. X   def "?" { question        }
  734. X   def "%" { percent         }
  735. X   def "(" { parenleft       }
  736. X   def ")" { parenright      }
  737. X   def "[" { bracketleft     }
  738. X   def "]" { bracketright    }
  739. X
  740. X
  741. X   ###################################################################
  742. X   #                                                                 #
  743. X   #   Common mathematical functions (from Knuth p. 162).            #
  744. X   #   mod is included, since @Rel mod is easily typed if needed.    #
  745. X   #                                                                 #
  746. X   ###################################################################
  747. X
  748. X   def arccos    { @Base "arccos"    }
  749. X   def arcsin    { @Base "arcsin"    }
  750. X   def arctan    { @Base "arctan"    }
  751. X   def arg    { @Base "arg"        }
  752. X   def cos    { @Base "cos"        }
  753. X   def cosh    { @Base "cosh"        }
  754. X   def cot    { @Base "cot"        }
  755. X   def coth    { @Base "coth"        }
  756. X   def csc    { @Base "csc"        }
  757. X   def deg    { @Base "deg"        }
  758. X   def det    { @Base "det"        }
  759. X   def dim    { @Base "dim"        }
  760. X   def exp    { @Base "exp"        }
  761. X   def gcd    { @Base "gcd"        }
  762. X   def hom    { @Base "hom"        }
  763. X   def inf    { @Base "inf"        }
  764. X   def ker    { @Base "ker"        }
  765. X   def lg    { @Base "lg"        }
  766. X   def lim    { @Base "lim"        }
  767. X   def liminf    { @OneCol { @Base "lim" ` @Base "inf" }    }
  768. X   def limsup    { @OneCol { @Base "lim" ` @Base "sup" }    }
  769. X   def ln    { @Base "ln"        }
  770. X   def log    { @Base "log"        }
  771. X   def max    { @Base "max"        }
  772. X   def min    { @Base "min"        }
  773. X   def Pr    { @Base "Pr"        }
  774. X   def sec    { @Base "sec"        }
  775. X   def sin    { @Base "sin"        }
  776. X   def sinh    { @Base "sinh"        }
  777. X   def supr    { @Base "sup"        }
  778. X   def tan    { @Base "tan"        }
  779. X   def tanh    { @Base "tanh"        }
  780. X   def mod    { @Base "mod"        }
  781. X
  782. X
  783. X   ###################################################################
  784. X   #                                                                 #
  785. X   #   Other symbols taken from TeX.                                 #
  786. X   #                                                                 #
  787. X   ###################################################################
  788. X
  789. X   def ldots { .       &0.3f .       &0.3f .            }
  790. X   def cdots { dotmath &0.3f dotmath &0.3f dotmath        }
  791. X   def vdots { @OneRow { dotmath ^/0.3f dotmath /0.3f dotmath } }
  792. X   def ddots { @OneCol @OneRow
  793. X           {        dotmath
  794. X             ^/0.3f |0.3f dotmath
  795. X                  /0.3f |     |0.3f dotmath
  796. X           }
  797. X         }
  798. X
  799. X
  800. X   ###################################################################
  801. X   #                                                                 #
  802. X   #   Symbols taken from eqn (Kernighan and Cherry 1975).           #
  803. X   #                                                                 #
  804. X   ###################################################################
  805. X
  806. X   def del    { gradient        }
  807. X   def grad    { gradient        }
  808. X   def "..."    { ellipsis        }
  809. X   def ",...,"    { , ellipsis ``` ,    }
  810. X   def "'"    { minute        }
  811. X   def empty    { emptyset        }
  812. X
  813. X
  814. X
  815. X   ###################################################################
  816. X   #                                                                 #
  817. X   #   Symbols with parameters.                                      #
  818. X   #                                                                 #
  819. X   #   These symbols are essentially those of eqn, with some         #
  820. X   #   changes and additions.                                        #
  821. X   #                                                                 #
  822. X   ###################################################################
  823. X
  824. X   def sup
  825. X      precedence 60
  826. X      associativity left
  827. X      left x
  828. X      named gap { @SupGap }
  829. X      right y
  830. X   {  @HContract @VContract
  831. X      {          | @Smaller y
  832. X    ^/gap  x
  833. X      }
  834. X   }
  835. X
  836. X   def sub
  837. X      precedence 60
  838. X      associativity left
  839. X      left x
  840. X      named gap { @SupGap }
  841. X      right y
  842. X   {  @HContract @VContract
  843. X      {
  844. X          x
  845. X     /gap    |  @Smaller y
  846. X      }
  847. X   }
  848. X
  849. X   def supp
  850. X      precedence 60
  851. X      associativity left
  852. X      left x
  853. X      named gap { @SupGap }
  854. X      right y
  855. X   {  @HContract @VContract
  856. X      { { ^/gap x /gap } |  @Smaller y
  857. X      }
  858. X   }
  859. X
  860. X   def on
  861. X      precedence 61
  862. X      associativity left
  863. X      left x
  864. X      named gap { @SupGap }
  865. X      right y
  866. X   {  x ^/  / y 
  867. X   }
  868. X
  869. X   def frac
  870. X      precedence 54
  871. X      associativity left
  872. X      left x
  873. X      named gap { 0ik }
  874. X      right y
  875. X   {  @HContract @VContract @Smaller
  876. X      { x ^/gap | fraction /gap | | y }
  877. X   }
  878. X
  879. X   def half { 1 frac 2 }
  880. X   def third { 1 frac 3 }
  881. X
  882. X   def over
  883. X      precedence 54
  884. X      associativity left
  885. X      left x
  886. X      named gap { 0.2f }
  887. X      right y
  888. X   {  
  889. X      @HContract @VContract
  890. X      {          |0.5rt @OneCol x
  891. X    ^//gap   @HLine
  892. X     //gap   |0.5rt @OneCol y
  893. X      }
  894. X   }
  895. X
  896. X   def from
  897. X      precedence 58
  898. X      associativity left
  899. X      left x
  900. X      named gap { @ThinGap  }
  901. X      named skew { 0c }
  902. X      right y
  903. X   {  
  904. X      @HContract @VContract
  905. X      {          |0.5rt x
  906. X     //gap   |0.5rt &skew @Smaller y
  907. X      }
  908. X   }
  909. X
  910. X   def to
  911. X      precedence 58
  912. X      associativity left
  913. X      left x
  914. X      named gap { @ThinGap  }
  915. X      named skew { 0c }
  916. X      right y
  917. X   {
  918. X      @HContract @VContract
  919. X      {          |0.5rt &skew @Smaller y
  920. X    ^//gap   |0.5rt x
  921. X      }
  922. X   }
  923. X
  924. X   def widefrom
  925. X      precedence 58
  926. X      associativity left
  927. X      left x
  928. X      named gap { @ThinGap  }
  929. X      right y
  930. X   {
  931. X      @HContract @VContract
  932. X      {  x //gap @HScale y
  933. X      }
  934. X   }
  935. X
  936. X   def wideto
  937. X      precedence 58
  938. X      associativity left
  939. X      left x
  940. X      named gap { @ThinGap  }
  941. X      right y
  942. X   {
  943. X      @HContract @VContract
  944. X      { @HScale y ^//gap x
  945. X      }
  946. X   }
  947. X
  948. X   def dot
  949. X      precedence 62
  950. X      left x
  951. X      named gap { @ThinGap }
  952. X   {  x to gap { gap } skew { @SkewGap } .
  953. X   }
  954. X
  955. X   def dotdot
  956. X      precedence 62
  957. X      left x
  958. X      named gap { @ThinGap }
  959. X   {  x to gap { gap } skew { @SkewGap } ..
  960. X   }
  961. X
  962. X   def hat
  963. X      precedence 62
  964. X      left x
  965. X      named gap { @ThinGap }
  966. X   {  x to gap { gap } skew { @SkewGap } @Base "^"
  967. X   }
  968. X
  969. X   def tilde
  970. X      precedence 62
  971. X      left x
  972. X      named gap { @ThinGap }
  973. X   {  x to gap { gap } skew { @SkewGap } @Base "~"
  974. X   }
  975. X
  976. X   def vec
  977. X      precedence 62
  978. X      left x
  979. X      named gap { @ThinGap }
  980. X   {  x to gap { gap } skew { @SkewGap } arrowright
  981. X   }
  982. X
  983. X   def dyad
  984. X      precedence 62
  985. X      left x
  986. X      named gap { @ThinGap }
  987. X   {  x to gap { gap } skew { @SkewGap } arrowboth
  988. X   }
  989. X
  990. X   def overbar
  991. X      precedence 62
  992. X      left x
  993. X      named gap { @ThinGap }
  994. X   {  x wideto gap { gap } minus
  995. X   }
  996. X
  997. X   def underbar
  998. X      precedence 62
  999. X      left x
  1000. X      named gap { @ThinGap }
  1001. X   {  x widefrom gap { gap } minus
  1002. X   }
  1003. X
  1004. X   def sqrt
  1005. X      precedence 56
  1006. X      named gap { @ThinGap }
  1007. X      right x
  1008. X   {
  1009. X      @HContract @VContract
  1010. X      { @VScale surd | @OneRow
  1011. X    { @HLine line { "0.03 ft setlinewidth 2 setlinecap" }
  1012. X      ^//gap  |gap  x //gap
  1013. X    }
  1014. X      }
  1015. X   }
  1016. X
  1017. X   def root
  1018. X      precedence 56
  1019. X      left x
  1020. X      right y
  1021. X   { "" sup x &0io sqrt y
  1022. X   }
  1023. X
  1024. X   def above
  1025. X      precedence 52
  1026. X      left x
  1027. X      named gap { @RowGap }
  1028. X      right y
  1029. X   {  |0.5rt x //gap |0.5rt y
  1030. X   }
  1031. X
  1032. X   def labove
  1033. X      precedence 52
  1034. X      left x
  1035. X      named gap { @RowGap }
  1036. X      right y
  1037. X   {  x //gap y
  1038. X   }
  1039. X
  1040. X   def cabove
  1041. X      precedence 52
  1042. X      left x
  1043. X      named gap { @RowGap }
  1044. X      right y
  1045. X   {  |0.5rt x //gap |0.5rt y
  1046. X   }
  1047. X
  1048. X   def rabove
  1049. X      precedence 52
  1050. X      left x
  1051. X      named gap { @RowGap }
  1052. X      right y
  1053. X   {  |1rt x //gap |1rt y
  1054. X   }
  1055. X
  1056. X   def mabove
  1057. X      precedence 52
  1058. X      left x
  1059. X      named gap { @RowGap }
  1060. X      right y
  1061. X   {  x /gap y
  1062. X   }
  1063. X
  1064. X   def nextcol
  1065. X      precedence 50
  1066. X      left x
  1067. X      named gap { @ColGap }
  1068. X      right y
  1069. X   { x |gap y
  1070. X   }
  1071. X
  1072. X   def matrix
  1073. X      precedence 100
  1074. X      named gap { @MedGap }
  1075. X      named atleft {}
  1076. X      named atright {}
  1077. X      right x
  1078. X   { vctr @HContract @VContract
  1079. X     {  @VScale atleft
  1080. X    ||@ThinGap  { //gap x //gap } ||@ThinGap
  1081. X    @VScale atright
  1082. X     }
  1083. X   }
  1084. X
  1085. X   Slope @Font 1.2f @Break 0c @Space @Body
  1086. X
  1087. X@End @Eq                  
  1088. END_OF_FILE
  1089.   if test 35552 -ne `wc -c <'include/eq'`; then
  1090.     echo shar: \"'include/eq'\" unpacked with wrong size!
  1091.   fi
  1092.   # end of 'include/eq'
  1093. fi
  1094. if test -f 'z37.c' -a "${1}" != "-c" ; then 
  1095.   echo shar: Will not clobber existing file \"'z37.c'\"
  1096. else
  1097.   echo shar: Extracting \"'z37.c'\" \(34601 characters\)
  1098.   sed "s/^X//" >'z37.c' <<'END_OF_FILE'
  1099. X/*@z37.c:Font Service:Declarations@*******************************************/
  1100. X/*                                                                           */
  1101. X/*  LOUT: A HIGH-LEVEL LANGUAGE FOR DOCUMENT FORMATTING (VERSION 2.05)       */
  1102. X/*  COPYRIGHT (C) 1993 Jeffrey H. Kingston                                   */
  1103. X/*                                                                           */
  1104. X/*  Jeffrey H. Kingston (jeff@cs.su.oz.au)                                   */
  1105. X/*  Basser Department of Computer Science                                    */
  1106. X/*  The University of Sydney 2006                                            */
  1107. X/*  AUSTRALIA                                                                */
  1108. X/*                                                                           */
  1109. X/*  This program is free software; you can redistribute it and/or modify     */
  1110. X/*  it under the terms of the GNU General Public License as published by     */
  1111. X/*  the Free Software Foundation; either version 1, or (at your option)      */
  1112. X/*  any later version.                                                       */
  1113. X/*                                                                           */
  1114. X/*  This program is distributed in the hope that it will be useful,          */
  1115. X/*  but WITHOUT ANY WARRANTY; without even the implied warranty of           */
  1116. X/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
  1117. X/*  GNU General Public License for more details.                             */
  1118. X/*                                                                           */
  1119. X/*  You should have received a copy of the GNU General Public License        */
  1120. X/*  along with this program; if not, write to the Free Software              */
  1121. X/*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
  1122. X/*                                                                           */
  1123. X/*  FILE:         z37.c                                                      */
  1124. X/*  MODULE:       Font Service                                               */
  1125. X/*  EXTERNS:      FontInit(), FontDefine(), FontChange(), FontWordSize(),    */
  1126. X/*                FontSize(), FontHalfXHeight(), FontEncoding(),             */
  1127. X/*                FontEncoding(), FontFamilyAndFace(), FontNeeded()          */
  1128. X/*                                                                           */
  1129. X/*  This module implements fonts, using encoding vectors and Adobe font      */
  1130. X/*  metrics files (.AFM files, version 2).                                   */
  1131. X/*                                                                           */
  1132. X/*****************************************************************************/
  1133. X#include "externs"
  1134. X#define DEFAULT_XHEIGHT 500    /* the default XHeight if font has none      */
  1135. X#define    NO_FONT          0    /* the not-a-font font number                */
  1136. X#define    MAX_CHARS    256    /* maximum number of chars in a font         */
  1137. X#define SZ_DFT           1000    /* default lout size is 50p                  */
  1138. X
  1139. Xstruct metrics {
  1140. X  LENGTH up;
  1141. X  LENGTH down;
  1142. X  LENGTH left;
  1143. X  LENGTH right;
  1144. X};
  1145. X
  1146. Xstatic struct metrics    *size_table[MAX_FONT];    /* metrics of sized fonts    */
  1147. Xstatic FULL_CHAR    *lig_table[MAX_FONT];    /* ligatures                 */
  1148. Xstatic OBJECT        font_table[MAX_FONT];    /* record of sized fonts     */
  1149. Xstatic OBJECT        font_root;        /* root of tree of fonts     */
  1150. Xstatic FONT_NUM        fontcount;        /* number of sized fonts     */
  1151. Xstatic int        font_seqnum;        /* unique number for a font  */
  1152. X
  1153. X
  1154. X/*@::FontInit(), FontDebug()@*************************************************/
  1155. X/*                                                                           */
  1156. X/*  FontInit()                                                               */
  1157. X/*                                                                           */
  1158. X/*  Initialise this module.                                                  */
  1159. X/*                                                                           */
  1160. X/*****************************************************************************/
  1161. X
  1162. XFontInit()
  1163. X{ debug0(DFT, D, "FontInit()");
  1164. X  fontcount    = 0;
  1165. X  font_root    = New(ACAT);
  1166. X  font_seqnum    = 0;
  1167. X  debug0(DFT, D, "FontInit returning.");
  1168. X}
  1169. X
  1170. X
  1171. X/*****************************************************************************/
  1172. X/*                                                                           */
  1173. X/*  FontDebug()                                                                 */
  1174. X/*                                                                           */
  1175. X/*  Print out font tree.                                                     */
  1176. X/*                                                                           */
  1177. X/*****************************************************************************/
  1178. X
  1179. X#if DEBUG_ON
  1180. Xstatic FontDebug()
  1181. X{ OBJECT family, face, filename, link, flink;  int i;
  1182. X  assert( font_root != nil && type(font_root)==ACAT, "FontDebug: font_root!" );
  1183. X  for( link = Down(font_root);  link != font_root;  link = NextDown(link) )
  1184. X  { Child(family, link);
  1185. X    assert( is_word(type(family)), "FontDebug: family!" );
  1186. X    fprintf(stderr, "family %s:\n", string(family));
  1187. X    for( flink = Down(family);  flink != family;  flink = NextDown(flink) )
  1188. X    { Child(face, flink);
  1189. X      assert( is_word(type(face)), "FontDebug: face!" );
  1190. X      fprintf(stderr, "   face %s in file ", string(face));
  1191. X      assert( Down(face) != face, "FontDebug: Down(face)!");
  1192. X      Child(filename, Down(face));
  1193. X      assert( is_word(type(filename)), "FontDebug: filename!" );
  1194. X      fprintf(stderr, "%s\n", string(filename));
  1195. X    }
  1196. X  }
  1197. X  for( i = 1;  i <= fontcount;  i++ )
  1198. X    fprintf(stderr, "  font_table[%d] = %s\n", i, EchoObject(font_table[i]));
  1199. X} /* end FontDebug */
  1200. X#endif
  1201. X
  1202. X
  1203. X/*@::FontDefine()@************************************************************/
  1204. X/*                                                                           */
  1205. X/*  FontDefine(family, face, inside)                                         */
  1206. X/*                                                                           */
  1207. X/*  Insert a font defined by fontdef <family> <face> { <inside> } into the   */
  1208. X/*  font tree; <inside> ::= <fontname> <AFMfilename> <CEVfilename> <recode>  */
  1209. X/*                                                                           */
  1210. X/*****************************************************************************/
  1211. X
  1212. XFontDefine(family, face, inside)
  1213. XOBJECT family, face, inside;
  1214. X{ OBJECT font_name, AFMfilename, CEVfilename, recode;
  1215. X  OBJECT short_name, link, y, val[4]; int i;
  1216. X  debug3(DFT, D, "FontDefine( %s, %s, %s )", string(family),
  1217. X    string(face), EchoObject(inside));
  1218. X
  1219. X  /* extract font_name, AFMfilename, CEVfilename, and recode */
  1220. X  if( type(inside) != ACAT )
  1221. X  { Error(WARN, &fpos(inside), "fontdef is not a sequence of words");
  1222. X    DisposeObject(inside);  return;
  1223. X  }
  1224. X  for( i = 0;  Down(inside) != inside && i != 4;  i++ )
  1225. X  { Child(val[i], Down(inside));
  1226. X    DeleteLink(Up(val[i]));
  1227. X    if( type(val[i]) == GAP_OBJ )  DisposeObject(val[i--]);
  1228. X    else if( !is_word(type(val[i])) )
  1229. X    { Error(WARN, &fpos(val[i]), "fontdef contains a non-word");
  1230. X      DisposeObject(inside);  return;
  1231. X    }
  1232. X  }
  1233. X  if( Down(inside) != inside || i != 4 )
  1234. X  { Error(WARN, &fpos(inside), "fontdef does not contain exactly four words");
  1235. X    DisposeObject(inside);  return;
  1236. X  }
  1237. X  font_name = val[0];    AFMfilename = val[1];
  1238. X  CEVfilename = val[2];  recode = val[3];
  1239. X
  1240. X  /* insert family into font tree if not already present */
  1241. X  for( link = Down(font_root);  link != font_root;  link = NextDown(link) )
  1242. X  { Child(y, link);
  1243. X    if( StringEqual(string(y), string(family)) )
  1244. X    { Dispose(family);  family = y; break; }
  1245. X  }
  1246. X  if( link == font_root )  Link(font_root, family);
  1247. X
  1248. X  /* insert face into family, or error if already present */
  1249. X  for( link = Down(family);  link != family;  link = NextDown(link) )
  1250. X  { Child(y, link);
  1251. X    if( StringEqual(string(y), string(face)) )
  1252. X    { Error(WARN, &fpos(face), "font %s %s already defined at%s",
  1253. X    string(family), string(face), EchoFilePos(&fpos(y)));
  1254. X      debug0(DFT, D, "FontDefine returning: font already defined");
  1255. X      Dispose(face);
  1256. X      return;
  1257. X    }
  1258. X  }
  1259. X  Link(family, face);
  1260. X
  1261. X  /* add AFMfilename as first size of font, and PostScript name as its child */
  1262. X  Link(face, AFMfilename);
  1263. X  short_name = MakeWordTwo(WORD, AsciiToFull("fnt"), StringInt(++font_seqnum),
  1264. X    no_fpos);
  1265. X  Link(AFMfilename, short_name);  Link(AFMfilename, font_name);
  1266. X
  1267. X  /* load encoding vector */
  1268. X  if( StringEqual(string(recode), STR_FONT_RECODE) )
  1269. X  { font_recoded(face) = TRUE;
  1270. X    font_encoding(AFMfilename) = EvLoad(CEVfilename, TRUE);
  1271. X  }
  1272. X  else if( StringEqual(string(recode), STR_FONT_NORECODE) )
  1273. X  { font_recoded(face) = FALSE;
  1274. X    font_encoding(AFMfilename) = EvLoad(CEVfilename, FALSE);
  1275. X  }
  1276. X  else Error(FATAL, &fpos(recode), "expecting either Recode or NoRecode here");
  1277. X  debug0(DFT, D, "FontDefine returning.");
  1278. X} /* end FontDefine */
  1279. X
  1280. X
  1281. X/*@::ReadFont()@**************************************************************/
  1282. X/*                                                                           */
  1283. X/*  static ReadFont(face, err)                                               */
  1284. X/*                                                                           */
  1285. X/*  Read in a font file.  Object err is used only for error reporting.       */
  1286. X/*                                                                           */
  1287. X/*****************************************************************************/
  1288. X
  1289. Xstatic ReadFont(face, err)
  1290. XOBJECT face, err;
  1291. X{ OBJECT filename, fontname;
  1292. X  FULL_CHAR buff[MAX_LINE], command[MAX_LINE], ch;
  1293. X  int wx, llx, lly, urx, ury, xheight2, i, lnum, ligtop;
  1294. X  BOOLEAN xhfound, wxfound, bfound;
  1295. X  FILE_NUM fnum;  FILE *fp;
  1296. X  struct metrics *fnt;
  1297. X  FULL_CHAR *lig, ligchar;
  1298. X  OBJECT x;
  1299. X  char *malloc();
  1300. X  assert( is_word(type(face)), "ReadFont: !is_word(type(face))!" );
  1301. X  debug1(DFT, DD, "ReadFont( %s, err )", string(face));
  1302. X
  1303. X  /* get a new font number for this font */
  1304. X  if( ++fontcount >= MAX_FONT )  Error(FATAL, &fpos(err),
  1305. X    "too many different fonts and sizes (max is %d)", MAX_FONT - 1);
  1306. X
  1307. X  /* open the Adobe font metrics (AFM) file of the font */
  1308. X  assert( Down(face) != face, "ReadFont: filename missing!" );
  1309. X  Child(filename, Down(face));
  1310. X  assert( Down(filename) != filename, "ReadFont: filename child missing!" );
  1311. X  fnum = DefineFile(string(filename), STR_EMPTY, &fpos(filename),
  1312. X    FONT_FILE, FONT_PATH);
  1313. X  fp = OpenFile(fnum, FALSE, FALSE);
  1314. X  if( fp == NULL )
  1315. X    Error(FATAL, &fpos(filename), "cannot open font file %s", FileName(fnum));
  1316. X
  1317. X  /* check that the AFM file begins, as it should, with "StartFontMetrics" */
  1318. X  if( StringFGets(buff, MAX_LINE, fp) == NULL ||
  1319. X    sscanf( (char *) buff, "%s", command) != 1 ||
  1320. X    !StringEqual(command, "StartFontMetrics")  )
  1321. X  { debug1(DFT, D, "first line of AFM file:%s", buff);
  1322. X    debug1(DFT, D, "command:%s", command);
  1323. X    Error(FATAL, &fpos(filename),
  1324. X      "font file %s does not begin with StartFontMetrics", FileName(fnum));
  1325. X  }
  1326. X
  1327. X  /* initialise font metrics and ligature tables for the new font */
  1328. X  fnt = (struct metrics *) malloc(MAX_CHARS * sizeof(struct metrics));
  1329. X  if( fnt == (struct metrics *) NULL )  Error(FATAL, &fpos(err),
  1330. X    "run out of memory reading font file %s", FileName(fnum));
  1331. X  lig = (FULL_CHAR *) malloc(2*MAX_CHARS*sizeof(FULL_CHAR));
  1332. X  if( lig == (FULL_CHAR *) NULL )  Error(FATAL, &fpos(err),
  1333. X    "run out of memory reading font file %s", FileName(fnum));
  1334. X  for( i = 0;  i < MAX_CHARS;  i++ )  lig[i] = 1;    /* i.e. char unknown */
  1335. X  ligtop = MAX_CHARS+2;        /* must avoid ligtop - MAX_CHARS == 0 or 1 */
  1336. X
  1337. X  /* read font metrics file */
  1338. X  xhfound = FALSE;  fontname = nil;  lnum = 1;
  1339. X  while ( ( StringFGets(buff, MAX_LINE, fp) ) != NULL )
  1340. X  {
  1341. X    lnum++;
  1342. X    sscanf( (char *) buff, "%s", command);
  1343. X    switch( command[0] )
  1344. X    {
  1345. X
  1346. X      case 'X':
  1347. X
  1348. X    if( StringEqual(command, AsciiToFull("XHeight")) ) 
  1349. X    { if( xhfound )
  1350. X      { Error(FATAL, &fpos(filename),
  1351. X          "XHeight found twice in font file (line %d)", lnum);
  1352. X      }
  1353. X      sscanf( (char *) buff, "XHeight %d", &xheight2);
  1354. X      xheight2 = xheight2 / 2;
  1355. X      xhfound = TRUE;
  1356. X    }
  1357. X    break;
  1358. X
  1359. X
  1360. X      case 'F':
  1361. X
  1362. X    if( StringEqual(command, AsciiToFull("FontName")) )
  1363. X    { if( fontname != nil )
  1364. X      { Error(FATAL, &fpos(filename),
  1365. X          "FontName found twice in font file %s (line %d)",
  1366. X          FileName(fnum), lnum);
  1367. X      }
  1368. X      sscanf( (char *) buff, "FontName %s", command);
  1369. X      if( StringEqual(command, STR_EMPTY) )
  1370. X      { Error(FATAL, &fpos(filename),
  1371. X          "FontName empty in font file %s (line %d)",
  1372. X          FileName(fnum), lnum);
  1373. X      }
  1374. X      Child(x, LastDown(filename));
  1375. X      if( !StringEqual(command, string(x)) )
  1376. X      Error(FATAL, &fpos(filename),
  1377. X        "FontName in AFM file (%s) and in fontdef (%s) disagree",
  1378. X        command, string(x));
  1379. X      fontname = MakeWord(WORD, command, &fpos(filename));
  1380. X    }
  1381. X    break;
  1382. X
  1383. X
  1384. X      case 'S':
  1385. X
  1386. X    if( !StringEqual(command, AsciiToFull("StartCharMetrics")) )
  1387. X      continue;
  1388. X    if( fontname == nil )  Error(FATAL, &fpos(filename),
  1389. X      "FontName missing in file %s", FileName(fnum));
  1390. X    if( !xhfound )  xheight2 = DEFAULT_XHEIGHT / 2;
  1391. X    while( StringFGets(buff, MAX_LINE, fp) != NULL &&
  1392. X           !StringBeginsWith(buff, AsciiToFull("EndCharMetrics")) )
  1393. X    {
  1394. X      /* read one line containing metric info for one character */
  1395. X      debug1(DFT, DD, "ReadFont reading %s", buff);
  1396. X      lnum++;  ch = '\0';  
  1397. X      wxfound = bfound = FALSE;
  1398. X      i = 0;  while( buff[i] == ' ' )  i++;
  1399. X      while( buff[i] != '\n' )
  1400. X      {
  1401. X          debug2(DFT, DD, "  ch = %d, &buff[i] = %s", ch, &buff[i]);
  1402. X          sscanf( (char *) &buff[i], "%s", command);
  1403. X          if( StringEqual(command, "N") )
  1404. X          { sscanf( (char *) &buff[i], "N %s", command);
  1405. X        ch = EvRetrieve(command, font_encoding(filename));
  1406. X          }
  1407. X          else if( StringEqual(command, "WX") )
  1408. X          {    sscanf( (char *) &buff[i], "WX %d", &wx);
  1409. X        wxfound = TRUE;
  1410. X          }
  1411. X          else if( StringEqual(command, "B") )
  1412. X          { sscanf( (char *) &buff[i], "B %d %d %d %d",
  1413. X          &llx, &lly, &urx, &ury);
  1414. X        bfound = TRUE;
  1415. X          }
  1416. X          else if( StringEqual(command, "L") && ch != '\0' )
  1417. X          { if( lig[ch] == 1 )  lig[ch] = ligtop - MAX_CHARS;
  1418. X        lig[ligtop++] = ch;
  1419. X        i++;  /* skip L */
  1420. X        while( buff[i] == ' ' )  i++;
  1421. X        while( buff[i] != ';' && buff[i] != '\n' )
  1422. X        { sscanf( (char *) &buff[i], "%s", command);
  1423. X          ligchar = EvRetrieve(command, font_encoding(filename));
  1424. X          if( ligchar != '\0' )  lig[ligtop++] = ligchar;
  1425. X          else
  1426. X          { Error(WARN, &fpos(filename),
  1427. X            "ignoring ligature character %s in font file %s (line %d%s",
  1428. X            command, FileName(fnum), lnum, ") as it is not encoded");
  1429. X            lig[ch] = 1;
  1430. X          }
  1431. X          if( ligtop > 2*MAX_CHARS - 5 )  Error(FATAL, &fpos(filename),
  1432. X            "too many ligature characters in font file %s (line %d)",
  1433. X            FileName(fnum), lnum);
  1434. X          while( buff[i] != ' ' && buff[i] != ';' )  i++;
  1435. X          while( buff[i] == ' ' ) i++;
  1436. X        }
  1437. X        lig[ligtop++] = '\0';
  1438. X          }
  1439. X          while( buff[i] != ';' && buff[i] != '\n' )  i++;
  1440. X          if( buff[i] == ';' )
  1441. X          { i++;  while( buff[i] == ' ' ) i++;
  1442. X          }
  1443. X      }
  1444. X      if( ch > '\0' )
  1445. X      { 
  1446. X        if( !wxfound )
  1447. X        { Error(FATAL, &fpos(filename),
  1448. X            "WX missing in font file %s (line %d)", FileName(fnum), lnum);
  1449. X        }
  1450. X        if( !bfound )
  1451. X        { Error(FATAL, &fpos(filename),
  1452. X            "B missing in font file %s (line %d)", FileName(fnum), lnum);
  1453. X        }
  1454. X        if( lig[ch] == 1 )  lig[ch] = 0;    /* set to known if unknown */
  1455. X        else if( lig[ch] > 1 )        /* add '\0' to end of ligs */
  1456. X          lig[ligtop++] = '\0';
  1457. X        fnt[ch].left  = llx;
  1458. X        fnt[ch].down  = lly - xheight2;
  1459. X        fnt[ch].right = wx;
  1460. X        fnt[ch].up    = ury - xheight2;
  1461. X        debug5(DFT, DD, "  fnt[%c] = (%d,%d,%d,%d)", ch, fnt[ch].left,
  1462. X          fnt[ch].down, fnt[ch].right, fnt[ch].up);
  1463. X      }
  1464. X    }
  1465. X
  1466. X    /* make a new font record and insert into font tree */
  1467. X    font_num(fontname) = fontcount;
  1468. X    font_size(fontname) = SZ_DFT;
  1469. X    font_xheight2(fontname) = xheight2;
  1470. X    font_encoding(fontname) = font_encoding(filename);
  1471. X    ch = EvRetrieve(STR_PS_SPACENAME, font_encoding(fontname));
  1472. X    font_spacewidth(fontname) = ch == '\0' ? 0 : fnt[ch].right;
  1473. X    font_table[fontcount] = fontname;
  1474. X    size_table[fontcount] = fnt;
  1475. X    lig_table[fontcount] = lig;
  1476. X    Link(face, fontname);
  1477. X
  1478. X    /* close file, debug and exit */
  1479. X    fclose(fp);
  1480. X    debug4(DFT, D, "ReadFont returning: %d, name %s, fs %d, xh2 %d",
  1481. X        fontcount, string(fontname), font_size(fontname), xheight2);
  1482. X    return;
  1483. X    break;
  1484. X
  1485. X
  1486. X      default:
  1487. X
  1488. X    break;
  1489. X
  1490. X    }
  1491. X  }
  1492. X  Error(FATAL, &fpos(filename),
  1493. X    "StartCharMetrics missing from font file %s", FileName(fnum));
  1494. X} /* end ReadFont */
  1495. X
  1496. X
  1497. X/*@::FontChange()@************************************************************/
  1498. X/*                                                                           */
  1499. X/*  FontChange(style, x)                                                     */
  1500. X/*                                                                           */
  1501. X/*  Returns an internal font number which is the current font changed        */
  1502. X/*  according to word object x.  e.g. if current font is Roman 12p and x is  */
  1503. X/*  "-3p", then FontChange returns the internal font number of Roman 9p.     */
  1504. X/*                                                                           */
  1505. X/*****************************************************************************/
  1506. X
  1507. XFontChange(style, x)
  1508. XSTYLE *style;  OBJECT x;
  1509. X{ /* register */ int i;
  1510. X  OBJECT par[3], family, face, fsize, y, link, new, old, tmpf;
  1511. X  GAP gp;  LENGTH flen;  int num, c;  unsigned inc;
  1512. X  struct metrics *newfnt, *oldfnt;  FULL_CHAR *lig;  char *malloc();
  1513. X  debug2(DFT, D, "FontChange( %s, %s )", EchoStyle(style), EchoObject(x));
  1514. X  assert( font(*style) <= fontcount, "FontChange: fontcount!");
  1515. X  /* ifdebug(DFT, DD, FontDebug()); */
  1516. X
  1517. X  /* set par[0..num-1] to the 1, 2 or 3 parameters of the font operator */
  1518. X  num = 0;
  1519. X  if( is_word(type(x)) )  par[num++] = x; 
  1520. X  else if( type(x) == ACAT )
  1521. X  { for( link = Down(x);  link != x;  link = NextDown(link) )
  1522. X    { Child(y, link);
  1523. X      debug1(DFT, DD, "  pars examining y = %s", EchoObject(y));
  1524. X      if( type(y) == GAP_OBJ )  continue;
  1525. X      if( !is_word(type(y)) || num >= 3 )
  1526. X      {    Error(WARN, &fpos(x), "error in left parameter of %s", KW_FONT);
  1527. X    debug0(DFT, D, "FontChange returning: ACAT children");
  1528. X    return;
  1529. X      }
  1530. X      par[num++] = y;
  1531. X    }
  1532. X  }
  1533. X  else
  1534. X  { Error(WARN, &fpos(x), "error in left parameter of %s", KW_FONT);
  1535. X    debug0(DFT, D, "FontChange returning: wrong type");
  1536. X    return;
  1537. X  }
  1538. X  debug1(DFT, DD, " found pars, num = %d", num);
  1539. X
  1540. X  /* extract fsize parameter, if any */
  1541. X  assert( num >= 1 && num <= 3, "FontChange: num!" );
  1542. X  c = string(par[num-1])[0];
  1543. X  if( c == CH_INCGAP || c == CH_DECGAP || decimaldigit(c) )
  1544. X  { fsize = par[num-1];  num--;
  1545. X  }
  1546. X  else fsize = nil;
  1547. X
  1548. X  /* check for initial font case: must have family, face, and size */
  1549. X  if( font(*style) == NO_FONT && (fsize == nil || num < 2) )
  1550. X    Error(FATAL, &fpos(x), "initial font must have family, face and size");
  1551. X
  1552. X  /* get font family */
  1553. X  if( num == 2 )
  1554. X  {
  1555. X    /* par[0] contains a new family name */
  1556. X    for( link = Down(font_root);  link != font_root;  link = NextDown(link) )
  1557. X    { Child(family, link);
  1558. X      if( StringEqual(string(family), string(par[0])) )  break;
  1559. X    }
  1560. X    if( link == font_root )
  1561. X    { Error(WARN,&fpos(par[0]), "font family %s not defined", string(par[0]));
  1562. X      return;
  1563. X    }
  1564. X  }
  1565. X  else
  1566. X  { /* preserve current family */
  1567. X    assert( Up(font_table[font(*style)]) != font_table[font(*style)],
  1568. X      "FontChange: Up(font_table[font(*style)]) !" );
  1569. X    Parent(face, Up(font_table[font(*style)]));
  1570. X    assert( is_word(type(face)), "FontChange: type(face)!" );
  1571. X    assert( Up(face) != face, "FontChange: Up(face)!" );
  1572. X    Parent(family, Up(face));
  1573. X    assert( is_word(type(family)), "FontChange: type(family)!" );
  1574. X  }
  1575. X
  1576. X  /* get font face */
  1577. X  if( num != 0 )
  1578. X  {
  1579. X    /* par[num-1] contains a new face name */
  1580. X    for( link = Down(family);  link != family;  link = NextDown(link) )
  1581. X    { Child(face, link);
  1582. X      if( StringEqual(string(face), string(par[num-1])) )  break;
  1583. X    }
  1584. X    if( link == family )
  1585. X    {
  1586. X      /* missing face name; first check whether a family name was intended */
  1587. X      for( link = Down(font_root);  link != font_root;  link = NextDown(link) )
  1588. X      {    Child(tmpf, link);
  1589. X    if( StringEqual(string(tmpf), string(par[num-1])) )  break;
  1590. X      }
  1591. X      if( font_root == Down(font_root) )
  1592. X      {    Error(FATAL, &fpos(par[num-1]), "there are no fonts");
  1593. X      }
  1594. X      else if( link != font_root )
  1595. X      {    Error(WARN, &fpos(par[num-1]),
  1596. X        "font family name %s must be accompanied by a face name",
  1597. X        string(par[num-1]));
  1598. X      }
  1599. X      else Error(WARN, &fpos(par[num-1]),
  1600. X        "font face name %s not defined in font family %s",
  1601. X        string(par[num-1]), string(family));
  1602. X      return;
  1603. X    }
  1604. X  }
  1605. X  else
  1606. X  {
  1607. X    /* preserve current face name */
  1608. X    Parent(face, Up(font_table[font(*style)]));
  1609. X    assert( is_word(type(face)), "FontChange: type(face)!" );
  1610. X    assert( Up(face) != face, "FontChange: Up(face)!" );
  1611. X  }
  1612. X
  1613. X  /* get font size */
  1614. X  if( fsize == nil )  flen = font_size(font_table[font(*style)]);
  1615. X  else 
  1616. X  { GetGap(fsize, style, &gp, &inc);
  1617. X    if( inc == GAP_ABS )  flen = width(gp);
  1618. X    else if( font(*style) == NO_FONT )
  1619. X      Error(FATAL, &fpos(fsize), "no font encloses this %s", string(fsize));
  1620. X    else if( inc==GAP_INC )  flen = font_size(font_table[font(*style)])+width(gp);
  1621. X    else if( inc==GAP_DEC )  flen = font_size(font_table[font(*style)])-width(gp);
  1622. X    else Error(INTERN, &fpos(x), "GetGap returned inc = %d!", inc);
  1623. X  }
  1624. X
  1625. X  if( flen <= 0 )
  1626. X  { Error(WARN, &fpos(fsize), "%s %s ignored: result is not positive",
  1627. X      string(fsize), KW_FONT);
  1628. X    return;
  1629. X  }
  1630. X
  1631. X  /* if the font file has not been read before, read it now */
  1632. X  assert( Down(face) != face && type(Down(face)) == LINK, "FontChange: dn!" );
  1633. X  if( Down(face) == LastDown(face) )  ReadFont(face, x);
  1634. X  assert( Down(face) != LastDown(face), "FontChange: after ReadFont!" );
  1635. X
  1636. X  /* search fonts of face for desired size; return if already present */
  1637. X  for( link = NextDown(Down(face));  link != face;  link = NextDown(link) )
  1638. X  { Child(fsize, link);
  1639. X    if( font_size(fsize) == flen )
  1640. X    { font(*style) = font_num(fsize);
  1641. X      SetGap(space_gap(*style), FALSE, TRUE, FIXED_UNIT, EDGE_MODE,
  1642. X            font_spacewidth(fsize));
  1643. X      debug2(DFT, D,"FontChange returning (old) %d (XHeight2 = %d)",
  1644. X            font(*style), font_xheight2(font_table[font(*style)]));
  1645. X      return;
  1646. X    }
  1647. X  }
  1648. X
  1649. X  /* now need to rescale the font; first create a sized font record */
  1650. X  if( ++fontcount >= MAX_FONT )  Error(FATAL, &fpos(x),
  1651. X    "too many different fonts and sizes (max is %d)", MAX_FONT - 1);
  1652. X  assert( Down(face) != face && NextDown(Down(face)) != face, "FontChange!!" );
  1653. X  Child(old, NextDown(Down(face)));
  1654. X  assert( is_word(type(old)), "FontChange: old!" );
  1655. X  new = MakeWord(WORD, string(old), no_fpos);
  1656. X  Link(face, new);
  1657. X  font_size(new)        = flen;
  1658. X  font_xheight2(new)    = font_xheight2(old) * font_size(new) / font_size(old);
  1659. X  font_encoding(new)    = font_encoding(old);
  1660. X  font_spacewidth(new)    = font_spacewidth(old) * font_size(new)/font_size(old);
  1661. X  font_num(new)         = fontcount;
  1662. X  font_table[fontcount] = new;
  1663. X  size_table[fontcount] =
  1664. X    (struct metrics *) malloc(MAX_CHARS * sizeof(struct metrics));
  1665. X  if( size_table[fontcount] == (struct metrics *) NULL )
  1666. X    Error(FATAL, &fpos(x), "run out of memory when changing font or font size");
  1667. X  lig_table[fontcount]  = lig = lig_table[font_num(old)];
  1668. X
  1669. X  /* scale old font to new size */
  1670. X  newfnt = size_table[font_num(new)];
  1671. X  oldfnt = size_table[font_num(old)];
  1672. X  for( i = 0;  i < MAX_CHARS;  i++ )  if( lig[i] != 1 )
  1673. X  { newfnt[i].left  = (oldfnt[i].left  * font_size(new)) / font_size(old);
  1674. X    newfnt[i].right = (oldfnt[i].right * font_size(new)) / font_size(old);
  1675. X    newfnt[i].down  = (oldfnt[i].down  * font_size(new)) / font_size(old);
  1676. X    newfnt[i].up    = (oldfnt[i].up    * font_size(new)) / font_size(old);
  1677. X  }
  1678. X
  1679. X  /* return new font number and exit */
  1680. X  font(*style) = fontcount;
  1681. X  SetGap(space_gap(*style), FALSE, TRUE, FIXED_UNIT, EDGE_MODE,
  1682. X    font_spacewidth(new));
  1683. X  debug2(DFT, D,"FontChange returning (scaled) %d (XHeight2 = %d)",
  1684. X    font(*style), font_xheight2(font_table[font(*style)]));
  1685. X  /* FontDebug(); */
  1686. X} /* end FontChange */
  1687. X
  1688. X
  1689. X/*@::FontWordSize()@**********************************************************/
  1690. X/*                                                                           */
  1691. X/*  FontWordSize(x)                                                          */
  1692. X/*                                                                           */
  1693. X/*  Calculate the horizontal and vertical size of WORD or QWORD x, replacing */
  1694. X/*  ligature sequences by ligature characters wherever they occur.           */
  1695. X/*                                                                           */
  1696. X/*****************************************************************************/
  1697. X
  1698. XFontWordSize(x)
  1699. XOBJECT x;
  1700. X{ FULL_CHAR *p, *q, *a, *b, *lig;  OBJECT tmp;
  1701. X  int r, u, d; struct metrics *fnt;
  1702. X  debug2(DFT, D, "FontWordSize( %s ), font = %d", string(x), word_font(x));
  1703. X  assert( is_word(type(x)), "FontWordSize: !is_word(type(x))!" );
  1704. X
  1705. X  p = q = string(x);
  1706. X  if( *p )
  1707. X  { if ( word_font(x) < 1 || word_font(x) > fontcount )
  1708. X      Error(FATAL, &fpos(x), "no current font at word %s", string(x));
  1709. X    fnt = size_table[word_font(x)];
  1710. X    lig = lig_table[word_font(x)];
  1711. X    d = u = r = 0;
  1712. X    do
  1713. X    { 
  1714. X      /* check for missing glyph (lig[] == 1) or ligatures (lig[] > 1) */
  1715. X      if( lig[*q = *p++] )
  1716. X      {
  1717. X    if( lig[*q] == 1 )
  1718. X    { tmp = MakeWord(QWORD, STR_SPACE, &fpos(x));
  1719. X      string(tmp)[0] = *q;
  1720. X      Error(WARN, &fpos(x),
  1721. X        "character %s left out (it has no glyph in font %s)",
  1722. X         StringQuotedWord(tmp), FontFamilyAndFace(word_font(x)));
  1723. X      Dispose(tmp);
  1724. X      continue;
  1725. X    }
  1726. X    else
  1727. X    { a = &lig[ lig[*(p-1)] + MAX_CHARS ];
  1728. X      while( *a++ == *(p-1) )
  1729. X      { b = p;
  1730. X        while( *a == *b && *(a+1) != '\0' && *b != '\0' )  a++, b++;
  1731. X        if( *(a+1) == '\0' )
  1732. X        { *q = *a;
  1733. X          p = b;
  1734. X          break;
  1735. X        }
  1736. X        else
  1737. X        { while( *++a );
  1738. X          a++;
  1739. X        }
  1740. X      }
  1741. X    }
  1742. X      }
  1743. X
  1744. X      /* accumulate size of *q */
  1745. X      if( fnt[*q].up   > u )  u = fnt[*q].up;
  1746. X      if( fnt[*q].down < d )  d = fnt[*q].down;
  1747. X      r += fnt[*q++].right;
  1748. X    } while( *p );
  1749. X    *q++ = '\0';
  1750. X    back(x, COL) = 0; fwd(x, COL)  = r;
  1751. X    back(x, ROW) = u; fwd(x, ROW)  = -d;
  1752. X  } 
  1753. X  else back(x, COL) = fwd(x, COL) = back(x, ROW) = fwd(x, ROW) = 0;
  1754. X  debug4(DFT, D, "FontWordSize returning %hd %hd %hd %hd",
  1755. X      back(x, COL), fwd(x, COL), back(x, ROW), fwd(x, ROW));
  1756. X} /* end FontWordSize */
  1757. X
  1758. X
  1759. X/*@::FontSize(), FontHalfXHeight(), FontEncoding(), FontName()@***************/
  1760. X/*                                                                           */
  1761. X/*  LENGTH FontSize(fnum, x)                                                 */
  1762. X/*                                                                           */
  1763. X/*  Return the size of this font.  x is for error messages only.             */
  1764. X/*                                                                           */
  1765. X/*****************************************************************************/
  1766. X
  1767. XLENGTH FontSize(fnum, x)
  1768. XFONT_NUM fnum;  OBJECT x;
  1769. X{ debug1(DFT, D, "FontSize( %d )", fnum);
  1770. X  assert( fnum <= fontcount, "FontSize!" );
  1771. X  if( fnum <= 0 )  Error(FATAL, &fpos(x), "no current font at this point");
  1772. X  debug1(DFT, D, "FontSize returning %d", font_size(font_table[fnum]));
  1773. X  return font_size(font_table[fnum]);
  1774. X} /* end FontSize */
  1775. X
  1776. X
  1777. X/*****************************************************************************/
  1778. X/*                                                                           */
  1779. X/*  LENGTH FontHalfXHeight(fnum)                                             */
  1780. X/*                                                                           */
  1781. X/*  Return the xheight2 value of this font.                                  */
  1782. X/*                                                                           */
  1783. X/*****************************************************************************/
  1784. X
  1785. XLENGTH FontHalfXHeight(fnum)
  1786. XFONT_NUM fnum;
  1787. X{ debug1(DFT, D, "FontHalfXHeight( %d )", fnum);
  1788. X  assert( fnum <= fontcount, "FontHalfXHeight!" );
  1789. X  debug1(DFT,D,"FontHalfXHeight returning %d", font_xheight2(font_table[fnum]));
  1790. X  return font_xheight2(font_table[fnum]);
  1791. X} /* end FontSize */
  1792. X
  1793. X
  1794. X/*****************************************************************************/
  1795. X/*                                                                           */
  1796. X/*  ENCODING FontEncoding(fnum)                                              */
  1797. X/*                                                                           */
  1798. X/*  Return the encoding of this font.                                        */
  1799. X/*                                                                           */
  1800. X/*****************************************************************************/
  1801. X
  1802. XENCODING FontEncoding(fnum)
  1803. XFONT_NUM fnum;
  1804. X{ debug1(DFT, D, "FontEncoding( %d )", fnum);
  1805. X  assert( fnum <= fontcount, "FontSize!" );
  1806. X  debug1(DFT, D, "FontEncoding returning %d", font_encoding(font_table[fnum]));
  1807. X  return font_encoding(font_table[fnum]);
  1808. X} /* end FontSize */
  1809. X
  1810. X
  1811. X/*****************************************************************************/
  1812. X/*                                                                           */
  1813. X/*  FULL_CHAR *FontName(fnum)                                                */
  1814. X/*                                                                           */
  1815. X/*  Return the short PostScript name of this font.                           */
  1816. X/*                                                                           */
  1817. X/*****************************************************************************/
  1818. X
  1819. XFULL_CHAR *FontName(fnum)
  1820. XFONT_NUM fnum;
  1821. X{ OBJECT face, AFMfilename, short_name;
  1822. X  debug1(DFT, D, "FontName( %d )", fnum);
  1823. X  assert( fnum <= fontcount, "FontName!" );
  1824. X  Parent(face, Up(font_table[fnum]));
  1825. X  Child(AFMfilename, Down(face));
  1826. X  Child(short_name, Down(AFMfilename));
  1827. X  assert( is_word(type(short_name)), "FontName: short_name!" );
  1828. X  debug1(DFT, D, "FontName returning %s", string(short_name));
  1829. X  return string(short_name);
  1830. X} /* end FontSize */
  1831. X
  1832. X
  1833. X/*@::FontFamilyAndFace(), FontPrintAll()@*************************************/
  1834. X/*                                                                           */
  1835. X/*  FULL_CHAR *FontFamilyAndFace(fnum)                                       */
  1836. X/*                                                                           */
  1837. X/*  Return a static string of the current font family and face.              */
  1838. X/*                                                                           */
  1839. X/*****************************************************************************/
  1840. X
  1841. XFULL_CHAR *FontFamilyAndFace(fnum)
  1842. XFONT_NUM fnum;
  1843. X{ OBJECT face, family; static FULL_CHAR buff[80];
  1844. X  debug1(DFT, D, "FontFamilyAndFace( %d )", fnum);
  1845. X  assert( fnum <= fontcount, "FontName!" );
  1846. X  Parent(face, Up(font_table[fnum]));
  1847. X  Parent(family, Up(face));
  1848. X  if( StringLength(string(family)) + StringLength(string(face)) + 1 > 80 )
  1849. X    Error(FATAL, no_fpos, "family and face names %s %s are too long",
  1850. X      string(family), string(face));
  1851. X  StringCopy(buff, string(family));
  1852. X  StringCat(buff, STR_SPACE);
  1853. X  StringCat(buff, string(face));
  1854. X  debug1(DFT, D, "FontName returning %s", buff);
  1855. X  return buff;
  1856. X} /* end FontFamilyAndFace */
  1857. X
  1858. X
  1859. X/*****************************************************************************/
  1860. X/*                                                                           */
  1861. X/*  FontPrintAll(fp)                                                            */
  1862. X/*                                                                           */
  1863. X/*  Print all font encoding commands on output file fp                       */
  1864. X/*                                                                           */
  1865. X/*****************************************************************************/
  1866. X
  1867. XFontPrintAll(fp)
  1868. XFILE *fp;
  1869. X{ OBJECT family, face, AFMfilename, short_name, ps_name, link, flink;
  1870. X  assert( font_root != nil && type(font_root)==ACAT, "FontDebug: font_root!" );
  1871. X  debug0(DFT, DD, "FontPrintAll(fp)");
  1872. X  for( link = Down(font_root);  link != font_root;  link = NextDown(link) )
  1873. X  { Child(family, link);
  1874. X    assert( is_word(type(family)), "FontPrintAll: family!" );
  1875. X    for( flink = Down(family);  flink != family;  flink = NextDown(flink) )
  1876. X    { Child(face, flink);
  1877. X      assert( is_word(type(face)), "FontPrintAll: face!" );
  1878. X      assert( Down(face) != face, "FontDebug: Down(face)!");
  1879. X      Child(AFMfilename, Down(face));
  1880. X      assert( is_word(type(AFMfilename)), "FontPrintAll: filename!" );
  1881. X      assert( Down(AFMfilename) != AFMfilename, "FontPrintAll: 1!" );
  1882. X      assert( LastDown(AFMfilename) != Down(AFMfilename), "FontPrintAll: 2!" );
  1883. X      Child(short_name, Down(AFMfilename));
  1884. X      assert( is_word(type(short_name)), "FontPrintAll: short_name!" );
  1885. X      Child(ps_name, LastDown(AFMfilename));
  1886. X      assert( is_word(type(ps_name)), "FontPrintAll: ps_name!" );
  1887. X      if( font_recoded(face) )
  1888. X      { fprintf(fp, "/%s%s %s /%s LoutRecode\n",
  1889. X      string(ps_name), string(short_name),
  1890. X      EvName(font_encoding(AFMfilename)), string(ps_name));
  1891. X        fprintf(fp, "/%s { /%s%s LoutFont } def\n", string(short_name),
  1892. X      string(ps_name), string(short_name));
  1893. X      }
  1894. X      else fprintf(fp, "/%s { /%s LoutFont } def\n", string(short_name),
  1895. X      string(ps_name));
  1896. X    }
  1897. X  }
  1898. X  fputs("\n", fp);
  1899. X  debug0(DFT, DD, "FontPrintAll returning.");
  1900. X} /* end FontPrintAll */
  1901. X
  1902. X
  1903. X/*@::FontNeeded()@************************************************************/
  1904. X/*                                                                           */
  1905. X/*  OBJECT FontNeeded(out_fp);                                               */
  1906. X/*                                                                           */
  1907. X/*  Writes font needed resources onto file out_fp.  Returns TRUE if none.    */
  1908. X/*                                                                           */
  1909. X/*****************************************************************************/
  1910. X
  1911. XBOOLEAN FontNeeded(out_fp)
  1912. XFILE *out_fp;
  1913. X{ BOOLEAN first_need = TRUE;
  1914. X  OBJECT link, flink, family, face, x;
  1915. X  for( link = Down(font_root); link != font_root; link = NextDown(link) )
  1916. X  { Child(family, link);
  1917. X    for( flink = Down(family);  flink != family;  flink = NextDown(flink) )
  1918. X    { Child(face, flink);
  1919. X      if( LastDown(face) != Down(face) )
  1920. X      { Child(x, LastDown(face));
  1921. X        fprintf(out_fp, "%s font %s\n",
  1922. X            first_need ? "%%DocumentNeededResources:" : "%%+", string(x));
  1923. X        first_need = FALSE;
  1924. X      }
  1925. X    }
  1926. X  }
  1927. X  return first_need;
  1928. X} /* end FontNeeded */
  1929. END_OF_FILE
  1930.   if test 34601 -ne `wc -c <'z37.c'`; then
  1931.     echo shar: \"'z37.c'\" unpacked with wrong size!
  1932.   fi
  1933.   # end of 'z37.c'
  1934. fi
  1935. echo shar: End of archive 9 \(of 35\).
  1936. cp /dev/null ark9isdone
  1937. MISSING=""
  1938. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ; do
  1939.     if test ! -f ark${I}isdone ; then
  1940.     MISSING="${MISSING} ${I}"
  1941.     fi
  1942. done
  1943. if test "${MISSING}" = "" ; then
  1944.     echo You have unpacked all 35 archives.
  1945.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1946. else
  1947.     echo You still must unpack the following archives:
  1948.     echo "        " ${MISSING}
  1949. fi
  1950. exit 0
  1951. exit 0 # Just in case...
  1952.