static VALUE rg_load_fontset(VALUE self, VALUE context, VALUE desc, VALUE lang) { return GOBJ2RVAL(pango_font_map_load_fontset(_SELF(self), RVAL2PANGOCONTEXT(context), RVAL2PANGOFONTDESCRIPTION(desc), RVAL2PANGOLANGUAGE(lang))); }
void glyph_cache_set_font(TGlyphCache *cache, PangoFontDescription *font_desc) { PangoFontMap *font_map; PangoFontMetrics *metrics; if (cache->hash) { g_hash_table_destroy(cache->hash); g_object_unref(cache->font_set); } cache->hash = g_hash_table_new_full(NULL, NULL, NULL, glyph_destroy_gfi); font_map = pango_xft_get_font_map( GDK_DISPLAY_XDISPLAY(cache->display), GDK_SCREEN_XNUMBER(cache->screen) ); g_object_ref (font_map); cache->font_set = pango_font_map_load_fontset( font_map, cache->context, font_desc, cache->lang ); g_object_unref(font_map); font_map = NULL; metrics = pango_fontset_get_metrics(cache->font_set); pango_font_metrics_ref(metrics); cache->ascent = pango_font_metrics_get_ascent(metrics); cache->descent = pango_font_metrics_get_descent(metrics); cache->width = pango_font_metrics_get_approximate_digit_width(metrics); cache->height = cache->ascent + cache->descent; if (cache->width <= 0) { fprintf (stderr, "Warning: cache->width = %d\n", cache->width); cache->width = cache->height / 2; } pango_font_metrics_unref(metrics); }
FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const UChar *characters, int length) : m_context(0) , m_font(0) , m_size(fontDescription.computedSize()) , m_syntheticBold(false) , m_syntheticOblique(false) , m_scaledFont(0) { FontPlatformData::init(); const UChar character = characters[0]; char const *family; switch (fontDescription.genericFamily()) { case FontDescription::SerifFamily: family = "serif"; break; case FontDescription::SansSerifFamily: family = "sans"; break; case FontDescription::MonospaceFamily: family = "monospace"; break; case FontDescription::NoFamily: case FontDescription::StandardFamily: default: family = "sans"; break; } m_context = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(m_fontMap)); PangoFontDescription* description = pango_font_description_new(); pango_font_description_set_absolute_size(description, fontDescription.computedSize() * PANGO_SCALE); if (fontDescription.weight() >= FontWeight600) pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD); if (fontDescription.italic()) pango_font_description_set_style(description, PANGO_STYLE_ITALIC); pango_font_description_set_family(description, family); pango_context_set_font_description(m_context, description); PangoFontset *fset = pango_font_map_load_fontset (m_fontMap, m_context, description, NULL); // Get the font from the fontset which contains the best glyph for this character m_font = pango_fontset_get_font(fset, (guint)character); #if PANGO_VERSION_CHECK(1,18,0) if (m_font) m_scaledFont = cairo_scaled_font_reference(pango_cairo_font_get_scaled_font(PANGO_CAIRO_FONT(m_font))); #else // This compatibility code for older versions of Pango is not well-tested. if (m_font) { PangoFcFont* fcfont = PANGO_FC_FONT(m_font); cairo_font_face_t* face = cairo_ft_font_face_create_for_pattern(fcfont->font_pattern); double size; if (FcPatternGetDouble(fcfont->font_pattern, FC_PIXEL_SIZE, 0, &size) != FcResultMatch) size = 12.0; cairo_matrix_t fontMatrix; cairo_matrix_init_scale(&fontMatrix, size, size); cairo_font_options_t* fontOptions; if (pango_cairo_context_get_font_options(m_context)) fontOptions = cairo_font_options_copy(pango_cairo_context_get_font_options(m_context)); else fontOptions = cairo_font_options_create(); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); m_scaledFont = cairo_scaled_font_create(face, &fontMatrix, &ctm, fontOptions); cairo_font_options_destroy(fontOptions); cairo_font_face_destroy(face); } #endif pango_font_description_free(description); }