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
;
324 } GPOS_MarkBasePosFormat1
;
332 GPOS_BaseRecord BaseRecord
[1];
342 GPOS_MarkRecord MarkRecord
[1];
349 static VOID
*load_CMAP_format12_table(HDC hdc
, ScriptCache
*psc
)
351 CMAP_Header
*CMAP_Table
= NULL
;
355 if (!psc
->CMAP_Table
)
357 length
= GetFontData(hdc
, CMAP_TAG
, 0, NULL
, 0);
358 if (length
!= GDI_ERROR
)
360 psc
->CMAP_Table
= HeapAlloc(GetProcessHeap(),0,length
);
361 GetFontData(hdc
, CMAP_TAG
, 0, psc
->CMAP_Table
, length
);
362 TRACE("Loaded cmap table of %i bytes\n",length
);
368 CMAP_Table
= psc
->CMAP_Table
;
370 for (i
= 0; i
< GET_BE_WORD(CMAP_Table
->numTables
); i
++)
372 if ( (GET_BE_WORD(CMAP_Table
->tables
[i
].platformID
) == 3) &&
373 (GET_BE_WORD(CMAP_Table
->tables
[i
].encodingID
) == 10) )
375 CMAP_SegmentedCoverage
*format
= (CMAP_SegmentedCoverage
*)(((BYTE
*)CMAP_Table
) + GET_BE_DWORD(CMAP_Table
->tables
[i
].offset
));
376 if (GET_BE_WORD(format
->format
) == 12)
383 static int compare_group(const void *a
, const void* b
)
385 const DWORD
*chr
= a
;
386 const CMAP_SegmentedCoverage_group
*group
= b
;
388 if (*chr
< GET_BE_DWORD(group
->startCharCode
))
390 if (*chr
> GET_BE_DWORD(group
->endCharCode
))
395 DWORD
OpenType_CMAP_GetGlyphIndex(HDC hdc
, ScriptCache
*psc
, DWORD utf32c
, LPWORD pgi
, DWORD flags
)
397 /* BMP: use gdi32 for ease */
398 if (utf32c
< 0x10000)
401 return GetGlyphIndicesW(hdc
,&ch
, 1, pgi
, flags
);
404 if (!psc
->CMAP_format12_Table
)
405 psc
->CMAP_format12_Table
= load_CMAP_format12_table(hdc
, psc
);
407 if (flags
& GGI_MARK_NONEXISTING_GLYPHS
)
412 if (psc
->CMAP_format12_Table
)
414 CMAP_SegmentedCoverage
*format
= NULL
;
415 CMAP_SegmentedCoverage_group
*group
= NULL
;
417 format
= (CMAP_SegmentedCoverage
*)psc
->CMAP_format12_Table
;
419 group
= bsearch(&utf32c
, format
->groups
, GET_BE_DWORD(format
->nGroups
),
420 sizeof(CMAP_SegmentedCoverage_group
), compare_group
);
424 DWORD offset
= utf32c
- GET_BE_DWORD(group
->startCharCode
);
425 *pgi
= GET_BE_DWORD(group
->startGlyphID
) + offset
;
436 static WORD
GDEF_get_glyph_class(const GDEF_Header
*header
, WORD glyph
)
440 const GDEF_ClassDefFormat1
*cf1
;
445 offset
= GET_BE_WORD(header
->GlyphClassDef
);
449 cf1
= (GDEF_ClassDefFormat1
*)(((BYTE
*)header
)+offset
);
450 if (GET_BE_WORD(cf1
->ClassFormat
) == 1)
452 if (glyph
>= GET_BE_WORD(cf1
->StartGlyph
))
454 int index
= glyph
- GET_BE_WORD(cf1
->StartGlyph
);
455 if (index
< GET_BE_WORD(cf1
->GlyphCount
))
456 class = GET_BE_WORD(cf1
->ClassValueArray
[index
]);
459 else if (GET_BE_WORD(cf1
->ClassFormat
) == 2)
461 const GDEF_ClassDefFormat2
*cf2
= (GDEF_ClassDefFormat2
*)cf1
;
463 top
= GET_BE_WORD(cf2
->ClassRangeCount
);
464 for (i
= 0; i
< top
; i
++)
466 if (glyph
>= GET_BE_WORD(cf2
->ClassRangeRecord
[i
].Start
) &&
467 glyph
<= GET_BE_WORD(cf2
->ClassRangeRecord
[i
].End
))
469 class = GET_BE_WORD(cf2
->ClassRangeRecord
[i
].Class
);
475 ERR("Unknown Class Format %i\n",GET_BE_WORD(cf1
->ClassFormat
));
480 static VOID
*load_gdef_table(HDC hdc
)
482 VOID
* GDEF_Table
= NULL
;
483 int length
= GetFontData(hdc
, GDEF_TAG
, 0, NULL
, 0);
484 if (length
!= GDI_ERROR
)
486 GDEF_Table
= HeapAlloc(GetProcessHeap(),0,length
);
487 GetFontData(hdc
, GDEF_TAG
, 0, GDEF_Table
, length
);
488 TRACE("Loaded GDEF table of %i bytes\n",length
);
493 void OpenType_GDEF_UpdateGlyphProps(HDC hdc
, ScriptCache
*psc
, const WORD
*pwGlyphs
, const WORD cGlyphs
, WORD
* pwLogClust
, const WORD cChars
, SCRIPT_GLYPHPROP
*pGlyphProp
)
497 if (!psc
->GDEF_Table
)
498 psc
->GDEF_Table
= load_gdef_table(hdc
);
500 for (i
= 0; i
< cGlyphs
; i
++)
506 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
509 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
513 class = GDEF_get_glyph_class(psc
->GDEF_Table
, pwGlyphs
[i
]);
519 pGlyphProp
[i
].sva
.fClusterStart
= 1;
520 pGlyphProp
[i
].sva
.fDiacritic
= 0;
521 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
524 pGlyphProp
[i
].sva
.fClusterStart
= 1;
525 pGlyphProp
[i
].sva
.fDiacritic
= 0;
526 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
529 pGlyphProp
[i
].sva
.fClusterStart
= 0;
530 pGlyphProp
[i
].sva
.fDiacritic
= 1;
531 pGlyphProp
[i
].sva
.fZeroWidth
= 1;
534 pGlyphProp
[i
].sva
.fClusterStart
= 0;
535 pGlyphProp
[i
].sva
.fDiacritic
= 0;
536 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
539 ERR("Unknown glyph class %i\n",class);
540 pGlyphProp
[i
].sva
.fClusterStart
= 1;
541 pGlyphProp
[i
].sva
.fDiacritic
= 0;
542 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
546 pGlyphProp
[i
].sva
.fClusterStart
= 0;
553 static INT
GSUB_apply_lookup(const OT_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
);
555 static INT
GSUB_is_glyph_covered(LPCVOID table
, UINT glyph
)
557 const OT_CoverageFormat1
* cf1
;
561 if (GET_BE_WORD(cf1
->CoverageFormat
) == 1)
563 int count
= GET_BE_WORD(cf1
->GlyphCount
);
565 TRACE("Coverage Format 1, %i glyphs\n",count
);
566 for (i
= 0; i
< count
; i
++)
567 if (glyph
== GET_BE_WORD(cf1
->GlyphArray
[i
]))
571 else if (GET_BE_WORD(cf1
->CoverageFormat
) == 2)
573 const OT_CoverageFormat2
* cf2
;
576 cf2
= (const OT_CoverageFormat2
*)cf1
;
578 count
= GET_BE_WORD(cf2
->RangeCount
);
579 TRACE("Coverage Format 2, %i ranges\n",count
);
580 for (i
= 0; i
< count
; i
++)
582 if (glyph
< GET_BE_WORD(cf2
->RangeRecord
[i
].Start
))
584 if ((glyph
>= GET_BE_WORD(cf2
->RangeRecord
[i
].Start
)) &&
585 (glyph
<= GET_BE_WORD(cf2
->RangeRecord
[i
].End
)))
587 return (GET_BE_WORD(cf2
->RangeRecord
[i
].StartCoverageIndex
) +
588 glyph
- GET_BE_WORD(cf2
->RangeRecord
[i
].Start
));
594 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1
->CoverageFormat
));
599 static INT
GSUB_apply_SingleSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
602 TRACE("Single Substitution Subtable\n");
604 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
607 const GSUB_SingleSubstFormat1
*ssf1
;
608 offset
= GET_BE_WORD(look
->SubTable
[j
]);
609 ssf1
= (const GSUB_SingleSubstFormat1
*)((const BYTE
*)look
+offset
);
610 if (GET_BE_WORD(ssf1
->SubstFormat
) == 1)
612 int offset
= GET_BE_WORD(ssf1
->Coverage
);
613 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1
->DeltaGlyphID
));
614 if (GSUB_is_glyph_covered((const BYTE
*)ssf1
+offset
, glyphs
[glyph_index
]) != -1)
616 TRACE(" Glyph 0x%x ->",glyphs
[glyph_index
]);
617 glyphs
[glyph_index
] = glyphs
[glyph_index
] + GET_BE_WORD(ssf1
->DeltaGlyphID
);
618 TRACE(" 0x%x\n",glyphs
[glyph_index
]);
619 return glyph_index
+ write_dir
;
624 const GSUB_SingleSubstFormat2
*ssf2
;
628 ssf2
= (const GSUB_SingleSubstFormat2
*)ssf1
;
629 offset
= GET_BE_WORD(ssf1
->Coverage
);
630 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2
->GlyphCount
));
631 index
= GSUB_is_glyph_covered((const BYTE
*)ssf2
+offset
, glyphs
[glyph_index
]);
632 TRACE(" Coverage index %i\n",index
);
635 if (glyphs
[glyph_index
] == GET_BE_WORD(ssf2
->Substitute
[index
]))
636 return GSUB_E_NOGLYPH
;
638 TRACE(" Glyph is 0x%x ->",glyphs
[glyph_index
]);
639 glyphs
[glyph_index
] = GET_BE_WORD(ssf2
->Substitute
[index
]);
640 TRACE("0x%x\n",glyphs
[glyph_index
]);
641 return glyph_index
+ write_dir
;
645 return GSUB_E_NOGLYPH
;
648 static INT
GSUB_apply_MultipleSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
651 TRACE("Multiple Substitution Subtable\n");
653 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
656 const GSUB_MultipleSubstFormat1
*msf1
;
657 offset
= GET_BE_WORD(look
->SubTable
[j
]);
658 msf1
= (const GSUB_MultipleSubstFormat1
*)((const BYTE
*)look
+offset
);
660 offset
= GET_BE_WORD(msf1
->Coverage
);
661 index
= GSUB_is_glyph_covered((const BYTE
*)msf1
+offset
, glyphs
[glyph_index
]);
664 const GSUB_Sequence
*seq
;
667 offset
= GET_BE_WORD(msf1
->Sequence
[index
]);
668 seq
= (const GSUB_Sequence
*)((const BYTE
*)msf1
+offset
);
669 sub_count
= GET_BE_WORD(seq
->GlyphCount
);
670 TRACE(" Glyph 0x%x (+%i)->",glyphs
[glyph_index
],(sub_count
-1));
672 for (j
= (*glyph_count
)+(sub_count
-1); j
> glyph_index
; j
--)
673 glyphs
[j
] =glyphs
[j
-(sub_count
-1)];
675 for (j
= 0; j
< sub_count
; j
++)
677 glyphs
[glyph_index
+ (sub_count
-1) - j
] = GET_BE_WORD(seq
->Substitute
[j
]);
679 glyphs
[glyph_index
+ j
] = GET_BE_WORD(seq
->Substitute
[j
]);
681 *glyph_count
= *glyph_count
+ (sub_count
- 1);
683 if (TRACE_ON(uniscribe
))
685 for (j
= 0; j
< sub_count
; j
++)
686 TRACE(" 0x%x",glyphs
[glyph_index
+j
]);
690 return glyph_index
+ (sub_count
* write_dir
);
693 return GSUB_E_NOGLYPH
;
696 static INT
GSUB_apply_AlternateSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
699 TRACE("Alternate Substitution Subtable\n");
701 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
704 const GSUB_AlternateSubstFormat1
*asf1
;
707 offset
= GET_BE_WORD(look
->SubTable
[j
]);
708 asf1
= (const GSUB_AlternateSubstFormat1
*)((const BYTE
*)look
+offset
);
709 offset
= GET_BE_WORD(asf1
->Coverage
);
711 index
= GSUB_is_glyph_covered((const BYTE
*)asf1
+offset
, glyphs
[glyph_index
]);
714 const GSUB_AlternateSet
*as
;
715 offset
= GET_BE_WORD(asf1
->AlternateSet
[index
]);
716 as
= (const GSUB_AlternateSet
*)((const BYTE
*)asf1
+offset
);
717 FIXME("%i alternates, picking index 0\n",GET_BE_WORD(as
->GlyphCount
));
718 if (glyphs
[glyph_index
] == GET_BE_WORD(as
->Alternate
[0]))
719 return GSUB_E_NOGLYPH
;
721 TRACE(" Glyph 0x%x ->",glyphs
[glyph_index
]);
722 glyphs
[glyph_index
] = GET_BE_WORD(as
->Alternate
[0]);
723 TRACE(" 0x%x\n",glyphs
[glyph_index
]);
724 return glyph_index
+ write_dir
;
727 return GSUB_E_NOGLYPH
;
730 static INT
GSUB_apply_LigatureSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
734 TRACE("Ligature Substitution Subtable\n");
735 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
737 const GSUB_LigatureSubstFormat1
*lsf1
;
740 offset
= GET_BE_WORD(look
->SubTable
[j
]);
741 lsf1
= (const GSUB_LigatureSubstFormat1
*)((const BYTE
*)look
+offset
);
742 offset
= GET_BE_WORD(lsf1
->Coverage
);
743 index
= GSUB_is_glyph_covered((const BYTE
*)lsf1
+offset
, glyphs
[glyph_index
]);
744 TRACE(" Coverage index %i\n",index
);
747 const GSUB_LigatureSet
*ls
;
750 offset
= GET_BE_WORD(lsf1
->LigatureSet
[index
]);
751 ls
= (const GSUB_LigatureSet
*)((const BYTE
*)lsf1
+offset
);
752 count
= GET_BE_WORD(ls
->LigatureCount
);
753 TRACE(" LigatureSet has %i members\n",count
);
754 for (k
= 0; k
< count
; k
++)
756 const GSUB_Ligature
*lig
;
757 int CompCount
,l
,CompIndex
;
759 offset
= GET_BE_WORD(ls
->Ligature
[k
]);
760 lig
= (const GSUB_Ligature
*)((const BYTE
*)ls
+offset
);
761 CompCount
= GET_BE_WORD(lig
->CompCount
) - 1;
762 CompIndex
= glyph_index
+write_dir
;
763 for (l
= 0; l
< CompCount
&& CompIndex
>= 0 && CompIndex
< *glyph_count
; l
++)
766 CompGlyph
= GET_BE_WORD(lig
->Component
[l
]);
767 if (CompGlyph
!= glyphs
[CompIndex
])
769 CompIndex
+= write_dir
;
773 int replaceIdx
= glyph_index
;
775 replaceIdx
= glyph_index
- CompCount
;
777 TRACE(" Glyph is 0x%x (+%i) ->",glyphs
[glyph_index
],CompCount
);
778 glyphs
[replaceIdx
] = GET_BE_WORD(lig
->LigGlyph
);
779 TRACE("0x%x\n",glyphs
[replaceIdx
]);
783 for (j
= replaceIdx
+ 1; j
< *glyph_count
; j
++)
784 glyphs
[j
] =glyphs
[j
+CompCount
];
785 *glyph_count
= *glyph_count
- CompCount
;
787 return replaceIdx
+ write_dir
;
792 return GSUB_E_NOGLYPH
;
795 static INT
GSUB_apply_ChainContextSubst(const OT_LookupList
* lookup
, const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
800 TRACE("Chaining Contextual Substitution Subtable\n");
801 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
) && !done
; j
++)
803 const GSUB_ChainContextSubstFormat1
*ccsf1
;
805 int dirLookahead
= write_dir
;
806 int dirBacktrack
= -1 * write_dir
;
808 offset
= GET_BE_WORD(look
->SubTable
[j
]);
809 ccsf1
= (const GSUB_ChainContextSubstFormat1
*)((const BYTE
*)look
+offset
);
810 if (GET_BE_WORD(ccsf1
->SubstFormat
) == 1)
812 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
815 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 2)
817 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
820 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 3)
824 const GSUB_ChainContextSubstFormat3_1
*ccsf3_1
;
825 const GSUB_ChainContextSubstFormat3_2
*ccsf3_2
;
826 const GSUB_ChainContextSubstFormat3_3
*ccsf3_3
;
827 const GSUB_ChainContextSubstFormat3_4
*ccsf3_4
;
828 int newIndex
= glyph_index
;
830 ccsf3_1
= (const GSUB_ChainContextSubstFormat3_1
*)ccsf1
;
832 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
834 for (k
= 0; k
< GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
); k
++)
836 offset
= GET_BE_WORD(ccsf3_1
->Coverage
[k
]);
837 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (dirBacktrack
* (k
+1))]) == -1)
840 if (k
!= GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
))
842 TRACE("Matched Backtrack\n");
844 ccsf3_2
= (const GSUB_ChainContextSubstFormat3_2
*)(((LPBYTE
)ccsf1
)+sizeof(GSUB_ChainContextSubstFormat3_1
) + (sizeof(WORD
) * (GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
)-1)));
846 indexGlyphs
= GET_BE_WORD(ccsf3_2
->InputGlyphCount
);
847 for (k
= 0; k
< indexGlyphs
; k
++)
849 offset
= GET_BE_WORD(ccsf3_2
->Coverage
[k
]);
850 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (write_dir
* k
)]) == -1)
853 if (k
!= indexGlyphs
)
855 TRACE("Matched IndexGlyphs\n");
857 ccsf3_3
= (const GSUB_ChainContextSubstFormat3_3
*)(((LPBYTE
)ccsf3_2
)+sizeof(GSUB_ChainContextSubstFormat3_2
) + (sizeof(WORD
) * (GET_BE_WORD(ccsf3_2
->InputGlyphCount
)-1)));
859 for (k
= 0; k
< GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
); k
++)
861 offset
= GET_BE_WORD(ccsf3_3
->Coverage
[k
]);
862 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (dirLookahead
* (indexGlyphs
+ k
))]) == -1)
865 if (k
!= GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
))
867 TRACE("Matched LookAhead\n");
869 ccsf3_4
= (const GSUB_ChainContextSubstFormat3_4
*)(((LPBYTE
)ccsf3_3
)+sizeof(GSUB_ChainContextSubstFormat3_3
) + (sizeof(WORD
) * (GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
)-1)));
871 if (GET_BE_WORD(ccsf3_4
->SubstCount
))
873 for (k
= 0; k
< GET_BE_WORD(ccsf3_4
->SubstCount
); k
++)
875 int lookupIndex
= GET_BE_WORD(ccsf3_4
->SubstLookupRecord
[k
].LookupListIndex
);
876 int SequenceIndex
= GET_BE_WORD(ccsf3_4
->SubstLookupRecord
[k
].SequenceIndex
) * write_dir
;
878 TRACE("SUBST: %i -> %i %i\n",k
, SequenceIndex
, lookupIndex
);
879 newIndex
= GSUB_apply_lookup(lookup
, lookupIndex
, glyphs
, glyph_index
+ SequenceIndex
, write_dir
, glyph_count
);
882 ERR("Chain failed to generate a glyph\n");
888 else return GSUB_E_NOGLYPH
;
894 static INT
GSUB_apply_lookup(const OT_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
897 const OT_LookupTable
*look
;
899 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
900 look
= (const OT_LookupTable
*)((const BYTE
*)lookup
+ offset
);
901 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look
->LookupType
),GET_BE_WORD(look
->LookupFlag
),GET_BE_WORD(look
->SubTableCount
));
902 switch(GET_BE_WORD(look
->LookupType
))
905 return GSUB_apply_SingleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
907 return GSUB_apply_MultipleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
909 return GSUB_apply_AlternateSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
911 return GSUB_apply_LigatureSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
913 return GSUB_apply_ChainContextSubst(lookup
, look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
915 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look
->LookupType
));
917 return GSUB_E_NOGLYPH
;
920 INT
OpenType_apply_GSUB_lookup(LPCVOID table
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
922 const GSUB_Header
*header
= (const GSUB_Header
*)table
;
923 const OT_LookupList
*lookup
= (const OT_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
925 return GSUB_apply_lookup(lookup
, lookup_index
, glyphs
, glyph_index
, write_dir
, glyph_count
);
931 static INT
GPOS_get_device_table_value(const OT_DeviceTable
*DeviceTable
, WORD ppem
)
933 static const WORD mask
[3] = {3,0xf,0xff};
934 if (DeviceTable
&& ppem
>= GET_BE_WORD(DeviceTable
->StartSize
) && ppem
<= GET_BE_WORD(DeviceTable
->EndSize
))
936 int format
= GET_BE_WORD(DeviceTable
->DeltaFormat
);
937 int index
= ppem
- GET_BE_WORD(DeviceTable
->StartSize
);
939 TRACE("device table, format %i, index %i\n",format
, index
);
940 index
= index
<< format
;
941 value
= (DeviceTable
->DeltaValue
[index
/sizeof(WORD
)] << (index
%sizeof(WORD
)))&mask
[format
-1];
942 TRACE("offset %i, value %i\n",index
, value
);
943 if (value
> mask
[format
-1]/2)
944 value
= -1 * ((mask
[format
-1]+1) - value
);
950 static VOID
GPOS_get_anchor_values(LPCVOID table
, LPPOINT pt
, WORD ppem
)
952 const GPOS_AnchorFormat1
* anchor1
= (const GPOS_AnchorFormat1
*)table
;
954 switch (GET_BE_WORD(anchor1
->AnchorFormat
))
958 TRACE("Anchor Format 1\n");
959 pt
->x
= (short)GET_BE_WORD(anchor1
->XCoordinate
);
960 pt
->y
= (short)GET_BE_WORD(anchor1
->YCoordinate
);
965 const GPOS_AnchorFormat2
* anchor2
= (const GPOS_AnchorFormat2
*)table
;
966 TRACE("Anchor Format 2\n");
967 pt
->x
= (short)GET_BE_WORD(anchor2
->XCoordinate
);
968 pt
->y
= (short)GET_BE_WORD(anchor2
->YCoordinate
);
974 const GPOS_AnchorFormat3
* anchor3
= (const GPOS_AnchorFormat3
*)table
;
975 TRACE("Anchor Format 3\n");
976 pt
->x
= (short)GET_BE_WORD(anchor3
->XCoordinate
);
977 pt
->y
= (short)GET_BE_WORD(anchor3
->YCoordinate
);
978 offset
= GET_BE_WORD(anchor3
->XDeviceTable
);
979 TRACE("ppem %i\n",ppem
);
982 const OT_DeviceTable
* DeviceTableX
= NULL
;
983 DeviceTableX
= (const OT_DeviceTable
*)((const BYTE
*)anchor3
+ offset
);
984 pt
->x
+= GPOS_get_device_table_value(DeviceTableX
, ppem
);
986 offset
= GET_BE_WORD(anchor3
->YDeviceTable
);
989 const OT_DeviceTable
* DeviceTableY
= NULL
;
990 DeviceTableY
= (const OT_DeviceTable
*)((const BYTE
*)anchor3
+ offset
);
991 pt
->y
+= GPOS_get_device_table_value(DeviceTableY
, ppem
);
996 ERR("Unknown Anchor Format %i\n",GET_BE_WORD(anchor1
->AnchorFormat
));
1002 static void GPOS_convert_design_units_to_device(LPOUTLINETEXTMETRICW lpotm
, LPLOGFONTW lplogfont
, int desX
, int desY
, double *devX
, double *devY
)
1004 int emHeight
= lpotm
->otmTextMetrics
.tmAscent
+ lpotm
->otmTextMetrics
.tmDescent
- lpotm
->otmTextMetrics
.tmInternalLeading
;
1006 TRACE("emHeight %i lfWidth %i\n",emHeight
, lplogfont
->lfWidth
);
1007 *devX
= (desX
* emHeight
) / (double)lpotm
->otmEMSquare
;
1008 *devY
= (desY
* emHeight
) / (double)lpotm
->otmEMSquare
;
1009 if (lplogfont
->lfWidth
)
1010 FIXME("Font with lfWidth set no handled properly\n");
1013 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
)
1017 TRACE("MarkToBase Attachment Positioning Subtable\n");
1019 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1022 const GPOS_MarkBasePosFormat1
*mbpf1
;
1023 offset
= GET_BE_WORD(look
->SubTable
[j
]);
1024 mbpf1
= (const GPOS_MarkBasePosFormat1
*)((const BYTE
*)look
+offset
);
1025 if (GET_BE_WORD(mbpf1
->PosFormat
) == 1)
1027 int offset
= GET_BE_WORD(mbpf1
->MarkCoverage
);
1029 mark_index
= GSUB_is_glyph_covered((const BYTE
*)mbpf1
+offset
, glyphs
[glyph_index
]);
1030 if (mark_index
!= -1)
1033 offset
= GET_BE_WORD(mbpf1
->BaseCoverage
);
1034 base_index
= GSUB_is_glyph_covered((const BYTE
*)mbpf1
+offset
, glyphs
[glyph_index
- write_dir
]);
1035 if (base_index
!= -1)
1037 const GPOS_MarkArray
*ma
;
1038 const GPOS_MarkRecord
*mr
;
1039 const GPOS_BaseArray
*ba
;
1040 const GPOS_BaseRecord
*br
;
1042 int class_count
= GET_BE_WORD(mbpf1
->ClassCount
);
1043 int baserecord_size
;
1046 TRACE("Mark %x(%i) and base %x(%i)\n",glyphs
[glyph_index
], mark_index
, glyphs
[glyph_index
- write_dir
], base_index
);
1047 offset
= GET_BE_WORD(mbpf1
->MarkArray
);
1048 ma
= (const GPOS_MarkArray
*)((const BYTE
*)mbpf1
+ offset
);
1049 if (mark_index
> GET_BE_WORD(ma
->MarkCount
))
1051 ERR("Mark index exeeded mark count\n");
1054 mr
= &ma
->MarkRecord
[mark_index
];
1055 mark_class
= GET_BE_WORD(mr
->Class
);
1056 TRACE("Mark Class %i total classes %i\n",mark_class
,class_count
);
1057 offset
= GET_BE_WORD(mbpf1
->BaseArray
);
1058 ba
= (const GPOS_BaseArray
*)((const BYTE
*)mbpf1
+ offset
);
1059 baserecord_size
= class_count
* sizeof(WORD
);
1060 br
= (const GPOS_BaseRecord
*)((const BYTE
*)ba
+ sizeof(WORD
) + (baserecord_size
* base_index
));
1061 offset
= GET_BE_WORD(br
->BaseAnchor
[mark_class
]);
1062 GPOS_get_anchor_values((const BYTE
*)ba
+ offset
, &base_pt
, ppem
);
1063 offset
= GET_BE_WORD(mr
->MarkAnchor
);
1064 GPOS_get_anchor_values((const BYTE
*)ma
+ offset
, &mark_pt
, ppem
);
1065 TRACE("Offset on base is %i,%i design units\n",base_pt
.x
,base_pt
.y
);
1066 TRACE("Offset on mark is %i,%i design units\n",mark_pt
.x
, mark_pt
.y
);
1067 pt
->x
+= base_pt
.x
- mark_pt
.x
;
1068 pt
->y
+= base_pt
.y
- mark_pt
.y
;
1069 TRACE("Resulting cumulative offset is %i,%i design units\n",pt
->x
,pt
->y
);
1074 FIXME("Unhandled Mark To Base Format %i\n",GET_BE_WORD(mbpf1
->PosFormat
));
1078 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
)
1081 const OT_LookupTable
*look
;
1082 int ppem
= lpotm
->otmTextMetrics
.tmAscent
+ lpotm
->otmTextMetrics
.tmDescent
- lpotm
->otmTextMetrics
.tmInternalLeading
;
1084 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
1085 look
= (const OT_LookupTable
*)((const BYTE
*)lookup
+ offset
);
1086 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look
->LookupType
),GET_BE_WORD(look
->LookupFlag
),GET_BE_WORD(look
->SubTableCount
));
1087 switch(GET_BE_WORD(look
->LookupType
))
1093 GPOS_apply_MarkToBase(look
, glyphs
, glyph_index
, write_dir
, glyph_count
, ppem
, &desU
);
1094 if (desU
.x
|| desU
.y
)
1096 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
1097 pGoffset
[glyph_index
].du
+= ((int)(devX
+0.5) - piAdvance
[glyph_index
-1]);
1098 pGoffset
[glyph_index
].dv
+= (int)(devY
+0.5);
1103 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look
->LookupType
));
1105 return glyph_index
+1;
1108 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
)
1110 const GPOS_Header
*header
= (const GPOS_Header
*)table
;
1111 const OT_LookupList
*lookup
= (const OT_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
1113 return GPOS_apply_lookup(lpotm
, lplogfont
, piAdvance
, lookup
, lookup_index
, glyphs
, glyph_index
, write_dir
, glyph_count
, pGoffset
);
1116 static void GSUB_initialize_script_cache(ScriptCache
*psc
)
1120 if (psc
->GSUB_Table
)
1122 const OT_ScriptList
*script
;
1123 const GSUB_Header
* header
= (const GSUB_Header
*)psc
->GSUB_Table
;
1124 script
= (const OT_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
1125 psc
->script_count
= GET_BE_WORD(script
->ScriptCount
);
1126 TRACE("initializing %i scripts in this font\n",psc
->script_count
);
1127 if (psc
->script_count
)
1129 psc
->scripts
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LoadedScript
) * psc
->script_count
);
1130 for (i
= 0; i
< psc
->script_count
; i
++)
1132 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
1133 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]);
1134 psc
->scripts
[i
].gsub_table
= ((const BYTE
*)script
+ offset
);
1140 static void GPOS_expand_script_cache(ScriptCache
*psc
)
1143 const OT_ScriptList
*script
;
1144 const GPOS_Header
* header
= (const GPOS_Header
*)psc
->GPOS_Table
;
1149 script
= (const OT_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
1150 count
= GET_BE_WORD(script
->ScriptCount
);
1152 if (!psc
->script_count
)
1154 psc
->script_count
= count
;
1155 TRACE("initializing %i scripts in this font\n",psc
->script_count
);
1156 if (psc
->script_count
)
1158 psc
->scripts
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LoadedScript
) * psc
->script_count
);
1159 for (i
= 0; i
< psc
->script_count
; i
++)
1161 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
1162 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]);
1163 psc
->scripts
[i
].gpos_table
= ((const BYTE
*)script
+ offset
);
1169 for (i
= 0; i
< count
; i
++)
1172 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
1173 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]);
1174 for (j
= 0; j
< psc
->script_count
; j
++)
1176 if (psc
->scripts
[j
].tag
== tag
)
1178 psc
->scripts
[j
].gpos_table
= ((const BYTE
*)script
+ offset
);
1182 if (j
== psc
->script_count
)
1184 psc
->script_count
++;
1185 psc
->scripts
= HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,psc
->scripts
, sizeof(LoadedScript
) * psc
->script_count
);
1186 psc
->scripts
[j
].tag
= tag
;
1187 psc
->scripts
[j
].gpos_table
= ((const BYTE
*)script
+ offset
);
1193 static void _initialize_script_cache(ScriptCache
*psc
)
1195 if (!psc
->script_count
)
1197 GSUB_initialize_script_cache(psc
);
1198 GPOS_expand_script_cache(psc
);
1202 HRESULT
OpenType_GetFontScriptTags(ScriptCache
*psc
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pScriptTags
, int *pcTags
)
1207 _initialize_script_cache(psc
);
1209 *pcTags
= psc
->script_count
;
1211 if (!searchingFor
&& cMaxTags
< *pcTags
)
1213 else if (searchingFor
)
1214 rc
= USP_E_SCRIPT_NOT_IN_FONT
;
1216 for (i
= 0; i
< psc
->script_count
; i
++)
1219 pScriptTags
[i
] = psc
->scripts
[i
].tag
;
1223 if (searchingFor
== psc
->scripts
[i
].tag
)
1225 pScriptTags
[0] = psc
->scripts
[i
].tag
;
1235 static void GSUB_initialize_language_cache(LoadedScript
*script
)
1239 if (script
->gsub_table
)
1242 const OT_Script
* table
= script
->gsub_table
;
1243 script
->language_count
= GET_BE_WORD(table
->LangSysCount
);
1244 offset
= GET_BE_WORD(table
->DefaultLangSys
);
1247 script
->default_language
.tag
= MS_MAKE_TAG('d','f','l','t');
1248 script
->default_language
.gsub_table
= (const BYTE
*)table
+ offset
;
1251 if (script
->language_count
)
1253 TRACE("Deflang %p, LangCount %i\n",script
->default_language
.gsub_table
, script
->language_count
);
1255 script
->languages
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LoadedLanguage
) * script
->language_count
);
1257 for (i
= 0; i
< script
->language_count
; i
++)
1259 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
1260 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]);
1261 script
->languages
[i
].gsub_table
= ((const BYTE
*)table
+ offset
);
1267 static void GPOS_expand_language_cache(LoadedScript
*script
)
1270 const OT_Script
* table
= script
->gpos_table
;
1276 offset
= GET_BE_WORD(table
->DefaultLangSys
);
1278 script
->default_language
.gpos_table
= (const BYTE
*)table
+ offset
;
1280 count
= GET_BE_WORD(table
->LangSysCount
);
1282 TRACE("Deflang %p, LangCount %i\n",script
->default_language
.gpos_table
, count
);
1283 if (!script
->language_count
)
1286 script
->language_count
= count
;
1288 script
->languages
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LoadedLanguage
) * script
->language_count
);
1290 for (i
= 0; i
< script
->language_count
; i
++)
1292 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
1293 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]);
1294 script
->languages
[i
].gpos_table
= ((const BYTE
*)table
+ offset
);
1300 for (i
= 0; i
< count
; i
++)
1302 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
1303 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]);
1305 for (j
= 0; j
< script
->language_count
; j
++)
1307 if (script
->languages
[j
].tag
== tag
)
1309 script
->languages
[j
].gpos_table
= ((const BYTE
*)table
+ offset
);
1313 if (j
== script
->language_count
)
1315 script
->language_count
++;
1316 script
->languages
= HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,script
->languages
, sizeof(LoadedLanguage
) * script
->language_count
);
1317 script
->languages
[j
].tag
= tag
;
1318 script
->languages
[j
].gpos_table
= ((const BYTE
*)table
+ offset
);
1324 static void _initialize_language_cache(LoadedScript
*script
)
1326 if (!script
->language_count
)
1328 GSUB_initialize_language_cache(script
);
1329 GPOS_expand_language_cache(script
);
1333 HRESULT
OpenType_GetFontLanguageTags(ScriptCache
*psc
, OPENTYPE_TAG script_tag
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pLanguageTags
, int *pcTags
)
1337 LoadedScript
*script
= NULL
;
1339 _initialize_script_cache(psc
);
1341 for (i
= 0; i
< psc
->script_count
; i
++)
1343 if (psc
->scripts
[i
].tag
== script_tag
)
1345 script
= &psc
->scripts
[i
];
1351 return E_INVALIDARG
;
1353 _initialize_language_cache(script
);
1355 if (!searchingFor
&& cMaxTags
< script
->language_count
)
1357 else if (searchingFor
)
1360 *pcTags
= script
->language_count
;
1362 for (i
= 0; i
< script
->language_count
; i
++)
1365 pLanguageTags
[i
] = script
->languages
[i
].tag
;
1369 if (searchingFor
== script
->languages
[i
].tag
)
1371 pLanguageTags
[0] = script
->languages
[i
].tag
;
1379 if (script
->default_language
.gsub_table
)
1382 pLanguageTags
[i
] = script
->default_language
.tag
;
1384 if (searchingFor
&& FAILED(rc
))
1386 pLanguageTags
[0] = script
->default_language
.tag
;
1389 *pcTags
= (*pcTags
) + 1;
1396 static void GSUB_initialize_feature_cache(LPCVOID table
, LoadedLanguage
*language
)
1400 if (language
->gsub_table
)
1402 const OT_LangSys
*lang
= language
->gsub_table
;
1403 const GSUB_Header
*header
= (const GSUB_Header
*)table
;
1404 const OT_FeatureList
*feature_list
;
1406 language
->feature_count
= GET_BE_WORD(lang
->FeatureCount
);
1407 TRACE("%i features\n",language
->feature_count
);
1409 if (language
->feature_count
)
1411 language
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(LoadedFeature
)*language
->feature_count
);
1413 feature_list
= (const OT_FeatureList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->FeatureList
));
1415 for (i
= 0; i
< language
->feature_count
; i
++)
1417 const OT_Feature
*feature
;
1419 int index
= GET_BE_WORD(lang
->FeatureIndex
[i
]);
1421 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]);
1422 language
->features
[i
].feature
= ((const BYTE
*)feature_list
+ GET_BE_WORD(feature_list
->FeatureRecord
[index
].Feature
));
1423 feature
= (const OT_Feature
*)language
->features
[i
].feature
;
1424 language
->features
[i
].lookup_count
= GET_BE_WORD(feature
->LookupCount
);
1425 language
->features
[i
].lookups
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
) * language
->features
[i
].lookup_count
);
1426 for (j
= 0; j
< language
->features
[i
].lookup_count
; j
++)
1427 language
->features
[i
].lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
1433 static void GPOS_expand_feature_cache(LPCVOID table
, LoadedLanguage
*language
)
1436 const OT_LangSys
*lang
= language
->gpos_table
;
1437 const GPOS_Header
*header
= (const GPOS_Header
*)table
;
1438 const OT_FeatureList
*feature_list
;
1443 count
= GET_BE_WORD(lang
->FeatureCount
);
1444 feature_list
= (const OT_FeatureList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->FeatureList
));
1446 TRACE("%i features\n",count
);
1447 if (!language
->feature_count
)
1449 language
->feature_count
= count
;
1451 if (language
->feature_count
)
1453 language
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(LoadedFeature
)*language
->feature_count
);
1455 for (i
= 0; i
< language
->feature_count
; i
++)
1457 const OT_Feature
*feature
;
1459 int index
= GET_BE_WORD(lang
->FeatureIndex
[i
]);
1461 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]);
1462 language
->features
[i
].feature
= ((const BYTE
*)feature_list
+ GET_BE_WORD(feature_list
->FeatureRecord
[index
].Feature
));
1463 feature
= (const OT_Feature
*)language
->features
[i
].feature
;
1464 language
->features
[i
].lookup_count
= GET_BE_WORD(feature
->LookupCount
);
1465 language
->features
[i
].lookups
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
) * language
->features
[i
].lookup_count
);
1466 for (j
= 0; j
< language
->features
[i
].lookup_count
; j
++)
1467 language
->features
[i
].lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
1473 language
->features
= HeapReAlloc(GetProcessHeap(),0,language
->features
, sizeof(LoadedFeature
)*(language
->feature_count
+ count
));
1475 for (i
= 0; i
< count
; i
++)
1477 const OT_Feature
*feature
;
1479 int index
= GET_BE_WORD(lang
->FeatureIndex
[i
]);
1480 int idx
= language
->feature_count
+ i
;
1482 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]);
1483 language
->features
[idx
].feature
= ((const BYTE
*)feature_list
+ GET_BE_WORD(feature_list
->FeatureRecord
[index
].Feature
));
1484 feature
= (const OT_Feature
*)language
->features
[idx
].feature
;
1485 language
->features
[idx
].lookup_count
= GET_BE_WORD(feature
->LookupCount
);
1486 language
->features
[idx
].lookups
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
) * language
->features
[idx
].lookup_count
);
1487 for (j
= 0; j
< language
->features
[idx
].lookup_count
; j
++)
1488 language
->features
[idx
].lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
1490 language
->feature_count
+= count
;
1494 static void _initialize_feature_cache(ScriptCache
*psc
, LoadedLanguage
*language
)
1496 if (!language
->feature_count
)
1498 GSUB_initialize_feature_cache(psc
->GSUB_Table
, language
);
1499 GPOS_expand_feature_cache(psc
->GPOS_Table
, language
);
1503 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
)
1507 LoadedScript
*script
= NULL
;
1508 LoadedLanguage
*language
= NULL
;
1510 _initialize_script_cache(psc
);
1512 for (i
= 0; i
< psc
->script_count
; i
++)
1514 if (psc
->scripts
[i
].tag
== script_tag
)
1516 script
= &psc
->scripts
[i
];
1527 return E_INVALIDARG
;
1530 _initialize_language_cache(script
);
1532 if ((script
->default_language
.gsub_table
|| script
->default_language
.gpos_table
) && script
->default_language
.tag
== language_tag
)
1533 language
= &script
->default_language
;
1536 for (i
= 0; i
< script
->language_count
; i
++)
1538 if (script
->languages
[i
].tag
== language_tag
)
1540 language
= &script
->languages
[i
];
1552 _initialize_feature_cache(psc
, language
);
1554 *pcTags
= language
->feature_count
;
1556 if (!searchingFor
&& cMaxTags
< *pcTags
)
1558 else if (searchingFor
)
1561 for (i
= 0; i
< language
->feature_count
; i
++)
1564 pFeatureTags
[i
] = language
->features
[i
].tag
;
1568 if (searchingFor
== language
->features
[i
].tag
)
1570 pFeatureTags
[0] = language
->features
[i
].tag
;
1573 *feature
= &language
->features
[i
];