X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fspv%2Fspv-legacy-decoder.c;h=1894092a14bf2e97e5b2bf8f5b084c1f620e5654;hb=c8d4730341536ea6120a273100b0333327bf880a;hp=9740a37eee01ae64796f24458e5582805fc1197a;hpb=50f6ea7d66d03895020891215fb4f55bbf061003;p=pspp diff --git a/src/output/spv/spv-legacy-decoder.c b/src/output/spv/spv-legacy-decoder.c index 9740a37eee..1894092a14 100644 --- a/src/output/spv/spv-legacy-decoder.c +++ b/src/output/spv/spv-legacy-decoder.c @@ -35,6 +35,7 @@ #include "output/pivot-table.h" #include "output/spv/detail-xml-parser.h" #include "output/spv/spv-legacy-data.h" +#include "output/spv/spv-table-look.h" #include "output/spv/spv.h" #include "output/spv/structure-xml-parser.h" @@ -48,31 +49,6 @@ #define N_(msgid) msgid #define _(msgid) gettext (msgid) -struct spv_legacy_properties - { - /* General properties. */ - bool omit_empty; - int width_ranges[TABLE_N_AXES][2]; /* In 1/96" units. */ - bool row_labels_in_corner; - - /* Footnote display settings. */ - bool show_numeric_markers; - bool footnote_marker_superscripts; - - /* Styles. */ - struct area_style areas[PIVOT_N_AREAS]; - struct table_border_style borders[PIVOT_N_BORDERS]; - - /* Print settings. */ - bool print_all_layers; - bool paginate_layers; - bool shrink_to_width; - bool shrink_to_length; - bool top_continuation, bottom_continuation; - char *continuation; - size_t n_orphan_lines; - }; - struct spv_series { struct hmap_node hmap_node; /* By name. */ @@ -599,16 +575,10 @@ optional_px (double inches, int default_px) return inches != DBL_MAX ? inches * 96.0 : default_px; } -static int -optional_pt (double inches, int default_pt) -{ - return inches != DBL_MAX ? inches * 72.0 + .5 : default_pt; -} - static void decode_spvdx_style_incremental (const struct spvdx_style *in, const struct spvdx_style *bg, - struct area_style *out) + struct table_area_style *out) { if (in && in->font_weight) out->font_style.bold = in->font_weight == SPVDX_FONT_WEIGHT_BOLD; @@ -674,9 +644,9 @@ decode_spvdx_style_incremental (const struct spvdx_style *in, static void decode_spvdx_style (const struct spvdx_style *in, const struct spvdx_style *bg, - struct area_style *out) + struct table_area_style *out) { - *out = (struct area_style) AREA_STYLE_INITIALIZER; + *out = (struct table_area_style) TABLE_AREA_STYLE_INITIALIZER; decode_spvdx_style_incremental (in, bg, out); } @@ -697,16 +667,16 @@ decode_label_frame (struct pivot_table *table, return NULL; struct pivot_value **target; - struct area_style *area; + struct table_area_style *area; if (lf->label->purpose == SPVDX_PURPOSE_TITLE) { target = &table->title; - area = &table->areas[PIVOT_AREA_TITLE]; + area = &table->look->areas[PIVOT_AREA_TITLE]; } else if (lf->label->purpose == SPVDX_PURPOSE_SUB_TITLE) { target = &table->caption; - area = &table->areas[PIVOT_AREA_CAPTION]; + area = &table->look->areas[PIVOT_AREA_CAPTION]; } else if (lf->label->purpose == SPVDX_PURPOSE_FOOTNOTE) { @@ -714,7 +684,7 @@ decode_label_frame (struct pivot_table *table, && lf->label->text[0]->uses_reference != INT_MIN) { target = NULL; - area = &table->areas[PIVOT_AREA_FOOTER]; + area = &table->look->areas[PIVOT_AREA_FOOTER]; } else return NULL; @@ -722,12 +692,12 @@ decode_label_frame (struct pivot_table *table, else if (lf->label->purpose == SPVDX_PURPOSE_LAYER) { target = NULL; - area = &table->areas[PIVOT_AREA_LAYERS]; + area = &table->look->areas[PIVOT_AREA_LAYERS]; } else return NULL; - area_style_uninit (area); + table_area_style_uninit (area); decode_spvdx_style (lf->label->style, lf->label->text_frame_style, area); if (target) @@ -865,7 +835,7 @@ decode_spvdx_derived_variable (const struct spvxml_node *node, return &BAD_REFERENCE; n_values = existing_series->n_values; - values = xcalloc (n_values, sizeof *values); + values = XCALLOC (n_values, struct spv_data_value); for (size_t i = 0; i < n_values; i++) values[i].width = -1; } @@ -1109,14 +1079,15 @@ add_dimension (struct spv_series **series, size_t n, = find_facet_level (v, base_facet_level + n); if (fl) { - struct area_style *area = (axis_type == PIVOT_AXIS_COLUMN - ? &table->areas[PIVOT_AREA_COLUMN_LABELS] - : axis_type == PIVOT_AXIS_ROW - ? &table->areas[PIVOT_AREA_ROW_LABELS] - : NULL); + struct table_area_style *area + = (axis_type == PIVOT_AXIS_COLUMN + ? &table->look->areas[PIVOT_AREA_COLUMN_LABELS] + : axis_type == PIVOT_AXIS_ROW + ? &table->look->areas[PIVOT_AREA_ROW_LABELS] + : NULL); if (area && fl->axis->label) { - area_style_uninit (area); + table_area_style_uninit (area); decode_spvdx_style (fl->axis->label->style, fl->axis->label->text_frame_style, area); } @@ -1130,7 +1101,7 @@ add_dimension (struct spv_series **series, size_t n, decode_spvdx_style_incremental ( fl2->axis->major_ticks->style, fl2->axis->major_ticks->tick_frame_style, - &table->areas[PIVOT_AREA_ROW_LABELS]); + &table->look->areas[PIVOT_AREA_ROW_LABELS]); } const struct spvdx_facet_level *fl3 = find_facet_level (v, base_facet_level); @@ -1229,7 +1200,7 @@ add_dimension (struct spv_series **series, size_t n, series[j]->n_index = max_cat + 1; series[j]->index_to_category = xcalloc ( max_cat + 1, sizeof *series[j]->index_to_category); - for (size_t cat1 = 0; cat1 < n_cats; ) + for (size_t cat1 = 0; cat1 < n_cats;) { /* Find a sequence of categories cat1...cat2 (exclusive), that all have the same value in series 'j'. (This might be only a single @@ -1335,7 +1306,7 @@ add_dimensions (struct hmap *series_map, const struct spvdx_nest *nest, return NULL; struct spv_series **series = xnmalloc (nest->n_vars, sizeof *series); - for (size_t i = 0; i < nest->n_vars; ) + for (size_t i = 0; i < nest->n_vars;) { size_t n; for (n = 0; i + n < nest->n_vars; n++) @@ -1380,7 +1351,7 @@ add_layers (struct hmap *series_map, return NULL; struct spv_series **series = xnmalloc (n_layers, sizeof *series); - for (size_t i = 0; i < n_layers; ) + for (size_t i = 0; i < n_layers;) { size_t n; for (n = 0; i + n < n_layers; n++) @@ -1417,65 +1388,6 @@ add_layers (struct hmap *series_map, return NULL; } -static int -optional_int (int x, int default_value) -{ - return x != INT_MIN ? x : default_value; -} - -static enum pivot_area -pivot_area_from_name (const char *name) -{ - static const char *area_names[PIVOT_N_AREAS] = { - [PIVOT_AREA_TITLE] = "title", - [PIVOT_AREA_CAPTION] = "caption", - [PIVOT_AREA_FOOTER] = "footnotes", - [PIVOT_AREA_CORNER] = "cornerLabels", - [PIVOT_AREA_COLUMN_LABELS] = "columnLabels", - [PIVOT_AREA_ROW_LABELS] = "rowLabels", - [PIVOT_AREA_DATA] = "data", - [PIVOT_AREA_LAYERS] = "layers", - }; - - enum pivot_area area; - for (area = 0; area < PIVOT_N_AREAS; area++) - if (!strcmp (name, area_names[area])) - break; - return area; -} - -static enum pivot_border -pivot_border_from_name (const char *name) -{ - static const char *border_names[PIVOT_N_BORDERS] = { - [PIVOT_BORDER_TITLE] = "titleLayerSeparator", - [PIVOT_BORDER_OUTER_LEFT] = "leftOuterFrame", - [PIVOT_BORDER_OUTER_TOP] = "topOuterFrame", - [PIVOT_BORDER_OUTER_RIGHT] = "rightOuterFrame", - [PIVOT_BORDER_OUTER_BOTTOM] = "bottomOuterFrame", - [PIVOT_BORDER_INNER_LEFT] = "leftInnerFrame", - [PIVOT_BORDER_INNER_TOP] = "topInnerFrame", - [PIVOT_BORDER_INNER_RIGHT] = "rightInnerFrame", - [PIVOT_BORDER_INNER_BOTTOM] = "bottomInnerFrame", - [PIVOT_BORDER_DATA_LEFT] = "dataAreaLeft", - [PIVOT_BORDER_DATA_TOP] = "dataAreaTop", - [PIVOT_BORDER_DIM_ROW_HORZ] = "horizontalDimensionBorderRows", - [PIVOT_BORDER_DIM_ROW_VERT] = "verticalDimensionBorderRows", - [PIVOT_BORDER_DIM_COL_HORZ] = "horizontalDimensionBorderColumns", - [PIVOT_BORDER_DIM_COL_VERT] = "verticalDimensionBorderColumns", - [PIVOT_BORDER_CAT_ROW_HORZ] = "horizontalCategoryBorderRows", - [PIVOT_BORDER_CAT_ROW_VERT] = "verticalCategoryBorderRows", - [PIVOT_BORDER_CAT_COL_HORZ] = "horizontalCategoryBorderColumns", - [PIVOT_BORDER_CAT_COL_VERT] = "verticalCategoryBorderColumns", - }; - - enum pivot_border border; - for (border = 0; border < PIVOT_N_BORDERS; border++) - if (!strcmp (name, border_names[border])) - break; - return border; -} - static struct pivot_category * find_category (struct spv_series *series, int index) { @@ -1498,7 +1410,7 @@ static void apply_styles_to_value (struct pivot_table *table, struct pivot_value *value, const struct spvdx_set_format *sf, - const struct area_style *base_area_style, + const struct table_area_style *base_area_style, const struct spvdx_style *fg, const struct spvdx_style *bg) { @@ -1553,7 +1465,7 @@ apply_styles_to_value (struct pivot_table *table, } if (fg || bg) { - struct area_style area; + struct table_area_style area; pivot_value_get_style ( value, value->font_style ? value->font_style : &base_area_style->font_style, @@ -1561,7 +1473,7 @@ apply_styles_to_value (struct pivot_table *table, &area); decode_spvdx_style_incremental (fg, bg, &area); pivot_value_set_style (value, &area); - area_style_uninit (&area); + table_area_style_uninit (&area); } } @@ -1580,13 +1492,13 @@ decode_set_cell_properties__ (struct pivot_table *table, && !interval && !major_ticks && !frame && !set_format) { /* Sets alt_fg_color and alt_bg_color. */ - struct area_style area; + struct table_area_style area; decode_spvdx_style (labeling, graph, &area); - table->areas[PIVOT_AREA_DATA].font_style.fg[1] + table->look->areas[PIVOT_AREA_DATA].font_style.fg[1] = area.font_style.fg[0]; - table->areas[PIVOT_AREA_DATA].font_style.bg[1] + table->look->areas[PIVOT_AREA_DATA].font_style.bg[1] = area.font_style.bg[0]; - area_style_uninit (&area); + table_area_style_uninit (&area); } else if (graph && !labeling && !interval && !major_ticks && !frame && !set_format) @@ -1618,10 +1530,10 @@ decode_set_cell_properties__ (struct pivot_table *table, struct pivot_category *c = find_category (s, include); if (c) { - const struct area_style *base_area_style + const struct table_area_style *base_area_style = (c->dimension->axis_type == PIVOT_AXIS_ROW - ? &table->areas[PIVOT_AREA_ROW_LABELS] - : &table->areas[PIVOT_AREA_COLUMN_LABELS]); + ? &table->look->areas[PIVOT_AREA_ROW_LABELS] + : &table->look->areas[PIVOT_AREA_COLUMN_LABELS]); apply_styles_to_value (table, c->name, set_format, base_area_style, major_ticks, frame); } @@ -1638,9 +1550,9 @@ decode_set_cell_properties__ (struct pivot_table *table, { /* Formatting for individual cells or groups of them with some dimensions in common. */ - int **indexes = xcalloc (table->n_dimensions, sizeof *indexes); - size_t *n = xcalloc (table->n_dimensions, sizeof *n); - size_t *allocated = xcalloc (table->n_dimensions, sizeof *allocated); + int **indexes = XCALLOC (table->n_dimensions, int *); + size_t *n = XCALLOC (table->n_dimensions, size_t); + size_t *allocated = XCALLOC (table->n_dimensions, size_t); for (size_t i = 0; i < intersect->n_where; i++) { @@ -1714,7 +1626,7 @@ decode_set_cell_properties__ (struct pivot_table *table, goto skip; } apply_styles_to_value (table, cell->value, set_format, - &table->areas[PIVOT_AREA_DATA], + &table->look->areas[PIVOT_AREA_DATA], labeling, interval); skip: ; @@ -1785,7 +1697,7 @@ decode_set_cell_properties (struct pivot_table *table, struct hmap *series_map, struct pivot_cell *cell; HMAP_FOR_EACH (cell, struct pivot_cell, hmap_node, &table->cells) apply_styles_to_value (table, cell->value, set_format, - &table->areas[PIVOT_AREA_DATA], + &table->look->areas[PIVOT_AREA_DATA], NULL, NULL); } } @@ -1798,177 +1710,6 @@ decode_set_cell_properties (struct pivot_table *table, struct hmap *series_map, } } -char * WARN_UNUSED_RESULT -decode_spvsx_legacy_properties (const struct spvsx_table_properties *in, - struct spv_legacy_properties **outp) -{ - struct spv_legacy_properties *out = xzalloc (sizeof *out); - char *error; - - if (!in) - { - error = xstrdup ("Legacy table lacks tableProperties"); - goto error; - } - - const struct spvsx_general_properties *g = in->general_properties; - out->omit_empty = g->hide_empty_rows != 0; - out->width_ranges[TABLE_HORZ][0] = optional_pt (g->minimum_column_width, -1); - out->width_ranges[TABLE_HORZ][1] = optional_pt (g->maximum_column_width, -1); - out->width_ranges[TABLE_VERT][0] = optional_pt (g->minimum_row_width, -1); - out->width_ranges[TABLE_VERT][1] = optional_pt (g->maximum_row_width, -1); - out->row_labels_in_corner - = g->row_dimension_labels != SPVSX_ROW_DIMENSION_LABELS_NESTED; - - const struct spvsx_footnote_properties *f = in->footnote_properties; - out->footnote_marker_superscripts - = (f->marker_position != SPVSX_MARKER_POSITION_SUBSCRIPT); - out->show_numeric_markers - = (f->number_format == SPVSX_NUMBER_FORMAT_NUMERIC); - - for (int i = 0; i < PIVOT_N_AREAS; i++) - area_style_copy (NULL, &out->areas[i], pivot_area_get_default_style (i)); - - const struct spvsx_cell_format_properties *cfp = in->cell_format_properties; - for (size_t i = 0; i < cfp->n_cell_style; i++) - { - const struct spvsx_cell_style *c = cfp->cell_style[i]; - const char *name = CHAR_CAST (const char *, c->node_.raw->name); - enum pivot_area area = pivot_area_from_name (name); - if (area == PIVOT_N_AREAS) - { - error = xasprintf ("unknown area \"%s\" in cellFormatProperties", - name); - goto error; - } - - struct area_style *a = &out->areas[area]; - const struct spvsx_style *s = c->style; - if (s->font_weight) - a->font_style.bold = s->font_weight == SPVSX_FONT_WEIGHT_BOLD; - if (s->font_style) - a->font_style.italic = s->font_style == SPVSX_FONT_STYLE_ITALIC; - a->font_style.underline = false; - if (s->color >= 0) - a->font_style.fg[0] = optional_color ( - s->color, (struct cell_color) CELL_COLOR_BLACK); - if (c->alternating_text_color >= 0 || s->color >= 0) - a->font_style.fg[1] = optional_color (c->alternating_text_color, - a->font_style.fg[0]); - if (s->color2 >= 0) - a->font_style.bg[0] = optional_color ( - s->color2, (struct cell_color) CELL_COLOR_WHITE); - if (c->alternating_color >= 0 || s->color2 >= 0) - a->font_style.bg[1] = optional_color (c->alternating_color, - a->font_style.bg[0]); - if (s->font_family) - { - free (a->font_style.typeface); - a->font_style.typeface = xstrdup (s->font_family); - } - - if (s->font_size) - a->font_style.size = optional_length (s->font_size, 0); - - if (s->text_alignment) - a->cell_style.halign - = (s->text_alignment == SPVSX_TEXT_ALIGNMENT_LEFT - ? TABLE_HALIGN_LEFT - : s->text_alignment == SPVSX_TEXT_ALIGNMENT_RIGHT - ? TABLE_HALIGN_RIGHT - : s->text_alignment == SPVSX_TEXT_ALIGNMENT_CENTER - ? TABLE_HALIGN_CENTER - : s->text_alignment == SPVSX_TEXT_ALIGNMENT_DECIMAL - ? TABLE_HALIGN_DECIMAL - : TABLE_HALIGN_MIXED); - if (s->label_location_vertical) - a->cell_style.valign - = (s->label_location_vertical == SPVSX_LABEL_LOCATION_VERTICAL_NEGATIVE - ? TABLE_VALIGN_BOTTOM - : s->label_location_vertical == SPVSX_LABEL_LOCATION_VERTICAL_POSITIVE - ? TABLE_VALIGN_TOP - : TABLE_VALIGN_CENTER); - - if (s->decimal_offset != DBL_MAX) - a->cell_style.decimal_offset = optional_px (s->decimal_offset, 0); - - if (s->margin_left != DBL_MAX) - a->cell_style.margin[TABLE_HORZ][0] = optional_px (s->margin_left, 8); - if (s->margin_right != DBL_MAX) - a->cell_style.margin[TABLE_HORZ][1] = optional_px (s->margin_right, - 11); - if (s->margin_top != DBL_MAX) - a->cell_style.margin[TABLE_VERT][0] = optional_px (s->margin_top, 1); - if (s->margin_bottom != DBL_MAX) - a->cell_style.margin[TABLE_VERT][1] = optional_px (s->margin_bottom, - 1); - } - - for (int i = 0; i < PIVOT_N_BORDERS; i++) - pivot_border_get_default_style (i, &out->borders[i]); - - const struct spvsx_border_properties *bp = in->border_properties; - for (size_t i = 0; i < bp->n_border_style; i++) - { - const struct spvsx_border_style *bin = bp->border_style[i]; - const char *name = CHAR_CAST (const char *, bin->node_.raw->name); - enum pivot_border border = pivot_border_from_name (name); - if (border == PIVOT_N_BORDERS) - { - error = xasprintf ("unknown border \"%s\" parsing borderProperties", - name); - goto error; - } - - struct table_border_style *bout = &out->borders[border]; - bout->stroke - = (bin->border_style_type == SPVSX_BORDER_STYLE_TYPE_NONE - ? TABLE_STROKE_NONE - : bin->border_style_type == SPVSX_BORDER_STYLE_TYPE_DASHED - ? TABLE_STROKE_DASHED - : bin->border_style_type == SPVSX_BORDER_STYLE_TYPE_THICK - ? TABLE_STROKE_THICK - : bin->border_style_type == SPVSX_BORDER_STYLE_TYPE_THIN - ? TABLE_STROKE_THIN - : bin->border_style_type == SPVSX_BORDER_STYLE_TYPE_DOUBLE - ? TABLE_STROKE_DOUBLE - : TABLE_STROKE_SOLID); - bout->color = optional_color (bin->color, - (struct cell_color) CELL_COLOR_BLACK); - } - - const struct spvsx_printing_properties *pp = in->printing_properties; - out->print_all_layers = pp->print_all_layers > 0; - out->paginate_layers = pp->print_each_layer_on_separate_page > 0; - out->shrink_to_width = pp->rescale_wide_table_to_fit_page > 0; - out->shrink_to_length = pp->rescale_long_table_to_fit_page > 0; - out->top_continuation = pp->continuation_text_at_top > 0; - out->bottom_continuation = pp->continuation_text_at_bottom > 0; - out->continuation = xstrdup (pp->continuation_text - ? pp->continuation_text : "(cont.)"); - out->n_orphan_lines = optional_int (pp->window_orphan_lines, 2); - - *outp = out; - return NULL; - -error: - spv_legacy_properties_destroy (out); - *outp = NULL; - return error; -} - -void -spv_legacy_properties_destroy (struct spv_legacy_properties *props) -{ - if (props) - { - for (size_t i = 0; i < PIVOT_N_AREAS; i++) - area_style_uninit (&props->areas[i]); - free (props->continuation); - free (props); - } -} - static struct spv_series * parse_formatting (const struct spvdx_visualization *v, const struct hmap *series_map, struct hmap *format_map) @@ -2015,44 +1756,19 @@ format_map_destroy (struct hmap *format_map) char * WARN_UNUSED_RESULT decode_spvdx_table (const struct spvdx_visualization *v, const char *subtype, - const struct spv_legacy_properties *props, + const struct pivot_table_look *look, struct spv_data *data, struct pivot_table **outp) { struct pivot_table *table = pivot_table_create__ (NULL, subtype); + pivot_table_set_look (table, look); + table->look = pivot_table_look_unshare (table->look); + struct hmap series_map = HMAP_INITIALIZER (series_map); struct hmap format_map = HMAP_INITIALIZER (format_map); struct spv_series **dim_series = NULL; char *error; - /* First get the legacy properties. */ - table->omit_empty = props->omit_empty; - for (enum table_axis axis = 0; axis < TABLE_N_AXES; axis++) - for (int i = 0; i < 2; i++) - if (props->width_ranges[axis][i] > 0) - table->sizing[axis].range[i] = props->width_ranges[axis][i]; - table->row_labels_in_corner = props->row_labels_in_corner; - - table->footnote_marker_superscripts = props->footnote_marker_superscripts; - table->show_numeric_markers = props->show_numeric_markers; - - for (size_t i = 0; i < PIVOT_N_AREAS; i++) - { - area_style_uninit (&table->areas[i]); - area_style_copy (NULL, &table->areas[i], &props->areas[i]); - } - for (size_t i = 0; i < PIVOT_N_BORDERS; i++) - table->borders[i] = props->borders[i]; - - table->print_all_layers = props->print_all_layers; - table->paginate_layers = props->paginate_layers; - table->shrink_to_fit[TABLE_HORZ] = props->shrink_to_width; - table->shrink_to_fit[TABLE_VERT] = props->shrink_to_length; - table->top_continuation = props->top_continuation; - table->bottom_continuation = props->bottom_continuation; - table->continuation = xstrdup (props->continuation); - table->n_orphan_lines = props->n_orphan_lines; - struct spvdx_visualization_extension *ve = v->visualization_extension; table->show_grid_lines = ve && ve->show_gridline; @@ -2064,8 +1780,8 @@ decode_spvdx_table (const struct spvdx_visualization *v, const char *subtype, &min_width, &max_width, &n) && v->graph->cell_style->width[n] == '\0') { - table->sizing[TABLE_HORZ].range[0] = min_width; - table->sizing[TABLE_HORZ].range[1] = max_width; + table->look->width_ranges[TABLE_HORZ][0] = min_width; + table->look->width_ranges[TABLE_HORZ][1] = max_width; } } @@ -2131,10 +1847,10 @@ decode_spvdx_table (const struct spvdx_visualization *v, const char *subtype, } if (v->graph->interval->labeling->style) { - area_style_uninit (&table->areas[PIVOT_AREA_DATA]); + table_area_style_uninit (&table->look->areas[PIVOT_AREA_DATA]); decode_spvdx_style (v->graph->interval->labeling->style, v->graph->cell_style, - &table->areas[PIVOT_AREA_DATA]); + &table->look->areas[PIVOT_AREA_DATA]); } /* Decode all of the sourceVariable and derivedVariable */ @@ -2143,7 +1859,7 @@ decode_spvdx_table (const struct spvdx_visualization *v, const char *subtype, while (n_nodes > 0) { bool progress = false; - for (size_t i = 0; i < n_nodes; ) + for (size_t i = 0; i < n_nodes;) { error = (spvdx_is_source_variable (nodes[i]) ? decode_spvdx_source_variable (nodes[i], data, &series_map)