Commit 09ad1ad2 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

new. (ms_obj_attr_get_markup) : new. (ms_obj_attr_destroy) : teach about

2004-03-06  Jody Goldberg <jody@gnome.org>

	* ms-obj.c (ms_obj_attr_new_markup) : new.
	(ms_obj_attr_get_markup) : new.
	(ms_obj_attr_destroy) : teach about PangoAttrList
	(append_txorun) : new.
	(ms_obj_read_pre_biff8_obj) : font colours come with the FONT info in
	  txoruns.  The docs are wrong the colour in the record is useless.
	  Remove some extra debug spew.

	* ms-excel-read.c (excel_wb_get_fmt) : no point using pointers to
	  ints.  Just use G_INT_TO_POINTER.
	(ms_sheet_get_fmt) : ditto.
	(excel_read_BOUNDSHEET) : ditto.
	(excel_workbook_new) : ditto.
	(excel_workbook_reset_style) : ditto.
	(base_char_width_for_read) : ditto.
	(excel_read_FORMAT) : ditto.
	(excel_read_FONT) : ditto.
	(excel_get_font) : ditto.
	  Also no need for this to take a sheet, take a workbook.
	(biff_font_data_destroy) : free the new optional attr lists.
	(ms_sheet_create_obj) : Use markup rather than a single colour.
	(biff_guint16_hash (guint16 const *d)
	(biff_guint32_hash (guint32 const *d)
	(biff_guint16_equal) : delete.
	(biff_guint32_equal) : delete.
	(excel_get_style_from_xf) : remove some useless code now that font
	  substitution is handled at the app level.
	(add_attr) : new.
	(ms_wb_get_font_markup) : new.  build a PangoAttrList from a FONT record.

	* ms-container.c (ms_container_get_fmt) : automatically chain up
	(ms_container_get_markup) : new.

	* ms-chart.c (chart_get_fmt) : delete.

2004-03-06  Jody Goldberg <jody@gnome.org>

	* src/sheet-object-graphic.c (sheet_object_text_finalize) : release
	  the markup.
	(sheet_object_text_new_view) : set the attributes.
	(sheet_object_text_clone) : handle the attributes.
	(gnm_so_text_set_font_color) : delete.
	(gnm_so_text_set_markup) : new.

2004-03-05  Jody Goldberg <jody@gnome.org>

	* src/colrow.c (colrow_set_sizes) : force re-render of variable width cells
	(colrow_restore_state_group) : ditto

	* src/rendered-value.c (rendered_value_render) : privatize

	* src/style.c (required_updates_for_style) : Now that rendered values
	  contain size info too we can dispense with the distinction between
	  rendering and sizing.  Without this changing the font size would not
	  resize because the rendered value cached the size and was not
	  re-rendered until draw, rather than at row-height calc.
parent 58ef5116
......@@ -8,11 +8,8 @@ release, and longer term bugs.
Release Critical
----------------
http://bugzilla.gnome.org/show_bug.cgi?id=131588 [-O0 vs -O2 for rangesum]
http://bugzilla.gnome.org/show_bug.cgi?id=97216 [sheet for graph creation]
http://bugzilla.gnome.org/show_bug.cgi?id=127203 [x axis child pos]
: X axis label seperation
: text in boxes for text-xls/pivot.xls is white [xl95 pallette id=9]
: box colors and warnings in christ95.xls
The Insert menu has an "Insert" entry. (Which is named thusly because it
......
2004-03-06 Jody Goldberg <jody@gnome.org>
* src/sheet-object-graphic.c (sheet_object_text_finalize) : release
the markup.
(sheet_object_text_new_view) : set the attributes.
(sheet_object_text_clone) : handle the attributes.
(gnm_so_text_set_font_color) : delete.
(gnm_so_text_set_markup) : new.
2004-03-05 Jody Goldberg <jody@gnome.org>
* src/colrow.c (colrow_set_sizes) : force re-render of variable width cells
(colrow_restore_state_group) : ditto
* src/rendered-value.c (rendered_value_render) : privatize
* src/style.c (required_updates_for_style) : Now that rendered values
contain size info too we can dispense with the distinction between
rendering and sizing. Without this changing the font size would not
resize because the rendered value cached the size and was not
re-rendered until draw, rather than at row-height calc.
2004-03-05 Morten Welinder <terra@gnome.org>
* src/gui-file.c (gui_file_save_as): We no longer need to show
......
2004-03-06 Jody Goldberg <jody@gnome.org>
* src/sheet-object-graphic.c (sheet_object_text_finalize) : release
the markup.
(sheet_object_text_new_view) : set the attributes.
(sheet_object_text_clone) : handle the attributes.
(gnm_so_text_set_font_color) : delete.
(gnm_so_text_set_markup) : new.
2004-03-05 Jody Goldberg <jody@gnome.org>
* src/colrow.c (colrow_set_sizes) : force re-render of variable width cells
(colrow_restore_state_group) : ditto
* src/rendered-value.c (rendered_value_render) : privatize
* src/style.c (required_updates_for_style) : Now that rendered values
contain size info too we can dispense with the distinction between
rendering and sizing. Without this changing the font size would not
resize because the rendered value cached the size and was not
re-rendered until draw, rather than at row-height calc.
2004-03-05 Morten Welinder <terra@gnome.org>
* src/gui-file.c (gui_file_save_as): We no longer need to show
......
2004-03-06 Jody Goldberg <jody@gnome.org>
* ms-obj.c (ms_obj_attr_new_markup) : new.
(ms_obj_attr_get_markup) : new.
(ms_obj_attr_destroy) : teach about PangoAttrList
(append_txorun) : new.
(ms_obj_read_pre_biff8_obj) : font colours come with the FONT info in
txoruns. The docs are wrong the colour in the record is useless.
Remove some extra debug spew.
* ms-excel-read.c (excel_wb_get_fmt) : no point using pointers to
ints. Just use G_INT_TO_POINTER.
(ms_sheet_get_fmt) : ditto.
(excel_read_BOUNDSHEET) : ditto.
(excel_workbook_new) : ditto.
(excel_workbook_reset_style) : ditto.
(base_char_width_for_read) : ditto.
(excel_read_FORMAT) : ditto.
(excel_read_FONT) : ditto.
(excel_get_font) : ditto.
Also no need for this to take a sheet, take a workbook.
(biff_font_data_destroy) : free the new optional attr lists.
(ms_sheet_create_obj) : Use markup rather than a single colour.
(biff_guint16_hash (guint16 const *d)
(biff_guint32_hash (guint32 const *d)
(biff_guint16_equal) : delete.
(biff_guint32_equal) : delete.
(excel_get_style_from_xf) : remove some useless code now that font
substitution is handled at the app level.
(add_attr) : new.
(ms_wb_get_font_markup) : new. build a PangoAttrList from a FONT record.
* ms-container.c (ms_container_get_fmt) : automatically chain up
(ms_container_get_markup) : new.
* ms-chart.c (chart_get_fmt) : delete.
2004-03-03 Jody Goldberg <jody@gnome.org>
* ms-formula-read.c (excel_formula_parses_ref_sheets) : extend to
......
......@@ -5,7 +5,7 @@
* Author:
* Jody Goldberg (jody@gnome.org)
*
* (C) 1999-2002 Jody Goldberg
* (C) 1999-2004 Jody Goldberg
**/
#include <gnumeric-config.h>
......@@ -1973,12 +1973,6 @@ chart_get_sheet (MSContainer const *container)
return ms_container_sheet (container->parent);
}
static GnmFormat *
chart_get_fmt (MSContainer const *container, guint16 indx)
{
return ms_container_get_fmt (container->parent, indx);
}
gboolean
ms_excel_read_chart (BiffQuery *q, MSContainer *container, MsBiffVersion ver,
SheetObject *sog)
......@@ -1988,7 +1982,7 @@ ms_excel_read_chart (BiffQuery *q, MSContainer *container, MsBiffVersion ver,
chart_create_obj,
chart_parse_expr,
chart_get_sheet,
chart_get_fmt
NULL
};
int const num_handler = sizeof(chart_biff_handler) /
sizeof(XLChartHandler *);
......
......@@ -7,7 +7,7 @@
* Author:
* Jody Goldberg (jody@gnome.org)
*
* (C) 2000-2003 Jody Goldberg
* (C) 2000-2004 Jody Goldberg
**/
#include <gnumeric-config.h>
......@@ -202,11 +202,32 @@ ms_container_sheet (MSContainer const *c)
}
GnmFormat *
ms_container_get_fmt (MSContainer const *c, guint16 indx)
ms_container_get_fmt (MSContainer const *c, unsigned indx)
{
for ( ; TRUE ; c = c->parent) {
g_return_val_if_fail (c != NULL, NULL);
g_return_val_if_fail (c->vtbl != NULL, NULL);
g_return_val_if_fail (c->vtbl->get_fmt != NULL, NULL);
if (c->vtbl->get_fmt != NULL)
break;
}
return (*c->vtbl->get_fmt) (c, indx);
}
/**
* ms_container_get_markup :
* @c : #MSContainer
* @indx :
*
* Return a #PangoAttrList the caller should not modify or free the list.
**/
PangoAttrList *
ms_container_get_markup (MSContainer const *c, unsigned indx)
{
for ( ; TRUE ; c = c->parent) {
g_return_val_if_fail (c != NULL, NULL);
g_return_val_if_fail (c->vtbl != NULL, NULL);
if (c->vtbl->get_markup != NULL)
break;
}
return (*c->vtbl->get_markup) (c, indx);
}
......@@ -3,7 +3,8 @@
#include "excel.h"
#include "ms-biff.h"
#include <glib-object.h>
#include <glib.h>
#include <pango/pango-attributes.h>
typedef struct _MSContainer MSContainer;
typedef struct _ExcelWorkbook ExcelWorkbook;
......@@ -12,12 +13,13 @@ typedef struct _MSEscherShape MSEscherShape;
typedef struct _MSObj MSObj;
typedef struct {
gboolean (*realize_obj) (MSContainer *container, MSObj *obj);
SheetObject * (*create_obj) (MSContainer *container, MSObj *obj);
GnmExpr const * (*parse_expr) (MSContainer *container,
guint8 const *data, int length);
Sheet * (*sheet) (MSContainer const *container);
GnmFormat * (*get_fmt) (MSContainer const *container, guint16 indx);
gboolean (*realize_obj) (MSContainer *c, MSObj *obj);
SheetObject * (*create_obj) (MSContainer *c, MSObj *obj);
GnmExpr const * (*parse_expr) (MSContainer *c,
guint8 const *expr, int length);
Sheet * (*sheet) (MSContainer const *c);
GnmFormat * (*get_fmt) (MSContainer const *c, unsigned indx);
PangoAttrList * (*get_markup) (MSContainer const *c, unsigned indx);
} MSContainerClass;
struct _MSContainer {
......@@ -53,6 +55,7 @@ GnmExpr const *ms_container_parse_expr (MSContainer *c,
guint8 const *data, int length);
Sheet *ms_container_sheet (MSContainer const *c);
GnmFormat *ms_container_get_fmt (MSContainer const *container, guint16 indx);
GnmFormat *ms_container_get_fmt (MSContainer const *c, unsigned indx);
PangoAttrList *ms_container_get_markup (MSContainer const *c, unsigned indx);
#endif /* MS_OFFICE_CONTAINER_H */
......@@ -6,7 +6,7 @@
* Jody Goldberg (jody@gnome.org)
* Michael Meeks (michael@ximian.com)
*
* (C) 1998-2003 Michael Meeks, Jody Goldberg
* (C) 1998-2004 Michael Meeks, Jody Goldberg
**/
#include <gnumeric-config.h>
#include <glib/gi18n.h>
......@@ -124,10 +124,11 @@ excel_iconv_open_for_import (guint codepage)
}
static GnmFormat *
excel_wb_get_fmt (ExcelWorkbook *ewb, guint16 idx)
excel_wb_get_fmt (ExcelWorkbook *ewb, unsigned idx)
{
char const *ans = NULL;
BiffFormatData const *d = g_hash_table_lookup (ewb->format_data, &idx);
BiffFormatData const *d = g_hash_table_lookup (ewb->format_data,
GINT_TO_POINTER (idx));
if (d)
ans = d->name;
......@@ -183,7 +184,7 @@ ms_sheet_get_sheet (MSContainer const *container)
}
static GnmFormat *
ms_sheet_get_fmt (MSContainer const *container, guint16 indx)
ms_sheet_get_fmt (MSContainer const *container, unsigned indx)
{
return excel_wb_get_fmt (container->ewb, indx);
}
......@@ -459,9 +460,7 @@ ms_sheet_create_obj (MSContainer *container, MSObj *obj)
break;
case 0x0E: /* Label */
case 0x06: { /* TextBox */
GnmColor *color = NULL;
case 0x06: /* TextBox */
so = g_object_new (sheet_object_text_get_type (), NULL);
if (ms_obj_attr_bag_lookup (obj->attrs, MS_OBJ_ATTR_FILLED))
......@@ -474,13 +473,10 @@ ms_sheet_create_obj (MSContainer *container, MSObj *obj)
/* default is none */
gnm_so_filled_set_outline_color (so,
ms_sheet_map_color (esheet, obj, MS_OBJ_ATTR_OUTLINE_COLOR));
gnm_so_text_set_markup (so,
ms_obj_attr_get_markup (obj, MS_OBJ_ATTR_MARKUP, NULL));
color = ms_sheet_map_color (esheet, obj,
MS_OBJ_ATTR_FONT_COLOR);
if (color) /* gnumeric default is fine */
gnm_so_text_set_font_color (so, color);
break;
}
/* Button */
case 0x07: so = g_object_new (sheet_widget_button_get_type (), NULL);
......@@ -616,7 +612,8 @@ excel_sheet_new (ExcelWorkbook *ewb, char const *sheet_name)
&ms_sheet_create_obj,
&ms_sheet_parse_expr,
&ms_sheet_get_sheet,
&ms_sheet_get_fmt
&ms_sheet_get_fmt,
NULL
};
ExcelReadSheet *esheet = g_new (ExcelReadSheet, 1);
......@@ -664,38 +661,6 @@ excel_unexpected_biff (BiffQuery *q, char const *state,
#endif
}
/**
* Generic 16 bit int index pointer functions.
**/
static guint
biff_guint16_hash (guint16 const *d)
{
return *d * 2;
}
static guint
biff_guint32_hash (guint32 const *d)
{
return *d * 2;
}
static gint
biff_guint16_equal (guint16 const *a, guint16 const *b)
{
if (*a == *b)
return 1;
return 0;
}
static gint
biff_guint32_equal (guint32 const *a, guint32 const *b)
{
if (*a == *b)
return 1;
return 0;
}
/**
* This returns whether there is a header byte
* and sets various flags from it
......@@ -1163,7 +1128,8 @@ excel_read_BOUNDSHEET (BiffQuery *q, ExcelWorkbook *ewb, MsBiffVersion ver)
ans->index = ewb->boundsheet_sheet_by_index->len;
g_ptr_array_add (ewb->boundsheet_sheet_by_index, ans->sheet ? ans->sheet->sheet : NULL);
g_hash_table_insert (ewb->boundsheet_data_by_stream, &ans->streamStartPos, ans);
g_hash_table_insert (ewb->boundsheet_data_by_stream,
GINT_TO_POINTER (ans->streamStartPos), ans);
d (1, fprintf (stderr,"Boundsheet: %d) '%s' %p, %d:%d\n", ans->index,
ans->name, ans->sheet, ans->type, ans->hidden););
......@@ -1196,7 +1162,7 @@ excel_read_FORMAT (BiffQuery *q, ExcelWorkbook *ewb)
}
d (2, printf ("Format data: 0x%x == '%s'\n", d->idx, d->name););
g_hash_table_insert (ewb->format_data, &d->idx, d);
g_hash_table_insert (ewb->format_data, GINT_TO_POINTER (d->idx), d);
}
static void
......@@ -1279,20 +1245,25 @@ excel_read_FONT (BiffQuery *q, ExcelWorkbook *ewb)
GSF_LE_GET_GUINT8 (q->data + 14), NULL);
}
fd->attrs = NULL;
fd->index = g_hash_table_size (ewb->font_data);
if (fd->index >= 4) /* Weird: for backwards compatibility */
fd->index++;
g_hash_table_insert (ewb->font_data, &fd->index, fd);
g_hash_table_insert (ewb->font_data, GINT_TO_POINTER (fd->index), fd);
d (1, fprintf (stderr,"Insert font '%s' (%d) size %d pts color %d\n",
fd->fontname, fd->index, fd->height / 20, fd->color_idx););
d (3, fprintf (stderr,"Font color = 0x%x\n", fd->color_idx););
}
static void
biff_font_data_destroy (BiffFontData *fd)
{
if (NULL != fd->attrs) {
pango_attr_list_unref (fd->attrs);
fd->attrs = NULL;
}
g_free (fd->fontname);
g_free (fd);
}
......@@ -1486,13 +1457,14 @@ excel_palette_destroy (ExcelPalette *pal)
* Returns the font color if there is one.
**/
static BiffFontData const *
excel_get_font (ExcelReadSheet *esheet, guint16 font_idx)
excel_get_font (ExcelWorkbook const *ewb, unsigned font_idx)
{
BiffFontData const *fd = g_hash_table_lookup (esheet->container.ewb->font_data,
&font_idx);
BiffFontData const *fd = g_hash_table_lookup (
ewb->font_data, GINT_TO_POINTER (font_idx));
g_return_val_if_fail (fd != NULL, NULL); /* flag the problem */
g_return_val_if_fail (fd->index != 4, NULL); /* should not exist */
return fd;
}
......@@ -1558,13 +1530,9 @@ excel_get_style_from_xf (ExcelReadSheet *esheet, guint16 xfidx)
mstyle_set_rotation (mstyle, xf->rotation);
/* Font */
fd = excel_get_font (esheet, xf->font_idx);
fd = excel_get_font (esheet->container.ewb, xf->font_idx);
if (fd != NULL) {
StyleUnderlineType underline = UNDERLINE_NONE;
char const *subs_fontname = fd->fontname;
if (subs_fontname)
mstyle_set_font_name (mstyle, subs_fontname);
else
mstyle_set_font_name (mstyle, fd->fontname);
mstyle_set_font_size (mstyle, fd->height / 20.0);
mstyle_set_font_bold (mstyle, fd->boldness >= 0x2bc);
......@@ -2605,11 +2573,72 @@ ms_wb_parse_expr (MSContainer *container, guint8 const *data, int length)
}
static GnmFormat *
ms_wb_get_fmt (MSContainer const *container, guint16 indx)
ms_wb_get_fmt (MSContainer const *container, unsigned indx)
{
return excel_wb_get_fmt (((ExcelWorkbook *)container), indx);
}
static void
add_attr (PangoAttrList *attr_list, PangoAttribute *attr)
{
attr->start_index = 0;
attr->end_index = 0;
pango_attr_list_insert (attr_list, attr);
}
static PangoAttrList *
ms_wb_get_font_markup (MSContainer const *c, unsigned indx)
{
ExcelWorkbook const *ewb = (ExcelWorkbook const *)c;
BiffFontData const *fd = excel_get_font (ewb, indx);
GnmColor *color;
g_return_val_if_fail (fd != NULL, NULL);
if (fd->attrs == NULL) {
PangoAttrList *attrs;
PangoUnderline underline = PANGO_UNDERLINE_NONE;
int rise = 0;
switch (fd->underline) {
case MS_BIFF_F_U_SINGLE:
case MS_BIFF_F_U_SINGLE_ACC:
underline = PANGO_UNDERLINE_SINGLE;
break;
case MS_BIFF_F_U_DOUBLE:
case MS_BIFF_F_U_DOUBLE_ACC:
underline = PANGO_UNDERLINE_DOUBLE;
break;
default: break;
}
switch (fd->script) {
case MS_BIFF_F_S_SUPER: rise = 500; break;
case MS_BIFF_F_S_SUB: rise = -500; break;
default: break;
}
attrs = pango_attr_list_new ();
add_attr (attrs, pango_attr_family_new (fd->fontname));
add_attr (attrs, pango_attr_size_new (fd->height * PANGO_SCALE / 20));
add_attr (attrs, pango_attr_weight_new (fd->boldness));
add_attr (attrs, pango_attr_style_new (fd->italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL));
add_attr (attrs, pango_attr_strikethrough_new (fd->struck_out));
add_attr (attrs, pango_attr_underline_new (underline));
add_attr (attrs, pango_attr_rise_new (rise));
color = (fd->color_idx == 127) ? style_color_black ()
: excel_palette_get (ewb->palette, fd->color_idx);
add_attr (attrs, pango_attr_foreground_new (
color->color.red, color->color.green, color->color.blue));
style_color_unref (color);
((BiffFontData *)fd)->attrs = attrs;
}
return fd->attrs;
}
static ExcelWorkbook *
excel_workbook_new (MsBiffVersion ver, IOContext *context, WorkbookView *wbv)
{
......@@ -2618,6 +2647,7 @@ excel_workbook_new (MsBiffVersion ver, IOContext *context, WorkbookView *wbv)
&ms_wb_parse_expr,
NULL,
&ms_wb_get_fmt,
&ms_wb_get_font_markup
};
ExcelWorkbook *ewb = g_new (ExcelWorkbook, 1);
......@@ -2635,15 +2665,15 @@ excel_workbook_new (MsBiffVersion ver, IOContext *context, WorkbookView *wbv)
ewb->gnum_wb = NULL;
ewb->boundsheet_sheet_by_index = g_ptr_array_new ();
ewb->boundsheet_data_by_stream = g_hash_table_new_full (
(GHashFunc)biff_guint32_hash, (GCompareFunc)biff_guint32_equal,
g_direct_hash, g_direct_equal,
NULL, (GDestroyNotify) biff_boundsheet_data_destroy);
ewb->font_data = g_hash_table_new_full (
(GHashFunc)biff_guint16_hash, (GCompareFunc)biff_guint16_equal,
g_direct_hash, g_direct_equal,
NULL, (GDestroyNotify)biff_font_data_destroy);
ewb->excel_sheets = g_ptr_array_new ();
ewb->XF_cell_records = g_ptr_array_new ();
ewb->format_data = g_hash_table_new_full (
(GHashFunc)biff_guint16_hash, (GCompareFunc)biff_guint16_equal,
g_direct_hash, g_direct_equal,
NULL, (GDestroyNotify)biff_format_data_destroy);
ewb->palette = excel_get_default_palette ();
ewb->global_strings = NULL;
......@@ -2668,7 +2698,7 @@ excel_workbook_reset_style (ExcelWorkbook *ewb)
g_hash_table_destroy (ewb->font_data);
ewb->font_data = g_hash_table_new_full (
(GHashFunc)biff_guint16_hash, (GCompareFunc)biff_guint16_equal,
g_direct_hash, g_direct_equal,
NULL, (GDestroyNotify)biff_font_data_destroy);
for (i = 0; i < ewb->XF_cell_records->len; i++)
......@@ -2678,7 +2708,7 @@ excel_workbook_reset_style (ExcelWorkbook *ewb)
g_hash_table_destroy (ewb->format_data);
ewb->format_data = g_hash_table_new_full (
(GHashFunc)biff_guint16_hash, (GCompareFunc)biff_guint16_equal,
g_direct_hash, g_direct_equal,
NULL, (GDestroyNotify)biff_format_data_destroy);
}
......@@ -3233,7 +3263,7 @@ base_char_width_for_read (ExcelReadSheet *esheet,
{
BiffXFData const *xf = excel_get_xf (esheet, xf_index);
BiffFontData const *fd = (xf != NULL)
? excel_get_font (esheet, xf->font_idx)
? excel_get_font (esheet->container.ewb, xf->font_idx)
: NULL;
/* default to Arial 10 */
char const * name = (fd != NULL) ? fd->fontname : "Arial";
......@@ -5351,8 +5381,8 @@ excel_read_BOF (BiffQuery *q,
excel_read_sheet (q, ewb, wb_view, esheet);
} else if (ver->type == MS_BIFF_TYPE_Worksheet) {
gboolean const found_it =
g_hash_table_lookup (ewb->boundsheet_data_by_stream, &q->streamPos) != NULL;
gboolean const found_it = NULL != g_hash_table_lookup (
ewb->boundsheet_data_by_stream, GINT_TO_POINTER (q->streamPos));
ExcelReadSheet *esheet = excel_workbook_get_sheet (ewb, *current_sheet);
esheet->container.ver = ver->version;
excel_read_sheet (q, ewb, wb_view, esheet);
......
......@@ -6,7 +6,7 @@
* Jody Goldberg (jody@gnome.org)
* Michael Meeks (michael@ximian.com)
*
* (C) 1998-2002 Michael Meeks
* (C) 1998-2004 Michael Meeks, Jody Goldberg
**/
#ifndef GNUMERIC_MS_EXCEL_H
#define GNUMERIC_MS_EXCEL_H
......@@ -15,6 +15,7 @@
#include "ms-excel-biff.h"
#include "ms-container.h"
#include <expr.h>
#include <pango/pango-attributes.h>
typedef struct {
Workbook *wb;
......@@ -79,7 +80,7 @@ typedef struct {
} ExcelPalette;
typedef struct {
guint16 index;
unsigned index;
int height; /* in 1/20ths of a point */
int italic; /* boolean */
int struck_out; /* boolean : strikethrough */
......@@ -88,10 +89,11 @@ typedef struct {
int script; /* sub = -1, none = 0, super = 1 */
MsBiffFontUnderline underline;
char *fontname;
PangoAttrList *attrs;
} BiffFontData;
typedef struct {
guint16 idx;
unsigned idx;
char *name;
} BiffFormatData;
......
......@@ -3,7 +3,7 @@
/*
* ms-obj.c: MS Excel Object support for Gnumeric
*
* Copyright (C) 2000-2002
* Copyright (C) 2000-2004
* Jody Goldberg (jody@gnome.org)
* Michael Meeks (mmeeks@gnu.org)
*
......@@ -122,6 +122,20 @@ ms_obj_attr_new_expr (MSObjAttrID id, GnmExpr const *expr)
return res;
}
MSObjAttr *
ms_obj_attr_new_markup (MSObjAttrID id, PangoAttrList *markup)
{
MSObjAttr *res = g_new (MSObjAttr, 1);
g_return_val_if_fail ((id & MS_OBJ_ATTR_MASK) == MS_OBJ_ATTR_IS_PANGO_ATTR_LIST_MASK, NULL);
/* be anal about constness */
*((MSObjAttrID *)&(res->id)) = id;
res->v.v_markup = markup;
pango_attr_list_ref (markup);
return res;
}
guint32
ms_obj_attr_get_uint (MSObj *obj, MSObjAttrID id, guint32 default_value)
{
......@@ -192,6 +206,20 @@ ms_obj_attr_get_expr (MSObj *obj, MSObjAttrID id, GnmExpr const *default_value)
return attr->v.v_expr;
}
PangoAttrList *
ms_obj_attr_get_markup (MSObj *obj, MSObjAttrID id, PangoAttrList *default_value)
{
MSObjAttr *attr;
g_return_val_if_fail (obj != NULL, default_value);
g_return_val_if_fail (id & MS_OBJ_ATTR_IS_PANGO_ATTR_LIST_MASK, default_value);
attr = ms_obj_attr_bag_lookup (obj->attrs, id);
if (attr == NULL)
return default_value;
return attr->v.v_markup;
}
static void
ms_obj_attr_destroy (MSObjAttr *attr)
{
......@@ -208,6 +236,10 @@ ms_obj_attr_destroy (MSObjAttr *attr)
attr->v.v_expr != NULL) {
gnm_expr_unref (attr->v.v_expr);
attr->v.v_expr = NULL;
} else if ((attr->id & MS_OBJ_ATTR_IS_PANGO_ATTR_LIST_MASK) &&
attr->v.v_markup != NULL) {
pango_attr_list_unref (attr->v.v_markup);
attr->v.v_markup = NULL;
}
g_free (attr);
}
......@@ -389,11 +421,27 @@ ms_obj_dump_impl (guint8 const *data, int len, int data_left, char const *name)
#define ms_obj_dump (data, len, data_left, name)
#endif
typedef struct {
unsigned first, last;
PangoAttrList *accum;
} TXORun;
static gboolean
append_txorun (PangoAttribute *src, TXORun *run)
{
PangoAttribute *dst = pango_attribute_copy (src);
dst->start_index = run->first;
dst->end_index = run->last;
pango_attr_list_change (run->accum, dst);
return FALSE;
}
/* S59DAD.HTM */
static gboolean
ms_obj_read_pre_biff8_obj (BiffQuery *q, MSContainer *container, MSObj *obj)
{
guint16 peek_op, tmp, len;
int txo_len;
guint8 const *data;
gboolean const has_fmla = GSF_LE_GET_GUINT16 (q->data+26) != 0;
......@@ -416,10 +464,6 @@ ms_obj_read_pre_biff8_obj (BiffQuery *q, MSContainer *container, MSObj *obj)
break;
case 1: /* line */
tmp = GSF_LE_GET_GUINT8 (q->data+40);
if (GSF_LE_GET_GUINT16 (q->data + 10) == 0 &&
GSF_LE_GET_GUINT16 (q->data + 14) < 20) {
g_warning("%hhu", tmp);
}
if (GSF_LE_GET_GUINT8 (q->data+38) & 0x0F)
ms_obj_attr_bag_insert (obj->attrs,
ms_obj_attr_new_flag (MS_OBJ_ATTR_ARROW_END));
......@@ -452,31 +496,54 @@ ms_obj_read_pre_biff8_obj (BiffQuery *q, MSContainer *container, MSObj *obj)
ms_obj_attr_new_uint (MS_OBJ_ATTR_FILL_COLOR,
0x80000000 | GSF_LE_GET_GUINT8 (q->data+35)));
}
ms_obj_attr_bag_insert (obj->attrs,
ms_obj_attr_new_uint (MS_OBJ_ATTR_FONT_COLOR,
0x80000000 | GSF_LE_GET_GUINT8 (q->data+34)));
ms_obj_attr_bag_insert (obj->attrs,
ms_obj_attr_new_uint (MS_OBJ_ATTR_OUTLINE_COLOR,
0x80000000 | GSF_LE_GET_GUINT8 (q->data+38)));
/* only pull in the text if it exists */
len = GSF_LE_GET_GUINT16 (q->data + 44);
if (len > 0) {
txo_len = GSF_LE_GET_GUINT16 (q->data + 48);
tmp = GSF_LE_GET_GUINT16 (q->data + 50);
data = q->data + 70;
g_return_val_if_fail ((unsigned)(data - q->data) < q->length, TRUE);
g_return_val_if_fail (!has_fmla, TRUE); /* how would this happen */
/* skip the obj name if defined */
if (has_name) {
data += *data + ((*data & 0x1) ? 1 : 2); /* padding byte */
g_return_val_if_fail ((unsigned)(data - q->data) < q->length, TRUE);
g_return_val_if_fail ((unsigned)(data - q->data) <= q->length, TRUE);
}
if (len > 0)
ms_obj_attr_bag_insert (obj->attrs,
ms_obj_attr_new_ptr (MS_OBJ_ATTR_TEXT,
g_strndup (data, len)));
data += (len & 1) ? (len+1) : len; /* padding byte */
if (txo_len > 0) {
TXORun txo_run;
g_return_val_if_fail (txo_len >= 16, TRUE); /* min two records */
g_return_val_if_fail ((unsigned)(data+txo_len-q->data) == q->length, TRUE);
txo_run.last = G_MAXINT;
txo_run.accum = pango_attr_list_new ();
for (txo_len -= 16 ; txo_len >= 0 ; txo_len -= 8) {
txo_run.first = GSF_LE_GET_GUINT16 (data + txo_len);
pango_attr_list_filter (ms_container_get_markup (
container, GSF_LE_GET_GUINT16 (data + txo_len + 2)),
(PangoAttrFilterFunc) append_txorun, &txo_run);
txo_run.last = txo_run.first - 1;
}
ms_obj_attr_bag_insert (obj->attrs,
ms_obj_attr_new_markup (MS_OBJ_ATTR_MARKUP, txo_run.accum));
pango_attr_list_unref (txo_run.accum<