Commit 9c2b76bc authored by Jon Kåre Hellan's avatar Jon Kåre Hellan

Illustrate margin definitions. (print_headers): Header, not top margin,

* src/print.c: Illustrate margin definitions.
(print_headers): Header, not top margin, should be top of header
area.
(print_footers): Footer, not bottom margin, should be top of
footer area.

* src/xml-io.c (xml_print_info_fix_margins): New function fix up
incorrectly stored margins.
(xml_read_print_margins): Use it.

* src/dialogs/dialog-printer-setup.c (do_fetch_margins,
do_setup_margin): Header, not top margin, should be top of header area
and footer, not bottom margin, should be top of footer area.

* plugins/excel/ms-excel-read.c (ms_excel_init_margins): New
function. Initialize margins to Excel defaults.  (ms_excel_sheet_new):
Call ms_excel_init_margins.

* plugins/excel/ms-excel-write.c (write_sheet_bools): Write margins
also for biff 7 (which is what we actually use).
parent 78d2c517
2001-02-10 Jon K Hellan <hellan@acm.org>
* src/print.c: Illustrate margin definitions.
(print_headers): Header, not top margin, should be top of header
area.
(print_footers): Footer, not bottom margin, should be top of
footer area.
* src/xml-io.c (xml_print_info_fix_margins): New function fix up
incorrectly stored margins.
(xml_read_print_margins): Use it.
2001-02-10 Jody Goldberg <jgoldberg@home.com>
* src/sheet-style.c (foreach_tile) : Only apply to applicable row or
......
2001-02-10 Jon K Hellan <hellan@acm.org>
* src/print.c: Illustrate margin definitions.
(print_headers): Header, not top margin, should be top of header
area.
(print_footers): Footer, not bottom margin, should be top of
footer area.
* src/xml-io.c (xml_print_info_fix_margins): New function fix up
incorrectly stored margins.
(xml_read_print_margins): Use it.
2001-02-10 Jody Goldberg <jgoldberg@home.com>
* src/sheet-style.c (foreach_tile) : Only apply to applicable row or
......
2001-02-10 Jon K Hellan <hellan@acm.org>
* src/print.c: Illustrate margin definitions.
(print_headers): Header, not top margin, should be top of header
area.
(print_footers): Footer, not bottom margin, should be top of
footer area.
* src/xml-io.c (xml_print_info_fix_margins): New function fix up
incorrectly stored margins.
(xml_read_print_margins): Use it.
2001-02-10 Jody Goldberg <jgoldberg@home.com>
* src/sheet-style.c (foreach_tile) : Only apply to applicable row or
......
2001-02-10 Jon K Hellan <hellan@acm.org>
* src/print.c: Illustrate margin definitions.
(print_headers): Header, not top margin, should be top of header
area.
(print_footers): Footer, not bottom margin, should be top of
footer area.
* src/xml-io.c (xml_print_info_fix_margins): New function fix up
incorrectly stored margins.
(xml_read_print_margins): Use it.
2001-02-10 Jody Goldberg <jgoldberg@home.com>
* src/sheet-style.c (foreach_tile) : Only apply to applicable row or
......
2001-02-10 Jon K Hellan <hellan@acm.org>
* src/print.c: Illustrate margin definitions.
(print_headers): Header, not top margin, should be top of header
area.
(print_footers): Footer, not bottom margin, should be top of
footer area.
* src/xml-io.c (xml_print_info_fix_margins): New function fix up
incorrectly stored margins.
(xml_read_print_margins): Use it.
2001-02-10 Jody Goldberg <jgoldberg@home.com>
* src/sheet-style.c (foreach_tile) : Only apply to applicable row or
......
2001-02-10 Jon K Hellan <hellan@acm.org>
* ms-excel-read.c (ms_excel_init_margins): New
function. Initialize margins to Excel defaults.
(ms_excel_sheet_new): Call ms_excel_init_margins.
* ms-excel-write.c (write_sheet_bools): Write margins also for
biff 7 (which is what we actually use).
2001-02-09 Jody Goldberg <jgoldberg@home.com>
* ms-excel-read.c (ms_sheet_obj_create) : don't free the object on
......
......@@ -60,6 +60,7 @@ static ExcelSheet *ms_excel_sheet_new (ExcelWorkbook *wb,
const char *name);
static void ms_excel_workbook_attach (ExcelWorkbook *wb,
ExcelSheet *ans);
static void margin_read (PrintUnit *pu, double val);
void
ms_excel_unexpected_biff (BiffQuery *q, char const *state,
......@@ -2278,6 +2279,35 @@ ms_sheet_parse_expr (MSContainer *container, guint8 const *data, int length)
data, length);
}
/*
* ms_excel_init_margins
* @sheet ExcelSheet
*
* Excel only saves margins when any of the margins differs from the
* default. So we must initialize the margins to Excel's defaults, which
* are:
* Top, bottom: 1 in - 72 pt
* Left, right: 3/4 in - 48 pt
* Header, footer: 1/2 in - 36 pt
*/
static void
ms_excel_init_margins (ExcelSheet *sheet)
{
PrintInformation *pi;
g_return_if_fail (sheet != NULL);
g_return_if_fail (sheet->gnum_sheet != NULL);
g_return_if_fail (sheet->gnum_sheet->print_info != NULL);
pi = sheet->gnum_sheet->print_info;
margin_read (&pi->margins.top, 1.0);
margin_read (&pi->margins.bottom, 1.0);
margin_read (&pi->margins.left, 0.75);
margin_read (&pi->margins.right, 0.75);
margin_read (&pi->margins.header, 0.5);
margin_read (&pi->margins.footer, 0.5);
}
static ExcelSheet *
ms_excel_sheet_new (ExcelWorkbook *wb, const char *name)
{
......@@ -2302,6 +2332,8 @@ ms_excel_sheet_new (ExcelWorkbook *wb, const char *name)
ans->base_char_width = -1;
ans->base_char_width_default = -1;
ms_excel_init_margins (ans);
return ans;
}
......
......@@ -2959,12 +2959,10 @@ write_sheet_bools (BiffPut *bp, ExcelSheet *sheet)
MS_OLE_SET_GUINT16 (data, pi->center_vertically);
ms_biff_put_commit (bp);
if (ver >= MS_BIFF_V8) {
margin_write (bp, BIFF_LEFT_MARGIN, &pi->margins.left);
margin_write (bp, BIFF_RIGHT_MARGIN, &pi->margins.right);
margin_write (bp, BIFF_TOP_MARGIN, &pi->margins.top);
margin_write (bp, BIFF_BOTTOM_MARGIN, &pi->margins.bottom);
}
margin_write (bp, BIFF_LEFT_MARGIN, &pi->margins.left);
margin_write (bp, BIFF_RIGHT_MARGIN, &pi->margins.right);
margin_write (bp, BIFF_TOP_MARGIN, &pi->margins.top);
margin_write (bp, BIFF_BOTTOM_MARGIN, &pi->margins.bottom);
/* See: S59DE3.HTM */
data = ms_biff_put_len_next (bp, BIFF_SETUP, 34);
......
2001-02-10 Jon K Hellan <hellan@acm.org>
* dialog-printer-setup.c (do_fetch_margins, do_setup_margin):
Header, not top margin, should be top of header area and footer,
not bottom margin, should be top of footer area.
2001-01-23 Morten Welinder <terra@diku.dk>
* dialog-search-replace.c (dialog_search_replace): Renamed dialog
......
......@@ -777,19 +777,19 @@ do_setup_margin (dialog_print_info_t *dpi)
displayed_unit);
unit_editor_configure (&dpi->margins.top, dpi, "spin-top",
pm->top.points,
pm->header.points,
displayed_unit);
unit_editor_configure (&dpi->margins.header, dpi, "spin-header",
MAX (pm->header.points - pm->top.points, 0),
MAX (pm->top.points - pm->header.points, 0),
displayed_unit);
unit_editor_configure (&dpi->margins.left, dpi, "spin-left",
pm->left.points, displayed_unit);
unit_editor_configure (&dpi->margins.right, dpi, "spin-right",
pm->right.points, displayed_unit);
unit_editor_configure (&dpi->margins.bottom, dpi, "spin-bottom",
pm->bottom.points, displayed_unit);
pm->footer.points, displayed_unit);
unit_editor_configure (&dpi->margins.footer, dpi, "spin-footer",
MAX (pm->footer.points - pm->bottom.points, 0),
MAX (pm->bottom.points - pm->footer.points, 0),
displayed_unit);
container = GTK_BOX (glade_xml_get_widget (dpi->gui,
......@@ -1374,24 +1374,25 @@ unit_info_to_print_unit (UnitInfo *ui)
/*
* Header and footer are stored with Excel semantics, but displayed with
* more natural semantics. In Excel, both top margin and header are measured
* from top of sheet. The Gnumeric user interface presents header as the
* band between top margin and the print area. Bottom margin and footer are
* handled likewise. */
* from top of sheet. See illustration at start of src/print.c. The Gnumeric
* user interface presents header as the band between top margin and the
* print area. Bottom margin and footer are handled likewise.
*/
static void
do_fetch_margins (dialog_print_info_t *dpi)
{
PrintMargins *m = &dpi->pi->margins;
GtkToggleButton *t;
m->top = unit_info_to_print_unit (&dpi->margins.top);
m->bottom = unit_info_to_print_unit (&dpi->margins.bottom);
m->header = unit_info_to_print_unit (&dpi->margins.top);
m->footer = unit_info_to_print_unit (&dpi->margins.bottom);
m->left = unit_info_to_print_unit (&dpi->margins.left);
m->right = unit_info_to_print_unit (&dpi->margins.right);
m->header = unit_info_to_print_unit (&dpi->margins.header);
m->footer = unit_info_to_print_unit (&dpi->margins.footer);
m->top = unit_info_to_print_unit (&dpi->margins.header);
m->bottom = unit_info_to_print_unit (&dpi->margins.footer);
m->header.points += m->top.points;
m->footer.points += m->bottom.points;
m->top.points += m->header.points;
m->bottom.points += m->footer.points;
t = GTK_TOGGLE_BUTTON (glade_xml_get_widget (dpi->gui, "center-horizontal"));
dpi->pi->center_horizontally = t->active;
......
......@@ -40,6 +40,40 @@
extern int print_debugging;
/*
* Margins
*
* In the internal format, top and bottom margins, header and footer have
* the same semantics as in Excel. That is:
*
* +----------------------------------------+
* | ^ ^ |
* | | top |header |
* | |margin v |
* |-- |------------- |
* | v header text |
* |------+--------------------------+------|
* | | | |
* |<---->| |<---->| ^
* | left | Cell |right | |Increasing
* |margin| |margin| |y
* | | Grid | | |
*
* ~ ~ ~ ~
*
* | | | |
* |------+--------------------------+------|
* | ^ footer text |
* |-- |------------------------------------|
* | |bottom ^ |
* | |margin |footer |
* | v v |
* +----------------------------------------+
*
* In the GUI on the other hand, top margin means the empty space above the
* header text, and header area means the area from the top of the header
* text to the top of the cell grid. */
typedef struct {
/*
* Part 1: The information the user configures on the Print Dialog
......@@ -288,11 +322,11 @@ print_hf_line (PrintJobInfo *pj, PrintHF *hf, double y,
/* Check if there's room to print. top and bottom are on the clip
* path, so we are actually requiring room for a 6x4 pt
* character. */
if (ABS (top - bottom) < 8)
if (ABS (top - bottom) < 8)
return;
if (ABS (left - right) < 6)
return;
gnome_print_gsave (pj->print_context);
print_make_rectangle_path (pj->print_context,
......@@ -302,7 +336,7 @@ print_hf_line (PrintJobInfo *pj, PrintHF *hf, double y,
if (print_debugging > 0) {
static double dash[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
static gint n_dash = 6;
gnome_print_gsave (pj->print_context);
gnome_print_setdash (pj->print_context, n_dash, dash, 0.0);
gnome_print_stroke (pj->print_context);
......@@ -332,7 +366,7 @@ print_headers (PrintJobInfo *pj)
double top, bottom, y, ascender;
ascender = gnome_font_get_ascender (pj->decoration_font);
y = pj->height - pm->top.points - ascender;
y = pj->height - pm->header.points - ascender;
top = 1 + pj->height - MIN (pm->header.points, pm->top.points);
bottom = -1 + pj->height - MAX (pm->header.points, pm->top.points);
......@@ -354,7 +388,7 @@ print_footers (PrintJobInfo *pj)
PrintMargins *pm = &pj->pi->margins;
double top, bottom, y;
y = pm->bottom.points
y = pm->footer.points
+ gnome_font_get_descender (pj->decoration_font);
top = 1 + MAX (pm->footer.points, pm->bottom.points);
bottom = -1 + MIN (pm->footer.points, pm->bottom.points);
......@@ -1120,7 +1154,7 @@ sheet_print (WorkbookControlGUI *wbcg, Sheet *sheet,
GNOME_PRINT_DIALOG_RANGE|GNOME_PRINT_DIALOG_COPIES);
g_return_if_fail (gpd != NULL);
gnome_print_dialog_construct_range_page (
gpd,
GNOME_PRINT_RANGE_CURRENT|GNOME_PRINT_RANGE_ALL|
......
......@@ -393,7 +393,7 @@ xml_set_value_double (xmlNodePtr node, const char *name, double val,
if (precision < 0 || precision > DBL_DIG)
precision = DBL_DIG;
if (fabs (val) < 1e9 && fabs (val) > 1e-5)
snprintf (str, 100 + DBL_DIG, "%.*g", precision, val);
else
......@@ -813,7 +813,7 @@ xml_write_names (XmlParseContext *ctxt, GList *names)
*/
if (!names)
return NULL;
#endif
#endif
cur = xmlNewDocNode (ctxt->doc, ctxt->ns, "Names", NULL);
......@@ -1252,6 +1252,22 @@ xml_write_print_info (XmlParseContext *ctxt, PrintInformation *pi)
return cur;
}
/*
* Earlier versions of Gnumeric confused top margin with header, bottom margin
* with footer (see comment at top of print.c). We fix this by making sure
* that top > header and bottom > footer.
*/
#define DSWAP(a,b) { double tmp; tmp = a; a = b; b = tmp; }
static void
xml_print_info_fix_margins (PrintInformation *pi)
{
if (pi->margins.top.points < pi->margins.header.points)
DSWAP (pi->margins.top.points, pi->margins.header.points);
if (pi->margins.bottom.points < pi->margins.footer.points)
DSWAP (pi->margins.bottom.points, pi->margins.footer.points);
}
static void
xml_read_print_margins (XmlParseContext *ctxt, xmlNodePtr tree)
{
......@@ -1278,6 +1294,7 @@ xml_read_print_margins (XmlParseContext *ctxt, xmlNodePtr tree)
xml_get_print_unit (child, &pi->margins.header);
if ((child = e_xml_get_child_by_name (tree, "footer")))
xml_get_print_unit (child, &pi->margins.footer);
xml_print_info_fix_margins (pi);
}
static void
......
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