[gnumeric] xlsx: write only rich text attributes that are present.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xlsx: write only rich text attributes that are present.
- Date: Tue, 3 Jun 2014 23:48:52 +0000 (UTC)
commit 66eafd9bffc1be47ec46d3378c5a26a72e56d543
Author: Morten Welinder <terra gnome org>
Date: Tue Jun 3 19:48:30 2014 -0400
xlsx: write only rich text attributes that are present.
plugins/excel/ChangeLog | 3 +-
plugins/excel/xlsx-write.c | 78 ++++++++++++++++++++++++++-----------------
2 files changed, 49 insertions(+), 32 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index d8db297..a6e7f1f 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,6 +1,7 @@
2014-06-03 Morten Welinder <terra gnome org>
- * xlsx-write.c (xlsx_write_rich_text): Add two missing "break;"
+ * xlsx-write.c (xlsx_write_rich_text): Add two missing "break;".
+ Write only attributes that are present.
(xlsx_write_shared_strings): Handle rich text.
* xlsx-read.c (xlsx_run_color): Handle indexed colours.
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 6d979cf..21b47b5 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -267,9 +267,7 @@ static void
xlsx_write_rich_text (GsfXMLOut *xml, char const *text, PangoAttrList *attrs)
{
PangoAttrIterator *iter;
- PangoAttribute *attr;
int start, end, max;
- char *buf;
if (attrs == NULL) {
gsf_xml_out_start_element (xml, "t");
@@ -281,42 +279,60 @@ xlsx_write_rich_text (GsfXMLOut *xml, char const *text, PangoAttrList *attrs)
max = strlen (text);
iter = pango_attr_list_get_iterator (attrs);
do {
+ PangoAttribute *attr;
+
gsf_xml_out_start_element (xml, "r");
gsf_xml_out_start_element (xml, "rPr");
- gsf_xml_out_start_element (xml, "rFont");
+
attr = pango_attr_iterator_get (iter, PANGO_ATTR_FAMILY);
- gsf_xml_out_add_cstr_unchecked (xml, "val", (attr)? ((PangoAttrString *) attr)->value:
"Calibri");
- gsf_xml_out_end_element (xml); /* </rFont> */
- gsf_xml_out_start_element (xml, "b");
+ if (attr) {
+ gsf_xml_out_start_element (xml, "rFont");
+ gsf_xml_out_add_cstr_unchecked (xml, "val", ((PangoAttrString *) attr)->value);
+ gsf_xml_out_end_element (xml); /* </rFont> */
+ }
+
attr = pango_attr_iterator_get (iter, PANGO_ATTR_WEIGHT);
- gsf_xml_out_add_cstr_unchecked (xml, "val", (attr && ((PangoAttrInt *) attr)->value >
PANGO_WEIGHT_NORMAL)? "true": "false");
- gsf_xml_out_end_element (xml); /* </b> */
- gsf_xml_out_start_element (xml, "i");
+ if (attr) {
+ gsf_xml_out_start_element (xml, "b");
+ gsf_xml_out_add_cstr_unchecked (xml, "val", ((PangoAttrInt *) attr)->value >
PANGO_WEIGHT_NORMAL ? "true": "false");
+ gsf_xml_out_end_element (xml); /* </b> */
+ }
+
attr = pango_attr_iterator_get (iter, PANGO_ATTR_STYLE);
- gsf_xml_out_add_cstr_unchecked (xml, "val", (attr && ((PangoAttrInt *) attr)->value !=
PANGO_STYLE_NORMAL)? "true": "false");
- gsf_xml_out_end_element (xml); /* </i> */
- gsf_xml_out_start_element (xml, "strike");
+ if (attr) {
+ gsf_xml_out_start_element (xml, "i");
+ gsf_xml_out_add_cstr_unchecked (xml, "val", ((PangoAttrInt *) attr)->value !=
PANGO_STYLE_NORMAL ? "true": "false");
+ gsf_xml_out_end_element (xml); /* </i> */
+ }
+
attr = pango_attr_iterator_get (iter, PANGO_ATTR_STRIKETHROUGH);
- gsf_xml_out_add_cstr_unchecked (xml, "val", (attr && ((PangoAttrInt *) attr)->value)? "true":
"false");
- gsf_xml_out_end_element (xml); /* </strike> */
- gsf_xml_out_start_element (xml, "color");
+ if (attr) {
+ gsf_xml_out_start_element (xml, "strike");
+ gsf_xml_out_add_cstr_unchecked (xml, "val", ((PangoAttrInt *) attr)->value ? "true":
"false");
+ gsf_xml_out_end_element (xml); /* </strike> */
+ }
+
attr = pango_attr_iterator_get (iter, PANGO_ATTR_FOREGROUND);
if (attr) {
PangoColor *color = &((PangoAttrColor *) attr)->color;
- buf = g_strdup_printf("FF%2x%2x%2x", color->red >> 8, color->green >> 8, color->blue
8);
+ char *buf = g_strdup_printf("FF%2x%2x%2x", color->red >> 8, color->green >> 8,
color->blue >> 8);
+ gsf_xml_out_start_element (xml, "color");
gsf_xml_out_add_cstr_unchecked (xml, "rgb", buf);
+ gsf_xml_out_end_element (xml); /* </color> */
g_free (buf);
- } else
- gsf_xml_out_add_cstr_unchecked (xml, "rgb", "FF000000");
- gsf_xml_out_end_element (xml); /* </color> */
- gsf_xml_out_start_element (xml, "sz");
+ }
+
attr = pango_attr_iterator_get (iter, PANGO_ATTR_SIZE);
- gsf_xml_out_add_uint (xml, "val", (attr)? ((PangoAttrInt *) attr)->value / PANGO_SCALE: 8);
- gsf_xml_out_end_element (xml); /* </sz> */
- gsf_xml_out_start_element (xml, "u");
+ if (attr) {
+ gsf_xml_out_start_element (xml, "sz");
+ gsf_xml_out_add_uint (xml, "val", ((PangoAttrInt *) attr)->value / PANGO_SCALE);
+ gsf_xml_out_end_element (xml); /* </sz> */
+ }
+
attr = pango_attr_iterator_get (iter, PANGO_ATTR_UNDERLINE);
if (attr) {
PangoUnderline u = ((PangoAttrInt *) attr)->value;
+ gsf_xml_out_start_element (xml, "u");
switch (u) {
case PANGO_UNDERLINE_NONE:
default:
@@ -335,20 +351,20 @@ xlsx_write_rich_text (GsfXMLOut *xml, char const *text, PangoAttrList *attrs)
gsf_xml_out_add_cstr_unchecked (xml, "val", "singleAccounting");
break;
}
- } else
- gsf_xml_out_add_cstr_unchecked (xml, "val", "none");
- gsf_xml_out_end_element (xml); /* </u> */
+ gsf_xml_out_end_element (xml); /* </u> */
+ }
+
gsf_xml_out_end_element (xml); /* </rPr> */
gsf_xml_out_start_element (xml, "t");
gsf_xml_out_add_cstr_unchecked (xml, "xml:space", "preserve");
pango_attr_iterator_range (iter, &start, &end);
if (end > max)
end = max;
- if (start > end)
- start = end;
- buf = g_strndup (text + start, end - start);
- gsf_xml_out_add_cstr (xml, NULL, buf);
- g_free (buf);
+ if (start < end) {
+ char *buf = g_strndup (text + start, end - start);
+ gsf_xml_out_add_cstr (xml, NULL, buf);
+ g_free (buf);
+ }
gsf_xml_out_end_element (xml); /* </t> */
gsf_xml_out_end_element (xml); /* </r> */
} while (pango_attr_iterator_next (iter));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]