📄 pango-ot-info.c
字号:
/* Pango * pango-ot-info.c: Store tables for OpenType * * Copyright (C) 2000 Red Hat Software * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */#include <config.h>#include "pango-ot-private.h"#include "pango-impl-utils.h"#include FT_MODULE_Hstatic void pango_ot_info_class_init (GObjectClass *object_class);static void pango_ot_info_finalize (GObject *object);static GObjectClass *parent_class;enum{ INFO_LOADED_GDEF = 1 << 0, INFO_LOADED_GSUB = 1 << 1, INFO_LOADED_GPOS = 1 << 2};GTypepango_ot_info_get_type (void){ static GType object_type = 0; if (!object_type) { const GTypeInfo object_info = { sizeof (PangoOTInfoClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc)pango_ot_info_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (PangoOTInfo), 0, /* n_preallocs */ NULL, /* init */ NULL, /* value_table */ }; object_type = g_type_register_static (G_TYPE_OBJECT, I_("PangoOTInfo"), &object_info, 0); } return object_type;}static voidpango_ot_info_class_init (GObjectClass *object_class){ parent_class = g_type_class_peek_parent (object_class); object_class->finalize = pango_ot_info_finalize;}static voidpango_ot_info_finalize (GObject *object){ PangoOTInfo *info = PANGO_OT_INFO (object); if (info->gdef) { HB_Done_GDEF_Table (info->gdef); info->gdef = NULL; } if (info->gsub) { HB_Done_GSUB_Table (info->gsub); info->gsub = NULL; } if (info->gpos) { HB_Done_GPOS_Table (info->gpos); info->gpos = NULL; } parent_class->finalize (object);}static voidpango_ot_info_finalizer (void *object){ FT_Face face = object; PangoOTInfo *info = face->generic.data; info->face = NULL; g_object_unref (info);}/** * pango_ot_info_get: * @face: a <type>FT_Face</type>. * * Returns the #PangoOTInfo structure for the given FreeType font. * * Return value: the #PangoOTInfo for @face. This object will have * the same lifetime as @face. * * Since: 1.2 **/PangoOTInfo *pango_ot_info_get (FT_Face face){ PangoOTInfo *info; if (face->generic.data) return face->generic.data; else { info = face->generic.data = g_object_new (PANGO_TYPE_OT_INFO, NULL); face->generic.finalizer = pango_ot_info_finalizer; info->face = face; } return info;}/* There must be be a better way to do this */static gbooleanis_truetype (FT_Face face){ return FT_IS_SFNT(face);}typedef struct _GlyphInfo GlyphInfo;struct _GlyphInfo { FT_UShort glyph; FT_UShort class;};static intcompare_glyph_info (gconstpointer a, gconstpointer b){ const GlyphInfo *info_a = a; const GlyphInfo *info_b = b; return (info_a->glyph < info_b->glyph) ? -1 : (info_a->glyph == info_b->glyph) ? 0 : 1;}/* Make a guess at the appropriate class for a glyph given * a character code that maps to the glyph */static gbooleanget_glyph_class (gunichar charcode, FT_UShort *class){ /* For characters mapped into the Arabic Presentation forms, using properties * derived as we apply GSUB substitutions will be more reliable */ if ((charcode >= 0xFB50 && charcode <= 0xFDFF) || /* Arabic Presentation Forms-A */ (charcode >= 0xFE70 && charcode <= 0XFEFF)) /* Arabic Presentation Forms-B */ return FALSE; switch (g_unichar_type (charcode)) { case G_UNICODE_COMBINING_MARK: case G_UNICODE_ENCLOSING_MARK: case G_UNICODE_NON_SPACING_MARK: *class = 3; /* Mark glyph (non-spacing combining glyph) */ return TRUE; case G_UNICODE_UNASSIGNED: case G_UNICODE_PRIVATE_USE: return FALSE; /* Unknown, don't assign a class; classes get * propagated during GSUB application */ default: *class = 1; /* Base glyph (single character, spacing glyph) */ return TRUE; }}static gbooleanset_unicode_charmap (FT_Face face){ int charmap; for (charmap = 0; charmap < face->num_charmaps; charmap++) if (face->charmaps[charmap]->encoding == ft_encoding_unicode) { FT_Error error = FT_Set_Charmap(face, face->charmaps[charmap]); return error == FT_Err_Ok; } return FALSE;}/* Synthesize a GDEF table using the font's charmap and the * Unicode property database. We'll fill in class definitions * for glyphs not in the charmap as we walk through the tables. */static voidsynthesize_class_def (PangoOTInfo *info){ GArray *glyph_infos; FT_UShort *glyph_indices; FT_UShort *classes; FT_ULong charcode; FT_UInt glyph; unsigned int i, j; FT_CharMap old_charmap; old_charmap = info->face->charmap; if (!old_charmap || !old_charmap->encoding != ft_encoding_unicode) if (!set_unicode_charmap (info->face)) return; glyph_infos = g_array_new (FALSE, FALSE, sizeof (GlyphInfo)); /* Collect all the glyphs in the charmap, and guess * the appropriate classes for them */ charcode = FT_Get_First_Char (info->face, &glyph); while (glyph != 0) { GlyphInfo glyph_info; if (glyph <= 65535) { glyph_info.glyph = glyph; if (get_glyph_class (charcode, &glyph_info.class)) g_array_append_val (glyph_infos, glyph_info); } charcode = FT_Get_Next_Char (info->face, charcode, &glyph); } /* Sort and remove duplicates */ g_array_sort (glyph_infos, compare_glyph_info); glyph_indices = g_new (FT_UShort, glyph_infos->len); classes = g_new (FT_UShort, glyph_infos->len); for (i = 0, j = 0; i < glyph_infos->len; i++) { GlyphInfo *info = &g_array_index (glyph_infos, GlyphInfo, i); if (j == 0 || info->glyph != glyph_indices[j - 1]) { glyph_indices[j] = info->glyph; classes[j] = info->class; j++; } } g_array_free (glyph_infos, TRUE); HB_GDEF_Build_ClassDefinition (info->gdef, info->face->num_glyphs, j, glyph_indices, classes); g_free (glyph_indices); g_free (classes); if (old_charmap && info->face->charmap != old_charmap) FT_Set_Charmap (info->face, old_charmap);}HB_GDEFpango_ot_info_get_gdef (PangoOTInfo *info){ g_return_val_if_fail (PANGO_IS_OT_INFO (info), NULL); if (!(info->loaded & INFO_LOADED_GDEF)) { FT_Error error; info->loaded |= INFO_LOADED_GDEF; if (is_truetype (info->face)) { error = HB_Load_GDEF_Table (info->face, &info->gdef); if (error && error != FT_Err_Table_Missing) g_warning ("Error loading GDEF table %d", error); if (!info->gdef) error = HB_New_GDEF_Table (info->face, &info->gdef); if (info->gdef && !info->gdef->GlyphClassDef.loaded) synthesize_class_def (info); } } return info->gdef;}HB_GSUBpango_ot_info_get_gsub (PangoOTInfo *info){ g_return_val_if_fail (PANGO_IS_OT_INFO (info), NULL); if (!(info->loaded & INFO_LOADED_GSUB)) { FT_Error error; HB_GDEF gdef = pango_ot_info_get_gdef (info); info->loaded |= INFO_LOADED_GSUB; if (is_truetype (info->face)) { error = HB_Load_GSUB_Table (info->face, &info->gsub, gdef); if (error && error != FT_Err_Table_Missing) g_warning ("Error loading GSUB table %d", error); } } return info->gsub;}HB_GPOSpango_ot_info_get_gpos (PangoOTInfo *info){ g_return_val_if_fail (PANGO_IS_OT_INFO (info), NULL); if (!(info->loaded & INFO_LOADED_GPOS)) { FT_Error error;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -