Commit 02221684 authored by Morten Welinder's avatar Morten Welinder

Fix sharing of fonts during writes.

parent 44095eb9
1999-06-09 Morten Welinder <terra@diku.dk>
* src/xml-io.c: Fix major thinko in writing fonts. (The name hash
table was used to look up a font, which always failed since keys
are names in that hash.)
1999-06-09 Nat Friedman <nat@gnome-support.com>
* src/sheet-view.c (sheet_view_insert_object): Commented out call
......
1999-06-09 Morten Welinder <terra@diku.dk>
* src/xml-io.c: Fix major thinko in writing fonts. (The name hash
table was used to look up a font, which always failed since keys
are names in that hash.)
1999-06-09 Nat Friedman <nat@gnome-support.com>
* src/sheet-view.c (sheet_view_insert_object): Commented out call
......
1999-06-09 Morten Welinder <terra@diku.dk>
* src/xml-io.c: Fix major thinko in writing fonts. (The name hash
table was used to look up a font, which always failed since keys
are names in that hash.)
1999-06-09 Nat Friedman <nat@gnome-support.com>
* src/sheet-view.c (sheet_view_insert_object): Commented out call
......
1999-06-09 Morten Welinder <terra@diku.dk>
* src/xml-io.c: Fix major thinko in writing fonts. (The name hash
table was used to look up a font, which always failed since keys
are names in that hash.)
1999-06-09 Nat Friedman <nat@gnome-support.com>
* src/sheet-view.c (sheet_view_insert_object): Commented out call
......
......@@ -9,11 +9,18 @@ GNOME Spread Sheet task list
A4 -> $A$4 -> $A4 -> A$4 -> A4
* Even More Functions
FORECAST, FTEST, GROWTH, INTERCEPT, LINEST, LOGEST, PERCENTILE,
QUARTILE, TREND, TTEST, ERROR.TYPE.
(This is not a claim that these are all.)
* Cell range naming
Finish implementing.
* Cell dimensio computation is broken on font change for multilines.
* Cell dimension computation is broken on font change for multilines.
* Number formatting
......
......@@ -22,13 +22,14 @@
* A parsing context.
*/
typedef struct parseXmlContext {
xmlDocPtr doc; /* Xml document */
xmlNsPtr ns; /* Main name space */
xmlNodePtr parent; /* used only for g_hash_table_foreach callbacks */
GHashTable *nameTable; /* to reproduce multiple refs with HREFs */
int fontIdx; /* for Font refs names ... */
Sheet *sheet; /* the associated sheet */
Workbook *wb; /* the associated sheet */
xmlDocPtr doc; /* Xml document */
xmlNsPtr ns; /* Main name space */
xmlNodePtr parent; /* used only for g_hash_table_foreach callbacks */
GHashTable *nameTable; /* to reproduce multiple refs with HREFs */
int fontIdx; /* for Font refs names ... */
GHashTable *fontname2name; /* For re-using fonts during writes */
Sheet *sheet; /* the associated sheet */
Workbook *wb; /* the associated sheet */
} parseXmlContext, *parseXmlContextPtr;
static Sheet *readXmlSheet (parseXmlContextPtr ctxt, xmlNodePtr tree);
......@@ -39,6 +40,8 @@ static xmlNodePtr writeXmlWorkbook (parseXmlContextPtr ctxt, Workbook *wb);
static gint ptrCompare (gconstpointer a, gconstpointer b); */
static void nameFree (gpointer key, gpointer value,
gpointer user_data);
static void fontname_nameFree (gpointer key, gpointer value,
gpointer user_data);
/*
* Internal stuff: xml helper functions.
......@@ -540,6 +543,7 @@ Sheet *gnumericReadXmlSheet (const char *filename)
ctxt.ns = gmr;
ctxt.nameTable = g_hash_table_new (g_str_hash, g_str_equal);
ctxt.fontIdx = 1;
ctxt.fontname2name = NULL;
sheet = readXmlSheet (&ctxt, res->root);
g_hash_table_foreach (ctxt.nameTable, nameFree, NULL);
g_hash_table_destroy (ctxt.nameTable);
......@@ -580,9 +584,12 @@ gnumericWriteXmlSheet (Sheet * sheet, const char *filename)
ctxt.ns = gmr;
ctxt.nameTable = g_hash_table_new (g_str_hash, g_str_equal);
ctxt.fontIdx = 1;
ctxt.fontname2name = g_hash_table_new (g_str_hash, g_str_equal);
xml->root = writeXmlSheet (&ctxt, sheet);
g_hash_table_foreach (ctxt.nameTable, nameFree, NULL);
g_hash_table_destroy (ctxt.nameTable);
g_hash_table_foreach (ctxt.fontname2name, fontname_nameFree, NULL);
g_hash_table_destroy (ctxt.fontname2name);
/*
* Dump it.
......@@ -636,6 +643,7 @@ Workbook *gnumericReadXmlWorkbook (const char *filename)
ctxt.ns = gmr;
ctxt.nameTable = g_hash_table_new (g_str_hash, g_str_equal);
ctxt.fontIdx = 1;
ctxt.fontname2name = NULL;
wb = readXmlWorkbook (&ctxt, res->root);
workbook_set_filename (wb, (char *) filename);
workbook_recalc_all (wb);
......@@ -675,9 +683,12 @@ gnumericWriteXmlWorkbook (Workbook *wb, const char *filename)
ctxt.ns = gmr;
ctxt.nameTable = g_hash_table_new (g_str_hash, g_str_equal);
ctxt.fontIdx = 1;
ctxt.fontname2name = g_hash_table_new (g_str_hash, g_str_equal);
xml->root = writeXmlWorkbook (&ctxt, wb);
g_hash_table_foreach (ctxt.nameTable, nameFree, NULL);
g_hash_table_destroy (ctxt.nameTable);
g_hash_table_foreach (ctxt.fontname2name, fontname_nameFree, NULL);
g_hash_table_destroy (ctxt.fontname2name);
/*
* Dump it.
......@@ -705,6 +716,16 @@ nameFree (gpointer key, gpointer value, gpointer user_data)
g_free (key);
}
/*
* Free a fontname and name when cleaning up the name Hash table.
*/
static void
fontname_nameFree (gpointer key, gpointer value, gpointer user_data)
{
g_free (key);
g_free (value);
}
static int
style_is_default_fore (StyleColor *color)
{
......@@ -818,7 +839,6 @@ writeXmlStyle (parseXmlContextPtr ctxt, Style * style)
{
xmlNodePtr cur, child;
char str[50];
char *name;
if ((style->halign == 0) && (style->valign == 0) &&
(style->orientation == 0) && (style->format == NULL) &&
......@@ -843,8 +863,10 @@ writeXmlStyle (parseXmlContextPtr ctxt, Style * style)
}
if (style->font != NULL){
if ((name = (char *)
g_hash_table_lookup (ctxt->nameTable, style->font)) != NULL){
const char *name;
name = (const char *) g_hash_table_lookup (ctxt->fontname2name,
style->font->font_name);
if (name) {
child = xmlNewChild (cur, ctxt->ns, "Font", NULL);
sprintf (str, "#%s", name);
xmlNewProp (child, "HREF", str);
......@@ -856,8 +878,10 @@ writeXmlStyle (parseXmlContextPtr ctxt, Style * style)
sprintf (str, "FontDef%d", ctxt->fontIdx++);
xmlNewProp (child, "NAME", str);
g_hash_table_insert (ctxt->nameTable, g_strdup (str), style->font);
g_hash_table_insert (ctxt->fontname2name,
g_strdup (style->font->font_name),
g_strdup (str));
}
}
if (style->border != NULL){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment