diff --git a/modules/hangul/hangul-fc.c b/modules/hangul/hangul-fc.c index 7692a84..7d2271b 100644 --- a/modules/hangul/hangul-fc.c +++ b/modules/hangul/hangul-fc.c @@ -26,6 +26,7 @@ #include "pango-engine.h" #include "pango-utils.h" #include "pangofc-font.h" +#include "pango-ot.h" #include "hangul-defs.h" #include "tables-jamos.i" @@ -50,6 +51,23 @@ static PangoEngineInfo script_engines[] = { } }; +static const PangoOTFeatureMap gsub_features[] = { + {"ccmp", PANGO_OT_ALL_GLYPHS}, + {"pdch", PANGO_OT_ALL_GLYPHS}, + {"ljmo", PANGO_OT_ALL_GLYPHS}, + {"vjmo", PANGO_OT_ALL_GLYPHS}, + {"tjmo", PANGO_OT_ALL_GLYPHS}, +}; + +static const PangoOTFeatureMap vertical_gsub_features[] = { + {"ccmp", PANGO_OT_ALL_GLYPHS}, + {"pdch", PANGO_OT_ALL_GLYPHS}, + {"ljmo", PANGO_OT_ALL_GLYPHS}, + {"vjmo", PANGO_OT_ALL_GLYPHS}, + {"tjmo", PANGO_OT_ALL_GLYPHS}, + {"vert", PANGO_OT_ALL_GLYPHS} +}; + static void set_glyph (PangoFont *font, PangoGlyphString *glyphs, int i, int offset, PangoGlyph glyph) { @@ -396,8 +414,7 @@ render_basic (PangoFont *font, gunichar wc, } static void -hangul_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED, - PangoFont *font, +set_glyphs ( PangoFont *font, const char *text, gint length, const PangoAnalysis *analysis G_GNUC_UNUSED, @@ -460,6 +477,89 @@ hangul_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED, start - text); } +static void +hangul_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED, + PangoFont *font, + const char *text, + gint length, + const PangoAnalysis *analysis, + PangoGlyphString *glyphs) +{ + PangoFcFont *fc_font; + FT_Face face; + PangoOTRulesetDescription desc; + const PangoOTRuleset *ruleset; + PangoOTBuffer *buffer; + gboolean has_ot_table; + gint num_glyphs; + gint i; + + g_return_if_fail (font != NULL); + g_return_if_fail (text != NULL); + g_return_if_fail (length >= 0); + g_return_if_fail (analysis != NULL); + + fc_font = PANGO_FC_FONT (font); + face = pango_fc_font_lock_face (fc_font); + if (!face) + return; + + set_glyphs (font, text, length, analysis, glyphs); + + has_ot_table = pango_ot_info_find_script (pango_ot_info_get (face), + PANGO_OT_TABLE_GSUB, + PANGO_OT_TAG_MAKE_FROM_STRING("hang"), + NULL); + if (!has_ot_table) goto done; + + buffer = pango_ot_buffer_new (fc_font); + + num_glyphs = glyphs->num_glyphs; + for (i=0; i < num_glyphs; i++) + { + PangoGlyph glyph; + int cluster; + + glyph = glyphs->glyphs[i].glyph; + cluster = glyphs->log_clusters[i]; + + pango_ot_buffer_add_glyph (buffer, glyph, 0, cluster); + } + pango_glyph_string_set_size (glyphs, 0); + + desc.script = analysis->script; + desc.language = analysis->language; + + if (PANGO_GRAVITY_IS_VERTICAL (analysis->gravity)) + { + desc.n_static_gsub_features = G_N_ELEMENTS (vertical_gsub_features); + desc.static_gsub_features = vertical_gsub_features; + } + else + { + desc.n_static_gsub_features = G_N_ELEMENTS (gsub_features); + desc.static_gsub_features = gsub_features; + } + desc.n_static_gpos_features = 0; + desc.static_gpos_features = NULL; + desc.n_other_features = 0; + desc.other_features = NULL; + + ruleset = pango_ot_ruleset_get_for_description ( pango_ot_info_get (face), &desc); + + pango_ot_ruleset_substitute (ruleset, buffer); + /*pango_ot_ruleset_position (ruleset, buffer);*/ + pango_ot_buffer_output (buffer, glyphs); + + pango_ot_buffer_destroy (buffer); + +done: + //fix_tone_mark_geometry (font, glyphs, HTONE1); + //fix_tone_mark_geometry (font, glyphs, HTONE2); + + pango_fc_font_unlock_face (fc_font); +} + static void hangul_engine_fc_class_init (PangoEngineShapeClass *class) {