diff options
Diffstat (limited to 'pango')
-rw-r--r-- | pango/pangocairo-fc.h | 7 | ||||
-rw-r--r-- | pango/pangocairo-fcfont.c | 19 | ||||
-rw-r--r-- | pango/pangocairo-fcfontmap.c | 10 | ||||
-rw-r--r-- | pango/pangofc-fontmap.c | 82 | ||||
-rw-r--r-- | pango/pangofc-fontmap.h | 1 |
5 files changed, 80 insertions, 39 deletions
diff --git a/pango/pangocairo-fc.h b/pango/pangocairo-fc.h index 6335058d..8e0d9a5d 100644 --- a/pango/pangocairo-fc.h +++ b/pango/pangocairo-fc.h @@ -45,9 +45,10 @@ struct _PangoCairoFcFontMap GType pango_cairo_fc_font_map_get_type (void); -PangoFcFont *_pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap, - PangoContext *context, - FcPattern *pattern); +PangoFcFont *_pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap, + PangoContext *context, + const PangoFontDescription *desc, + FcPattern *pattern); gboolean _pango_cairo_fc_get_render_key (PangoCairoFcFontMap *cffontmap, PangoContext *context, diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c index ea335472..52da3a4a 100644 --- a/pango/pangocairo-fcfont.c +++ b/pango/pangocairo-fcfont.c @@ -321,15 +321,15 @@ _pango_cairo_fc_get_render_key (PangoCairoFcFontMap *cffontmap, } PangoFcFont * -_pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap, - PangoContext *context, - FcPattern *pattern) +_pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap, + PangoContext *context, + const PangoFontDescription *desc, + FcPattern *pattern) { PangoCairoFcFont *cffont; - FcResult result; const PangoMatrix *pango_ctm; FcMatrix *fc_matrix; - double pixel_size; + double size; g_return_val_if_fail (PANGO_IS_CAIRO_FC_FONT_MAP (cffontmap), NULL); g_return_val_if_fail (pattern != NULL, NULL); @@ -358,10 +358,13 @@ _pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap, cairo_matrix_destroy (tmp_matrix); } - result = FcPatternGetDouble (pattern, FC_PIXEL_SIZE, 0, &pixel_size); - g_assert (result == FcResultMatch); + if (pango_font_description_get_size_is_absolute (desc)) + size = pango_font_description_get_size (desc); + else + size = cffontmap->dpi * pango_font_description_get_size (desc) / 72.; - cairo_matrix_scale (cffont->font_matrix, pixel_size, pixel_size); + cairo_matrix_scale (cffont->font_matrix, + size / PANGO_SCALE, size / PANGO_SCALE); cffont->total_matrix = cairo_matrix_create (); diff --git a/pango/pangocairo-fcfontmap.c b/pango/pangocairo-fcfontmap.c index e05fd279..a1a107e9 100644 --- a/pango/pangocairo-fcfontmap.c +++ b/pango/pangocairo-fcfontmap.c @@ -112,11 +112,13 @@ pango_cairo_fc_font_map_get_render_key (PangoFcFontMap *fcfontmap, } static PangoFcFont * -pango_cairo_fc_font_map_create_font (PangoFcFontMap *fcfontmap, - PangoContext *context, - FcPattern *pattern) +pango_cairo_fc_font_map_create_font (PangoFcFontMap *fcfontmap, + PangoContext *context, + const PangoFontDescription *desc, + FcPattern *pattern) { - return _pango_cairo_fc_font_new (PANGO_CAIRO_FC_FONT_MAP (fcfontmap), context, pattern); + return _pango_cairo_fc_font_new (PANGO_CAIRO_FC_FONT_MAP (fcfontmap), + context, desc, pattern); } static void diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index efbf284c..c4068db3 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -63,6 +63,8 @@ struct _PangoFcFontMapPrivate PangoFcFamily **families; int n_families; /* -1 == uninitialized */ + double dpi; + /* Decoders */ GSList *findfuncs; @@ -167,6 +169,7 @@ pango_fc_font_map_init (PangoFcFontMap *fcfontmap) (GDestroyNotify)g_free, (GDestroyNotify)pango_coverage_unref); priv->fontset_cache = g_queue_new (); + priv->dpi = -1; } static void @@ -641,7 +644,9 @@ pango_fc_convert_width_to_fc (PangoStretch pango_stretch) #endif static FcPattern * -pango_fc_make_pattern (const PangoFontDescription *description) +pango_fc_make_pattern (const PangoFontDescription *description, + PangoLanguage *language, + double pixel_size) { FcPattern *pattern; int slant; @@ -669,7 +674,7 @@ pango_fc_make_pattern (const PangoFontDescription *description) #ifdef FC_WIDTH FC_WIDTH, FcTypeInteger, width, #endif - (size_is_absolute ? FC_PIXEL_SIZE : FC_SIZE), FcTypeDouble, size, + FC_PIXEL_SIZE, FcTypeDouble, pixel_size, NULL); families = g_strsplit (pango_font_description_get_family (description), ",", -1); @@ -679,14 +684,18 @@ pango_fc_make_pattern (const PangoFontDescription *description) g_strfreev (families); + if (language) + FcPatternAddString (pattern, FC_LANG, (FcChar8 *) pango_language_to_string (language)); + return pattern; } static PangoFont * -pango_fc_font_map_new_font (PangoFontMap *fontmap, - PangoContext *context, - FcPattern *match, - gboolean cache) +pango_fc_font_map_new_font (PangoFontMap *fontmap, + PangoContext *context, + const PangoFontDescription *description, + FcPattern *match, + gboolean cache) { PangoFcFontMapClass *class; PangoFcFontMap *fcfontmap = (PangoFcFontMap *)fontmap; @@ -719,6 +728,7 @@ pango_fc_font_map_new_font (PangoFontMap *fontmap, { fcfont = PANGO_FC_FONT_MAP_GET_CLASS (fontmap)->create_font (fcfontmap, context, + description, match); } else @@ -814,6 +824,33 @@ pango_fc_default_substitute (PangoFcFontMap *fontmap, PANGO_FC_FONT_MAP_GET_CLASS (fontmap)->default_substitute (fontmap, pattern); } +static gdouble +pango_fc_font_map_get_dpi (PangoFcFontMap *fcfontmap) +{ + if (fcfontmap->priv->dpi < 0) + { + FcResult result = FcResultNoMatch; + FcPattern *tmp = FcPatternBuild (NULL, + FC_FAMILY, FcTypeString, "Sans", + FC_SIZE, FcTypeDouble, 10., + NULL); + if (tmp) + { + pango_fc_default_substitute (fcfontmap, tmp); + result = FcPatternGetDouble (tmp, FC_DPI, 0, &fcfontmap->priv->dpi); + FcPatternDestroy (tmp); + } + + if (result != FcResultMatch) + { + g_warning ("Error getting DPI from fontconfig, using 72.0"); + fcfontmap->priv->dpi = 72.0; + } + } + + return fcfontmap->priv->dpi; +} + static double transformed_length (const PangoMatrix *matrix, double dx, @@ -837,10 +874,15 @@ pango_fc_font_map_get_render_key (PangoFcFontMap *fcfontmap, return PANGO_FC_FONT_MAP_GET_CLASS (fcfontmap)->get_render_key (fcfontmap, context, desc, x_size, y_size, flags); else { - int size = pango_font_description_get_size (desc); + double size; const PangoMatrix *matrix; gboolean retval = TRUE; - + + if (pango_font_description_get_size_is_absolute (desc)) + size = pango_font_description_get_size (desc); + else + size = pango_fc_font_map_get_dpi (fcfontmap) * pango_font_description_get_size (desc) / 72.; + if (context) matrix = pango_context_get_matrix (context); else @@ -903,9 +945,7 @@ pango_fc_font_map_get_patterns (PangoFontMap *fontmap, if (patterns == NULL) { - pattern = pango_fc_make_pattern (desc); - if (language) - FcPatternAddString (pattern, FC_LANG, (FcChar8 *) pango_language_to_string (language)); + pattern = pango_fc_make_pattern (desc, language, key.y_size / 1024.); pango_fc_default_substitute (fcfontmap, pattern); @@ -976,7 +1016,7 @@ pango_fc_font_map_load_font (PangoFontMap *fontmap, if (patterns->n_patterns > 0) { - return pango_fc_font_map_new_font (fontmap, context, + return pango_fc_font_map_new_font (fontmap, context, description, patterns->patterns[0], FALSE); } @@ -1060,7 +1100,8 @@ pango_fc_font_map_load_fontset (PangoFontMap *fontmap, { PangoFont *font; - font = pango_fc_font_map_new_font (fontmap, context, patterns->patterns[i], cache); + font = pango_fc_font_map_new_font (fontmap, context, desc, + patterns->patterns[i], cache); if (font) pango_fontset_simple_append (simple, font); } @@ -1118,6 +1159,8 @@ pango_fc_font_map_clear_fontset_cache (PangoFcFontMap *fcfontmap) void pango_fc_font_map_cache_clear (PangoFcFontMap *fcfontmap) { + fcfontmap->priv->dpi = -1; + /* Clear the fontset cache first, since any entries * in the fontset_cache must also be in the pattern cache. */ @@ -1566,17 +1609,8 @@ pango_fc_face_list_sizes (PangoFontFace *face, if (FcPatternGetDouble (fontset->fonts[i], FC_PIXEL_SIZE, 0, &size) == FcResultMatch) { if (dpi < 0) - { - FcPattern *tmp = FcPatternDuplicate (fontset->fonts[i]); - pango_fc_default_substitute (fcface->family->fontmap, tmp); - if (FcPatternGetDouble (tmp, FC_DPI, 0, &dpi) != FcResultMatch) - { - g_warning ("Error getting DPI from fontconfig, using 72.0"); - dpi = 72.0; - } - FcPatternDestroy (tmp); - } - + dpi = pango_fc_font_map_get_dpi (fcface->family->fontmap); + size_i = (int) (PANGO_SCALE * size * 72.0 / dpi); g_array_append_val (size_array, size_i); } diff --git a/pango/pangofc-fontmap.h b/pango/pangofc-fontmap.h index 3cc87512..4e98bc78 100644 --- a/pango/pangofc-fontmap.h +++ b/pango/pangofc-fontmap.h @@ -103,6 +103,7 @@ struct _PangoFcFontMapClass guint *flags); PangoFcFont *(*create_font) (PangoFcFontMap *fontmap, PangoContext *context, + const PangoFontDescription *desc, FcPattern *pattern); /*< private >*/ |