/contrib/groff/src/preproc/eqn/mark.cpp

https://bitbucket.org/freebsd/freebsd-head/ · C++ · 121 lines · 84 code · 16 blank · 21 comment · 6 complexity · 7b01d151e67306bc7e92fc0d92b6ed71 MD5 · raw file

  1. // -*- C++ -*-
  2. /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3. Written by James Clark (jjc@jclark.com)
  4. This file is part of groff.
  5. groff is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 2, or (at your option) any later
  8. version.
  9. groff is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with groff; see the file COPYING. If not, write to the Free Software
  15. Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
  16. #include "eqn.h"
  17. #include "pbox.h"
  18. class mark_box : public pointer_box {
  19. public:
  20. mark_box(box *);
  21. int compute_metrics(int);
  22. void output();
  23. void debug_print();
  24. };
  25. // we push down marks so that they don't interfere with spacing
  26. box *make_mark_box(box *p)
  27. {
  28. list_box *b = p->to_list_box();
  29. if (b != 0) {
  30. b->list.p[0] = make_mark_box(b->list.p[0]);
  31. return b;
  32. }
  33. else
  34. return new mark_box(p);
  35. }
  36. mark_box::mark_box(box *pp) : pointer_box(pp)
  37. {
  38. }
  39. void mark_box::output()
  40. {
  41. p->output();
  42. }
  43. int mark_box::compute_metrics(int style)
  44. {
  45. int res = p->compute_metrics(style);
  46. if (res)
  47. error("multiple marks and lineups");
  48. printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
  49. printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
  50. printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
  51. printf(".nr " MARK_REG " 0\n");
  52. return FOUND_MARK;
  53. }
  54. void mark_box::debug_print()
  55. {
  56. fprintf(stderr, "mark { ");
  57. p->debug_print();
  58. fprintf(stderr, " }");
  59. }
  60. class lineup_box : public pointer_box {
  61. public:
  62. lineup_box(box *);
  63. void output();
  64. int compute_metrics(int style);
  65. void debug_print();
  66. };
  67. // we push down lineups so that they don't interfere with spacing
  68. box *make_lineup_box(box *p)
  69. {
  70. list_box *b = p->to_list_box();
  71. if (b != 0) {
  72. b->list.p[0] = make_lineup_box(b->list.p[0]);
  73. return b;
  74. }
  75. else
  76. return new lineup_box(p);
  77. }
  78. lineup_box::lineup_box(box *pp) : pointer_box(pp)
  79. {
  80. }
  81. void lineup_box::output()
  82. {
  83. p->output();
  84. }
  85. int lineup_box::compute_metrics(int style)
  86. {
  87. int res = p->compute_metrics(style);
  88. if (res)
  89. error("multiple marks and lineups");
  90. printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
  91. printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
  92. printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
  93. printf(".nr " MARK_REG " 0\n");
  94. return FOUND_LINEUP;
  95. }
  96. void lineup_box::debug_print()
  97. {
  98. fprintf(stderr, "lineup { ");
  99. p->debug_print();
  100. fprintf(stderr, " }");
  101. }