#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, \
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));
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);
}
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;
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);
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;
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);
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;
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. */
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. */
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)
{
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;
{
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;
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);
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