From: handa Date: Fri, 12 Oct 2007 05:40:00 +0000 (+0000) Subject: Include m17n-core.h instead of m17n.h. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=2c12dd57b7ad7d94110bb1872afd802a689c882b;p=m17n%2Fm17n-lib.git Include m17n-core.h instead of m17n.h. (Mexist): New variable. (enum FontLayoutCmdRuleSrcType): New enum SRC_EXIST. (FontLayoutCmdRule): New member src.exist. (parse_otf_command): Handle gsub_count and gpos_count separately. (load_otf_command): Adjusted for the change of MFLTOtfSpec. (load_command): Handle the command "exist". (free_flt_command): Adjusted for the change of MFLTOtfSpec. (run_rule): Handle the case SRC_EXIST. (run_otf): Adjusted for the change of MFLTOtfSpec. (run_command): Check the range of FROM. (check_otf_spec): Delete it. (m17n_init_flt): Call m17n_init_core instead of m17n_init. Initialize Mexist. (m17n_fini_flt): Call m17n_fini_core instead of m17n_fiini. (mflt_find): Call font->check_otf instead of check_otf_spec. (mflt_run): Keep the metrics in 26.6 fixed point. --- diff --git a/src/m17n-flt.c b/src/m17n-flt.c index ac9b2f1..80795ea 100644 --- a/src/m17n-flt.c +++ b/src/m17n-flt.c @@ -25,7 +25,10 @@ @brief FLT support for a window system. This section defines the m17n FLT API concerning character - layouting facility using FLT (Font Layout Table). */ + layouting facility using FLT (Font Layout Table). FLT + + +*/ /*=*/ @@ -42,7 +45,7 @@ #include #include -#include "m17n.h" +#include "m17n-core.h" #include "m17n-flt.h" #include "m17n-misc.h" #include "internal.h" @@ -347,7 +350,7 @@ GREPLACE (MFLTGlyphString *src, int src_from, int src_to, #define CMD_ID_TO_INDEX(id) (CMD_ID_OFFSET_INDEX - (id)) #define INDEX_TO_CMD_ID(idx) (CMD_ID_OFFSET_INDEX - (idx)) -static MSymbol Mcond, Mrange; +static MSymbol Mcond, Mrange, Mexist; #define GLYPH_CODE_P(code) \ ((code) >= GLYPH_CODE_MIN && (code) <= GLYPH_CODE_MAX) @@ -370,7 +373,8 @@ enum FontLayoutCmdRuleSrcType SRC_REGEX, SRC_INDEX, SRC_SEQ, - SRC_RANGE + SRC_RANGE, + SRC_EXIST }; typedef struct @@ -389,6 +393,9 @@ typedef struct struct { int from, to; } range; + struct { + int c; + } exist; } src; int n_cmds; @@ -684,18 +691,21 @@ parse_otf_command (MSymbol symbol, MFLTOtfSpec *spec) spec->script = script; spec->langsys = langsys; - spec->gsub_count = gsub_count; - spec->gpos_count = gpos_count; - if (gsub_count + gpos_count > 0) + spec->gsub_gpos[0].count = gsub_count; + if (gsub_count > 0) { - spec->gsub = malloc (sizeof (int) * (gsub_count + gpos_count)); - if (! spec->gsub) + spec->gsub_gpos[0].tags = malloc (sizeof (int) * gsub_count); + if (! spec->gsub_gpos[0].tags) MERROR (MERROR_FLT, -2); - spec->gpos = spec->gsub + gsub_count; - if (gsub_count > 0) - memcpy (spec->gsub, gsub, sizeof (int) * gsub_count); - if (gpos_count > 0) - memcpy (spec->gpos, gpos, sizeof (int) * gpos_count); + memcpy (spec->gsub_gpos[0].tags, gsub, sizeof (int) * gsub_count); + } + spec->gsub_gpos[1].count = gpos_count; + if (gpos_count > 0) + { + spec->gsub_gpos[1].tags = malloc (sizeof (int) * gpos_count); + if (! spec->gsub_gpos[1].tags) + MERROR (MERROR_FLT, -2); + memcpy (spec->gsub_gpos[1].tags, gpos, sizeof (int) * gpos_count); } return 0; } @@ -727,7 +737,7 @@ load_otf_command (FontLayoutCmd *cmd, MSymbol sym) if (result == -2) return result; if (result < 0) - cmd->body.otf.gsub_count = cmd->body.otf.gpos_count = 0; + cmd->body.otf.gsub_gpos[0].count = cmd->body.otf.gsub_gpos[1].count = 0; cmd->type = FontLayoutCmdTypeOTF; return 0; } @@ -853,7 +863,8 @@ load_command (FontLayoutStage *stage, MPlist *plist, { /* PLIST ::= ( cond ... ) | ( STRING ... ) | ( INTEGER ... ) | ( ( INTEGER INTEGER ) ... ) - | ( ( range INTEGER INTEGER ) ... ) */ + | ( ( range INTEGER INTEGER ) ... ) + | ( ( exist INTEGER ) ... ) */ MPlist *elt = MPLIST_PLIST (plist); int len = MPLIST_LENGTH (elt) - 1; FontLayoutCmd *cmd; @@ -978,6 +989,8 @@ load_command (FontLayoutStage *stage, MPlist *plist, } else if (MPLIST_SYMBOL_P (pl) && size == 3) { + if (MPLIST_SYMBOL (pl) != Mrange) + MERROR (MERROR_FLT, INVALID_CMD_ID); cmd->body.rule.src_type = SRC_RANGE; pl = MPLIST_NEXT (pl); if (! MPLIST_INTEGER_P (pl)) @@ -990,6 +1003,21 @@ load_command (FontLayoutStage *stage, MPlist *plist, cmd->body.rule.src.range.to = (unsigned) MPLIST_INTEGER (pl); } + else if (MPLIST_SYMBOL_P (pl) && size <= 2) + { + if (MPLIST_SYMBOL (pl) != Mexist) + MERROR (MERROR_FLT, INVALID_CMD_ID); + cmd->body.rule.src_type = SRC_EXIST; + if (size == 1) + cmd->body.rule.src.exist.c = -1; + else + { + pl = MPLIST_NEXT (pl); + if (! MPLIST_INTEGER_P (pl)) + MERROR (MERROR_DRAW, INVALID_CMD_ID); + cmd->body.rule.src.exist.c = MPLIST_INTEGER (pl); + } + } else MERROR (MERROR_DRAW, INVALID_CMD_ID); } @@ -1105,8 +1133,10 @@ free_flt_command (FontLayoutCmd *cmd) free (cmd->body.cond.cmd_ids); else if (cmd->type == FontLayoutCmdTypeOTF) { - if (cmd->body.otf.gsub_count + cmd->body.otf.gpos_count > 0) - free (cmd->body.otf.gsub); + if (cmd->body.otf.gsub_gpos[0].count > 0) + free (cmd->body.otf.gsub_gpos[0].tags); + if (cmd->body.otf.gsub_gpos[1].count > 0) + free (cmd->body.otf.gsub_gpos[1].tags); } } @@ -1388,6 +1418,42 @@ run_rule (int depth, if (MDEBUG_FLAG () > 2) MDEBUG_PRINT3 ("\n [FLT] %*s(INDEX %d", depth, "", rule->src.match_idx); } + else if (rule->src_type == SRC_EXIST) + { + int encoded; + unsigned code; + + if (rule->src.exist.c < 0) + { + if (from >= to) + return 0; + code = GREF (ctx->in, from)->code; + to = from + 1; + encoded = GREF (ctx->in, from)->encoded; + } + else + { + code = rule->src.exist.c; + to = from; + encoded = 0; + } + if (! encoded) + { + static MFLTGlyphString gstring; + + if (! gstring.glyph_size) + { + gstring.glyph_size = ctx->in->glyph_size; + gstring.glyphs = calloc (1, gstring.glyph_size); + gstring.allocated = 1; + gstring.used = 1; + } + gstring.glyphs[0].code = code; + if (ctx->font->get_glyph_id (ctx->font, &gstring, 0, 1) < 0 + || ! gstring.glyphs[0].encoded) + return 0; + } + } consumed = 0; depth++; @@ -1463,7 +1529,7 @@ run_otf (int depth, if (to < 0) return to; out_len = ctx->out->used - from_idx; - if (otf_spec->gpos_count > 0) + if (otf_spec->gsub_gpos[1].count > 0) { MFLTGlyphAdjustment *a; @@ -1569,7 +1635,7 @@ run_command (int depth, int id, int from, int to, FontLayoutContext *ctx) if (MDEBUG_FLAG () > 2) MDEBUG_PRINT3 ("\n [FLT] %*s(DIRECT 0x%X", depth, "", ctx->code_offset + id); - i = from < to ? from : from - 1; + i = (from < to || from == 0) ? from : from - 1; GDUP (ctx, i); g = GREF (ctx->out, ctx->out->used - 1); g->code = ctx->code_offset + id; @@ -1967,37 +2033,6 @@ run_stages (MFLTGlyphString *gstring, int from, int to, #define CHECK_FLT_COVERAGE(flt) ((flt)->coverage || load_flt (flt, 0) == 0) #define CHECK_FLT_STAGES(flt) ((flt)->stages || load_flt (flt, 1) == 0) -static int -check_otf_spec (MFLTOtfSpec *src, MFLTOtfSpec *tgt) -{ - int i, j; - unsigned int feature; - - if (src->script && src->script != tgt->script) - return 0; - if (src->langsys && src->langsys != tgt->langsys) - return 0; - for (i = 0; i < src->gsub_count; i++) - { - feature = src->gsub[i]; - for (j = 0; j < tgt->gsub_count; j++) - if (feature == tgt->gsub[j]) - break; - if (j == tgt->gsub_count) - return 0; - } - for (i = 0; i < src->gpos_count; i++) - { - feature = src->gpos[i]; - for (j = 0; j < tgt->gpos_count; j++) - if (feature == tgt->gpos[j]) - break; - if (j == tgt->gpos_count) - return 0; - } - return 1; -} - /* Internal API */ @@ -2028,7 +2063,7 @@ m17n_init_flt (void) merror_code = MERROR_NONE; if (m17n__flt_initialized++) return; - m17n_init (); + m17n_init_core (); if (merror_code != MERROR_NONE) { m17n__flt_initialized--; @@ -2036,17 +2071,17 @@ m17n_init_flt (void) } MDEBUG_PUSH_TIME (); + MDEBUG_PUSH_TIME (); Mcond = msymbol ("cond"); Mrange = msymbol ("range"); Mfont = msymbol ("font"); Mlayouter = msymbol ("layouter"); + Mexist = msymbol ("exist"); MDEBUG_POP_TIME (); MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the flt modules.")); MDEBUG_POP_TIME (); - - return; } void @@ -2061,6 +2096,7 @@ m17n_fini_flt (void) MDEBUG_PUSH_TIME (); MDEBUG_PUSH_TIME (); + MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize database module.")); if (flt_list) { @@ -2083,7 +2119,7 @@ m17n_fini_flt (void) MDEBUG_POP_TIME (); MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the flt modules.")); MDEBUG_POP_TIME (); - m17n_fini (); + m17n_fini_core (); } /*** @} */ @@ -2120,13 +2156,13 @@ mflt_find (int c, MFLTFont *font) if (flt->family && flt->family != font->family) continue; if (flt->otf.sym - && (! font->otf.sym - || ! check_otf_spec (&flt->otf, &font->otf))) + && (! font->check_otf (font, &flt->otf))) continue; - if (c < 0 - || (CHECK_FLT_COVERAGE (flt) - && mchartable_lookup (flt->coverage, c))) - return flt; + if (c >= 0 + && (! CHECK_FLT_COVERAGE (flt) + || ! mchartable_lookup (flt->coverage, c))) + continue; + return flt; } return NULL; } @@ -2228,6 +2264,7 @@ mflt_run (MFLTGlyphString *gstring, int from, int to, ctx.out->allocated *= 2; } +#if 0 for (i = from; i < to; i++) { MFLTGlyph *g = GREF (gstring, i); @@ -2241,6 +2278,7 @@ mflt_run (MFLTGlyphString *gstring, int from, int to, g->xoff >>= 6; g->yoff >>= 6; } +#endif if (MDEBUG_FLAG ()) {