summaryrefslogtreecommitdiff
path: root/pango/pangocairo-fcfont.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2009-01-28 22:07:38 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2009-01-28 22:07:38 +0000
commit4aa395acd2740de461a359cba0068baf3f9a1b1d (patch)
treef0fed4655e64b81759a0980b35887eb1e66b3952 /pango/pangocairo-fcfont.c
parentceb03fea0dd21294e5b7eb13d8bc6b94b512037e (diff)
downloadpango-4aa395acd2740de461a359cba0068baf3f9a1b1d.tar.gz
Change PangoFc font loading API such that PangoContext is not passed down.
2009-01-09 Behdad Esfahbod <behdad@gnome.org> * docs/pango-sections.txt: * docs/tmpl/pangofc-fontmap.sgml: * docs/tmpl/text-attributes.sgml: * pango/pangocairo-fc.h: * pango/pangocairo-fcfont.c (get_font_size), (get_gravity_class), (get_gravity), (_pango_cairo_fc_font_new): * pango/pangocairo-fcfontmap.c (pango_cairo_fc_font_map_font_key_substitute), (pango_cairo_fc_font_map_create_font), (pango_cairo_fc_font_map_class_init): * pango/pangofc-font.c (_pango_fc_font_get_font_key), (_pango_fc_font_set_font_key): * pango/pangofc-fontmap.c (pango_fc_font_key_equal), (pango_fc_font_key_hash), (pango_fc_font_key_free), (pango_fc_font_key_copy), (get_context_matrix), (pango_fc_font_key_init), (pango_fc_font_key_get_pattern), (pango_fc_font_key_get_matrix), (pango_fc_font_key_get_context_key), (pango_fc_font_map_init), (pango_fc_font_map_class_init), (pango_fc_font_map_add), (_pango_fc_font_map_remove), (pango_fc_make_pattern), (pango_fc_font_map_new_font), (pango_fc_default_substitute), (pango_fc_font_map_get_patterns), (pango_fc_font_map_load_fontset): * pango/pangofc-fontmap.h: * pango/pangofc-private.h: Change PangoFc font loading API such that PangoContext is not passed down. We use a new opaque struct called PangoFcFontKey. This struct is in fact our font hash key. This avoids problems where previously we were using context members that were not necessarily considered by the pangofc layer when caching. This is in preparation for lazy loading of fonts in the pangofc fontmap. svn path=/trunk/; revision=2804
Diffstat (limited to 'pango/pangocairo-fcfont.c')
-rw-r--r--pango/pangocairo-fcfont.c78
1 files changed, 43 insertions, 35 deletions
diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c
index 129fa865..1c9a77aa 100644
--- a/pango/pangocairo-fcfont.c
+++ b/pango/pangocairo-fcfont.c
@@ -169,52 +169,59 @@ pango_cairo_fc_font_init (PangoCairoFcFont *cffont G_GNUC_UNUSED)
********************/
static double
-get_font_size (PangoCairoFcFontMap *cffontmap,
- PangoContext *context,
- const PangoFontDescription *desc,
- FcPattern *pattern)
+get_font_size (const FcPattern *pattern)
{
double size;
-
- /* The reason why we read FC_PIXEL_SIZE here rather than just
- * using the specified size is to support operations like clamping
- * a font to a minimal readable size in fonts.conf. This is pretty weird,
- * since it could mean that changing the Cairo CTM doesn't change the
- * font size, but it's just a more radical version of the non-linear
- * font scaling we already have due to hinting and due to bitmap
- * fonts being only available at a few sizes.
- *
- * If honoring FC_PIXEL_SIZE gets in the way of more useful features
- * it should be removed since it only matters in the unusual case
- * of people doing exotic stuff in fonts.conf.
- */
+ double dpi;
if (FcPatternGetDouble (pattern, FC_PIXEL_SIZE, 0, &size) == FcResultMatch)
- return size * PANGO_SCALE / pango_matrix_get_font_scale_factor (pango_context_get_matrix (context));
+ return size * PANGO_SCALE;
/* Just in case FC_PIXEL_SIZE got unset between pango_fc_make_pattern()
- * and here.
+ * and here. That would be very weird.
*/
- if (pango_font_description_get_size_is_absolute (desc))
- return pango_font_description_get_size (desc);
- else
- {
- double dpi = pango_cairo_context_get_resolution (context);
- if (dpi <= 0)
- dpi = cffontmap->dpi;
+ if (FcPatternGetDouble (pattern, FC_DPI, 0, &dpi) != FcResultMatch)
+ dpi = 72;
+
+ if (FcPatternGetDouble (pattern, FC_SIZE, 0, &size) == FcResultMatch)
+ return size * dpi / 72.;
+
+ /* Whatever */
+ return 18.;
+}
+
+static gpointer
+get_gravity_class (void)
+{
+ static GEnumClass *class = NULL;
- return dpi * pango_font_description_get_size (desc) / 72.;
+ if (G_UNLIKELY (!class))
+ class = g_type_class_ref (PANGO_TYPE_GRAVITY);
+
+ return class;
+}
+
+static PangoGravity
+get_gravity (const FcPattern *pattern)
+{
+ char *s;
+
+ if (FcPatternGetString (pattern, PANGO_FC_GRAVITY, 0, (FcChar8 **)(void *)&s) == FcResultMatch)
+ {
+ GEnumValue *value = g_enum_get_value_by_nick (get_gravity_class (), s);
+ return value->value;
}
+
+ return PANGO_GRAVITY_SOUTH;
}
PangoFcFont *
-_pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap,
- PangoContext *context,
- const PangoFontDescription *desc,
- FcPattern *pattern)
+_pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap,
+ PangoFcFontKey *key)
{
PangoCairoFcFont *cffont;
+ const FcPattern *pattern = pango_fc_font_key_get_pattern (key);
cairo_matrix_t font_matrix;
FcMatrix *fc_matrix;
double size;
@@ -226,7 +233,8 @@ _pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap,
"pattern", pattern,
NULL);
- size = get_font_size (cffontmap, context, desc, pattern);
+ size = get_font_size (pattern) /
+ pango_matrix_get_font_scale_factor (pango_fc_font_key_get_matrix (key));
if (FcPatternGetMatrix (pattern,
FC_MATRIX, 0, &fc_matrix) == FcResultMatch)
@@ -244,9 +252,9 @@ _pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap,
_pango_cairo_font_private_initialize (&cffont->cf_priv,
(PangoCairoFont *) cffont,
- pango_font_description_get_gravity (desc),
- _pango_cairo_context_get_merged_font_options (context),
- pango_context_get_matrix (context),
+ get_gravity (pattern),
+ pango_fc_font_key_get_context_key (key),
+ pango_fc_font_key_get_matrix (key),
&font_matrix);
((PangoFcFont *)(cffont))->is_hinted = _pango_cairo_font_private_is_metrics_hinted (&cffont->cf_priv);