1 #ifndef lint 2 static char sccsid[] = "@(#)shift.c 2.2 (CWI) 87/04/01"; 3 #endif lint 4 #include "e.h" 5 #include "y.tab.h" 6 7 subsup(p1, p2, p3) 8 int p1, p2, p3; 9 { 10 if (p2 != 0 && p3 != 0) 11 shift2(p1, p2, p3); 12 else if (p2 != 0) 13 bshiftb(p1, SUB, p2); 14 else if (p3 != 0) 15 bshiftb(p1, SUP, p3); 16 } 17 18 extern float Subbase, Supshift; 19 extern char *Sub1space, *Sup1space, *Sub2space; 20 extern char *SS1space, *SS2space; 21 22 bshiftb(p1, dir, p2) 23 int p1, dir, p2; 24 { 25 int subps; 26 float shval, d1, h1, b1, h2, b2; 27 char *sh1, *sh2; 28 29 yyval = p1; 30 h1 = eht[p1]; 31 b1 = ebase[p1]; 32 h2 = eht[p2]; 33 b2 = ebase[p2]; 34 subps = ps; 35 ps += deltaps; 36 sh1 = sh2 = ""; 37 if (dir == SUB) { 38 /* base .2m below bottom of main box */ 39 shval = b1 + EM(Subbase, ps); 40 ebase[yyval] = shval + b2; 41 eht[yyval] = max(h1-b1+shval+b2, h2); 42 if (rfont[p1] == ITAL && lfont[p2] == ROM) 43 sh1 = Sub1space; 44 } else { /* superscript */ 45 /* 4/10 up main box */ 46 d1 = EM(Subbase, subps); 47 ebase[yyval] = b1; 48 shval = -(Supshift * (h1-b1)) - b2; 49 if (Supshift*(h1-b1) + h2 < h1-b1) /* raise little super */ 50 shval = -(h1-b1) + h2-b2 - d1; 51 eht[yyval] = h1 + max(0, h2 - (1-Supshift)*(h1-b1)); 52 if (rfont[p1] == ITAL) 53 sh1 = Sup1space; 54 } 55 dprintf(".\tS%d <- %d shift %g %d; b=%g, h=%g, ps=%d, subps=%d\n", 56 yyval, p1, shval, p2, ebase[yyval], eht[yyval], ps, subps); 57 sh2 = Sub2space; 58 printf(".as %d \\v'%gm'%s%s\\*(%d%s%s\\v'%gm'\n", 59 yyval, REL(shval,ps), DPS(ps,subps), sh1, p2, 60 DPS(subps,ps), sh2, REL(-shval,ps)); 61 rfont[p1] = 0; 62 sfree(p2); 63 } 64 65 shift2(p1, p2, p3) 66 int p1, p2, p3; 67 { 68 int subps; 69 float h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh; 70 int treg; 71 72 treg = salloc(); 73 yyval = p1; 74 subps = ps; /* sub and sup at this size */ 75 ps += deltaps; /* outer size */ 76 h1 = eht[p1]; b1 = ebase[p1]; 77 h2 = eht[p2]; b2 = ebase[p2]; 78 h3 = eht[p3]; b3 = ebase[p3]; 79 subsh = EM(Subbase, ps); 80 if (b1 > b2 + subsh) /* move little sub down */ 81 subsh += b1; 82 eht[yyval] = max(subsh+b2-b1+h1, h2); 83 supsh = -Supshift*(h1-b1) - b3; 84 d2 = EM(Subbase, subps); 85 if (h3 < (1-Supshift)*(h1-b1)) 86 supsh = -(h1-b1) + (h3-b3) - d2; 87 ebase[yyval] = subsh + b2 - b1; 88 eht[yyval] = h1 + subsh+b2-b1 + max(0, h3-(1-Supshift)*(h1-b1)); 89 dprintf(".\tS%d <- %d sub %d sup %d, ps=%d, subps=%d, h=%g, b=%g\n", 90 yyval, p1, p2, p3, ps, subps, eht[yyval], ebase[yyval]); 91 printf(".ds %d %s\\*(%d\n", p2, SS1space, p2); 92 nrwid(p2, subps, p2); 93 printf(".ds %d %s\\*(%d\n", p3, SS2space, p3); 94 nrwid(p3, subps, p3); 95 printf(".nr %d \\n(%d\n", treg, p3); 96 printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2); 97 printf(".as %d %s\\v'%gm'\\*(%d\\v'%gm'\\h'-\\n(%du'\\\n", 98 p1, DPS(ps,subps), REL(subsh,subps), p2, REL(-subsh,subps), p2); 99 printf("\\v'%gm'\\*(%d\\v'%gm'\\h'-\\n(%du+\\n(%du'%s%s\n", 100 REL(supsh,subps), p3, REL(-supsh,subps), p3, treg, DPS(subps,ps), Sub2space); 101 if (rfont[p2] == ITAL) 102 rfont[yyval] = 0; /* lie */ 103 sfree(p2); sfree(p3); sfree(treg); 104 } 105