| Commit | Line | Data |
|---|---|---|
| 92d0a6a6 | 1 | // -*- C++ -*- |
| 4d3e9548 JL |
2 | /* Copyright (C) 1989, 1990, 1991, 1992, 2007, 2009 |
| 3 | Free Software Foundation, Inc. | |
| 92d0a6a6 JR |
4 | Written by James Clark (jjc@jclark.com) |
| 5 | ||
| 6 | This file is part of groff. | |
| 7 | ||
| 8 | groff is free software; you can redistribute it and/or modify it under | |
| 9 | the terms of the GNU General Public License as published by the Free | |
| 4d3e9548 JL |
10 | Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. | |
| 92d0a6a6 JR |
12 | |
| 13 | groff is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 16 | for more details. | |
| 17 | ||
| 4d3e9548 JL |
18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
| 92d0a6a6 JR |
20 | |
| 21 | #include "eqn.h" | |
| 22 | #include "pbox.h" | |
| 23 | ||
| 24 | #define STRING_FORMAT PREFIX "str%d" | |
| 25 | ||
| 26 | #define SPECIAL_STRING "0s" | |
| 27 | #define SPECIAL_WIDTH_REG "0w" | |
| 28 | #define SPECIAL_HEIGHT_REG "0h" | |
| 29 | #define SPECIAL_DEPTH_REG "0d" | |
| 30 | #define SPECIAL_SUB_KERN_REG "0skern" | |
| 31 | #define SPECIAL_SKEW_REG "0skew" | |
| 32 | ||
| 33 | /* | |
| 34 | For example: | |
| 35 | ||
| 36 | .de Cl | |
| 37 | .ds 0s \Z'\\*[0s]'\v'\\n(0du'\D'l \\n(0wu -\\n(0hu-\\n(0du'\v'\\n(0hu' | |
| 38 | .. | |
| 39 | .EQ | |
| 40 | define cancel 'special Cl' | |
| 41 | .EN | |
| 42 | */ | |
| 43 | ||
| 44 | ||
| 45 | class special_box : public pointer_box { | |
| 46 | char *macro_name; | |
| 47 | public: | |
| 48 | special_box(char *, box *); | |
| 49 | ~special_box(); | |
| 50 | int compute_metrics(int); | |
| 51 | void compute_subscript_kern(); | |
| 52 | void compute_skew(); | |
| 53 | void output(); | |
| 54 | void debug_print(); | |
| 55 | }; | |
| 56 | ||
| 57 | box *make_special_box(char *s, box *p) | |
| 58 | { | |
| 59 | return new special_box(s, p); | |
| 60 | } | |
| 61 | ||
| 62 | special_box::special_box(char *s, box *pp) : pointer_box(pp), macro_name(s) | |
| 63 | { | |
| 64 | } | |
| 65 | ||
| 66 | special_box::~special_box() | |
| 67 | { | |
| 68 | a_delete macro_name; | |
| 69 | } | |
| 70 | ||
| 71 | int special_box::compute_metrics(int style) | |
| 72 | { | |
| 73 | int r = p->compute_metrics(style); | |
| 74 | p->compute_subscript_kern(); | |
| 75 | p->compute_skew(); | |
| 76 | printf(".ds " SPECIAL_STRING " \""); | |
| 77 | p->output(); | |
| 78 | printf("\n"); | |
| 79 | printf(".nr " SPECIAL_WIDTH_REG " 0\\n[" WIDTH_FORMAT "]\n", p->uid); | |
| 80 | printf(".nr " SPECIAL_HEIGHT_REG " \\n[" HEIGHT_FORMAT "]\n", p->uid); | |
| 81 | printf(".nr " SPECIAL_DEPTH_REG " \\n[" DEPTH_FORMAT "]\n", p->uid); | |
| 82 | printf(".nr " SPECIAL_SUB_KERN_REG " \\n[" SUB_KERN_FORMAT "]\n", p->uid); | |
| 83 | printf(".nr " SPECIAL_SKEW_REG " 0\\n[" SKEW_FORMAT "]\n", p->uid); | |
| 84 | printf(".%s\n", macro_name); | |
| 85 | printf(".rn " SPECIAL_STRING " " STRING_FORMAT "\n", uid); | |
| 86 | printf(".nr " WIDTH_FORMAT " 0\\n[" SPECIAL_WIDTH_REG "]\n", uid); | |
| 87 | printf(".nr " HEIGHT_FORMAT " 0>?\\n[" SPECIAL_HEIGHT_REG "]\n", uid); | |
| 88 | printf(".nr " DEPTH_FORMAT " 0>?\\n[" SPECIAL_DEPTH_REG "]\n", uid); | |
| 89 | printf(".nr " SUB_KERN_FORMAT " 0>?\\n[" SPECIAL_SUB_KERN_REG "]\n", uid); | |
| 90 | printf(".nr " SKEW_FORMAT " 0\\n[" SPECIAL_SKEW_REG "]\n", uid); | |
| 91 | // User will have to change MARK_REG if appropriate. | |
| 92 | return r; | |
| 93 | } | |
| 94 | ||
| 95 | void special_box::compute_subscript_kern() | |
| 96 | { | |
| 97 | // Already computed in compute_metrics(), so do nothing. | |
| 98 | } | |
| 99 | ||
| 100 | void special_box::compute_skew() | |
| 101 | { | |
| 102 | // Already computed in compute_metrics(), so do nothing. | |
| 103 | } | |
| 104 | ||
| 105 | void special_box::output() | |
| 106 | { | |
| 4d3e9548 JL |
107 | if (output_format == troff) |
| 108 | printf("\\*[" STRING_FORMAT "]", uid); | |
| 109 | else if (output_format == mathml) | |
| 110 | printf("<merror>eqn specials cannot be expressed in MathML</merror>"); | |
| 92d0a6a6 JR |
111 | } |
| 112 | ||
| 113 | void special_box::debug_print() | |
| 114 | { | |
| 115 | fprintf(stderr, "special %s { ", macro_name); | |
| 116 | p->debug_print(); | |
| 117 | fprintf(stderr, " }"); | |
| 118 | } |