Imported Upstream version 1.23.0
[platform/upstream/groff.git] / src / devices / grohtml / html-text.h
1 // -*- C++ -*-
2 /* Copyright (C) 2000-2020 Free Software Foundation, Inc.
3  *
4  *  Gaius Mulley (gaius@glam.ac.uk) wrote html-text.h
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 3 of the License, or
17 (at your option) any later 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
25 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
26
27 #include "html.h"
28 #include "html-table.h"
29
30 #define STYLE_VERTICAL_SPACE "1em"
31
32 /*
33  *  supported html dialects.
34  */
35
36 typedef enum {xhtml, html4} html_dialect;
37
38 /*
39  *  html tags
40  */
41
42 typedef enum {I_TAG, B_TAG, P_TAG, SUB_TAG, SUP_TAG, TT_TAG,
43               PRE_TAG, SMALL_TAG, BIG_TAG, BREAK_TAG,
44               COLOR_TAG} HTML_TAG;
45
46 typedef struct tag_definition {
47   HTML_TAG        type;
48   void           *arg1;
49   int             text_emitted;
50   color           col;
51   html_indent    *indent;
52   tag_definition *next;
53 } tag_definition ;
54
55 /*
56  *  the state of the current paragraph.
57  *  It allows post-html.cpp to request font changes, paragraph start/end
58  *  and emits balanced tags with a small amount of peephole optimization.
59  */
60
61 class html_text {
62 public:
63          html_text         (simple_output *op, html_dialect d);
64         ~html_text         (void);
65   void   flush_text        (void);
66   void   do_emittext       (const char *s, int length);
67   void   do_italic         (void);
68   void   do_bold           (void);
69   void   do_roman          (void);
70   void   do_tt             (void);
71   void   do_pre            (void);
72   void   do_small          (void);
73   void   do_big            (void);
74   void   do_para           (const char *arg, int space); // used for no indentation
75   void   do_para           (simple_output *op, const char *arg1,
76                             int indentation, int pageoffset, int linelength,
77                             int space);
78   void   do_sup            (void);
79   void   do_sub            (void);
80   void   do_space          (void);
81   void   do_break          (void);
82   void   do_newline        (void);
83   void   do_table          (const char *arg);
84   void   done_bold         (void);
85   void   done_italic       (void);
86   char  *done_para         (void);
87   void   done_sup          (void);
88   void   done_sub          (void);
89   void   done_tt           (void);
90   void   done_pre          (void);
91   void   done_small        (void);
92   void   done_big          (void);
93   void   do_color          (color *c);
94   void   done_color        (void);
95   int    emitted_text      (void);
96   int    ever_emitted_text (void);
97   int    starts_with_space (void);
98   int    retrieve_para_space (void);
99   void   emit_space        (void);
100   int    is_in_pre         (void);
101   int    uses_indent       (void);
102   void   remove_tag        (HTML_TAG tag);
103   void   remove_sub_sup    (void);
104   void   remove_para_align (void);
105   void   remove_para_space (void);
106   char  *get_alignment     (void);
107
108 private:
109   tag_definition   *stackptr;    /* the current paragraph state */
110   tag_definition   *lastptr;     /* the end of the stack        */
111   simple_output    *out;
112   html_dialect      dialect;     /* which dialect of html?      */
113   int               space_emitted;   /* just emitted a space?   */
114   int               current_indentation;   /* current .in value */
115   int               pageoffset;            /* .po value         */
116   int               linelength;          /* current line length */
117   int               blank_para;   /* have we ever written text? */
118   int               start_space;  /* does para start with a .sp */
119   html_indent      *indent;                 /* our indent class */
120
121   int    is_present          (HTML_TAG t);
122   void   end_tag             (tag_definition *t);
123   void   start_tag           (tag_definition *t);
124   void   do_para             (const char *arg, html_indent *in, int space);
125   void   push_para           (HTML_TAG t);
126   void   push_para           (HTML_TAG t, void *arg, html_indent *in);
127   void   push_para           (color *c);
128   void   do_push             (tag_definition *p);
129   char  *shutdown            (HTML_TAG t);
130   void   check_emit_text     (tag_definition *t);
131   int    remove_break        (void);
132   void   issue_tag           (const char *tagname, const char *arg, int space=2);
133   void   issue_color_begin   (color *c);
134   void   remove_def          (tag_definition *t);
135   html_indent *remove_indent (HTML_TAG tag);
136   void   dump_stack_element  (tag_definition *p);
137   void   dump_stack          (void);
138 };