[gnumeric] Text export: take conditional formats into account
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Text export: take conditional formats into account
- Date: Sun, 14 Feb 2021 23:16:59 +0000 (UTC)
commit 2d520dbd2832ee93e0089a4e2f05ff3b6476d935
Author: Morten Welinder <terra gnome org>
Date: Sun Feb 14 18:14:54 2021 -0500
Text export: take conditional formats into account
They don't actually matter most of the time, but a conditional number
format can be set and the configurable text export can be convinced
to pay attention to formats.
ChangeLog | 9 +++++++++
NEWS | 1 +
plugins/html/latex.c | 4 ++--
plugins/html/roff.c | 4 ++--
src/cell.c | 36 ++++++++++++++++++++++++++++++++++--
src/cell.h | 1 +
src/cellspan.c | 2 +-
src/rendered-value.c | 15 +--------------
src/sheet.c | 2 +-
9 files changed, 52 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index dbf32316d..64c0157d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-02-14 Morten Welinder <terra gnome org>
+
+ * src/cell.c (gnm_cell_get_effective_style): New function to
+ resolve conditional styling.
+
+ * src/rendered-value.c (gnm_rendered_value_new): Use
+ gnm_cell_get_effective_style instead of doing it by hand.
+
+
2021-01-30 Morten Welinder <terra gnome org>
* autogen.sh: check that YELP_HELP_INIT has been expanded.
diff --git a/NEWS b/NEWS
index d7425d2e8..bfea1497e 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,7 @@ Morten:
* Allow plain space as 1000s separator in FR locale.
* Fix graph size problem affecting image output. [#507]
* Check for yelp in autogen. [#558]
+ * Fix ssconvert problem with conditional styles.
--------------------------------------------------------------------------
Gnumeric 1.12.48
diff --git a/plugins/html/latex.c b/plugins/html/latex.c
index 7840d4e47..5c0e89a11 100644
--- a/plugins/html/latex.c
+++ b/plugins/html/latex.c
@@ -931,7 +931,7 @@ latex2e_write_multicolumn_cell (GsfOutput *output, GnmCell *cell, int start_col,
GnmStyleBorderType right_border = GNM_STYLE_BORDER_NONE;
/* Print the cell according to its style. */
- GnmStyle const *style = gnm_cell_get_style (cell);
+ GnmStyle const *style = gnm_cell_get_effective_style (cell);
gboolean hidden = gnm_style_get_contents_hidden (style);
g_return_if_fail (style != NULL);
@@ -1515,7 +1515,7 @@ latex_file_save (GOFileSaver const *fs, G_GNUC_UNUSED GOIOContext *io_context,
static void
latex2e_table_write_cell (GsfOutput *output, GnmCell *cell)
{
- GnmStyle const *style = gnm_cell_get_style (cell);
+ GnmStyle const *style = gnm_cell_get_effective_style (cell);
if (gnm_style_get_contents_hidden (style))
return;
diff --git a/plugins/html/roff.c b/plugins/html/roff.c
index 5559f2b1f..e54e1be5a 100644
--- a/plugins/html/roff.c
+++ b/plugins/html/roff.c
@@ -48,7 +48,7 @@ roff_fprintf (GsfOutput *output, GnmCell *cell)
if (gnm_cell_is_empty (cell))
return 0;
- style = gnm_cell_get_style (cell);
+ style = gnm_cell_get_effective_style (cell);
if (style != NULL && gnm_style_get_contents_hidden (style))
return 0;
@@ -121,7 +121,7 @@ roff_file_save (GOFileSaver const *fs, GOIOContext *io_context,
if (!cell) {
gsf_output_printf (output, "l");
} else {
- GnmStyle const *style = gnm_cell_get_style (cell);
+ GnmStyle const *style = gnm_cell_get_effective_style (cell);
if (!style)
break;
if (gnm_style_get_align_h (style) & GNM_HALIGN_RIGHT)
diff --git a/src/cell.c b/src/cell.c
index a59e8fdc3..ab2558080 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -22,6 +22,7 @@
#include <number-match.h>
#include <sheet-style.h>
#include <parse-util.h>
+#include <style-conditions.h>
#include <goffice/goffice.h>
@@ -1001,6 +1002,36 @@ gnm_cell_get_style (GnmCell const *cell)
cell->pos.row);
}
+/**
+ * gnm_cell_get_effective_style:
+ * @cell: #GnmCell to query
+ *
+ * Returns: (transfer none): the fully qualified style for @cell, taking any
+ * conditional formats into account.
+ */
+GnmStyle const *
+gnm_cell_get_effective_style (GnmCell const *cell)
+{
+ GnmStyleConditions *conds;
+ GnmStyle const *mstyle;
+
+ g_return_val_if_fail (cell != NULL, NULL);
+
+ mstyle = gnm_cell_get_style (cell);
+ conds = gnm_style_get_conditions (mstyle);
+ if (conds) {
+ GnmEvalPos ep;
+ int res;
+ eval_pos_init_cell (&ep, cell);
+
+ res = gnm_style_conditions_eval (conds, &ep);
+ if (res >= 0)
+ mstyle = gnm_style_get_cond_style (mstyle, res);
+ }
+ return mstyle;
+}
+
+
/**
* gnm_cell_get_format_given_style: (skip)
* @cell: #GnmCell to query
@@ -1017,7 +1048,7 @@ gnm_cell_get_format_given_style (GnmCell const *cell, GnmStyle const *style)
g_return_val_if_fail (cell != NULL, go_format_general ());
if (style == NULL)
- style = gnm_cell_get_style (cell);
+ style = gnm_cell_get_effective_style (cell);
fmt = gnm_style_get_format (style);
@@ -1040,7 +1071,8 @@ gnm_cell_get_format_given_style (GnmCell const *cell, GnmStyle const *style)
GOFormat const *
gnm_cell_get_format (GnmCell const *cell)
{
- return gnm_cell_get_format_given_style (cell, NULL);
+ GnmStyle const *mstyle = gnm_cell_get_effective_style (cell);
+ return gnm_cell_get_format_given_style (cell, mstyle);
}
static GnmValue *
diff --git a/src/cell.h b/src/cell.h
index f2b5f9838..092c11ba0 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -82,6 +82,7 @@ void gnm_cell_convert_expr_to_value (GnmCell *cell);
* Manipulate GnmCell attributes
*/
GnmStyle const *gnm_cell_get_style (GnmCell const *cell);
+GnmStyle const *gnm_cell_get_effective_style (GnmCell const *cell);
GOFormat const *gnm_cell_get_format (GnmCell const *cell);
GOFormat const *gnm_cell_get_format_given_style (GnmCell const *cell, GnmStyle const *style);
diff --git a/src/cellspan.c b/src/cellspan.c
index ea0020752..280c9a405 100644
--- a/src/cellspan.c
+++ b/src/cellspan.c
@@ -236,7 +236,7 @@ cell_calc_span (GnmCell const *cell, int *col1, int *col2)
g_return_if_fail (cell != NULL);
sheet = cell->base.sheet;
- style = gnm_cell_get_style (cell);
+ style = gnm_cell_get_effective_style (cell);
h_align = gnm_style_default_halign (style, cell);
/*
diff --git a/src/rendered-value.c b/src/rendered-value.c
index 3d399201c..664afbf62 100644
--- a/src/rendered-value.c
+++ b/src/rendered-value.c
@@ -31,7 +31,6 @@
#include <style-color.h>
#include <style-font.h>
#include <style-border.h>
-#include <style-conditions.h>
#include <sheet.h>
#include <sheet-merge.h>
#include <gnm-format.h>
@@ -265,7 +264,6 @@ gnm_rendered_value_new (GnmCell const *cell,
PangoDirection dir;
char const *text;
gboolean debug = debug_rv ();
- GnmStyleConditions *conds;
g_return_val_if_fail (cell != NULL, NULL);
@@ -290,18 +288,7 @@ gnm_rendered_value_new (GnmCell const *cell,
/* Must come after above gnm_cell_eval. */
g_return_val_if_fail (cell->value != NULL, NULL);
- mstyle = gnm_cell_get_style (cell);
-
- conds = gnm_style_get_conditions (mstyle);
- if (conds) {
- GnmEvalPos ep;
- int res;
- eval_pos_init_cell (&ep, cell);
-
- res = gnm_style_conditions_eval (conds, &ep);
- if (res >= 0)
- mstyle = gnm_style_get_cond_style (mstyle, res);
- }
+ mstyle = gnm_cell_get_effective_style (cell);
rotation = gnm_style_get_rotation (mstyle);
if (rotation) {
diff --git a/src/sheet.c b/src/sheet.c
index 1bf16e09a..02152f2c2 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -2644,7 +2644,7 @@ cb_max_cell_height (GnmCellIter const *iter, struct cb_fit *data)
* that they are all the same height, more or less.
*/
Sheet const *sheet = cell->base.sheet;
- height = gnm_style_get_pango_height (gnm_cell_get_style (cell),
+ height = gnm_style_get_pango_height (gnm_cell_get_effective_style (cell),
sheet->rendered_values->context,
sheet->last_zoom_factor_used);
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]