#include "output/driver-provider.h"
#include "output/message-item.h"
#include "output/options.h"
+#include "output/pivot-table.h"
#include "output/render.h"
#include "output/table-item.h"
#include "output/text-item.h"
static void
ascii_output_text (struct ascii_driver *a, const char *text)
{
- ascii_output_table_item_unref (
- a, table_item_create (table_from_string (text), NULL, NULL));
+ struct pivot_table *pt = pivot_table_create_for_text (
+ NULL, pivot_value_new_user_text (text, -1));
+ ascii_output_table_item_unref (a, table_item_create (pt));
}
static void
#include "output/message-item.h"
#include "output/options.h"
#include "output/page-setup-item.h"
+#include "output/pivot-table.h"
#include "output/render.h"
#include "output/table-item.h"
#include "output/table.h"
static struct xr_rendering *
xr_rendering_create_text (struct xr_driver *xr, const char *text, cairo_t *cr)
{
- struct table_item *table_item;
- struct xr_rendering *r;
-
- table_item = table_item_create (table_from_string (text), NULL, NULL);
- r = xr_rendering_create (xr, &table_item->output_item, cr);
+ struct pivot_table *pt = pivot_table_create_for_text (
+ NULL, pivot_value_new_user_text (text, -1));
+ struct table_item *table_item = table_item_create (pt);
+ struct xr_rendering *r = xr_rendering_create (xr, &table_item->output_item,
+ cr);
table_item_unref (table_item);
return r;
}
void
-pivot_table_submit (struct pivot_table *pt)
+pivot_table_flatten (const struct pivot_table *pt)
{
- pivot_table_assign_label_depth (CONST_CAST (struct pivot_table *, pt));
-
int old_decimal = settings_get_decimal_char (FMT_COMMA);
if (pt->decimal == '.' || pt->decimal == ',')
settings_set_decimal_char (pt->decimal);
- if (pt->print_all_layers)
- {
- size_t *layer_indexes;
-
- PIVOT_AXIS_FOR_EACH (layer_indexes, &pt->axes[PIVOT_AXIS_LAYER])
- {
- if (pt->paginate_layers)
- text_item_submit (text_item_create (TEXT_ITEM_EJECT_PAGE, ""));
- pivot_table_submit_layer (pt, layer_indexes);
- }
- }
- else
- pivot_table_submit_layer (pt, pt->current_layer);
+ pivot_table_submit_layer (pt, pt->current_layer);
settings_set_decimal_char (old_decimal);
-
- pivot_table_destroy (pt);
}
}
/* Creates and returns a new pivot table with the given TITLE and a single cell
- with the given CONTENT.
-
- This is really just for error handling. */
+ with the given CONTENT. */
struct pivot_table *
pivot_table_create_for_text (struct pivot_value *title,
struct pivot_value *content)
table->axes[PIVOT_AXIS_COLUMN].label_depth = 1;
pivot_axis_assign_label_depth (table, PIVOT_AXIS_LAYER, false);
}
-\f
-/* Footnotes. */
+void
+pivot_table_submit (struct pivot_table *pt)
+{
+ pivot_table_assign_label_depth (CONST_CAST (struct pivot_table *, pt));
+ table_item_submit (table_item_create (pt));
\f
-\f
-static void
+ static void
indent (int indentation)
{
for (int i = 0; i < indentation * 2; i++)
device with the given PARAMS. */
struct render_pager *
render_pager_create (const struct render_params *params,
- const struct table_item *table_item)
+ const struct pivot_table *pt)
{
const struct table *table = table_item_get_table (table_item);
#include <stddef.h>
#include "output/table-provider.h"
-struct table_item;
+struct pivot_table;
enum render_line_style
{
RENDER_N_LINES
};
-/* Parameters for rendering a table_item to a device.
+/* Parameters for rendering a pivot table to a device.
Coordinate system
/* An iterator for breaking render_pages into smaller chunks. */
struct render_pager *render_pager_create (const struct render_params *,
- const struct table_item *);
+ const struct pivot_table *);
void render_pager_destroy (struct render_pager *);
bool render_pager_has_next (const struct render_pager *);
cell->options = opt;
cell->n_footnotes = 0;
- cell->destructor = NULL;
int style_idx = (opt & TAB_STYLE_MASK) >> TAB_STYLE_SHIFT;
const struct area_style *style = t->styles[style_idx];
/* Table items.
A table item is a subclass of an output item (see output-item.h) that
- contains a table (see table.h) and some formatting properties. Currently
- the formatting properties are an optional title (a brief description
- typically displayed above the table) and an optional caption (a more verbose
- description typically displayed below the table). */
+ contains a pivot table (see pivot-table.h). */
#include "libpspp/compiler.h"
#include "output/output-item.h"
-#include "output/table.h"
-/* Title or caption in a table item. */
-struct table_item_text
- {
- char *content;
- const struct footnote **footnotes;
- size_t n_footnotes;
- struct area_style *style;
- };
-
-struct table_item_text *table_item_text_create (const char *);
-struct table_item_text *table_item_text_clone (const struct table_item_text *);
-void table_item_text_destroy (struct table_item_text *);
-
-/* A table item.
-
- The members of struct table_item should not be accessed directly. Use one
- of the accessor functions defined below. */
+/* A table item. */
struct table_item
{
struct output_item output_item; /* Superclass. */
- struct table *table; /* The table to be rendered. */
- struct table_item_text *title; /* Null if there is no title. */
- struct table_item_text *layers; /* Null if there is no layer info. */
- struct table_item_text *caption; /* Null if there is no caption. */
+ struct pivot_table *table; /* The table to be rendered. */
};
-struct table_item *table_item_create (struct table *, const char *title,
- const char *caption);
-
-const struct table *table_item_get_table (const struct table_item *);
-
-const struct table_item_text *table_item_get_title (const struct table_item *);
-void table_item_set_title (struct table_item *,
- const struct table_item_text *);
-
-const struct table_item_text *table_item_get_layers (
- const struct table_item *);
-void table_item_set_layers (struct table_item *,
- const struct table_item_text *);
-
-const struct table_item_text *table_item_get_caption (
- const struct table_item *);
-void table_item_set_caption (struct table_item *,
- const struct table_item_text *);
+struct table_item *table_item_create (struct pivot_table *);
\f
/* This boilerplate for table_item, a subclass of output_item, was
autogenerated by mk-class-boilerplate. */
size_t n_footnotes;
const struct area_style *style;
-
- /* Called to free the cell's data, if nonnull. */
- void (*destructor) (void *destructor_aux);
- void *destructor_aux;
};
void table_cell_free (struct table_cell *);
struct table_class
{
- /* Frees TABLE.
-
- The table class may assume that any cells that were retrieved by calling
- the 'get_cell' function have been freed (by calling their destructors)
- before this function is called. */
+ /* Frees TABLE. */
void (*destroy) (struct table *table);
/* Initializes CELL with the contents of the table cell at column X and row
- Y within TABLE. All members of CELL must be initialized, except that if
- 'destructor' is set to a null pointer, then 'destructor_aux' need not be
- initialized. The 'contents' member of CELL must be set to a nonnull
- value.
+ Y within TABLE. All members of CELL must be initialized. The
+ 'contents' member of CELL must be set to a nonnull value.
The table class must allow any number of cells in the table to be
retrieved simultaneously; that is, TABLE must not assume that a given
return n;
}
\f
-/* Returns a table that contains a single cell, whose contents are the
- left-aligned TEXT. */
-struct table *
-table_from_string (const char *text)
-{
- struct tab_table *t = tab_create (1, 1);
- tab_text (t, 0, 0, TAB_LEFT, text);
- return &t->table;
-}
-\f
const char *
table_halign_to_string (enum table_halign halign)
{
void table_set_hr (struct table *, int hr);
void table_set_ht (struct table *, int ht);
void table_set_hb (struct table *, int hb);
-\f
-/* Table classes. */
-
-/* Simple kinds of tables. */
-struct table *table_from_string (const char *);
#endif /* output/table.h */
struct table_item *
text_item_to_table_item (struct text_item *text_item)
{
- struct tab_table *tab = tab_create (1, 1);
+ struct pivot_value *text = pivot_value_new_user_text (
+ text_item_get_text (text_item), -1);
- struct area_style *style = pool_alloc (tab->container, sizeof *style);
- *style = (struct area_style) AREA_STYLE_INITIALIZER;
- struct font_style *font_style = &style->font_style;
+ struct font_style *font_style = xmalloc (sizeof *font_style);
if (text_item->typeface)
- font_style->typeface = pool_strdup (tab->container, text_item->typeface);
+ font_style->typeface = xstrdup (tab->container, text_item->typeface);
+ else if (text_item->type == TEXT_ITEM_SYNTAX
+ || text_item->type == TEXT_ITEM_LOG)
+ font_style->typeface = xstrdup ("Monospace");
font_style->size = text_item->size;
font_style->bold = text_item->bold;
font_style->italic = text_item->italic;
font_style->underline = text_item->underline;
font_style->markup = text_item->markup;
- tab->styles[0] = style;
-
- int opts = TAB_LEFT;
- if (text_item->markup)
- opts |= TAB_MARKUP;
- if (text_item->type == TEXT_ITEM_SYNTAX || text_item->type == TEXT_ITEM_LOG)
- opts |= TAB_FIX;
- tab_text (tab, 0, 0, opts, text_item_get_text (text_item));
- struct table_item *table_item = table_item_create (&tab->table, NULL, NULL);
+ text->font_style = font_style;
+
+ struct table_item *table_item = table_item_create (
+ pivot_table_create_for_text (NULL, text));
text_item_unref (text_item);
return table_item;
}