special.cpp revision 151497
1114402Sru// -*- C++ -*- 2114402Sru/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. 3114402Sru Written by James Clark (jjc@jclark.com) 4114402Sru 5114402SruThis file is part of groff. 6114402Sru 7114402Srugroff is free software; you can redistribute it and/or modify it under 8114402Sruthe terms of the GNU General Public License as published by the Free 9114402SruSoftware Foundation; either version 2, or (at your option) any later 10114402Sruversion. 11114402Sru 12114402Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY 13114402SruWARRANTY; without even the implied warranty of MERCHANTABILITY or 14114402SruFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15114402Srufor more details. 16114402Sru 17114402SruYou should have received a copy of the GNU General Public License along 18114402Sruwith groff; see the file COPYING. If not, write to the Free Software 19151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 20114402Sru 21114402Sru#include "eqn.h" 22114402Sru#include "pbox.h" 23114402Sru 24114402Sru#define STRING_FORMAT PREFIX "str%d" 25114402Sru 26114402Sru#define SPECIAL_STRING "0s" 27114402Sru#define SPECIAL_WIDTH_REG "0w" 28114402Sru#define SPECIAL_HEIGHT_REG "0h" 29114402Sru#define SPECIAL_DEPTH_REG "0d" 30114402Sru#define SPECIAL_SUB_KERN_REG "0skern" 31114402Sru#define SPECIAL_SKEW_REG "0skew" 32114402Sru 33114402Sru/* 34114402SruFor example: 35114402Sru 36114402Sru.de Cl 37114402Sru.ds 0s \Z'\\*[0s]'\v'\\n(0du'\D'l \\n(0wu -\\n(0hu-\\n(0du'\v'\\n(0hu' 38114402Sru.. 39114402Sru.EQ 40114402Srudefine cancel 'special Cl' 41114402Sru.EN 42114402Sru*/ 43114402Sru 44114402Sru 45114402Sruclass special_box : public pointer_box { 46114402Sru char *macro_name; 47114402Srupublic: 48114402Sru special_box(char *, box *); 49114402Sru ~special_box(); 50114402Sru int compute_metrics(int); 51114402Sru void compute_subscript_kern(); 52114402Sru void compute_skew(); 53114402Sru void output(); 54114402Sru void debug_print(); 55114402Sru}; 56114402Sru 57114402Srubox *make_special_box(char *s, box *p) 58114402Sru{ 59114402Sru return new special_box(s, p); 60114402Sru} 61114402Sru 62114402Sruspecial_box::special_box(char *s, box *pp) : pointer_box(pp), macro_name(s) 63114402Sru{ 64114402Sru} 65114402Sru 66114402Sruspecial_box::~special_box() 67114402Sru{ 68114402Sru a_delete macro_name; 69114402Sru} 70114402Sru 71114402Sruint special_box::compute_metrics(int style) 72114402Sru{ 73114402Sru int r = p->compute_metrics(style); 74114402Sru p->compute_subscript_kern(); 75114402Sru p->compute_skew(); 76114402Sru printf(".ds " SPECIAL_STRING " \""); 77114402Sru p->output(); 78114402Sru printf("\n"); 79114402Sru printf(".nr " SPECIAL_WIDTH_REG " 0\\n[" WIDTH_FORMAT "]\n", p->uid); 80114402Sru printf(".nr " SPECIAL_HEIGHT_REG " \\n[" HEIGHT_FORMAT "]\n", p->uid); 81114402Sru printf(".nr " SPECIAL_DEPTH_REG " \\n[" DEPTH_FORMAT "]\n", p->uid); 82114402Sru printf(".nr " SPECIAL_SUB_KERN_REG " \\n[" SUB_KERN_FORMAT "]\n", p->uid); 83114402Sru printf(".nr " SPECIAL_SKEW_REG " 0\\n[" SKEW_FORMAT "]\n", p->uid); 84114402Sru printf(".%s\n", macro_name); 85114402Sru printf(".rn " SPECIAL_STRING " " STRING_FORMAT "\n", uid); 86114402Sru printf(".nr " WIDTH_FORMAT " 0\\n[" SPECIAL_WIDTH_REG "]\n", uid); 87114402Sru printf(".nr " HEIGHT_FORMAT " 0>?\\n[" SPECIAL_HEIGHT_REG "]\n", uid); 88114402Sru printf(".nr " DEPTH_FORMAT " 0>?\\n[" SPECIAL_DEPTH_REG "]\n", uid); 89114402Sru printf(".nr " SUB_KERN_FORMAT " 0>?\\n[" SPECIAL_SUB_KERN_REG "]\n", uid); 90114402Sru printf(".nr " SKEW_FORMAT " 0\\n[" SPECIAL_SKEW_REG "]\n", uid); 91114402Sru // User will have to change MARK_REG if appropriate. 92114402Sru return r; 93114402Sru} 94114402Sru 95114402Sruvoid special_box::compute_subscript_kern() 96114402Sru{ 97114402Sru // Already computed in compute_metrics(), so do nothing. 98114402Sru} 99114402Sru 100114402Sruvoid special_box::compute_skew() 101114402Sru{ 102114402Sru // Already computed in compute_metrics(), so do nothing. 103114402Sru} 104114402Sru 105114402Sruvoid special_box::output() 106114402Sru{ 107114402Sru printf("\\*[" STRING_FORMAT "]", uid); 108114402Sru} 109114402Sru 110114402Sruvoid special_box::debug_print() 111114402Sru{ 112114402Sru fprintf(stderr, "special %s { ", macro_name); 113114402Sru p->debug_print(); 114114402Sru fprintf(stderr, " }"); 115114402Sru} 116