diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2012-08-16 20:51:57 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2012-08-16 21:10:10 -0400 |
commit | 8168660e5f1906aed2a45d30529058f51473bcef (patch) | |
tree | 8c5a9172672404c0f85bc78f3ba31a566cb52aba /pango/pango-ot-info.c | |
parent | feff5a6e2682048a07a6ba09af83254e290bf394 (diff) | |
parent | 656d473b52e3edea621c0681d2ba14363f257e84 (diff) | |
download | pango-8168660e5f1906aed2a45d30529058f51473bcef.tar.gz |
Merge branch 'harfbuzz-ng-external'
Conflicts:
configure.in
docs/tmpl/text-attributes.sgml
modules/arabic/arabic-ot.c
modules/indic/indic-ot.c
pango/opentype/Makefile.am
pango/opentype/hb-blob.c
pango/opentype/hb-buffer-private.h
pango/opentype/hb-common.h
pango/opentype/hb-ot-layout-gsubgpos-private.hh
pango/opentype/hb-private.h
pango/pango-ot-info.c
Diffstat (limited to 'pango/pango-ot-info.c')
-rw-r--r-- | pango/pango-ot-info.c | 297 |
1 files changed, 12 insertions, 285 deletions
diff --git a/pango/pango-ot-info.c b/pango/pango-ot-info.c index e5d9c641..1f552c3a 100644 --- a/pango/pango-ot-info.c +++ b/pango/pango-ot-info.c @@ -31,8 +31,6 @@ static void pango_ot_info_finalize (GObject *object); -static void synthesize_class_def (PangoOTInfo *info); - G_DEFINE_TYPE (PangoOTInfo, pango_ot_info, G_TYPE_OBJECT); static void @@ -69,31 +67,6 @@ pango_ot_info_finalizer (void *object) g_object_unref (info); } -static hb_blob_t * -_get_table (hb_tag_t tag, void *user_data) -{ - PangoOTInfo *info = (PangoOTInfo *) user_data; - FT_Byte *buffer; - FT_ULong length = 0; - FT_Error error; - - error = FT_Load_Sfnt_Table (info->face, tag, 0, NULL, &length); - if (error) - return hb_blob_create_empty (); - - buffer = g_malloc (length); - if (buffer == NULL) - return hb_blob_create_empty (); - - error = FT_Load_Sfnt_Table (info->face, tag, 0, buffer, &length); - if (error) - return hb_blob_create_empty (); - - return hb_blob_create ((const char *) buffer, length, - HB_MEMORY_MODE_WRITABLE, - g_free, buffer); -} - /** * pango_ot_info_get: @@ -122,26 +95,7 @@ pango_ot_info_get (FT_Face face) face->generic.finalizer = pango_ot_info_finalizer; info->face = face; - - if (face->stream->read == NULL) { - hb_blob_t *blob; - - blob = hb_blob_create ((const char *) face->stream->base, - (unsigned int) face->stream->size, - HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, - NULL, NULL); - info->hb_face = hb_face_create_for_data (blob, face->face_index); - hb_blob_destroy (blob); - } else { - info->hb_face = hb_face_create_for_tables (_get_table, NULL, info); - } - - - hb_face_set_unicode_funcs (info->hb_face, hb_glib_get_unicode_funcs ()); - - /* XXX this is such a waste if not SFNT */ - if (!hb_ot_layout_has_font_glyph_classes (info->hb_face)) - synthesize_class_def (info); + info->hb_face = hb_ft_face_create (face, NULL); } return info; @@ -153,142 +107,6 @@ _pango_ot_info_get_hb_face (PangoOTInfo *info) return info->hb_face; } -typedef struct _GlyphInfo GlyphInfo; - -struct _GlyphInfo { - unsigned short glyph; - unsigned short class; -}; - -static int -compare_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 gboolean -get_glyph_class (gunichar charcode, - unsigned short *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 ((int) g_unichar_type (charcode)) - { - case G_UNICODE_SPACING_MARK: - case G_UNICODE_ENCLOSING_MARK: - case G_UNICODE_NON_SPACING_MARK: - *class = HB_OT_LAYOUT_GLYPH_CLASS_MARK; /* 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 = HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH; /* Base glyph (single character, spacing glyph) */ - return TRUE; - } -} - -static gboolean -set_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 void -synthesize_class_def (PangoOTInfo *info) -{ - GArray *glyph_infos; - hb_codepoint_t *glyph_indices; - unsigned char *classes; - gunichar 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 (hb_codepoint_t, glyph_infos->len); - classes = g_new (unsigned char, 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_ot_layout_build_glyph_classes (info->hb_face, glyph_indices, classes, j); - - g_free (glyph_indices); - g_free (classes); - - if (old_charmap && info->face->charmap != old_charmap) - FT_Set_Charmap (info->face, old_charmap); -} - static hb_tag_t get_hb_table_type (PangoOTTableType table_type) { @@ -433,11 +251,11 @@ pango_ot_info_list_scripts (PangoOTInfo *info, { hb_tag_t tt = get_hb_table_type (table_type); PangoOTTag *result; - unsigned int count = 0; + unsigned int count; - hb_ot_layout_table_get_script_tags (info->hb_face, tt, &count, NULL); + count = hb_ot_layout_table_get_script_tags (info->hb_face, tt, 0, NULL, NULL); result = g_new (PangoOTTag, count + 1); - hb_ot_layout_table_get_script_tags (info->hb_face, tt, &count, result); + hb_ot_layout_table_get_script_tags (info->hb_face, tt, 0, &count, result); result[count] = 0; return result; @@ -463,11 +281,11 @@ pango_ot_info_list_languages (PangoOTInfo *info, { hb_tag_t tt = get_hb_table_type (table_type); PangoOTTag *result; - unsigned int count = 0; + unsigned int count; - hb_ot_layout_script_get_language_tags (info->hb_face, tt, script_index, &count, NULL); + count = hb_ot_layout_script_get_language_tags (info->hb_face, tt, script_index, 0, NULL, NULL); result = g_new (PangoOTTag, count + 1); - hb_ot_layout_script_get_language_tags (info->hb_face, tt, script_index, &count, result); + hb_ot_layout_script_get_language_tags (info->hb_face, tt, script_index, 0, &count, result); result[count] = 0; return result; @@ -497,11 +315,11 @@ pango_ot_info_list_features (PangoOTInfo *info, { hb_tag_t tt = get_hb_table_type (table_type); PangoOTTag *result; - unsigned int count = 0; + unsigned int count; - hb_ot_layout_language_get_feature_tags (info->hb_face, tt, script_index, language_index, &count, NULL); + count = hb_ot_layout_language_get_feature_tags (info->hb_face, tt, script_index, language_index, 0, NULL, NULL); result = g_new (PangoOTTag, count + 1); - hb_ot_layout_language_get_feature_tags (info->hb_face, tt, script_index, language_index, &count, result); + hb_ot_layout_language_get_feature_tags (info->hb_face, tt, script_index, language_index, 0, &count, result); result[count] = 0; return result; @@ -512,31 +330,7 @@ _pango_ot_info_substitute (const PangoOTInfo *info, const PangoOTRuleset *ruleset, PangoOTBuffer *buffer) { - unsigned int i; - - for (i = 0; i < ruleset->rules->len; i++) - { - PangoOTRule *rule = &g_array_index (ruleset->rules, PangoOTRule, i); - unsigned int lookup_count, j; - unsigned int lookup_indexes[1000]; - - if (rule->table_type != PANGO_OT_TABLE_GSUB) - continue; - - lookup_count = G_N_ELEMENTS (lookup_indexes); - hb_ot_layout_feature_get_lookup_indexes (info->hb_face, - HB_OT_TAG_GSUB, - rule->feature_index, - &lookup_count, - lookup_indexes); - - lookup_count = MIN (G_N_ELEMENTS (lookup_indexes), lookup_count); - for (j = 0; j < lookup_count; j++) - hb_ot_layout_substitute_lookup (info->hb_face, - buffer->buffer, - lookup_indexes[j], - rule->property_bit); - } + /* Deprecated. */ } void @@ -544,72 +338,5 @@ _pango_ot_info_position (const PangoOTInfo *info, const PangoOTRuleset *ruleset, PangoOTBuffer *buffer) { - unsigned int i; - gboolean is_hinted; - hb_font_t *hb_font; - - hb_buffer_clear_positions (buffer->buffer); - - /* XXX reuse hb_font */ - hb_font = hb_font_create (); - hb_font_set_scale (hb_font, - info->face->size->metrics.x_scale, - info->face->size->metrics.y_scale); - is_hinted = buffer->font->is_hinted; - hb_font_set_ppem (hb_font, - is_hinted ? info->face->size->metrics.x_ppem : 0, - is_hinted ? info->face->size->metrics.y_ppem : 0); - - for (i = 0; i < ruleset->rules->len; i++) - { - PangoOTRule *rule = &g_array_index (ruleset->rules, PangoOTRule, i); - hb_mask_t mask; - unsigned int lookup_count, j; - unsigned int lookup_indexes[1000]; - - if (rule->table_type != PANGO_OT_TABLE_GPOS) - continue; - - mask = rule->property_bit; - lookup_count = G_N_ELEMENTS (lookup_indexes); - hb_ot_layout_feature_get_lookup_indexes (info->hb_face, - HB_OT_TAG_GPOS, - rule->feature_index, - &lookup_count, - lookup_indexes); - - lookup_count = MIN (G_N_ELEMENTS (lookup_indexes), lookup_count); - for (j = 0; j < lookup_count; j++) - hb_ot_layout_position_lookup (info->hb_face, hb_font, - buffer->buffer, - lookup_indexes[j], - rule->property_bit); - - buffer->applied_gpos = TRUE; - } - - if (buffer->applied_gpos) - { - unsigned int i, j; - unsigned int len = hb_buffer_get_len (buffer->buffer); - hb_glyph_position_t *positions = hb_buffer_get_glyph_positions (buffer->buffer); - - /* First handle all left-to-right connections */ - for (j = 0; j < len; j++) - { - if (positions[j].cursive_chain > 0) - positions[j].y_pos += positions[j - positions[j].cursive_chain].y_pos; - } - - /* Then handle all right-to-left connections */ - for (i = len; i > 0; i--) - { - j = i - 1; - - if (positions[j].cursive_chain < 0) - positions[j].y_pos += positions[j - positions[j].cursive_chain].y_pos; - } - } - - hb_font_destroy (hb_font); + /* Deprecated. */ } |