From: handa Date: Sat, 7 Aug 2004 01:59:14 +0000 (+0000) Subject: (IGNORED_GLYPH): New macro. X-Git-Tag: REL-0-9-1~7 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=350952b2ca65eb6e3959c8d4e39e1fe5e02a76fc;p=m17n%2Flibotf.git (IGNORED_GLYPH): New macro. (gstring_subst, match_ids, match_chain_ids, match_classes) (match_chain_classes, match_coverages, match_chain_coverages): use IGNORED_GLYPH. (lookup_gsub): Likewise. Include OTF_MarkAttachmentType in flag. (lookup_gpos): Likewise. --- diff --git a/src/otfdrive.c b/src/otfdrive.c index b2122ce..a857e68 100644 --- a/src/otfdrive.c +++ b/src/otfdrive.c @@ -29,6 +29,14 @@ write to the Free Software Foundation, Inc., 59 Temple Place, Suite #include "otf.h" #include "otferror.h" +/* Return nonzero if OTF_Glyph *G should be ignored according to + LookupFlag FLAG. */ +#define IGNORED_GLYPH(g, flag) \ + ((g)->glyph_id == 0 \ + || ((flag) & (1 << (g)->GlyphClass)) \ + || (((flag) & OTF_MarkAttachmentType) \ + && ((flag) >> 8) == (g)->MarkAttachClass)) + #define GSTRING_DELETE(gstring, from, len) \ do { \ memmove (gstring->glyphs + from, gstring->glyphs + from + len, \ @@ -68,16 +76,17 @@ gstring_subst (OTF_GlyphString *gstring, int from, int to, int flag, int non_ignored_idx; for (i = non_ignored_idx = to - 1; i >= from; i--) - if (! gstring->glyphs[i].glyph_id - || (flag & (1 << gstring->glyphs[i].GlyphClass))) - { - OTF_Glyph temp = gstring->glyphs[i]; + { + OTF_Glyph *g = gstring->glyphs + i; + if (IGNORED_GLYPH (g, flag)) + { + OTF_Glyph temp = *g; - memmove (gstring->glyphs + i, gstring->glyphs + i + 1, - sizeof (OTF_Glyph) * (non_ignored_idx - i)); - gstring->glyphs[non_ignored_idx--] = temp; - len--; - } + memmove (g, g + 1, sizeof (OTF_Glyph) * (non_ignored_idx - i)); + gstring->glyphs[non_ignored_idx--] = temp; + len--; + } + } if (len < num) GSTRING_INSERT (gstring, from, (num - len)); @@ -252,8 +261,7 @@ match_ids (OTF_GlyphString *gstring, int gidx, int flag, int i; for (g = gbeg, i = 0; g < gend && i < count; g++) - if (g->glyph_id && ! (flag & (1 << g->GlyphClass)) - && g->glyph_id != ids[i++]) + if (! IGNORED_GLYPH (g, flag) && g->glyph_id != ids[i++]) return -1; return (i < count ? -1 : g - gbeg); } @@ -267,10 +275,10 @@ match_chain_ids (OTF_GlyphString *gstring, int gidx, int flag, if (i > 0) { int j; + OTF_Glyph *g; - for (j = gidx - 1; j >= 0; j--) - if (gstring->glyphs[j].glyph_id - && --i == 0) + for (j = gidx - 1, g = gstring->glyphs + j; j >= 0; j--, g--) + if (! IGNORED_GLYPH (g, flag) && --i == 0) break; if (i > 0) return -1; @@ -302,7 +310,7 @@ match_classes (OTF_ClassDef *class_def, OTF_GlyphString *gstring, int gidx, int i; for (g = gbeg, i = 0; g < gend && i < count; g++) - if (g->glyph_id && ! (flag & (1 << g->GlyphClass)) + if (! IGNORED_GLYPH (g, flag) && get_class_def (class_def, g->glyph_id) != classes[i++]) return -1; return (i < count ? -1 : g - gbeg); @@ -320,10 +328,10 @@ match_chain_classes (OTF_GlyphString *gstring, int gidx, int flag, if (i > 0) { int j; + OTF_Glyph *g; - for (j = gidx - 1; j >= 0 && i > 0; j--) - if (gstring->glyphs[j].glyph_id - && i-- == 0) + for (j = gidx - 1, g = gstring->glyphs + j; j >= 0; j--, g--) + if (! IGNORED_GLYPH (g, flag) && i-- == 0) break; if (i > 0) return -1; @@ -355,7 +363,7 @@ match_coverages (OTF_GlyphString *gstring, int gidx, int flag, int count, int i; for (g = gbeg, i = 0; g < gend && i < count; g++) - if (g->glyph_id && ! (flag & (1 << g->GlyphClass)) + if (! IGNORED_GLYPH (g, flag) && get_coverage_index (coverages + i++, g->glyph_id) < 0) return -1; return (i < count ? -1 : g - gbeg); @@ -370,10 +378,10 @@ match_chain_coverages (OTF_GlyphString *gstring, int gidx, int flag, if (i > 0) { int j; + OTF_Glyph *g; - for (j = gidx - 1; j >= 0; j--) - if (gstring->glyphs[j].glyph_id - && --i == 0) + for (j = gidx - 1, g= gstring->glyphs +j; j >= 0; j--, g--) + if (! IGNORED_GLYPH (g, flag) && --i == 0) break; if (i > 0) return -1; @@ -403,14 +411,13 @@ lookup_gsub (OTF_LookupList *lookup_list, unsigned lookup_list_index, char *errfmt = "GSUB Looking up%s"; int errret = -1; OTF_Lookup *lookup = lookup_list->Lookup + lookup_list_index; - unsigned int flag = lookup->LookupFlag & OTF_LookupFlagIgnoreMask; + unsigned int flag = (lookup->LookupFlag + & (OTF_LookupFlagIgnoreMask | OTF_MarkAttachmentType)); int orig_gidx = gidx; OTF_Glyph *g = gstring->glyphs + gidx; int i; - if (! g->glyph_id - || (g->GlyphClass - && (flag & (1 << g->GlyphClass)))) + if (IGNORED_GLYPH (g, flag)) return (gidx + 1); /* Try all subtables until one of them handles the current glyph. */ @@ -726,15 +733,14 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index, char *errfmt = "GPOS Looking up%s"; int errret = -1; OTF_Lookup *lookup = lookup_list->Lookup + lookup_list_index; - unsigned int flag = lookup->LookupFlag & OTF_LookupFlagIgnoreMask; + unsigned int flag = (lookup->LookupFlag + & (OTF_LookupFlagIgnoreMask | OTF_MarkAttachmentType)); int orig_gidx = gidx; OTF_Glyph *g = gstring->glyphs + gidx; int i; - if (! g->glyph_id - || g->positioning_type - || (g->GlyphClass - && (flag & (1 << g->GlyphClass)))) + if (IGNORED_GLYPH (g, flag) + || g->positioning_type) return (gidx + 1); /* Try all subtables until one of them handles the current glyph. */ @@ -782,19 +788,15 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index, case 2: { - int next_gidx = gidx + 1; + int next_gidx; OTF_Glyph *nextg; - while (next_gidx < gstring->used - && (! gstring->glyphs[next_gidx].glyph_id - || ! (flag - & (1 << gstring->glyphs[next_gidx].GlyphClass)))) - next_gidx++; + for (next_gidx = gidx + 1, nextg = gstring->glyphs + next_gidx; + next_gidx < gstring->used && ! IGNORED_GLYPH (nextg, flag); + next_gidx++, nextg++); - if (next_gidx >= gstring->used) - continue; - nextg = gstring->glyphs + next_gidx; - if (nextg->positioning_type) + if (next_gidx >= gstring->used + || nextg->positioning_type) continue; if (subtable->Format == 1) { @@ -869,18 +871,17 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index, OTF_GPOS_MarkBase1 *mark_base1 = &subtable->u.mark_base1; OTF_MarkRecord *mark_record; OTF_AnchorRecord *base_record; - OTF_Glyph *baseg = g - 1; + OTF_Glyph *baseg; int coverage_idx_base; - while (baseg >= gstring->glyphs - && (! baseg->glyph_id - || (baseg->GlyphClass - && (flag & (1 << baseg->GlyphClass))))) - baseg--; + for (baseg = g - 1; + baseg >= gstring->glyphs && IGNORED_GLYPH (baseg, flag); + baseg--); + if (baseg < gstring->glyphs) + continue; coverage_idx_base = get_coverage_index (&mark_base1->BaseCoverage, baseg->glyph_id); - if (coverage_idx_base < 0) continue; mark_record = mark_base1->MarkArray.MarkRecord + coverage_idx; @@ -900,7 +901,7 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index, { OTF_GPOS_MarkLig1 *mark_lig1 = &subtable->u.mark_lig1; unsigned class = g->MarkAttachClass; - OTF_Glyph *ligg = g - 1; + OTF_Glyph *ligg; int coverage_idx_lig; OTF_MarkRecord *mark_record; OTF_ComponentRecord *cmp_record; @@ -911,16 +912,14 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index, for (j = 0; j < mark_lig1->ClassCount; j++) num_class[j] = 0; - while (ligg >= gstring->glyphs - && (! ligg->glyph_id - || (ligg->GlyphClass - && (flag & (1 << ligg->GlyphClass))))) - { - if (ligg->positioning_type == 5 - && ligg->MarkAttachClass < mark_lig1->ClassCount) - num_class[ligg->MarkAttachClass]++; - ligg--; - } + for (ligg = g - 1; + ligg >= gstring->glyphs && IGNORED_GLYPH (ligg, flag); + ligg--) + if (ligg->positioning_type == 5 + && ligg->MarkAttachClass < mark_lig1->ClassCount) + num_class[ligg->MarkAttachClass]++; + if (ligg < gstring->glyphs) + continue; coverage_idx_lig = get_coverage_index (&mark_lig1->LigatureCoverage, ligg->glyph_id); @@ -955,14 +954,12 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index, OTF_GPOS_MarkMark1 *mark_mark1 = &subtable->u.mark_mark1; OTF_MarkRecord *mark1_record; OTF_AnchorRecord *mark2_record; - OTF_Glyph *prevg = g - 1; + OTF_Glyph *prevg; int coverage_idx_base; - while (prevg >= gstring->glyphs - && (! prevg->glyph_id - || (prevg->GlyphClass - && (flag & (1 << prevg->GlyphClass))))) - prevg--; + for (prevg = g - 1; + prevg >= gstring->glyphs && IGNORED_GLYPH (prevg, flag); + prevg--); if (prevg < gstring->glyphs) continue; coverage_idx_base