30dcdff75f26dfd604b67f94a1428d608d17ed1a
[pspp] / src / output / table-provider.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997, 1998, 1999, 2000, 2009, 2011, 2013, 2014, 2018 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef OUTPUT_TABLE_PROVIDER
18 #define OUTPUT_TABLE_PROVIDER 1
19
20 #include <stdint.h>
21 #include "output/table.h"
22
23 struct pool;
24 struct string;
25
26 enum table_halign table_halign_interpret (enum table_halign, bool numeric);
27
28 struct footnote
29   {
30     //size_t idx;
31     char *content;
32     char *marker;
33     struct table_area_style *style;
34   };
35
36 struct footnote *footnote_clone (const struct footnote *);
37 void footnote_destroy (struct footnote *);
38
39 /* A cell in a table. */
40 struct table_cell
41   {
42     /* Occupied table region.
43
44        d[TABLE_HORZ][0] is the leftmost column.
45        d[TABLE_HORZ][1] is the rightmost column, plus 1.
46        d[TABLE_VERT][0] is the top row.
47        d[TABLE_VERT][1] is the bottom row, plus 1.
48
49        For an ordinary cell:
50            d[TABLE_HORZ][1] == d[TABLE_HORZ][0] + 1
51        and d[TABLE_VERT][1] == d[TABLE_VERT][0] + 1
52
53        For a joined cell:
54           d[TABLE_HORZ][1] > d[TABLE_HORZ][0] + 1
55        or d[TABLE_VERT][1] > d[TABLE_VERT][0] + 1
56        or both. */
57     int d[TABLE_N_AXES][2];
58
59     unsigned int options;       /* TAB_*. */
60     char *text;                 /* A paragraph of text. */
61     char **subscripts;
62     size_t n_subscripts;
63     struct footnote **footnotes;
64     size_t n_footnotes;
65     struct table_area_style *style;
66   };
67
68 struct table_cell *table_cell_clone (const struct table_cell *);
69 void table_cell_destroy (struct table_cell *);
70
71 void table_cell_format_footnote_markers (const struct table_cell *,
72                                          struct string *);
73
74 /* Returns the number of columns that CELL spans.  This is 1 for an ordinary
75    cell and greater than one for a cell that joins multiple columns. */
76 static inline int
77 table_cell_colspan (const struct table_cell *cell)
78 {
79   return cell->d[TABLE_HORZ][1] - cell->d[TABLE_HORZ][0];
80 }
81
82 /* Returns the number of rows that CELL spans.  This is 1 for an ordinary cell
83    and greater than one for a cell that joins multiple rows. */
84 static inline int
85 table_cell_rowspan (const struct table_cell *cell)
86 {
87   return cell->d[TABLE_VERT][1] - cell->d[TABLE_VERT][0];
88 }
89
90 /* Returns true if CELL is a joined cell, that is, if it spans multiple rows
91    or columns.  Otherwise, returns false. */
92 static inline bool
93 table_cell_is_joined (const struct table_cell *cell)
94 {
95   return table_cell_colspan (cell) > 1 || table_cell_rowspan (cell) > 1;
96 }
97 \f
98 /* For use primarily by output drivers. */
99
100 void table_get_cell (const struct table *, int x, int y, struct table_cell *);
101 int table_get_rule (const struct table *, enum table_axis, int x, int y,
102                     struct cell_color *);
103 size_t table_collect_footnotes (const struct table_item *, struct footnote ***);
104
105 #endif /* output/table-provider.h */