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