Commit f4e2ea7e authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa
Browse files

Merge the style we just read with the existing information from the cell



1999-06-25  Miguel de Icaza  <miguel@gnu.org>

	* src/xml-io.c (xml_read_cell): Merge the style we just read with
	the existing information from the cell (which are the defaults).
	This is only for compatibility with the old format

1999-06-24  Miguel de Icaza  <miguel@gnu.org>

	* src/xml-io.c (style_font_new_from_x11): Implemented

	* src/style.c (style_font_new): Improved matching of the font.

	* src/xml-io.c 	(xml_write_style): Save Bold and Italic
	properties.  Save Units as double.
	(xml_read_style): Add conversion hook from old format.
	(xml_read_style): Load properly italic and bold properties.

	(xml_read_cell): Add new style reading code.  It is
	compatible with the old Style reading code.
	(xml_read_rows_info, xml_read_cols_info, xml_read_styles): Moved
	Cols, Rows and Styles loading code here, for code clarity.
parent a2afcaa3
1999-06-25 Miguel de Icaza <miguel@gnu.org>
* src/xml-io.c (xml_read_cell): Merge the style we just read with
the existing information from the cell (which are the defaults).
This is only for compatibility with the old format
1999-06-24 Miguel de Icaza <miguel@gnu.org>
* src/xml-io.c (xml_read_cell): Add new style reading code. It is
* src/xml-io.c (style_font_new_from_x11): Implemented
* src/style.c (style_font_new): Improved matching of the font.
* src/xml-io.c (xml_write_style): Save Bold and Italic
properties. Save Units as double.
(xml_read_style): Add conversion hook from old format.
(xml_read_style): Load properly italic and bold properties.
(xml_read_cell): Add new style reading code. It is
compatible with the old Style reading code.
(xml_read_rows_info, xml_read_cols_info, xml_read_styles): Moved
Cols, Rows and Styles loading code here, for code clarity.
* src/style.c (style_font_new_simple): Include the scale in the
key lookup variable.
......
1999-06-25 Miguel de Icaza <miguel@gnu.org>
* src/xml-io.c (xml_read_cell): Merge the style we just read with
the existing information from the cell (which are the defaults).
This is only for compatibility with the old format
1999-06-24 Miguel de Icaza <miguel@gnu.org>
* src/xml-io.c (xml_read_cell): Add new style reading code. It is
* src/xml-io.c (style_font_new_from_x11): Implemented
* src/style.c (style_font_new): Improved matching of the font.
* src/xml-io.c (xml_write_style): Save Bold and Italic
properties. Save Units as double.
(xml_read_style): Add conversion hook from old format.
(xml_read_style): Load properly italic and bold properties.
(xml_read_cell): Add new style reading code. It is
compatible with the old Style reading code.
(xml_read_rows_info, xml_read_cols_info, xml_read_styles): Moved
Cols, Rows and Styles loading code here, for code clarity.
* src/style.c (style_font_new_simple): Include the scale in the
key lookup variable.
......
......@@ -3,7 +3,7 @@
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
* (C) 1998 Miguel de Icaza
* (C) 1998, 1999 Miguel de Icaza
*/
#include <config.h>
#include <gnome.h>
......@@ -129,7 +129,12 @@ style_font_new (const char *font_name, double size, double scale, int bold, int
font = style_font_new_simple (font_name, size, scale, bold, italic);
if (!font){
font = gnumeric_default_font;
if (bold)
font = gnumeric_default_bold_font;
else if (italic)
font = gnumeric_default_italic_font;
else
font = gnumeric_default_font;
style_font_ref (font);
}
......@@ -615,19 +620,24 @@ font_init (void)
if (!gnumeric_default_font)
g_error ("Could not load the default font");
g_warning ("Using hard coded 14!\n");
gnumeric_default_bold_font = style_font_new (DEFAULT_FONT, 14, 1.0, TRUE, FALSE);
gnumeric_default_italic_font = style_font_new (DEFAULT_FONT, 14, 1.0, FALSE, TRUE);
printf ("Font: %s\n", gnumeric_default_bold_font->dfont->x_font_name);
{
static int warning_shown;
/*
* Load bold font
*/
gnumeric_default_bold_font = style_font_new_simple (
DEFAULT_FONT, DEFAULT_SIZE, 1.0, TRUE, FALSE);
if (gnumeric_default_bold_font == NULL){
gnumeric_default_bold_font = gnumeric_default_font;
style_font_ref (gnumeric_default_bold_font);
}
if (!warning_shown){
g_warning ("Style created with scale is 1.0");
warning_shown = TRUE;
}
/*
* Load italic font
*/
gnumeric_default_italic_font = style_font_new_simple (
DEFAULT_FONT, DEFAULT_SIZE, 1.0, FALSE, TRUE);
if (gnumeric_default_italic_font == NULL){
gnumeric_default_italic_font = gnumeric_default_font;
style_font_ref (gnumeric_default_italic_font);
}
}
......
......@@ -599,7 +599,7 @@ xml_read_style_border (parse_xml_context_t *ctxt, xmlNodePtr tree)
{
StyleBorder *ret;
StyleBorderType style [4] = { BORDER_NONE, BORDER_NONE, BORDER_NONE, BORDER_NONE };
StyleColor *color [4] = { NULL, NULL, NULL, NULL };
StyleColor *color [4] = { NULL, NULL, NULL, NULL };
xmlNodePtr side;
int lp;
......@@ -663,7 +663,9 @@ xml_write_style (parse_xml_context_t *ctxt, Style *style, int style_idx)
child = xmlNewChild (cur, ctxt->ns, "Font",
xmlEncodeEntities(ctxt->doc,
style->font->font_name));
xml_set_value_int (child, "Unit", style->font->size);
xml_set_value_double (child, "Unit", style->font->size);
xml_set_value_int (child, "Bold", style->font->is_bold);
xml_set_value_int (child, "Italic", style->font->is_italic);
}
......@@ -676,6 +678,63 @@ xml_write_style (parse_xml_context_t *ctxt, Style *style, int style_idx)
return cur;
}
static const char *
font_component (const char *fontname, int idx)
{
int i = 0;
const char *p = fontname;
for (; *p && i < idx; p++){
if (*p == '-')
i++;
}
if (*p == '-')
p++;
return p;
}
/**
* style_font_new_from_x11:
* @fontname: an X11-like font name.
* @scale: scale desired
*
* Tries to guess the fontname, the weight and italization parameters
* to invoke style_font_new
*
* Returns: A valid style font.
*/
static StyleFont *
style_font_new_from_x11 (const char *fontname, double units, double scale)
{
StyleFont *sf;
char *typeface = "Helvetica";
int is_bold = 0;
int is_italic = 0;
char *c;
/*
* FIXME: we should do something about the typeface instead
* of hardcoding it to helvetica.
*/
c = font_component (fontname, 2);
if (strncmp (c, "bold", 4) == 0)
is_bold = 1;
c = font_component (fontname, 3);
if (strncmp (c, "o", 1) == 0)
is_italic = 1;
if (strncmp (c, "i", 1) == 0)
is_italic = 1;
sf = style_font_new (typeface, units, scale, is_bold, is_italic);
if (sf == NULL)
sf = style_font_new_from (gnumeric_default_font, scale);
return sf;
}
/*
* Create a Style equivalent to the XML subtree of doc.
*/
......@@ -739,12 +798,28 @@ xml_read_style (parse_xml_context_t *ctxt, xmlNodePtr tree, Style * ret)
while (child != NULL){
if (!strcmp (child->name, "Font")){
char *font;
int units = 14;
xml_get_value_int (child, "Unit", &units);
double units = 14;
int is_bold = 0;
int is_italic = 0;
int t;
xml_get_value_double (child, "Unit", &units);
if (xml_get_value_int (child, "Bold", &t))
is_bold = t;
if (xml_get_value_int (child, "Italic", &t))
is_italic = t;
font = xmlNodeGetContent(child);
if (font != NULL) {
ret->font = style_font_new (font, units, 1.0, 0, 0);
StyleFont *sf;
if (*font == '-'){
sf = style_font_new_from_x11 (font, units, 1.0);
} else
sf = style_font_new (font, units, 1.0, is_bold, is_italic);
ret->font = sf;
free(font);
}
if (ret->font){
......@@ -1046,8 +1121,20 @@ xml_read_cell (parse_xml_context_t *ctxt, xmlNodePtr tree)
style_read = TRUE;
s = g_hash_table_lookup (ctxt->style_table, GINT_TO_POINTER (style_idx));
if (s){
Style *copy;
/*
* The main style is the style we read, but this
* style might be incomplete (ie, older formats might
* not have full styles.
*
* so we merge the missing bits from the current cell
* style
*/
copy = style_duplicate (s);
style_merge_to (copy, ret->style);
style_destroy (ret->style);
ret->style = style_duplicate (s);
ret->style = copy;
} else {
printf ("Error: could not find style %d\n", style_idx);
}
......@@ -1541,6 +1628,9 @@ xml_probe (const char *filename)
}
gmr = xmlSearchNsByHref (res, res->root, "http://www.gnome.org/gnumeric/");
if (gmr == NULL)
gmr = xmlSearchNsByHref (res, res->root, "http://www.gnome.org/gnumeric/v2");
if (res->root->name == NULL || strcmp (res->root->name, "Workbook") || (gmr == NULL)){
xmlFreeDoc (res);
return FALSE;
......@@ -1669,6 +1759,8 @@ gnumeric_xml_read_workbook (const char *filename)
* Do a bit of checking, get the namespaces, and chech the top elem.
*/
gmr = xmlSearchNsByHref (res, res->root, "http://www.gnome.org/gnumeric/");
if (gmr == NULL)
gmr = xmlSearchNsByHref (res, res->root, "http://www.gnome.org/gnumeric/v2");
if (strcmp (res->root->name, "Workbook") || (gmr == NULL)){
fprintf (stderr, "gnumeric_xml_read_workbook %s: not an Workbook file\n",
filename);
......
Supports Markdown
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