Commit d6fe542a authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Add some config variables to the application to allow for axis dependent

zooming based on the screen display resolution (eg 110 dpi).  No GUI currently
available.

2000-02-04  Jody Goldberg <jgoldberg@home.com>

	* src/widgets/widget-font-selector.c (font_selector_set_points) : new
	  function.
	* src/dialogs/dialog-cell-format.c (fmt_dialog_init_font_page) : Use it.

2000-02-04  Jody Goldberg <jgoldberg@home.com>

	* src/sheet.c (sheet_col_set_internal_width) : Scale by the axis
	  resolution adjment.
	(sheet_row_set_internal_height) : Ditto.
	(colrow_set_units) : Ditto.
	(sheet_compute_col_row_new_size) : Ditto.

	* src/item-bar.c (item_bar_fonts_init) : Scale by resolution.
	(item_bar_start_resize) : Ditto.
	(item_bar_event) : Ditto.

	* src/cell.c (cell_calc_dimensions) : Adjust interface to take the
	  cell. Scale the height test by the vertical resolution adjustment.

	* src/cell-draw.c (sheet_view_get_style_font) : rename from
	  sheet_get_style_font in preparation for view split.  Scale
	  the font by the average of the resolutions.
parent 1bca03e0
2000-02-04 Jody Goldberg <jgoldberg@home.com>
* src/widgets/widget-font-selector.c (font_selector_set_points) : new
function.
* src/dialogs/dialog-cell-format.c (fmt_dialog_init_font_page) : Use it.
2000-01-31 Michael Meeks <mmeeks@gnu.org>
* src/cell-draw.c (cell_draw): Ameliorate the 'Fatal Error' to
......@@ -9,6 +15,25 @@
* src/func.c: constify.
2000-02-04 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (sheet_col_set_internal_width) : Scale by the axis
resolution adjment.
(sheet_row_set_internal_height) : Ditto.
(colrow_set_units) : Ditto.
(sheet_compute_col_row_new_size) : Ditto.
* src/item-bar.c (item_bar_fonts_init) : Scale by resolution.
(item_bar_start_resize) : Ditto.
(item_bar_event) : Ditto.
* src/cell.c (cell_calc_dimensions) : Adjust interface to take the
cell. Scale the height test by the vertical resolution adjustment.
* src/cell-draw.c (sheet_view_get_style_font) : rename from
sheet_get_style_font in preparation for view split. Scale
the font by the average of the resolutions.
2000-02-03 Jody Goldberg <jgoldberg@home.com>
* src/xml-io.c (xml_{read,write}_selection_info) : New functions.
......
2000-02-04 Jody Goldberg <jgoldberg@home.com>
* src/widgets/widget-font-selector.c (font_selector_set_points) : new
function.
* src/dialogs/dialog-cell-format.c (fmt_dialog_init_font_page) : Use it.
2000-01-31 Michael Meeks <mmeeks@gnu.org>
* src/cell-draw.c (cell_draw): Ameliorate the 'Fatal Error' to
......@@ -9,6 +15,25 @@
* src/func.c: constify.
2000-02-04 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (sheet_col_set_internal_width) : Scale by the axis
resolution adjment.
(sheet_row_set_internal_height) : Ditto.
(colrow_set_units) : Ditto.
(sheet_compute_col_row_new_size) : Ditto.
* src/item-bar.c (item_bar_fonts_init) : Scale by resolution.
(item_bar_start_resize) : Ditto.
(item_bar_event) : Ditto.
* src/cell.c (cell_calc_dimensions) : Adjust interface to take the
cell. Scale the height test by the vertical resolution adjustment.
* src/cell-draw.c (sheet_view_get_style_font) : rename from
sheet_get_style_font in preparation for view split. Scale
the font by the average of the resolutions.
2000-02-03 Jody Goldberg <jgoldberg@home.com>
* src/xml-io.c (xml_{read,write}_selection_info) : New functions.
......
......@@ -48,12 +48,6 @@ static ExcelSheet *ms_excel_sheet_new (ExcelWorkbook *wb,
static void ms_excel_workbook_attach (ExcelWorkbook *wb,
ExcelSheet *ans);
/* FIXME : MS quotes its measurments in 'pts' but scales that
* to the screen somehow. This is a crude approximation
* just scales things by 1.4.
*/
#define MAGIC_ZOOM 1.4
void
ms_excel_unexpected_biff (BiffQuery *q, char const *const state)
{
......@@ -1939,10 +1933,7 @@ ms_excel_sheet_new (ExcelWorkbook *wb, const char *name)
ans->gnum_sheet = sheet_new (wb->gnum_wb, name);
/* HACK HACK HACK : default zoom to 1.4 for now.
* See SCL for details.
*/
sheet_set_zoom_factor (ans->gnum_sheet, MAGIC_ZOOM);
sheet_set_zoom_factor (ans->gnum_sheet, 1.);
ans->wb = wb;
ans->obj_queue = NULL;
......@@ -3305,12 +3296,7 @@ ms_excel_read_sheet (ExcelSheet *sheet, BiffQuery *q, ExcelWorkbook *wb)
double const zoom = (double)MS_OLE_GET_GUINT16 (q->data) /
MS_OLE_GET_GUINT16 (q->data + 2);
/* FIXME : HACK HACK HACK
* MS stores sizes in pts but seems to scale
* the points -> pixels depending on the monitor size.
* Pick a quick scale factor to avoid looking really ugly.
*/
sheet_set_zoom_factor (sheet->gnum_sheet, zoom*MAGIC_ZOOM);
sheet_set_zoom_factor (sheet->gnum_sheet, zoom);
} else
g_warning ("Duff BIFF_SCL record");
break;
......@@ -3913,14 +3899,12 @@ ms_excel_read_workbook (CommandContext *context, Workbook *workbook,
#endif
/* FIXME FIXME FIXME :
* This is wrong on many levels.
* 1) We are scaling this by arbitrary factors.
* 2) We are sizing the window including the toolbars,
* menus, and notbook tabs. Excel does not.
* We are sizing the window including the toolbars,
* menus, and notbook tabs. Excel does not.
*/
workbook_view_set_size (wb->gnum_wb,
width*1.35 / 20.,
height*1.5 / 20.);
width / 20.,
height / 20.);
if (options & 0x0001)
printf ("Unsupported : Hidden workbook\n");
......
......@@ -18,6 +18,9 @@ typedef struct
Sheet * clipboard_sheet;
CellRegion * clipboard_copied_contents;
Range clipboard_cut_range;
/* Display resolution */
float horizontal_dpi, vertical_dpi;
} GnumericApplication;
static GnumericApplication app;
......@@ -30,8 +33,30 @@ static GnumericApplication app;
void
application_init (void)
{
gboolean h_was_default = TRUE;
gboolean v_was_default = TRUE;
app.clipboard_copied_contents = NULL;
app.clipboard_sheet = NULL;
app.horizontal_dpi = 110.;
app.vertical_dpi = 120.;
gnome_config_push_prefix ("Gnumeric/Screen_Resolution/");
app.horizontal_dpi =
gnome_config_get_float_with_default ("Horizontal_dpi=110",
&h_was_default);
app.vertical_dpi =
gnome_config_get_float_with_default ("Vertical_dpi=120",
&v_was_default);
if (h_was_default)
gnome_config_set_float ("Horizontal_dpi", app.horizontal_dpi);
if (v_was_default)
gnome_config_set_float ("Vertical_dpi", app.vertical_dpi);
if (h_was_default || v_was_default)
gnome_config_sync ();
gnome_config_pop_prefix ();
}
/**
......@@ -222,3 +247,19 @@ application_workbook_get_by_index (int i)
return close.wb;
}
float
application_display_dpi_get (gboolean const horizontal)
{
return horizontal ? app.horizontal_dpi : app.vertical_dpi;
}
void
application_display_dpi_set (gboolean const horizontal, float const val)
{
if (horizontal)
app.horizontal_dpi = val;
else
app.vertical_dpi = val;
}
......@@ -19,4 +19,8 @@ Sheet * application_clipboard_sheet_get (void);
CellRegion * application_clipboard_contents_get (void);
Range const* application_clipboard_area_get (void);
float application_display_dpi_get (gboolean const horizontal);
void application_display_dpi_set (gboolean const horizontal, float const);
#endif /* GNUMERIC_APPLICATION_H */
......@@ -101,15 +101,6 @@ cell_split_text (GdkFont *font, char const *text, int const width)
return list;
}
static inline StyleFont *
sheet_get_style_font (const Sheet *sheet, MStyle *mstyle)
{
double zoom = sheet->last_zoom_factor_used;
StyleFont *font = mstyle_get_font (mstyle, zoom);
return font;
}
/*
* Returns the number of columns used for the draw
*/
......@@ -137,7 +128,7 @@ cell_draw (Cell *cell, MStyle *mstyle,
g_return_val_if_fail (GNUMERIC_IS_SHEET (gsheet), 1);
canvas = GNOME_CANVAS (gsheet);
style_font = sheet_get_style_font (cell->sheet, mstyle);
style_font = sheet_view_get_style_font (cell->sheet, mstyle);
font = style_font_gdk_font (style_font);
text_base = y1 + cell->row->pixels - font->descent;
......
......@@ -18,6 +18,7 @@
#include "cursors.h"
#include "utils.h"
#include "gnumeric-util.h"
#include "application.h"
static int redraws_frozen = 0;
static int redraws_deep_frozen = 0;
......@@ -1186,7 +1187,7 @@ cell_get_span (Cell *cell, int *col1, int *col2)
/*
* calc_text_dimensions
* @is_number: whether we are computing the size for a number.
* @cell: The cell we are working on.
* @style: the style formatting constraints (font, alignments)
* @text: the string contents.
* @cell_w: the cell width
......@@ -1202,11 +1203,12 @@ cell_get_span (Cell *cell, int *col1, int *col2)
* please keep it that way.
*/
static void
calc_text_dimensions (int is_number, MStyle *mstyle,
const char *text, int cell_w, int cell_h, int *h, int *w,
double zoom)
calc_text_dimensions (Cell *cell, MStyle *mstyle,
const char *text, int *h, int *w)
{
StyleFont *style_font = mstyle_get_font (mstyle, zoom);
gboolean const is_number = cell_is_number (cell);
int const cell_w = COL_INTERNAL_WIDTH (cell->col);
StyleFont *style_font = sheet_view_get_style_font (cell->sheet, mstyle);
GdkFont *gdk_font = style_font->dfont->gdk_font;
int text_width, font_height;
......@@ -1289,7 +1291,6 @@ calc_text_dimensions (int is_number, MStyle *mstyle,
void
cell_calc_dimensions (Cell *cell)
{
char *rendered_text;
int left, right;
g_return_if_fail (cell != NULL);
......@@ -1297,25 +1298,24 @@ cell_calc_dimensions (Cell *cell)
cell_unregister_span (cell);
if (cell->text) {
char *rendered_text = cell->text->str;
MStyle *mstyle = sheet_style_compute (cell->sheet,
cell->col->pos,
cell->row->pos);
int h, w;
rendered_text = cell->text->str;
calc_text_dimensions (cell_is_number (cell),
mstyle, rendered_text,
COL_INTERNAL_WIDTH (cell->col),
ROW_INTERNAL_HEIGHT (cell->row),
&h, &w,
cell->sheet->last_zoom_factor_used);
calc_text_dimensions (cell, mstyle, rendered_text, &h, &w);
cell->width = cell->col->margin_a + cell->col->margin_b + w;
cell->height = cell->row->margin_a + cell->row->margin_b + h;
if (!cell->row->hard_size &&
(cell->height * cell->sheet->last_zoom_factor_used) > cell->row->pixels)
sheet_row_set_internal_height (cell->sheet, cell->row, h);
if (!cell->row->hard_size) {
double const scale =
cell->sheet->last_zoom_factor_used *
application_display_dpi_get (FALSE) / 72.;
if ((cell->height * scale) > cell->row->pixels)
sheet_row_set_internal_height (cell->sheet, cell->row, h);
}
mstyle_unref (mstyle);
} else
......
......@@ -22,6 +22,7 @@
#include "formats.h"
#include "pattern.h"
#include "mstyle.h"
#include "application.h"
#define GLADE_FILE "cell-format.glade"
......@@ -1197,6 +1198,11 @@ fmt_dialog_init_font_page (FormatState *state)
if (!mstyle_is_element_conflict (state->style, MSTYLE_FONT_SIZE))
font_selector_set_points (state->font.selector,
mstyle_get_font_size (state->style));
/* Set the resolution scaling factor */
font_selector_set_screen_res (state->font.selector,
application_display_dpi_get (TRUE),
application_display_dpi_get (FALSE));
}
/*****************************************************************************/
......
......@@ -16,6 +16,7 @@
#include "gnumeric-util.h"
#include "selection.h"
#include "workbook-cmd-format.h"
#include "application.h"
/* Marshal forward declarations */
static void item_bar_marshal (GtkObject *,
......@@ -84,12 +85,14 @@ item_bar_fonts_init (ItemBar *item_bar)
{
double const zoom_factor =
item_bar->sheet_view->sheet->last_zoom_factor_used;
double const res = MIN(application_display_dpi_get (FALSE),
application_display_dpi_get (TRUE)) / 72.;
StyleFont * const normal_font =
style_font_new_simple (DEFAULT_FONT, DEFAULT_SIZE,
zoom_factor, FALSE, FALSE);
res*zoom_factor, FALSE, FALSE);
StyleFont * const bold_font =
style_font_new_simple (DEFAULT_FONT, DEFAULT_SIZE,
zoom_factor, TRUE, FALSE);
res*zoom_factor, TRUE, FALSE);
/* Now that we have the new fonts unref the old ones */
item_bar_fonts_unref (item_bar);
......@@ -384,7 +387,8 @@ static void
item_bar_start_resize (ItemBar *bar)
{
Sheet const * const sheet = bar->sheet_view->sheet;
double const zoom = sheet->last_zoom_factor_used;
double const res = application_display_dpi_get (bar->orientation == GTK_ORIENTATION_VERTICAL);
double const zoom = sheet->last_zoom_factor_used * res / 72.;
GnumericSheet const * const gsheet = GNUMERIC_SHEET (bar->sheet_view->sheet_view);
GnomeCanvas const * const canvas = GNOME_CANVAS (gsheet);
GnomeCanvasGroup * const group = GNOME_CANVAS_GROUP (canvas->root);
......@@ -514,9 +518,10 @@ item_bar_event (GnomeCanvasItem *item, GdkEvent *e)
GnomeCanvas * const canvas = item->canvas;
ItemBar * const item_bar = ITEM_BAR (item);
Sheet * const sheet = item_bar->sheet_view->sheet;
double const zoom = sheet->last_zoom_factor_used;
const gboolean resizing = ITEM_BAR_RESIZING (item_bar);
const gboolean is_vertical = (item_bar->orientation == GTK_ORIENTATION_VERTICAL);
double const res = application_display_dpi_get (is_vertical);
double const zoom = sheet->last_zoom_factor_used * res / 72.;
int pos, start, element;
/* NOTE :
......
......@@ -12,6 +12,7 @@
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "item-edit.h"
#include "application.h"
#define CURSOR_LEN 4
static GnomeCanvasItem *item_edit_parent_class;
......@@ -59,9 +60,11 @@ item_edit_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int xd, yd, wd, hd, dx, dy;
char *text;
int cursor_pos, text_len, first_part_len, total_len;
double const res = MIN(application_display_dpi_get (FALSE),
application_display_dpi_get (TRUE)) / 72.;
style_font = mstyle_get_font (item_edit->mstyle,
item_edit->sheet->last_zoom_factor_used);
item_edit->sheet->last_zoom_factor_used * res);
font = style_font_gdk_font (style_font);
......
......@@ -20,6 +20,7 @@
#include "gnumeric-util.h"
#include "utils.h"
#include "selection.h"
#include "application.h"
/* Sizes for column/row headers */
......@@ -873,6 +874,20 @@ sheet_view_adjust_preferences (SheetView *sheet_view)
gtk_widget_hide (sheet_view->vs);
}
StyleFont *
sheet_view_get_style_font (const Sheet *sheet, MStyle *mstyle)
{
/* Scale the font size by the average scaling factor for the
* display. 72dpi is base size
*/
double const zoom = sheet->last_zoom_factor_used;
double const res = MIN(application_display_dpi_get (FALSE),
application_display_dpi_get (TRUE)) / 72.;
return mstyle_get_font (mstyle, zoom * res);
}
#if 0
#ifdef ENABLE_BONOBO
void
......
......@@ -88,6 +88,8 @@ void sheet_view_selection_unant (SheetView *sheet_view);
void sheet_view_adjust_preferences (SheetView *sheet_view);
StyleFont * sheet_view_get_style_font (Sheet const *sheet, MStyle *mstyle);
typedef struct {
GtkTableClass parent_class;
} SheetViewClass;
......
......@@ -20,6 +20,7 @@
#include "gnumeric-util.h"
#include "utils.h"
#include "selection.h"
#include "application.h"
/* Sizes for column/row headers */
......@@ -873,6 +874,20 @@ sheet_view_adjust_preferences (SheetView *sheet_view)
gtk_widget_hide (sheet_view->vs);
}
StyleFont *
sheet_view_get_style_font (const Sheet *sheet, MStyle *mstyle)
{
/* Scale the font size by the average scaling factor for the
* display. 72dpi is base size
*/
double const zoom = sheet->last_zoom_factor_used;
double const res = MIN(application_display_dpi_get (FALSE),
application_display_dpi_get (TRUE)) / 72.;
return mstyle_get_font (mstyle, zoom * res);
}
#if 0
#ifdef ENABLE_BONOBO
void
......
......@@ -88,6 +88,8 @@ void sheet_view_selection_unant (SheetView *sheet_view);
void sheet_view_adjust_preferences (SheetView *sheet_view);
StyleFont * sheet_view_get_style_font (Sheet const *sheet, MStyle *mstyle);
typedef struct {
GtkTableClass parent_class;
} SheetViewClass;
......
......@@ -98,8 +98,8 @@ static void
sheet_init_default_styles (Sheet *sheet)
{
/* Sizes seem to match excel */
col_row_info_init (&sheet->cols.default_style, 62.0);
col_row_info_init (&sheet->rows.default_style, 15.0);
col_row_info_init (&sheet->cols.default_style, 40.);
col_row_info_init (&sheet->rows.default_style, 9.);
}
/* Initialize some of the columns and rows, to test the display engine */
......@@ -284,7 +284,9 @@ sheet_foreach_colrow (Sheet *sheet, ColRowCollection *infos,
static gboolean
sheet_compute_col_row_new_size (Sheet *sheet, ColRowInfo *ci, void *data)
{
double const pix_per_unit = sheet->last_zoom_factor_used;
double const pix_per_unit =
sheet->last_zoom_factor_used *
application_display_dpi_get ((gboolean)data) / 72.;
gboolean const hidden = (ci->pixels < 0);
ci->pixels = (ci->units + ci->margin_a_pt + ci->margin_b_pt) * pix_per_unit;
......@@ -313,14 +315,14 @@ sheet_set_zoom_factor (Sheet *sheet, double factor)
sheet->last_zoom_factor_used = factor;
/* First, the default styles */
sheet_compute_col_row_new_size (sheet, &sheet->rows.default_style, NULL);
sheet_compute_col_row_new_size (sheet, &sheet->cols.default_style, NULL);
sheet_compute_col_row_new_size (sheet, &sheet->rows.default_style, (void*)FALSE);
sheet_compute_col_row_new_size (sheet, &sheet->cols.default_style, (void*)TRUE);
/* Then every column and row */
sheet_foreach_colrow (sheet, &sheet->cols, 0, SHEET_MAX_COLS-1,
&sheet_compute_col_row_new_size, NULL);
sheet_foreach_colrow (sheet, &sheet->rows, 0, SHEET_MAX_ROWS-1,
&sheet_compute_col_row_new_size, NULL);
&sheet_compute_col_row_new_size, (void*)FALSE);
sheet_foreach_colrow (sheet, &sheet->cols, 0, SHEET_MAX_COLS-1,
&sheet_compute_col_row_new_size, (void*)TRUE);
for (l = sheet->sheet_views; l; l = l->next){
SheetView *sheet_view = l->data;
......@@ -466,9 +468,10 @@ sheet_compute_visible_ranges (Sheet const *sheet)
}
static void
colrow_set_units (Sheet *sheet, ColRowInfo *info)
colrow_set_units (Sheet *sheet, ColRowInfo *info, gboolean const horizontal)
{
double const pix = sheet->last_zoom_factor_used;
double const pix = sheet->last_zoom_factor_used *
application_display_dpi_get (horizontal) / 72.;
int p = info->pixels;
if (p < 0) p = -p;
......@@ -644,7 +647,7 @@ sheet_row_info_set_height (Sheet *sheet, ColRowInfo *ri, int height, gboolean he
ri->hard_size = TRUE;
ri->pixels = (ri->pixels >= 0) ? height : -height;
colrow_set_units (sheet, ri);
colrow_set_units (sheet, ri, FALSE);
sheet_compute_visible_ranges (sheet);
......@@ -704,7 +707,8 @@ sheet_row_set_internal_height (Sheet *sheet, ColRowInfo *ri, double height)
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (ri != NULL);
pix = sheet->last_zoom_factor_used;
pix = sheet->last_zoom_factor_used *
application_display_dpi_get (FALSE) / 72.;
if (ri->units == height)
return;
......@@ -739,7 +743,8 @@ sheet_col_set_internal_width (Sheet *sheet, ColRowInfo *ci, double width)
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (ci != NULL);
pix = sheet->last_zoom_factor_used;
pix = sheet->last_zoom_factor_used *
application_display_dpi_get (TRUE) / 72.;
if (ci->units == width)
return;
......@@ -976,7 +981,7 @@ sheet_col_info_set_width (Sheet *sheet, ColRowInfo *ci, int width)
ci->pixels = (ci->pixels >= 0) ? width : -width;
colrow_set_units (sheet, ci);
colrow_set_units (sheet, ci, FALSE);
sheet_compute_visible_ranges (sheet);
sheet_redraw_all (sheet);
......
......@@ -5,7 +5,7 @@
#include <libgnomeprint/gnome-font.h>
#define DEFAULT_FONT "Helvetica"
#define DEFAULT_SIZE 12.0
#define DEFAULT_SIZE 10.0
typedef struct _MStyleBorder MStyleBorder;
......
......@@ -50,7 +50,7 @@ reload_preview (FontSelector *fs)
fs->is_bold ? GNOME_FONT_BOLD : GNOME_FONT_BOOK,
fs->is_italic,
fs->size,
1.0);
fs->resolution_adjustment_factor);
if (!display_font) {
g_warning ("Uh oh, cannot get the display font");
......@@ -245,6 +245,7 @@ fs_init (FontSelector *fs)
fs->size = 10;
fs->is_bold = fs->is_italic = FALSE;
fs->resolution_adjustment_factor = 1.;
fs->font_name_entry = glade_xml_get_widget (fs->gui, "font-name-entry");
fs->font_style_entry = glade_xml_get_widget (fs->gui, "font-style-entry");
fs->font_size_entry = glade_xml_get_widget (fs->gui, "font-size-entry");
......@@ -385,3 +386,12 @@ font_selector_set_points (FontSelector *fs,
}
}
void
font_selector_set_screen_res (FontSelector *fs, float h_dpi, float v_dpi)
{
g_return_if_fail (IS_FONT_SELECTOR (fs));
fs->resolution_adjustment_factor = MIN(h_dpi, v_dpi) / 72.;
reload_preview (fs);
}
......@@ -24,6 +24,7 @@ typedef struct {
gboolean is_bold;
gboolean is_italic;
double size;
double resolution_adjustment_factor;
/* The current gnome_font */
GnomeFont *gnome_font;
......@@ -45,5 +46,8 @@ void font_selector_set_style (FontSelector *fs,
void font_selector_set_points (FontSelector *fs,
double point_size);
void font_selector_set_screen_res (FontSelector *fs,
float h_dpi,
float v_dpi);
#endif /* GNUMERIC_WIDGET_FONT_SELECTOR_H */
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