📄 pangofc-font.c
字号:
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){ PangoFcFont *fcfont = PANGO_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_slice_new0 (PangoFcMetricsInfo); 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); info->metrics = pango_fc_font_create_metrics_for_context (fcfont, context); g_object_unref (context); } return pango_font_metrics_ref (info->metrics);}static PangoFontMap *pango_fc_font_get_font_map (PangoFont *font){ PangoFcFont *fcfont = PANGO_FC_FONT (font); return fcfont->fontmap;}static gbooleanpango_fc_font_real_has_char (PangoFcFont *font, gunichar wc){ FcCharSet *charset; if (FcPatternGetCharSet (font->font_pattern, FC_CHARSET, 0, &charset) != FcResultMatch) return FALSE; return FcCharSetHasChar (charset, wc);}static guintpango_fc_font_real_get_glyph (PangoFcFont *font, gunichar wc){ FT_Face face; FT_UInt index; guint idx; GUnicharToGlyphCacheEntry *entry; PangoFcFontPrivate *priv = font->priv; if (G_UNLIKELY (priv->char_to_glyph_cache == NULL)) { priv->char_to_glyph_cache = g_new0 (GUnicharToGlyphCacheEntry, GLYPH_CACHE_NUM_ENTRIES); /* Make sure all cache entries are invalid initially */ priv->char_to_glyph_cache[0].ch = 1; /* char 1 cannot happen in bucket 0 */ } idx = wc & GLYPH_CACHE_MASK; entry = priv->char_to_glyph_cache + idx; if (entry->ch != wc) { face = PANGO_FC_FONT_LOCK_FACE (font); index = FcFreeTypeCharIndex (face, wc); if (index > (FT_UInt)face->num_glyphs) index = 0; entry->ch = wc; entry->glyph = index; PANGO_FC_FONT_UNLOCK_FACE (font); } return entry->glyph;}/** * pango_fc_font_lock_face: * @font: a #PangoFcFont. * * Gets the FreeType <type>FT_Face</type> associated with a font, * This face will be kept around until you call * pango_fc_font_unlock_face(). * * Return value: the FreeType <type>FT_Face</type> associated with @font. * * Since: 1.4 **/FT_Facepango_fc_font_lock_face (PangoFcFont *font){ g_return_val_if_fail (PANGO_IS_FC_FONT (font), NULL); return PANGO_FC_FONT_LOCK_FACE (font);}/** * pango_fc_font_unlock_face: * @font: a #PangoFcFont. * * Releases a font previously obtained with * pango_fc_font_lock_face(). * * Since: 1.4 **/voidpango_fc_font_unlock_face (PangoFcFont *font){ g_return_if_fail (PANGO_IS_FC_FONT (font)); PANGO_FC_FONT_UNLOCK_FACE (font);}/** * pango_fc_font_has_char: * @font: a #PangoFcFont * @wc: Unicode codepoint to look up * * Determines whether @font has a glyph for the codepoint @wc. * * Return value: %TRUE if @font has the requested codepoint. * * Since: 1.4 **/gbooleanpango_fc_font_has_char (PangoFcFont *font, gunichar wc){ PangoFcFontPrivate *priv = font->priv; FcCharSet *charset; g_return_val_if_fail (PANGO_IS_FC_FONT (font), FALSE); if (priv->decoder) { charset = pango_fc_decoder_get_charset (priv->decoder, font); return FcCharSetHasChar (charset, wc); } return PANGO_FC_FONT_GET_CLASS (font)->has_char (font, wc);}/** * pango_fc_font_get_glyph: * @font: a #PangoFcFont * @wc: Unicode character to look up * * Gets the glyph index for a given Unicode character * for @font. If you only want to determine * whether the font has the glyph, use pango_fc_font_has_char(). * * Return value: the glyph index, or 0, if the Unicode * character doesn't exist in the font. * * Since: 1.4 **/PangoGlyphpango_fc_font_get_glyph (PangoFcFont *font, gunichar wc){ PangoFcFontPrivate *priv = font->priv; /* Replace NBSP with a normal space; it should be invariant that * they shape the same other than breaking properties. */ if (wc == 0xA0) wc = 0x20; if (priv->decoder) return pango_fc_decoder_get_glyph (priv->decoder, font, wc); return PANGO_FC_FONT_GET_CLASS (font)->get_glyph (font, wc);}/** * pango_fc_font_get_unknown_glyph: * @font: a #PangoFcFont * @wc: the Unicode character for which a glyph is needed. * * Returns the index of a glyph suitable for drawing @wc as an * unknown character. * * Use PANGO_GET_UNKNOWN_GLYPH() instead. * * Return value: a glyph index into @font. * * Since: 1.4 **/PangoGlyphpango_fc_font_get_unknown_glyph (PangoFcFont *font, gunichar wc){ if (font && PANGO_FC_FONT_GET_CLASS (font)->get_unknown_glyph) return PANGO_FC_FONT_GET_CLASS (font)->get_unknown_glyph (font, wc); return PANGO_GET_UNKNOWN_GLYPH (wc);}void_pango_fc_font_shutdown (PangoFcFont *font){ g_return_if_fail (PANGO_IS_FC_FONT (font)); if (PANGO_FC_FONT_GET_CLASS (font)->shutdown) PANGO_FC_FONT_GET_CLASS (font)->shutdown (font);}/** * pango_fc_font_kern_glyphs * @font: a #PangoFcFont * @glyphs: a #PangoGlyphString * * Adjust each adjacent pair of glyphs in @glyphs according to * kerning information in @font. * * Since: 1.4 **/voidpango_fc_font_kern_glyphs (PangoFcFont *font, PangoGlyphString *glyphs){ FT_Face face; FT_Error error; FT_Vector kerning; int i; g_return_if_fail (PANGO_IS_FC_FONT (font)); g_return_if_fail (glyphs != NULL); face = PANGO_FC_FONT_LOCK_FACE (font); if (!face) return; if (!FT_HAS_KERNING (face)) { PANGO_FC_FONT_UNLOCK_FACE (font); return; } for (i = 1; i < glyphs->num_glyphs; ++i) { error = FT_Get_Kerning (face, glyphs->glyphs[i-1].glyph, glyphs->glyphs[i].glyph, ft_kerning_default, &kerning); if (error == FT_Err_Ok) glyphs->glyphs[i-1].geometry.width += PANGO_UNITS_26_6 (kerning.x); } PANGO_FC_FONT_UNLOCK_FACE (font);}/** * _pango_fc_font_get_decoder * @font: a #PangoFcFont * * This will return any custom decoder set on this font. * * Return value: The custom decoder * * Since: 1.6 **/PangoFcDecoder *_pango_fc_font_get_decoder (PangoFcFont *font){ PangoFcFontPrivate *priv = font->priv; return priv->decoder;}/** * _pango_fc_font_set_decoder * @font: a #PangoFcFont * @decoder: a #PangoFcDecoder to set for this font * * This sets a custom decoder for this font. Any previous decoder * will be released before this one is set. * * Since: 1.6 **/void_pango_fc_font_set_decoder (PangoFcFont *font, PangoFcDecoder *decoder){ PangoFcFontPrivate *priv = font->priv; if (priv->decoder) g_object_unref (priv->decoder); priv->decoder = decoder; if (priv->decoder) g_object_ref (priv->decoder);}gpointer_pango_fc_font_get_context_key (PangoFcFont *fcfont){ PangoFcFontPrivate *priv = fcfont->priv; return priv->context_key;}void_pango_fc_font_set_context_key (PangoFcFont *fcfont, gpointer context_key){ PangoFcFontPrivate *priv = fcfont->priv; priv->context_key = context_key;}static FT_Glyph_Metrics *get_per_char (FT_Face face, FT_Int32 load_flags, PangoGlyph glyph){ FT_Error error; FT_Glyph_Metrics *result; error = FT_Load_Glyph (face, glyph, load_flags); if (error == FT_Err_Ok) result = &face->glyph->metrics; else result = NULL; return result;}/** * pango_fc_font_get_raw_extents: * @fcfont: a #PangoFcFont * @load_flags: flags to pass to FT_Load_Glyph() * @glyph: the glyph index to load * @ink_rect: location to store ink extents of the glyph, or %NULL * @logical_rect: location to store logical extents of the glyph or %NULL * * Gets the extents of a single glyph from a font. The extents are in * user space; that is, they are not transformed by any matrix in effect * for the font. * * Long term, this functionality probably belongs in the default * implementation of the get_glyph_extents() virtual function. * The other possibility would be to to make it public in something * like it's current form, and also expose glyph information * caching functionality similar to pango_ft2_font_set_glyph_info(). * * Since: 1.6 **/voidpango_fc_font_get_raw_extents (PangoFcFont *fcfont, FT_Int32 load_flags, PangoGlyph glyph, PangoRectangle *ink_rect, PangoRectangle *logical_rect){ FT_Glyph_Metrics *gm; FT_Face face; g_return_if_fail (PANGO_IS_FC_FONT (fcfont)); face = PANGO_FC_FONT_LOCK_FACE (fcfont); if (glyph == PANGO_GLYPH_EMPTY) gm = NULL; else gm = get_per_char (face, load_flags, glyph); if (gm) { if (ink_rect) { ink_rect->x = PANGO_UNITS_26_6 (gm->horiBearingX); ink_rect->width = PANGO_UNITS_26_6 (gm->width); ink_rect->y = -PANGO_UNITS_26_6 (gm->horiBearingY); ink_rect->height = PANGO_UNITS_26_6 (gm->height); } if (logical_rect) { logical_rect->x = 0; logical_rect->width = PANGO_UNITS_26_6 (gm->horiAdvance); if (fcfont->is_hinted || (face->face_flags & FT_FACE_FLAG_SCALABLE) == 0) { logical_rect->y = - PANGO_UNITS_26_6 (face->size->metrics.ascender); logical_rect->height = PANGO_UNITS_26_6 (face->size->metrics.ascender - face->size->metrics.descender); } else { FT_Fixed ascender, descender; ascender = FT_MulFix (face->ascender, face->size->metrics.y_scale); descender = FT_MulFix (face->descender, face->size->metrics.y_scale); logical_rect->y = - PANGO_UNITS_26_6 (ascender); logical_rect->height = PANGO_UNITS_26_6 (ascender - descender); } } } else { if (ink_rect) { ink_rect->x = 0; ink_rect->width = 0; ink_rect->y = 0; ink_rect->height = 0; } if (logical_rect) { logical_rect->x = 0; logical_rect->width = 0; logical_rect->y = 0; logical_rect->height = 0; } } PANGO_FC_FONT_UNLOCK_FACE (fcfont);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -