From d8173c5209396aad14621859fdf8d572ef88319e Mon Sep 17 00:00:00 2001 From: handa Date: Fri, 12 Oct 2007 05:31:51 +0000 Subject: [PATCH] (Mexist): New variable. (enum FontLayoutCmdRuleSrcType): New enum SRC_EXIST. (FontLayoutCmdRule): New member src.exist. (load_category_table): Use isalnum, not isalpha. (load_command): Check the command "exist". (run_rule): Hande the case SRC_EXIST. (run_command): Check the range of FROM. (mfont__flt_init): Initialize Mexist. --- src/font-flt.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/src/font-flt.c b/src/font-flt.c index 6f05fbe..882463b 100644 --- a/src/font-flt.c +++ b/src/font-flt.c @@ -257,7 +257,7 @@ static MPlist *flt_list; #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) @@ -280,7 +280,8 @@ enum FontLayoutCmdRuleSrcType SRC_REGEX, SRC_INDEX, SRC_SEQ, - SRC_RANGE + SRC_RANGE, + SRC_EXIST }; typedef struct @@ -299,6 +300,9 @@ typedef struct struct { int from, to; } range; + struct { + int c; + } exist; } src; int n_cmds; @@ -383,7 +387,7 @@ load_category_table (MPlist *plist) MERROR (MERROR_FONT, NULL); category_code = MPLIST_INTEGER (elt); } - if (! isalpha (category_code)) + if (! isalnum (category_code)) MERROR (MERROR_FONT, NULL); if (from == to) @@ -687,6 +691,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); } @@ -1064,6 +1083,33 @@ 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) + { + MGlyph *g = MGLYPH (from); + int encoded = g->otf_encoded; + unsigned code; + + if (rule->src.exist.c < 0) + { + if (from >= to) + return 0; + code = g->code; + to = from + 1; + } + else + { + code = rule->src.exist.c; + to = from; + encoded = 0; + } + if (! encoded) + { + code = (g->rface->rfont->driver->encode_char + (NULL, (MFont *) g->rface->rfont, NULL, code)); + if (code == MCHAR_INVALID_CODE) + return 0; + } + } consumed = 0; depth++; @@ -1157,7 +1203,7 @@ run_command (int depth, int id, MGlyphString *gstring, int from, int to, /* Direct code (== id + ctx->code_offset) output. The source is not consumed. */ - if (from < to) + if (from < to || from == 1) g = *(MGLYPH (from)); else g = *(MGLYPH (from - 1)); @@ -1307,6 +1353,7 @@ mfont__flt_init (void) Mcond = msymbol ("cond"); Mrange = msymbol ("range"); Mlayouter = msymbol ("layouter"); + Mexist = msymbol ("exist"); flt_list = mplist (); return 0; } -- 1.7.10.4