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 /* These are all structures needed for the cmap format 12 table */
47 #define CMAP_TAG MS_MAKE_TAG('c', 'm', 'a', 'p')
53 } CMAP_EncodingRecord
;
58 CMAP_EncodingRecord tables
[1];
65 } CMAP_SegmentedCoverage_group
;
73 CMAP_SegmentedCoverage_group groups
[1];
74 } CMAP_SegmentedCoverage
;
76 /* These are all structures needed for the GDEF table */
77 #define GDEF_TAG MS_MAKE_TAG('G', 'D', 'E', 'F')
79 enum {BaseGlyph
=1, LigatureGlyph
, MarkGlyph
, ComponentGlyph
};
86 WORD MarkAttachClassDef
;
93 WORD ClassValueArray
[1];
94 } GDEF_ClassDefFormat1
;
100 } GDEF_ClassRangeRecord
;
104 WORD ClassRangeCount
;
105 GDEF_ClassRangeRecord ClassRangeRecord
[1];
106 } GDEF_ClassDefFormat2
;
108 /* These are all structures needed for the GSUB table */
124 OT_ScriptRecord ScriptRecord
[1];
135 OT_LangSysRecord LangSysRecord
[1];
139 WORD LookupOrder
; /* Reserved */
140 WORD ReqFeatureIndex
;
142 WORD FeatureIndex
[1];
152 OT_FeatureRecord FeatureRecord
[1];
156 WORD FeatureParams
; /* Reserved */
158 WORD LookupListIndex
[1];
177 } OT_CoverageFormat1
;
182 WORD StartCoverageIndex
;
188 OT_RangeRecord RangeRecord
[1];
189 } OT_CoverageFormat2
;
192 WORD SubstFormat
; /* = 1 */
195 } GSUB_SingleSubstFormat1
;
198 WORD SubstFormat
; /* = 2 */
202 }GSUB_SingleSubstFormat2
;
205 WORD SubstFormat
; /* = 1 */
209 }GSUB_MultipleSubstFormat1
;
217 WORD SubstFormat
; /* = 1 */
221 }GSUB_LigatureSubstFormat1
;
236 WORD LookupListIndex
;
238 }GSUB_SubstLookupRecord
;
241 WORD SubstFormat
; /* = 1 */
243 WORD ChainSubRuleSetCount
;
244 WORD ChainSubRuleSet
[1];
245 }GSUB_ChainContextSubstFormat1
;
248 WORD SubstFormat
; /* = 3 */
249 WORD BacktrackGlyphCount
;
251 }GSUB_ChainContextSubstFormat3_1
;
254 WORD InputGlyphCount
;
256 }GSUB_ChainContextSubstFormat3_2
;
259 WORD LookaheadGlyphCount
;
261 }GSUB_ChainContextSubstFormat3_3
;
265 GSUB_SubstLookupRecord SubstLookupRecord
[1];
266 }GSUB_ChainContextSubstFormat3_4
;
269 WORD SubstFormat
; /* = 1 */
271 WORD AlternateSetCount
;
272 WORD AlternateSet
[1];
273 } GSUB_AlternateSubstFormat1
;
280 /* These are all structures needed for the GPOS table */
300 } GPOS_AnchorFormat1
;
307 } GPOS_AnchorFormat2
;
315 } GPOS_AnchorFormat3
;
321 static VOID
*load_CMAP_format12_table(HDC hdc
, ScriptCache
*psc
)
323 CMAP_Header
*CMAP_Table
= NULL
;
327 if (!psc
->CMAP_Table
)
329 length
= GetFontData(hdc
, CMAP_TAG
, 0, NULL
, 0);
330 if (length
!= GDI_ERROR
)
332 psc
->CMAP_Table
= HeapAlloc(GetProcessHeap(),0,length
);
333 GetFontData(hdc
, CMAP_TAG
, 0, psc
->CMAP_Table
, length
);
334 TRACE("Loaded cmap table of %i bytes\n",length
);
340 CMAP_Table
= psc
->CMAP_Table
;
342 for (i
= 0; i
< GET_BE_WORD(CMAP_Table
->numTables
); i
++)
344 if ( (GET_BE_WORD(CMAP_Table
->tables
[i
].platformID
) == 3) &&
345 (GET_BE_WORD(CMAP_Table
->tables
[i
].encodingID
) == 10) )
347 CMAP_SegmentedCoverage
*format
= (CMAP_SegmentedCoverage
*)(((BYTE
*)CMAP_Table
) + GET_BE_DWORD(CMAP_Table
->tables
[i
].offset
));
348 if (GET_BE_WORD(format
->format
) == 12)
355 static int compare_group(const void *a
, const void* b
)
357 const DWORD
*chr
= a
;
358 const CMAP_SegmentedCoverage_group
*group
= b
;
360 if (*chr
< GET_BE_DWORD(group
->startCharCode
))
362 if (*chr
> GET_BE_DWORD(group
->endCharCode
))
367 DWORD
OpenType_CMAP_GetGlyphIndex(HDC hdc
, ScriptCache
*psc
, DWORD utf32c
, LPWORD pgi
, DWORD flags
)
369 /* BMP: use gdi32 for ease */
370 if (utf32c
< 0x10000)
373 return GetGlyphIndicesW(hdc
,&ch
, 1, pgi
, flags
);
376 if (!psc
->CMAP_format12_Table
)
377 psc
->CMAP_format12_Table
= load_CMAP_format12_table(hdc
, psc
);
379 if (flags
& GGI_MARK_NONEXISTING_GLYPHS
)
384 if (psc
->CMAP_format12_Table
)
386 CMAP_SegmentedCoverage
*format
= NULL
;
387 CMAP_SegmentedCoverage_group
*group
= NULL
;
389 format
= (CMAP_SegmentedCoverage
*)psc
->CMAP_format12_Table
;
391 group
= bsearch(&utf32c
, format
->groups
, GET_BE_DWORD(format
->nGroups
),
392 sizeof(CMAP_SegmentedCoverage_group
), compare_group
);
396 DWORD offset
= utf32c
- GET_BE_DWORD(group
->startCharCode
);
397 *pgi
= GET_BE_DWORD(group
->startGlyphID
) + offset
;
408 static WORD
GDEF_get_glyph_class(const GDEF_Header
*header
, WORD glyph
)
412 const GDEF_ClassDefFormat1
*cf1
;
417 offset
= GET_BE_WORD(header
->GlyphClassDef
);
421 cf1
= (GDEF_ClassDefFormat1
*)(((BYTE
*)header
)+offset
);
422 if (GET_BE_WORD(cf1
->ClassFormat
) == 1)
424 if (glyph
>= GET_BE_WORD(cf1
->StartGlyph
))
426 int index
= glyph
- GET_BE_WORD(cf1
->StartGlyph
);
427 if (index
< GET_BE_WORD(cf1
->GlyphCount
))
428 class = GET_BE_WORD(cf1
->ClassValueArray
[index
]);
431 else if (GET_BE_WORD(cf1
->ClassFormat
) == 2)
433 const GDEF_ClassDefFormat2
*cf2
= (GDEF_ClassDefFormat2
*)cf1
;
435 top
= GET_BE_WORD(cf2
->ClassRangeCount
);
436 for (i
= 0; i
< top
; i
++)
438 if (glyph
>= GET_BE_WORD(cf2
->ClassRangeRecord
[i
].Start
) &&
439 glyph
<= GET_BE_WORD(cf2
->ClassRangeRecord
[i
].End
))
441 class = GET_BE_WORD(cf2
->ClassRangeRecord
[i
].Class
);
447 ERR("Unknown Class Format %i\n",GET_BE_WORD(cf1
->ClassFormat
));
452 static VOID
*load_gdef_table(HDC hdc
)
454 VOID
* GDEF_Table
= NULL
;
455 int length
= GetFontData(hdc
, GDEF_TAG
, 0, NULL
, 0);
456 if (length
!= GDI_ERROR
)
458 GDEF_Table
= HeapAlloc(GetProcessHeap(),0,length
);
459 GetFontData(hdc
, GDEF_TAG
, 0, GDEF_Table
, length
);
460 TRACE("Loaded GDEF table of %i bytes\n",length
);
465 void OpenType_GDEF_UpdateGlyphProps(HDC hdc
, ScriptCache
*psc
, const WORD
*pwGlyphs
, const WORD cGlyphs
, WORD
* pwLogClust
, const WORD cChars
, SCRIPT_GLYPHPROP
*pGlyphProp
)
469 if (!psc
->GDEF_Table
)
470 psc
->GDEF_Table
= load_gdef_table(hdc
);
472 for (i
= 0; i
< cGlyphs
; i
++)
478 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
481 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
485 class = GDEF_get_glyph_class(psc
->GDEF_Table
, pwGlyphs
[i
]);
491 pGlyphProp
[i
].sva
.fClusterStart
= 1;
492 pGlyphProp
[i
].sva
.fDiacritic
= 0;
493 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
496 pGlyphProp
[i
].sva
.fClusterStart
= 1;
497 pGlyphProp
[i
].sva
.fDiacritic
= 0;
498 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
501 pGlyphProp
[i
].sva
.fClusterStart
= 0;
502 pGlyphProp
[i
].sva
.fDiacritic
= 1;
503 pGlyphProp
[i
].sva
.fZeroWidth
= 1;
506 pGlyphProp
[i
].sva
.fClusterStart
= 0;
507 pGlyphProp
[i
].sva
.fDiacritic
= 0;
508 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
511 ERR("Unknown glyph class %i\n",class);
512 pGlyphProp
[i
].sva
.fClusterStart
= 1;
513 pGlyphProp
[i
].sva
.fDiacritic
= 0;
514 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
518 pGlyphProp
[i
].sva
.fClusterStart
= 0;
525 static INT
GSUB_apply_lookup(const OT_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
);
527 static INT
GSUB_is_glyph_covered(LPCVOID table
, UINT glyph
)
529 const OT_CoverageFormat1
* cf1
;
533 if (GET_BE_WORD(cf1
->CoverageFormat
) == 1)
535 int count
= GET_BE_WORD(cf1
->GlyphCount
);
537 TRACE("Coverage Format 1, %i glyphs\n",count
);
538 for (i
= 0; i
< count
; i
++)
539 if (glyph
== GET_BE_WORD(cf1
->GlyphArray
[i
]))
543 else if (GET_BE_WORD(cf1
->CoverageFormat
) == 2)
545 const OT_CoverageFormat2
* cf2
;
548 cf2
= (const OT_CoverageFormat2
*)cf1
;
550 count
= GET_BE_WORD(cf2
->RangeCount
);
551 TRACE("Coverage Format 2, %i ranges\n",count
);
552 for (i
= 0; i
< count
; i
++)
554 if (glyph
< GET_BE_WORD(cf2
->RangeRecord
[i
].Start
))
556 if ((glyph
>= GET_BE_WORD(cf2
->RangeRecord
[i
].Start
)) &&
557 (glyph
<= GET_BE_WORD(cf2
->RangeRecord
[i
].End
)))
559 return (GET_BE_WORD(cf2
->RangeRecord
[i
].StartCoverageIndex
) +
560 glyph
- GET_BE_WORD(cf2
->RangeRecord
[i
].Start
));
566 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1
->CoverageFormat
));
571 static INT
GSUB_apply_SingleSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
574 TRACE("Single Substitution Subtable\n");
576 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
579 const GSUB_SingleSubstFormat1
*ssf1
;
580 offset
= GET_BE_WORD(look
->SubTable
[j
]);
581 ssf1
= (const GSUB_SingleSubstFormat1
*)((const BYTE
*)look
+offset
);
582 if (GET_BE_WORD(ssf1
->SubstFormat
) == 1)
584 int offset
= GET_BE_WORD(ssf1
->Coverage
);
585 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1
->DeltaGlyphID
));
586 if (GSUB_is_glyph_covered((const BYTE
*)ssf1
+offset
, glyphs
[glyph_index
]) != -1)
588 TRACE(" Glyph 0x%x ->",glyphs
[glyph_index
]);
589 glyphs
[glyph_index
] = glyphs
[glyph_index
] + GET_BE_WORD(ssf1
->DeltaGlyphID
);
590 TRACE(" 0x%x\n",glyphs
[glyph_index
]);
591 return glyph_index
+ write_dir
;
596 const GSUB_SingleSubstFormat2
*ssf2
;
600 ssf2
= (const GSUB_SingleSubstFormat2
*)ssf1
;
601 offset
= GET_BE_WORD(ssf1
->Coverage
);
602 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2
->GlyphCount
));
603 index
= GSUB_is_glyph_covered((const BYTE
*)ssf2
+offset
, glyphs
[glyph_index
]);
604 TRACE(" Coverage index %i\n",index
);
607 if (glyphs
[glyph_index
] == GET_BE_WORD(ssf2
->Substitute
[index
]))
608 return GSUB_E_NOGLYPH
;
610 TRACE(" Glyph is 0x%x ->",glyphs
[glyph_index
]);
611 glyphs
[glyph_index
] = GET_BE_WORD(ssf2
->Substitute
[index
]);
612 TRACE("0x%x\n",glyphs
[glyph_index
]);
613 return glyph_index
+ write_dir
;
617 return GSUB_E_NOGLYPH
;
620 static INT
GSUB_apply_MultipleSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
623 TRACE("Multiple Substitution Subtable\n");
625 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
628 const GSUB_MultipleSubstFormat1
*msf1
;
629 offset
= GET_BE_WORD(look
->SubTable
[j
]);
630 msf1
= (const GSUB_MultipleSubstFormat1
*)((const BYTE
*)look
+offset
);
632 offset
= GET_BE_WORD(msf1
->Coverage
);
633 index
= GSUB_is_glyph_covered((const BYTE
*)msf1
+offset
, glyphs
[glyph_index
]);
636 const GSUB_Sequence
*seq
;
639 offset
= GET_BE_WORD(msf1
->Sequence
[index
]);
640 seq
= (const GSUB_Sequence
*)((const BYTE
*)msf1
+offset
);
641 sub_count
= GET_BE_WORD(seq
->GlyphCount
);
642 TRACE(" Glyph 0x%x (+%i)->",glyphs
[glyph_index
],(sub_count
-1));
644 for (j
= (*glyph_count
)+(sub_count
-1); j
> glyph_index
; j
--)
645 glyphs
[j
] =glyphs
[j
-(sub_count
-1)];
647 for (j
= 0; j
< sub_count
; j
++)
649 glyphs
[glyph_index
+ (sub_count
-1) - j
] = GET_BE_WORD(seq
->Substitute
[j
]);
651 glyphs
[glyph_index
+ j
] = GET_BE_WORD(seq
->Substitute
[j
]);
653 *glyph_count
= *glyph_count
+ (sub_count
- 1);
655 if (TRACE_ON(uniscribe
))
657 for (j
= 0; j
< sub_count
; j
++)
658 TRACE(" 0x%x",glyphs
[glyph_index
+j
]);
662 return glyph_index
+ (sub_count
* write_dir
);
665 return GSUB_E_NOGLYPH
;
668 static INT
GSUB_apply_AlternateSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
671 TRACE("Alternate Substitution Subtable\n");
673 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
676 const GSUB_AlternateSubstFormat1
*asf1
;
679 offset
= GET_BE_WORD(look
->SubTable
[j
]);
680 asf1
= (const GSUB_AlternateSubstFormat1
*)((const BYTE
*)look
+offset
);
681 offset
= GET_BE_WORD(asf1
->Coverage
);
683 index
= GSUB_is_glyph_covered((const BYTE
*)asf1
+offset
, glyphs
[glyph_index
]);
686 const GSUB_AlternateSet
*as
;
687 offset
= GET_BE_WORD(asf1
->AlternateSet
[index
]);
688 as
= (const GSUB_AlternateSet
*)((const BYTE
*)asf1
+offset
);
689 FIXME("%i alternates, picking index 0\n",GET_BE_WORD(as
->GlyphCount
));
690 if (glyphs
[glyph_index
] == GET_BE_WORD(as
->Alternate
[0]))
691 return GSUB_E_NOGLYPH
;
693 TRACE(" Glyph 0x%x ->",glyphs
[glyph_index
]);
694 glyphs
[glyph_index
] = GET_BE_WORD(as
->Alternate
[0]);
695 TRACE(" 0x%x\n",glyphs
[glyph_index
]);
696 return glyph_index
+ write_dir
;
699 return GSUB_E_NOGLYPH
;
702 static INT
GSUB_apply_LigatureSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
706 TRACE("Ligature Substitution Subtable\n");
707 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
709 const GSUB_LigatureSubstFormat1
*lsf1
;
712 offset
= GET_BE_WORD(look
->SubTable
[j
]);
713 lsf1
= (const GSUB_LigatureSubstFormat1
*)((const BYTE
*)look
+offset
);
714 offset
= GET_BE_WORD(lsf1
->Coverage
);
715 index
= GSUB_is_glyph_covered((const BYTE
*)lsf1
+offset
, glyphs
[glyph_index
]);
716 TRACE(" Coverage index %i\n",index
);
719 const GSUB_LigatureSet
*ls
;
722 offset
= GET_BE_WORD(lsf1
->LigatureSet
[index
]);
723 ls
= (const GSUB_LigatureSet
*)((const BYTE
*)lsf1
+offset
);
724 count
= GET_BE_WORD(ls
->LigatureCount
);
725 TRACE(" LigatureSet has %i members\n",count
);
726 for (k
= 0; k
< count
; k
++)
728 const GSUB_Ligature
*lig
;
729 int CompCount
,l
,CompIndex
;
731 offset
= GET_BE_WORD(ls
->Ligature
[k
]);
732 lig
= (const GSUB_Ligature
*)((const BYTE
*)ls
+offset
);
733 CompCount
= GET_BE_WORD(lig
->CompCount
) - 1;
734 CompIndex
= glyph_index
+write_dir
;
735 for (l
= 0; l
< CompCount
&& CompIndex
>= 0 && CompIndex
< *glyph_count
; l
++)
738 CompGlyph
= GET_BE_WORD(lig
->Component
[l
]);
739 if (CompGlyph
!= glyphs
[CompIndex
])
741 CompIndex
+= write_dir
;
745 int replaceIdx
= glyph_index
;
747 replaceIdx
= glyph_index
- CompCount
;
749 TRACE(" Glyph is 0x%x (+%i) ->",glyphs
[glyph_index
],CompCount
);
750 glyphs
[replaceIdx
] = GET_BE_WORD(lig
->LigGlyph
);
751 TRACE("0x%x\n",glyphs
[replaceIdx
]);
755 for (j
= replaceIdx
+ 1; j
< *glyph_count
; j
++)
756 glyphs
[j
] =glyphs
[j
+CompCount
];
757 *glyph_count
= *glyph_count
- CompCount
;
759 return replaceIdx
+ write_dir
;
764 return GSUB_E_NOGLYPH
;
767 static INT
GSUB_apply_ChainContextSubst(const OT_LookupList
* lookup
, const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
772 TRACE("Chaining Contextual Substitution Subtable\n");
773 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
) && !done
; j
++)
775 const GSUB_ChainContextSubstFormat1
*ccsf1
;
777 int dirLookahead
= write_dir
;
778 int dirBacktrack
= -1 * write_dir
;
780 offset
= GET_BE_WORD(look
->SubTable
[j
]);
781 ccsf1
= (const GSUB_ChainContextSubstFormat1
*)((const BYTE
*)look
+offset
);
782 if (GET_BE_WORD(ccsf1
->SubstFormat
) == 1)
784 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
787 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 2)
789 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
792 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 3)
796 const GSUB_ChainContextSubstFormat3_1
*ccsf3_1
;
797 const GSUB_ChainContextSubstFormat3_2
*ccsf3_2
;
798 const GSUB_ChainContextSubstFormat3_3
*ccsf3_3
;
799 const GSUB_ChainContextSubstFormat3_4
*ccsf3_4
;
800 int newIndex
= glyph_index
;
802 ccsf3_1
= (const GSUB_ChainContextSubstFormat3_1
*)ccsf1
;
804 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
806 for (k
= 0; k
< GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
); k
++)
808 offset
= GET_BE_WORD(ccsf3_1
->Coverage
[k
]);
809 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (dirBacktrack
* (k
+1))]) == -1)
812 if (k
!= GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
))
814 TRACE("Matched Backtrack\n");
816 ccsf3_2
= (const GSUB_ChainContextSubstFormat3_2
*)(((LPBYTE
)ccsf1
)+sizeof(GSUB_ChainContextSubstFormat3_1
) + (sizeof(WORD
) * (GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
)-1)));
818 indexGlyphs
= GET_BE_WORD(ccsf3_2
->InputGlyphCount
);
819 for (k
= 0; k
< indexGlyphs
; k
++)
821 offset
= GET_BE_WORD(ccsf3_2
->Coverage
[k
]);
822 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (write_dir
* k
)]) == -1)
825 if (k
!= indexGlyphs
)
827 TRACE("Matched IndexGlyphs\n");
829 ccsf3_3
= (const GSUB_ChainContextSubstFormat3_3
*)(((LPBYTE
)ccsf3_2
)+sizeof(GSUB_ChainContextSubstFormat3_2
) + (sizeof(WORD
) * (GET_BE_WORD(ccsf3_2
->InputGlyphCount
)-1)));
831 for (k
= 0; k
< GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
); k
++)
833 offset
= GET_BE_WORD(ccsf3_3
->Coverage
[k
]);
834 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (dirLookahead
* (indexGlyphs
+ k
))]) == -1)
837 if (k
!= GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
))
839 TRACE("Matched LookAhead\n");
841 ccsf3_4
= (const GSUB_ChainContextSubstFormat3_4
*)(((LPBYTE
)ccsf3_3
)+sizeof(GSUB_ChainContextSubstFormat3_3
) + (sizeof(WORD
) * (GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
)-1)));
843 if (GET_BE_WORD(ccsf3_4
->SubstCount
))
845 for (k
= 0; k
< GET_BE_WORD(ccsf3_4
->SubstCount
); k
++)
847 int lookupIndex
= GET_BE_WORD(ccsf3_4
->SubstLookupRecord
[k
].LookupListIndex
);
848 int SequenceIndex
= GET_BE_WORD(ccsf3_4
->SubstLookupRecord
[k
].SequenceIndex
) * write_dir
;
850 TRACE("SUBST: %i -> %i %i\n",k
, SequenceIndex
, lookupIndex
);
851 newIndex
= GSUB_apply_lookup(lookup
, lookupIndex
, glyphs
, glyph_index
+ SequenceIndex
, write_dir
, glyph_count
);
854 ERR("Chain failed to generate a glyph\n");
860 else return GSUB_E_NOGLYPH
;
866 static INT
GSUB_apply_lookup(const OT_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
869 const OT_LookupTable
*look
;
871 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
872 look
= (const OT_LookupTable
*)((const BYTE
*)lookup
+ offset
);
873 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look
->LookupType
),GET_BE_WORD(look
->LookupFlag
),GET_BE_WORD(look
->SubTableCount
));
874 switch(GET_BE_WORD(look
->LookupType
))
877 return GSUB_apply_SingleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
879 return GSUB_apply_MultipleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
881 return GSUB_apply_AlternateSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
883 return GSUB_apply_LigatureSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
885 return GSUB_apply_ChainContextSubst(lookup
, look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
887 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look
->LookupType
));
889 return GSUB_E_NOGLYPH
;
892 INT
OpenType_apply_GSUB_lookup(LPCVOID table
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
894 const GSUB_Header
*header
= (const GSUB_Header
*)table
;
895 const OT_LookupList
*lookup
= (const OT_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
897 return GSUB_apply_lookup(lookup
, lookup_index
, glyphs
, glyph_index
, write_dir
, glyph_count
);
903 static INT
GPOS_get_device_table_value(const OT_DeviceTable
*DeviceTable
, WORD ppem
)
905 static const WORD mask
[3] = {3,0xf,0xff};
906 if (DeviceTable
&& ppem
>= GET_BE_WORD(DeviceTable
->StartSize
) && ppem
<= GET_BE_WORD(DeviceTable
->EndSize
))
908 int format
= GET_BE_WORD(DeviceTable
->DeltaFormat
);
909 int index
= ppem
- GET_BE_WORD(DeviceTable
->StartSize
);
911 TRACE("device table, format %i, index %i\n",format
, index
);
912 index
= index
<< format
;
913 value
= (DeviceTable
->DeltaValue
[index
/sizeof(WORD
)] << (index
%sizeof(WORD
)))&mask
[format
-1];
914 TRACE("offset %i, value %i\n",index
, value
);
915 if (value
> mask
[format
-1]/2)
916 value
= -1 * ((mask
[format
-1]+1) - value
);
922 static VOID
GPOS_get_anchor_values(LPCVOID table
, LPPOINT pt
, WORD ppem
)
924 const GPOS_AnchorFormat1
* anchor1
= (const GPOS_AnchorFormat1
*)table
;
926 switch (GET_BE_WORD(anchor1
->AnchorFormat
))
930 TRACE("Anchor Format 1\n");
931 pt
->x
= (short)GET_BE_WORD(anchor1
->XCoordinate
);
932 pt
->y
= (short)GET_BE_WORD(anchor1
->YCoordinate
);
937 const GPOS_AnchorFormat2
* anchor2
= (const GPOS_AnchorFormat2
*)table
;
938 TRACE("Anchor Format 2\n");
939 pt
->x
= (short)GET_BE_WORD(anchor2
->XCoordinate
);
940 pt
->y
= (short)GET_BE_WORD(anchor2
->YCoordinate
);
946 const GPOS_AnchorFormat3
* anchor3
= (const GPOS_AnchorFormat3
*)table
;
947 TRACE("Anchor Format 3\n");
948 pt
->x
= (short)GET_BE_WORD(anchor3
->XCoordinate
);
949 pt
->y
= (short)GET_BE_WORD(anchor3
->YCoordinate
);
950 offset
= GET_BE_WORD(anchor3
->XDeviceTable
);
951 TRACE("ppem %i\n",ppem
);
954 const OT_DeviceTable
* DeviceTableX
= NULL
;
955 DeviceTableX
= (const OT_DeviceTable
*)((const BYTE
*)anchor3
+ offset
);
956 pt
->x
+= GPOS_get_device_table_value(DeviceTableX
, ppem
);
958 offset
= GET_BE_WORD(anchor3
->YDeviceTable
);
961 const OT_DeviceTable
* DeviceTableY
= NULL
;
962 DeviceTableY
= (const OT_DeviceTable
*)((const BYTE
*)anchor3
+ offset
);
963 pt
->y
+= GPOS_get_device_table_value(DeviceTableY
, ppem
);
968 ERR("Unknown Anchor Format %i\n",GET_BE_WORD(anchor1
->AnchorFormat
));
974 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
)
977 const OT_LookupTable
*look
;
979 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
980 look
= (const OT_LookupTable
*)((const BYTE
*)lookup
+ offset
);
981 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look
->LookupType
),GET_BE_WORD(look
->LookupFlag
),GET_BE_WORD(look
->SubTableCount
));
982 switch(GET_BE_WORD(look
->LookupType
))
985 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look
->LookupType
));
987 return glyph_index
+1;
990 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
)
992 const GPOS_Header
*header
= (const GPOS_Header
*)table
;
993 const OT_LookupList
*lookup
= (const OT_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
995 return GPOS_apply_lookup(lpotm
, lplogfont
, piAdvance
, lookup
, lookup_index
, glyphs
, glyph_index
, write_dir
, glyph_count
, pGoffset
);
998 static void GSUB_initialize_script_cache(ScriptCache
*psc
)
1002 if (psc
->GSUB_Table
)
1004 const OT_ScriptList
*script
;
1005 const GSUB_Header
* header
= (const GSUB_Header
*)psc
->GSUB_Table
;
1006 script
= (const OT_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
1007 psc
->script_count
= GET_BE_WORD(script
->ScriptCount
);
1008 TRACE("initializing %i scripts in this font\n",psc
->script_count
);
1009 if (psc
->script_count
)
1011 psc
->scripts
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LoadedScript
) * psc
->script_count
);
1012 for (i
= 0; i
< psc
->script_count
; i
++)
1014 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
1015 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]);
1016 psc
->scripts
[i
].gsub_table
= ((const BYTE
*)script
+ offset
);
1022 static void GPOS_expand_script_cache(ScriptCache
*psc
)
1025 const OT_ScriptList
*script
;
1026 const GPOS_Header
* header
= (const GPOS_Header
*)psc
->GPOS_Table
;
1031 script
= (const OT_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
1032 count
= GET_BE_WORD(script
->ScriptCount
);
1034 if (!psc
->script_count
)
1036 psc
->script_count
= count
;
1037 TRACE("initializing %i scripts in this font\n",psc
->script_count
);
1038 if (psc
->script_count
)
1040 psc
->scripts
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LoadedScript
) * psc
->script_count
);
1041 for (i
= 0; i
< psc
->script_count
; i
++)
1043 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
1044 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]);
1045 psc
->scripts
[i
].gpos_table
= ((const BYTE
*)script
+ offset
);
1051 for (i
= 0; i
< count
; i
++)
1054 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
1055 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]);
1056 for (j
= 0; j
< psc
->script_count
; j
++)
1058 if (psc
->scripts
[j
].tag
== tag
)
1060 psc
->scripts
[j
].gpos_table
= ((const BYTE
*)script
+ offset
);
1064 if (j
== psc
->script_count
)
1066 psc
->script_count
++;
1067 psc
->scripts
= HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,psc
->scripts
, sizeof(LoadedScript
) * psc
->script_count
);
1068 psc
->scripts
[j
].tag
= tag
;
1069 psc
->scripts
[j
].gpos_table
= ((const BYTE
*)script
+ offset
);
1075 static void _initialize_script_cache(ScriptCache
*psc
)
1077 if (!psc
->script_count
)
1079 GSUB_initialize_script_cache(psc
);
1080 GPOS_expand_script_cache(psc
);
1084 HRESULT
OpenType_GetFontScriptTags(ScriptCache
*psc
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pScriptTags
, int *pcTags
)
1089 _initialize_script_cache(psc
);
1091 *pcTags
= psc
->script_count
;
1093 if (!searchingFor
&& cMaxTags
< *pcTags
)
1095 else if (searchingFor
)
1096 rc
= USP_E_SCRIPT_NOT_IN_FONT
;
1098 for (i
= 0; i
< psc
->script_count
; i
++)
1101 pScriptTags
[i
] = psc
->scripts
[i
].tag
;
1105 if (searchingFor
== psc
->scripts
[i
].tag
)
1107 pScriptTags
[0] = psc
->scripts
[i
].tag
;
1117 static void GSUB_initialize_language_cache(LoadedScript
*script
)
1121 if (script
->gsub_table
)
1124 const OT_Script
* table
= script
->gsub_table
;
1125 script
->language_count
= GET_BE_WORD(table
->LangSysCount
);
1126 offset
= GET_BE_WORD(table
->DefaultLangSys
);
1129 script
->default_language
.tag
= MS_MAKE_TAG('d','f','l','t');
1130 script
->default_language
.gsub_table
= (const BYTE
*)table
+ offset
;
1133 if (script
->language_count
)
1135 TRACE("Deflang %p, LangCount %i\n",script
->default_language
.gsub_table
, script
->language_count
);
1137 script
->languages
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LoadedLanguage
) * script
->language_count
);
1139 for (i
= 0; i
< script
->language_count
; i
++)
1141 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
1142 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]);
1143 script
->languages
[i
].gsub_table
= ((const BYTE
*)table
+ offset
);
1149 static void GPOS_expand_language_cache(LoadedScript
*script
)
1152 const OT_Script
* table
= script
->gpos_table
;
1158 offset
= GET_BE_WORD(table
->DefaultLangSys
);
1160 script
->default_language
.gpos_table
= (const BYTE
*)table
+ offset
;
1162 count
= GET_BE_WORD(table
->LangSysCount
);
1164 TRACE("Deflang %p, LangCount %i\n",script
->default_language
.gpos_table
, count
);
1165 if (!script
->language_count
)
1168 script
->language_count
= count
;
1170 script
->languages
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LoadedLanguage
) * script
->language_count
);
1172 for (i
= 0; i
< script
->language_count
; i
++)
1174 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
1175 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]);
1176 script
->languages
[i
].gpos_table
= ((const BYTE
*)table
+ offset
);
1182 for (i
= 0; i
< count
; i
++)
1184 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
1185 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]);
1187 for (j
= 0; j
< script
->language_count
; j
++)
1189 if (script
->languages
[j
].tag
== tag
)
1191 script
->languages
[j
].gpos_table
= ((const BYTE
*)table
+ offset
);
1195 if (j
== script
->language_count
)
1197 script
->language_count
++;
1198 script
->languages
= HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,script
->languages
, sizeof(LoadedLanguage
) * script
->language_count
);
1199 script
->languages
[j
].tag
= tag
;
1200 script
->languages
[j
].gpos_table
= ((const BYTE
*)table
+ offset
);
1206 static void _initialize_language_cache(LoadedScript
*script
)
1208 if (!script
->language_count
)
1210 GSUB_initialize_language_cache(script
);
1211 GPOS_expand_language_cache(script
);
1215 HRESULT
OpenType_GetFontLanguageTags(ScriptCache
*psc
, OPENTYPE_TAG script_tag
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pLanguageTags
, int *pcTags
)
1219 LoadedScript
*script
= NULL
;
1221 _initialize_script_cache(psc
);
1223 for (i
= 0; i
< psc
->script_count
; i
++)
1225 if (psc
->scripts
[i
].tag
== script_tag
)
1227 script
= &psc
->scripts
[i
];
1233 return E_INVALIDARG
;
1235 _initialize_language_cache(script
);
1237 if (!searchingFor
&& cMaxTags
< script
->language_count
)
1239 else if (searchingFor
)
1242 *pcTags
= script
->language_count
;
1244 for (i
= 0; i
< script
->language_count
; i
++)
1247 pLanguageTags
[i
] = script
->languages
[i
].tag
;
1251 if (searchingFor
== script
->languages
[i
].tag
)
1253 pLanguageTags
[0] = script
->languages
[i
].tag
;
1261 if (script
->default_language
.gsub_table
)
1264 pLanguageTags
[i
] = script
->default_language
.tag
;
1266 if (searchingFor
&& FAILED(rc
))
1268 pLanguageTags
[0] = script
->default_language
.tag
;
1271 *pcTags
= (*pcTags
) + 1;
1278 static void GSUB_initialize_feature_cache(LPCVOID table
, LoadedLanguage
*language
)
1282 if (language
->gsub_table
)
1284 const OT_LangSys
*lang
= language
->gsub_table
;
1285 const GSUB_Header
*header
= (const GSUB_Header
*)table
;
1286 const OT_FeatureList
*feature_list
;
1288 language
->feature_count
= GET_BE_WORD(lang
->FeatureCount
);
1289 TRACE("%i features\n",language
->feature_count
);
1291 if (language
->feature_count
)
1293 language
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(LoadedFeature
)*language
->feature_count
);
1295 feature_list
= (const OT_FeatureList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->FeatureList
));
1297 for (i
= 0; i
< language
->feature_count
; i
++)
1299 const OT_Feature
*feature
;
1301 int index
= GET_BE_WORD(lang
->FeatureIndex
[i
]);
1303 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]);
1304 language
->features
[i
].feature
= ((const BYTE
*)feature_list
+ GET_BE_WORD(feature_list
->FeatureRecord
[index
].Feature
));
1305 feature
= (const OT_Feature
*)language
->features
[i
].feature
;
1306 language
->features
[i
].lookup_count
= GET_BE_WORD(feature
->LookupCount
);
1307 language
->features
[i
].lookups
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
) * language
->features
[i
].lookup_count
);
1308 for (j
= 0; j
< language
->features
[i
].lookup_count
; j
++)
1309 language
->features
[i
].lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
1315 static void GPOS_expand_feature_cache(LPCVOID table
, LoadedLanguage
*language
)
1318 const OT_LangSys
*lang
= language
->gpos_table
;
1319 const GPOS_Header
*header
= (const GPOS_Header
*)table
;
1320 const OT_FeatureList
*feature_list
;
1325 count
= GET_BE_WORD(lang
->FeatureCount
);
1326 feature_list
= (const OT_FeatureList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->FeatureList
));
1328 TRACE("%i features\n",count
);
1329 if (!language
->feature_count
)
1331 language
->feature_count
= count
;
1333 if (language
->feature_count
)
1335 language
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(LoadedFeature
)*language
->feature_count
);
1337 for (i
= 0; i
< language
->feature_count
; i
++)
1339 const OT_Feature
*feature
;
1341 int index
= GET_BE_WORD(lang
->FeatureIndex
[i
]);
1343 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]);
1344 language
->features
[i
].feature
= ((const BYTE
*)feature_list
+ GET_BE_WORD(feature_list
->FeatureRecord
[index
].Feature
));
1345 feature
= (const OT_Feature
*)language
->features
[i
].feature
;
1346 language
->features
[i
].lookup_count
= GET_BE_WORD(feature
->LookupCount
);
1347 language
->features
[i
].lookups
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
) * language
->features
[i
].lookup_count
);
1348 for (j
= 0; j
< language
->features
[i
].lookup_count
; j
++)
1349 language
->features
[i
].lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
1355 language
->features
= HeapReAlloc(GetProcessHeap(),0,language
->features
, sizeof(LoadedFeature
)*(language
->feature_count
+ count
));
1357 for (i
= 0; i
< count
; i
++)
1359 const OT_Feature
*feature
;
1361 int index
= GET_BE_WORD(lang
->FeatureIndex
[i
]);
1362 int idx
= language
->feature_count
+ i
;
1364 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]);
1365 language
->features
[idx
].feature
= ((const BYTE
*)feature_list
+ GET_BE_WORD(feature_list
->FeatureRecord
[index
].Feature
));
1366 feature
= (const OT_Feature
*)language
->features
[idx
].feature
;
1367 language
->features
[idx
].lookup_count
= GET_BE_WORD(feature
->LookupCount
);
1368 language
->features
[idx
].lookups
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
) * language
->features
[idx
].lookup_count
);
1369 for (j
= 0; j
< language
->features
[idx
].lookup_count
; j
++)
1370 language
->features
[idx
].lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
1372 language
->feature_count
+= count
;
1376 static void _initialize_feature_cache(ScriptCache
*psc
, LoadedLanguage
*language
)
1378 if (!language
->feature_count
)
1380 GSUB_initialize_feature_cache(psc
->GSUB_Table
, language
);
1381 GPOS_expand_feature_cache(psc
->GPOS_Table
, language
);
1385 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
)
1389 LoadedScript
*script
= NULL
;
1390 LoadedLanguage
*language
= NULL
;
1392 _initialize_script_cache(psc
);
1394 for (i
= 0; i
< psc
->script_count
; i
++)
1396 if (psc
->scripts
[i
].tag
== script_tag
)
1398 script
= &psc
->scripts
[i
];
1409 return E_INVALIDARG
;
1412 _initialize_language_cache(script
);
1414 if ((script
->default_language
.gsub_table
|| script
->default_language
.gpos_table
) && script
->default_language
.tag
== language_tag
)
1415 language
= &script
->default_language
;
1418 for (i
= 0; i
< script
->language_count
; i
++)
1420 if (script
->languages
[i
].tag
== language_tag
)
1422 language
= &script
->languages
[i
];
1434 _initialize_feature_cache(psc
, language
);
1436 *pcTags
= language
->feature_count
;
1438 if (!searchingFor
&& cMaxTags
< *pcTags
)
1440 else if (searchingFor
)
1443 for (i
= 0; i
< language
->feature_count
; i
++)
1446 pFeatureTags
[i
] = language
->features
[i
].tag
;
1450 if (searchingFor
== language
->features
[i
].tag
)
1452 pFeatureTags
[0] = language
->features
[i
].tag
;
1455 *feature
= &language
->features
[i
];