Commit a7948285 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg
Browse files

More tuning for General.

2000-10-18  Jody Goldberg <jgoldberg@home.com>

	* src/format.c (fmt_general_float) : clamp the precision at DBL_PREC.

	* src/rendered-value.c (rendered_value_new_ext) : Don't forget the
	  intercharacter spacing when approximating the width of a character.

	* src/str.c (string_get_nocopy) : new function.

	* src/cell.c (cell_set_value) : Use it.

2000-10-16  Jody Goldberg <jgoldberg@home.com>

	* src/rendered-value.c (rendered_value_new_ext) : fix some leaks.
parent 9d7b7209
2000-10-18 Jody Goldberg <jgoldberg@home.com>
* src/format.c (fmt_general_float) : clamp the precision at DBL_PREC.
* src/rendered-value.c (rendered_value_new_ext) : Don't forget the
intercharacter spacing when approximating the width of a character.
* src/str.c (string_get_nocopy) : new function.
* src/cell.c (cell_set_value) : Use it.
2000-10-16 Jody Goldberg <jgoldberg@home.com>
* src/rendered-value.c (rendered_value_new_ext) : fix some leaks.
......
2000-10-18 Jody Goldberg <jgoldberg@home.com>
* src/format.c (fmt_general_float) : clamp the precision at DBL_PREC.
* src/rendered-value.c (rendered_value_new_ext) : Don't forget the
intercharacter spacing when approximating the width of a character.
* src/str.c (string_get_nocopy) : new function.
* src/cell.c (cell_set_value) : Use it.
2000-10-16 Jody Goldberg <jgoldberg@home.com>
* src/rendered-value.c (rendered_value_new_ext) : fix some leaks.
......
2000-10-18 Jody Goldberg <jgoldberg@home.com>
* src/format.c (fmt_general_float) : clamp the precision at DBL_PREC.
* src/rendered-value.c (rendered_value_new_ext) : Don't forget the
intercharacter spacing when approximating the width of a character.
* src/str.c (string_get_nocopy) : new function.
* src/cell.c (cell_set_value) : Use it.
2000-10-16 Jody Goldberg <jgoldberg@home.com>
* src/rendered-value.c (rendered_value_new_ext) : fix some leaks.
......
2000-10-18 Jody Goldberg <jgoldberg@home.com>
* src/format.c (fmt_general_float) : clamp the precision at DBL_PREC.
* src/rendered-value.c (rendered_value_new_ext) : Don't forget the
intercharacter spacing when approximating the width of a character.
* src/str.c (string_get_nocopy) : new function.
* src/cell.c (cell_set_value) : Use it.
2000-10-16 Jody Goldberg <jgoldberg@home.com>
* src/rendered-value.c (rendered_value_new_ext) : fix some leaks.
......
2000-10-18 Jody Goldberg <jgoldberg@home.com>
* src/format.c (fmt_general_float) : clamp the precision at DBL_PREC.
* src/rendered-value.c (rendered_value_new_ext) : Don't forget the
intercharacter spacing when approximating the width of a character.
* src/str.c (string_get_nocopy) : new function.
* src/cell.c (cell_set_value) : Use it.
2000-10-16 Jody Goldberg <jgoldberg@home.com>
* src/rendered-value.c (rendered_value_new_ext) : fix some leaks.
......
......@@ -438,7 +438,8 @@ cell_set_value (Cell *cell, Value *v, StyleFormat *opt_fmt)
g_free (tmp);
} else if (opt_fmt) {
/* If available use the supplied format */
cell->entered_text = string_get (format_value (opt_fmt, v, NULL, NULL, -1));
cell->entered_text = string_get_nocopy (
format_value (opt_fmt, v, NULL, NULL, -1));
} else {
/* Fall back on using the format applied to the cell.
* re-render using the assigned format to handle width
......@@ -446,7 +447,8 @@ cell_set_value (Cell *cell, Value *v, StyleFormat *opt_fmt)
*/
MStyle *mstyle = cell_get_mstyle (cell);
StyleFormat *format = mstyle_get_format (mstyle);
cell->entered_text = string_get (format_value (format, v, NULL, NULL, -1));
cell->entered_text = string_get_nocopy (
format_value (format, v, NULL, NULL, -1));
mstyle_unref (mstyle);
}
}
......
......@@ -1452,7 +1452,7 @@ fmt_general_float (float_t val, float col_width)
log_val = log10 (abs_val);
if (col_width >= 0.) {
prec = (int) floor (col_width - .2); /* '.' is small */
prec = (int) floor (col_width - .5); /* '.' is small */
/* Display 0 for cols that are too narrow for scientific
* notation with 1 > abs (value) >= 0 */
......@@ -1461,15 +1461,19 @@ fmt_general_float (float_t val, float col_width)
if (tmp >= prec)
return g_strdup ("0");
}
if (prec > DBL_DIG)
prec = DBL_DIG;
} else
prec = DBL_DIG;
/* Decrease the precision if we are going to use scientific notation
* the E+00 take up space */
if (log_val > prec || log_val < -3.)
prec -= 4;
else if (log_val < 0.)
prec += (int)floor (log_val);
/* FIXME : glib bug. it does not handle G, use g */
/* FIXME : glib bug. it does not handle G, use g (fixed in 1.2.9) */
return g_strdup_printf ("%.*g", prec, val);
}
......
......@@ -102,12 +102,18 @@ rendered_value_new_ext (Cell *cell, MStyle *mstyle)
/* FIXME : how does one get the width of the
* widest character used to display numbers.
* Use 4 as the max width for now.
* Use 4 as the max width for now. Count the
* inter character spacing by measuring a
* string with 10 digits
*
* This does not belong here at all. There
* should be a global scaled StyleFont cache
* indexed by stylefont and scale (res*zoom)
* which pre-calculates this stuff.
*/
double const font_width = gdk_string_measure
(gdk_font, "4");
double const font_width = gdk_string_measure (gdk_font, "4444444444") / 10.;
if (font_width > 0)
col_width = COL_INTERNAL_WIDTH (cell->col_info) / font_width;
col_width = (COL_INTERNAL_WIDTH (cell->col_info)) / font_width;
style_font_unref (style_font);
} else
......
......@@ -43,6 +43,34 @@ string_get (const char *s)
return string;
}
/*
* string_get_nocopy :
*
* Take control of the supplied string.
* delete it if it is already availabl.e
*/
String *
string_get_nocopy (char *s)
{
String *string;
string = string_lookup (s);
if (string){
string_ref (string);
g_free (s);
return string;
}
/* If non-existant, create */
string = g_new (String, 1);
string->ref_count = 1;
string->str = s;
g_hash_table_insert (string_hash_table, string->str, string);
return string;
}
String *
string_ref (String *string)
{
......
......@@ -12,6 +12,7 @@ void string_init (void);
String *string_lookup (const char *s);
String *string_get (const char *s);
String *string_get_nocopy (char *s);
String *string_ref (String *);
void string_unref (String *);
......
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