shift.c 3.3 KB

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