1 /* otfdrive.c -- OpenType font driver.
4 by AIST (National Institute of Advanced Industrial Science and Technology)
5 Registration Number H15PRO???
7 This file is part of the OTF library.
9 The OTF library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
14 The OTF library is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with the OTF library; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
31 #define GSTRING_DELETE(gstring, from, len) \
33 memmove (gstring->glyphs + from, gstring->glyphs + from + len, \
34 sizeof (OTF_Glyph) * (gstring->used - from - len)); \
35 gstring->used -= len; \
39 #define GSTRING_INSERT(gstring, pos, len) \
41 if (gstring->used + len > gstring->size) \
43 char *errfmt = "GSTRING%s"; \
45 gstring->size = gstring->used + len; \
46 gstring->glyphs = (OTF_Glyph *) realloc (gstring->glyphs, \
48 if (! gstring->glyphs) \
49 OTF_ERROR (OTF_ERROR_MEMORY, ""); \
51 memmove (gstring->glyphs + pos + len, gstring->glyphs + pos, \
52 sizeof (OTF_Glyph) * (gstring->used - pos)); \
53 gstring->used += len; \
58 gstring_subst (OTF_GlyphString *gstring, int from, int to,
59 OTF_GlyphID *ids, int num)
66 GSTRING_INSERT (gstring, from, (num - len));
68 GSTRING_DELETE (gstring, from, (len - num));
69 for (i = 0; i < num; i++)
70 gstring->glyphs[from + i].glyph_id = ids[i];
76 get_coverage_index (OTF_Coverage *coverage, OTF_GlyphID id)
80 if (coverage->CoverageFormat == 1)
82 for (i = 0; i < coverage->Count; i++)
83 if (coverage->table.GlyphArray[i] == id)
88 for (i = 0; i < coverage->Count; i++)
89 if (coverage->table.RangeRecord[i].Start <= id
90 && coverage->table.RangeRecord[i].End >= id)
91 return (coverage->table.RangeRecord[i].StartCoverageIndex
92 + (id - coverage->table.RangeRecord[i].Start));
98 get_class_def (OTF_ClassDef *class_def, OTF_GlyphID glyph_id)
100 if (class_def->ClassFormat == 1)
102 int idx = (int) glyph_id - (int) class_def->f.f1.StartGlyph;
104 if (idx >= 0 && idx < class_def->f.f1.GlyphCount)
105 return class_def->f.f1.ClassValueArray[idx];
111 for (i = 0; i < class_def->f.f2.ClassRangeCount; i++)
112 if (glyph_id >= class_def->f.f2.ClassRangeRecord[i].Start
113 && glyph_id <= class_def->f.f2.ClassRangeRecord[i].End)
114 return class_def->f.f2.ClassRangeRecord[i].Class;
120 get_langsys (OTF_ScriptList *script_list, char *script, char *language)
123 OTF_Tag script_tag = OTF_tag (script);
124 OTF_Tag langsys_tag = OTF_tag (language);
127 for (i = 0; i < script_list->ScriptCount; i++)
128 if (script_list->Script[i].ScriptTag == script_tag)
130 OTF_Script *script = script_list->Script + i;
133 return &script->DefaultLangSys;
134 for (j = 0; j < script->LangSysCount; j++)
135 if (script->LangSysRecord[j].LangSysTag == langsys_tag)
136 return script->LangSys + j;
137 return &script->DefaultLangSys;
144 setup_lookup_indices (OTF_LangSys *LangSys, OTF_FeatureList *FeatureList,
145 char *features, int *lookup_indices)
148 OTF_Feature *feature;
149 int *feature_table = alloca (sizeof (int) * FeatureList->FeatureCount);
151 for (i = 0; i < FeatureList->FeatureCount; i++)
152 feature_table[i] = 0;
160 if (*features == '*')
162 /* Consume all remaining features. */
163 for (i = 0; i < FeatureList->FeatureCount; i++)
164 if (! feature_table[i])
166 feature = FeatureList->Feature + i;
167 for (j = 0; j < feature->LookupCount; j++)
168 lookup_indices[n++] = feature->LookupListIndex[j];
173 if (*features == '~')
174 negate = 1, features++;
175 for (i = 0; *features && *features != ','; i++, features++)
176 tagname[i] = *features;
182 tag = OTF_tag (tagname);
183 for (i = 0; i < FeatureList->FeatureCount; i++)
185 feature = FeatureList->Feature + i;
186 if (tag == feature->FeatureTag)
189 for (j = 0; j < feature->LookupCount; j++)
190 lookup_indices[n++] = feature->LookupListIndex[j];
191 feature_table[i] = 1;
201 match_ids (OTF_GlyphString *gstring, int gidx, int count, OTF_GlyphID *ids)
203 OTF_Glyph *gbeg = gstring->glyphs + gidx;
204 OTF_Glyph *gend = gstring->glyphs + gstring->used;
208 for (g = gbeg, i = 0; g < gend && i < count; g++)
209 if (g->glyph_id && g->glyph_id != ids[i++])
211 return (i < count ? -1 : g - gbeg);
215 match_chain_ids (OTF_GlyphString *gstring, int gidx, OTF_ChainRule *rule)
219 for (i = rule->BacktrackGlyphCount, j = gidx - 1; j >= 0 && i > 0; j--)
220 if (gstring->glyphs[j].glyph_id)
225 i = match_ids (gstring, j, rule->BacktrackGlyphCount, rule->Backtrack);
229 i = match_ids (gstring, gidx, rule->InputGlyphCount - 1, rule->Input);
233 i = match_ids (gstring, gidx, rule->LookaheadGlyphCount, rule->LookAhead);
240 match_classes (OTF_ClassDef *class_def, OTF_GlyphString *gstring, int gidx,
241 int count, unsigned *classes)
243 OTF_Glyph *gbeg = gstring->glyphs + gidx;
244 OTF_Glyph *gend = gstring->glyphs + gstring->used;
248 for (g = gbeg, i = 0; g < gend && i < count; g++)
250 && get_class_def (class_def, g->glyph_id) != classes[i++])
252 return (i < count ? -1 : g - gbeg);
256 match_chain_classes (OTF_GlyphString *gstring, int gidx,
257 OTF_ClassDef *BacktrackClassDef,
258 OTF_ClassDef *InputClassDef,
259 OTF_ClassDef *LookaheadClassDef,
260 OTF_ChainClassRule *rule)
264 for (i = rule->BacktrackGlyphCount, j = gidx - 1; j >= 0 && i > 0; j--)
265 if (gstring->glyphs[j].glyph_id)
270 i = match_classes (BacktrackClassDef, gstring, j,
271 rule->BacktrackGlyphCount, rule->Backtrack);
275 i = match_classes (InputClassDef, gstring, gidx,
276 rule->InputGlyphCount - 1, rule->Input);
280 i = match_classes (LookaheadClassDef, gstring, gidx,
281 rule->LookaheadGlyphCount, rule->LookAhead);
289 match_coverages (OTF_GlyphString *gstring, int gidx, int count,
290 OTF_Coverage *coverages)
292 OTF_Glyph *gbeg = gstring->glyphs + gidx;
293 OTF_Glyph *gend = gstring->glyphs + gstring->used;
297 for (g = gbeg, i = 0; g < gend && i < count; g++)
299 && get_coverage_index (coverages + i, g->glyph_id) < 0)
301 return (i < count ? -1 : g - gbeg);
305 match_chain_coverages (OTF_GlyphString *gstring, int gidx,
306 OTF_GSUB_ChainContext3 *context3)
310 if (gidx < context3->BacktrackGlyphCount
311 || (gidx + context3->InputGlyphCount
312 + context3->LookaheadGlyphCount) >= gstring->used)
315 for (i = context3->BacktrackGlyphCount, j = gidx - 1; j >= 0 && i > 0; j--)
316 if (gstring->glyphs[j].glyph_id)
321 i = match_coverages (gstring, j, context3->BacktrackGlyphCount,
322 context3->Backtrack);
326 i = match_coverages (gstring, gidx, context3->InputGlyphCount - 1,
327 context3->Input + 1);
331 i = match_coverages (gstring, gidx, context3->LookaheadGlyphCount,
332 context3->LookAhead);
339 lookup_gsub (OTF_LookupList *lookup_list, unsigned lookup_list_index,
340 OTF_GlyphString *gstring, int gidx)
342 char *errfmt = "GSUB Looking up%s";
344 OTF_Lookup *lookup = lookup_list->Lookup + lookup_list_index;
345 unsigned int flag = lookup->LookupFlag;
346 int orig_gidx = gidx;
347 OTF_Glyph *g = gstring->glyphs + gidx;
352 && (flag & (1 << g->GlyphClass))))
355 /* Try all subtables until one of them handles the current glyph. */
356 for (i = 0; i < lookup->SubTableCount && gidx == orig_gidx; i++)
358 unsigned lookup_type = lookup->LookupType;
359 OTF_LookupSubTableGSUB *subtable = lookup->SubTable.gsub + i;
362 if (lookup_type == 7)
364 OTF_GSUB_Extension1 *extension1 = &subtable->u.extension1;
366 lookup_type = extension1->ExtensionLookupType;
367 subtable = extension1->ExtensionSubtable;
370 if (subtable->Coverage.offset)
372 coverage_idx = get_coverage_index (&subtable->Coverage,
374 if (coverage_idx < 0)
378 switch (lookup->LookupType)
381 if (subtable->Format == 1)
382 g->glyph_id += subtable->u.single1.DeltaGlyphID;
384 g->glyph_id = subtable->u.single2.Substitute[coverage_idx];
390 OTF_GSUB_Multiple1 *multiple1 = &subtable->u.multiple1;
391 OTF_Sequence *seq = multiple1->Sequence + coverage_idx;
393 gstring_subst (gstring, gidx, gidx + 1,
394 seq->Substitute, seq->GlyphCount);
395 gidx += seq->GlyphCount;
400 if (subtable->Format == 1)
402 OTF_GSUB_Alternate1 *alt1 = &subtable->u.alternate1;
403 OTF_AlternateSet *altset = alt1->AlternateSet + coverage_idx;
405 g->glyph_id = altset->Alternate[0];
409 OTF_ERROR (OTF_ERROR_GSUB_DRIVE, " (invalid SubFormat)");
413 if (subtable->Format == 1)
415 OTF_GSUB_Ligature1 *lig1 = &subtable->u.ligature1;
416 OTF_LigatureSet *ligset = lig1->LigatureSet + coverage_idx;
420 for (j = 0; j < ligset->LigatureCount; j++)
424 lig = ligset->Ligature + j;
425 n = match_ids (gstring, gidx + 1,
426 lig->CompCount - 1, lig->Component);
429 gstring_subst (gstring, gidx, gidx + 1 + n,
436 OTF_ERROR (OTF_ERROR_GSUB_DRIVE, " (invalid SubFormat)");
440 if (subtable->Format == 1)
442 OTF_GSUB_Context1 *context1 = &subtable->u.context1;
443 OTF_RuleSet *set = context1->RuleSet + coverage_idx;
448 for (j = 0; j < set->RuleCount; j++)
450 rule = set->Rule + j;
451 if (match_ids (gstring, gidx + 1,
452 rule->GlyphCount - 1, rule->Input) < 0)
454 orig_used = gstring->used;
455 for (k = 0; k < rule->LookupCount; k++)
456 lookup_gsub (lookup_list,
457 rule->LookupRecord[k].LookupListIndex,
459 gidx + rule->LookupRecord[k].SequenceIndex);
460 gidx += rule->GlyphCount + (gstring->used - orig_used);
464 else if (subtable->Format == 2)
466 OTF_GSUB_Context2 *context2 = &subtable->u.context2;
473 class = get_class_def (&context2->ClassDef, g->glyph_id);
474 set = context2->ClassSet + class;
475 for (j = 0; j < set->ClassRuleCnt; j++)
477 rule = set->ClassRule + j;
478 if (match_classes (&context2->ClassDef,
480 rule->GlyphCount - 1, rule->Class)
483 orig_used = gstring->used;
484 for (k = 0; k < rule->LookupCount; k++)
485 lookup_gsub (lookup_list,
486 rule->LookupRecord[k].LookupListIndex,
488 gidx + rule->LookupRecord[k].SequenceIndex);
489 gidx += rule->GlyphCount + (gstring->used - orig_used);
493 else /* subtable->Format == 3 */
495 OTF_GSUB_Context3 *context3 = &subtable->u.context3;
499 if (match_coverages (gstring, gidx + 1, context3->GlyphCount - 1,
500 context3->Coverage + 1) < 0)
502 orig_used = gstring->used;
503 for (j = 0; j < context3->LookupCount; j++)
504 lookup_gsub (lookup_list,
505 context3->LookupRecord[j].LookupListIndex,
507 gidx + context3->LookupRecord[j].SequenceIndex);
508 gidx += context3->GlyphCount + (gstring->used - orig_used);
513 if (subtable->Format == 1)
515 OTF_GSUB_ChainContext1 *context1 = &subtable->u.chain_context1;
516 OTF_ChainRuleSet *set = context1->ChainRuleSet + coverage_idx;
520 for (j = 0; j < set->ChainRuleCount; j++)
522 OTF_ChainRule *rule = set->ChainRule + j;
524 if (gidx < rule->BacktrackGlyphCount
525 || (gidx + rule->InputGlyphCount
526 + rule->LookaheadGlyphCount) >= gstring->used)
528 if (match_chain_ids (gstring, gidx, rule) < 0)
530 orig_used = gstring->used;
531 for (k = 0; k < rule->LookupCount; k++)
532 lookup_gsub (lookup_list,
533 rule->LookupRecord[k].LookupListIndex,
535 gidx + rule->LookupRecord[k].SequenceIndex);
536 gidx += rule->InputGlyphCount + (gstring->used - orig_used);
540 else if (subtable->Format == 2)
542 OTF_GSUB_ChainContext2 *context2 = &subtable->u.chain_context2;
543 OTF_ChainClassSet *set;
548 // printf ("GSUB 6-2: c:0x%x g:0x%x\n", g->c, g->glyph_id);
549 class = get_class_def (&context2->InputClassDef, g->glyph_id);
550 set = context2->ChainClassSet + class;
551 for (j = 0; j < set->ChainClassRuleCnt; j++)
553 OTF_ChainClassRule *rule = set->ChainClassRule + j;
556 if (gidx < rule->BacktrackGlyphCount
557 || (gidx + rule->InputGlyphCount
558 + rule->LookaheadGlyphCount) >= gstring->used)
560 if (match_chain_classes (gstring, gidx,
561 &context2->BacktrackClassDef,
562 &context2->InputClassDef,
563 &context2->LookaheadClassDef,
566 orig_used = gstring->used;
567 for (k = 0; k < rule->LookupCount; k++)
568 lookup_gsub (lookup_list,
569 rule->LookupRecord[k].LookupListIndex,
571 gidx + rule->LookupRecord[k].SequenceIndex);
572 gidx += rule->InputGlyphCount + (gstring->used - orig_used);
578 OTF_GSUB_ChainContext3 *context3 = &subtable->u.chain_context3;
582 if (match_chain_coverages (gstring, gidx, context3) < 0)
584 orig_used = gstring->used;
585 for (j = 0; j < context3->LookupCount; j++)
586 lookup_gsub (lookup_list,
587 context3->LookupRecord[j].LookupListIndex,
589 gidx + context3->LookupRecord[j].SequenceIndex);
590 gidx += context3->InputGlyphCount + (gstring->used - orig_used);
596 OTF_GSUB_ReverseChain1 *reverse = &subtable->u.reverse_chain1;
597 int back_gidx = gidx + 1 + reverse->BacktrackGlyphCount;
598 int ahead_gidx = gidx - reverse->LookaheadGlyphCount;
601 if (back_gidx > gstring->used || ahead_gidx < 0)
604 for (j = 0; j < reverse->BacktrackGlyphCount; j++)
605 if (get_coverage_index (reverse->Backtrack + j,
606 gstring->glyphs[gidx + 1 + j].glyph_id)
609 if (j < reverse->BacktrackGlyphCount)
611 for (j = 0; j < reverse->LookaheadGlyphCount; j++)
612 if (get_coverage_index (reverse->LookAhead + j,
613 gstring->glyphs[gidx - 1 - j].glyph_id)
616 if (j < reverse->LookaheadGlyphCount)
618 g->glyph_id = reverse->Substitute[coverage_idx];
626 if (gidx == orig_gidx)
628 //printf ("not applied\n");
633 // printf ("done\n");
642 get_anchor (OTF_Anchor *anchor, OTF_ValueRecord *rec)
644 unsigned value_format = OTF_XPlacement | OTF_YPlacement;
646 rec->XPlacement = anchor->XCoordinate;
647 rec->YPlacement = anchor->YCoordinate;
648 if (anchor->AnchorFormat == 1)
651 else if (anchor->AnchorFormat == 2)
652 /* Not yet implemented */
654 else if (anchor->AnchorFormat == 3)
655 /* Not yet implemented */
662 lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
663 OTF_GlyphString *gstring, int gidx)
665 char *errfmt = "GPOS Looking up%s";
667 OTF_Lookup *lookup = lookup_list->Lookup + lookup_list_index;
668 unsigned int flag = lookup->LookupFlag;
669 int orig_gidx = gidx;
670 OTF_Glyph *g = gstring->glyphs + gidx;
675 && (flag & (1 << g->GlyphClass))))
678 /* Try all subtables until one of them handles the current glyph. */
679 for (i = 0; i < lookup->SubTableCount && gidx == orig_gidx; i++)
681 OTF_LookupSubTableGPOS *subtable = lookup->SubTable.gpos + i;
684 // printf ("subtype:%d ", subtable->Format);
685 if (subtable->Coverage.offset)
687 coverage_idx = get_coverage_index (&subtable->Coverage,
689 if (coverage_idx < 0)
691 // printf ("not covererd ");
696 switch (lookup->LookupType)
699 g->positioning_type = lookup->LookupType;
700 if (subtable->Format == 1)
702 OTF_GPOS_Single1 *single1 = &subtable->u.single1;
704 g->f.f1.format = single1->ValueFormat;
705 g->f.f1.value = &single1->Value;
707 else if (subtable->Format == 2)
709 OTF_GPOS_Single2 *single2 = &subtable->u.single2;
711 g->f.f1.format = single2->ValueFormat;
712 g->f.f1.value = single2->Value + coverage_idx;
717 if (gidx + 1 >= gstring->used)
719 if (subtable->Format == 1)
721 OTF_GPOS_Pair1 *pair1 = &subtable->u.pair1;
722 OTF_PairSet *set = pair1->PairSet + coverage_idx;
725 for (j = 0; j < set->PairValueCount; j++)
727 if (set->PairValueRecord[j].SecondGlyph != g[1].glyph_id)
730 g->positioning_type = lookup->LookupType;
731 g->f.f2.format = pair1->ValueFormat1;
732 g->f.f2.value = &set->PairValueRecord[j].Value1;
733 if (pair1->ValueFormat2)
736 g->positioning_type = lookup->LookupType;
737 g->f.f2.format = pair1->ValueFormat2;
738 g->f.f2.value = &set->PairValueRecord[j].Value2;
742 else if (subtable->Format == 2)
744 OTF_GPOS_Pair2 *pair2 = &subtable->u.pair2;
745 unsigned class1, class2;
747 // printf ("GPOS 2-2: c:0x%x g:0x%x\n", g->c, g->glyph_id);
749 class1 = get_class_def (&pair2->ClassDef1, g->glyph_id);
750 class2 = get_class_def (&pair2->ClassDef2, g[1].glyph_id);
751 g->positioning_type = lookup->LookupType;
752 g->f.f2.format = pair2->ValueFormat1;
754 = &pair2->Class1Record[class1].Class2Record[class2].Value1;
755 if (pair2->ValueFormat2)
758 g->positioning_type = lookup->LookupType;
759 g->f.f2.format = pair2->ValueFormat2;
761 = &pair2->Class1Record[class1].Class2Record[class2].Value2;
768 OTF_GPOS_Cursive1 *cursive1 = &subtable->u.cursive1;
770 g->positioning_type = lookup->LookupType;
772 = &cursive1->EntryExitRecord[coverage_idx].EntryAnchor;
774 = &cursive1->EntryExitRecord[coverage_idx].ExitAnchor;
781 if (subtable->Format == 1)
783 OTF_GPOS_MarkBase1 *mark_base1 = &subtable->u.mark_base1;
784 OTF_MarkRecord *mark_record;
785 OTF_AnchorRecord *base_record;
786 int coverage_idx_base
787 = get_coverage_index (&mark_base1->BaseCoverage,
790 if (coverage_idx_base < 0)
792 // printf ("GPOS 4-1: c:0x%x g:0x%x\n", g->c, g->glyph_id);
793 mark_record = mark_base1->MarkArray.MarkRecord + coverage_idx;
795 = mark_base1->BaseArray.AnchorRecord + coverage_idx_base;
796 g->f.f4.mark_anchor = &mark_record->MarkAnchor;
798 = &base_record->Anchor[mark_record->Class];
799 g->positioning_type = lookup->LookupType;
807 if (subtable->Format == 1)
809 /* As the document of this lookup type is quite
810 ambiguous, and we can't know the exact procedure to
812 OTF_ERROR (OTF_ERROR_GPOS_DRIVE, " (not yet supported)");
819 if (subtable->Format == 1)
821 OTF_GPOS_MarkMark1 *mark_mark1 = &subtable->u.mark_mark1;
822 OTF_MarkRecord *mark1_record;
823 OTF_AnchorRecord *mark2_record;
824 int coverage_idx_base
825 = get_coverage_index (&mark_mark1->Mark2Coverage,
828 if (coverage_idx_base < 0)
830 // printf ("GPOS 6-1: c:0x%x g:0x%x\n", g->c, g->glyph_id);
831 mark1_record = mark_mark1->Mark1Array.MarkRecord + coverage_idx;
833 = mark_mark1->Mark2Array.AnchorRecord + coverage_idx_base;
834 g->f.f6.mark1_anchor = &mark1_record->MarkAnchor;
836 = &mark2_record->Anchor[mark1_record->Class];
837 g->positioning_type = lookup->LookupType;
843 OTF_ERROR (OTF_ERROR_GPOS_DRIVE, " (not yet supported)");
847 if (subtable->Format == 1)
848 OTF_ERROR (OTF_ERROR_GPOS_DRIVE, " (not yet supported)");
849 else if (subtable->Format == 2)
851 OTF_GPOS_ChainContext2 *context2 = &subtable->u.chain_context2;
852 OTF_ChainClassSet *set;
857 // printf ("GPOS 8-2: c:0x%x g:0x%x\n", g->c, g->glyph_id);
858 class = get_class_def (&context2->InputClassDef, g->glyph_id);
859 set = context2->ChainClassSet + class;
860 for (j = 0; j < set->ChainClassRuleCnt; j++)
862 OTF_ChainClassRule *rule = set->ChainClassRule + j;
863 int fore_idx = gidx + rule->InputGlyphCount;
866 if (gidx < rule->BacktrackGlyphCount
867 || (gidx + rule->InputGlyphCount
868 + rule->LookaheadGlyphCount) >= gstring->used)
870 for (k = 0; k < rule->BacktrackGlyphCount; k++)
871 if (get_class_def (&context2->BacktrackClassDef,
872 gstring->glyphs[gidx - 1 - k].glyph_id)
873 != rule->Backtrack[k])
875 if (k < rule->BacktrackGlyphCount)
877 for (k = 1; k < rule->InputGlyphCount; k++)
878 if (get_class_def (&context2->InputClassDef,
879 gstring->glyphs[gidx + k].glyph_id)
880 != rule->Input[k - 1])
882 if (k < rule->InputGlyphCount)
884 for (k = 0; k < rule->LookaheadGlyphCount; k++)
885 if (get_class_def (&context2->LookaheadClassDef,
886 gstring->glyphs[fore_idx + k].glyph_id)
887 != rule->LookAhead[k])
889 if (k < rule->LookaheadGlyphCount)
892 orig_used = gstring->used;
893 for (k = 0; k < rule->LookupCount; k++)
894 lookup_gpos (lookup_list,
895 rule->LookupRecord[k].LookupListIndex,
897 gidx + rule->LookupRecord[k].SequenceIndex);
898 gidx += rule->InputGlyphCount + (gstring->used - orig_used);
902 else if (subtable->Format == 3)
903 OTF_ERROR (OTF_ERROR_GPOS_DRIVE, " (not yet supported)");
905 OTF_ERROR (OTF_ERROR_GPOS_DRIVE, " (invalid subformat)");
909 OTF_ERROR (OTF_ERROR_GPOS_DRIVE, " (not yet supported)");
916 if (gidx == orig_gidx)
918 // printf ("not applied\n");
923 // printf ("done\n");
933 OTF_drive_cmap (OTF *otf, OTF_GlyphString *gstring)
939 && OTF_get_table (otf, "cmap") < 0)
943 for (i = 0; i < gstring->used; i++)
944 if (! gstring->glyphs[i].glyph_id)
946 int c = gstring->glyphs[i].c;
947 if (c < 32 || ! cmap->unicode_table)
948 gstring->glyphs[i].glyph_id = 0;
950 gstring->glyphs[i].glyph_id = cmap->unicode_table[c];
956 OTF_get_unicode (OTF *otf, OTF_GlyphID code)
959 && OTF_get_table (otf, "cmap") < 0)
962 || code > otf->cmap->max_glyph_id
963 || ! otf->cmap->decode_table)
965 return otf->cmap->decode_table[code];
969 OTF_drive_gdef (OTF *otf, OTF_GlyphString *gstring)
975 && OTF_get_table (otf, "GDEF") < 0)
979 if (gdef->glyph_class_def.offset)
980 for (i = 0; i < gstring->used; i++)
981 gstring->glyphs[i].GlyphClass
982 = get_class_def (&gdef->glyph_class_def,
983 gstring->glyphs[i].glyph_id);
985 if (gdef->mark_attach_class_def.offset)
986 for (i = 0; i < gstring->used; i++)
987 gstring->glyphs[i].MarkAttachClass
988 = get_class_def (&gdef->mark_attach_class_def,
989 gstring->glyphs[i].glyph_id);
996 OTF_drive_gsub (OTF *otf, OTF_GlyphString *gstring,
997 char *script, char *language, char *features)
999 char *errfmt = "GSUB driving%s";
1002 OTF_LangSys *LangSys;
1003 int *lookup_indices;
1007 && OTF_get_table (otf, "GSUB") < 0)
1010 if (gsub->FeatureList.FeatureCount == 0
1011 || gsub->LookupList.LookupCount == 0)
1014 LangSys = get_langsys (&gsub->ScriptList, script, language);
1018 /* One lookup may be used by multiple features. */
1019 lookup_indices = alloca (sizeof (int)
1020 * gsub->LookupList.LookupCount
1021 * gsub->FeatureList.FeatureCount);
1022 if (! lookup_indices)
1023 OTF_ERROR (OTF_ERROR_MEMORY, " feature list");
1024 n = setup_lookup_indices (LangSys, &gsub->FeatureList,
1025 features, lookup_indices);
1029 for (i = 0; i < n; i++)
1031 int index = lookup_indices[i];
1034 if (gsub->LookupList.Lookup[index].LookupType != 8)
1037 while (gidx < gstring->used)
1039 gidx = lookup_gsub (&gsub->LookupList, index, gstring, gidx);
1046 gidx = gstring->used - 1;
1049 gidx = lookup_gsub (&gsub->LookupList, index, gstring, gidx);
1060 OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
1061 char *script, char *language, char *features)
1063 char *errfmt = "GPOS driving%s";
1066 OTF_LangSys *LangSys;
1067 int *lookup_indices;
1071 && OTF_get_table (otf, "GPOS") < 0)
1074 if (gpos->FeatureList.FeatureCount == 0
1075 || gpos->LookupList.LookupCount == 0)
1078 LangSys = get_langsys (&gpos->ScriptList, script, language);
1082 /* One lookup may be used by multiple features. */
1083 lookup_indices = alloca (sizeof (int)
1084 * gpos->LookupList.LookupCount
1085 * gpos->FeatureList.FeatureCount);
1086 if (! lookup_indices)
1087 OTF_ERROR (OTF_ERROR_MEMORY, " feature list");
1088 n = setup_lookup_indices (LangSys, &gpos->FeatureList,
1089 features, lookup_indices);
1093 for (i = 0; i < n; i++)
1095 int index = lookup_indices[i];
1098 while (gidx < gstring->used)
1100 gidx = lookup_gpos (&gpos->LookupList, index, gstring, gidx);
1110 OTF_drive_tables (OTF *otf, OTF_GlyphString *gstring,
1111 char *script, char *language,
1112 char *gsub_features, char *gpos_features)
1114 if (OTF_drive_cmap (otf, gstring) < 0)
1116 if (OTF_drive_gdef (otf, gstring) < 0)
1119 && OTF_drive_gsub (otf, gstring, script, language, gsub_features) < 0)
1122 && OTF_drive_gpos (otf, gstring, script, language, gpos_features) < 0)