-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);
- }
-}
-