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