175584Sru// -*- C++ -*-
2151497Sru/* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005
3151497Sru * Free Software Foundation, Inc.
475584Sru *
5114402Sru *  Gaius Mulley (gaius@glam.ac.uk) wrote html-text.h
675584Sru *
775584Sru *  html-text.h
875584Sru *
975584Sru *  provides a state machine interface which generates html text.
1075584Sru */
1175584Sru
1275584Sru/*
1375584SruThis file is part of groff.
1475584Sru
1575584Srugroff is free software; you can redistribute it and/or modify it under
1675584Sruthe terms of the GNU General Public License as published by the Free
1775584SruSoftware Foundation; either version 2, or (at your option) any later
1875584Sruversion.
1975584Sru
2075584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY
2175584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or
2275584SruFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2375584Srufor more details.
2475584Sru
2575584SruYou should have received a copy of the GNU General Public License along
2675584Sruwith groff; see the file COPYING.  If not, write to the Free Software
27151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
2875584Sru
2975584Sru#include "html.h"
30104862Sru#include "html-table.h"
3175584Sru
32151497Sru#define STYLE_VERTICAL_SPACE "1em"
33151497Sru
3475584Sru/*
3575584Sru *  html tags
3675584Sru */
3775584Sru
3875584Srutypedef enum {I_TAG, B_TAG, P_TAG, SUB_TAG, SUP_TAG, TT_TAG,
39104862Sru	      PRE_TAG, SMALL_TAG, BIG_TAG, BREAK_TAG,
40104862Sru	      COLOR_TAG} HTML_TAG;
4175584Sru
4275584Srutypedef struct tag_definition {
4375584Sru  HTML_TAG        type;
44104862Sru  void           *arg1;
4575584Sru  int             text_emitted;
46104862Sru  color           col;
47104862Sru  html_indent    *indent;
4875584Sru  tag_definition *next;
4975584Sru} tag_definition ;
5075584Sru
5175584Sru/*
5275584Sru *  the state of the current paragraph.
53114402Sru *  It allows post-html.cpp to request font changes, paragraph start/end
5475584Sru *  and emits balanced tags with a small amount of peephole optimization.
5575584Sru */
5675584Sru
5775584Sruclass html_text {
5875584Srupublic:
59104862Sru         html_text         (simple_output *op);
60104862Sru        ~html_text         (void);
61104862Sru  void   flush_text        (void);
62104862Sru  void   do_emittext       (const char *s, int length);
63104862Sru  void   do_italic         (void);
64104862Sru  void   do_bold           (void);
65104862Sru  void   do_roman          (void);
66104862Sru  void   do_tt             (void);
67104862Sru  void   do_pre            (void);
68104862Sru  void   do_small          (void);
69104862Sru  void   do_big            (void);
70151497Sru  void   do_para           (const char *arg, int space); // used for no indentation
71104862Sru  void   do_para           (simple_output *op, const char *arg1,
72151497Sru			    int indentation, int pageoffset, int linelength,
73151497Sru                            int space);
74104862Sru  void   do_sup            (void);
75104862Sru  void   do_sub            (void);
76104862Sru  void   do_space          (void);
77104862Sru  void   do_break          (void);
78104862Sru  void   do_newline        (void);
79104862Sru  void   do_table          (const char *arg);
80104862Sru  void   done_bold         (void);
81104862Sru  void   done_italic       (void);
82104862Sru  char  *done_para         (void);
83104862Sru  void   done_sup          (void);
84104862Sru  void   done_sub          (void);
85104862Sru  void   done_tt           (void);
86104862Sru  void   done_pre          (void);
87104862Sru  void   done_small        (void);
88104862Sru  void   done_big          (void);
89104862Sru  void   do_color          (color *c);
90104862Sru  void   done_color        (void);
91104862Sru  int    emitted_text      (void);
92104862Sru  int    ever_emitted_text (void);
93104862Sru  int    starts_with_space (void);
94151497Sru  int    retrieve_para_space (void);
95104862Sru  void   emit_space        (void);
96104862Sru  int    is_in_pre         (void);
97151497Sru  int    uses_indent       (void);
98104862Sru  void   remove_tag        (HTML_TAG tag);
99104862Sru  void   remove_sub_sup    (void);
100104862Sru  void   remove_para_align (void);
101151497Sru  void   remove_para_space (void);
102151497Sru  char  *get_alignment     (void);
10375584Sru
10475584Sruprivate:
10575584Sru  tag_definition   *stackptr;    /* the current paragraph state */
10675584Sru  tag_definition   *lastptr;     /* the end of the stack        */
10775584Sru  simple_output    *out;
108104862Sru  int               space_emitted;   /* just emitted a space?   */
109104862Sru  int               current_indentation;   /* current .in value */
110104862Sru  int               pageoffset;            /* .po value         */
111104862Sru  int               linelength;          /* current line length */
112104862Sru  int               blank_para;   /* have we ever written text? */
113104862Sru  int               start_space;  /* does para start with a .sp */
114104862Sru  html_indent      *indent;                 /* our indent class */
11575584Sru
116104862Sru  int    is_present          (HTML_TAG t);
117104862Sru  void   end_tag             (tag_definition *t);
118104862Sru  void   start_tag           (tag_definition *t);
119151497Sru  void   do_para             (const char *arg, html_indent *in, int space);
120104862Sru  void   push_para           (HTML_TAG t);
121104862Sru  void   push_para           (HTML_TAG t, void *arg, html_indent *in);
122104862Sru  void   push_para           (color *c);
123104862Sru  void   do_push             (tag_definition *p);
124104862Sru  char  *shutdown            (HTML_TAG t);
125104862Sru  void   check_emit_text     (tag_definition *t);
126104862Sru  int    remove_break        (void);
127151497Sru  void   issue_tag           (const char *tagname, const char *arg, int space=2);
128104862Sru  void   issue_color_begin   (color *c);
129104862Sru  void   remove_def          (tag_definition *t);
130104862Sru  html_indent *remove_indent (HTML_TAG tag);
131104862Sru  void   dump_stack_element  (tag_definition *p);
132104862Sru  void   dump_stack          (void);
13375584Sru};
134