2 /* Copyright (C) 1989-2018 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 extern int class_flag; // set if there was a call to '.class'
24 extern void get_flags();
28 class charinfo : glyph {
29 static int next_index;
30 charinfo *translation;
32 unsigned char special_translation;
33 unsigned char hyphenation_code;
35 unsigned char ascii_code;
36 unsigned char asciify_code;
38 char transparent_translate; // non-zero means translation applies
39 // to transparent throughput
40 char translate_input; // non-zero means that asciify_code is
41 // active for .asciify (set by .trin)
43 // Unicode character classes
44 std::vector<std::pair<int, int> > ranges;
45 std::vector<charinfo *> nested_classes;
47 enum { // Values for the flags bitmask. See groff
48 // manual, description of the '.cflags' request.
52 OVERLAPS_HORIZONTALLY = 0x08,
53 OVERLAPS_VERTICALLY = 0x10,
56 DONT_BREAK_BEFORE = 0x80,
57 DONT_BREAK_AFTER = 0x100,
58 INTER_CHAR_SPACE = 0x200
64 TRANSLATE_STRETCHABLE_SPACE,
65 TRANSLATE_HYPHEN_INDICATOR
71 int overlaps_vertically();
72 int overlaps_horizontally();
73 int can_break_before();
74 int can_break_after();
77 int prohibit_break_before();
78 int prohibit_break_after();
79 int inter_char_space();
80 unsigned char get_hyphenation_code();
81 unsigned char get_ascii_code();
82 unsigned char get_asciify_code();
83 int get_unicode_code();
84 void set_hyphenation_code(unsigned char);
85 void set_ascii_code(unsigned char);
86 void set_asciify_code(unsigned char);
87 void set_translation_input();
88 int get_translation_input();
89 charinfo *get_translation(int = 0);
90 void set_translation(charinfo *, int, int);
92 void set_flags(unsigned int);
93 void set_special_translation(int, int);
94 int get_special_translation(int = 0);
95 macro *set_macro(macro *);
96 macro *setx_macro(macro *, char_mode);
98 int first_time_not_found();
105 symbol *get_symbol();
106 void add_to_class(int);
107 void add_to_class(int, int);
108 void add_to_class(charinfo *);
110 bool contains(int, bool = false);
111 bool contains(symbol, bool = false);
112 bool contains(charinfo *, bool = false);
115 charinfo *get_charinfo(symbol);
116 extern charinfo *charset_table[];
117 charinfo *get_charinfo_by_number(int);
119 inline int charinfo::overlaps_horizontally()
123 return flags & OVERLAPS_HORIZONTALLY;
126 inline int charinfo::overlaps_vertically()
130 return flags & OVERLAPS_VERTICALLY;
133 inline int charinfo::can_break_before()
137 return flags & BREAK_BEFORE;
140 inline int charinfo::can_break_after()
144 return flags & BREAK_AFTER;
147 inline int charinfo::ends_sentence()
151 return flags & ENDS_SENTENCE;
154 inline int charinfo::transparent()
158 return flags & TRANSPARENT;
161 inline int charinfo::ignore_hcodes()
165 return flags & IGNORE_HCODES;
168 inline int charinfo::prohibit_break_before()
172 return flags & DONT_BREAK_BEFORE;
175 inline int charinfo::prohibit_break_after()
179 return flags & DONT_BREAK_AFTER;
182 inline int charinfo::inter_char_space()
186 return flags & INTER_CHAR_SPACE;
189 inline int charinfo::numbered()
194 inline int charinfo::is_normal()
196 return mode == CHAR_NORMAL;
199 inline int charinfo::is_fallback()
201 return mode == CHAR_FALLBACK;
204 inline int charinfo::is_special()
206 return mode == CHAR_SPECIAL;
209 inline charinfo *charinfo::get_translation(int transparent_throughput)
211 return (transparent_throughput && !transparent_translate
216 inline unsigned char charinfo::get_hyphenation_code()
218 return hyphenation_code;
221 inline unsigned char charinfo::get_ascii_code()
226 inline unsigned char charinfo::get_asciify_code()
228 return (translate_input ? asciify_code : 0);
231 inline void charinfo::set_flags(unsigned int c)
236 inline glyph *charinfo::as_glyph()
241 inline void charinfo::set_translation_input()
246 inline int charinfo::get_translation_input()
248 return translate_input;
251 inline int charinfo::get_special_translation(int transparent_throughput)
253 return (transparent_throughput && !transparent_translate
254 ? int(TRANSLATE_NONE)
255 : special_translation);
258 inline macro *charinfo::get_macro()
263 inline int charinfo::first_time_not_found()
273 inline symbol *charinfo::get_symbol()
278 inline void charinfo::add_to_class(int c)
281 // TODO ranges cumbersome for single characters?
282 ranges.push_back(std::pair<int, int>(c, c));
285 inline void charinfo::add_to_class(int lo,
289 ranges.push_back(std::pair<int, int>(lo, hi));
292 inline void charinfo::add_to_class(charinfo *ci)
295 nested_classes.push_back(ci);
298 inline bool charinfo::is_class()
300 return (!ranges.empty() || !nested_classes.empty());