Commit fc24c937 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Copy font description early. We aren't supposed to touch the result of

2006-05-08  Morten Welinder  <terra@gnome.org>

	* src/style.c (style_font_new_simple): Copy font description
	early.  We aren't supposed to touch the result of
	pango_context_get_font_description!
	(gnm_font_metrics_new, gnm_font_metrics_free): Moved to goffice.

	* src/style-font.h: Add GOFont and GOFontMetrics members.  Remove
	PangoFontDescription member.
parent 4fecaace
2006-05-08 Morten Welinder <terra@gnome.org>
* src/style.c (style_font_new_simple): Copy font description
early. We aren't supposed to touch the result of
pango_context_get_font_description!
(gnm_font_metrics_new, gnm_font_metrics_free): Moved to goffice.
* src/style-font.h: Add GOFont and GOFontMetrics members. Remove
PangoFontDescription member.
2006-05-08 Jody Goldberg <jody@gnome.org>
* configure.in : post release bump
......
Gnumeric 1.7.1
Morten:
* Moved font metrics to goffice.
* Fixed font initialization.
--------------------------------------------------------------------------
Gnumeric 1.7.0
PACKAGERS :
......
......@@ -260,7 +260,11 @@ ms_container_read_markup (MSContainer const *c,
txo_run.last = G_MAXINT;
txo_run.accum = pango_attr_list_new ();
g_print ("str=[%s] %d\n", str, strlen (str));
for (txo_len -= 16 ; txo_len >= 0 ; txo_len -= 8) {
g_print ("tco: %d %d\n",
GSF_LE_GET_GUINT16 (data + txo_len),
GSF_LE_GET_GUINT16 (data + txo_len + 2));
txo_run.first = g_utf8_offset_to_pointer (str,
GSF_LE_GET_GUINT16 (data + txo_len)) - str;
pango_attr_list_filter (ms_container_get_markup (
......
......@@ -392,25 +392,29 @@ ms_read_TXO (BiffQuery *q, MSContainer *c, PangoAttrList **markup)
if (ms_biff_query_peek_next (q, &op) && op == BIFF_CONTINUE) {
gboolean use_utf16;
guint maxlen;
ms_biff_query_next (q);
use_utf16 = q->data[0] != 0;
maxlen = use_utf16 ? q->length / 2 : q->length-1;
g_print ("maxlen=%d\n", maxlen);
text = excel_get_chars (c->importer,
q->data + 1, MIN (text_len, q->length-1), use_utf16);
if (q->length < text_len) {
q->data + 1, MIN (text_len, maxlen), use_utf16);
if (maxlen < text_len) {
GString *accum = g_string_new (text);
g_free (text);
text_len -= q->length - 1;
text_len -= maxlen;
while (ms_biff_query_peek_next (q, &op) && op == BIFF_CONTINUE) {
ms_biff_query_next (q);
text = excel_get_chars (c->importer, q->data,
MIN (q->length, text_len), use_utf16);
g_string_append (accum, text);
g_free (text);
if (text_len <= q->length)
maxlen = use_utf16 ? q->length / 2 : q->length;
if (text_len <= maxlen)
break;
text_len -= q->length;
text_len -= maxlen;
}
text = g_string_free (accum, FALSE);
}
......
......@@ -27,6 +27,7 @@
#include <goffice/utils/format-impl.h>
#include <goffice/utils/go-glib-extras.h>
#include <goffice/utils/go-font.h>
#include <glib/gi18n.h>
#include <string.h>
#include <stdio.h>
......@@ -192,7 +193,7 @@ zero_measure (const GString *str, PangoLayout *layout)
*/
static void
gnm_format_general (PangoLayout *layout, GString *str,
GnmFormatMeasure measure, const GnmFontMetrics *metrics,
GnmFormatMeasure measure, const GOFontMetrics *metrics,
gnm_float val,
int col_width,
gboolean unicode_minus)
......@@ -395,7 +396,7 @@ pango_measure (const GString *str, PangoLayout *layout)
void
gnm_format_layout (PangoLayout *result,
GnmFontMetrics *metrics,
GOFontMetrics *metrics,
GOFormat const *format,
GnmValue const *value, GOColor *go_color,
int col_width,
......@@ -508,7 +509,7 @@ format_value_gstring (GString *str, GOFormat const *format,
new_str = g_string_sized_new (G_ASCII_DTOSTR_BUF_SIZE + GNM_DIG);
gnm_format_general (NULL, str->len ? new_str : str,
strlen_measure,
gnm_font_metrics_unit,
go_font_metrics_unit,
val, col_width, unicode_minus);
if (new_str) {
go_string_append_gstring (str, new_str);
......
......@@ -15,7 +15,7 @@ void format_value_gstring (GString *result,
GODateConventions const *date_conv);
void gnm_format_layout (PangoLayout *result,
GnmFontMetrics *metrics,
GOFontMetrics *metrics,
GOFormat const *format,
GnmValue const *value, GOColor *go_color,
int col_width,
......
......@@ -41,6 +41,7 @@
#include <goffice/cut-n-paste/foocanvas/foo-canvas.h>
#include <gsf/gsf-impl-utils.h>
#include <string.h>
#include <goffice/utils/go-font.h>
static FooCanvasItemClass *parent_class;
......@@ -261,7 +262,7 @@ ie_layout (FooCanvasItem *item)
text = wbcg_edit_get_display_text (scg_get_wbcg (ie->scg));
pango_layout_set_text (ie->layout, text, -1);
pango_layout_set_font_description (ie->layout, gfont->pango.font_descr);
pango_layout_set_font_description (ie->layout, gfont->go.font->desc);
pango_layout_set_wrap (ie->layout, PANGO_WRAP_WORD_CHAR);
pango_layout_set_width (ie->layout, (int)(item->x2 - item->x1)*PANGO_SCALE);
......
......@@ -19,6 +19,7 @@
#include "gutils.h"
#include "gnumeric-gconf.h"
#include <goffice/utils/go-glib-extras.h>
#include <goffice/utils/go-font.h>
#include <stdio.h>
......@@ -1515,7 +1516,7 @@ gnm_style_get_pango_attrs (GnmStyle const *style,
{
GnmFont *font = gnm_style_get_font (style, context, zoom);
add_attr (l, pango_attr_font_desc_new (font->pango.font_descr));
add_attr (l, pango_attr_font_desc_new (font->go.font->desc));
}
add_attr (l, pango_attr_scale_new (zoom));
......
......@@ -35,6 +35,7 @@
#include "ranges.h"
#include "style-font.h"
#include "gnumeric-gconf.h"
#include <goffice/utils/go-font.h>
#include <libgnomeprint/gnome-print-job.h>
#include <libgnomeprint/gnome-print-config.h>
......@@ -288,7 +289,7 @@ ensure_decoration_layout (PrintJobInfo *pj)
1.);
pj->decoration_layout = layout;
pango_layout_set_font_description (layout, font->pango.font_descr);
pango_layout_set_font_description (layout, font->go.font->desc);
gnm_style_unref (style);
}
return pj->decoration_layout;
......
......@@ -39,6 +39,7 @@
#include <string.h>
#include <goffice/utils/go-glib-extras.h>
#include <goffice/utils/go-font.h>
#undef DEBUG_BOUNDING_BOX
......@@ -66,7 +67,7 @@ calc_indent (PangoContext *context, const GnmStyle *mstyle, double zoom)
int n = gnm_style_get_indent (mstyle);
if (n) {
GnmFont *style_font = gnm_style_get_font (mstyle, context, zoom);
indent = PANGO_PIXELS (n * style_font->metrics->avg_digit_width);
indent = PANGO_PIXELS (n * style_font->go.metrics->avg_digit_width);
}
}
return MIN (indent, 65535);
......@@ -379,7 +380,7 @@ rendered_value_new (GnmCell *cell, GnmStyle const *mstyle,
col_width = col_width_pixels * PANGO_SCALE;
}
gnm_format_layout (layout, font->metrics, format, cell->value,
gnm_format_layout (layout, font->go.metrics, format, cell->value,
&fore, col_width, date_conv, TRUE);
}
......
......@@ -5,31 +5,17 @@
#include <pango/pango.h>
#include <libgnomeprint/gnome-font.h>
/* Needs to move to Goffice. */
struct _GnmFontMetrics {
int digit_widths[10];
int min_digit_width;
int max_digit_width;
int avg_digit_width;
int hyphen_width, minus_width, plus_width;
int E_width;
};
extern const GnmFontMetrics *gnm_font_metrics_unit;
GnmFontMetrics *gnm_font_metrics_new (PangoContext *context,
PangoFontDescription *font_descr);
void gnm_font_metrics_free (GnmFontMetrics *metrics);
struct _GnmFont {
int ref_count;
char *font_name;
double size_pts;
double scale;
GnmFontMetrics *metrics;
struct {
GOFont const *font;
GOFontMetrics *metrics;
} go;
struct {
PangoFont *font;
PangoFontDescription *font_descr;
} pango;
unsigned int is_bold : 1;
......
......@@ -27,6 +27,7 @@
#include <gdk/gdkpango.h>
#include <gtk/gtkmain.h>
#include <string.h>
#include <goffice/utils/go-font.h>
#undef DEBUG_REF_COUNT
#undef DEBUG_FONTS
......@@ -74,60 +75,6 @@ get_substitute_font (gchar const *fontname)
return NULL;
}
GnmFontMetrics *
gnm_font_metrics_new (PangoContext *context, PangoFontDescription *font_descr)
{
PangoLayout *layout = pango_layout_new (context);
GnmFontMetrics *res = g_new0 (GnmFontMetrics, 1);
int i, sumw = 0;
pango_layout_set_font_description (layout, font_descr);
res->min_digit_width = INT_MAX;
for (i = 0; i <= 9; i++) {
char c = '0' + i;
int w;
pango_layout_set_text (layout, &c, 1);
pango_layout_get_size (layout, &w, NULL);
res->digit_widths[i] = w;
w = MAX (w, PANGO_SCALE); /* At least one pixel. */
res->min_digit_width = MIN (w, res->min_digit_width);
res->max_digit_width = MAX (w, res->max_digit_width);
sumw += w;
}
res->avg_digit_width = (sumw + 5) / 10;
pango_layout_set_text (layout, "-", -1);
pango_layout_get_size (layout, &res->hyphen_width, NULL);
pango_layout_set_text (layout, "\xe2\x88\x92", -1);
pango_layout_get_size (layout, &res->minus_width, NULL);
pango_layout_set_text (layout, "+", -1);
pango_layout_get_size (layout, &res->plus_width, NULL);
pango_layout_set_text (layout, "E", -1);
pango_layout_get_size (layout, &res->E_width, NULL);
g_object_unref (layout);
return res;
}
void
gnm_font_metrics_free (GnmFontMetrics *metrics)
{
g_free (metrics);
}
static GnmFontMetrics gnm_font_metrics_unit_var;
/* All widths == 1. */
const GnmFontMetrics *gnm_font_metrics_unit = &gnm_font_metrics_unit_var;
static GnmFont *
style_font_new_simple (PangoContext *context,
char const *font_name, double size_pts, double scale,
......@@ -168,7 +115,8 @@ style_font_new_simple (PangoContext *context,
/* One reference for the cache, one for the caller. */
font->ref_count = 2;
desc = pango_context_get_font_description (context);
desc = pango_font_description_copy (pango_context_get_font_description (context));
pango_font_description_set_family (desc, font_name);
pango_font_description_set_weight (desc,
bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
......@@ -187,16 +135,15 @@ style_font_new_simple (PangoContext *context,
}
if (font->pango.font == NULL) {
font->pango.font_descr = NULL;
pango_font_description_free (desc);
g_hash_table_insert (style_font_negative_hash,
font, font);
return NULL;
}
}
font->pango.font_descr = pango_font_description_copy (desc);
font->metrics = gnm_font_metrics_new (context,
font->pango.font_descr);
font->go.font = go_font_new_by_desc (desc);
font->go.metrics = go_font_metrics_new (context, font->go.font);
g_hash_table_insert (style_font_hash, font, font);
} else
font->ref_count++;
......@@ -289,13 +236,13 @@ style_font_unref (GnmFont *sf)
g_object_unref (G_OBJECT (sf->pango.font));
sf->pango.font = NULL;
}
if (sf->pango.font_descr != NULL) {
pango_font_description_free (sf->pango.font_descr);
sf->pango.font_descr = NULL;
if (sf->go.font) {
go_font_unref (sf->go.font);
sf->go.font = NULL;
}
if (sf->metrics) {
gnm_font_metrics_free (sf->metrics);
sf->metrics = NULL;
if (sf->go.metrics) {
go_font_metrics_free (sf->go.metrics);
sf->go.metrics = NULL;
}
g_hash_table_remove (style_font_hash, sf);
g_free (sf->font_name);
......@@ -345,11 +292,6 @@ gnm_pango_context_get (void)
if (screen != NULL) {
context = gdk_pango_context_get_for_screen (screen);
#ifndef GDK_DISABLE_DEPRECATED
/* this function is deprecated in newer gtk */
gdk_pango_context_set_colormap (context,
gdk_screen_get_default_colormap (screen));
#endif
} else {
PangoFontMap *fontmap = pango_ft2_font_map_new ();
pango_ft2_font_map_set_resolution (PANGO_FT2_FONT_MAP (fontmap), 96, 96);
......@@ -403,7 +345,7 @@ font_init (void)
}
gnumeric_default_font_width = pts_scale *
PANGO_PIXELS (gnumeric_default_font->metrics->avg_digit_width);
PANGO_PIXELS (gnumeric_default_font->go.metrics->avg_digit_width);
style_font_unref (gnumeric_default_font);
g_object_unref (G_OBJECT (context));
}
......@@ -418,18 +360,6 @@ font_shutdown (void)
void
style_init (void)
{
int i;
gnm_font_metrics_unit_var.min_digit_width = 1;
gnm_font_metrics_unit_var.max_digit_width = 1;
gnm_font_metrics_unit_var.avg_digit_width = 1;
gnm_font_metrics_unit_var.hyphen_width = 1;
gnm_font_metrics_unit_var.minus_width = 1;
gnm_font_metrics_unit_var.plus_width = 1;
gnm_font_metrics_unit_var.E_width = 1;
for (i = 0; i <= 9; i++)
gnm_font_metrics_unit_var.digit_widths[i] = 1;
style_font_hash = g_hash_table_new (style_font_hash_func,
style_font_equal);
style_font_negative_hash = g_hash_table_new (style_font_hash_func,
......
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