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

https://bitbucket.org/freebsd/freebsd-head/ · C++ · 115 lines · 69 code · 14 blank · 32 comment · 0 complexity · 0dfa4488b632bf4a841020814f69faad 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. #define STRING_FORMAT PREFIX "str%d"
  19. #define SPECIAL_STRING "0s"
  20. #define SPECIAL_WIDTH_REG "0w"
  21. #define SPECIAL_HEIGHT_REG "0h"
  22. #define SPECIAL_DEPTH_REG "0d"
  23. #define SPECIAL_SUB_KERN_REG "0skern"
  24. #define SPECIAL_SKEW_REG "0skew"
  25. /*
  26. For example:
  27. .de Cl
  28. .ds 0s \Z'\\*[0s]'\v'\\n(0du'\D'l \\n(0wu -\\n(0hu-\\n(0du'\v'\\n(0hu'
  29. ..
  30. .EQ
  31. define cancel 'special Cl'
  32. .EN
  33. */
  34. class special_box : public pointer_box {
  35. char *macro_name;
  36. public:
  37. special_box(char *, box *);
  38. ~special_box();
  39. int compute_metrics(int);
  40. void compute_subscript_kern();
  41. void compute_skew();
  42. void output();
  43. void debug_print();
  44. };
  45. box *make_special_box(char *s, box *p)
  46. {
  47. return new special_box(s, p);
  48. }
  49. special_box::special_box(char *s, box *pp) : pointer_box(pp), macro_name(s)
  50. {
  51. }
  52. special_box::~special_box()
  53. {
  54. a_delete macro_name;
  55. }
  56. int special_box::compute_metrics(int style)
  57. {
  58. int r = p->compute_metrics(style);
  59. p->compute_subscript_kern();
  60. p->compute_skew();
  61. printf(".ds " SPECIAL_STRING " \"");
  62. p->output();
  63. printf("\n");
  64. printf(".nr " SPECIAL_WIDTH_REG " 0\\n[" WIDTH_FORMAT "]\n", p->uid);
  65. printf(".nr " SPECIAL_HEIGHT_REG " \\n[" HEIGHT_FORMAT "]\n", p->uid);
  66. printf(".nr " SPECIAL_DEPTH_REG " \\n[" DEPTH_FORMAT "]\n", p->uid);
  67. printf(".nr " SPECIAL_SUB_KERN_REG " \\n[" SUB_KERN_FORMAT "]\n", p->uid);
  68. printf(".nr " SPECIAL_SKEW_REG " 0\\n[" SKEW_FORMAT "]\n", p->uid);
  69. printf(".%s\n", macro_name);
  70. printf(".rn " SPECIAL_STRING " " STRING_FORMAT "\n", uid);
  71. printf(".nr " WIDTH_FORMAT " 0\\n[" SPECIAL_WIDTH_REG "]\n", uid);
  72. printf(".nr " HEIGHT_FORMAT " 0>?\\n[" SPECIAL_HEIGHT_REG "]\n", uid);
  73. printf(".nr " DEPTH_FORMAT " 0>?\\n[" SPECIAL_DEPTH_REG "]\n", uid);
  74. printf(".nr " SUB_KERN_FORMAT " 0>?\\n[" SPECIAL_SUB_KERN_REG "]\n", uid);
  75. printf(".nr " SKEW_FORMAT " 0\\n[" SPECIAL_SKEW_REG "]\n", uid);
  76. // User will have to change MARK_REG if appropriate.
  77. return r;
  78. }
  79. void special_box::compute_subscript_kern()
  80. {
  81. // Already computed in compute_metrics(), so do nothing.
  82. }
  83. void special_box::compute_skew()
  84. {
  85. // Already computed in compute_metrics(), so do nothing.
  86. }
  87. void special_box::output()
  88. {
  89. printf("\\*[" STRING_FORMAT "]", uid);
  90. }
  91. void special_box::debug_print()
  92. {
  93. fprintf(stderr, "special %s { ", macro_name);
  94. p->debug_print();
  95. fprintf(stderr, " }");
  96. }