📄 pangoft2.c
字号:
PangoFT2GlyphInfo *info; info = g_hash_table_lookup (ft2font->glyph_info, GUINT_TO_POINTER (glyph)); if ((info == NULL) && create) { info = g_slice_new0 (PangoFT2GlyphInfo); pango_fc_font_get_raw_extents (fcfont, ft2font->load_flags, glyph, &info->ink_rect, &info->logical_rect); g_hash_table_insert (ft2font->glyph_info, GUINT_TO_POINTER(glyph), info); } return info;}static voidpango_ft2_font_get_glyph_extents (PangoFont *font, PangoGlyph glyph, PangoRectangle *ink_rect, PangoRectangle *logical_rect){ PangoFT2GlyphInfo *info; if (glyph == PANGO_GLYPH_EMPTY) { if (ink_rect) ink_rect->x = ink_rect->y = ink_rect->height = ink_rect->width = 0; if (logical_rect) logical_rect->x = logical_rect->y = logical_rect->height = logical_rect->width = 0; return; } if (glyph & PANGO_GLYPH_UNKNOWN_FLAG) { glyph = pango_ft2_get_unknown_glyph (font); if (glyph == PANGO_GLYPH_EMPTY) { /* No unknown glyph found for the font, draw a box */ PangoFontMetrics *metrics = pango_font_get_metrics (font, NULL); if (metrics) { if (ink_rect) { ink_rect->x = PANGO_SCALE; ink_rect->width = metrics->approximate_char_width - 2 * PANGO_SCALE; ink_rect->y = - (metrics->ascent - PANGO_SCALE); ink_rect->height = metrics->ascent + metrics->descent - 2 * PANGO_SCALE; } if (logical_rect) { logical_rect->x = 0; logical_rect->width = metrics->approximate_char_width; logical_rect->y = -metrics->ascent; logical_rect->height = metrics->ascent + metrics->descent; } pango_font_metrics_unref (metrics); } else { if (ink_rect) ink_rect->x = ink_rect->y = ink_rect->height = ink_rect->width = 0; if (logical_rect) logical_rect->x = logical_rect->y = logical_rect->height = logical_rect->width = 0; } return; } } info = pango_ft2_font_get_glyph_info (font, glyph, TRUE); if (ink_rect) *ink_rect = info->ink_rect; if (logical_rect) *logical_rect = info->logical_rect;}/** * pango_ft2_font_get_kerning: * @font: a #PangoFont * @left: the left #PangoGlyph * @right: the right #PangoGlyph * * Retrieves kerning information for a combination of two glyphs. * * Use pango_fc_font_kern_glyphs() instead. * * Return value: The amount of kerning (in Pango units) to apply for * the given combination of glyphs. **/intpango_ft2_font_get_kerning (PangoFont *font, PangoGlyph left, PangoGlyph right){ PangoFcFont *fc_font = PANGO_FC_FONT (font); FT_Face face; FT_Error error; FT_Vector kerning; face = pango_fc_font_lock_face (fc_font); if (!face) return 0; if (!FT_HAS_KERNING (face)) { pango_fc_font_unlock_face (fc_font); return 0; } error = FT_Get_Kerning (face, left, right, ft_kerning_default, &kerning); if (error != FT_Err_Ok) { pango_fc_font_unlock_face (fc_font); return 0; } pango_fc_font_unlock_face (fc_font); return PANGO_UNITS_26_6 (kerning.x);}static FT_Facepango_ft2_font_real_lock_face (PangoFcFont *font){ return pango_ft2_font_get_face ((PangoFont *)font);}static voidpango_ft2_font_real_unlock_face (PangoFcFont *font){}static gbooleanpango_ft2_free_glyph_info_callback (gpointer key, gpointer value, gpointer data){ PangoFT2Font *font = PANGO_FT2_FONT (data); PangoFT2GlyphInfo *info = value; if (font->glyph_cache_destroy && info->cached_glyph) (*font->glyph_cache_destroy) (info->cached_glyph); g_slice_free (PangoFT2GlyphInfo, info); return TRUE;}static voidpango_ft2_font_finalize (GObject *object){ PangoFT2Font *ft2font = (PangoFT2Font *)object; if (ft2font->face) { FT_Done_Face (ft2font->face); ft2font->face = NULL; } g_hash_table_foreach_remove (ft2font->glyph_info, pango_ft2_free_glyph_info_callback, object); g_hash_table_destroy (ft2font->glyph_info); G_OBJECT_CLASS (pango_ft2_font_parent_class)->finalize (object);}/** * pango_ft2_font_get_coverage: * @font: a #PangoFT2Font. * @language: a language tag. * @returns: a #PangoCoverage. * * Gets the #PangoCoverage for a #PangoFT2Font. Use pango_font_get_coverage() instead. **/PangoCoverage *pango_ft2_font_get_coverage (PangoFont *font, PangoLanguage *language){ return pango_font_get_coverage (font, language);}/* Utility functions *//** * pango_ft2_get_unknown_glyph: * @font: a #PangoFont * * Return the index of a glyph suitable for drawing unknown characters with * @font, or %PANGO_GLYPH_EMPTY if no suitable glyph found. * * If you want to draw an unknown-box for a character that is not covered * by the font, * use PANGO_GET_UNKNOWN_GLYPH() instead. * * Return value: a glyph index into @font, or %PANGO_GLYPH_EMPTY **/PangoGlyphpango_ft2_get_unknown_glyph (PangoFont *font){ FT_Face face = pango_ft2_font_get_face (font); if (face && FT_IS_SFNT (face)) /* TrueType fonts have an 'unknown glyph' box on glyph index 0 */ return 0; else return PANGO_GLYPH_EMPTY;}typedef struct{ FT_Error code; const char msg[40];} ft_error_description;static intft_error_compare (const void *pkey, const void *pbase){ return ((ft_error_description *) pkey)->code - ((ft_error_description *) pbase)->code;}G_CONST_RETURN char *_pango_ft2_ft_strerror (FT_Error error){#undef __FTERRORS_H__#define FT_ERRORDEF( e, v, s ) { e, s },#define FT_ERROR_START_LIST {#define FT_ERROR_END_LIST }; static const ft_error_description ft_errors[] =#include FT_ERRORS_H#undef FT_ERRORDEF#undef FT_ERROR_START_LIST#undef FT_ERROR_END_LIST ft_error_description *found = bsearch (&error, ft_errors, G_N_ELEMENTS (ft_errors), sizeof (ft_errors[0]), ft_error_compare); if (found != NULL) return found->msg; else { static char *default_msg = NULL; if (!default_msg) default_msg = g_malloc (60); g_sprintf (default_msg, "Unknown FreeType2 error %#x", error); return default_msg; }}void *_pango_ft2_font_get_cache_glyph_data (PangoFont *font, int glyph_index){ PangoFT2GlyphInfo *info; if (!PANGO_FT2_IS_FONT (font)) return NULL; info = pango_ft2_font_get_glyph_info (font, glyph_index, FALSE); if (info == NULL) return NULL; return info->cached_glyph;}void_pango_ft2_font_set_cache_glyph_data (PangoFont *font, int glyph_index, void *cached_glyph){ PangoFT2GlyphInfo *info; if (!PANGO_FT2_IS_FONT (font)) return; info = pango_ft2_font_get_glyph_info (font, glyph_index, TRUE); info->cached_glyph = cached_glyph; /* TODO: Implement limiting of the number of cached glyphs */}void_pango_ft2_font_set_glyph_cache_destroy (PangoFont *font, GDestroyNotify destroy_notify){ if (!PANGO_FT2_IS_FONT (font)) return; PANGO_FT2_FONT (font)->glyph_cache_destroy = destroy_notify;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -