cea73bdfa396ea6fe51e005610da3fce6287b480
[platform/upstream/groff.git] / src / devices / grohtml / html-table.h
1 // -*- C++ -*-
2 /* Copyright (C) 2002-2018  Free Software Foundation, Inc.
3  *
4  *  Gaius Mulley (gaius@glam.ac.uk) wrote html-table.h
5  *
6  *  html-table.h
7  *
8  *  provides the methods necessary to handle indentation and tab
9  *  positions using html tables.
10  */
11
12 /*
13 This file is part of groff.
14
15 groff is free software; you can redistribute it and/or modify it under
16 the terms of the GNU General Public License as published by the Free
17 Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 groff is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27
28 #include "html.h"
29
30 #if !defined(HTML_TABLE_H)
31 #define HTML_TABLE_H
32
33 typedef struct tab_position {
34   char alignment;
35   int  position;
36   struct tab_position *next;
37 } tab_position;
38
39
40 class tabs {
41 public:
42          tabs         ();
43         ~tabs         ();
44   void  clear         (void);
45   int   compatible    (const char *s);
46   void  init          (const char *s);
47   void  check_init    (const char *s);
48   int   find_tab      (int pos);
49   int   get_tab_pos   (int n);
50   char  get_tab_align (int n);
51   void  dump_tabs     (void);
52
53 private:
54   void  delete_list (void);
55   tab_position *tab;
56 };
57
58 /*
59  *  define a column
60  */
61
62 typedef struct cols {
63   int          left, right;
64   int          no;
65   char         alignment;
66   struct cols *next;
67 } cols;
68
69 class html_table {
70 public:
71       html_table          (simple_output *op, int linelen);
72      ~html_table          (void);
73   int   add_column        (int coln, int hstart, int hend, char align);
74   cols *get_column        (int coln);
75   int   insert_column     (int coln, int hstart, int hend, char align);
76   int   modify_column     (cols *c, int hstart, int hend, char align);
77   int   find_tab_column   (int pos);
78   int   find_column       (int pos);
79   int   get_tab_pos       (int n);
80   char  get_tab_align     (int n);
81   void  set_linelength    (int linelen);
82   int   no_columns        (void);
83   int   no_gaps           (void);
84   int   is_gap            (cols *c);
85   void  dump_table        (void);
86   void  emit_table_header (int space);
87   void  emit_col          (int n);
88   void  emit_new_row      (void);
89   void  emit_finish_table (void);
90   int   get_right         (cols *c);
91   void  add_indent        (int indent);
92   void  finish_row        (void);
93   int   get_effective_linelength (void);
94   void  set_space         (int space);
95   void  emit_colspan      (void);
96   void  emit_td           (int percentage, const char *s = ">");
97
98   tabs          *tab_stops;    /* tab stop positions */
99   simple_output *out;
100 private:
101   cols          *columns;      /* column entries */
102   int            linelength;
103   cols          *last_col;     /* last column started */
104   int            start_space;  /* have we seen a `.sp' tag? */
105
106   void  remove_cols (cols *c);
107 };
108
109 /*
110  *  the indentation wrapper.
111  *  Builds an indentation from a html-table.
112  *  This table is only emitted if the paragraph is emitted.
113  */
114
115 class html_indent {
116 public:
117   html_indent  (simple_output *op, int ind, int pageoffset, int linelength);
118   ~html_indent (void);
119   void begin   (int space);   // called if we need to use the indent
120   void get_reg (int *ind, int *pageoffset, int *linelength);
121
122   // the indent is shutdown when it is deleted
123
124 private:
125   void end    (void);
126   int         is_used;
127   int         pg;        // values of the registers as passed via initialization
128   int         ll;
129   int         in;
130   html_table *table;
131 };
132
133 #endif