[gnumeric] Write diagonal borders to xlsx and fix reading of diagonal borders from xlsx files. [#652690]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Write diagonal borders to xlsx and fix reading of diagonal borders from xlsx files. [#652690]
- Date: Thu, 16 Jun 2011 19:01:30 +0000 (UTC)
commit fdb9cede16c6f0778e9f746c64eb1f1514a21237
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Thu Jun 16 13:00:00 2011 -0600
Write diagonal borders to xlsx and fix reading of diagonal borders from xlsx files. [#652690]
2011-06-16 Andreas J. Guelzow <aguelzow pyrshep ca>
* xlsx-write.c (xlsx_write_border): write diagonal border element
(xlsx_write_borders): support diagonal elements
* xlsx-read.c (xlsx_col_border_begin): new
(xlsx_border_end): fir reference counting
(xlsx_border_diagonal_end): new
NEWS | 1 +
plugins/excel/ChangeLog | 8 +++++
plugins/excel/xlsx-read.c | 63 +++++++++++++++++++++++++++++++++++++++++--
plugins/excel/xlsx-write.c | 47 +++++++++++++++++++++++++++-----
4 files changed, 108 insertions(+), 11 deletions(-)
---
diff --git a/NEWS b/NEWS
index f2b3176..73b2618 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ Andreas
* In xlsx files, do not ignore gradient cell background fills
completely. [#644496]
* Export some cell formatting to xlsx files. [#532635]
+ * Fix reading of diagonal borders from xlsx files. [#652690]
Morten:
* Fix leaks in SHEET. [#650761]
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 9681826..b3632f8 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,11 @@
+2011-06-16 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * xlsx-write.c (xlsx_write_border): write diagonal border element
+ (xlsx_write_borders): support diagonal elements
+ * xlsx-read.c (xlsx_col_border_begin): new
+ (xlsx_border_end): fir reference counting
+ (xlsx_border_diagonal_end): new
+
2011-06-15 Andreas J. Guelzow <aguelzow pyrshep ca>
* xlsx-write.c (xlsx_write_border): use edition 1 elements
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index dbafd27..147f3ab 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -3471,6 +3471,33 @@ xlsx_col_elem_begin (GsfXMLIn *xin, xmlChar const **attrs)
}
static void
+xlsx_col_border_begin (GsfXMLIn *xin, xmlChar const **attrs)
+{
+ XLSXReadState *state = (XLSXReadState *)xin->user_state;
+ gboolean diagonal_down = FALSE, diagonal_up = FALSE;
+
+ xlsx_col_elem_begin (xin, attrs);
+ for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
+ if (attr_bool (xin, attrs, "diagonalDown", &diagonal_down)) ;
+ else (attr_bool (xin, attrs, "diagonalUp", &diagonal_up)) ;
+
+ if (diagonal_up) {
+ GnmBorder *border = gnm_style_border_fetch
+ (GNM_STYLE_BORDER_THIN, style_color_black (), GNM_STYLE_BORDER_DIAGONAL);
+ gnm_style_set_border (state->style_accum,
+ MSTYLE_BORDER_DIAGONAL,
+ border);
+ }
+ if (diagonal_down) {
+ GnmBorder *border = gnm_style_border_fetch
+ (GNM_STYLE_BORDER_HAIR, style_color_black (), GNM_STYLE_BORDER_DIAGONAL);
+ gnm_style_set_border (state->style_accum,
+ MSTYLE_BORDER_REV_DIAGONAL,
+ border);
+ }
+}
+
+static void
xlsx_font_name (GsfXMLIn *xin, xmlChar const **attrs)
{
XLSXReadState *state = (XLSXReadState *)xin->user_state;
@@ -3683,6 +3710,36 @@ xlsx_border_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
gnm_style_set_border (state->style_accum,
GNM_STYLE_BORDER_LOCATION_TO_STYLE_ELEMENT (loc),
border);
+ state->border_color = NULL;
+}
+
+static void
+xlsx_border_diagonal_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+ XLSXReadState *state = (XLSXReadState *)xin->user_state;
+ GnmBorder *border, *new_border;
+
+ if (NULL == state->border_color)
+ state->border_color = style_color_black ();
+ new_border = gnm_style_border_fetch
+ (state->border_style, state->border_color, GNM_STYLE_BORDER_DIAGONAL);
+
+ border = gnm_style_get_border (state->style_accum, MSTYLE_BORDER_REV_DIAGONAL);
+ if (border != NULL && border->line_type != GNM_STYLE_BORDER_NONE) {
+ gnm_style_border_ref (new_border);
+ gnm_style_set_border (state->style_accum,
+ MSTYLE_BORDER_REV_DIAGONAL,
+ new_border);
+ }
+ border = gnm_style_get_border (state->style_accum, MSTYLE_BORDER_DIAGONAL);
+ if (border != NULL && border->line_type != GNM_STYLE_BORDER_NONE) {
+ gnm_style_border_ref (new_border);
+ gnm_style_set_border (state->style_accum,
+ MSTYLE_BORDER_DIAGONAL,
+ new_border);
+ }
+ gnm_style_border_unref (new_border);
+ state->border_color = NULL;
}
static void
@@ -3904,7 +3961,7 @@ GSF_XML_IN_NODE_FULL (START, STYLE_INFO, XL_NS_SS, "styleSheet", GSF_XML_NO_CONT
GSF_XML_IN_NODE_FULL (STYLE_INFO, BORDERS, XL_NS_SS, "borders", GSF_XML_NO_CONTENT,
FALSE, FALSE, &xlsx_collection_begin, &xlsx_collection_end, XLSX_COLLECT_BORDERS),
- GSF_XML_IN_NODE (BORDERS, BORDER, XL_NS_SS, "border", GSF_XML_NO_CONTENT, &xlsx_col_elem_begin, &xlsx_col_elem_end),
+ GSF_XML_IN_NODE (BORDERS, BORDER, XL_NS_SS, "border", GSF_XML_NO_CONTENT, &xlsx_col_border_begin, &xlsx_col_elem_end),
GSF_XML_IN_NODE_FULL (BORDER, LEFT_B, XL_NS_SS, "left", GSF_XML_NO_CONTENT, FALSE, FALSE,
&xlsx_border_begin, &xlsx_border_end, GNM_STYLE_BORDER_LEFT),
GSF_XML_IN_NODE (LEFT_B, LEFT_COLOR, XL_NS_SS, "color", GSF_XML_NO_CONTENT, &xlsx_border_color, NULL),
@@ -3923,8 +3980,8 @@ GSF_XML_IN_NODE_FULL (START, STYLE_INFO, XL_NS_SS, "styleSheet", GSF_XML_NO_CONT
GSF_XML_IN_NODE_FULL (BORDER, BOTTOM_B, XL_NS_SS, "bottom", GSF_XML_NO_CONTENT, FALSE, FALSE,
&xlsx_border_begin, &xlsx_border_end, GNM_STYLE_BORDER_BOTTOM),
GSF_XML_IN_NODE (BOTTOM_B, BOTTOM_COLOR, XL_NS_SS, "color", GSF_XML_NO_CONTENT, &xlsx_border_color, NULL),
- GSF_XML_IN_NODE_FULL (BORDER, DIAG_B, XL_NS_SS, "diagonal", GSF_XML_NO_CONTENT, FALSE, FALSE,
- &xlsx_border_begin, &xlsx_border_end, GNM_STYLE_BORDER_DIAG),
+ GSF_XML_IN_NODE (BORDER, DIAG_B, XL_NS_SS, "diagonal", GSF_XML_NO_CONTENT,
+ &xlsx_border_begin, &xlsx_border_diagonal_end),
GSF_XML_IN_NODE (DIAG_B, DIAG_COLOR, XL_NS_SS, "color", GSF_XML_NO_CONTENT, &xlsx_border_color, NULL),
GSF_XML_IN_NODE (BORDER, BORDER_VERT, XL_NS_SS, "vertical", GSF_XML_NO_CONTENT, NULL, NULL),
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 16dbd25..45075ee 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -593,6 +593,10 @@ xlsx_write_border (XLSXWriteState *state, GsfXMLOut *xml, GnmBorder *border, Gnm
gsf_xml_out_start_element (xml, "left");
/* gsf_xml_out_start_element (xml, "start"); (ECMA 376 2nd edition) */
break;
+ case MSTYLE_BORDER_DIAGONAL:
+ case MSTYLE_BORDER_REV_DIAGONAL:
+ gsf_xml_out_start_element (xml, "diagonal");
+ break;
default:
case MSTYLE_BORDER_RIGHT:
gsf_xml_out_start_element (xml, "right");
@@ -682,7 +686,22 @@ xlsx_write_borders (XLSXWriteState *state, GsfXMLOut *xml)
gsf_xml_out_add_int (xml, "count", styles_w_border->len);
for (i = 0 ; i < styles_w_border->len ; i++) {
GnmStyle const *style = g_ptr_array_index (styles_w_border, i);
+ gboolean diagonal_border_written = FALSE;
gsf_xml_out_start_element (xml, "border");
+ if (gnm_style_is_element_set (style, MSTYLE_BORDER_DIAGONAL)) {
+ GnmBorder *border = gnm_style_get_border
+ (style, MSTYLE_BORDER_DIAGONAL);
+ gsf_xml_out_add_bool
+ (xml, "diagonalUp",
+ (border->line_type != GNM_STYLE_BORDER_NONE));
+ }
+ if (gnm_style_is_element_set (style, MSTYLE_BORDER_REV_DIAGONAL)) {
+ GnmBorder *border = gnm_style_get_border
+ (style, MSTYLE_BORDER_REV_DIAGONAL);
+ gsf_xml_out_add_bool
+ (xml, "diagonalDown",
+ (border->line_type != GNM_STYLE_BORDER_NONE));
+ }
if (gnm_style_is_element_set (style, MSTYLE_BORDER_TOP))
xlsx_write_border (state, xml,
gnm_style_get_border
@@ -703,14 +722,26 @@ xlsx_write_borders (XLSXWriteState *state, GsfXMLOut *xml)
gnm_style_get_border
(style, MSTYLE_BORDER_RIGHT),
MSTYLE_BORDER_RIGHT);
- /* if (gnm_style_is_element_set (style, MSTYLE_BORDER_REV_DIAGONAL)) */
- /* xlsx_write_border (state, xml, */
- /* gnm_style_get_border */
- /* (MSTYLE_BORDER_REV_DIAGONAL)); */
- /* if (gnm_style_is_element_set (style, MSTYLE_BORDER_DIAGONAL)) */
- /* xlsx_write_border (state, xml, */
- /* gnm_style_get_border */
- /* (MSTYLE_BORDER_DIAGONAL)); */
+ if (gnm_style_is_element_set (style, MSTYLE_BORDER_DIAGONAL)) {
+ GnmBorder *border = gnm_style_get_border
+ (style, MSTYLE_BORDER_DIAGONAL);
+ if (border->line_type != GNM_STYLE_BORDER_NONE) {
+ diagonal_border_written = TRUE;
+ xlsx_write_border (state, xml,
+ border,
+ MSTYLE_BORDER_DIAGONAL);
+ }
+ }
+ if (!diagonal_border_written &&
+ gnm_style_is_element_set (style, MSTYLE_BORDER_REV_DIAGONAL)) {
+ GnmBorder *border = gnm_style_get_border
+ (style, MSTYLE_BORDER_REV_DIAGONAL);
+ if (border->line_type != GNM_STYLE_BORDER_NONE) {
+ xlsx_write_border (state, xml,
+ border,
+ MSTYLE_BORDER_REV_DIAGONAL);
+ }
+ }
gsf_xml_out_end_element (xml); /* border */
}
gsf_xml_out_end_element (xml);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]