Commit 9c2fdec5 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

fix unicode codepage to be actual unicode with the high bit lopped off,


2002-08-18  Jody Goldberg <jody@gnome.org>

	* ms-excel-util.c (excel_iconv_open_for_import) : fix unicode codepage
	  to be actual unicode with the high bit lopped off, which I hope is
	  synonymous with 8859-1.  This still needs to be translated into
	  utf8.
parent 91f126d9
2002-08-18 Jody Goldberg <jody@gnome.org>
* ms-excel-util.c (excel_iconv_open_for_import) : fix unicode codepage
to be actual unicode with the high bit lopped off, which I hope is
synonymous with 8859-1. This still needs to be translated into
utf8.
2002-08-17 Jon K Hellan <hellan@acm.org>
* ms-chart.c (BC_R): Fix typos.
......
......@@ -67,7 +67,7 @@
#define d(level, code)
#endif
static excel_iconv_t current_workbook_iconv = NULL;
static GIConv current_workbook_iconv = NULL;
char const *excel_builtin_formats[EXCEL_BUILTIN_FORMAT_LEN] = {
/* 0x00 */ "General",
......@@ -686,8 +686,8 @@ get_chars (char const *ptr, guint length, gboolean use_utf16)
char *outbuf = g_new (char, outbytes + 1);
ans = outbuf;
excel_iconv (current_workbook_iconv,
&ptr, &length, &outbuf, &outbytes);
g_iconv (current_workbook_iconv,
(char **)&ptr, &length, &outbuf, &outbytes);
i = outbuf - ans;
ans [i] = 0;
......@@ -4881,7 +4881,7 @@ ms_excel_read_workbook (IOContext *context, WorkbookView *wb_view,
/* MW: And on Excel seems to drive the display
of currency amounts. */
guint16 const codepage = GSF_LE_GET_GUINT16 (q->data);
excel_iconv_close (current_workbook_iconv);
gnm_iconv_close (current_workbook_iconv);
current_workbook_iconv = excel_iconv_open_for_import (codepage);
d (0, {
switch (codepage) {
......@@ -5034,8 +5034,8 @@ ms_excel_read_workbook (IOContext *context, WorkbookView *wb_view,
fflush (stdout);
}
#endif
excel_iconv_close (current_workbook_iconv);
current_workbook_iconv = 0;
gnm_iconv_close (current_workbook_iconv);
current_workbook_iconv = NULL;
if (wb) {
/* Cleanup */
ms_excel_workbook_destroy (wb);
......
/* vim: set sw=8: */
/**
* ms-excel-util.c: Utility functions for MS Excel import / export
*
......@@ -24,11 +25,6 @@
#include <langinfo.h>
#endif
#ifdef HAVE_ICONV_H
#define HAVE_ICONV
#include <iconv.h>
#endif
/*
* TwoWayTable
*
......@@ -461,74 +457,38 @@ excel_iconv_win_codepage (void)
}
/*these two will figure out which charset names to use*/
excel_iconv_t
GIConv
excel_iconv_open_for_import (guint codepage)
{
#ifndef HAVE_ICONV
iconv_t iconv_handle;
GIConv iconv_handle;
if (codepage != 1200 && codepage != 1201) {
char* src_charset = g_strdup_printf ("CP%d", codepage);
iconv_handle = iconv_open ("UTF-8", src_charset);
iconv_handle = g_iconv_open ("UTF-8", src_charset);
g_free (src_charset);
if (iconv_handle != (excel_iconv_t)(-1))
if (iconv_handle != (GIConv)(-1))
return iconv_handle;
g_warning ("Unknown codepage %d", codepage);
return (GIConv)(-1);
}
/* 1200 == little endian unicode */
#endif
return (excel_iconv_t)(-1);
/* this is 'compressed' unicode. unicode characters 0000->00FF
* which looks the same as 8859-1. I have no idea what little
* endian vs bigendian has to do with this. There is only 1
* byte, and it would certainly not be useful to keep the low
* byte as 0.
*/
return g_iconv_open ("UTF-8", "ISO-8859-1");
}
excel_iconv_t
GIConv
excel_iconv_open_for_export (void)
{
#ifndef HAVE_ICONV
return (excel_iconv_t)(-1);
#else
static char* dest_charset = NULL;
iconv_t iconv_handle;
GIConv iconv_handle;
if (!dest_charset)
dest_charset = g_strdup_printf ("CP%d", excel_iconv_win_codepage());
iconv_handle = iconv_open (dest_charset, "UTF-8");
iconv_handle = g_iconv_open (dest_charset, "UTF-8");
return iconv_handle;
#endif
}
void
excel_iconv_close (excel_iconv_t handle)
{
#ifdef HAVE_ICONV
if (handle && handle != (excel_iconv_t)(-1))
iconv_close (handle);
#endif
}
size_t
excel_iconv (excel_iconv_t handle,
char const * *inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft)
{
#ifndef HAVE_ICONV
guint tocopy = *inbytesleft <= *outbytesleft ? *inbytesleft : *outbytesleft;
memcpy(*outbuf,*inbuf,tocopy);
*outbuf += tocopy;
*inbuf += tocopy;
*outbytesleft -= tocopy;
*inbytesleft -= tocopy;
#else
while (*inbytesleft) {
if (handle && handle != (iconv_t)(-1))
iconv ((iconv_t)handle, (char **)inbuf, inbytesleft,
outbuf, outbytesleft);
if (!*inbytesleft || !*outbytesleft)
return 0;
/*got invalid seq - so replace it with original character*/
**outbuf = **inbuf; (*outbuf)++; (*outbytesleft)--;
(*inbuf)++; (*inbytesleft)--;
}
#endif
return 0;
}
......@@ -52,12 +52,7 @@ two_way_table_idx_to_key (const TwoWayTable *table, gint idx);
/* A new version based on hard coded tables to match XL */
double lookup_font_base_char_width (char const *name, double size_pts,
gboolean const is_default);
/* a group of iconv_* - like functions, with safe fallbacks if iconv is
* unavailable. Sorry for stupid prefix - Vlad Harchev <hvv@hippo.ru>
*/
typedef void* excel_iconv_t; /*can't be NULL or (-1) */
void destroy_xl_font_widths (void);
/*
* this returns code of the codepage that should be used when exporting
......@@ -66,19 +61,7 @@ typedef void* excel_iconv_t; /*can't be NULL or (-1) */
guint excel_iconv_win_codepage (void);
/*these two will figure out which charset names to use*/
excel_iconv_t excel_iconv_open_for_import (guint codepage);
excel_iconv_t excel_iconv_open_for_export (void);
void excel_iconv_close (excel_iconv_t handle);
/* if fails (or if compiled without support for iconv), it will copy the input
* string to output and pretend that all worked fine. If some char is
* non-convertable, it will replace that char with "?". It's required that
* inbytesleft <= outbytesleft (so that fallback will be able to work). As for
* now, return value is not meaningfull at all - 0 is always returned.
*/
size_t excel_iconv (excel_iconv_t handle, char const **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);
void destroy_xl_font_widths (void);
GIConv excel_iconv_open_for_import (guint codepage);
GIConv excel_iconv_open_for_export (void);
#endif
......@@ -62,7 +62,7 @@
#define N_ELEMENTS_BETWEEN_PROGRESS_UPDATES 20
static excel_iconv_t current_workbook_iconv = NULL;
static GIConv current_workbook_iconv = NULL;
static guint style_color_to_rgb888 (const StyleColor *c);
static gint palette_get_index (ExcelWorkbook *wb, guint c);
......@@ -98,13 +98,14 @@ biff_convert_text (char **buf, const char *txt, MsBiffVersion ver)
} else {
size_t inbufleft = len, outbufleft = len*8;
char *outbufptr;
char const * inbufptr = txt;
char const *inbufptr = txt;
*buf = g_new(char, outbufleft);
outbufptr = *buf;
excel_iconv (current_workbook_iconv, &inbufptr, &inbufleft,
&outbufptr, &outbufleft);
g_iconv (current_workbook_iconv,
(char **)&inbufptr, &inbufleft,
&outbufptr, &outbufleft);
len = outbufptr - *buf;
};
return len;
......@@ -3508,7 +3509,7 @@ write_workbook (IOContext *context, BiffPut *bp, ExcelWorkbook *wb, MsBiffVersio
s->streamPos);
}
/* End Finalised workbook */
excel_iconv_close (current_workbook_iconv);
gnm_iconv_close (current_workbook_iconv);
current_workbook_iconv = NULL;
}
......
/* vim: set sw=8: */
/**
* ms-summary.c: MS Excel support for Gnumeric
*
......@@ -24,7 +25,7 @@
typedef struct _MsOleSummaryHeader MsOleSummaryHeader;
typedef struct _MsOleSummaryRecord MsOleSummaryRecord;
typedef guint32 MsOleSummaryFileTime;
static excel_iconv_t current_summary_iconv = NULL;
static GIConv current_summary_iconv = NULL;
#define SUMMARY_DEBUG 0
......@@ -167,7 +168,7 @@ read_summary_items (SummaryInfo *sin, MsOleSummary *si, MsOlePropertySetID psid)
ptr++;
}
excel_iconv (current_summary_iconv,
g_iconv (current_summary_iconv,
&inbufptr, &inbytes,
&outbufptr, &outbytes);
......@@ -250,7 +251,7 @@ ms_summary_read (MsOle *f, SummaryInfo *sin)
printf ("ms_summary_read: Unable to open DocumentSummaryInformation.\n");
#endif
}
excel_iconv_close (current_summary_iconv);
gnm_iconv_close (current_summary_iconv);
current_summary_iconv = NULL;
}
......@@ -281,8 +282,8 @@ set_summary_item (SummaryItem *s_item, MsOleSummary *ms_sum)
char const * inbufptr = s_item->v.txt;
guint32 retlen;
excel_iconv (current_summary_iconv, &inbufptr, &inbufleft,
&outbufptr, &outbufleft);
g_iconv (current_summary_iconv, &inbufptr, &inbufleft,
&outbufptr, &outbufleft);
retlen = outbufptr - mbbuf;
ret = g_new(char, retlen + 1);
ret[retlen] = 0;
......@@ -365,7 +366,7 @@ ms_summary_write (MsOle *f, SummaryInfo *sin)
si = ms_ole_docsummary_create (f);
if (si == NULL) {
g_warning ("ms_summary_write: doc summary NOT created.");
excel_iconv_close (current_summary_iconv);
gnm_iconv_close (current_summary_iconv);
current_summary_iconv = NULL;
return;
}
......@@ -379,6 +380,6 @@ ms_summary_write (MsOle *f, SummaryInfo *sin)
g_list_free (si_list);
ms_ole_summary_close (si);
excel_iconv_close (current_summary_iconv);
gnm_iconv_close (current_summary_iconv);
current_summary_iconv = 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