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