Merge from vendor branch GROFF:
[dragonfly.git] / contrib / groff / src / devices / grohtml / html-text.h
1 // -*- C++ -*-
2 /* Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
3  *
4  *  Gaius Mulley (gaius@glam.ac.uk) wrote html-text.cc
5  *
6  *  html-text.h
7  *
8  *  provides a state machine interface which generates html text.
9  */
10
11 /*
12 This file is part of groff.
13
14 groff is free software; you can redistribute it and/or modify it under
15 the terms of the GNU General Public License as published by the Free
16 Software Foundation; either version 2, or (at your option) any later
17 version.
18
19 groff is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License along
25 with groff; see the file COPYING.  If not, write to the Free Software
26 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27
28 #include "html.h"
29 #include "html-table.h"
30
31 /*
32  *  html tags
33  */
34
35 typedef enum {I_TAG, B_TAG, P_TAG, SUB_TAG, SUP_TAG, TT_TAG,
36               PRE_TAG, SMALL_TAG, BIG_TAG, BREAK_TAG,
37               COLOR_TAG} HTML_TAG;
38
39 typedef struct tag_definition {
40   HTML_TAG        type;
41   void           *arg1;
42   int             text_emitted;
43   color           col;
44   html_indent    *indent;
45   tag_definition *next;
46 } tag_definition ;
47
48 /*
49  *  the state of the current paragraph.
50  *  It allows post-html.cc to request font changes, paragraph start/end
51  *  and emits balanced tags with a small amount of peephole optimization.
52  */
53
54 class html_text {
55 public:
56          html_text         (simple_output *op);
57         ~html_text         (void);
58   void   flush_text        (void);
59   void   do_emittext       (const char *s, int length);
60   void   do_italic         (void);
61   void   do_bold           (void);
62   void   do_roman          (void);
63   void   do_tt             (void);
64   void   do_pre            (void);
65   void   do_small          (void);
66   void   do_big            (void);
67   void   do_para           (const char *arg);  // used for no indentation
68   void   do_para           (simple_output *op, const char *arg1,
69                             int indentation, int pageoffset, int linelength);
70   void   do_sup            (void);
71   void   do_sub            (void);
72   void   do_space          (void);
73   void   do_break          (void);
74   void   do_newline        (void);
75   void   do_table          (const char *arg);
76   void   done_bold         (void);
77   void   done_italic       (void);
78   char  *done_para         (void);
79   void   done_sup          (void);
80   void   done_sub          (void);
81   void   done_tt           (void);
82   void   done_pre          (void);
83   void   done_small        (void);
84   void   done_big          (void);
85   void   do_color          (color *c);
86   void   done_color        (void);
87   int    emitted_text      (void);
88   int    ever_emitted_text (void);
89   int    starts_with_space (void);
90   void   emit_space        (void);
91   int    is_in_pre         (void);
92   void   remove_tag        (HTML_TAG tag);
93   void   remove_sub_sup    (void);
94   void   remove_para_align (void);
95
96 private:
97   tag_definition   *stackptr;    /* the current paragraph state */
98   tag_definition   *lastptr;     /* the end of the stack        */
99   simple_output    *out;
100   int               space_emitted;   /* just emitted a space?   */
101   int               current_indentation;   /* current .in value */
102   int               pageoffset;            /* .po value         */
103   int               linelength;          /* current line length */
104   int               blank_para;   /* have we ever written text? */
105   int               start_space;  /* does para start with a .sp */
106   html_indent      *indent;                 /* our indent class */
107
108   int    is_present          (HTML_TAG t);
109   void   end_tag             (tag_definition *t);
110   void   start_tag           (tag_definition *t);
111   void   do_para             (const char *arg, html_indent *in);
112   void   push_para           (HTML_TAG t);
113   void   push_para           (HTML_TAG t, void *arg, html_indent *in);
114   void   push_para           (color *c);
115   void   do_push             (tag_definition *p);
116   char  *shutdown            (HTML_TAG t);
117   void   check_emit_text     (tag_definition *t);
118   int    remove_break        (void);
119   void   issue_tag           (char *tagname, char *arg);
120   void   issue_color_begin   (color *c);
121   void   remove_def          (tag_definition *t);
122   html_indent *remove_indent (HTML_TAG tag);
123   void   dump_stack_element  (tag_definition *p);
124   void   dump_stack          (void);
125 };