home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / groff / troff / node.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-30  |  11.8 KB  |  509 lines

  1. // -*- C++ -*-
  2. /* Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  3.      Written by James Clark (jjc@jclark.uucp)
  4.  
  5. This file is part of groff.
  6.  
  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 1, or (at your option) any later
  10. version.
  11.  
  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
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License along
  18. with groff; see the file LICENSE.  If not, write to the Free Software
  19. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  20.  
  21.  
  22. struct hyphen_list {
  23.   unsigned char hyphen;
  24.   unsigned char breakable;
  25.   unsigned char hyphenation_code;
  26.   hyphen_list *next;
  27.   hyphen_list(unsigned char code, hyphen_list *p = 0);
  28. };
  29.  
  30. void hyphenate(hyphen_list *, unsigned);
  31.  
  32. enum hyphenation_type { HYPHEN_MIDDLE, HYPHEN_BOUNDARY, HYPHEN_INHIBIT };
  33.  
  34. class ascii_output_file;
  35.  
  36. struct breakpoint;
  37. struct vertical_size;
  38. struct charinfo;
  39.  
  40. class macro;
  41.  
  42. class troff_output_file;
  43. class tfont;
  44. class environment;
  45.  
  46. class glyph_node;
  47. class diverted_space_node;
  48. class token_node;
  49.  
  50. struct node {
  51.   node *next;
  52.   node();
  53.   node(node *n);
  54.   node *add_char(charinfo *c, environment *, hunits *widthp);
  55.  
  56.   virtual ~node();
  57.   virtual node *copy() = 0;
  58.   virtual hunits width();
  59.   virtual hunits subscript_correction();
  60.   virtual hunits italic_correction();
  61.   virtual hunits left_italic_correction();
  62.   virtual hunits skew();
  63.   virtual int nspaces();
  64.   virtual int merge_space(hunits);
  65.   virtual vunits vertical_width();
  66.   virtual node *last_char_node();
  67.   virtual void vertical_extent(vunits *min, vunits *max);
  68.   virtual int character_type();
  69.   virtual void set_vertical_size(vertical_size *);
  70.   virtual int ends_sentence();
  71.   virtual node *merge_self(node *);
  72.   virtual node *add_discretionary_hyphen();
  73.   virtual node *add_self(node *, hyphen_list **);
  74.   virtual hyphen_list *get_hyphen_list(hyphen_list *s = 0);
  75.   virtual void ascii_print(ascii_output_file *);
  76.   virtual void asciify(macro *);
  77.   virtual int discardable();
  78.   virtual void spread_space(int *, hunits *);
  79.   virtual void freeze_space();
  80.   virtual breakpoint *get_breakpoints(hunits width, int nspaces,
  81.                       breakpoint *rest = 0,
  82.                       int is_inner = 0);
  83.   virtual int nbreaks();
  84.   virtual void split(int, node **, node **);
  85.   virtual hyphenation_type get_hyphenation_type();
  86.   virtual int reread(int *);
  87.   virtual token_node *get_token_node();
  88.   virtual int overlaps_vertically();
  89.   virtual int overlaps_horizontally();
  90.   virtual units size();
  91.   virtual int interpret(macro *);
  92.  
  93.   virtual node *merge_glyph_node(glyph_node *);
  94.   virtual tfont *get_tfont();
  95.   virtual void tprint(troff_output_file *);
  96.   virtual void zero_width_tprint(troff_output_file *);
  97.  
  98.   node *add_italic_correction(hunits *);
  99.  
  100.   virtual int same(node *) = 0;
  101.   virtual const char *type() = 0;
  102. };
  103.  
  104. inline node::node() : next(0)
  105. {
  106. }
  107.  
  108. inline node::node(node *n) : next(n)
  109. {
  110. }
  111.  
  112. inline node::~node()
  113. {
  114. }
  115.  
  116. // 0 means it doesn't, 1 means it does, 2 means it's transparent
  117.  
  118. int node_list_ends_sentence(node *);
  119.  
  120. struct breakpoint {
  121.   breakpoint *next;
  122.   hunits width;
  123.   int nspaces;
  124.   node *nd;
  125.   int index;
  126.   char hyphenated;
  127. };
  128.  
  129. class line_start_node : public node {
  130. public:
  131.   line_start_node() {}
  132.   node *copy() { return new line_start_node; }
  133.   int same(node *);
  134.   const char *type();
  135.   void asciify(macro *);
  136. };
  137.  
  138. class space_node : public node {
  139. private:
  140. #if 0
  141.   enum { BLOCK = 1024 };
  142.   static space_node *free_list;
  143.   void operator delete(void *);
  144. #endif
  145. protected:
  146.   hunits n;
  147.   char set;
  148.   space_node(hunits, int, node * = 0);
  149. public:
  150.   space_node(hunits d, node *p = 0);
  151. #if 0
  152.   ~space_node();
  153.   void *operator new(size_t);
  154. #endif
  155.   node *copy();
  156.   int nspaces();
  157.   hunits width();
  158.   int discardable();
  159.   int merge_space(hunits);
  160.   void freeze_space();
  161.   void spread_space(int*, hunits*);
  162.   void tprint(troff_output_file *);
  163.   breakpoint *get_breakpoints(hunits width, int nspaces, breakpoint *rest = 0,
  164.                   int is_inner = 0);
  165.   int nbreaks();
  166.   void split(int, node **, node **);
  167.   void ascii_print(ascii_output_file *);
  168.   int same(node *);
  169.   const char *type();
  170. };
  171.  
  172. class word_space_node : public space_node {
  173.   word_space_node(hunits, int, node * = 0);
  174. public:
  175.   word_space_node(hunits, node * = 0);
  176.   node *copy();
  177.   void tprint(troff_output_file *);
  178.   int same(node *);
  179.   const char *type();
  180. };
  181.  
  182.   
  183. class diverted_space_node : public node {
  184. public:
  185.   vunits n;
  186.   diverted_space_node(vunits d, node *p = 0);
  187.   node *copy();
  188.   int reread(int *);
  189.   int same(node *);
  190.   const char *type();
  191. };
  192.  
  193. class diverted_copy_file_node : public node {
  194.   symbol filename;
  195. public:
  196.   vunits n;
  197.   diverted_copy_file_node(symbol s, node *p = 0);
  198.   node *copy();
  199.   int reread(int *);
  200.   int same(node *);
  201.   const char *type();
  202. };
  203.  
  204. class extra_size_node : public node {
  205.   vunits n;
  206.  public:
  207.   extra_size_node(vunits i) : n(i) {}
  208.   void set_vertical_size(vertical_size *);
  209.   node *copy();
  210.   int same(node *);
  211.   const char *type();
  212. };
  213.  
  214. class vertical_size_node : public node {
  215.   vunits n;
  216.  public:
  217.   vertical_size_node(vunits i) : n(i) {}
  218.   void set_vertical_size(vertical_size *);
  219.   void asciify(macro *);
  220.   node *copy();
  221.   int same(node *);
  222.   const char *type();
  223. };
  224.  
  225. class hmotion_node : public node {
  226. protected:
  227.   hunits n;
  228. public:
  229.   hmotion_node(hunits i, node *next = 0) : node(next), n(i) {}
  230.   node *copy();
  231.   void tprint(troff_output_file *);
  232.   hunits width();
  233.   void ascii_print(ascii_output_file *);
  234.   int same(node *);
  235.   const char *type();
  236. };
  237.  
  238. class space_char_hmotion_node : public hmotion_node {
  239. public:
  240.   space_char_hmotion_node(hunits i, node *next = 0);
  241.   node *copy();
  242.   void ascii_print(ascii_output_file *);
  243.   void asciify(macro *);
  244.   int same(node *);
  245.   const char *type();
  246. };
  247.  
  248. class vmotion_node : public node {
  249.   vunits n;
  250.  public:
  251.   vmotion_node(vunits i) : n(i) {}
  252.   void tprint(troff_output_file *);
  253.   node *copy();
  254.   vunits vertical_width();
  255.   int same(node *);
  256.   const char *type();
  257. };
  258.  
  259.  
  260. class hline_node : public node {
  261.   hunits x;
  262.   node *n;
  263.  public:
  264.   hline_node(hunits i, node *c, node *next = 0) : node(next), x(i), n(c) {}
  265.   ~hline_node();
  266.   node *copy();
  267.   hunits width();
  268.   void tprint(troff_output_file *);
  269.   int same(node *);
  270.   const char *type();
  271. };
  272.  
  273. class vline_node : public node {
  274.   vunits x;
  275.   node *n;
  276.  public:
  277.   vline_node(vunits  i, node *c, node *next= 0) : node(next), x(i), n(c) {}
  278.   ~vline_node();
  279.   node *copy();
  280.   void tprint(troff_output_file *);
  281.   hunits width();
  282.   vunits vertical_width();
  283.   void vertical_extent(vunits *, vunits *);
  284.   int same(node *);
  285.   const char *type();
  286. };
  287.  
  288.  
  289. class dummy_node : public node {
  290.  public:
  291.   dummy_node(node *nd = 0) : node(nd) {}
  292.   node *copy();
  293.   int same(node *);
  294.   const char *type();
  295.   hyphenation_type get_hyphenation_type();
  296. };
  297.  
  298. class transparent_dummy_node : public node {
  299. public:
  300.   transparent_dummy_node() {}
  301.   node *copy();
  302.   int same(node *);
  303.   const char *type();
  304.   int ends_sentence();
  305.   hyphenation_type get_hyphenation_type();
  306. };
  307.  
  308. class zero_width_node : public node {
  309.   node *n;
  310.  public:
  311.   zero_width_node(node *gn);
  312.   ~zero_width_node();
  313.   node *copy();
  314.   void tprint(troff_output_file *);
  315.   int same(node *);
  316.   const char *type();
  317.   void append(node *);
  318.   int character_type();
  319.   void vertical_extent(vunits *min, vunits *max);
  320. };
  321.  
  322. class left_italic_corrected_node : public node {
  323.   node *n;
  324.   hunits x;
  325. public:
  326.   left_italic_corrected_node(node * = 0);
  327.   ~left_italic_corrected_node();
  328.   void tprint(troff_output_file *);
  329.   void ascii_print(ascii_output_file *);
  330.   void asciify(macro *);
  331.   node *copy();
  332.   int same(node *);
  333.   const char *type();
  334.   hunits width();
  335.   node *last_char_node();
  336.   void vertical_extent(vunits *, vunits *);
  337.   int ends_sentence();
  338.   int overlaps_horizontally();
  339.   int overlaps_vertically();
  340.   hyphenation_type get_hyphenation_type();
  341.   tfont *get_tfont();
  342.   int character_type();
  343.   hunits skew();
  344.   hunits italic_correction();
  345.   hunits subscript_correction();
  346.   hyphen_list *get_hyphen_list(hyphen_list *ss = 0);
  347.   node *add_self(node *, hyphen_list **);
  348.   node *merge_glyph_node(glyph_node *);
  349. };
  350.  
  351. class overstrike_node : public node {
  352.   node *list;
  353.   hunits max_width;
  354. public:
  355.   overstrike_node();
  356.   ~overstrike_node();
  357.   node *copy();
  358.   void tprint(troff_output_file *);
  359.   void overstrike(node *);    // add another node to be overstruck
  360.   hunits width();
  361.   int same(node *);
  362.   const char *type();
  363. };
  364.  
  365. class bracket_node : public node {
  366.   node *list;
  367.   hunits max_width;
  368. public:
  369.   bracket_node();
  370.   ~bracket_node();
  371.   node *copy();
  372.   void tprint(troff_output_file *);
  373.   void bracket(node *);    // add another node to be overstruck
  374.   hunits width();
  375.   int same(node *);
  376.   const char *type();
  377. };
  378.  
  379. class special_node : public node {
  380.   macro mac;
  381.   void tprint_start(troff_output_file *);
  382.   void tprint_char(troff_output_file *, unsigned char);
  383.   void tprint_end(troff_output_file *);
  384. public:
  385.   special_node(const macro &);
  386.   node *copy();
  387.   void tprint(troff_output_file *);
  388.   int same(node *);
  389.   const char *type();
  390. };
  391.  
  392. class charinfo;
  393.  
  394. class composite_node : public node {
  395.   charinfo *ci;
  396.   node *n;
  397.   font_size sz;
  398. public:
  399.   composite_node(node *, charinfo *, font_size, node * = 0);
  400.   ~composite_node();
  401.   node *copy();
  402.   hunits width();
  403.   node *last_char_node();
  404.   units size();
  405.   void tprint(troff_output_file *);
  406.   hyphenation_type get_hyphenation_type();
  407.   int overlaps_horizontally();
  408.   int overlaps_vertically();
  409.   void ascii_print(ascii_output_file *);
  410.   void asciify(macro *);
  411.   hyphen_list *get_hyphen_list(hyphen_list *tail);
  412.   node *add_self(node *, hyphen_list **);
  413.   tfont *get_tfont();
  414.   int same(node *);
  415.   const char *type();
  416.   void vertical_extent(vunits *, vunits *);
  417.   vunits vertical_width();
  418. };
  419.  
  420. struct hvpair {
  421.   hunits h;
  422.   vunits v;
  423.  
  424.   hvpair();
  425. };
  426.  
  427. class draw_node : public node {
  428.   int npoints;
  429.   font_size sz;
  430.   char code;
  431.   hvpair *point;
  432. public:
  433.   draw_node(char, hvpair *, int, font_size);
  434.   ~draw_node();
  435.   hunits width();
  436.   vunits vertical_width();
  437.   node *copy();
  438.   void tprint(troff_output_file *);
  439.   int same(node *);
  440.   const char *type();
  441. };
  442.  
  443. node *make_node(charinfo *ci, environment *);
  444. int character_exists(charinfo *, environment *);
  445.  
  446. int same_node_list(node *n1, node *n2);
  447. node *reverse_node_list(node *n);
  448. void delete_node_list(node *);
  449. node *copy_node_list(node *);
  450.  
  451. hunits env_digit_width(environment *);
  452. hunits env_space_width(environment *);
  453. hunits env_narrow_space_width(environment *);
  454. hunits env_half_narrow_space_width(environment *);
  455. int get_bold_fontno(int f);
  456.  
  457. inline hyphen_list::hyphen_list(unsigned char code, hyphen_list *p)
  458. : hyphenation_code(code), next(p), hyphen(0), breakable(0)
  459. {
  460. }
  461.  
  462. extern void read_desc();
  463. extern int mount_font(int n, symbol, symbol = NULL_SYMBOL);
  464. extern void mount_style(int n, symbol);
  465. extern int is_good_fontno(int n);
  466. extern int symbol_fontno(symbol);
  467. extern int next_available_font_position();
  468. extern void init_size_table(int *);
  469. extern int get_underline_fontno();
  470.  
  471. class output_file {
  472.   char make_g_plus_plus_shut_up;
  473. public:
  474.   output_file();
  475.   virtual ~output_file();
  476.   virtual void flush() = 0;
  477.   virtual void transparent_char(unsigned char) = 0;
  478.   virtual void print_line(hunits x, vunits y, node *n,
  479.               vunits before, vunits after) = 0;
  480.   virtual void begin_page(int pageno, vunits page_length) = 0;
  481.   virtual void copy_file(hunits x, vunits y, const char *filename) = 0;
  482.   virtual int is_printing() = 0;
  483. #ifdef COLUMN
  484.   virtual void vjustify(vunits, symbol);
  485. #endif /* COLUMN */
  486. };
  487.  
  488. extern char *pipe_command;
  489.  
  490. extern output_file *the_output;
  491. extern void init_output();
  492. int in_output_page_list(int n);
  493.  
  494. static void invalidate_fontno(int);
  495.  
  496. class font_family {
  497.   int *map;
  498.   int map_size;
  499. public:
  500.   const symbol nm;
  501.  
  502.   font_family(symbol);
  503.   ~font_family();
  504.   make_definite(int);
  505.   friend void invalidate_fontno(int);
  506. };
  507.  
  508. font_family *lookup_family(symbol);
  509.