return pivot_table_create__ (pivot_value_new_text (title), title);
}
-/* Creates and returns a new pivot table with the given TITLE, and takes
- ownership of TITLE. The new pivot table's subtype is SUBTYPE, which
- should be an untranslated English string that describes the contents of
- the table at a high level without being specific about the variables or
- other context involved.
+/* Creates and returns a new pivot table with the given TITLE (which may be
+ null), and takes ownership of TITLE. The new pivot table's subtype is
+ SUBTYPE, which should be an untranslated English string that describes the
+ contents of the table at a high level without being specific about the
+ variables or other context involved.
Operations commonly performed on the new pivot_table:
void
pivot_value_set_style (struct pivot_value *value,
const struct table_area_style *area)
+{
+ pivot_value_set_font_style (value, &area->font_style);
+ pivot_value_set_cell_style (value, &area->cell_style);
+}
+
+void
+pivot_value_set_font_style (struct pivot_value *value,
+ const struct font_style *font_style)
{
if (value->font_style)
font_style_uninit (value->font_style);
else
value->font_style = xmalloc (sizeof *value->font_style);
- font_style_copy (NULL, value->font_style, &area->font_style);
+ font_style_copy (NULL, value->font_style, font_style);
+}
+void
+pivot_value_set_cell_style (struct pivot_value *value,
+ const struct cell_style *cell_style)
+{
if (!value->cell_style)
value->cell_style = xmalloc (sizeof *value->cell_style);
- *value->cell_style = area->cell_style;
+ *value->cell_style = *cell_style;
}
/* Frees the data owned by ARG (but not ARG itself). */
struct table_area_style *);
void pivot_value_set_style (struct pivot_value *,
const struct table_area_style *);
+void pivot_value_set_font_style (struct pivot_value *,
+ const struct font_style *);
+void pivot_value_set_cell_style (struct pivot_value *,
+ const struct cell_style *);
/* Template arguments. */
struct pivot_argument
#include "libpspp/pool.h"
#include "output/driver.h"
#include "output/output-item-provider.h"
+#include "output/pivot-table.h"
#include "output/table.h"
#include "output/table-item.h"
#include "output/table-provider.h"
.type = type,
.style = FONT_STYLE_INITIALIZER,
};
+
+ if (type == TEXT_ITEM_SYNTAX || type == TEXT_ITEM_LOG)
+ {
+ free (item->style.typeface);
+ item->style.typeface = xstrdup ("Monospaced");
+ }
+
return item;
}
struct table_item *
text_item_to_table_item (struct text_item *text_item)
{
- struct table *tab = table_create (1, 1, 0, 0, 0, 0);
+ struct pivot_table *table = pivot_table_create__ (NULL, "Text");
+ pivot_table_set_look (table, pivot_table_look_builtin_default ());
- struct table_area_style *style = pool_alloc (tab->container, sizeof *style);
- *style = (struct table_area_style) {
- .cell_style = CELL_STYLE_INITIALIZER,
- .cell_style.halign = TABLE_HALIGN_LEFT,
- };
- font_style_copy (tab->container, &style->font_style, &text_item->style);
- tab->styles[0] = style;
-
- int opts = 0;
- if (text_item->style.markup)
- opts |= TAB_MARKUP;
- if (text_item->type == TEXT_ITEM_SYNTAX || text_item->type == TEXT_ITEM_LOG)
- opts |= TAB_FIX;
- table_text (tab, 0, 0, opts, text_item_get_text (text_item));
- struct table_item *table_item = table_item_create (tab);
- text_item_unref (text_item);
- return table_item;
+ struct pivot_dimension *d = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Text"));
+ d->hide_all_labels = true;
+ pivot_category_create_leaf (d->root, pivot_value_new_text ("null"));
+
+ struct pivot_value *content = pivot_value_new_user_text (
+ text_item->text, SIZE_MAX);
+ pivot_value_set_font_style (content, &text_item->style);
+ pivot_table_put1 (table, 0, content);
+
+ return table;
}
\f
static const char *