summaryrefslogtreecommitdiffstats
path: root/src/roff/troff/charinfo.h
blob: 0a7a48150259cfb9341c13df30d453097266a069 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// -*- C++ -*-
/* Copyright (C) 1989-2020 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 3 of the License, 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 this program.  If not, see <http://www.gnu.org/licenses/>. */

#include <vector>
#include <utility>

extern int class_flag;	// set if there was a call to '.class'
extern void get_flags();

class macro;

class charinfo : glyph {
  static int next_index;
  charinfo *translation;
  macro *mac;
  unsigned char special_translation;
  unsigned char hyphenation_code;
  unsigned int flags;
  unsigned char ascii_code;
  unsigned char asciify_code;
  char not_found;
  char transparent_translate;	// non-zero means translation applies
				// to transparent throughput
  char translate_input;		// non-zero means that asciify_code is
				// active for .asciify (set by .trin)
  char_mode mode;
  // Unicode character classes
  std::vector<std::pair<int, int> > ranges;
  std::vector<charinfo *> nested_classes;
public:
  enum {		// Values for the flags bitmask.  See groff
			// manual, description of the '.cflags' request.
    ENDS_SENTENCE = 0x01,
    BREAK_BEFORE = 0x02,
    BREAK_AFTER = 0x04,
    OVERLAPS_HORIZONTALLY = 0x08,
    OVERLAPS_VERTICALLY = 0x10,
    TRANSPARENT = 0x20,
    IGNORE_HCODES = 0x40,
    DONT_BREAK_BEFORE = 0x80,
    DONT_BREAK_AFTER = 0x100,
    INTER_CHAR_SPACE = 0x200
  };
  enum {
    TRANSLATE_NONE,
    TRANSLATE_SPACE,
    TRANSLATE_DUMMY,
    TRANSLATE_STRETCHABLE_SPACE,
    TRANSLATE_HYPHEN_INDICATOR
  };
  symbol nm;
  charinfo(symbol);
  glyph *as_glyph();
  int ends_sentence();
  int overlaps_vertically();
  int overlaps_horizontally();
  int can_break_before();
  int can_break_after();
  int transparent();
  int ignore_hcodes();
  int prohibit_break_before();
  int prohibit_break_after();
  int inter_char_space();
  unsigned char get_hyphenation_code();
  unsigned char get_ascii_code();
  unsigned char get_asciify_code();
  int get_unicode_code();
  void set_hyphenation_code(unsigned char);
  void set_ascii_code(unsigned char);
  void set_asciify_code(unsigned char);
  void set_translation_input();
  int get_translation_input();
  charinfo *get_translation(int = 0);
  void set_translation(charinfo *, int, int);
  void get_flags();
  void set_flags(unsigned int);
  void set_special_translation(int, int);
  int get_special_translation(int = 0);
  macro *set_macro(macro *);
  macro *setx_macro(macro *, char_mode);
  macro *get_macro();
  int first_time_not_found();
  void set_number(int);
  int get_number();
  int numbered();
  int is_normal();
  int is_fallback();
  int is_special();
  symbol *get_symbol();
  void add_to_class(int);
  void add_to_class(int, int);
  void add_to_class(charinfo *);
  bool is_class();
  bool contains(int, bool = false);
  bool contains(symbol, bool = false);
  bool contains(charinfo *, bool = false);
};

charinfo *get_charinfo(symbol);
extern charinfo *charset_table[];
charinfo *get_charinfo_by_number(int);

inline int charinfo::overlaps_horizontally()
{
  if (class_flag)
    ::get_flags();
  return flags & OVERLAPS_HORIZONTALLY;
}

inline int charinfo::overlaps_vertically()
{
  if (class_flag)
    ::get_flags();
  return flags & OVERLAPS_VERTICALLY;
}

inline int charinfo::can_break_before()
{
  if (class_flag)
    ::get_flags();
  return flags & BREAK_BEFORE;
}

inline int charinfo::can_break_after()
{
  if (class_flag)
    ::get_flags();
  return flags & BREAK_AFTER;
}

inline int charinfo::ends_sentence()
{
  if (class_flag)
    ::get_flags();
  return flags & ENDS_SENTENCE;
}

inline int charinfo::transparent()
{
  if (class_flag)
    ::get_flags();
  return flags & TRANSPARENT;
}

inline int charinfo::ignore_hcodes()
{
  if (class_flag)
    ::get_flags();
  return flags & IGNORE_HCODES;
}

inline int charinfo::prohibit_break_before()
{
  if (class_flag)
    ::get_flags();
  return flags & DONT_BREAK_BEFORE;
}

inline int charinfo::prohibit_break_after()
{
  if (class_flag)
    ::get_flags();
  return flags & DONT_BREAK_AFTER;
}

inline int charinfo::inter_char_space()
{
  if (class_flag)
    ::get_flags();
  return flags & INTER_CHAR_SPACE;
}

inline int charinfo::numbered()
{
  return number >= 0;
}

inline int charinfo::is_normal()
{
  return mode == CHAR_NORMAL;
}

inline int charinfo::is_fallback()
{
  return mode == CHAR_FALLBACK;
}

inline int charinfo::is_special()
{
  return mode == CHAR_SPECIAL;
}

inline charinfo *charinfo::get_translation(int transparent_throughput)
{
  return (transparent_throughput && !transparent_translate
	  ? 0
	  : translation);
}

inline unsigned char charinfo::get_hyphenation_code()
{
  return hyphenation_code;
}

inline unsigned char charinfo::get_ascii_code()
{
  return ascii_code;
}

inline unsigned char charinfo::get_asciify_code()
{
  return (translate_input ? asciify_code : 0);
}

inline void charinfo::set_flags(unsigned int c)
{
  flags = c;
}

inline glyph *charinfo::as_glyph()
{
  return this;
}

inline void charinfo::set_translation_input()
{
  translate_input = 1;
}

inline int charinfo::get_translation_input()
{
  return translate_input;
}

inline int charinfo::get_special_translation(int transparent_throughput)
{
  return (transparent_throughput && !transparent_translate
	  ? int(TRANSLATE_NONE)
	  : special_translation);
}

inline macro *charinfo::get_macro()
{
  return mac;
}

inline int charinfo::first_time_not_found()
{
  if (not_found)
    return 0;
  else {
    not_found = 1;
    return 1;
  }
}

inline symbol *charinfo::get_symbol()
{
  return &nm;
}

inline void charinfo::add_to_class(int c)
{
  class_flag = 1;
  // TODO ranges cumbersome for single characters?
  ranges.push_back(std::pair<int, int>(c, c));
}

inline void charinfo::add_to_class(int lo,
				   int hi)
{
  class_flag = 1;
  ranges.push_back(std::pair<int, int>(lo, hi));
}

inline void charinfo::add_to_class(charinfo *ci)
{
  class_flag = 1;
  nested_classes.push_back(ci);
}

inline bool charinfo::is_class()
{
  return (!ranges.empty() || !nested_classes.empty());
}