summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/groff/eqn/special.cc
blob: 64ee5530fc8c48d830b7f182d6825870e761885d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// -*- C++ -*-
/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
     Written by James Clark (jjc@jclark.com)

This file is part of groff.

groff is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.

groff is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with groff; see the file COPYING.  If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

#include "eqn.h"
#include "pbox.h"

#define STRING_FORMAT PREFIX "str%d"

#define SPECIAL_STRING "0s"
#define SPECIAL_WIDTH_REG "0w"
#define SPECIAL_HEIGHT_REG "0h"
#define SPECIAL_DEPTH_REG "0d"
#define SPECIAL_SUB_KERN_REG "0skern"
#define SPECIAL_SKEW_REG "0skew"

/*
For example:

.de Cl
.ds 0s \Z'\\*[0s]'\v'\\n(0du'\D'l \\n(0wu -\\n(0hu-\\n(0du'\v'\\n(0hu'
..
.EQ
define cancel 'special Cl'
.EN
*/


class special_box : public pointer_box {
  char *macro_name;
public:
  special_box(char *, box *);
  ~special_box();
  int compute_metrics(int);
  void compute_subscript_kern();
  void compute_skew();
  void output();
  void debug_print();
};

box *make_special_box(char *s, box *p)
{
  return new special_box(s, p);
}

special_box::special_box(char *s, box *pp) :macro_name(s), pointer_box(pp)
{
}

special_box::~special_box()
{
  a_delete macro_name;
}

int special_box::compute_metrics(int style)
{
  int r = p->compute_metrics(style);
  p->compute_subscript_kern();
  p->compute_skew();
  printf(".ds " SPECIAL_STRING " \"");
  p->output();
  printf("\n");
  printf(".nr " SPECIAL_WIDTH_REG " 0\\n[" WIDTH_FORMAT "]\n", p->uid);
  printf(".nr " SPECIAL_HEIGHT_REG " \\n[" HEIGHT_FORMAT "]\n", p->uid);
  printf(".nr " SPECIAL_DEPTH_REG " \\n[" DEPTH_FORMAT "]\n", p->uid);
  printf(".nr " SPECIAL_SUB_KERN_REG " \\n[" SUB_KERN_FORMAT "]\n", p->uid);
  printf(".nr " SPECIAL_SKEW_REG " 0\\n[" SKEW_FORMAT "]\n", p->uid);
  printf(".%s\n", macro_name);
  printf(".rn " SPECIAL_STRING " " STRING_FORMAT "\n", uid);
  printf(".nr " WIDTH_FORMAT " 0\\n[" SPECIAL_WIDTH_REG "]\n", uid);
  printf(".nr " HEIGHT_FORMAT " 0>?\\n[" SPECIAL_HEIGHT_REG "]\n", uid);
  printf(".nr " DEPTH_FORMAT " 0>?\\n[" SPECIAL_DEPTH_REG "]\n", uid);
  printf(".nr " SUB_KERN_FORMAT " 0>?\\n[" SPECIAL_SUB_KERN_REG "]\n", uid);
  printf(".nr " SKEW_FORMAT " 0\\n[" SPECIAL_SKEW_REG "]\n", uid);
  // User will have to change MARK_REG if appropriate.
  return r;
}

void special_box::compute_subscript_kern()
{
  // Already computed in compute_metrics(), so do nothing.
}

void special_box::compute_skew()
{
  // Already computed in compute_metrics(), so do nothing.
}

void special_box::output()
{
  printf("\\*[" STRING_FORMAT "]", uid);
}

void special_box::debug_print()
{
  fprintf(stderr, "special %s { ", macro_name);
  p->debug_print();
  fprintf(stderr, " }");
}