Commit 840607cd authored by Michael Meeks's avatar Michael Meeks
Browse files

Fix lots of the same bugs due to patching cockup,

Get shot of most Style * uses,
Clean html plugin,
minor bug fixes.
parent 36760f3d
No preview for this file type
No preview for this file type
......@@ -1024,8 +1024,9 @@ ms_excel_get_style_from_xf (ExcelSheet *sheet, guint16 xfidx)
StyleColor *fore, *back, *basefore;
int back_index;
MStyle *mstyle;
Range range;
g_return_val_if_fail (xf, NULL);
g_return_val_if_fail (xf != NULL, NULL);
if (xf->mstyle != NULL)
return xf->mstyle;
......@@ -1071,6 +1072,9 @@ ms_excel_get_style_from_xf (ExcelSheet *sheet, guint16 xfidx)
g_return_val_if_fail (back && fore, NULL);
/*
* This is riddled with leaking StyleColor references !
*/
mstyle_set_color (mstyle, MSTYLE_COLOR_FORE, fore);
mstyle_set_color (mstyle, MSTYLE_COLOR_BACK, back);
......
......@@ -167,15 +167,10 @@ gnumeric_cell (FunctionEvalInfo *ei, Value **argv)
*/
return value_new_error (&ei->pos, _("Unimplemented"));
} else if (!g_strcasecmp (info_type, "format")) {
Cell *cell = sheet_cell_get (ei->pos.sheet, ref.col, ref.row);
if (cell && CELL_IS_FORMAT_SET (cell)) {
Style *style = cell_get_style (cell);
Value *val = translate_cell_format (style->format);
style_unref (style);
return val;
} else
return value_new_string ("G");
MStyle *mstyle = sheet_style_compute (ei->pos.sheet, ref.col, ref.row);
Value *val = translate_cell_format (mstyle_get_format (mstyle));
mstyle_unref (mstyle);
return val;
} else if (!g_strcasecmp (info_type, "prefix")) {
/* Text value corresponding to the "label prefix" of the cell.
* Returns single quotation mark (') if the cell contains
......
1999-10-24 Michael Meeks <mmeeks@gnu.org>
* html.c (html_write_cell_str): move common code here.
(html_read): Update style setting.
(html_cell_bold, html_cell_italic): kill.
(html_write_cell32, html_write_cell40): update style bits.
* font.c (font_get_size): kill ( mstyle_get_font_size )
(font_match): Move common code here.
(font_is_helvetica, font_is_monospaced, font_is_sansserif): update.
* epsf.c (epsf_write_cell): Kill 'Style'
1999-10-20 Michael Meeks <mmeeks@gnu.org>
* roff.c (write_wb_roff): kill leak.
......
......@@ -41,78 +41,78 @@
static void
epsf_write_cell (FILE *fp, Cell *cell, float x, float y)
{
Style *style;
MStyle *mstyle;
int cell_width, cell_height;
RGB_t rgb;
int font_size;
if (!cell) { /* empty cell */
if (!cell) /* empty cell */
return;
} else {
style = cell_get_style (cell);
if (!style) {
/* is this case posible? */
return;
else {
mstyle = cell_get_mstyle (cell);
g_return_if_fail (mstyle != NULL);
rgb.r = mstyle_get_color (mstyle, MSTYLE_COLOR_BACK)->color.red >> 8;
rgb.g = mstyle_get_color (mstyle, MSTYLE_COLOR_BACK)->color.green >> 8;
rgb.b = mstyle_get_color (mstyle, MSTYLE_COLOR_BACK)->color.blue >> 8;
ps_set_color (fp, &rgb);
cell_width = CELL_WIDTH (cell);
cell_height = CELL_HEIGHT (cell);
ps_box_filled (fp, x, y, cell_width, cell_height);
rgb.r = mstyle_get_color (mstyle, MSTYLE_COLOR_FORE)->color.red >> 8;
rgb.g = mstyle_get_color (mstyle, MSTYLE_COLOR_FORE)->color.green >> 8;
rgb.b = mstyle_get_color (mstyle, MSTYLE_COLOR_FORE)->color.blue >> 8;
ps_set_color (fp, &rgb);
ps_box_bordered (fp, x, y, cell_width, cell_height, 0.5);
font_size = mstyle_get_font_size (mstyle);
if (!font_size)
font_size = 10;
if (font_is_sansserif (mstyle)) {
if (mstyle_get_font_bold (mstyle) &&
mstyle_get_font_italic (mstyle))
ps_set_font (fp, HELVETICA_BOLD_OBLIQUE, font_size);
else if (mstyle_get_font_bold (mstyle))
ps_set_font (fp, HELVETICA_BOLD, font_size);
else if (mstyle_get_font_italic (mstyle))
ps_set_font (fp, HELVETICA_OBLIQUE, font_size);
else
ps_set_font (fp, HELVETICA, font_size);
} else if (font_is_monospaced (mstyle)) {
if (mstyle_get_font_bold (mstyle) &&
mstyle_get_font_italic (mstyle))
ps_set_font (fp, COURIER_BOLD_ITALIC, font_size);
else if (mstyle_get_font_bold (mstyle))
ps_set_font (fp, COURIER_BOLD, font_size);
else if (mstyle_get_font_italic (mstyle))
ps_set_font (fp, COURIER_ITALIC, font_size);
else
ps_set_font (fp, COURIER, font_size);
} else {
rgb.r = style->back_color->color.red >> 8;
rgb.g = style->back_color->color.green >> 8;
rgb.b = style->back_color->color.blue >> 8;
ps_set_color (fp, &rgb);
cell_width = CELL_WIDTH(cell);
cell_height= CELL_HEIGHT(cell);
ps_box_filled (fp, x, y, cell_width, cell_height);
rgb.r = style->fore_color->color.red >> 8;
rgb.g = style->fore_color->color.green >> 8;
rgb.b = style->fore_color->color.blue >> 8;
ps_set_color (fp, &rgb);
ps_box_bordered (fp, x, y, cell_width, cell_height, 0.5);
font_size = font_get_size (style);
if (!font_size)
font_size = 10;
if (font_is_sansserif (style)) {
if (style->font->is_bold && style->font->is_italic)
ps_set_font (fp, HELVETICA_BOLD_OBLIQUE, font_size);
else if (style->font->is_bold)
ps_set_font (fp, HELVETICA_BOLD, font_size);
else if (style->font->is_italic)
ps_set_font (fp, HELVETICA_OBLIQUE, font_size);
else
ps_set_font (fp, HELVETICA, font_size);
} else if (font_is_monospaced (style)) {
if (style->font->is_bold && style->font->is_italic)
ps_set_font (fp, COURIER_BOLD_ITALIC, font_size);
else if (style->font->is_bold)
ps_set_font (fp, COURIER_BOLD, font_size);
else if (style->font->is_italic)
ps_set_font (fp, COURIER_ITALIC, font_size);
else
ps_set_font (fp, COURIER, font_size);
} else {
if (style->font->is_bold && style->font->is_italic)
ps_set_font (fp, TIMES_BOLD_ITALIC, font_size);
else if (style->font->is_bold)
ps_set_font (fp, TIMES_BOLD, font_size);
else if (style->font->is_italic)
ps_set_font (fp, TIMES_ITALIC, font_size);
else
ps_set_font (fp, TIMES, font_size);
}
if (style->halign & HALIGN_RIGHT)
ps_text_right (fp, cell->text->str,
x + cell_width - 2, y+2 + (font_size/3));
else if (style->halign & HALIGN_CENTER)
ps_text_center (fp, cell->text->str,
x + 2, x + cell_width - 2, y+2 + (font_size/3));
if (mstyle_get_font_bold (mstyle) &&
mstyle_get_font_italic (mstyle))
ps_set_font (fp, TIMES_BOLD_ITALIC, font_size);
else if (mstyle_get_font_bold (mstyle))
ps_set_font (fp, TIMES_BOLD, font_size);
else if (mstyle_get_font_italic (mstyle))
ps_set_font (fp, TIMES_ITALIC, font_size);
else
ps_text_left (fp, cell->text->str, x+2, y+2 + (font_size/3));
ps_write_raw (fp, "\n");
ps_set_font (fp, TIMES, font_size);
}
style_unref (style);
if (mstyle_get_align_h (mstyle) & HALIGN_RIGHT)
ps_text_right (fp, cell->text->str,
x + cell_width - 2, y+2 + (font_size/3));
else if (mstyle_get_align_h (mstyle) & HALIGN_CENTER)
ps_text_center (fp, cell->text->str,
x + 2, x + cell_width - 2, y + 2 + (font_size / 3));
else
ps_text_left (fp, cell->text->str, x + 2, y + 2 + (font_size / 3));
ps_write_raw (fp, "\n");
}
mstyle_unref (mstyle);
}
/*
......
......@@ -23,24 +23,21 @@
#include "config.h"
#include "font.h"
/*
*/
int
font_is_monospaced (Style *style)
static int
font_match (MStyle *mstyle, char **names)
{
char *name[] = {"Courier", "fixed", NULL};
int i;
const char *font_name;
if (!style)
return 0;
if (!style->font)
return 0;
if (!style->font->font_name)
if (!mstyle)
return 0;
font_name = mstyle_get_font_name (mstyle);
/* printf ("%s\n", style->font->font_name); */
for (i = 0; name[i]; i++) {
if (strcmp (name[i], style->font->font_name) == 0)
g_return_val_if_fail (names != NULL, 0);
g_return_val_if_fail (font_name != NULL, 0);
for (i = 0; names[i]; i++) {
if (strcasecmp (font_name, names[i]) == 0)
return 1;
}
return 0;
......@@ -49,54 +46,32 @@ font_is_monospaced (Style *style)
/*
*/
int
font_is_helvetica (Style *style)
font_is_monospaced (MStyle *mstyle)
{
if (!style)
return 0;
if (!style->font)
return 0;
if (!style->font->font_name)
return 0;
char *names[] = { "Courier", "fixed", NULL };
if (strcmp ("Helvetica", style->font->font_name) == 0)
return 1;
return 0;
return font_match (mstyle, names);
}
/*
*/
int
font_is_sansserif (Style *style)
font_is_helvetica (MStyle *mstyle)
{
int i;
char *name[] = {
"helvetica","avantgarde","neep","blippo","capri","clean","fixed",NULL};
if (!style)
return 0;
if (!style->font)
return 0;
if (!style->font->font_name)
return 0;
char *names [] = { "Helvetica", NULL };
for (i = 0; name[i]; i++) {
if (strcasecmp (style->font->font_name, name[i]) == 0)
return 1;
}
return 0;
return font_match (mstyle, names);
}
/*
*/
int
font_get_size (Style *style)
font_is_sansserif (MStyle *mstyle)
{
if (!style)
return 0;
if (!style->font)
return 0;
char *names [] = { "helvetica", "avantgarde",
"neep", "blippo", "capri",
"clean", "fixed", NULL };
/* printf ("%f %f\n", style->font->size, style->font->scale); */
return ((int)style->font->size);
return font_match (mstyle, names);
}
......@@ -25,10 +25,9 @@
#include "../../src/gnumeric.h"
#include "../../src/gnumeric-util.h"
int font_is_monospaced (Style *style);
int font_is_helvetica (Style *style);
int font_is_sansserif (Style *style);
int font_get_size (Style *style);
int font_is_monospaced (MStyle *mstyle);
int font_is_helvetica (MStyle *mstyle);
int font_is_sansserif (MStyle *mstyle);
#endif
......@@ -56,67 +56,73 @@ html_fprintf (FILE *fp, const char *s)
return len;
}
static void
html_write_cell_str (FILE *fp, Cell *cell, MStyle *mstyle)
{
if (font_is_monospaced (mstyle))
fprintf (fp, "<TT>");
if (mstyle_get_font_bold (mstyle))
fprintf (fp, "<B>");
if (mstyle_get_font_italic (mstyle))
fprintf (fp, "<I>");
html_fprintf (fp, cell->text->str);
if (mstyle_get_font_italic (mstyle))
fprintf (fp, "</I>");
if (mstyle_get_font_bold (mstyle))
fprintf (fp, "</B>");
if (font_is_monospaced (mstyle))
fprintf (fp, "</TT>");
}
/*
* write a TD
*/
static void
html_write_cell32 (FILE *fp, Cell *cell)
{
Style *style;
MStyle *mstyle;
unsigned char r, g, b;
if (!cell) { /* empty cell */
fprintf (fp, "\t<TD>");
} else {
style = cell_get_style (cell);
if (!style) {
/* is this case posible? */
html_fprintf (fp, cell->text->str);
} else {
switch (cell_get_horizontal_align (cell, style->halign)) {
case HALIGN_RIGHT :
fprintf (fp, " align=right");
break;
case HALIGN_CENTER :
fprintf (fp, " align=center");
break;
default :
break;
}
if (style->valign & VALIGN_TOP)
fprintf (fp, " valign=top");
r = style->back_color->color.red >> 8;
g = style->back_color->color.green >> 8;
b = style->back_color->color.blue >> 8;
if (r != 255 || g != 255 || b != 255)
fprintf (fp, " bgcolor=\"#%02X%02X%02X\"", r, g, b);
fprintf (fp, ">");
r = style->fore_color->color.red >> 8;
g = style->fore_color->color.green >> 8;
b = style->fore_color->color.blue >> 8;
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "<FONT color=\"#%02X%02X%02X\">",
r, g, b);
if (font_is_monospaced (style))
fprintf (fp, "<TT>");
if (style->font->is_bold)
fprintf (fp, "<B>");
if (style->font->is_italic)
fprintf (fp, "<I>");
html_fprintf (fp, cell->text->str);
if (style->font->is_italic)
fprintf (fp, "</I>");
if (style->font->is_bold)
fprintf (fp, "</B>");
if (font_is_monospaced (style))
fprintf (fp, "</TT>");
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "</FONT>");
mstyle = cell_get_mstyle (cell);
g_return_if_fail (mstyle != NULL);
switch (cell_get_horizontal_align (cell,
mstyle_get_align_h (mstyle))) {
case HALIGN_RIGHT :
fprintf (fp, " align=right");
break;
case HALIGN_CENTER :
fprintf (fp, " align=center");
break;
default :
break;
}
style_unref (style);
if (mstyle_get_align_v (mstyle) & VALIGN_TOP)
fprintf (fp, " valign=top");
r = mstyle_get_color (mstyle, MSTYLE_COLOR_BACK)->color.red >> 8;
g = mstyle_get_color (mstyle, MSTYLE_COLOR_BACK)->color.green >> 8;
b = mstyle_get_color (mstyle, MSTYLE_COLOR_BACK)->color.blue >> 8;
if (r != 255 || g != 255 || b != 255)
fprintf (fp, " bgcolor=\"#%02X%02X%02X\"", r, g, b);
fprintf (fp, ">");
r = mstyle_get_color (mstyle, MSTYLE_COLOR_FORE)->color.red >> 8;
g = mstyle_get_color (mstyle, MSTYLE_COLOR_FORE)->color.green >> 8;
b = mstyle_get_color (mstyle, MSTYLE_COLOR_FORE)->color.blue >> 8;
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "<FONT color=\"#%02X%02X%02X\">",
r, g, b);
html_write_cell_str (fp, cell, mstyle);
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "</FONT>");
}
mstyle_unref (mstyle);
fprintf (fp, "</TD>\n");
}
......@@ -126,59 +132,45 @@ html_write_cell32 (FILE *fp, Cell *cell)
static void
html_write_cell40 (FILE *fp, Cell *cell)
{
Style *style;
MStyle *mstyle;
unsigned char r, g, b;
if (!cell) { /* empty cell */
fprintf (fp, "\t<TD>");
} else {
style = cell_get_style (cell);
mstyle = cell_get_mstyle (cell);
g_return_if_fail (mstyle != NULL);
if (!style) {
/* is this case posible? */
html_fprintf (fp, cell->text->str);
} else {
switch (cell_get_horizontal_align (cell, style->halign)) {
case HALIGN_RIGHT :
fprintf (fp, " halign=right");
break;
case HALIGN_CENTER :
fprintf (fp, " halign=center");
break;
default :
break;
}
if (style->valign & VALIGN_TOP)
fprintf (fp, " valign=top");
r = style->back_color->color.red >> 8;
g = style->back_color->color.green >> 8;
b = style->back_color->color.blue >> 8;
if (r != 255 || g != 255 || b != 255)
fprintf (fp, " bgcolor=\"#%02X%02X%02X\"", r, g, b);
fprintf (fp, ">");
r = style->fore_color->color.red >> 8;
g = style->fore_color->color.green >> 8;
b = style->fore_color->color.blue >> 8;
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "<FONT color=\"#%02X%02X%02X\">",
r, g, b);
if (font_is_monospaced (style))
fprintf (fp, "<TT>");
if (style->font->is_bold)
fprintf (fp, "<B>");
if (style->font->is_italic)
fprintf (fp, "<I>");
html_fprintf (fp, cell->text->str);
if (style->font->is_italic)
fprintf (fp, "</I>");
if (style->font->is_bold)
fprintf (fp, "</B>");
if (font_is_monospaced (style))
fprintf (fp, "</TT>");
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "</FONT>");
switch (cell_get_horizontal_align (cell,
mstyle_get_align_h (mstyle))) {
case HALIGN_RIGHT :
fprintf (fp, " halign=right");
break;
case HALIGN_CENTER :
fprintf (fp, " halign=center");
break;
default :
break;
}
if (mstyle_get_align_v (mstyle) & VALIGN_TOP)
fprintf (fp, " valign=top");
r = mstyle_get_color (mstyle, MSTYLE_COLOR_BACK)->color.red >> 8;
g = mstyle_get_color (mstyle, MSTYLE_COLOR_BACK)->color.green >> 8;
b = mstyle_get_color (mstyle, MSTYLE_COLOR_BACK)->color.blue >> 8;
if (r != 255 || g != 255 || b != 255)
fprintf (fp, " bgcolor=\"#%02X%02X%02X\"", r, g, b);
fprintf (fp, ">");
r = mstyle_get_color (mstyle, MSTYLE_COLOR_FORE)->color.red >> 8;
g = mstyle_get_color (mstyle, MSTYLE_COLOR_FORE)->color.green >> 8;
b = mstyle_get_color (mstyle, MSTYLE_COLOR_FORE)->color.blue >> 8;
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "<FONT color=\"#%02X%02X%02X\">",
r, g, b);
html_write_cell_str (fp, cell, mstyle);
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "</FONT>");
}
fprintf (fp, "</TD>\n");
}
......@@ -352,40 +344,6 @@ html_get_string (char *s, int *flags)
return buf;
}
/*
* change the font of a cell to bold
*/
static void
html_cell_bold (Cell *cell)
{
MStyle *mstyle;
if (!cell)
return;
mstyle = mstyle_new ();
mstyle_set_font_bold (mstyle, TRUE);
cell_set_mstyle (cell, mstyle);
}
/*
* change the font of a cell to italic
*/
static void
html_cell_italic (Cell *cell)
{
MStyle *mstyle;
if (!cell)
return;
mstyle = mstyle_new ();
mstyle_set_font_italic (mstyle, TRUE);
cell_set_mstyle (cell, mstyle);
}
/*
* try at least to read back what we have written before..
*/
......@@ -463,21 +421,23 @@ html_read (Workbook *wb, const char *filename)
str = html_get_string (p, &flags);
cell = sheet_cell_fetch (sheet, col, row);
if (str && cell) {
Style *style = cell_get_style (cell);
/* set the attributes of the cell
*/
if (style && style->font && flags) {
if (flags & HTML_BOLD) {
html_cell_bold (cell);
}
if (flags & HTML_ITALIC) {
html_cell_italic (cell);
}
if (flags & HTML_RIGHT) {
MStyle *mstyle = mstyle_new ();
if (flags) {
MStyle *mstyle = mstyle_new ();
/*
* set the attributes of the cell
*/
if (flags & HTML_BOLD)
mstyle_set_font_bold (mstyle, TRUE);
if (flags & HTML_ITALIC)
mstyle_set_font_italic (mstyle, TRUE);
if (flags & HTML_RIGHT)
mstyle_set_align_h (mstyle, HALIGN_CENTER);
cell_set_mstyle (cell, mstyle);
}