shift.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "e.h"
  10. #include "y.tab.h"
  11. void subsup(int p1, int p2, int p3)
  12. {
  13. if (p2 != 0 && p3 != 0)
  14. shift2(p1, p2, p3);
  15. else if (p2 != 0)
  16. bshiftb(p1, SUB, p2);
  17. else if (p3 != 0)
  18. bshiftb(p1, SUP, p3);
  19. }
  20. extern double Subbase, Supshift;
  21. extern char *Sub1space, *Sup1space, *Sub2space;
  22. extern char *SS1space, *SS2space;
  23. void bshiftb(int p1, int dir, int p2)
  24. {
  25. int subps, n;
  26. double shval, d1, h1, b1, h2, b2;
  27. char *sh1, *sh2;
  28. yyval = p1;
  29. h1 = eht[p1];
  30. b1 = ebase[p1];
  31. h2 = eht[p2];
  32. b2 = ebase[p2];
  33. subps = ps;
  34. ps += deltaps;
  35. if (dir == SUB) {
  36. /* base .2m below bottom of main box */
  37. shval = b1 + EM(Subbase, ps);
  38. ebase[yyval] = shval + b2;
  39. eht[yyval] = max(h1-b1+shval+b2, h2);
  40. if (rfont[p1] == ITAL && lfont[p2] == ROM)
  41. n = 2; /* Sub1space */
  42. else
  43. n = max(2, class[rclass[p1]][lclass[p2]]);
  44. sh1 = pad(n);
  45. rclass[p1] = OTHER; /* OTHER leaves too much after sup */
  46. } else { /* superscript */
  47. /* 4/10 up main box */
  48. d1 = EM(Subbase, subps);
  49. ebase[yyval] = b1;
  50. shval = -(Supshift * (h1-b1)) - b2;
  51. if (Supshift*(h1-b1) + h2 < h1-b1) /* raise little super */
  52. shval = -(h1-b1) + h2-b2 - d1;
  53. eht[yyval] = h1 + max(0, h2 - (1-Supshift)*(h1-b1));
  54. if (rclass[p1] == ILETF)
  55. n = 4;
  56. else if (rfont[p1] == ITAL)
  57. n = 2; /* Sup1space */
  58. else
  59. n = max(1, class[rclass[p1]][lclass[p2]]);
  60. sh1 = pad(n);
  61. rclass[p1] = rclass[p2]; /* OTHER leaves too much after sup */
  62. }
  63. dprintf(".\tS%d <- %d shift %g %d; b=%g, h=%g, ps=%d, subps=%d\n",
  64. yyval, p1, shval, p2, ebase[yyval], eht[yyval], ps, subps);
  65. sh2 = Sub2space; /* was Sub2space; */
  66. printf(".as %d \\v'%gm'%s%s\\*(%d%s%s\\v'%gm'\n",
  67. yyval, REL(shval,ps), DPS(ps,subps), sh1, p2,
  68. DPS(subps,ps), sh2, REL(-shval,ps));
  69. rfont[p1] = 0;
  70. sfree(p2);
  71. }
  72. void shift2(int p1, int p2, int p3)
  73. {
  74. int subps;
  75. double h1, h2, h3, b1, b2, b3, subsh, d2, supsh;
  76. int treg;
  77. char *sh2;
  78. treg = salloc();
  79. yyval = p1;
  80. subps = ps; /* sub and sup at this size */
  81. ps += deltaps; /* outer size */
  82. h1 = eht[p1]; b1 = ebase[p1];
  83. h2 = eht[p2]; b2 = ebase[p2];
  84. h3 = eht[p3]; b3 = ebase[p3];
  85. subsh = EM(Subbase, ps);
  86. if (b1 > b2 + subsh) /* move little sub down */
  87. subsh += b1;
  88. eht[yyval] = max(subsh+b2-b1+h1, h2);
  89. supsh = -Supshift*(h1-b1) - b3;
  90. d2 = EM(Subbase, subps);
  91. if (h3 < (1-Supshift)*(h1-b1))
  92. supsh = -(h1-b1) + (h3-b3) - d2;
  93. ebase[yyval] = subsh + b2 - b1;
  94. eht[yyval] = h1 + subsh+b2-b1 + max(0, h3-(1-Supshift)*(h1-b1));
  95. dprintf(".\tS%d <- %d sub %d sup %d, ps=%d, subps=%d, h=%g, b=%g\n",
  96. yyval, p1, p2, p3, ps, subps, eht[yyval], ebase[yyval]);
  97. if (rclass[p1] == ILETF)
  98. sh2 = "\\|\\|";
  99. else
  100. sh2 = SS2space;
  101. /*n = max(class[rclass[p1]][lclass[p2]], class[rclass[p1]][lclass[p3]]);
  102. /*sh2 = pad(max(2, n));
  103. */
  104. printf(".ds %d %s\\*(%d\n", p2, SS1space, p2);
  105. nrwid(p2, subps, p2);
  106. printf(".ds %d %s\\*(%d\n", p3, sh2, p3);
  107. nrwid(p3, subps, p3);
  108. printf(".nr %d \\n(%d\n", treg, p3);
  109. printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
  110. printf(".as %d %s\\v'%gm'\\*(%d\\v'%gm'\\h'-\\n(%du'\\\n",
  111. p1, DPS(ps,subps), REL(subsh,subps), p2, REL(-subsh,subps), p2);
  112. printf("\\v'%gm'\\*(%d\\v'%gm'\\h'-\\n(%du+\\n(%du'%s%s\n",
  113. REL(supsh,subps), p3, REL(-supsh,subps), p3, treg, DPS(subps,ps), Sub2space);
  114. if (rfont[p2] == ITAL)
  115. rfont[yyval] = 0; /* lie */
  116. rclass[yyval] = rclass[p3]; /* was OTHER */
  117. sfree(p2); sfree(p3); sfree(treg);
  118. }