1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010, 2011, 2018 Free Sonftware 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_PAGE_SETUP_ITEM_H
18 #define OUTPUT_PAGE_SETUP_ITEM_H 1
19 
20 /* Page setup items.
21 
22    A page setup item configures the paper size, margins, header and footer,
23    and other attributes used for printing. */
24 
25 #include <stdbool.h>
26 #include "output/output-item.h"
27 #include "table.h"
28 
29 enum page_orientation
30   {
31     PAGE_PORTRAIT,
32     PAGE_LANDSCAPE
33   };
34 
35 enum page_chart_size
36   {
37     PAGE_CHART_AS_IS,
38     PAGE_CHART_FULL_HEIGHT,
39     PAGE_CHART_HALF_HEIGHT,
40     PAGE_CHART_QUARTER_HEIGHT,
41   };
42 
43 struct page_paragraph
44   {
45     char *markup;
46     enum table_halign halign;
47   };
48 
49 struct page_heading
50   {
51     struct page_paragraph *paragraphs;
52     size_t n;
53   };
54 
55 void page_heading_copy (struct page_heading *, const struct page_heading *);
56 void page_heading_uninit (struct page_heading *);
57 
58 struct page_setup
59   {
60     int initial_page_number;
61     double paper[TABLE_N_AXES];         /* Paper size in inches. */
62     double margins[TABLE_N_AXES][2];    /* In inches. */
63     enum page_orientation orientation;
64     double object_spacing;      /* Space between objects, in inches. */
65     enum page_chart_size chart_size;
66     struct page_heading headings[2]; /* Header and footer. */
67     char *file_name;
68   };
69 
70 #define PAGE_SETUP_INITIALIZER                                          \
71     {                                                                   \
72         .initial_page_number = 1,                                       \
73         .paper = { [TABLE_HORZ] = 8.5, [TABLE_VERT] = 11.0 },           \
74         .margins = { { 0.5, 0.5 }, { 0.5, 0.5 } },                      \
75         .orientation = PAGE_PORTRAIT,                                   \
76         .object_spacing = 12.0 / 72.0,                                  \
77         .chart_size = PAGE_CHART_AS_IS,                                 \
78     }
79 
80 struct page_setup *page_setup_clone (const struct page_setup *);
81 void page_setup_destroy (struct page_setup *);
82 
83 /* A page setup item. */
84 struct page_setup_item
85   {
86     struct output_item output_item;
87     struct page_setup *page_setup;
88   };
89 
90 struct page_setup_item *page_setup_item_create (const struct page_setup *);
91 
92 /* This boilerplate for page_setup_item, a subclass of output_item, was
93    autogenerated by mk-class-boilerplate. */
94 
95 #include <assert.h>
96 #include "libpspp/cast.h"
97 
98 extern const struct output_item_class page_setup_item_class;
99 
100 /* Returns true if SUPER is a page_setup_item, otherwise false. */
101 static inline bool
is_page_setup_item(const struct output_item * super)102 is_page_setup_item (const struct output_item *super)
103 {
104   return super->class == &page_setup_item_class;
105 }
106 
107 /* Returns SUPER converted to page_setup_item.  SUPER must be a page_setup_item, as
108    reported by is_page_setup_item. */
109 static inline struct page_setup_item *
to_page_setup_item(const struct output_item * super)110 to_page_setup_item (const struct output_item *super)
111 {
112   assert (is_page_setup_item (super));
113   return UP_CAST (super, struct page_setup_item, output_item);
114 }
115 
116 /* Returns INSTANCE converted to output_item. */
117 static inline struct output_item *
page_setup_item_super(const struct page_setup_item * instance)118 page_setup_item_super (const struct page_setup_item *instance)
119 {
120   return CONST_CAST (struct output_item *, &instance->output_item);
121 }
122 
123 /* Increments INSTANCE's reference count and returns INSTANCE. */
124 static inline struct page_setup_item *
page_setup_item_ref(const struct page_setup_item * instance)125 page_setup_item_ref (const struct page_setup_item *instance)
126 {
127   return to_page_setup_item (output_item_ref (&instance->output_item));
128 }
129 
130 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
131    the reference count is now zero. */
132 static inline void
page_setup_item_unref(struct page_setup_item * instance)133 page_setup_item_unref (struct page_setup_item *instance)
134 {
135   output_item_unref (&instance->output_item);
136 }
137 
138 /* Returns true if INSTANCE's reference count is greater than 1,
139    false otherwise. */
140 static inline bool
page_setup_item_is_shared(const struct page_setup_item * instance)141 page_setup_item_is_shared (const struct page_setup_item *instance)
142 {
143   return output_item_is_shared (&instance->output_item);
144 }
145 
146 void page_setup_item_submit (struct page_setup_item *);
147 
148 #endif /* output/page-setup-item.h */
149