Commit 2c7b7671 authored by Michael Meeks's avatar Michael Meeks

Add Jon to authors, Major Jon commit of Excel row/col size export, Fixup

Add Jon to authors,
Major Jon commit of Excel row/col size export,
Fixup html finaly,
parent 25c775f5
1999-12-18 Michael Meeks <mmeeks@gnu.org>
* src/about.c (dialog_about): add Jon.
1999-12-17 Jon K Hellan <hellan@acm.org>
* src/sheet.c (sheet_get_default_external_col_width): New
function. Get default column width in units, including margins.
(sheet_get_default_external_row_height): New function. Get default
row height in units, including margins.
(sheet_col_get_external_width): New function. Get column width in
units, including margins.
(sheet_row_get_external_height): New function. Get row height in
units, including margins.
* src/sheet.h: Declare new functions in sheet.c
1999-12-18 Michael Meeks <mmeeks@gnu.org>
* src/dialogs/dialog-cell-sort.c (dialog_cell_sort): add command context.
......
1999-12-18 Michael Meeks <mmeeks@gnu.org>
* src/about.c (dialog_about): add Jon.
1999-12-17 Jon K Hellan <hellan@acm.org>
* src/sheet.c (sheet_get_default_external_col_width): New
function. Get default column width in units, including margins.
(sheet_get_default_external_row_height): New function. Get default
row height in units, including margins.
(sheet_col_get_external_width): New function. Get column width in
units, including margins.
(sheet_row_get_external_height): New function. Get row height in
units, including margins.
* src/sheet.h: Declare new functions in sheet.c
1999-12-18 Michael Meeks <mmeeks@gnu.org>
* src/dialogs/dialog-cell-sort.c (dialog_cell_sort): add command context.
......
......@@ -275,3 +275,6 @@ Office 2000 and 'explorer' compatibility.
* Excel Import
* Localise sheet/workbook Name import,
* Import names even if they arn't referenced.
* Html export
* Export style information for blank cells.
\ No newline at end of file
1999-12-17 Jon K Hellan <hellan@acm.org>
* ms-excel-write.h (struct _ExcelCol ): define it
(struct _ExcelSheet): Add base_char_width
* ms-excel-write.c (log_put_color, palette_get_index,
gather_palette, write_palette, excel_font_new, excel_font_hash,
excel_font_equal, after_put_format, map_pattern_index_to_excel,
halign_to_excel, valign_to_excel, fixup_fill_colors,
get_xf_differences, log_xf_data, build_xf_data,
write_xf_magic_record, write_value, write_formula, write_cell,
write_mulblank, pre_pass): Cosmetics
(write_font, write_fonts, write_format, write_formats,
write_xf_record, write_xf, write_workbook): Conform to
conventional parameter order
(orientation_to_excel, border_type_to_excel): Make inline
(write_default_row_height): New function. Write default row
height.
(lookup_base_char_width_for_write): New function. Locate font for
measuring base char width, and call measuring function.
(get_base_char_width): New function: Return base char width for
column sizing.
(write_default_col_width): New function. Write default col width.
(write_colinfo): New function. Write column info for a run of
identical columns
(write_colinfos): New function. Write column info for all columns.
(write_sheet_bools): Use write_default_row_height,
write_default_col_width, write_colinfos.
(write_sheet_bools):
(write_rowinfo): Write true row height. Add sheet to signature.
(write_sheet): Add sheet to write_rowinfo call.
(new_sheet): Initialize base_char_width.
* ms-excel-util.h: #include <sheet.h>
(EXCEL_DEFAULT_CHAR_WIDTH): Move here from ms-excel-read.h
(lookup_font_base_char_width): Declare it.
* ms-excel-util.c (lookup_font_base_char_width): New
function. Measure "base character width" of font. Previously in
lookup_base_char_width in ms-excel-read.c
* ms-excel-read.c: #include ms-excel-util.h
(lookup_base_char_width_for_read): Renamed from
lookup_base_char_width because of similar, but different function
in ms-excel-write.c. Split in two. Font locating stays here. Font
measuring moved to new function lookup_font_base_char_width in
ms-excel-util.c
(get_base_char_width): Use lookup_base_char_width_for_read.
(ms_excel_read_default_row_height): Refer to Excel doc page.
(ms_excel_read_default_col_width): Ditto
1999-12-14 Jon K Hellan <hellan@acm.org>
* ms-excel-write.h (XF_MAGIC, PALETTE_ALSO_BLACK, FILL_MAGIC,
......
......@@ -20,6 +20,7 @@
#include "selection.h"
#include "utils.h" /* for cell_name */
#include "ranges.h"
#include "ms-excel-util.h"
#include "ms-excel-xf.h"
/* #define NO_DEBUG_EXCEL */
......@@ -2346,37 +2347,14 @@ print_font_mapping_debug_info (ExcelSheet *sheet, MStyle const *ms)
#endif
/**
* lookup_base_char_width:
* lookup_base_char_width_for_read:
* @sheet the Excel sheet
*
* Measures base character width for column sizing. Returns width.
*
* There is no such thing as a typical width, but we have to do
* something.
*
* It looks like the width of 'n' is very close to Excel's concept of
* width. For Times in 3 sizes, the average is .45% too low, for
* Helvetica in 3 sizes it is .02% too low.
*
* Widths based on text samples come out lower, but can be used if
* scaled appropriately. Using the sample below, we reduce the
* difference in precision between Times and Helvetica to 0.13%.
*/
/*
* FIXME: If a column is marked italic, Excel exports a different width.
* Looks like it tracks bold/italic variations, but we know that it doesn't
* track family/size. Weird.
* Measures base character width for column sizing. Returns width
*/
static double
lookup_base_char_width (ExcelSheet *sheet)
lookup_base_char_width_for_read (ExcelSheet *sheet)
{
double scaling = 1.2304; /* Recalibrate if sample is changed !! */
static char *sample =
"Widths based on text samples come out too low, but "
"can be used if scaled appropriately. Experiments "
"showed that a 2 line sample was very slightly more";
MStyle *ms;
double res;
gboolean def;
......@@ -2386,7 +2364,7 @@ lookup_base_char_width (ExcelSheet *sheet)
* right so far.
*/
def = !sheet->wb->XF_cell_records ||
sheet->wb->XF_cell_records->len == 0;
(sheet->wb->XF_cell_records->len == 0);
if (def)
ms = NULL;
......@@ -2397,21 +2375,15 @@ lookup_base_char_width (ExcelSheet *sheet)
res = EXCEL_DEFAULT_CHAR_WIDTH;
else {
StyleFont *sf;
double samplewidth, average;
sf = mstyle_get_font (ms, 1.0);
samplewidth = gnome_font_get_width_string
(style_font_gnome_font (sf), sample);
average = samplewidth / strlen (sample);
res = average * scaling;
#ifndef NO_DEBUG_EXCEL
if (ms_excel_read_debug > 2) {
print_font_mapping_debug_info (sheet, ms);
printf ("Character width based on %d character sample:"
" %g - adjusted to %g\n",
strlen (sample), average, res);
}
#endif
res = lookup_font_base_char_width (sf,
(ms_excel_read_debug > 2));
style_font_unref (sf);
mstyle_unref (ms);
}
......@@ -2431,12 +2403,19 @@ lookup_base_char_width (ExcelSheet *sheet)
* This style is actually common to all sheets in the
* workbook, but I find it more robust to treat it as a sheet
* attribute.
*
* FIXME: There is a function with this name both in ms-excel-read.c and
* ms-excel-write.c. The only difference is lookup_base_char_width_for_read
* vs. lookup_base_char_width_for_write. Pass the function as parameter?
* May be not. I don't like clever code.
*/
static double
get_base_char_width (ExcelSheet *sheet)
{
if (sheet->base_char_width <= 0)
sheet->base_char_width = lookup_base_char_width (sheet);
sheet->base_char_width
= lookup_base_char_width_for_read (sheet);
return sheet->base_char_width;
}
......@@ -2922,6 +2901,7 @@ ms_excel_read_selection (ExcelSheet *sheet, BiffQuery *q)
* @sheet The Excel sheet
*
* Processes a BIFF default row height (BIFF_DEFAULTROWHEIGHT) record.
* See: S59D72.HTM
*/
static void
ms_excel_read_default_row_height (BiffQuery *q, ExcelSheet *sheet)
......@@ -2955,6 +2935,7 @@ ms_excel_read_default_row_height (BiffQuery *q, ExcelSheet *sheet)
* @sheet The Excel sheet
*
* Processes a BIFF default column width (BIFF_DEFCOLWIDTH) record.
* See: S59D73.HTM
*/
static void
ms_excel_read_default_col_width (BiffQuery *q, ExcelSheet *sheet)
......
......@@ -109,8 +109,6 @@ typedef struct _ExcelWorkbook
Workbook *gnum_wb;
} ExcelWorkbook;
#define EXCEL_DEFAULT_CHAR_WIDTH 12
extern ExcelSheet * ms_excel_workbook_get_sheet (ExcelWorkbook *wb, guint idx);
extern Sheet* biff_get_externsheet_name (ExcelWorkbook *wb, guint16 idx, gboolean get_first);
extern char* biff_get_text (guint8 const *ptr, guint32 length, guint32 *byte_length);
......
/**
* ms-excel-util.c: Utility functions for MS Excel export
* ms-excel-util.c: Utility functions for MS Excel import / export
*
* Author:
* Jon K Hellan (hellan@acm.org)
......@@ -161,3 +161,52 @@ two_way_table_idx_to_key (const TwoWayTable *table, gint idx)
return g_ptr_array_index (table->idx_to_key, idx - table->base);
}
/**
* lookup_font_base_char_width:
* @font the style font
* @logging_condition print debug log if this is true
*
* Measures base character width for column sizing. Returns width.
*
* There is no such thing as a typical width, but we have to do
* something.
*
* It looks like the width of 'n' is very close to Excel's concept of
* width. For Times in 3 sizes, the average is .45% too low, for
* Helvetica in 3 sizes it is .02% too low.
*
* Widths based on text samples come out lower, but can be used if
* scaled appropriately. Using the sample below, we reduce the
* difference in precision between Times and Helvetica to 0.13%.
*/
/*
* FIXME: If a column is marked italic, Excel exports a different width.
* Looks like it tracks bold/italic variations, but we know that it doesn't
* track family/size. Weird.
*/
double
lookup_font_base_char_width (StyleFont *font, gboolean logging_condition)
{
double scaling = 1.2304; /* Recalibrate if sample is changed !! */
static char *sample =
"Widths based on text samples come out too low, but "
"can be used if scaled appropriately. Experiments "
"showed that a 2 line sample was very slightly more";
double res;
double samplewidth, average;
samplewidth = gnome_font_get_width_string
(style_font_gnome_font (font), sample);
average = samplewidth / strlen (sample);
res = average * scaling;
#ifndef NO_DEBUG_EXCEL
if (logging_condition)
printf ("Character width based on %d character sample:"
" %g - adjusted to %g\n",
strlen (sample), average, res);
#endif
return res;
}
/**
* ms-excel-util.h: Utility functions for MS Excel export
* ms-excel-util.h: Utility functions for MS Excel import / export
*
* Author:
* Jon K Hellan (hellan@acm.org)
......@@ -10,6 +10,7 @@
#define GNUMERIC_MS_EXCEL_UTIL_H
#include <glib.h>
#include "sheet.h"
typedef struct _TwoWayTable TwoWayTable;
......@@ -45,5 +46,12 @@ two_way_table_key_to_idx (const TwoWayTable *table, gconstpointer key);
gpointer
two_way_table_idx_to_key (const TwoWayTable *table, gint idx);
#define EXCEL_DEFAULT_CHAR_WIDTH 12
/* Measures base character width for column sizing. Returns width. */
double
lookup_font_base_char_width (StyleFont *font, gboolean logging_condition);
#endif
This diff is collapsed.
......@@ -17,6 +17,7 @@
typedef struct _ExcelFont ExcelFont;
typedef struct _ExcelCell ExcelCell;
typedef struct _ExcelRow ExcelRow;
typedef struct _ExcelCol ExcelCol;
typedef struct _ExcelSheet ExcelSheet;
typedef struct _ExcelWorkbook ExcelWorkbook;
typedef struct _XF XF;
......@@ -52,6 +53,15 @@ struct _ExcelCell {
Cell *gnum_cell;
};
struct _ExcelCol
{
ExcelSheet *sheet;
guint16 first;
guint16 last;
double width;
guint16 xf;
};
struct _ExcelSheet {
ExcelWorkbook *wb;
Sheet *gnum_sheet;
......@@ -63,6 +73,7 @@ struct _ExcelSheet {
GHashTable *formula_cache;
gpointer cell_used_map;
ExcelCell *cells;
double base_char_width;
};
struct _ExcelWorkbook {
......
1999-12-18 Michael Meeks <mmeeks@gnu.org>
* html.c (html_get_color): implement helper.
(html_write_cell32, html_write_cell40): use it + be more defensive.
1999-12-18 Jarl van Katwijk <jarl@casema.net>
* html.c (html_write_cell32, html_write_cell40): fix stupid bug.
......
......@@ -76,6 +76,14 @@ html_write_cell_str (FILE *fp, Cell *cell, MStyle *mstyle)
fprintf (fp, "</TT>");
}
static void
html_get_color (MStyle *mstyle, MStyleElementType t, int *r, int *g, int *b)
{
*r = mstyle_get_color (mstyle, t)->color.red >> 8;
*g = mstyle_get_color (mstyle, t)->color.green >> 8;
*b = mstyle_get_color (mstyle, t)->color.blue >> 8;
}
/*
* write a TD
*/
......@@ -83,7 +91,7 @@ static void
html_write_cell32 (FILE *fp, Cell *cell)
{
MStyle *mstyle;
unsigned char r, g, b;
unsigned int r, g, b;
if (!cell) { /* empty cell */
fprintf (fp, "\t<TD>");
......@@ -107,15 +115,11 @@ html_write_cell32 (FILE *fp, Cell *cell)
}
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)
html_get_color (mstyle, MSTYLE_COLOR_BACK, &r, &g, &b);
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;
html_get_color (mstyle, MSTYLE_COLOR_FORE, &r, &g, &b);
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "<FONT color=\"#%02X%02X%02X\">",
r, g, b);
......@@ -135,7 +139,7 @@ static void
html_write_cell40 (FILE *fp, Cell *cell)
{
MStyle *mstyle;
unsigned char r, g, b;
unsigned int r, g, b;
if (!cell) { /* empty cell */
fprintf (fp, "\t<TD>");
......@@ -159,15 +163,11 @@ html_write_cell40 (FILE *fp, Cell *cell)
}
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)
html_get_color (mstyle, MSTYLE_COLOR_BACK, &r, &g, &b);
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;
html_get_color (mstyle, MSTYLE_COLOR_FORE, &r, &g, &b);
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "<FONT color=\"#%02X%02X%02X\">",
r, g, b);
......
......@@ -76,6 +76,14 @@ html_write_cell_str (FILE *fp, Cell *cell, MStyle *mstyle)
fprintf (fp, "</TT>");
}
static void
html_get_color (MStyle *mstyle, MStyleElementType t, int *r, int *g, int *b)
{
*r = mstyle_get_color (mstyle, t)->color.red >> 8;
*g = mstyle_get_color (mstyle, t)->color.green >> 8;
*b = mstyle_get_color (mstyle, t)->color.blue >> 8;
}
/*
* write a TD
*/
......@@ -83,7 +91,7 @@ static void
html_write_cell32 (FILE *fp, Cell *cell)
{
MStyle *mstyle;
unsigned char r, g, b;
unsigned int r, g, b;
if (!cell) { /* empty cell */
fprintf (fp, "\t<TD>");
......@@ -107,15 +115,11 @@ html_write_cell32 (FILE *fp, Cell *cell)
}
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)
html_get_color (mstyle, MSTYLE_COLOR_BACK, &r, &g, &b);
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;
html_get_color (mstyle, MSTYLE_COLOR_FORE, &r, &g, &b);
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "<FONT color=\"#%02X%02X%02X\">",
r, g, b);
......@@ -135,7 +139,7 @@ static void
html_write_cell40 (FILE *fp, Cell *cell)
{
MStyle *mstyle;
unsigned char r, g, b;
unsigned int r, g, b;
if (!cell) { /* empty cell */
fprintf (fp, "\t<TD>");
......@@ -159,15 +163,11 @@ html_write_cell40 (FILE *fp, Cell *cell)
}
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)
html_get_color (mstyle, MSTYLE_COLOR_BACK, &r, &g, &b);
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;
html_get_color (mstyle, MSTYLE_COLOR_FORE, &r, &g, &b);
if (r != 0 || g != 0 || b != 0)
fprintf (fp, "<FONT color=\"#%02X%02X%02X\">",
r, g, b);
......
......@@ -28,6 +28,7 @@ dialog_about (Workbook *wb)
N_("Ross Ihaka, special functions."),
N_("Jukka-Pekka Iivonen, numerous functions and tools."),
N_("Jakub Jelinek, Gnumeric hacker."),
N_("Jon K Hellan, Excel hacker."),
N_("Chris Lahey, Number format engine."),
N_("Adrian Likins, Documentation, debugging."),
N_("Takashi Matsuda, simple text plugin."),
......
......@@ -28,6 +28,7 @@ dialog_about (Workbook *wb)
N_("Ross Ihaka, special functions."),
N_("Jukka-Pekka Iivonen, numerous functions and tools."),
N_("Jakub Jelinek, Gnumeric hacker."),
N_("Jon K Hellan, Excel hacker."),
N_("Chris Lahey, Number format engine."),
N_("Adrian Likins, Documentation, debugging."),
N_("Takashi Matsuda, simple text plugin."),
......
......@@ -1006,6 +1006,76 @@ sheet_col_get_distance (Sheet const *sheet, int from, int to)
return pixels;
}
/**
* sheet_get_default_external_col_width:
*
* Return the default number of units in a column, including margins.
* This function returns the raw sum, no rounding etc.
*/
double
sheet_get_default_external_col_width (Sheet const *sheet)
{
ColRowInfo const *ci;
g_assert (sheet != NULL);
ci = &sheet->cols.default_style;
return ci->units + ci->margin_a_pt + ci->margin_b_pt;
}
/**
* sheet_get_default_external_row_height:
*
* Return the default number of units in a row, including margins.
* This function returns the raw sum, no rounding etc.
*/
double
sheet_get_default_external_row_height (Sheet const *sheet)
{
ColRowInfo const *ci;
g_assert (sheet != NULL);
ci = &sheet->rows.default_style;
return ci->units + ci->margin_a_pt + ci->margin_b_pt;
}
/**
* sheet_col_get_external_height:
*
* Return the number of units in a row, including margins.
* This function returns the raw sum. If you need rounding and
* fiddling, use sheet_col_get_unit_distance.
*/
double
sheet_col_get_external_width (Sheet const *sheet, int const pos)
{
ColRowInfo const *ci;
g_assert (sheet != NULL);
ci = sheet_col_get_info (sheet, pos);
return ci->units + ci->margin_a_pt + ci->margin_b_pt;
}
/**
* sheet_row_get_external_height:
*
* Return the number of units in a row, including margins.
* This function returns the raw sum. If you need rounding and
* fiddling, use sheet_row_get_unit_distance.
*/
double
sheet_row_get_external_height (Sheet const *sheet, int const pos)
{
ColRowInfo const *ci;
g_assert (sheet != NULL);
ci = sheet_row_get_info (sheet, pos);
return ci->units + ci->margin_a_pt + ci->margin_b_pt;
}
/**
* sheet_row_get_distance:
*
......
......@@ -227,6 +227,12 @@ ColRowInfo *sheet_col_fetch (Sheet *sheet, int pos);
void sheet_col_add (Sheet *sheet, ColRowInfo *cp);
void sheet_row_add (Sheet *sheet, ColRowInfo *cp);
/* Return the number of units (points) in a col/row, including margins */
double sheet_get_default_external_col_width (Sheet const *sheet);
double sheet_get_default_external_row_height (Sheet const *sheet);
double sheet_col_get_external_width (Sheet const *sheet, int const pos);
double sheet_row_get_external_height (Sheet const *sheet, int const pos);
/* Measure distances in pixels from one col/row to another */
int sheet_col_get_distance (Sheet const *sheet, int from_col, int to_col);
int sheet_row_get_distance (Sheet const *sheet, int from_row, int to_row);
......
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