2 * Opentype font interfaces for the Uniscribe Script Processor (usp10.dll)
4 * Copyright 2012 CodeWeavers, Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "usp10_internal.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
38 #ifdef WORDS_BIGENDIAN
39 #define GET_BE_WORD(x) (x)
40 #define GET_BE_DWORD(x) (x)
42 #define GET_BE_WORD(x) RtlUshortByteSwap(x)
43 #define GET_BE_DWORD(x) RtlUlongByteSwap(x)
46 #define round(x) (((x) < 0) ? (int)((x) - 0.5) : (int)((x) + 0.5))
48 /* These are all structures needed for the cmap format 12 table */
49 #define CMAP_TAG MS_MAKE_TAG('c', 'm', 'a', 'p')
55 } CMAP_EncodingRecord;
60 CMAP_EncodingRecord tables[1];
67 } CMAP_SegmentedCoverage_group;
75 CMAP_SegmentedCoverage_group groups[1];
76 } CMAP_SegmentedCoverage;
78 /* These are all structures needed for the GDEF table */
79 #define GDEF_TAG MS_MAKE_TAG('G', 'D', 'E', 'F')
81 enum {BaseGlyph=1, LigatureGlyph, MarkGlyph, ComponentGlyph};
88 WORD MarkAttachClassDef;
95 WORD ClassValueArray[1];
102 } OT_ClassRangeRecord;
106 WORD ClassRangeCount;
107 OT_ClassRangeRecord ClassRangeRecord[1];
108 } OT_ClassDefFormat2;
110 /* These are all structures needed for the GSUB table */
126 OT_ScriptRecord ScriptRecord[1];
137 OT_LangSysRecord LangSysRecord[1];
141 WORD LookupOrder; /* Reserved */
142 WORD ReqFeatureIndex;
144 WORD FeatureIndex[1];
154 OT_FeatureRecord FeatureRecord[1];
158 WORD FeatureParams; /* Reserved */
160 WORD LookupListIndex[1];
179 } OT_CoverageFormat1;
184 WORD StartCoverageIndex;
190 OT_RangeRecord RangeRecord[1];
191 } OT_CoverageFormat2;
194 WORD SubstFormat; /* = 1 */
197 } GSUB_SingleSubstFormat1;
200 WORD SubstFormat; /* = 2 */
204 }GSUB_SingleSubstFormat2;
207 WORD SubstFormat; /* = 1 */
211 }GSUB_MultipleSubstFormat1;
219 WORD SubstFormat; /* = 1 */
223 }GSUB_LigatureSubstFormat1;
238 WORD LookupListIndex;
240 }GSUB_SubstLookupRecord;
243 WORD SubstFormat; /* = 1 */
245 WORD ChainSubRuleSetCount;
246 WORD ChainSubRuleSet[1];
247 }GSUB_ChainContextSubstFormat1;
250 WORD SubstFormat; /* = 3 */
251 WORD BacktrackGlyphCount;
253 }GSUB_ChainContextSubstFormat3_1;
256 WORD InputGlyphCount;
258 }GSUB_ChainContextSubstFormat3_2;
261 WORD LookaheadGlyphCount;
263 }GSUB_ChainContextSubstFormat3_3;
267 GSUB_SubstLookupRecord SubstLookupRecord[1];
268 }GSUB_ChainContextSubstFormat3_4;
271 WORD SubstFormat; /* = 1 */
273 WORD AlternateSetCount;
274 WORD AlternateSet[1];
275 } GSUB_AlternateSubstFormat1;
282 /* These are all structures needed for the GPOS table */
302 } GPOS_AnchorFormat1;
309 } GPOS_AnchorFormat2;
317 } GPOS_AnchorFormat3;
335 } GPOS_SinglePosFormat1;
343 } GPOS_SinglePosFormat2;
351 WORD PairSetOffset[1];
352 } GPOS_PairPosFormat1;
363 WORD Class1Record[1];
364 } GPOS_PairPosFormat2;
370 } GPOS_PairValueRecord;
374 GPOS_PairValueRecord PairValueRecord[1];
384 } GPOS_MarkBasePosFormat1;
392 GPOS_BaseRecord BaseRecord[1];
402 GPOS_MarkRecord MarkRecord[1];
412 } GPOS_MarkMarkPosFormat1;
420 GPOS_Mark2Record Mark2Record[1];
425 WORD LookupListIndex;
426 } GPOS_PosLookupRecord;
430 WORD BacktrackGlyphCount;
432 } GPOS_ChainContextPosFormat3_1;
435 WORD InputGlyphCount;
437 } GPOS_ChainContextPosFormat3_2;
440 WORD LookaheadGlyphCount;
442 } GPOS_ChainContextPosFormat3_3;
446 GPOS_PosLookupRecord PosLookupRecord[1];
447 } GPOS_ChainContextPosFormat3_4;
453 static VOID *load_CMAP_format12_table(HDC hdc, ScriptCache *psc)
455 CMAP_Header *CMAP_Table = NULL;
459 if (!psc->CMAP_Table)
461 length = GetFontData(hdc, CMAP_TAG , 0, NULL, 0);
462 if (length != GDI_ERROR)
464 psc->CMAP_Table = HeapAlloc(GetProcessHeap(),0,length);
465 GetFontData(hdc, CMAP_TAG , 0, psc->CMAP_Table, length);
466 TRACE("Loaded cmap table of %i bytes\n",length);
472 CMAP_Table = psc->CMAP_Table;
474 for (i = 0; i < GET_BE_WORD(CMAP_Table->numTables); i++)
476 if ( (GET_BE_WORD(CMAP_Table->tables[i].platformID) == 3) &&
477 (GET_BE_WORD(CMAP_Table->tables[i].encodingID) == 10) )
479 CMAP_SegmentedCoverage *format = (CMAP_SegmentedCoverage*)(((BYTE*)CMAP_Table) + GET_BE_DWORD(CMAP_Table->tables[i].offset));
480 if (GET_BE_WORD(format->format) == 12)
487 static int compare_group(const void *a, const void* b)
489 const DWORD *chr = a;
490 const CMAP_SegmentedCoverage_group *group = b;
492 if (*chr < GET_BE_DWORD(group->startCharCode))
494 if (*chr > GET_BE_DWORD(group->endCharCode))
499 DWORD OpenType_CMAP_GetGlyphIndex(HDC hdc, ScriptCache *psc, DWORD utf32c, LPWORD pgi, DWORD flags)
501 /* BMP: use gdi32 for ease */
502 if (utf32c < 0x10000)
505 return GetGlyphIndicesW(hdc,&ch, 1, pgi, flags);
508 if (!psc->CMAP_format12_Table)
509 psc->CMAP_format12_Table = load_CMAP_format12_table(hdc, psc);
511 if (flags & GGI_MARK_NONEXISTING_GLYPHS)
516 if (psc->CMAP_format12_Table)
518 CMAP_SegmentedCoverage *format = NULL;
519 CMAP_SegmentedCoverage_group *group = NULL;
521 format = (CMAP_SegmentedCoverage *)psc->CMAP_format12_Table;
523 group = bsearch(&utf32c, format->groups, GET_BE_DWORD(format->nGroups),
524 sizeof(CMAP_SegmentedCoverage_group), compare_group);
528 DWORD offset = utf32c - GET_BE_DWORD(group->startCharCode);
529 *pgi = GET_BE_DWORD(group->startGlyphID) + offset;
540 static WORD OT_get_glyph_class(const void *table, WORD glyph)
543 const OT_ClassDefFormat1 *cf1 = table;
545 if (!table) return 0;
547 if (GET_BE_WORD(cf1->ClassFormat) == 1)
549 if (glyph >= GET_BE_WORD(cf1->StartGlyph))
551 int index = glyph - GET_BE_WORD(cf1->StartGlyph);
552 if (index < GET_BE_WORD(cf1->GlyphCount))
553 class = GET_BE_WORD(cf1->ClassValueArray[index]);
556 else if (GET_BE_WORD(cf1->ClassFormat) == 2)
558 const OT_ClassDefFormat2 *cf2 = table;
560 top = GET_BE_WORD(cf2->ClassRangeCount);
561 for (i = 0; i < top; i++)
563 if (glyph >= GET_BE_WORD(cf2->ClassRangeRecord[i].Start) &&
564 glyph <= GET_BE_WORD(cf2->ClassRangeRecord[i].End))
566 class = GET_BE_WORD(cf2->ClassRangeRecord[i].Class);
572 ERR("Unknown Class Format %i\n",GET_BE_WORD(cf1->ClassFormat));
577 static VOID *load_gdef_table(HDC hdc)
579 VOID* GDEF_Table = NULL;
580 int length = GetFontData(hdc, GDEF_TAG , 0, NULL, 0);
581 if (length != GDI_ERROR)
583 GDEF_Table = HeapAlloc(GetProcessHeap(),0,length);
584 GetFontData(hdc, GDEF_TAG , 0, GDEF_Table, length);
585 TRACE("Loaded GDEF table of %i bytes\n",length);
590 void OpenType_GDEF_UpdateGlyphProps(HDC hdc, ScriptCache *psc, const WORD *pwGlyphs, const WORD cGlyphs, WORD* pwLogClust, const WORD cChars, SCRIPT_GLYPHPROP *pGlyphProp)
593 void *glyph_class_table = NULL;
595 if (!psc->GDEF_Table)
596 psc->GDEF_Table = load_gdef_table(hdc);
600 const GDEF_Header *header = psc->GDEF_Table;
601 WORD offset = GET_BE_WORD( header->GlyphClassDef );
603 glyph_class_table = (BYTE *)psc->GDEF_Table + offset;
606 for (i = 0; i < cGlyphs; i++)
612 k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
615 for (; k < cChars && pwLogClust[k] == i; k++)
619 class = OT_get_glyph_class( glyph_class_table, pwGlyphs[i] );
625 pGlyphProp[i].sva.fClusterStart = 1;
626 pGlyphProp[i].sva.fDiacritic = 0;
627 pGlyphProp[i].sva.fZeroWidth = 0;
630 pGlyphProp[i].sva.fClusterStart = 1;
631 pGlyphProp[i].sva.fDiacritic = 0;
632 pGlyphProp[i].sva.fZeroWidth = 0;
635 pGlyphProp[i].sva.fClusterStart = 0;
636 pGlyphProp[i].sva.fDiacritic = 1;
637 pGlyphProp[i].sva.fZeroWidth = 1;
640 pGlyphProp[i].sva.fClusterStart = 0;
641 pGlyphProp[i].sva.fDiacritic = 0;
642 pGlyphProp[i].sva.fZeroWidth = 0;
645 ERR("Unknown glyph class %i\n",class);
646 pGlyphProp[i].sva.fClusterStart = 1;
647 pGlyphProp[i].sva.fDiacritic = 0;
648 pGlyphProp[i].sva.fZeroWidth = 0;
652 pGlyphProp[i].sva.fClusterStart = 0;
659 static INT GSUB_apply_lookup(const OT_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count);
661 static INT GSUB_is_glyph_covered(LPCVOID table , UINT glyph)
663 const OT_CoverageFormat1* cf1;
667 if (GET_BE_WORD(cf1->CoverageFormat) == 1)
669 int count = GET_BE_WORD(cf1->GlyphCount);
671 TRACE("Coverage Format 1, %i glyphs\n",count);
672 for (i = 0; i < count; i++)
673 if (glyph == GET_BE_WORD(cf1->GlyphArray[i]))
677 else if (GET_BE_WORD(cf1->CoverageFormat) == 2)
679 const OT_CoverageFormat2* cf2;
682 cf2 = (const OT_CoverageFormat2*)cf1;
684 count = GET_BE_WORD(cf2->RangeCount);
685 TRACE("Coverage Format 2, %i ranges\n",count);
686 for (i = 0; i < count; i++)
688 if (glyph < GET_BE_WORD(cf2->RangeRecord[i].Start))
690 if ((glyph >= GET_BE_WORD(cf2->RangeRecord[i].Start)) &&
691 (glyph <= GET_BE_WORD(cf2->RangeRecord[i].End)))
693 return (GET_BE_WORD(cf2->RangeRecord[i].StartCoverageIndex) +
694 glyph - GET_BE_WORD(cf2->RangeRecord[i].Start));
700 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1->CoverageFormat));
705 static INT GSUB_apply_SingleSubst(const OT_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
708 TRACE("Single Substitution Subtable\n");
710 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
713 const GSUB_SingleSubstFormat1 *ssf1;
714 offset = GET_BE_WORD(look->SubTable[j]);
715 ssf1 = (const GSUB_SingleSubstFormat1*)((const BYTE*)look+offset);
716 if (GET_BE_WORD(ssf1->SubstFormat) == 1)
718 int offset = GET_BE_WORD(ssf1->Coverage);
719 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1->DeltaGlyphID));
720 if (GSUB_is_glyph_covered((const BYTE*)ssf1+offset, glyphs[glyph_index]) != -1)
722 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
723 glyphs[glyph_index] = glyphs[glyph_index] + GET_BE_WORD(ssf1->DeltaGlyphID);
724 TRACE(" 0x%x\n",glyphs[glyph_index]);
725 return glyph_index + write_dir;
730 const GSUB_SingleSubstFormat2 *ssf2;
734 ssf2 = (const GSUB_SingleSubstFormat2 *)ssf1;
735 offset = GET_BE_WORD(ssf1->Coverage);
736 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2->GlyphCount));
737 index = GSUB_is_glyph_covered((const BYTE*)ssf2+offset, glyphs[glyph_index]);
738 TRACE(" Coverage index %i\n",index);
741 if (glyphs[glyph_index] == GET_BE_WORD(ssf2->Substitute[index]))
742 return GSUB_E_NOGLYPH;
744 TRACE(" Glyph is 0x%x ->",glyphs[glyph_index]);
745 glyphs[glyph_index] = GET_BE_WORD(ssf2->Substitute[index]);
746 TRACE("0x%x\n",glyphs[glyph_index]);
747 return glyph_index + write_dir;
751 return GSUB_E_NOGLYPH;
754 static INT GSUB_apply_MultipleSubst(const OT_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
757 TRACE("Multiple Substitution Subtable\n");
759 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
762 const GSUB_MultipleSubstFormat1 *msf1;
763 offset = GET_BE_WORD(look->SubTable[j]);
764 msf1 = (const GSUB_MultipleSubstFormat1*)((const BYTE*)look+offset);
766 offset = GET_BE_WORD(msf1->Coverage);
767 index = GSUB_is_glyph_covered((const BYTE*)msf1+offset, glyphs[glyph_index]);
770 const GSUB_Sequence *seq;
773 offset = GET_BE_WORD(msf1->Sequence[index]);
774 seq = (const GSUB_Sequence*)((const BYTE*)msf1+offset);
775 sub_count = GET_BE_WORD(seq->GlyphCount);
776 TRACE(" Glyph 0x%x (+%i)->",glyphs[glyph_index],(sub_count-1));
778 for (j = (*glyph_count)+(sub_count-1); j > glyph_index; j--)
779 glyphs[j] =glyphs[j-(sub_count-1)];
781 for (j = 0; j < sub_count; j++)
783 glyphs[glyph_index + (sub_count-1) - j] = GET_BE_WORD(seq->Substitute[j]);
785 glyphs[glyph_index + j] = GET_BE_WORD(seq->Substitute[j]);
787 *glyph_count = *glyph_count + (sub_count - 1);
789 if (TRACE_ON(uniscribe))
791 for (j = 0; j < sub_count; j++)
792 TRACE(" 0x%x",glyphs[glyph_index+j]);
796 return glyph_index + (sub_count * write_dir);
799 return GSUB_E_NOGLYPH;
802 static INT GSUB_apply_AlternateSubst(const OT_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
805 TRACE("Alternate Substitution Subtable\n");
807 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
810 const GSUB_AlternateSubstFormat1 *asf1;
813 offset = GET_BE_WORD(look->SubTable[j]);
814 asf1 = (const GSUB_AlternateSubstFormat1*)((const BYTE*)look+offset);
815 offset = GET_BE_WORD(asf1->Coverage);
817 index = GSUB_is_glyph_covered((const BYTE*)asf1+offset, glyphs[glyph_index]);
820 const GSUB_AlternateSet *as;
821 offset = GET_BE_WORD(asf1->AlternateSet[index]);
822 as = (const GSUB_AlternateSet*)((const BYTE*)asf1+offset);
823 FIXME("%i alternates, picking index 0\n",GET_BE_WORD(as->GlyphCount));
824 if (glyphs[glyph_index] == GET_BE_WORD(as->Alternate[0]))
825 return GSUB_E_NOGLYPH;
827 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
828 glyphs[glyph_index] = GET_BE_WORD(as->Alternate[0]);
829 TRACE(" 0x%x\n",glyphs[glyph_index]);
830 return glyph_index + write_dir;
833 return GSUB_E_NOGLYPH;
836 static INT GSUB_apply_LigatureSubst(const OT_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
840 TRACE("Ligature Substitution Subtable\n");
841 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
843 const GSUB_LigatureSubstFormat1 *lsf1;
846 offset = GET_BE_WORD(look->SubTable[j]);
847 lsf1 = (const GSUB_LigatureSubstFormat1*)((const BYTE*)look+offset);
848 offset = GET_BE_WORD(lsf1->Coverage);
849 index = GSUB_is_glyph_covered((const BYTE*)lsf1+offset, glyphs[glyph_index]);
850 TRACE(" Coverage index %i\n",index);
853 const GSUB_LigatureSet *ls;
856 offset = GET_BE_WORD(lsf1->LigatureSet[index]);
857 ls = (const GSUB_LigatureSet*)((const BYTE*)lsf1+offset);
858 count = GET_BE_WORD(ls->LigatureCount);
859 TRACE(" LigatureSet has %i members\n",count);
860 for (k = 0; k < count; k++)
862 const GSUB_Ligature *lig;
863 int CompCount,l,CompIndex;
865 offset = GET_BE_WORD(ls->Ligature[k]);
866 lig = (const GSUB_Ligature*)((const BYTE*)ls+offset);
867 CompCount = GET_BE_WORD(lig->CompCount) - 1;
868 CompIndex = glyph_index+write_dir;
869 for (l = 0; l < CompCount && CompIndex >= 0 && CompIndex < *glyph_count; l++)
872 CompGlyph = GET_BE_WORD(lig->Component[l]);
873 if (CompGlyph != glyphs[CompIndex])
875 CompIndex += write_dir;
879 int replaceIdx = glyph_index;
881 replaceIdx = glyph_index - CompCount;
883 TRACE(" Glyph is 0x%x (+%i) ->",glyphs[glyph_index],CompCount);
884 glyphs[replaceIdx] = GET_BE_WORD(lig->LigGlyph);
885 TRACE("0x%x\n",glyphs[replaceIdx]);
889 for (j = replaceIdx + 1; j < *glyph_count; j++)
890 glyphs[j] =glyphs[j+CompCount];
891 *glyph_count = *glyph_count - CompCount;
893 return replaceIdx + write_dir;
898 return GSUB_E_NOGLYPH;
901 static INT GSUB_apply_ChainContextSubst(const OT_LookupList* lookup, const OT_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
906 TRACE("Chaining Contextual Substitution Subtable\n");
907 for (j = 0; j < GET_BE_WORD(look->SubTableCount) && !done; j++)
909 const GSUB_ChainContextSubstFormat1 *ccsf1;
911 int dirLookahead = write_dir;
912 int dirBacktrack = -1 * write_dir;
914 offset = GET_BE_WORD(look->SubTable[j]);
915 ccsf1 = (const GSUB_ChainContextSubstFormat1*)((const BYTE*)look+offset);
916 if (GET_BE_WORD(ccsf1->SubstFormat) == 1)
918 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
921 else if (GET_BE_WORD(ccsf1->SubstFormat) == 2)
923 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
926 else if (GET_BE_WORD(ccsf1->SubstFormat) == 3)
930 const GSUB_ChainContextSubstFormat3_1 *ccsf3_1;
931 const GSUB_ChainContextSubstFormat3_2 *ccsf3_2;
932 const GSUB_ChainContextSubstFormat3_3 *ccsf3_3;
933 const GSUB_ChainContextSubstFormat3_4 *ccsf3_4;
934 int newIndex = glyph_index;
936 ccsf3_1 = (const GSUB_ChainContextSubstFormat3_1 *)ccsf1;
938 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
940 for (k = 0; k < GET_BE_WORD(ccsf3_1->BacktrackGlyphCount); k++)
942 offset = GET_BE_WORD(ccsf3_1->Coverage[k]);
943 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirBacktrack * (k+1))]) == -1)
946 if (k != GET_BE_WORD(ccsf3_1->BacktrackGlyphCount))
948 TRACE("Matched Backtrack\n");
950 ccsf3_2 = (const GSUB_ChainContextSubstFormat3_2 *)((BYTE *)ccsf1 +
951 FIELD_OFFSET(GSUB_ChainContextSubstFormat3_1, Coverage[GET_BE_WORD(ccsf3_1->BacktrackGlyphCount)]));
953 indexGlyphs = GET_BE_WORD(ccsf3_2->InputGlyphCount);
954 for (k = 0; k < indexGlyphs; k++)
956 offset = GET_BE_WORD(ccsf3_2->Coverage[k]);
957 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (write_dir * k)]) == -1)
960 if (k != indexGlyphs)
962 TRACE("Matched IndexGlyphs\n");
964 ccsf3_3 = (const GSUB_ChainContextSubstFormat3_3 *)((BYTE *)ccsf3_2 +
965 FIELD_OFFSET(GSUB_ChainContextSubstFormat3_2, Coverage[GET_BE_WORD(ccsf3_2->InputGlyphCount)]));
967 for (k = 0; k < GET_BE_WORD(ccsf3_3->LookaheadGlyphCount); k++)
969 offset = GET_BE_WORD(ccsf3_3->Coverage[k]);
970 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirLookahead * (indexGlyphs + k))]) == -1)
973 if (k != GET_BE_WORD(ccsf3_3->LookaheadGlyphCount))
975 TRACE("Matched LookAhead\n");
977 ccsf3_4 = (const GSUB_ChainContextSubstFormat3_4 *)((BYTE *)ccsf3_3 +
978 FIELD_OFFSET(GSUB_ChainContextSubstFormat3_3, Coverage[GET_BE_WORD(ccsf3_3->LookaheadGlyphCount)]));
980 if (GET_BE_WORD(ccsf3_4->SubstCount))
982 for (k = 0; k < GET_BE_WORD(ccsf3_4->SubstCount); k++)
984 int lookupIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].LookupListIndex);
985 int SequenceIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].SequenceIndex) * write_dir;
987 TRACE("SUBST: %i -> %i %i\n",k, SequenceIndex, lookupIndex);
988 newIndex = GSUB_apply_lookup(lookup, lookupIndex, glyphs, glyph_index + SequenceIndex, write_dir, glyph_count);
991 ERR("Chain failed to generate a glyph\n");
997 else return GSUB_E_NOGLYPH;
1003 static INT GSUB_apply_lookup(const OT_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
1006 const OT_LookupTable *look;
1008 offset = GET_BE_WORD(lookup->Lookup[lookup_index]);
1009 look = (const OT_LookupTable*)((const BYTE*)lookup + offset);
1010 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look->LookupType),GET_BE_WORD(look->LookupFlag),GET_BE_WORD(look->SubTableCount));
1011 switch(GET_BE_WORD(look->LookupType))
1014 return GSUB_apply_SingleSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1016 return GSUB_apply_MultipleSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1018 return GSUB_apply_AlternateSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1020 return GSUB_apply_LigatureSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1022 return GSUB_apply_ChainContextSubst(lookup, look, glyphs, glyph_index, write_dir, glyph_count);
1024 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look->LookupType));
1026 return GSUB_E_NOGLYPH;
1029 INT OpenType_apply_GSUB_lookup(LPCVOID table, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
1031 const GSUB_Header *header = (const GSUB_Header *)table;
1032 const OT_LookupList *lookup = (const OT_LookupList*)((const BYTE*)header + GET_BE_WORD(header->LookupList));
1034 return GSUB_apply_lookup(lookup, lookup_index, glyphs, glyph_index, write_dir, glyph_count);
1040 static INT GPOS_apply_lookup(LPOUTLINETEXTMETRICW lpotm, LPLOGFONTW lplogfont, INT* piAdvance, const OT_LookupList* lookup, INT lookup_index, const WORD *glyphs, INT glyph_index, INT write_dir, INT glyph_count, GOFFSET *pGoffset);
1042 static INT GPOS_get_device_table_value(const OT_DeviceTable *DeviceTable, WORD ppem)
1044 static const WORD mask[3] = {3,0xf,0xff};
1045 if (DeviceTable && ppem >= GET_BE_WORD(DeviceTable->StartSize) && ppem <= GET_BE_WORD(DeviceTable->EndSize))
1047 int format = GET_BE_WORD(DeviceTable->DeltaFormat);
1048 int index = ppem - GET_BE_WORD(DeviceTable->StartSize);
1050 TRACE("device table, format %i, index %i\n",format, index);
1051 index = index << format;
1052 value = (DeviceTable->DeltaValue[index/sizeof(WORD)] << (index%sizeof(WORD)))&mask[format-1];
1053 TRACE("offset %i, value %i\n",index, value);
1054 if (value > mask[format-1]/2)
1055 value = -1 * ((mask[format-1]+1) - value);
1061 static VOID GPOS_get_anchor_values(LPCVOID table, LPPOINT pt, WORD ppem)
1063 const GPOS_AnchorFormat1* anchor1 = (const GPOS_AnchorFormat1*)table;
1065 switch (GET_BE_WORD(anchor1->AnchorFormat))
1069 TRACE("Anchor Format 1\n");
1070 pt->x = (short)GET_BE_WORD(anchor1->XCoordinate);
1071 pt->y = (short)GET_BE_WORD(anchor1->YCoordinate);
1076 const GPOS_AnchorFormat2* anchor2 = (const GPOS_AnchorFormat2*)table;
1077 TRACE("Anchor Format 2\n");
1078 pt->x = (short)GET_BE_WORD(anchor2->XCoordinate);
1079 pt->y = (short)GET_BE_WORD(anchor2->YCoordinate);
1085 const GPOS_AnchorFormat3* anchor3 = (const GPOS_AnchorFormat3*)table;
1086 TRACE("Anchor Format 3\n");
1087 pt->x = (short)GET_BE_WORD(anchor3->XCoordinate);
1088 pt->y = (short)GET_BE_WORD(anchor3->YCoordinate);
1089 offset = GET_BE_WORD(anchor3->XDeviceTable);
1090 TRACE("ppem %i\n",ppem);
1093 const OT_DeviceTable* DeviceTableX = NULL;
1094 DeviceTableX = (const OT_DeviceTable*)((const BYTE*)anchor3 + offset);
1095 pt->x += GPOS_get_device_table_value(DeviceTableX, ppem);
1097 offset = GET_BE_WORD(anchor3->YDeviceTable);
1100 const OT_DeviceTable* DeviceTableY = NULL;
1101 DeviceTableY = (const OT_DeviceTable*)((const BYTE*)anchor3 + offset);
1102 pt->y += GPOS_get_device_table_value(DeviceTableY, ppem);
1107 ERR("Unknown Anchor Format %i\n",GET_BE_WORD(anchor1->AnchorFormat));
1113 static void GPOS_convert_design_units_to_device(LPOUTLINETEXTMETRICW lpotm, LPLOGFONTW lplogfont, int desX, int desY, double *devX, double *devY)
1115 int emHeight = lpotm->otmTextMetrics.tmAscent + lpotm->otmTextMetrics.tmDescent - lpotm->otmTextMetrics.tmInternalLeading;
1117 TRACE("emHeight %i lfWidth %i\n",emHeight, lplogfont->lfWidth);
1118 *devX = (desX * emHeight) / (double)lpotm->otmEMSquare;
1119 *devY = (desY * emHeight) / (double)lpotm->otmEMSquare;
1120 if (lplogfont->lfWidth)
1121 FIXME("Font with lfWidth set no handled properly\n");
1124 static INT GPOS_get_value_record(WORD ValueFormat, const WORD data[], GPOS_ValueRecord *record)
1127 if (ValueFormat & 0x0001) { if (data) record->XPlacement = GET_BE_WORD(data[offset]); offset++; }
1128 if (ValueFormat & 0x0002) { if (data) record->YPlacement = GET_BE_WORD(data[offset]); offset++; }
1129 if (ValueFormat & 0x0004) { if (data) record->XAdvance = GET_BE_WORD(data[offset]); offset++; }
1130 if (ValueFormat & 0x0008) { if (data) record->YAdvance = GET_BE_WORD(data[offset]); offset++; }
1131 if (ValueFormat & 0x0010) { if (data) record->XPlaDevice = GET_BE_WORD(data[offset]); offset++; }
1132 if (ValueFormat & 0x0020) { if (data) record->YPlaDevice = GET_BE_WORD(data[offset]); offset++; }
1133 if (ValueFormat & 0x0040) { if (data) record->XAdvDevice = GET_BE_WORD(data[offset]); offset++; }
1134 if (ValueFormat & 0x0080) { if (data) record->YAdvDevice = GET_BE_WORD(data[offset]); offset++; }
1138 static VOID GPOS_get_value_record_offsets(const BYTE* head, GPOS_ValueRecord *ValueRecord, WORD ValueFormat, INT ppem, LPPOINT ptPlacement, LPPOINT ptAdvance)
1140 if (ValueFormat & 0x0001) ptPlacement->x += (short)ValueRecord->XPlacement;
1141 if (ValueFormat & 0x0002) ptPlacement->y += (short)ValueRecord->YPlacement;
1142 if (ValueFormat & 0x0004) ptAdvance->x += (short)ValueRecord->XAdvance;
1143 if (ValueFormat & 0x0008) ptAdvance->y += (short)ValueRecord->YAdvance;
1144 if (ValueFormat & 0x0010) ptPlacement->x += GPOS_get_device_table_value((const OT_DeviceTable*)(head + ValueRecord->XPlaDevice), ppem);
1145 if (ValueFormat & 0x0020) ptPlacement->y += GPOS_get_device_table_value((const OT_DeviceTable*)(head + ValueRecord->YPlaDevice), ppem);
1146 if (ValueFormat & 0x0040) ptAdvance->x += GPOS_get_device_table_value((const OT_DeviceTable*)(head + ValueRecord->XAdvDevice), ppem);
1147 if (ValueFormat & 0x0080) ptAdvance->y += GPOS_get_device_table_value((const OT_DeviceTable*)(head + ValueRecord->YAdvDevice), ppem);
1148 if (ValueFormat & 0xFF00) FIXME("Unhandled Value Format %x\n",ValueFormat&0xFF00);
1151 static VOID GPOS_apply_SingleAdjustment(const OT_LookupTable *look, const WORD *glyphs, INT glyph_index, INT write_dir, INT glyph_count, INT ppem, LPPOINT ptAdjust, LPPOINT ptAdvance)
1155 TRACE("Single Adjustment Positioning Subtable\n");
1157 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
1159 const GPOS_SinglePosFormat1 *spf1;
1160 WORD offset = GET_BE_WORD(look->SubTable[j]);
1161 spf1 = (const GPOS_SinglePosFormat1*)((const BYTE*)look+offset);
1162 if (GET_BE_WORD(spf1->PosFormat) == 1)
1164 offset = GET_BE_WORD(spf1->Coverage);
1165 if (GSUB_is_glyph_covered((const BYTE*)spf1+offset, glyphs[glyph_index]) != -1)
1167 GPOS_ValueRecord ValueRecord = {0,0,0,0,0,0,0,0};
1168 WORD ValueFormat = GET_BE_WORD(spf1->ValueFormat);
1169 GPOS_get_value_record(ValueFormat, spf1->Value, &ValueRecord);
1170 GPOS_get_value_record_offsets((const BYTE*)spf1, &ValueRecord, ValueFormat, ppem, ptAdjust, ptAdvance);
1171 TRACE("Glyph Adjusted by %i,%i\n",ValueRecord.XPlacement,ValueRecord.YPlacement);
1174 else if (GET_BE_WORD(spf1->PosFormat) == 2)
1177 const GPOS_SinglePosFormat2 *spf2;
1178 spf2 = (const GPOS_SinglePosFormat2*)spf1;
1179 offset = GET_BE_WORD(spf2->Coverage);
1180 index = GSUB_is_glyph_covered((const BYTE*)spf2+offset, glyphs[glyph_index]);
1184 GPOS_ValueRecord ValueRecord = {0,0,0,0,0,0,0,0};
1185 WORD ValueFormat = GET_BE_WORD(spf2->ValueFormat);
1186 size = GPOS_get_value_record(ValueFormat, spf2->Value, &ValueRecord);
1189 offset = size * index;
1190 GPOS_get_value_record(ValueFormat, &spf2->Value[offset], &ValueRecord);
1192 GPOS_get_value_record_offsets((const BYTE*)spf2, &ValueRecord, ValueFormat, ppem, ptAdjust, ptAdvance);
1193 TRACE("Glyph Adjusted by %i,%i\n",ValueRecord.XPlacement,ValueRecord.YPlacement);
1197 FIXME("Single Adjustment Positioning: Format %i Unhandled\n",GET_BE_WORD(spf1->PosFormat));
1201 static void apply_pair_value( const void *pos_table, WORD val_fmt1, WORD val_fmt2, const WORD *pair,
1202 INT ppem, POINT *adjust, POINT *advance )
1204 GPOS_ValueRecord val_rec1 = {0,0,0,0,0,0,0,0};
1205 GPOS_ValueRecord val_rec2 = {0,0,0,0,0,0,0,0};
1208 size = GPOS_get_value_record( val_fmt1, pair, &val_rec1 );
1209 GPOS_get_value_record( val_fmt2, pair + size, &val_rec2 );
1213 GPOS_get_value_record_offsets( pos_table, &val_rec1, val_fmt1, ppem, adjust, advance );
1214 TRACE( "Glyph 1 resulting cumulative offset is %i,%i design units\n", adjust[0].x, adjust[0].y );
1215 TRACE( "Glyph 1 resulting cumulative advance is %i,%i design units\n", advance[0].x, advance[0].y );
1219 GPOS_get_value_record_offsets( pos_table, &val_rec2, val_fmt2, ppem, adjust + 1, advance + 1 );
1220 TRACE( "Glyph 2 resulting cumulative offset is %i,%i design units\n", adjust[1].x, adjust[1].y );
1221 TRACE( "Glyph 2 resulting cumulative advance is %i,%i design units\n", advance[1].x, advance[1].y );
1225 static INT GPOS_apply_PairAdjustment(const OT_LookupTable *look, const WORD *glyphs, INT glyph_index, INT write_dir, INT glyph_count, INT ppem, LPPOINT ptAdjust, LPPOINT ptAdvance)
1229 TRACE("Pair Adjustment Positioning Subtable\n");
1231 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
1233 const GPOS_PairPosFormat1 *ppf1;
1234 WORD offset = GET_BE_WORD(look->SubTable[j]);
1235 ppf1 = (const GPOS_PairPosFormat1*)((const BYTE*)look+offset);
1236 if (GET_BE_WORD(ppf1->PosFormat) == 1)
1239 WORD ValueFormat1 = GET_BE_WORD(ppf1->ValueFormat1);
1240 WORD ValueFormat2 = GET_BE_WORD(ppf1->ValueFormat2);
1241 INT val_fmt1_size = GPOS_get_value_record( ValueFormat1, NULL, NULL );
1242 INT val_fmt2_size = GPOS_get_value_record( ValueFormat2, NULL, NULL );
1243 offset = GET_BE_WORD(ppf1->Coverage);
1244 index = GSUB_is_glyph_covered((const BYTE*)ppf1+offset, glyphs[glyph_index]);
1245 if (index != -1 && index < GET_BE_WORD(ppf1->PairSetCount))
1249 const GPOS_PairSet *ps;
1250 const GPOS_PairValueRecord *pair_val_rec;
1251 offset = GET_BE_WORD(ppf1->PairSetOffset[index]);
1252 ps = (const GPOS_PairSet*)((const BYTE*)ppf1+offset);
1253 pair_count = GET_BE_WORD(ps->PairValueCount);
1254 pair_val_rec = ps->PairValueRecord;
1255 for (k = 0; k < pair_count; k++)
1257 WORD second_glyph = GET_BE_WORD(pair_val_rec->SecondGlyph);
1258 if (glyphs[glyph_index+write_dir] == second_glyph)
1261 TRACE("Format 1: Found Pair %x,%x\n",glyphs[glyph_index],glyphs[glyph_index+write_dir]);
1262 apply_pair_value( ppf1, ValueFormat1, ValueFormat2, pair_val_rec->Value1, ppem, ptAdjust, ptAdvance );
1263 if (ValueFormat2) next++;
1264 return glyph_index + next;
1266 pair_val_rec = (const GPOS_PairValueRecord *)(pair_val_rec->Value1 + val_fmt1_size + val_fmt2_size);
1270 else if (GET_BE_WORD(ppf1->PosFormat) == 2)
1272 const GPOS_PairPosFormat2 *ppf2 = (const GPOS_PairPosFormat2*)((const BYTE*)look + offset);
1274 WORD ValueFormat1 = GET_BE_WORD( ppf2->ValueFormat1 );
1275 WORD ValueFormat2 = GET_BE_WORD( ppf2->ValueFormat2 );
1276 INT val_fmt1_size = GPOS_get_value_record( ValueFormat1, NULL, NULL );
1277 INT val_fmt2_size = GPOS_get_value_record( ValueFormat2, NULL, NULL );
1278 WORD class1_count = GET_BE_WORD( ppf2->Class1Count );
1279 WORD class2_count = GET_BE_WORD( ppf2->Class2Count );
1281 offset = GET_BE_WORD( ppf2->Coverage );
1282 index = GSUB_is_glyph_covered( (const BYTE*)ppf2 + offset, glyphs[glyph_index] );
1285 WORD class1, class2;
1286 class1 = OT_get_glyph_class( (const BYTE *)ppf2 + GET_BE_WORD(ppf2->ClassDef1), glyphs[glyph_index] );
1287 class2 = OT_get_glyph_class( (const BYTE *)ppf2 + GET_BE_WORD(ppf2->ClassDef2), glyphs[glyph_index + write_dir] );
1288 if (class1 < class1_count && class2 < class2_count)
1290 const WORD *pair_val = ppf2->Class1Record + (class1 * class2_count + class2) * (val_fmt1_size + val_fmt2_size);
1293 TRACE( "Format 2: Found Pair %x,%x\n", glyphs[glyph_index], glyphs[glyph_index + write_dir] );
1295 apply_pair_value( ppf2, ValueFormat1, ValueFormat2, pair_val, ppem, ptAdjust, ptAdvance );
1296 if (ValueFormat2) next++;
1297 return glyph_index + next;
1302 FIXME("Pair Adjustment Positioning: Format %i Unhandled\n",GET_BE_WORD(ppf1->PosFormat));
1304 return glyph_index+1;
1307 static VOID GPOS_apply_MarkToBase(const OT_LookupTable *look, const WORD *glyphs, INT glyph_index, INT write_dir, INT glyph_count, INT ppem, LPPOINT pt)
1311 TRACE("MarkToBase Attachment Positioning Subtable\n");
1313 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
1316 const GPOS_MarkBasePosFormat1 *mbpf1;
1317 offset = GET_BE_WORD(look->SubTable[j]);
1318 mbpf1 = (const GPOS_MarkBasePosFormat1*)((const BYTE*)look+offset);
1319 if (GET_BE_WORD(mbpf1->PosFormat) == 1)
1321 int offset = GET_BE_WORD(mbpf1->MarkCoverage);
1323 mark_index = GSUB_is_glyph_covered((const BYTE*)mbpf1+offset, glyphs[glyph_index]);
1324 if (mark_index != -1)
1327 offset = GET_BE_WORD(mbpf1->BaseCoverage);
1328 base_index = GSUB_is_glyph_covered((const BYTE*)mbpf1+offset, glyphs[glyph_index - write_dir]);
1329 if (base_index != -1)
1331 const GPOS_MarkArray *ma;
1332 const GPOS_MarkRecord *mr;
1333 const GPOS_BaseArray *ba;
1334 const GPOS_BaseRecord *br;
1336 int class_count = GET_BE_WORD(mbpf1->ClassCount);
1337 int baserecord_size;
1340 TRACE("Mark %x(%i) and base %x(%i)\n",glyphs[glyph_index], mark_index, glyphs[glyph_index - write_dir], base_index);
1341 offset = GET_BE_WORD(mbpf1->MarkArray);
1342 ma = (const GPOS_MarkArray*)((const BYTE*)mbpf1 + offset);
1343 if (mark_index > GET_BE_WORD(ma->MarkCount))
1345 ERR("Mark index exeeded mark count\n");
1348 mr = &ma->MarkRecord[mark_index];
1349 mark_class = GET_BE_WORD(mr->Class);
1350 TRACE("Mark Class %i total classes %i\n",mark_class,class_count);
1351 offset = GET_BE_WORD(mbpf1->BaseArray);
1352 ba = (const GPOS_BaseArray*)((const BYTE*)mbpf1 + offset);
1353 baserecord_size = class_count * sizeof(WORD);
1354 br = (const GPOS_BaseRecord*)((const BYTE*)ba + sizeof(WORD) + (baserecord_size * base_index));
1355 offset = GET_BE_WORD(br->BaseAnchor[mark_class]);
1356 GPOS_get_anchor_values((const BYTE*)ba + offset, &base_pt, ppem);
1357 offset = GET_BE_WORD(mr->MarkAnchor);
1358 GPOS_get_anchor_values((const BYTE*)ma + offset, &mark_pt, ppem);
1359 TRACE("Offset on base is %i,%i design units\n",base_pt.x,base_pt.y);
1360 TRACE("Offset on mark is %i,%i design units\n",mark_pt.x, mark_pt.y);
1361 pt->x += base_pt.x - mark_pt.x;
1362 pt->y += base_pt.y - mark_pt.y;
1363 TRACE("Resulting cumulative offset is %i,%i design units\n",pt->x,pt->y);
1368 FIXME("Unhandled Mark To Base Format %i\n",GET_BE_WORD(mbpf1->PosFormat));
1372 static VOID GPOS_apply_MarkToMark(const OT_LookupTable *look, const WORD *glyphs, INT glyph_index, INT write_dir, INT glyph_count, INT ppem, LPPOINT pt)
1376 TRACE("MarkToMark Attachment Positioning Subtable\n");
1378 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
1381 const GPOS_MarkMarkPosFormat1 *mmpf1;
1382 offset = GET_BE_WORD(look->SubTable[j]);
1383 mmpf1 = (const GPOS_MarkMarkPosFormat1*)((const BYTE*)look+offset);
1384 if (GET_BE_WORD(mmpf1->PosFormat) == 1)
1386 int offset = GET_BE_WORD(mmpf1->Mark1Coverage);
1388 mark_index = GSUB_is_glyph_covered((const BYTE*)mmpf1+offset, glyphs[glyph_index]);
1389 if (mark_index != -1)
1392 offset = GET_BE_WORD(mmpf1->Mark2Coverage);
1393 mark2_index = GSUB_is_glyph_covered((const BYTE*)mmpf1+offset, glyphs[glyph_index - write_dir]);
1394 if (mark2_index != -1)
1396 const GPOS_MarkArray *ma;
1397 const GPOS_MarkRecord *mr;
1398 const GPOS_Mark2Array *m2a;
1399 const GPOS_Mark2Record *m2r;
1401 int class_count = GET_BE_WORD(mmpf1->ClassCount);
1402 int mark2record_size;
1405 TRACE("Mark %x(%i) and Mark2 %x(%i)\n",glyphs[glyph_index], mark_index, glyphs[glyph_index - write_dir], mark2_index);
1406 offset = GET_BE_WORD(mmpf1->Mark1Array);
1407 ma = (const GPOS_MarkArray*)((const BYTE*)mmpf1 + offset);
1408 if (mark_index > GET_BE_WORD(ma->MarkCount))
1410 ERR("Mark index exeeded mark count\n");
1413 mr = &ma->MarkRecord[mark_index];
1414 mark_class = GET_BE_WORD(mr->Class);
1415 TRACE("Mark Class %i total classes %i\n",mark_class,class_count);
1416 offset = GET_BE_WORD(mmpf1->Mark2Array);
1417 m2a = (const GPOS_Mark2Array*)((const BYTE*)mmpf1 + offset);
1418 mark2record_size = class_count * sizeof(WORD);
1419 m2r = (const GPOS_Mark2Record*)((const BYTE*)m2a + sizeof(WORD) + (mark2record_size * mark2_index));
1420 offset = GET_BE_WORD(m2r->Mark2Anchor[mark_class]);
1421 GPOS_get_anchor_values((const BYTE*)m2a + offset, &mark2_pt, ppem);
1422 offset = GET_BE_WORD(mr->MarkAnchor);
1423 GPOS_get_anchor_values((const BYTE*)ma + offset, &mark_pt, ppem);
1424 TRACE("Offset on mark2 is %i,%i design units\n",mark2_pt.x,mark2_pt.y);
1425 TRACE("Offset on mark is %i,%i design units\n",mark_pt.x, mark_pt.y);
1426 pt->x += mark2_pt.x - mark_pt.x;
1427 pt->y += mark2_pt.y - mark_pt.y;
1428 TRACE("Resulting cumulative offset is %i,%i design units\n",pt->x,pt->y);
1433 FIXME("Unhandled Mark To Mark Format %i\n",GET_BE_WORD(mmpf1->PosFormat));
1437 static INT GPOS_apply_ChainContextPos(LPOUTLINETEXTMETRICW lpotm, LPLOGFONTW lplogfont, INT* piAdvance, const OT_LookupList *lookup, const OT_LookupTable *look, const WORD *glyphs, INT glyph_index, INT write_dir, INT glyph_count, INT ppem, GOFFSET *pGoffset)
1441 TRACE("Chaining Contextual Positioning Subtable\n");
1443 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
1446 const GPOS_ChainContextPosFormat3_1 *ccpf3;
1447 int dirLookahead = write_dir;
1448 int dirBacktrack = -1 * write_dir;
1450 offset = GET_BE_WORD(look->SubTable[j]);
1451 ccpf3 = (const GPOS_ChainContextPosFormat3_1*)((const BYTE*)look+offset);
1453 if (GET_BE_WORD(ccpf3->PosFormat) == 1)
1455 FIXME(" TODO: subtype 1 (Simple Chaining Context Glyph Positioning)\n");
1458 else if (GET_BE_WORD(ccpf3->PosFormat) == 2)
1460 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Positioning)\n");
1463 else if (GET_BE_WORD(ccpf3->PosFormat) == 3)
1467 const GPOS_ChainContextPosFormat3_2 *ccpf3_2;
1468 const GPOS_ChainContextPosFormat3_3 *ccpf3_3;
1469 const GPOS_ChainContextPosFormat3_4 *ccpf3_4;
1471 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Positioning)\n");
1473 for (k = 0; k < GET_BE_WORD(ccpf3->BacktrackGlyphCount); k++)
1475 offset = GET_BE_WORD(ccpf3->Coverage[k]);
1476 if (GSUB_is_glyph_covered((const BYTE*)ccpf3+offset, glyphs[glyph_index + (dirBacktrack * (k+1))]) == -1)
1479 if (k != GET_BE_WORD(ccpf3->BacktrackGlyphCount))
1481 TRACE("Matched Backtrack\n");
1483 ccpf3_2 = (const GPOS_ChainContextPosFormat3_2*)((BYTE *)ccpf3 +
1484 FIELD_OFFSET(GPOS_ChainContextPosFormat3_1, Coverage[GET_BE_WORD(ccpf3->BacktrackGlyphCount)]));
1486 indexGlyphs = GET_BE_WORD(ccpf3_2->InputGlyphCount);
1487 for (k = 0; k < indexGlyphs; k++)
1489 offset = GET_BE_WORD(ccpf3_2->Coverage[k]);
1490 if (GSUB_is_glyph_covered((const BYTE*)ccpf3+offset, glyphs[glyph_index + (write_dir * k)]) == -1)
1493 if (k != indexGlyphs)
1495 TRACE("Matched IndexGlyphs\n");
1497 ccpf3_3 = (const GPOS_ChainContextPosFormat3_3*)((BYTE *)ccpf3_2 +
1498 FIELD_OFFSET(GPOS_ChainContextPosFormat3_2, Coverage[GET_BE_WORD(ccpf3_2->InputGlyphCount)]));
1500 for (k = 0; k < GET_BE_WORD(ccpf3_3->LookaheadGlyphCount); k++)
1502 offset = GET_BE_WORD(ccpf3_3->Coverage[k]);
1503 if (GSUB_is_glyph_covered((const BYTE*)ccpf3+offset, glyphs[glyph_index + (dirLookahead * (indexGlyphs + k))]) == -1)
1506 if (k != GET_BE_WORD(ccpf3_3->LookaheadGlyphCount))
1508 TRACE("Matched LookAhead\n");
1510 ccpf3_4 = (const GPOS_ChainContextPosFormat3_4*)((BYTE *)ccpf3_3 +
1511 FIELD_OFFSET(GPOS_ChainContextPosFormat3_3, Coverage[GET_BE_WORD(ccpf3_3->LookaheadGlyphCount)]));
1513 if (GET_BE_WORD(ccpf3_4->PosCount))
1515 for (k = 0; k < GET_BE_WORD(ccpf3_4->PosCount); k++)
1517 int lookupIndex = GET_BE_WORD(ccpf3_4->PosLookupRecord[k].LookupListIndex);
1518 int SequenceIndex = GET_BE_WORD(ccpf3_4->PosLookupRecord[k].SequenceIndex) * write_dir;
1520 TRACE("Position: %i -> %i %i\n",k, SequenceIndex, lookupIndex);
1521 GPOS_apply_lookup(lpotm, lplogfont, piAdvance, lookup, lookupIndex, glyphs, glyph_index + SequenceIndex, write_dir, glyph_count, pGoffset);
1523 return glyph_index + indexGlyphs + GET_BE_WORD(ccpf3_3->LookaheadGlyphCount);
1525 else return glyph_index + 1;
1528 FIXME("Unhandled Chaining Contextual Positioning Format %i\n",GET_BE_WORD(ccpf3->PosFormat));
1530 return glyph_index + 1;
1533 static INT GPOS_apply_lookup(LPOUTLINETEXTMETRICW lpotm, LPLOGFONTW lplogfont, INT* piAdvance, const OT_LookupList* lookup, INT lookup_index, const WORD *glyphs, INT glyph_index, INT write_dir, INT glyph_count, GOFFSET *pGoffset)
1536 const OT_LookupTable *look;
1537 int ppem = lpotm->otmTextMetrics.tmAscent + lpotm->otmTextMetrics.tmDescent - lpotm->otmTextMetrics.tmInternalLeading;
1539 offset = GET_BE_WORD(lookup->Lookup[lookup_index]);
1540 look = (const OT_LookupTable*)((const BYTE*)lookup + offset);
1541 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look->LookupType),GET_BE_WORD(look->LookupFlag),GET_BE_WORD(look->SubTableCount));
1542 switch(GET_BE_WORD(look->LookupType))
1547 POINT adjust = {0,0};
1548 POINT advance = {0,0};
1549 GPOS_apply_SingleAdjustment(look, glyphs, glyph_index, write_dir, glyph_count, ppem, &adjust, &advance);
1550 if (adjust.x || adjust.y)
1552 GPOS_convert_design_units_to_device(lpotm, lplogfont, adjust.x, adjust.y, &devX, &devY);
1553 pGoffset[glyph_index].du += round(devX);
1554 pGoffset[glyph_index].dv += round(devY);
1556 if (advance.x || advance.y)
1558 GPOS_convert_design_units_to_device(lpotm, lplogfont, advance.x, advance.y, &devX, &devY);
1559 piAdvance[glyph_index] += round(devX);
1561 FIXME("Unhandled adjustment to Y advancement\n");
1567 POINT advance[2]= {{0,0},{0,0}};
1568 POINT adjust[2]= {{0,0},{0,0}};
1571 index = GPOS_apply_PairAdjustment(look, glyphs, glyph_index, write_dir, glyph_count, ppem, adjust, advance);
1572 if (adjust[0].x || adjust[0].y)
1574 GPOS_convert_design_units_to_device(lpotm, lplogfont, adjust[0].x, adjust[0].y, &devX, &devY);
1575 pGoffset[glyph_index].du += round(devX);
1576 pGoffset[glyph_index].dv += round(devY);
1578 if (advance[0].x || advance[0].y)
1580 GPOS_convert_design_units_to_device(lpotm, lplogfont, advance[0].x, advance[0].y, &devX, &devY);
1581 piAdvance[glyph_index] += round(devX);
1583 if (adjust[1].x || adjust[1].y)
1585 GPOS_convert_design_units_to_device(lpotm, lplogfont, adjust[1].x, adjust[1].y, &devX, &devY);
1586 pGoffset[glyph_index + write_dir].du += round(devX);
1587 pGoffset[glyph_index + write_dir].dv += round(devY);
1589 if (advance[1].x || advance[1].y)
1591 GPOS_convert_design_units_to_device(lpotm, lplogfont, advance[1].x, advance[1].y, &devX, &devY);
1592 piAdvance[glyph_index + write_dir] += round(devX);
1600 GPOS_apply_MarkToBase(look, glyphs, glyph_index, write_dir, glyph_count, ppem, &desU);
1601 if (desU.x || desU.y)
1603 GPOS_convert_design_units_to_device(lpotm, lplogfont, desU.x, desU.y, &devX, &devY);
1604 pGoffset[glyph_index].du += (round(devX) - piAdvance[glyph_index-1]);
1605 pGoffset[glyph_index].dv += round(devY);
1613 GPOS_apply_MarkToMark(look, glyphs, glyph_index, write_dir, glyph_count, ppem, &desU);
1614 if (desU.x || desU.y)
1616 GPOS_convert_design_units_to_device(lpotm, lplogfont, desU.x, desU.y, &devX, &devY);
1617 pGoffset[glyph_index].du += round(devX) + pGoffset[glyph_index-1].du;
1618 pGoffset[glyph_index].dv += round(devY) + pGoffset[glyph_index-1].dv;
1624 return GPOS_apply_ChainContextPos(lpotm, lplogfont, piAdvance, lookup, look, glyphs, glyph_index, write_dir, glyph_count, ppem, pGoffset);
1627 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look->LookupType));
1629 return glyph_index+1;
1632 INT OpenType_apply_GPOS_lookup(LPOUTLINETEXTMETRICW lpotm, LPLOGFONTW lplogfont, INT* piAdvance, LPCVOID table, INT lookup_index, const WORD *glyphs, INT glyph_index, INT write_dir, INT glyph_count, GOFFSET *pGoffset)
1634 const GPOS_Header *header = (const GPOS_Header *)table;
1635 const OT_LookupList *lookup = (const OT_LookupList*)((const BYTE*)header + GET_BE_WORD(header->LookupList));
1637 return GPOS_apply_lookup(lpotm, lplogfont, piAdvance, lookup, lookup_index, glyphs, glyph_index, write_dir, glyph_count, pGoffset);
1640 static void GSUB_initialize_script_cache(ScriptCache *psc)
1644 if (psc->GSUB_Table)
1646 const OT_ScriptList *script;
1647 const GSUB_Header* header = (const GSUB_Header*)psc->GSUB_Table;
1648 script = (const OT_ScriptList*)((const BYTE*)header + GET_BE_WORD(header->ScriptList));
1649 psc->script_count = GET_BE_WORD(script->ScriptCount);
1650 TRACE("initializing %i scripts in this font\n",psc->script_count);
1651 if (psc->script_count)
1653 psc->scripts = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LoadedScript) * psc->script_count);
1654 for (i = 0; i < psc->script_count; i++)
1656 int offset = GET_BE_WORD(script->ScriptRecord[i].Script);
1657 psc->scripts[i].tag = MS_MAKE_TAG(script->ScriptRecord[i].ScriptTag[0], script->ScriptRecord[i].ScriptTag[1], script->ScriptRecord[i].ScriptTag[2], script->ScriptRecord[i].ScriptTag[3]);
1658 psc->scripts[i].gsub_table = ((const BYTE*)script + offset);
1664 static void GPOS_expand_script_cache(ScriptCache *psc)
1667 const OT_ScriptList *script;
1668 const GPOS_Header* header = (const GPOS_Header*)psc->GPOS_Table;
1673 script = (const OT_ScriptList*)((const BYTE*)header + GET_BE_WORD(header->ScriptList));
1674 count = GET_BE_WORD(script->ScriptCount);
1676 if (!psc->script_count)
1678 psc->script_count = count;
1679 TRACE("initializing %i scripts in this font\n",psc->script_count);
1680 if (psc->script_count)
1682 psc->scripts = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LoadedScript) * psc->script_count);
1683 for (i = 0; i < psc->script_count; i++)
1685 int offset = GET_BE_WORD(script->ScriptRecord[i].Script);
1686 psc->scripts[i].tag = MS_MAKE_TAG(script->ScriptRecord[i].ScriptTag[0], script->ScriptRecord[i].ScriptTag[1], script->ScriptRecord[i].ScriptTag[2], script->ScriptRecord[i].ScriptTag[3]);
1687 psc->scripts[i].gpos_table = ((const BYTE*)script + offset);
1693 for (i = 0; i < count; i++)
1696 int offset = GET_BE_WORD(script->ScriptRecord[i].Script);
1697 OPENTYPE_TAG tag = MS_MAKE_TAG(script->ScriptRecord[i].ScriptTag[0], script->ScriptRecord[i].ScriptTag[1], script->ScriptRecord[i].ScriptTag[2], script->ScriptRecord[i].ScriptTag[3]);
1698 for (j = 0; j < psc->script_count; j++)
1700 if (psc->scripts[j].tag == tag)
1702 psc->scripts[j].gpos_table = ((const BYTE*)script + offset);
1706 if (j == psc->script_count)
1708 psc->script_count++;
1709 psc->scripts = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,psc->scripts, sizeof(LoadedScript) * psc->script_count);
1710 psc->scripts[j].tag = tag;
1711 psc->scripts[j].gpos_table = ((const BYTE*)script + offset);
1717 static void _initialize_script_cache(ScriptCache *psc)
1719 if (!psc->script_count)
1721 GSUB_initialize_script_cache(psc);
1722 GPOS_expand_script_cache(psc);
1726 HRESULT OpenType_GetFontScriptTags(ScriptCache *psc, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags)
1731 _initialize_script_cache(psc);
1733 *pcTags = psc->script_count;
1735 if (!searchingFor && cMaxTags < *pcTags)
1737 else if (searchingFor)
1738 rc = USP_E_SCRIPT_NOT_IN_FONT;
1740 for (i = 0; i < psc->script_count; i++)
1743 pScriptTags[i] = psc->scripts[i].tag;
1747 if (searchingFor == psc->scripts[i].tag)
1749 pScriptTags[0] = psc->scripts[i].tag;
1759 static void GSUB_initialize_language_cache(LoadedScript *script)
1763 if (script->gsub_table)
1766 const OT_Script* table = script->gsub_table;
1767 script->language_count = GET_BE_WORD(table->LangSysCount);
1768 offset = GET_BE_WORD(table->DefaultLangSys);
1771 script->default_language.tag = MS_MAKE_TAG('d','f','l','t');
1772 script->default_language.gsub_table = (const BYTE*)table + offset;
1775 if (script->language_count)
1777 TRACE("Deflang %p, LangCount %i\n",script->default_language.gsub_table, script->language_count);
1779 script->languages = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LoadedLanguage) * script->language_count);
1781 for (i = 0; i < script->language_count; i++)
1783 int offset = GET_BE_WORD(table->LangSysRecord[i].LangSys);
1784 script->languages[i].tag = MS_MAKE_TAG(table->LangSysRecord[i].LangSysTag[0], table->LangSysRecord[i].LangSysTag[1], table->LangSysRecord[i].LangSysTag[2], table->LangSysRecord[i].LangSysTag[3]);
1785 script->languages[i].gsub_table = ((const BYTE*)table + offset);
1791 static void GPOS_expand_language_cache(LoadedScript *script)
1794 const OT_Script* table = script->gpos_table;
1800 offset = GET_BE_WORD(table->DefaultLangSys);
1802 script->default_language.gpos_table = (const BYTE*)table + offset;
1804 count = GET_BE_WORD(table->LangSysCount);
1806 TRACE("Deflang %p, LangCount %i\n",script->default_language.gpos_table, count);
1807 if (!script->language_count)
1810 script->language_count = count;
1812 script->languages = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LoadedLanguage) * script->language_count);
1814 for (i = 0; i < script->language_count; i++)
1816 int offset = GET_BE_WORD(table->LangSysRecord[i].LangSys);
1817 script->languages[i].tag = MS_MAKE_TAG(table->LangSysRecord[i].LangSysTag[0], table->LangSysRecord[i].LangSysTag[1], table->LangSysRecord[i].LangSysTag[2], table->LangSysRecord[i].LangSysTag[3]);
1818 script->languages[i].gpos_table = ((const BYTE*)table + offset);
1824 for (i = 0; i < count; i++)
1826 int offset = GET_BE_WORD(table->LangSysRecord[i].LangSys);
1827 OPENTYPE_TAG tag = MS_MAKE_TAG(table->LangSysRecord[i].LangSysTag[0], table->LangSysRecord[i].LangSysTag[1], table->LangSysRecord[i].LangSysTag[2], table->LangSysRecord[i].LangSysTag[3]);
1829 for (j = 0; j < script->language_count; j++)
1831 if (script->languages[j].tag == tag)
1833 script->languages[j].gpos_table = ((const BYTE*)table + offset);
1837 if (j == script->language_count)
1839 script->language_count++;
1840 script->languages = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,script->languages, sizeof(LoadedLanguage) * script->language_count);
1841 script->languages[j].tag = tag;
1842 script->languages[j].gpos_table = ((const BYTE*)table + offset);
1848 static void _initialize_language_cache(LoadedScript *script)
1850 if (!script->language_count)
1852 GSUB_initialize_language_cache(script);
1853 GPOS_expand_language_cache(script);
1857 HRESULT OpenType_GetFontLanguageTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pLanguageTags, int *pcTags)
1861 LoadedScript *script = NULL;
1863 _initialize_script_cache(psc);
1865 for (i = 0; i < psc->script_count; i++)
1867 if (psc->scripts[i].tag == script_tag)
1869 script = &psc->scripts[i];
1875 return E_INVALIDARG;
1877 _initialize_language_cache(script);
1879 if (!searchingFor && cMaxTags < script->language_count)
1881 else if (searchingFor)
1884 *pcTags = script->language_count;
1886 for (i = 0; i < script->language_count; i++)
1889 pLanguageTags[i] = script->languages[i].tag;
1893 if (searchingFor == script->languages[i].tag)
1895 pLanguageTags[0] = script->languages[i].tag;
1903 if (script->default_language.gsub_table)
1906 pLanguageTags[i] = script->default_language.tag;
1908 if (searchingFor && FAILED(rc))
1910 pLanguageTags[0] = script->default_language.tag;
1913 *pcTags = (*pcTags) + 1;
1920 static void GSUB_initialize_feature_cache(LPCVOID table, LoadedLanguage *language)
1924 if (language->gsub_table)
1926 const OT_LangSys *lang = language->gsub_table;
1927 const GSUB_Header *header = (const GSUB_Header *)table;
1928 const OT_FeatureList *feature_list;
1930 language->feature_count = GET_BE_WORD(lang->FeatureCount);
1931 TRACE("%i features\n",language->feature_count);
1933 if (language->feature_count)
1935 language->features = HeapAlloc(GetProcessHeap(),0,sizeof(LoadedFeature)*language->feature_count);
1937 feature_list = (const OT_FeatureList*)((const BYTE*)header + GET_BE_WORD(header->FeatureList));
1939 for (i = 0; i < language->feature_count; i++)
1941 const OT_Feature *feature;
1943 int index = GET_BE_WORD(lang->FeatureIndex[i]);
1945 language->features[i].tag = MS_MAKE_TAG(feature_list->FeatureRecord[index].FeatureTag[0], feature_list->FeatureRecord[index].FeatureTag[1], feature_list->FeatureRecord[index].FeatureTag[2], feature_list->FeatureRecord[index].FeatureTag[3]);
1946 language->features[i].feature = ((const BYTE*)feature_list + GET_BE_WORD(feature_list->FeatureRecord[index].Feature));
1947 feature = (const OT_Feature*)language->features[i].feature;
1948 language->features[i].lookup_count = GET_BE_WORD(feature->LookupCount);
1949 language->features[i].lookups = HeapAlloc(GetProcessHeap(),0,sizeof(WORD) * language->features[i].lookup_count);
1950 for (j = 0; j < language->features[i].lookup_count; j++)
1951 language->features[i].lookups[j] = GET_BE_WORD(feature->LookupListIndex[j]);
1957 static void GPOS_expand_feature_cache(LPCVOID table, LoadedLanguage *language)
1960 const OT_LangSys *lang = language->gpos_table;
1961 const GPOS_Header *header = (const GPOS_Header *)table;
1962 const OT_FeatureList *feature_list;
1967 count = GET_BE_WORD(lang->FeatureCount);
1968 feature_list = (const OT_FeatureList*)((const BYTE*)header + GET_BE_WORD(header->FeatureList));
1970 TRACE("%i features\n",count);
1971 if (!language->feature_count)
1973 language->feature_count = count;
1975 if (language->feature_count)
1977 language->features = HeapAlloc(GetProcessHeap(),0,sizeof(LoadedFeature)*language->feature_count);
1979 for (i = 0; i < language->feature_count; i++)
1981 const OT_Feature *feature;
1983 int index = GET_BE_WORD(lang->FeatureIndex[i]);
1985 language->features[i].tag = MS_MAKE_TAG(feature_list->FeatureRecord[index].FeatureTag[0], feature_list->FeatureRecord[index].FeatureTag[1], feature_list->FeatureRecord[index].FeatureTag[2], feature_list->FeatureRecord[index].FeatureTag[3]);
1986 language->features[i].feature = ((const BYTE*)feature_list + GET_BE_WORD(feature_list->FeatureRecord[index].Feature));
1987 feature = (const OT_Feature*)language->features[i].feature;
1988 language->features[i].lookup_count = GET_BE_WORD(feature->LookupCount);
1989 language->features[i].lookups = HeapAlloc(GetProcessHeap(),0,sizeof(WORD) * language->features[i].lookup_count);
1990 for (j = 0; j < language->features[i].lookup_count; j++)
1991 language->features[i].lookups[j] = GET_BE_WORD(feature->LookupListIndex[j]);
1997 language->features = HeapReAlloc(GetProcessHeap(),0,language->features, sizeof(LoadedFeature)*(language->feature_count + count));
1999 for (i = 0; i < count; i++)
2001 const OT_Feature *feature;
2003 int index = GET_BE_WORD(lang->FeatureIndex[i]);
2004 int idx = language->feature_count + i;
2006 language->features[idx].tag = MS_MAKE_TAG(feature_list->FeatureRecord[index].FeatureTag[0], feature_list->FeatureRecord[index].FeatureTag[1], feature_list->FeatureRecord[index].FeatureTag[2], feature_list->FeatureRecord[index].FeatureTag[3]);
2007 language->features[idx].feature = ((const BYTE*)feature_list + GET_BE_WORD(feature_list->FeatureRecord[index].Feature));
2008 feature = (const OT_Feature*)language->features[idx].feature;
2009 language->features[idx].lookup_count = GET_BE_WORD(feature->LookupCount);
2010 language->features[idx].lookups = HeapAlloc(GetProcessHeap(),0,sizeof(WORD) * language->features[idx].lookup_count);
2011 for (j = 0; j < language->features[idx].lookup_count; j++)
2012 language->features[idx].lookups[j] = GET_BE_WORD(feature->LookupListIndex[j]);
2014 language->feature_count += count;
2018 static void _initialize_feature_cache(ScriptCache *psc, LoadedLanguage *language)
2020 if (!language->feature_count)
2022 GSUB_initialize_feature_cache(psc->GSUB_Table, language);
2023 GPOS_expand_feature_cache(psc->GPOS_Table, language);
2027 HRESULT OpenType_GetFontFeatureTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG language_tag, BOOL filtered, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pFeatureTags, int *pcTags, LoadedFeature** feature)
2031 LoadedScript *script = NULL;
2032 LoadedLanguage *language = NULL;
2034 _initialize_script_cache(psc);
2036 for (i = 0; i < psc->script_count; i++)
2038 if (psc->scripts[i].tag == script_tag)
2040 script = &psc->scripts[i];
2051 return E_INVALIDARG;
2054 _initialize_language_cache(script);
2056 if ((script->default_language.gsub_table || script->default_language.gpos_table) && script->default_language.tag == language_tag)
2057 language = &script->default_language;
2060 for (i = 0; i < script->language_count; i++)
2062 if (script->languages[i].tag == language_tag)
2064 language = &script->languages[i];
2076 _initialize_feature_cache(psc, language);
2078 *pcTags = language->feature_count;
2080 if (!searchingFor && cMaxTags < *pcTags)
2082 else if (searchingFor)
2085 for (i = 0; i < language->feature_count; i++)
2088 pFeatureTags[i] = language->features[i].tag;
2092 if (searchingFor == language->features[i].tag)
2094 pFeatureTags[0] = language->features[i].tag;
2097 *feature = &language->features[i];