/contrib/groff/src/roff/troff/node.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 676 lines · 600 code · 55 blank · 21 comment · 1 complexity · e86c358a6c4e5229e608298b206e9ae5 MD5 · raw file

  1. // -*- C++ -*-
  2. /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004
  3. Free Software Foundation, Inc.
  4. Written by James Clark (jjc@jclark.com)
  5. This file is part of groff.
  6. groff is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation; either version 2, or (at your option) any later
  9. version.
  10. groff is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. for more details.
  14. You should have received a copy of the GNU General Public License along
  15. with groff; see the file COPYING. If not, write to the Free Software
  16. Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
  17. struct hyphen_list {
  18. unsigned char hyphen;
  19. unsigned char breakable;
  20. unsigned char hyphenation_code;
  21. hyphen_list *next;
  22. hyphen_list(unsigned char code, hyphen_list *p = 0);
  23. };
  24. void hyphenate(hyphen_list *, unsigned);
  25. enum hyphenation_type { HYPHEN_MIDDLE, HYPHEN_BOUNDARY, HYPHEN_INHIBIT };
  26. class ascii_output_file;
  27. struct breakpoint;
  28. struct vertical_size;
  29. class charinfo;
  30. class macro;
  31. class troff_output_file;
  32. class tfont;
  33. class environment;
  34. class glyph_node;
  35. class diverted_space_node;
  36. class token_node;
  37. struct node {
  38. node *next;
  39. node *last;
  40. statem *state;
  41. statem *push_state;
  42. int div_nest_level;
  43. int is_special;
  44. node();
  45. node(node *);
  46. node(node *, statem *, int);
  47. node *add_char(charinfo *, environment *, hunits *, int *, node ** = 0);
  48. virtual ~node();
  49. virtual node *copy() = 0;
  50. virtual int set_unformat_flag();
  51. virtual int force_tprint() = 0;
  52. virtual int is_tag() = 0;
  53. virtual hunits width();
  54. virtual hunits subscript_correction();
  55. virtual hunits italic_correction();
  56. virtual hunits left_italic_correction();
  57. virtual hunits skew();
  58. virtual int nspaces();
  59. virtual int merge_space(hunits, hunits, hunits);
  60. virtual vunits vertical_width();
  61. virtual node *last_char_node();
  62. virtual void vertical_extent(vunits *, vunits *);
  63. virtual int character_type();
  64. virtual void set_vertical_size(vertical_size *);
  65. virtual int ends_sentence();
  66. virtual node *merge_self(node *);
  67. virtual node *add_discretionary_hyphen();
  68. virtual node *add_self(node *, hyphen_list **);
  69. virtual hyphen_list *get_hyphen_list(hyphen_list *, int *);
  70. virtual void ascii_print(ascii_output_file *);
  71. virtual void asciify(macro *);
  72. virtual int discardable();
  73. virtual void spread_space(int *, hunits *);
  74. virtual void freeze_space();
  75. virtual void is_escape_colon();
  76. virtual breakpoint *get_breakpoints(hunits, int, breakpoint * = 0, int = 0);
  77. virtual int nbreaks();
  78. virtual void split(int, node **, node **);
  79. virtual hyphenation_type get_hyphenation_type();
  80. virtual int reread(int *);
  81. virtual token_node *get_token_node();
  82. virtual int overlaps_vertically();
  83. virtual int overlaps_horizontally();
  84. virtual units size();
  85. virtual int interpret(macro *);
  86. virtual node *merge_glyph_node(glyph_node *);
  87. virtual tfont *get_tfont();
  88. virtual color *get_glyph_color();
  89. virtual color *get_fill_color();
  90. virtual void tprint(troff_output_file *);
  91. virtual void zero_width_tprint(troff_output_file *);
  92. node *add_italic_correction(hunits *);
  93. virtual int same(node *) = 0;
  94. virtual const char *type() = 0;
  95. virtual void debug_node();
  96. virtual void debug_node_list();
  97. };
  98. inline node::node()
  99. : next(0), last(0), state(0), push_state(0), div_nest_level(0), is_special(0)
  100. {
  101. }
  102. inline node::node(node *n)
  103. : next(n), last(0), state(0), push_state(0), div_nest_level(0), is_special(0)
  104. {
  105. }
  106. inline node::node(node *n, statem *s, int divlevel)
  107. : next(n), last(0), push_state(0), div_nest_level(divlevel), is_special(0)
  108. {
  109. if (s)
  110. state = new statem(s);
  111. else
  112. state = 0;
  113. }
  114. inline node::~node()
  115. {
  116. }
  117. // 0 means it doesn't, 1 means it does, 2 means it's transparent
  118. int node_list_ends_sentence(node *);
  119. struct breakpoint {
  120. breakpoint *next;
  121. hunits width;
  122. int nspaces;
  123. node *nd;
  124. int index;
  125. char hyphenated;
  126. };
  127. class line_start_node : public node {
  128. public:
  129. line_start_node() {}
  130. node *copy() { return new line_start_node; }
  131. int same(node *);
  132. int force_tprint();
  133. int is_tag();
  134. const char *type();
  135. void asciify(macro *);
  136. };
  137. class space_node : public node {
  138. private:
  139. #if 0
  140. enum { BLOCK = 1024 };
  141. static space_node *free_list;
  142. void operator delete(void *);
  143. #endif
  144. protected:
  145. hunits n;
  146. char set;
  147. char was_escape_colon;
  148. color *col; /* for grotty */
  149. space_node(hunits, int, int, color *, statem *, int, node * = 0);
  150. public:
  151. space_node(hunits, color *, statem *, int, node * = 0);
  152. space_node(hunits, color *, node * = 0);
  153. #if 0
  154. ~space_node();
  155. void *operator new(size_t);
  156. #endif
  157. node *copy();
  158. int nspaces();
  159. hunits width();
  160. int discardable();
  161. int merge_space(hunits, hunits, hunits);
  162. void freeze_space();
  163. void is_escape_colon();
  164. void spread_space(int *, hunits *);
  165. void tprint(troff_output_file *);
  166. breakpoint *get_breakpoints(hunits, int, breakpoint * = 0, int = 0);
  167. int nbreaks();
  168. void split(int, node **, node **);
  169. void ascii_print(ascii_output_file *);
  170. int same(node *);
  171. void asciify(macro *);
  172. const char *type();
  173. int force_tprint();
  174. int is_tag();
  175. hyphenation_type get_hyphenation_type();
  176. };
  177. struct width_list {
  178. hunits width;
  179. hunits sentence_width;
  180. width_list *next;
  181. width_list(hunits, hunits);
  182. width_list(width_list *);
  183. };
  184. class word_space_node : public space_node {
  185. protected:
  186. width_list *orig_width;
  187. unsigned char unformat;
  188. word_space_node(hunits, int, color *, width_list *, int, statem *, int,
  189. node * = 0);
  190. public:
  191. word_space_node(hunits, color *, width_list *, node * = 0);
  192. ~word_space_node();
  193. node *copy();
  194. int reread(int *);
  195. int set_unformat_flag();
  196. void tprint(troff_output_file *);
  197. int same(node *);
  198. void asciify(macro *);
  199. const char *type();
  200. int merge_space(hunits, hunits, hunits);
  201. int force_tprint();
  202. int is_tag();
  203. };
  204. class unbreakable_space_node : public word_space_node {
  205. unbreakable_space_node(hunits, int, color *, statem *, int, node * = 0);
  206. public:
  207. unbreakable_space_node(hunits, color *, node * = 0);
  208. node *copy();
  209. int reread(int *);
  210. void tprint(troff_output_file *);
  211. int same(node *);
  212. void asciify(macro *);
  213. const char *type();
  214. int force_tprint();
  215. int is_tag();
  216. breakpoint *get_breakpoints(hunits, int, breakpoint * = 0, int = 0);
  217. int nbreaks();
  218. void split(int, node **, node **);
  219. int merge_space(hunits, hunits, hunits);
  220. node *add_self(node *, hyphen_list **);
  221. hyphen_list *get_hyphen_list(hyphen_list *, int *);
  222. hyphenation_type get_hyphenation_type();
  223. };
  224. class diverted_space_node : public node {
  225. public:
  226. vunits n;
  227. diverted_space_node(vunits, node * = 0);
  228. diverted_space_node(vunits, statem *, int, node * = 0);
  229. node *copy();
  230. int reread(int *);
  231. int same(node *);
  232. const char *type();
  233. int force_tprint();
  234. int is_tag();
  235. };
  236. class diverted_copy_file_node : public node {
  237. symbol filename;
  238. public:
  239. vunits n;
  240. diverted_copy_file_node(symbol, node * = 0);
  241. diverted_copy_file_node(symbol, statem *, int, node * = 0);
  242. node *copy();
  243. int reread(int *);
  244. int same(node *);
  245. const char *type();
  246. int force_tprint();
  247. int is_tag();
  248. };
  249. class extra_size_node : public node {
  250. vunits n;
  251. public:
  252. extra_size_node(vunits);
  253. extra_size_node(vunits, statem *, int);
  254. void set_vertical_size(vertical_size *);
  255. node *copy();
  256. int same(node *);
  257. const char *type();
  258. int force_tprint();
  259. int is_tag();
  260. };
  261. class vertical_size_node : public node {
  262. vunits n;
  263. public:
  264. vertical_size_node(vunits, statem *, int);
  265. vertical_size_node(vunits);
  266. void set_vertical_size(vertical_size *);
  267. void asciify(macro *);
  268. node *copy();
  269. int set_unformat_flag();
  270. int same(node *);
  271. const char *type();
  272. int force_tprint();
  273. int is_tag();
  274. };
  275. class hmotion_node : public node {
  276. protected:
  277. hunits n;
  278. unsigned char was_tab;
  279. unsigned char unformat;
  280. color *col; /* for grotty */
  281. public:
  282. hmotion_node(hunits i, color *c, node *nxt = 0)
  283. : node(nxt), n(i), was_tab(0), unformat(0), col(c) {}
  284. hmotion_node(hunits i, color *c, statem *s, int divlevel, node *nxt = 0)
  285. : node(nxt, s, divlevel), n(i), was_tab(0), unformat(0), col(c) {}
  286. hmotion_node(hunits i, int flag1, int flag2, color *c, statem *s,
  287. int divlevel, node *nxt = 0)
  288. : node(nxt, s, divlevel), n(i), was_tab(flag1), unformat(flag2),
  289. col(c) {}
  290. hmotion_node(hunits i, int flag1, int flag2, color *c, node *nxt = 0)
  291. : node(nxt), n(i), was_tab(flag1), unformat(flag2), col(c) {}
  292. node *copy();
  293. int reread(int *);
  294. int set_unformat_flag();
  295. void asciify(macro *);
  296. void tprint(troff_output_file *);
  297. hunits width();
  298. void ascii_print(ascii_output_file *);
  299. int same(node *);
  300. const char *type();
  301. int force_tprint();
  302. int is_tag();
  303. node *add_self(node *, hyphen_list **);
  304. hyphen_list *get_hyphen_list(hyphen_list *, int *);
  305. hyphenation_type get_hyphenation_type();
  306. };
  307. class space_char_hmotion_node : public hmotion_node {
  308. public:
  309. space_char_hmotion_node(hunits, color *, node * = 0);
  310. space_char_hmotion_node(hunits, color *, statem *, int, node * = 0);
  311. node *copy();
  312. void ascii_print(ascii_output_file *);
  313. void asciify(macro *);
  314. void tprint(troff_output_file *);
  315. int same(node *);
  316. const char *type();
  317. int force_tprint();
  318. int is_tag();
  319. node *add_self(node *, hyphen_list **);
  320. hyphen_list *get_hyphen_list(hyphen_list *, int *);
  321. hyphenation_type get_hyphenation_type();
  322. };
  323. class vmotion_node : public node {
  324. vunits n;
  325. color *col; /* for grotty */
  326. public:
  327. vmotion_node(vunits, color *);
  328. vmotion_node(vunits, color *, statem *, int);
  329. void tprint(troff_output_file *);
  330. node *copy();
  331. vunits vertical_width();
  332. int same(node *);
  333. const char *type();
  334. int force_tprint();
  335. int is_tag();
  336. };
  337. class hline_node : public node {
  338. hunits x;
  339. node *n;
  340. public:
  341. hline_node(hunits, node *, node * = 0);
  342. hline_node(hunits, node *, statem *, int, node * = 0);
  343. ~hline_node();
  344. node *copy();
  345. hunits width();
  346. void tprint(troff_output_file *);
  347. int same(node *);
  348. const char *type();
  349. int force_tprint();
  350. int is_tag();
  351. };
  352. class vline_node : public node {
  353. vunits x;
  354. node *n;
  355. public:
  356. vline_node(vunits, node *, node * = 0);
  357. vline_node(vunits, node *, statem *, int, node * = 0);
  358. ~vline_node();
  359. node *copy();
  360. void tprint(troff_output_file *);
  361. hunits width();
  362. vunits vertical_width();
  363. void vertical_extent(vunits *, vunits *);
  364. int same(node *);
  365. const char *type();
  366. int force_tprint();
  367. int is_tag();
  368. };
  369. class dummy_node : public node {
  370. public:
  371. dummy_node(node *nd = 0) : node(nd) {}
  372. node *copy();
  373. int same(node *);
  374. const char *type();
  375. int force_tprint();
  376. int is_tag();
  377. hyphenation_type get_hyphenation_type();
  378. };
  379. class transparent_dummy_node : public node {
  380. public:
  381. transparent_dummy_node(node *nd = 0) : node(nd) {}
  382. node *copy();
  383. int same(node *);
  384. const char *type();
  385. int force_tprint();
  386. int is_tag();
  387. int ends_sentence();
  388. hyphenation_type get_hyphenation_type();
  389. };
  390. class zero_width_node : public node {
  391. node *n;
  392. public:
  393. zero_width_node(node *);
  394. zero_width_node(node *, statem *, int);
  395. ~zero_width_node();
  396. node *copy();
  397. void tprint(troff_output_file *);
  398. int same(node *);
  399. const char *type();
  400. int force_tprint();
  401. int is_tag();
  402. void append(node *);
  403. int character_type();
  404. void vertical_extent(vunits *, vunits *);
  405. };
  406. class left_italic_corrected_node : public node {
  407. node *n;
  408. hunits x;
  409. public:
  410. left_italic_corrected_node(node * = 0);
  411. left_italic_corrected_node(statem *, int, node * = 0);
  412. ~left_italic_corrected_node();
  413. void tprint(troff_output_file *);
  414. void ascii_print(ascii_output_file *);
  415. void asciify(macro *);
  416. node *copy();
  417. int same(node *);
  418. const char *type();
  419. int force_tprint();
  420. int is_tag();
  421. hunits width();
  422. node *last_char_node();
  423. void vertical_extent(vunits *, vunits *);
  424. int ends_sentence();
  425. int overlaps_horizontally();
  426. int overlaps_vertically();
  427. hyphenation_type get_hyphenation_type();
  428. tfont *get_tfont();
  429. int character_type();
  430. hunits skew();
  431. hunits italic_correction();
  432. hunits subscript_correction();
  433. hyphen_list *get_hyphen_list(hyphen_list *, int *);
  434. node *add_self(node *, hyphen_list **);
  435. node *merge_glyph_node(glyph_node *);
  436. };
  437. class overstrike_node : public node {
  438. node *list;
  439. hunits max_width;
  440. public:
  441. overstrike_node();
  442. overstrike_node(statem *, int);
  443. ~overstrike_node();
  444. node *copy();
  445. void tprint(troff_output_file *);
  446. void overstrike(node *); // add another node to be overstruck
  447. hunits width();
  448. int same(node *);
  449. const char *type();
  450. int force_tprint();
  451. int is_tag();
  452. node *add_self(node *, hyphen_list **);
  453. hyphen_list *get_hyphen_list(hyphen_list *, int *);
  454. hyphenation_type get_hyphenation_type();
  455. };
  456. class bracket_node : public node {
  457. node *list;
  458. hunits max_width;
  459. public:
  460. bracket_node();
  461. bracket_node(statem *, int);
  462. ~bracket_node();
  463. node *copy();
  464. void tprint(troff_output_file *);
  465. void bracket(node *); // add another node to be overstruck
  466. hunits width();
  467. int same(node *);
  468. const char *type();
  469. int force_tprint();
  470. int is_tag();
  471. };
  472. class special_node : public node {
  473. macro mac;
  474. tfont *tf;
  475. color *gcol;
  476. color *fcol;
  477. int no_init_string;
  478. void tprint_start(troff_output_file *);
  479. void tprint_char(troff_output_file *, unsigned char);
  480. void tprint_end(troff_output_file *);
  481. public:
  482. special_node(const macro &, int = 0);
  483. special_node(const macro &, tfont *, color *, color *, statem *, int,
  484. int = 0);
  485. node *copy();
  486. void tprint(troff_output_file *);
  487. int same(node *);
  488. const char *type();
  489. int force_tprint();
  490. int is_tag();
  491. int ends_sentence();
  492. tfont *get_tfont();
  493. };
  494. class suppress_node : public node {
  495. int is_on;
  496. int emit_limits; // must we issue the extent of the area written out?
  497. symbol filename;
  498. char position;
  499. int image_id;
  500. public:
  501. suppress_node(int, int);
  502. suppress_node(symbol, char, int);
  503. suppress_node(int, int, symbol, char, int, statem *, int);
  504. suppress_node(int, int, symbol, char, int);
  505. node *copy();
  506. void tprint(troff_output_file *);
  507. hunits width();
  508. int same(node *);
  509. const char *type();
  510. int force_tprint();
  511. int is_tag();
  512. private:
  513. void put(troff_output_file *, const char *);
  514. };
  515. class tag_node : public node {
  516. public:
  517. string tag_string;
  518. int delayed;
  519. tag_node();
  520. tag_node(string, int);
  521. tag_node(string, statem *, int, int);
  522. node *copy();
  523. void tprint(troff_output_file *);
  524. int same(node *);
  525. const char *type();
  526. int force_tprint();
  527. int is_tag();
  528. int ends_sentence();
  529. };
  530. struct hvpair {
  531. hunits h;
  532. vunits v;
  533. hvpair();
  534. };
  535. class draw_node : public node {
  536. int npoints;
  537. font_size sz;
  538. color *gcol;
  539. color *fcol;
  540. char code;
  541. hvpair *point;
  542. public:
  543. draw_node(char, hvpair *, int, font_size, color *, color *);
  544. draw_node(char, hvpair *, int, font_size, color *, color *, statem *, int);
  545. ~draw_node();
  546. hunits width();
  547. vunits vertical_width();
  548. node *copy();
  549. void tprint(troff_output_file *);
  550. int same(node *);
  551. const char *type();
  552. int force_tprint();
  553. int is_tag();
  554. };
  555. class charinfo;
  556. node *make_node(charinfo *, environment *);
  557. int character_exists(charinfo *, environment *);
  558. int same_node_list(node *, node *);
  559. node *reverse_node_list(node *);
  560. void delete_node_list(node *);
  561. node *copy_node_list(node *);
  562. int get_bold_fontno(int);
  563. inline hyphen_list::hyphen_list(unsigned char code, hyphen_list *p)
  564. : hyphen(0), breakable(0), hyphenation_code(code), next(p)
  565. {
  566. }
  567. extern void read_desc();
  568. extern int mount_font(int, symbol, symbol = NULL_SYMBOL);
  569. extern int check_font(symbol, symbol);
  570. extern int check_style(symbol);
  571. extern void mount_style(int, symbol);
  572. extern int is_good_fontno(int);
  573. extern int symbol_fontno(symbol);
  574. extern int next_available_font_position();
  575. extern void init_size_table(int *);
  576. extern int get_underline_fontno();
  577. class output_file {
  578. char make_g_plus_plus_shut_up;
  579. public:
  580. output_file();
  581. virtual ~output_file();
  582. virtual void trailer(vunits);
  583. virtual void flush() = 0;
  584. virtual void transparent_char(unsigned char) = 0;
  585. virtual void print_line(hunits x, vunits y, node *n,
  586. vunits before, vunits after, hunits width) = 0;
  587. virtual void begin_page(int pageno, vunits page_length) = 0;
  588. virtual void copy_file(hunits x, vunits y, const char *filename) = 0;
  589. virtual int is_printing() = 0;
  590. virtual void put_filename(const char *);
  591. virtual void on();
  592. virtual void off();
  593. #ifdef COLUMN
  594. virtual void vjustify(vunits, symbol);
  595. #endif /* COLUMN */
  596. mtsm state;
  597. };
  598. #ifndef POPEN_MISSING
  599. extern char *pipe_command;
  600. #endif
  601. extern output_file *the_output;
  602. extern void init_output();
  603. int in_output_page_list(int);
  604. class font_family {
  605. int *map;
  606. int map_size;
  607. public:
  608. const symbol nm;
  609. font_family(symbol);
  610. ~font_family();
  611. int make_definite(int);
  612. static void invalidate_fontno(int);
  613. };
  614. font_family *lookup_family(symbol);
  615. symbol get_font_name(int, environment *);
  616. symbol get_style_name(int);
  617. extern search_path include_search_path;