summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2005-08-15 19:41:00 +0000
committerOwen Taylor <otaylor@src.gnome.org>2005-08-15 19:41:00 +0000
commitd95e7b978abe87c7f4b71a0689f0e0670a8ccb74 (patch)
tree3b36337192c3dc31d99b11c6c2c09c8b3c200f8e /pango
parentbb7216ad5a09bbdc5fd1d8f6b87d16ea0a52346c (diff)
downloadpango-d95e7b978abe87c7f4b71a0689f0e0670a8ccb74.tar.gz
Cut out the meat of pango_fc_font_get_metrics_for_context() and export it
2005-08-15 Owen Taylor <otaylor@redhat.com> * pango/pangofc-font.c (pango_fc_font_create_metrics_for_context) pango/pangofc-private.h pango/pangocairo-fcfcont.c: Cut out the meat of pango_fc_font_get_metrics_for_context() and export it (privately), so that PangoCairoFcFont can create a variant that sets the font options on the context it creates. (#311522)
Diffstat (limited to 'pango')
-rw-r--r--pango/pangocairo-fcfont.c53
-rw-r--r--pango/pangofc-font.c77
-rw-r--r--pango/pangofc-private.h11
3 files changed, 108 insertions, 33 deletions
diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c
index c3e99c13..eb6825ef 100644
--- a/pango/pangocairo-fcfont.c
+++ b/pango/pangocairo-fcfont.c
@@ -30,6 +30,7 @@
#include "pangocairo-private.h"
#include "pangocairo-fc.h"
#include "pangofc-private.h"
+#include "pango-utils.h"
#define PANGO_TYPE_CAIRO_FC_FONT (pango_cairo_fc_font_get_type ())
#define PANGO_CAIRO_FC_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CAIRO_FC_FONT, PangoCairoFcFont))
@@ -242,6 +243,57 @@ pango_cairo_fc_font_get_glyph_extents (PangoFont *font,
*logical_rect = info->logical_rect;
}
+/* This function is cut-and-pasted from pangocairo-fcfont.c - it might be
+ * better to add a virtual fcfont->create_context (font).
+ */
+static PangoFontMetrics *
+pango_cairo_fc_font_get_metrics (PangoFont *font,
+ PangoLanguage *language)
+{
+ PangoFcFont *fcfont = PANGO_FC_FONT (font);
+ PangoCairoFcFont *cffont = PANGO_CAIRO_FC_FONT (font);
+ PangoFcMetricsInfo *info = NULL; /* Quiet gcc */
+ GSList *tmp_list;
+
+ const char *sample_str = pango_language_get_sample_string (language);
+
+ tmp_list = fcfont->metrics_by_lang;
+ while (tmp_list)
+ {
+ info = tmp_list->data;
+
+ if (info->sample_str == sample_str) /* We _don't_ need strcmp */
+ break;
+
+ tmp_list = tmp_list->next;
+ }
+
+ if (!tmp_list)
+ {
+ PangoContext *context;
+
+ if (!fcfont->fontmap)
+ return pango_font_metrics_new ();
+
+ info = g_new0 (PangoFcMetricsInfo, 1);
+
+ fcfont->metrics_by_lang = g_slist_prepend (fcfont->metrics_by_lang,
+ info);
+
+ info->sample_str = sample_str;
+
+ context = pango_fc_font_map_create_context (PANGO_FC_FONT_MAP (fcfont->fontmap));
+ pango_context_set_language (context, language);
+ pango_cairo_context_set_font_options (context, cffont->options);
+
+ info->metrics = pango_fc_font_create_metrics_for_context (fcfont, context);
+
+ g_object_unref (context);
+ }
+
+ return pango_font_metrics_ref (info->metrics);
+}
+
static FT_Face
pango_cairo_fc_font_lock_face (PangoFcFont *font)
{
@@ -293,6 +345,7 @@ pango_cairo_fc_font_class_init (PangoCairoFcFontClass *class)
object_class->finalize = pango_cairo_fc_font_finalize;
font_class->get_glyph_extents = pango_cairo_fc_font_get_glyph_extents;
+ font_class->get_metrics = pango_cairo_fc_font_get_metrics;
fc_font_class->lock_face = pango_cairo_fc_font_lock_face;
fc_font_class->unlock_face = pango_cairo_fc_font_unlock_face;
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 84a55eb4..21ddf8d0 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -30,14 +30,6 @@
#include FT_TRUETYPE_TABLES_H
-typedef struct _PangoFcMetricsInfo PangoFcMetricsInfo;
-
-struct _PangoFcMetricsInfo
-{
- const char *sample_str;
- PangoFontMetrics *metrics;
-};
-
enum {
PROP_0,
PROP_PATTERN
@@ -402,6 +394,40 @@ max_glyph_width (PangoLayout *layout)
return max_width;
}
+PangoFontMetrics *
+pango_fc_font_create_metrics_for_context (PangoFcFont *fcfont,
+ PangoContext *context)
+{
+ PangoFontMetrics *metrics;
+ PangoLayout *layout;
+ PangoRectangle extents;
+ PangoLanguage *language = pango_context_get_language (context);
+ const char *sample_str = pango_language_get_sample_string (language);
+
+ metrics = pango_font_metrics_new ();
+
+ get_face_metrics (fcfont, metrics);
+
+ layout = pango_layout_new (context);
+ pango_layout_set_font_description (layout, fcfont->description);
+
+ pango_layout_set_text (layout, sample_str, -1);
+ pango_layout_get_extents (layout, NULL, &extents);
+
+ metrics->approximate_char_width =
+ extents.width / g_utf8_strlen (sample_str, -1);
+
+ pango_layout_set_text (layout, "0123456789", -1);
+ metrics->approximate_digit_width = max_glyph_width (layout);
+
+ g_object_unref (layout);
+
+ return metrics;
+}
+
+/* This function is cut-and-pasted into pangocairo-fcfont.c - it might be
+ * better to add a virtual fcfont->create_context (font).
+ */
static PangoFontMetrics *
pango_fc_font_get_metrics (PangoFont *font,
PangoLanguage *language)
@@ -425,39 +451,24 @@ pango_fc_font_get_metrics (PangoFont *font,
if (!tmp_list)
{
- PangoLayout *layout;
- PangoRectangle extents;
PangoContext *context;
+ if (!fcfont->fontmap)
+ return pango_font_metrics_new ();
+
info = g_new0 (PangoFcMetricsInfo, 1);
+
fcfont->metrics_by_lang = g_slist_prepend (fcfont->metrics_by_lang,
info);
+
+ info->sample_str = sample_str;
- if (fcfont->fontmap)
- {
- info->sample_str = sample_str;
- info->metrics = pango_font_metrics_new ();
-
- get_face_metrics (fcfont, info->metrics);
-
- context = pango_fc_font_map_create_context (PANGO_FC_FONT_MAP (fcfont->fontmap));
- pango_context_set_language (context, language);
-
- layout = pango_layout_new (context);
- pango_layout_set_font_description (layout, fcfont->description);
-
- pango_layout_set_text (layout, sample_str, -1);
- pango_layout_get_extents (layout, NULL, &extents);
-
- info->metrics->approximate_char_width =
- extents.width / g_utf8_strlen (sample_str, -1);
+ context = pango_fc_font_map_create_context (PANGO_FC_FONT_MAP (fcfont->fontmap));
+ pango_context_set_language (context, language);
- pango_layout_set_text (layout, "0123456789", -1);
- info->metrics->approximate_digit_width = max_glyph_width (layout);
+ info->metrics = pango_fc_font_create_metrics_for_context (fcfont, context);
- g_object_unref (layout);
- g_object_unref (context);
- }
+ g_object_unref (context);
}
return pango_font_metrics_ref (info->metrics);
diff --git a/pango/pangofc-private.h b/pango/pangofc-private.h
index 751a87f6..c0be7648 100644
--- a/pango/pangofc-private.h
+++ b/pango/pangofc-private.h
@@ -27,6 +27,14 @@
G_BEGIN_DECLS
+typedef struct _PangoFcMetricsInfo PangoFcMetricsInfo;
+
+struct _PangoFcMetricsInfo
+{
+ const char *sample_str;
+ PangoFontMetrics *metrics;
+};
+
#define PANGO_SCALE_26_6 (PANGO_SCALE / (1<<6))
#define PANGO_PIXELS_26_6(d) \
(((d) >= 0) ? \
@@ -52,6 +60,9 @@ void pango_fc_font_get_raw_extents (PangoFcFont *font,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect);
+PangoFontMetrics *pango_fc_font_create_metrics_for_context (PangoFcFont *font,
+ PangoContext *context);
+
G_END_DECLS
#endif /* __PANGOFC_PRIVATE_H__ */