Add support for reading and writing SPV files.
[pspp] / src / output / spv / spv-output.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 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 #include <config.h>
18
19 #include "output/spv/spv-output.h"
20
21 #include "output/pivot-table.h"
22 #include "output/spv/spv.h"
23 #include "output/text-item.h"
24
25 #include "gl/xalloc.h"
26
27 void
28 spv_text_submit (const struct spv_item *in)
29 {
30   enum spv_item_class class = spv_item_get_class (in);
31   enum text_item_type type
32     = (class == SPV_CLASS_HEADINGS ? TEXT_ITEM_TITLE
33        : class == SPV_CLASS_PAGETITLE ? TEXT_ITEM_PAGE_TITLE
34        : TEXT_ITEM_LOG);
35   const struct pivot_value *value = spv_item_get_text (in);
36   char *text = pivot_value_to_string (value, SETTINGS_VALUE_SHOW_DEFAULT,
37                                       SETTINGS_VALUE_SHOW_DEFAULT);
38   struct text_item *item = text_item_create_nocopy (type, text);
39   const struct font_style *font = value->font_style;
40   if (font)
41     {
42       item->bold = font->bold;
43       item->italic = font->italic;
44       item->underline = font->underline;
45       item->markup = font->markup;
46       if (font->typeface)
47         item->typeface = xstrdup (font->typeface);
48       item->size = font->size;
49     }
50   text_item_submit (item);
51 }