From 94864f7df42dc6495de1f785ec4ba45f33b63515 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 9 Feb 2019 16:00:45 -0800 Subject: [PATCH] work --- src/output/ascii.c | 6 +++-- src/output/cairo.c | 11 +++++---- src/output/pivot-output.c | 20 ++-------------- src/output/pivot-table.c | 14 +++++------ src/output/render.c | 2 +- src/output/render.h | 6 ++--- src/output/tab.c | 1 - src/output/table-item.h | 48 ++++--------------------------------- src/output/table-provider.h | 16 +++---------- src/output/table.c | 10 -------- src/output/table.h | 5 ---- src/output/text-item.c | 25 +++++++++---------- 12 files changed, 41 insertions(+), 123 deletions(-) diff --git a/src/output/ascii.c b/src/output/ascii.c index 6f8644ba3f..7833ed0ac5 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -44,6 +44,7 @@ #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" @@ -460,8 +461,9 @@ ascii_output_table_item_unref (struct ascii_driver *a, 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 diff --git a/src/output/cairo.c b/src/output/cairo.c index 4794fe25e1..80bca382a7 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -43,6 +43,7 @@ #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" @@ -1582,11 +1583,11 @@ xr_driver_destroy (struct xr_driver *xr) 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; diff --git a/src/output/pivot-output.c b/src/output/pivot-output.c index 69a6f7fec6..08db3a0781 100644 --- a/src/output/pivot-output.c +++ b/src/output/pivot-output.c @@ -488,29 +488,13 @@ pivot_table_submit_layer (const struct pivot_table *pt, } 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); } diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index 2adcf62634..96821170ef 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -696,9 +696,7 @@ pivot_table_create__ (struct pivot_value *title) } /* 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) @@ -1202,12 +1200,14 @@ pivot_table_assign_label_depth (struct pivot_table *table) table->axes[PIVOT_AXIS_COLUMN].label_depth = 1; pivot_axis_assign_label_depth (table, PIVOT_AXIS_LAYER, false); } - -/* 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)); - -static void + static void indent (int indentation) { for (int i = 0; i < indentation * 2; i++) diff --git a/src/output/render.c b/src/output/render.c index 4c98ad0fd9..0fad329ee4 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -1552,7 +1552,7 @@ add_text_page (struct render_pager *p, const struct table_item_text *t, 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); diff --git a/src/output/render.h b/src/output/render.h index c10f237160..31046e98fe 100644 --- a/src/output/render.h +++ b/src/output/render.h @@ -21,7 +21,7 @@ #include #include "output/table-provider.h" -struct table_item; +struct pivot_table; enum render_line_style { @@ -34,7 +34,7 @@ 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 @@ -137,7 +137,7 @@ struct render_params /* 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 *); diff --git a/src/output/tab.c b/src/output/tab.c index bf1f4671e5..19f7072dd0 100644 --- a/src/output/tab.c +++ b/src/output/tab.c @@ -484,7 +484,6 @@ tab_get_cell (const struct table *table, int x, int y, 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]; diff --git a/src/output/table-item.h b/src/output/table-item.h index b7866a3c9b..8d62421ea1 100644 --- a/src/output/table-item.h +++ b/src/output/table-item.h @@ -20,59 +20,19 @@ /* 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 *); /* This boilerplate for table_item, a subclass of output_item, was autogenerated by mk-class-boilerplate. */ diff --git a/src/output/table-provider.h b/src/output/table-provider.h index 5df00458ed..d4822d01a1 100644 --- a/src/output/table-provider.h +++ b/src/output/table-provider.h @@ -61,10 +61,6 @@ struct table_cell 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 *); @@ -100,18 +96,12 @@ table_cell_is_joined (const struct table_cell *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 diff --git a/src/output/table.c b/src/output/table.c index 8f717ead56..18b822ba70 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -298,16 +298,6 @@ table_collect_footnotes (const struct table_item *item, return n; } -/* 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; -} - const char * table_halign_to_string (enum table_halign halign) { diff --git a/src/output/table.h b/src/output/table.h index 5331aa3438..1229e9062f 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -262,10 +262,5 @@ void table_set_hl (struct table *, int hl); void table_set_hr (struct table *, int hr); void table_set_ht (struct table *, int ht); void table_set_hb (struct table *, int hb); - -/* Table classes. */ - -/* Simple kinds of tables. */ -struct table *table_from_string (const char *); #endif /* output/table.h */ diff --git a/src/output/text-item.c b/src/output/text-item.c index 2aba955eb3..eb3155affc 100644 --- a/src/output/text-item.c +++ b/src/output/text-item.c @@ -97,27 +97,24 @@ text_item_submit (struct text_item *item) 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; } -- 2.30.2