1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2018 Free Software Foundation, Inc.
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.
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.
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/>. */
19 #include "output/page-setup.h"
24 #include "output/options.h"
26 #include "gl/xalloc.h"
29 page_paragraph_equals (const struct page_paragraph
*a
,
30 const struct page_paragraph
*b
)
32 return (!a
|| !b
? a
== b
33 : !a
->markup
|| !b
->markup
? a
->markup
== b
->markup
34 : !strcmp (a
->markup
, b
->markup
) && a
->halign
== b
->halign
);
38 page_heading_copy (struct page_heading
*dst
, const struct page_heading
*src
)
41 dst
->paragraphs
= xmalloc (dst
->n
* sizeof *dst
->paragraphs
);
42 for (size_t i
= 0; i
< dst
->n
; i
++)
44 dst
->paragraphs
[i
].markup
= xstrdup (src
->paragraphs
[i
].markup
);
45 dst
->paragraphs
[i
].halign
= src
->paragraphs
[i
].halign
;
50 page_heading_uninit (struct page_heading
*ph
)
55 for (size_t i
= 0; i
< ph
->n
; i
++)
56 free (ph
->paragraphs
[i
].markup
);
57 free (ph
->paragraphs
);
61 page_heading_equals (const struct page_heading
*a
,
62 const struct page_heading
*b
)
70 for (size_t i
= 0; i
< a
->n
; i
++)
71 if (!page_paragraph_equals (&a
->paragraphs
[i
], &b
->paragraphs
[i
]))
78 page_setup_clone (const struct page_setup
*old
)
80 struct page_setup
*new = xmalloc (sizeof *new);
82 for (int i
= 0; i
< 2; i
++)
83 page_heading_copy (&new->headings
[i
], &old
->headings
[i
]);
85 new->file_name
= xstrdup (new->file_name
);
90 page_setup_destroy (struct page_setup
*ps
)
94 for (int i
= 0; i
< 2; i
++)
95 page_heading_uninit (&ps
->headings
[i
]);
101 static struct driver_option
102 opt (struct driver_options
*options
, const char *key
, const char *default_value
)
104 return driver_option_get (options
, key
, default_value
);
108 page_setup_parse (struct driver_options
*o
)
110 struct page_setup
*ps
= xmalloc (sizeof *ps
);
111 *ps
= (struct page_setup
) PAGE_SETUP_INITIALIZER
;
113 enum { H
= TABLE_HORZ
, V
= TABLE_VERT
};
114 parse_paper_size (opt (o
, "paper-size", ""), &ps
->paper
[H
], &ps
->paper
[V
]);
116 ps
->margins
[H
][0] = parse_dimension (opt (o
, "left-margin", ".5in"));
117 ps
->margins
[H
][1] = parse_dimension (opt (o
, "right-margin", ".5in"));
118 ps
->margins
[V
][0] = parse_dimension (opt (o
, "top-margin", ".5in"));
119 ps
->margins
[V
][1] = parse_dimension (opt (o
, "bottom-margin", ".5in"));
121 ps
->object_spacing
= parse_dimension (opt (o
, "object-spacing", NULL
));
122 if (ps
->object_spacing
<= 0)
123 ps
->object_spacing
= 12.0 / 72.0;