Commit 7b77a4d0 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

store the style for labels (BC_R(fontx)) : lookup the font and assign it


2005-07-29  Jody Goldberg <jody@gnome.org>

	* ms-chart.c (BC_R(objectlink)) : store the style for labels
	(BC_R(fontx)) : lookup the font and assign it to a style.  Need to
	  finish GOFont to store the remaining attributes.
	* ms-excel-read.c (excel_font_get_gofont) : new.
	(excel_read_FONT) : init the gofont member.
	(excel_font_free) : unref it here.
parent c92442dd
......@@ -22,6 +22,8 @@ Jody:
* Store the current settings before previewing. [#301494]
* Fix leak in xls chart import. [#157058]
* Fix object movement and snap to grid in RTL.
* XLS import of image fills. [#127756]
* XLS import of font for chart labels.
Jon Kåre:
* Improve sc/xspread import.
......
2005-07-29 Jody Goldberg <jody@gnome.org>
* ms-chart.c (BC_R(objectlink)) : store the style for labels
(BC_R(fontx)) : lookup the font and assign it to a style. Need to
finish GOFont to store the remaining attributes.
* ms-excel-read.c (excel_font_get_gofont) : new.
(excel_read_FONT) : init the gofont member.
(excel_font_free) : unref it here.
2005-07-15 Jody Goldberg <jody@gnome.org>
* ms-excel-write.c (excel_write_SETUP) : remove unecessary scaling.
......
......@@ -47,6 +47,7 @@
#include <goffice/graph/gog-label.h>
#include <goffice/data/go-data-simple.h>
#include <goffice/utils/go-color.h>
#include <goffice/utils/go-font.h>
#include <goffice/utils/go-pattern.h>
#include <goffice/utils/go-marker.h>
......@@ -180,10 +181,11 @@ BC_R(get_style) (XLChartReadState *s)
}
static int
BC_R(top_state) (XLChartReadState *s)
BC_R(top_state) (XLChartReadState *s, unsigned n)
{
g_return_val_if_fail (s != NULL, 0);
return g_array_index (s->stack, int, s->stack->len-1);
g_return_val_if_fail (s->stack->len >= n+1, 0);
return g_array_index (s->stack, int, s->stack->len-1-n);
}
static GOColor
......@@ -277,10 +279,10 @@ BC_R(ai)(XLChartHandler const *handle,
guint16 const flags = GSF_LE_GET_GUINT16 (q->data + 2);
guint16 const length = GSF_LE_GET_GUINT16 (q->data + 6);
int popped_state = BC_R(top_state) (s);
int top_state = BC_R(top_state) (s, 0);
/* ignore these for now */
if (popped_state == BIFF_CHART_text)
if (top_state == BIFF_CHART_text)
return FALSE;
/* Rest are 0 */
......@@ -905,10 +907,17 @@ static gboolean
BC_R(fontx)(XLChartHandler const *handle,
XLChartReadState *s, BiffQuery *q)
{
#if 0
/* Child of TEXT, index into FONT table */
guint16 const font = GSF_LE_GET_GUINT16 (q->data);
#endif
if (s->style != NULL) {
/* Child of TEXT, index into FONT table */
ExcelFont const *font = excel_font_get (s->container.importer,
GSF_LE_GET_GUINT16 (q->data));
GOFont const *gfont = excel_font_get_gofont (font);
go_font_ref (gfont);
gog_style_set_font (s->style, gfont);
d (-2, fprintf (stderr, "apply font;"););
} else {
d (-2, fprintf (stderr, "ignore font;"););
}
return FALSE;
}
......@@ -944,7 +953,7 @@ ms_chart_map_color (XLChartReadState const *s, guint32 raw, guint32 alpha)
{
GOColor res;
if ((~0x7ffffff) & raw) {
GnmColor *c= excel_palette_get (s->container.importer,
GnmColor *c = excel_palette_get (s->container.importer,
(0x7ffffff & raw));
res = GDK_TO_UINT (c->gdk_color);
style_color_unref (c);
......@@ -1201,7 +1210,7 @@ BC_R(lineformat)(XLChartHandler const *handle,
guint16 const flags = GSF_LE_GET_GUINT16 (q->data+8);
BC_R(get_style) (s);
switch (GSF_LE_GET_GUINT16 (q->data+6)) {
switch (GSF_LE_GET_GINT16 (q->data+6)) {
default :
case -1 : s->style->line.width = 0; /* hairline */
break;
......@@ -1219,7 +1228,7 @@ BC_R(lineformat)(XLChartHandler const *handle,
d (0, fprintf (stderr, "flags == %hd.\n", flags););
d (0, fprintf (stderr, "Lines are %f pts wide.\n", s->style->line.width););
d (0, fprintf (stderr, "Lines have a %s pattern.\n",
ms_line_pattern [s->style->line.pattern ]););
ms_line_pattern [s->style->line.pattern]););
if (s->style->line.pattern <= G_N_ELEMENTS (dash_map))
s->style->line.dash_type = dash_map [s->style->line.pattern];
......@@ -1350,6 +1359,8 @@ BC_R(objectlink)(XLChartHandler const *handle,
default :
fprintf (stderr, "ERROR : TEXT is linked to undocumented object\n");
};});
if (NULL != label && NULL != s->style)
gog_styled_object_set_style (GOG_STYLED_OBJECT (label), s->style);
return FALSE;
}
......@@ -1458,6 +1469,13 @@ static gboolean
BC_R(pos)(XLChartHandler const *handle,
XLChartReadState *s, BiffQuery *q)
{
switch (BC_R(top_state) (s, 0)) {
case BIFF_CHART_text :
fprintf (stderr, "text pos;");
break;
default :
;
}
return FALSE;
}
......@@ -1719,7 +1737,7 @@ BC_R(seriestext)(XLChartHandler const *handle,
gnm_go_data_scalar_new_expr (sheet, expr);
else
value_release (value);
} else if (BC_R(top_state) (s) == BIFF_CHART_text) {
} else if (BC_R(top_state) (s, 0) == BIFF_CHART_text) {
if (s->text != NULL) {
g_warning ("multiple seriestext associated with 1 text record ?");
g_free (str);
......@@ -1767,7 +1785,7 @@ typedef enum {
MS_CHART_BLANK_ZERO = 1,
MS_CHART_BLANK_INTERPOLATE = 2,
MS_CHART_BLANK_MAX = 3
} MS_CHART_BLANK;
} MSChartBlank;
static char const *const ms_chart_blank[] = {
"Skip blanks", "Blanks are zero", "Interpolate blanks"
};
......@@ -1783,7 +1801,7 @@ BC_R(shtprops)(XLChartHandler const *handle,
gboolean const dont_size_with_window = (flags&0x04) ? TRUE : FALSE;
gboolean const has_pos_record = (flags&0x08) ? TRUE : FALSE;
gboolean ignore_pos_record = FALSE;
MS_CHART_BLANK blanks;
MSChartBlank blanks;
g_return_val_if_fail (tmp < MS_CHART_BLANK_MAX, TRUE);
blanks = tmp;
......@@ -1924,7 +1942,7 @@ BC_R(tick)(XLChartHandler const *handle,
*/
if (flags&0x02)
fputs ("Auto text background mode", stderr);
fputs ("Auto text background mode\n", stderr);
else
fprintf (stderr, "background mode = %d\n", (unsigned)GSF_LE_GET_GUINT8 (q->data+3));
......@@ -2072,7 +2090,7 @@ BC_R(end)(XLChartHandler const *handle,
g_return_val_if_fail (s->stack != NULL, TRUE);
g_return_val_if_fail (s->stack->len > 0, TRUE);
popped_state = BC_R(top_state) (s);
popped_state = BC_R(top_state) (s, 0);
s->stack = g_array_remove_index_fast (s->stack, s->stack->len-1);
switch (popped_state) {
......@@ -2084,7 +2102,7 @@ BC_R(end)(XLChartHandler const *handle,
case BIFF_CHART_frame :
if (s->style != NULL) {
int top_state = BC_R(top_state) (s);
int top_state = BC_R(top_state) (s, 0);
GogObject *obj = NULL;
if (top_state == BIFF_CHART_legend)
obj = s->legend;
......@@ -2504,7 +2522,6 @@ not_a_matrix:
break;
case BIFF_CHART_text :
#warning Do something with the style
if (s->text != NULL) {
g_free (s->text);
s->text = NULL;
......
......@@ -66,6 +66,7 @@
#include <gnm-so-filled.h>
#include <sheet-object-graph.h>
#include <sheet-object-image.h>
#include <goffice/utils/go-font.h>
#include <goffice/utils/go-units.h>
#include <goffice/utils/go-glib-extras.h>
#include <goffice/graph/gog-style.h>
......@@ -1267,7 +1268,7 @@ static void
excel_read_FONT (BiffQuery *q, GnmXLImporter *importer)
{
MsBiffVersion const ver = importer->ver;
BiffFontData *fd = g_new (BiffFontData, 1);
ExcelFont *fd = g_new (ExcelFont, 1);
guint16 data;
guint8 data1;
......@@ -1350,6 +1351,7 @@ excel_read_FONT (BiffQuery *q, GnmXLImporter *importer)
fd->color_idx &= 0x7f; /* Undocumented but a good idea */
fd->attrs = NULL;
fd->go_font = NULL;
fd->index = g_hash_table_size (importer->font_data);
if (fd->index >= 4) /* Weird: for backwards compatibility */
......@@ -1362,12 +1364,16 @@ excel_read_FONT (BiffQuery *q, GnmXLImporter *importer)
}
static void
biff_font_data_destroy (BiffFontData *fd)
excel_font_free (ExcelFont *fd)
{
if (NULL != fd->attrs) {
pango_attr_list_unref (fd->attrs);
fd->attrs = NULL;
}
if (NULL != fd->go_font) {
go_font_unref (fd->go_font);
fd->go_font = NULL;
}
g_free (fd->fontname);
g_free (fd);
}
......@@ -1571,10 +1577,10 @@ excel_read_PALETTE (BiffQuery *q, GnmXLImporter *importer)
* NB. index 4 is omitted supposedly for backwards compatiblity
* Returns the font color if there is one.
**/
static BiffFontData const *
excel_get_font (GnmXLImporter const *importer, unsigned font_idx)
ExcelFont const *
excel_font_get (GnmXLImporter const *importer, unsigned font_idx)
{
BiffFontData const *fd = g_hash_table_lookup (
ExcelFont const *fd = g_hash_table_lookup (
importer->font_data, GINT_TO_POINTER (font_idx));
g_return_val_if_fail (fd != NULL, NULL); /* flag the problem */
......@@ -1583,6 +1589,25 @@ excel_get_font (GnmXLImporter const *importer, unsigned font_idx)
return fd;
}
GOFont const *
excel_font_get_gofont (ExcelFont const *efont)
{
if (NULL == efont->go_font) {
PangoFontDescription *desc = pango_font_description_new ();
#warning FINISH when GOFont is smarter
pango_font_description_set_family (desc, efont->fontname);
pango_font_description_set_weight (desc, efont->boldness);
pango_font_description_set_style (desc,
efont->italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
pango_font_description_set_size (desc,
efont->height * PANGO_SCALE / 20);
((ExcelFont *)efont)->go_font = go_font_new_by_desc (desc);
}
return efont->go_font;
}
static BiffXFData const *
excel_get_xf (ExcelReadSheet *esheet, unsigned xfidx)
{
......@@ -1617,7 +1642,7 @@ excel_get_xf (ExcelReadSheet *esheet, unsigned xfidx)
static GnmStyle *
excel_get_style_from_xf (ExcelReadSheet *esheet, BiffXFData const *xf)
{
BiffFontData const *fd;
ExcelFont const *fd;
GnmColor *pattern_color, *back_color, *font_color;
int pattern_index, back_index, font_index;
GnmStyle *mstyle;
......@@ -1653,7 +1678,7 @@ excel_get_style_from_xf (ExcelReadSheet *esheet, BiffXFData const *xf)
gnm_style_set_text_dir (mstyle, xf->text_dir);
/* Font */
fd = excel_get_font (esheet->container.importer, xf->font_idx);
fd = excel_font_get (esheet->container.importer, xf->font_idx);
if (fd != NULL) {
GnmUnderline underline = UNDERLINE_NONE;
gnm_style_set_font_name (mstyle, fd->fontname);
......@@ -2684,11 +2709,11 @@ static PangoAttrList *
ms_wb_get_font_markup (MSContainer const *c, unsigned indx)
{
GnmXLImporter *importer = (GnmXLImporter *)c;
BiffFontData const *fd = excel_get_font (importer, indx);
ExcelFont const *fd = excel_font_get (importer, indx);
GnmColor *color;
if (fd == NULL) { /* random fallback */
fd = excel_get_font (importer, 0);
fd = excel_font_get (importer, 0);
if (NULL == fd)
return NULL;
}
......@@ -2732,7 +2757,7 @@ ms_wb_get_font_markup (MSContainer const *c, unsigned indx)
color->gdk_color.red, color->gdk_color.green, color->gdk_color.blue));
style_color_unref (color);
((BiffFontData *)fd)->attrs = attrs;
((ExcelFont *)fd)->attrs = attrs;
}
return fd->attrs;
......@@ -2771,7 +2796,7 @@ gnm_xl_importer_new (IOContext *context, WorkbookView *wb_view)
NULL, (GDestroyNotify) biff_boundsheet_data_destroy);
importer->font_data = g_hash_table_new_full (
g_direct_hash, g_direct_equal,
NULL, (GDestroyNotify)biff_font_data_destroy);
NULL, (GDestroyNotify)excel_font_free);
importer->excel_sheets = g_ptr_array_new ();
importer->XF_cell_records = g_ptr_array_new ();
importer->format_table = g_hash_table_new_full (
......@@ -2793,7 +2818,7 @@ excel_workbook_reset_style (GnmXLImporter *importer)
g_hash_table_destroy (importer->font_data);
importer->font_data = g_hash_table_new_full (
g_direct_hash, g_direct_equal,
NULL, (GDestroyNotify)biff_font_data_destroy);
NULL, (GDestroyNotify)excel_font_free);
for (i = 0; i < importer->XF_cell_records->len; i++)
biff_xf_data_destroy (g_ptr_array_index (importer->XF_cell_records, i));
......@@ -3398,8 +3423,8 @@ xl_find_fontspec (ExcelReadSheet *esheet, float *size20)
{
/* Use the 'Normal' Style which is by definition the 0th */
BiffXFData const *xf = excel_get_xf (esheet, 0);
BiffFontData const *fd = (xf != NULL)
? excel_get_font (esheet->container.importer, xf->font_idx)
ExcelFont const *fd = (xf != NULL)
? excel_font_get (esheet->container.importer, xf->font_idx)
: NULL;
*size20 = (fd != NULL) ? (fd->height / (20. * 10.)) : 1.;
return xl_lookup_font_specs ((fd != NULL) ? fd->fontname : "Arial");
......
......@@ -85,7 +85,8 @@ typedef struct {
MsBiffFontUnderline underline;
char *fontname;
PangoAttrList *attrs;
} BiffFontData;
GOFont const *go_font;
} ExcelFont;
typedef struct {
unsigned idx;
......@@ -140,7 +141,9 @@ char *excel_get_text (GnmXLImporter const *importer,
guint8 const *ptr, guint32 length,
guint32 *byte_length);
GnmColor *excel_palette_get (GnmXLImporter *importer, gint idx);
GnmColor *excel_palette_get (GnmXLImporter *importer, gint idx);
ExcelFont const *excel_font_get (GnmXLImporter const *importer, unsigned idx);
GOFont const *excel_font_get_gofont (ExcelFont const *font);
GdkPixbuf *excel_read_IMDATA (BiffQuery *q, gboolean keep_image);
void excel_read_SCL (BiffQuery *q, Sheet *esheet);
......
......@@ -1631,7 +1631,7 @@ write_palette (BiffPut *bp, ExcelWriteState *ewb)
* Return string description of font to print in debug log
**/
static char *
excel_font_to_string (ExcelFont const *f)
excel_font_to_string (ExcelWriteFont const *f)
{
static char buf[96];
guint nused;
......@@ -1661,7 +1661,7 @@ excel_font_to_string (ExcelFont const *f)
#endif
static void
excel_font_free (ExcelFont *efont)
excel_font_free (ExcelWriteFont *efont)
{
/* FONT_SKIP has value == NULL */
d (3, fprintf (stderr, "free %p", efont););
......@@ -1672,16 +1672,16 @@ excel_font_free (ExcelFont *efont)
}
}
static ExcelFont *
static ExcelWriteFont *
excel_font_new (GnmStyle const *base_style)
{
ExcelFont *efont;
ExcelWriteFont *efont;
GnmColor *c;
if (base_style == NULL)
return NULL;
efont = g_new (ExcelFont, 1);
efont = g_new (ExcelWriteFont, 1);
efont->font_name = gnm_style_get_font_name (base_style);
efont->font_name_copy = NULL;
efont->size_pts = gnm_style_get_font_size (base_style);
......@@ -1698,7 +1698,7 @@ excel_font_new (GnmStyle const *base_style)
}
static void
excel_font_overlay_pango (ExcelFont *efont, GSList *pango)
excel_font_overlay_pango (ExcelWriteFont *efont, GSList *pango)
{
GSList *ptr;
......@@ -1756,7 +1756,7 @@ static guint
excel_font_hash (gconstpointer f)
{
guint res = 0;
ExcelFont *font = (ExcelFont *) f;
ExcelWriteFont *font = (ExcelWriteFont *) f;
if (f)
res = (int)(font->size_pts + g_str_hash (font->font_name))
......@@ -1777,8 +1777,8 @@ excel_font_equal (gconstpointer a, gconstpointer b)
else if (!a || !b)
res = FALSE; /* Recognize junk - inelegant, I know! */
else {
ExcelFont const *fa = (ExcelFont const *) a;
ExcelFont const *fb = (ExcelFont const *) b;
ExcelWriteFont const *fa = (ExcelWriteFont const *) a;
ExcelWriteFont const *fb = (ExcelWriteFont const *) b;
res = !strcmp (fa->font_name, fb->font_name)
&& (fa->size_pts == fb->size_pts)
&& (fa->is_bold == fb->is_bold)
......@@ -1792,14 +1792,14 @@ excel_font_equal (gconstpointer a, gconstpointer b)
return res;
}
static ExcelFont *
static ExcelWriteFont *
fonts_get_font (ExcelWriteState *ewb, gint idx)
{
return two_way_table_idx_to_key (ewb->fonts.two_way_table, idx);
}
static void
after_put_font (ExcelFont *f, gboolean was_added, gint index, gconstpointer dummy)
after_put_font (ExcelWriteFont *f, gboolean was_added, gint index, gconstpointer dummy)
{
if (was_added) {
d (1, fprintf (stderr, "Found unique font %d - %s\n",
......@@ -1810,7 +1810,7 @@ after_put_font (ExcelFont *f, gboolean was_added, gint index, gconstpointer dumm
/**
* put_efont :
* @efont : #ExcelFont
* @efont : #ExcelWriteFont
* @ewb : #ExcelWriteState
*
* Absorbs ownership of @efont potentially freeing it.
......@@ -1818,7 +1818,7 @@ after_put_font (ExcelFont *f, gboolean was_added, gint index, gconstpointer dumm
* Returns the index of the font
**/
static inline gint
put_efont (ExcelFont *efont, ExcelWriteState *ewb)
put_efont (ExcelWriteFont *efont, ExcelWriteState *ewb)
{
TwoWayTable *twt = ewb->fonts.two_way_table;
......@@ -1837,7 +1837,7 @@ put_style_font (GnmStyle *style, gconstpointer dummy, ExcelWriteState *ewb)
}
static void
excel_write_FONT (ExcelWriteState *ewb, ExcelFont const *f)
excel_write_FONT (ExcelWriteState *ewb, ExcelWriteFont const *f)
{
guint8 data[64];
guint32 size_pts = f->size_pts * 20;
......@@ -1895,7 +1895,7 @@ excel_write_FONTs (BiffPut *bp, ExcelWriteState *ewb)
TwoWayTable *twt = ewb->fonts.two_way_table;
int nfonts = twt->idx_to_key->len;
int i;
ExcelFont *f;
ExcelWriteFont *f;
for (i = 0; i < nfonts; i++) {
if (i != FONT_SKIP) { /* FONT_SKIP is invalid, skip it */
......@@ -2118,7 +2118,7 @@ txomarkup_new (ExcelWriteState *ewb, PangoAttrList *markup, GnmStyle *style)
if (txo->len == 0 && noattrs) {
/* trim start */
} else {
ExcelFont *efont = excel_font_new (style);
ExcelWriteFont *efont = excel_font_new (style);
gint tmp[2];
excel_font_overlay_pango (efont, attrs);
......@@ -2353,7 +2353,7 @@ static void
log_xf_data (ExcelWriteState *ewb, BiffXFData *xfd, int idx)
{
int i;
ExcelFont *f = fonts_get_font (ewb, xfd->font_idx);
ExcelWriteFont *f = fonts_get_font (ewb, xfd->font_idx);
/* Formats are saved using the 'C' locale number format */
char * desc = style_format_as_XL (xfd->style_format, FALSE);
......@@ -2386,7 +2386,7 @@ log_xf_data (ExcelWriteState *ewb, BiffXFData *xfd, int idx)
static void
build_xf_data (ExcelWriteState *ewb, BiffXFData *xfd, GnmStyle *st)
{
ExcelFont *f;
ExcelWriteFont *f;
GnmBorder const *b;
int i;
......
......@@ -36,7 +36,7 @@ typedef struct {
gboolean is_auto;
GnmUnderline underline;
gboolean strikethrough;
} ExcelFont;
} ExcelWriteFont;
typedef struct {
ExcelWriteState *ewb;
......
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