Commit 1e5613ea authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Move richtext import to pango's convention of byte offsets, rather than

character.

2004-04-20  Jody Goldberg <jody@gnome.org>

	* ms-excel-read.c (sst_read_string) : Use the right string when
	  calculating offsets.
parent 2276f9d1
2004-04-20 Jody Goldberg <jody@gnome.org>
* src/stf-export.c (stf_export_sheet) : simplify
2004-04-20 Morten Welinder <terra@gnome.org>
* src/stf-parse.c (stf_parse_sheet): Handle the case of more
......
2004-04-20 Jody Goldberg <jody@gnome.org>
* src/stf-export.c (stf_export_sheet) : simplify
2004-04-20 Morten Welinder <terra@gnome.org>
* src/stf-parse.c (stf_parse_sheet): Handle the case of more
......
2004-04-20 Jody Goldberg <jody@gnome.org>
* ms-excel-read.c (sst_read_string) : Use the right string when
calculating offsets.
2004-04-19 Jody Goldberg <jody@gnome.org>
* ms-chart.c (BC_R(end)) : graph style wants outline not line
......
......@@ -249,7 +249,8 @@ append_txorun (PangoAttribute *src, TXORun *run)
return FALSE;
}
PangoAttrList *
ms_container_read_markup (MSContainer const *c, guint8 const *data, int txo_len)
ms_container_read_markup (MSContainer const *c,
guint8 const *data, int txo_len, char const *str)
{
TXORun txo_run;
......@@ -258,7 +259,8 @@ ms_container_read_markup (MSContainer const *c, guint8 const *data, int txo_len)
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);
txo_run.first = g_utf8_offset_to_pointer (str,
GSF_LE_GET_GUINT16 (data + txo_len)) - str;
pango_attr_list_filter (ms_container_get_markup (
c, GSF_LE_GET_GUINT16 (data + txo_len + 2)),
(PangoAttrFilterFunc) append_txorun, &txo_run);
......
......@@ -57,6 +57,8 @@ GnmExpr const *ms_container_parse_expr (MSContainer *c,
Sheet *ms_container_sheet (MSContainer const *c);
GnmFormat *ms_container_get_fmt (MSContainer const *c, unsigned indx);
PangoAttrList *ms_container_get_markup (MSContainer const *c, unsigned indx);
PangoAttrList *ms_container_read_markup (MSContainer const *c, guint8 const *data, int txo_len);
PangoAttrList *ms_container_read_markup (MSContainer const *c,
guint8 const *data, int txo_len,
char const *str);
#endif /* MS_OFFICE_CONTAINER_H */
......@@ -906,7 +906,8 @@ append_markup (PangoAttribute *src, TXORun *run)
}
static PangoAttrList *
excel_read_LABEL_markup (BiffQuery *q, ExcelReadSheet *esheet, unsigned str_len)
excel_read_LABEL_markup (BiffQuery *q, ExcelReadSheet *esheet,
char const *str, unsigned str_len)
{
guint8 const * const end = q->data + q->length;
guint8 const *ptr = q->data + 8 + str_len;
......@@ -926,7 +927,8 @@ excel_read_LABEL_markup (BiffQuery *q, ExcelReadSheet *esheet, unsigned str_len)
txo_run.accum = pango_attr_list_new ();
while (n > 0) {
n -= 4;
txo_run.first = GSF_LE_GET_GUINT16 (ptr + n);
txo_run.first = g_utf8_offset_to_pointer (str,
GSF_LE_GET_GUINT16 (ptr + n)) - str;
pango_attr_list_filter (ms_container_get_markup (
c, GSF_LE_GET_GUINT16 (ptr + n + 2)),
(PangoAttrFilterFunc) append_markup, &txo_run);
......@@ -942,7 +944,8 @@ excel_read_LABEL_markup (BiffQuery *q, ExcelReadSheet *esheet, unsigned str_len)
txo_run.accum = pango_attr_list_new ();
while (n > 0) {
n -= 2;
txo_run.first = GSF_LE_GET_GUINT8 (ptr + n);
txo_run.first = g_utf8_offset_to_pointer (str,
GSF_LE_GET_GUINT8 (ptr + n)) - str;
pango_attr_list_filter (ms_container_get_markup (
c, GSF_LE_GET_GUINT8 (ptr + n + 1)),
(PangoAttrFilterFunc) append_markup, &txo_run);
......@@ -1003,8 +1006,8 @@ sst_read_string (BiffQuery *q, MSContainer const *c,
for (i = total_n_markup ; i-- > 0 ; offset += 4) {
offset = ms_biff_query_bound_check (q, offset, 4);
if ((q->length - offset) >= 4) {
txo_run.last = g_utf8_offset_to_pointer (str,
GSF_LE_GET_GUINT16 (q->data+offset)) - str;
txo_run.last = g_utf8_offset_to_pointer (res->str,
GSF_LE_GET_GUINT16 (q->data+offset)) - res->str;
if (prev_markup != NULL) {
pango_attr_list_filter (prev_markup,
(PangoAttrFilterFunc) append_markup, &txo_run);
......@@ -5006,11 +5009,14 @@ excel_read_LABEL (BiffQuery *q, ExcelReadSheet *esheet, gboolean has_markup)
excel_set_xf (esheet, q);
if (txt != NULL) {
GnmFormat *fmt = NULL;
if (has_markup)
fmt = style_format_new_markup (
excel_read_LABEL_markup (q, esheet, txt, str_len));
/* might free txt, do not do this until after parsing markup */
v = value_new_string_nocopy (txt);
if (has_markup) {
PangoAttrList *markup =
excel_read_LABEL_markup (q, esheet, str_len);
GnmFormat *fmt = style_format_new_markup (markup);
if (fmt != NULL) {
value_set_fmt (v, fmt);
style_format_unref (fmt);
}
......
......@@ -378,7 +378,7 @@ ms_read_TXO (BiffQuery *q, MSContainer *c, PangoAttrList **markup)
if (ms_biff_query_peek_next (q, &op) && op == BIFF_CONTINUE) {
ms_biff_query_next (q);
*markup = ms_container_read_markup (c, q->data, q->length);
*markup = ms_container_read_markup (c, q->data, q->length, text);
} else
g_warning ("Unusual, TXO text with no formatting has 0x%x @ 0x%x", op, q->streamPos);
} else {
......@@ -423,20 +423,36 @@ ms_obj_dump_impl (guint8 const *data, int len, int data_left, char const *name)
static gboolean
read_pre_biff8_read_str (BiffQuery *q, MSContainer *container, MSObj *obj,
MSObjAttrID id, guint8 const **first, unsigned len)
MSObjAttrID text_id, guint8 const **first,
unsigned len, unsigned txo_len)
{
guint8 const *last = q->data + q->length;
char *str;
g_return_val_if_fail (*first + len <= last, TRUE);
g_return_val_if_fail (text_id != MS_OBJ_ATTR_NONE, TRUE);
if (id != MS_OBJ_ATTR_NONE)
ms_obj_attr_bag_insert (obj->attrs,
ms_obj_attr_new_ptr (id, ms_biff_get_chars (*first, len, FALSE)));
str = ms_biff_get_chars (*first, len, FALSE);
ms_obj_attr_bag_insert (obj->attrs, ms_obj_attr_new_ptr (text_id, str));
*first += len;
if (((*first - q->data) & 1))
(*first)++; /* pad to word bound */
if (txo_len > 0) {
guint8 const *last = q->data + q->length;
PangoAttrList *markup;
g_return_val_if_fail ((*first + txo_len) <= last, TRUE);
markup = ms_container_read_markup (container, *first, txo_len, str);
ms_obj_attr_bag_insert (obj->attrs,
ms_obj_attr_new_markup (MS_OBJ_ATTR_MARKUP, markup));
pango_attr_list_unref (markup);
*first += txo_len;
}
return FALSE;
}
......@@ -471,30 +487,6 @@ read_pre_biff8_read_expr (BiffQuery *q, MSContainer *container, MSObj *obj,
return FALSE;
}
static gboolean
read_pre_biff8_read_markup (BiffQuery *q, MSContainer *container, MSObj *obj,
MSObjAttrID id, guint8 const **first,
int txo_len, unsigned if_empty)
{
if (txo_len > 0) {
guint8 const *last = q->data + q->length;
PangoAttrList *markup;
g_return_val_if_fail ((*first + txo_len) <= last, TRUE);
markup = ms_container_read_markup (container, *first, txo_len);
ms_obj_attr_bag_insert (obj->attrs,
ms_obj_attr_new_markup (MS_OBJ_ATTR_MARKUP, markup));
pango_attr_list_unref (markup);
*first += txo_len;
} else
ms_obj_attr_bag_insert (obj->attrs,
ms_obj_attr_new_markup (MS_OBJ_ATTR_MARKUP,
ms_container_get_markup (container, if_empty)));
return FALSE;
}
static guint8 const *
read_pre_biff8_read_name_and_fmla (BiffQuery *q, MSContainer *container, MSObj *obj,
gboolean has_name, unsigned offset)
......@@ -503,8 +495,8 @@ read_pre_biff8_read_name_and_fmla (BiffQuery *q, MSContainer *container, MSObj *
gboolean const fmla_len = GSF_LE_GET_GUINT16 (q->data+26);
if (has_name &&
read_pre_biff8_read_str (q, container, obj,
MS_OBJ_ATTR_OBJ_NAME, &data, *(data++)))
read_pre_biff8_read_str (q, container, obj, MS_OBJ_ATTR_OBJ_NAME,
&data, *(data++), 0))
return NULL;
if (read_pre_biff8_read_expr (q, container, obj,
MS_OBJ_ATTR_NONE, &data, fmla_len))
......@@ -597,10 +589,13 @@ ms_obj_read_pre_biff8_obj (BiffQuery *q, MSContainer *c, MSObj *obj)
data = read_pre_biff8_read_name_and_fmla (q, c, obj, has_name, 70);
if (data == NULL ||
read_pre_biff8_read_str (q, c, obj,
MS_OBJ_ATTR_TEXT, &data, len) ||
read_pre_biff8_read_markup (q, c, obj,
MS_OBJ_ATTR_MARKUP, &data, txo_len, if_empty))
MS_OBJ_ATTR_TEXT, &data, len, txo_len))
return TRUE;
if (txo_len == 0)
ms_obj_attr_bag_insert (obj->attrs,
ms_obj_attr_new_markup (MS_OBJ_ATTR_MARKUP,
ms_container_get_markup (c, if_empty)));
break;
case 7: /* button */
......@@ -664,9 +659,7 @@ ms_obj_read_pre_biff8_obj (BiffQuery *q, MSContainer *c, MSObj *obj)
data = read_pre_biff8_read_name_and_fmla (q, c, obj, has_name, 70);
if (data == NULL ||
read_pre_biff8_read_str (q, c, obj,
MS_OBJ_ATTR_TEXT, &data, len) ||
read_pre_biff8_read_markup (q, c, obj,
MS_OBJ_ATTR_MARKUP, &data, 16, 0))
MS_OBJ_ATTR_TEXT, &data, len, 16))
return TRUE;
break;
case 0xF : /* dialog frame */
......
2004-04-19 Jody Goldberg <jody@gnome.org>
http://bugzilla.gnome.org/show_bug.cgi?id=127411
* graph/gog-chart.c (gog_chart_view_render) : render the style.
2004-04-17 Jody Goldberg <jody@gnome.org>
......
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* stf-export.c : Structured Text Format Exporter (STF-E)
* Engine to construct CSV files
......@@ -370,7 +371,7 @@ static gboolean
stf_export_sheet (StfExportOptions_t *export_options, Sheet *sheet)
{
GString *separator;
gboolean error = FALSE;
char const *newline;
int col, row;
GnmRange r;
......@@ -385,45 +386,27 @@ stf_export_sheet (StfExportOptions_t *export_options, Sheet *sheet)
separator = g_string_new (NULL);
g_string_append_unichar (separator, export_options->cell_separator);
r = sheet_get_extent (sheet, FALSE);
switch (export_options->terminator_type) {
default:
g_warning ("Unknown line terminator, defaulting to \\n");
case TERMINATOR_TYPE_LINEFEED : newline = "\n"; break;
case TERMINATOR_TYPE_RETURN : newline = "\r"; break;
case TERMINATOR_TYPE_RETURN_LINEFEED : newline = "\r\n"; break;
}
r = sheet_get_extent (sheet, FALSE);
for (row = r.start.row; row <= r.end.row; row++) {
for (col = r.start.col; col <= r.end.col; col++) {
GnmCell *cell = sheet_cell_get (sheet, col, row);
if (!stf_export_cell (export_options, cell)) {
for (col = r.start.col; col <= r.end.col; col++)
if (!stf_export_cell (export_options,
sheet_cell_get (sheet, col, row)) ||
(col != r.end.col &&
!export_options->write_func (separator->str,
export_options->write_data))) {
g_string_free (separator, TRUE);
return FALSE;
}
if (col != r.end.col)
if (!export_options->write_func (separator->str, export_options->write_data)) {
g_string_free (separator, TRUE);
return FALSE;
}
}
error = FALSE;
switch (export_options->terminator_type) {
case TERMINATOR_TYPE_LINEFEED :
if (!export_options->write_func ("\n", export_options->write_data))
error = TRUE;
break;
case TERMINATOR_TYPE_RETURN :
if (!export_options->write_func ("\r", export_options->write_data))
error = TRUE;
break;
case TERMINATOR_TYPE_RETURN_LINEFEED :
if (!export_options->write_func ("\r\n", export_options->write_data))
error = TRUE;
break;
default :
g_warning ("STF-E : Unknown terminator type");
break;
}
if (error) {
if (!export_options->write_func (newline, export_options->write_data)) {
g_string_free (separator, TRUE);
return FALSE;
}
......@@ -432,7 +415,6 @@ stf_export_sheet (StfExportOptions_t *export_options, Sheet *sheet)
return TRUE;
}
/**
* stf_export:
* @export_options: an export options struct
......@@ -445,7 +427,7 @@ stf_export_sheet (StfExportOptions_t *export_options, Sheet *sheet)
gboolean
stf_export (StfExportOptions_t *export_options)
{
GSList *iterator;
GSList *ptr;
g_return_val_if_fail (export_options != NULL, FALSE);
g_return_val_if_fail (export_options->terminator_type != TERMINATOR_TYPE_UNKNOWN, FALSE);
......@@ -453,20 +435,10 @@ stf_export (StfExportOptions_t *export_options)
g_return_val_if_fail (export_options->sheet_list != NULL, FALSE);
g_return_val_if_fail (export_options->quoting_mode != QUOTING_MODE_UNKNOWN, FALSE);
iterator = export_options->sheet_list;
while (iterator) {
for (ptr = export_options->sheet_list; ptr != NULL ; ptr = ptr->next)
if (!stf_export_sheet (export_options, iterator->data))
break;
iterator = g_slist_next (iterator);
}
if (iterator) /* hmm, something went wrong */
return FALSE;
else
return TRUE;
return ptr == 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