matrix.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "e.h"
  2. startcol(int type) /* mark start of column in lp[] array */
  3. {
  4. int oct = ct;
  5. lp[ct++] = type;
  6. lp[ct++] = 0; /* count, to come */
  7. lp[ct++] = 0; /* separation, to come */
  8. return oct;
  9. }
  10. void column(int oct, int sep) /* remember end of column that started at lp[oct] */
  11. {
  12. int i, type;
  13. lp[oct+1] = ct - oct - 3;
  14. lp[oct+2] = sep;
  15. type = lp[oct];
  16. if (dbg) {
  17. printf(".\t%d column of", type);
  18. for (i = oct+3; i < ct; i++ )
  19. printf(" S%d", lp[i]);
  20. printf(", rows=%d, sep=%d\n", lp[oct+1], lp[oct+2]);
  21. }
  22. }
  23. void matrix(int oct) /* matrix is list of columns */
  24. {
  25. int nrow, ncol, i, j, k, val[100];
  26. double b, hb;
  27. char *space;
  28. extern char *Matspace;
  29. space = Matspace; /* between columns of matrix */
  30. nrow = lp[oct+1]; /* disaster if rows inconsistent */
  31. /* also assumes just columns */
  32. /* fix when add other things */
  33. ncol = 0;
  34. for (i = oct+1; i < ct; i += lp[i]+3 ) {
  35. ncol++;
  36. dprintf(".\tcolct=%d\n", lp[i]);
  37. }
  38. for (k=1; k <= nrow; k++) {
  39. hb = b = 0;
  40. j = oct + k + 2;
  41. for (i=0; i < ncol; i++) {
  42. hb = max(hb, eht[lp[j]]-ebase[lp[j]]);
  43. b = max(b, ebase[lp[j]]);
  44. j += nrow + 3;
  45. }
  46. dprintf(".\trow %d: b=%g, hb=%g\n", k, b, hb);
  47. j = oct + k + 2;
  48. for (i=0; i<ncol; i++) {
  49. ebase[lp[j]] = b;
  50. eht[lp[j]] = b + hb;
  51. j += nrow + 3;
  52. }
  53. }
  54. j = oct;
  55. for (i=0; i<ncol; i++) {
  56. pile(j);
  57. val[i] = yyval;
  58. j += nrow + 3;
  59. }
  60. yyval = salloc();
  61. eht[yyval] = eht[val[0]];
  62. ebase[yyval] = ebase[val[0]];
  63. lfont[yyval] = rfont[yyval] = 0;
  64. dprintf(".\tmatrix S%d: r=%d, c=%d, h=%g, b=%g\n",
  65. yyval,nrow,ncol,eht[yyval],ebase[yyval]);
  66. printf(".ds %d \"", yyval);
  67. for( i=0; i<ncol; i++ ) {
  68. printf("\\*(%d%s", val[i], i==ncol-1 ? "" : space);
  69. sfree(val[i]);
  70. }
  71. printf("\n");
  72. }