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')
53 GPOS_LOOKUP_ADJUST_SINGLE
= 0x1,
54 GPOS_LOOKUP_ADJUST_PAIR
= 0x2,
55 GPOS_LOOKUP_ATTACH_CURSIVE
= 0x3,
56 GPOS_LOOKUP_ATTACH_MARK_TO_BASE
= 0x4,
57 GPOS_LOOKUP_ATTACH_MARK_TO_LIGATURE
= 0x5,
58 GPOS_LOOKUP_ATTACH_MARK_TO_MARK
= 0x6,
59 GPOS_LOOKUP_POSITION_CONTEXT
= 0x7,
60 GPOS_LOOKUP_POSITION_CONTEXT_CHAINED
= 0x8,
61 GPOS_LOOKUP_POSITION_EXTENSION
= 0x9,
66 GSUB_LOOKUP_SINGLE
= 0x1,
67 GSUB_LOOKUP_MULTIPLE
= 0x2,
68 GSUB_LOOKUP_ALTERNATE
= 0x3,
69 GSUB_LOOKUP_LIGATURE
= 0x4,
70 GSUB_LOOKUP_CONTEXT
= 0x5,
71 GSUB_LOOKUP_CONTEXT_CHAINED
= 0x6,
72 GSUB_LOOKUP_EXTENSION
= 0x7,
73 GSUB_LOOKUP_CONTEXT_CHAINED_REVERSE
= 0x8,
80 } CMAP_EncodingRecord
;
85 CMAP_EncodingRecord tables
[1];
92 } CMAP_SegmentedCoverage_group
;
100 CMAP_SegmentedCoverage_group groups
[1];
101 } CMAP_SegmentedCoverage
;
103 /* These are all structures needed for the GDEF table */
104 enum {BaseGlyph
=1, LigatureGlyph
, MarkGlyph
, ComponentGlyph
};
111 WORD MarkAttachClassDef
;
118 WORD ClassValueArray
[1];
119 } OT_ClassDefFormat1
;
125 } OT_ClassRangeRecord
;
129 WORD ClassRangeCount
;
130 OT_ClassRangeRecord ClassRangeRecord
[1];
131 } OT_ClassDefFormat2
;
133 /* These are all structures needed for the GSUB table */
149 OT_ScriptRecord ScriptRecord
[1];
160 OT_LangSysRecord LangSysRecord
[1];
164 WORD LookupOrder
; /* Reserved */
165 WORD ReqFeatureIndex
;
167 WORD FeatureIndex
[1];
177 OT_FeatureRecord FeatureRecord
[1];
181 WORD FeatureParams
; /* Reserved */
183 WORD LookupListIndex
[1];
202 } OT_CoverageFormat1
;
207 WORD StartCoverageIndex
;
213 OT_RangeRecord RangeRecord
[1];
214 } OT_CoverageFormat2
;
217 WORD SubstFormat
; /* = 1 */
220 } GSUB_SingleSubstFormat1
;
223 WORD SubstFormat
; /* = 2 */
227 }GSUB_SingleSubstFormat2
;
230 WORD SubstFormat
; /* = 1 */
234 }GSUB_MultipleSubstFormat1
;
242 WORD SubstFormat
; /* = 1 */
246 }GSUB_LigatureSubstFormat1
;
261 WORD LookupListIndex
;
263 }GSUB_SubstLookupRecord
;
268 WORD SubRuleSetCount
;
270 }GSUB_ContextSubstFormat1
;
284 GSUB_SubstLookupRecord SubstLookupRecord
[1];
293 }GSUB_ContextSubstFormat2
;
296 WORD SubClassRuleCnt
;
297 WORD SubClassRule
[1];
304 }GSUB_SubClassRule_1
;
307 GSUB_SubstLookupRecord SubstLookupRecord
[1];
308 }GSUB_SubClassRule_2
;
311 WORD SubstFormat
; /* = 1 */
313 WORD ChainSubRuleSetCount
;
314 WORD ChainSubRuleSet
[1];
315 }GSUB_ChainContextSubstFormat1
;
318 WORD SubstFormat
; /* = 2 */
320 WORD BacktrackClassDef
;
322 WORD LookaheadClassDef
;
323 WORD ChainSubClassSetCnt
;
324 WORD ChainSubClassSet
[1];
325 }GSUB_ChainContextSubstFormat2
;
328 WORD ChainSubClassRuleCnt
;
329 WORD ChainSubClassRule
[1];
330 }GSUB_ChainSubClassSet
;
333 WORD BacktrackGlyphCount
;
335 }GSUB_ChainSubClassRule_1
;
338 WORD InputGlyphCount
;
340 }GSUB_ChainSubClassRule_2
;
343 WORD LookaheadGlyphCount
;
345 }GSUB_ChainSubClassRule_3
;
349 GSUB_SubstLookupRecord SubstLookupRecord
[1];
350 }GSUB_ChainSubClassRule_4
;
353 WORD SubstFormat
; /* = 3 */
354 WORD BacktrackGlyphCount
;
356 }GSUB_ChainContextSubstFormat3_1
;
359 WORD InputGlyphCount
;
361 }GSUB_ChainContextSubstFormat3_2
;
364 WORD LookaheadGlyphCount
;
366 }GSUB_ChainContextSubstFormat3_3
;
370 GSUB_SubstLookupRecord SubstLookupRecord
[1];
371 }GSUB_ChainContextSubstFormat3_4
;
374 WORD SubstFormat
; /* = 1 */
376 WORD AlternateSetCount
;
377 WORD AlternateSet
[1];
378 } GSUB_AlternateSubstFormat1
;
387 WORD ExtensionLookupType
;
388 DWORD ExtensionOffset
;
389 } GSUB_ExtensionPosFormat1
;
391 /* These are all structures needed for the GPOS table */
411 } GPOS_AnchorFormat1
;
418 } GPOS_AnchorFormat2
;
426 } GPOS_AnchorFormat3
;
444 } GPOS_SinglePosFormat1
;
452 } GPOS_SinglePosFormat2
;
460 WORD PairSetOffset
[1];
461 } GPOS_PairPosFormat1
;
472 WORD Class1Record
[1];
473 } GPOS_PairPosFormat2
;
479 } GPOS_PairValueRecord
;
483 GPOS_PairValueRecord PairValueRecord
[1];
489 } GPOS_EntryExitRecord
;
495 GPOS_EntryExitRecord EntryExitRecord
[1];
496 } GPOS_CursivePosFormat1
;
505 } GPOS_MarkBasePosFormat1
;
513 GPOS_BaseRecord BaseRecord
[1];
523 GPOS_MarkRecord MarkRecord
[1];
529 WORD LigatureCoverage
;
533 } GPOS_MarkLigPosFormat1
;
537 WORD LigatureAttach
[1];
538 } GPOS_LigatureArray
;
541 WORD LigatureAnchor
[1];
542 } GPOS_ComponentRecord
;
546 GPOS_ComponentRecord ComponentRecord
[1];
547 } GPOS_LigatureAttach
;
556 } GPOS_MarkMarkPosFormat1
;
564 GPOS_Mark2Record Mark2Record
[1];
569 WORD LookupListIndex
;
570 } GPOS_PosLookupRecord
;
578 } GPOS_ContextPosFormat2
;
581 WORD PosClassRuleCnt
;
582 WORD PosClassRule
[1];
589 } GPOS_PosClassRule_1
;
592 GPOS_PosLookupRecord PosLookupRecord
[1];
593 } GPOS_PosClassRule_2
;
597 WORD BacktrackGlyphCount
;
599 } GPOS_ChainContextPosFormat3_1
;
602 WORD InputGlyphCount
;
604 } GPOS_ChainContextPosFormat3_2
;
607 WORD LookaheadGlyphCount
;
609 } GPOS_ChainContextPosFormat3_3
;
613 GPOS_PosLookupRecord PosLookupRecord
[1];
614 } GPOS_ChainContextPosFormat3_4
;
618 WORD ExtensionLookupType
;
619 DWORD ExtensionOffset
;
620 } GPOS_ExtensionPosFormat1
;
626 static VOID
*load_CMAP_format12_table(HDC hdc
, ScriptCache
*psc
)
628 CMAP_Header
*CMAP_Table
= NULL
;
632 if (!psc
->CMAP_Table
)
634 length
= GetFontData(hdc
, CMAP_TAG
, 0, NULL
, 0);
635 if (length
!= GDI_ERROR
)
637 psc
->CMAP_Table
= heap_alloc(length
);
638 GetFontData(hdc
, CMAP_TAG
, 0, psc
->CMAP_Table
, length
);
639 TRACE("Loaded cmap table of %i bytes\n",length
);
645 CMAP_Table
= psc
->CMAP_Table
;
647 for (i
= 0; i
< GET_BE_WORD(CMAP_Table
->numTables
); i
++)
649 if ( (GET_BE_WORD(CMAP_Table
->tables
[i
].platformID
) == 3) &&
650 (GET_BE_WORD(CMAP_Table
->tables
[i
].encodingID
) == 10) )
652 CMAP_SegmentedCoverage
*format
= (CMAP_SegmentedCoverage
*)(((BYTE
*)CMAP_Table
) + GET_BE_DWORD(CMAP_Table
->tables
[i
].offset
));
653 if (GET_BE_WORD(format
->format
) == 12)
660 static int compare_group(const void *a
, const void* b
)
662 const DWORD
*chr
= a
;
663 const CMAP_SegmentedCoverage_group
*group
= b
;
665 if (*chr
< GET_BE_DWORD(group
->startCharCode
))
667 if (*chr
> GET_BE_DWORD(group
->endCharCode
))
672 DWORD
OpenType_CMAP_GetGlyphIndex(HDC hdc
, ScriptCache
*psc
, DWORD utf32c
, WORD
*glyph_index
, DWORD flags
)
674 /* BMP: use gdi32 for ease */
675 if (utf32c
< 0x10000)
678 return GetGlyphIndicesW(hdc
, &ch
, 1, glyph_index
, flags
);
681 if (!psc
->CMAP_format12_Table
)
682 psc
->CMAP_format12_Table
= load_CMAP_format12_table(hdc
, psc
);
684 if (flags
& GGI_MARK_NONEXISTING_GLYPHS
)
685 *glyph_index
= 0xffffu
;
689 if (psc
->CMAP_format12_Table
)
691 CMAP_SegmentedCoverage
*format
= NULL
;
692 CMAP_SegmentedCoverage_group
*group
= NULL
;
694 format
= (CMAP_SegmentedCoverage
*)psc
->CMAP_format12_Table
;
696 group
= bsearch(&utf32c
, format
->groups
, GET_BE_DWORD(format
->nGroups
),
697 sizeof(CMAP_SegmentedCoverage_group
), compare_group
);
701 DWORD offset
= utf32c
- GET_BE_DWORD(group
->startCharCode
);
702 *glyph_index
= GET_BE_DWORD(group
->startGlyphID
) + offset
;
713 static WORD
OT_get_glyph_class(const void *table
, WORD glyph
)
716 const OT_ClassDefFormat1
*cf1
= table
;
718 if (!table
) return 0;
720 if (GET_BE_WORD(cf1
->ClassFormat
) == 1)
722 if (glyph
>= GET_BE_WORD(cf1
->StartGlyph
))
724 int index
= glyph
- GET_BE_WORD(cf1
->StartGlyph
);
725 if (index
< GET_BE_WORD(cf1
->GlyphCount
))
726 class = GET_BE_WORD(cf1
->ClassValueArray
[index
]);
729 else if (GET_BE_WORD(cf1
->ClassFormat
) == 2)
731 const OT_ClassDefFormat2
*cf2
= table
;
733 top
= GET_BE_WORD(cf2
->ClassRangeCount
);
734 for (i
= 0; i
< top
; i
++)
736 if (glyph
>= GET_BE_WORD(cf2
->ClassRangeRecord
[i
].Start
) &&
737 glyph
<= GET_BE_WORD(cf2
->ClassRangeRecord
[i
].End
))
739 class = GET_BE_WORD(cf2
->ClassRangeRecord
[i
].Class
);
745 ERR("Unknown Class Format %i\n",GET_BE_WORD(cf1
->ClassFormat
));
750 void OpenType_GDEF_UpdateGlyphProps(ScriptCache
*psc
, const WORD
*pwGlyphs
, const WORD cGlyphs
, WORD
* pwLogClust
, const WORD cChars
, SCRIPT_GLYPHPROP
*pGlyphProp
)
753 void *glyph_class_table
= NULL
;
757 const GDEF_Header
*header
= psc
->GDEF_Table
;
758 WORD offset
= GET_BE_WORD( header
->GlyphClassDef
);
760 glyph_class_table
= (BYTE
*)psc
->GDEF_Table
+ offset
;
763 for (i
= 0; i
< cGlyphs
; i
++)
769 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
772 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
776 class = OT_get_glyph_class( glyph_class_table
, pwGlyphs
[i
] );
782 pGlyphProp
[i
].sva
.fClusterStart
= 1;
783 pGlyphProp
[i
].sva
.fDiacritic
= 0;
784 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
787 pGlyphProp
[i
].sva
.fClusterStart
= 1;
788 pGlyphProp
[i
].sva
.fDiacritic
= 0;
789 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
792 pGlyphProp
[i
].sva
.fClusterStart
= 0;
793 pGlyphProp
[i
].sva
.fDiacritic
= 1;
794 pGlyphProp
[i
].sva
.fZeroWidth
= 1;
797 pGlyphProp
[i
].sva
.fClusterStart
= 0;
798 pGlyphProp
[i
].sva
.fDiacritic
= 0;
799 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
802 ERR("Unknown glyph class %i\n",class);
803 pGlyphProp
[i
].sva
.fClusterStart
= 1;
804 pGlyphProp
[i
].sva
.fDiacritic
= 0;
805 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
809 pGlyphProp
[i
].sva
.fClusterStart
= 0;
816 static INT
GSUB_apply_lookup(const OT_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
);
818 static int GSUB_is_glyph_covered(const void *table
, unsigned int glyph
)
820 const OT_CoverageFormat1
* cf1
;
824 if (GET_BE_WORD(cf1
->CoverageFormat
) == 1)
826 int count
= GET_BE_WORD(cf1
->GlyphCount
);
828 TRACE("Coverage Format 1, %i glyphs\n",count
);
829 for (i
= 0; i
< count
; i
++)
830 if (glyph
== GET_BE_WORD(cf1
->GlyphArray
[i
]))
834 else if (GET_BE_WORD(cf1
->CoverageFormat
) == 2)
836 const OT_CoverageFormat2
* cf2
;
839 cf2
= (const OT_CoverageFormat2
*)cf1
;
841 count
= GET_BE_WORD(cf2
->RangeCount
);
842 TRACE("Coverage Format 2, %i ranges\n",count
);
843 for (i
= 0; i
< count
; i
++)
845 if (glyph
< GET_BE_WORD(cf2
->RangeRecord
[i
].Start
))
847 if ((glyph
>= GET_BE_WORD(cf2
->RangeRecord
[i
].Start
)) &&
848 (glyph
<= GET_BE_WORD(cf2
->RangeRecord
[i
].End
)))
850 return (GET_BE_WORD(cf2
->RangeRecord
[i
].StartCoverageIndex
) +
851 glyph
- GET_BE_WORD(cf2
->RangeRecord
[i
].Start
));
857 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1
->CoverageFormat
));
862 static const BYTE
*GSUB_get_subtable(const OT_LookupTable
*look
, int index
)
864 int offset
= GET_BE_WORD(look
->SubTable
[index
]);
866 if (GET_BE_WORD(look
->LookupType
) == GSUB_LOOKUP_EXTENSION
)
868 const GSUB_ExtensionPosFormat1
*ext
= (const GSUB_ExtensionPosFormat1
*)((const BYTE
*)look
+ offset
);
869 if (GET_BE_WORD(ext
->SubstFormat
) == 1)
871 offset
+= GET_BE_DWORD(ext
->ExtensionOffset
);
875 FIXME("Unhandled Extension Substitution Format %i\n",GET_BE_WORD(ext
->SubstFormat
));
878 return (const BYTE
*)look
+ offset
;
881 static INT
GSUB_apply_SingleSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
884 TRACE("Single Substitution Subtable\n");
886 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
888 const GSUB_SingleSubstFormat1
*ssf1
= (const GSUB_SingleSubstFormat1
*)GSUB_get_subtable(look
, j
);
889 if (GET_BE_WORD(ssf1
->SubstFormat
) == 1)
891 int offset
= GET_BE_WORD(ssf1
->Coverage
);
892 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1
->DeltaGlyphID
));
893 if (GSUB_is_glyph_covered((const BYTE
*)ssf1
+offset
, glyphs
[glyph_index
]) != -1)
895 TRACE(" Glyph 0x%x ->",glyphs
[glyph_index
]);
896 glyphs
[glyph_index
] = glyphs
[glyph_index
] + GET_BE_WORD(ssf1
->DeltaGlyphID
);
897 TRACE(" 0x%x\n",glyphs
[glyph_index
]);
898 return glyph_index
+ write_dir
;
903 const GSUB_SingleSubstFormat2
*ssf2
;
907 ssf2
= (const GSUB_SingleSubstFormat2
*)ssf1
;
908 offset
= GET_BE_WORD(ssf1
->Coverage
);
909 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2
->GlyphCount
));
910 index
= GSUB_is_glyph_covered((const BYTE
*)ssf2
+offset
, glyphs
[glyph_index
]);
911 TRACE(" Coverage index %i\n",index
);
914 if (glyphs
[glyph_index
] == GET_BE_WORD(ssf2
->Substitute
[index
]))
915 return GSUB_E_NOGLYPH
;
917 TRACE(" Glyph is 0x%x ->",glyphs
[glyph_index
]);
918 glyphs
[glyph_index
] = GET_BE_WORD(ssf2
->Substitute
[index
]);
919 TRACE("0x%x\n",glyphs
[glyph_index
]);
920 return glyph_index
+ write_dir
;
924 return GSUB_E_NOGLYPH
;
927 static INT
GSUB_apply_MultipleSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
930 TRACE("Multiple Substitution Subtable\n");
932 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
935 const GSUB_MultipleSubstFormat1
*msf1
;
936 msf1
= (const GSUB_MultipleSubstFormat1
*)GSUB_get_subtable(look
, j
);
938 offset
= GET_BE_WORD(msf1
->Coverage
);
939 index
= GSUB_is_glyph_covered((const BYTE
*)msf1
+offset
, glyphs
[glyph_index
]);
942 const GSUB_Sequence
*seq
;
945 offset
= GET_BE_WORD(msf1
->Sequence
[index
]);
946 seq
= (const GSUB_Sequence
*)((const BYTE
*)msf1
+offset
);
947 sub_count
= GET_BE_WORD(seq
->GlyphCount
);
948 TRACE(" Glyph 0x%x (+%i)->",glyphs
[glyph_index
],(sub_count
-1));
950 for (j
= (*glyph_count
)+(sub_count
-1); j
> glyph_index
; j
--)
951 glyphs
[j
] =glyphs
[j
-(sub_count
-1)];
953 for (j
= 0; j
< sub_count
; j
++)
955 glyphs
[glyph_index
+ (sub_count
-1) - j
] = GET_BE_WORD(seq
->Substitute
[j
]);
957 glyphs
[glyph_index
+ j
] = GET_BE_WORD(seq
->Substitute
[j
]);
959 *glyph_count
= *glyph_count
+ (sub_count
- 1);
961 if (TRACE_ON(uniscribe
))
963 for (j
= 0; j
< sub_count
; j
++)
964 TRACE(" 0x%x",glyphs
[glyph_index
+j
]);
969 return glyph_index
+ sub_count
;
971 return glyph_index
- 1;
974 return GSUB_E_NOGLYPH
;
977 static INT
GSUB_apply_AlternateSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
980 TRACE("Alternate Substitution Subtable\n");
982 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
985 const GSUB_AlternateSubstFormat1
*asf1
;
988 asf1
= (const GSUB_AlternateSubstFormat1
*)GSUB_get_subtable(look
, j
);
989 offset
= GET_BE_WORD(asf1
->Coverage
);
991 index
= GSUB_is_glyph_covered((const BYTE
*)asf1
+offset
, glyphs
[glyph_index
]);
994 const GSUB_AlternateSet
*as
;
995 offset
= GET_BE_WORD(asf1
->AlternateSet
[index
]);
996 as
= (const GSUB_AlternateSet
*)((const BYTE
*)asf1
+offset
);
997 FIXME("%i alternates, picking index 0\n",GET_BE_WORD(as
->GlyphCount
));
998 if (glyphs
[glyph_index
] == GET_BE_WORD(as
->Alternate
[0]))
999 return GSUB_E_NOGLYPH
;
1001 TRACE(" Glyph 0x%x ->",glyphs
[glyph_index
]);
1002 glyphs
[glyph_index
] = GET_BE_WORD(as
->Alternate
[0]);
1003 TRACE(" 0x%x\n",glyphs
[glyph_index
]);
1004 return glyph_index
+ write_dir
;
1007 return GSUB_E_NOGLYPH
;
1010 static INT
GSUB_apply_LigatureSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
1014 TRACE("Ligature Substitution Subtable\n");
1015 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1017 const GSUB_LigatureSubstFormat1
*lsf1
;
1020 lsf1
= (const GSUB_LigatureSubstFormat1
*)GSUB_get_subtable(look
, j
);
1021 offset
= GET_BE_WORD(lsf1
->Coverage
);
1022 index
= GSUB_is_glyph_covered((const BYTE
*)lsf1
+offset
, glyphs
[glyph_index
]);
1023 TRACE(" Coverage index %i\n",index
);
1026 const GSUB_LigatureSet
*ls
;
1029 offset
= GET_BE_WORD(lsf1
->LigatureSet
[index
]);
1030 ls
= (const GSUB_LigatureSet
*)((const BYTE
*)lsf1
+offset
);
1031 count
= GET_BE_WORD(ls
->LigatureCount
);
1032 TRACE(" LigatureSet has %i members\n",count
);
1033 for (k
= 0; k
< count
; k
++)
1035 const GSUB_Ligature
*lig
;
1036 int CompCount
,l
,CompIndex
;
1038 offset
= GET_BE_WORD(ls
->Ligature
[k
]);
1039 lig
= (const GSUB_Ligature
*)((const BYTE
*)ls
+offset
);
1040 CompCount
= GET_BE_WORD(lig
->CompCount
) - 1;
1041 CompIndex
= glyph_index
+write_dir
;
1042 for (l
= 0; l
< CompCount
&& CompIndex
>= 0 && CompIndex
< *glyph_count
; l
++)
1045 CompGlyph
= GET_BE_WORD(lig
->Component
[l
]);
1046 if (CompGlyph
!= glyphs
[CompIndex
])
1048 CompIndex
+= write_dir
;
1052 int replaceIdx
= glyph_index
;
1054 replaceIdx
= glyph_index
- CompCount
;
1056 TRACE(" Glyph is 0x%x (+%i) ->",glyphs
[glyph_index
],CompCount
);
1057 glyphs
[replaceIdx
] = GET_BE_WORD(lig
->LigGlyph
);
1058 TRACE("0x%x\n",glyphs
[replaceIdx
]);
1061 unsigned int j
= replaceIdx
+ 1;
1062 memmove(&glyphs
[j
], &glyphs
[j
+ CompCount
], (*glyph_count
- j
) * sizeof(*glyphs
));
1063 *glyph_count
= *glyph_count
- CompCount
;
1065 return replaceIdx
+ write_dir
;
1070 return GSUB_E_NOGLYPH
;
1073 static INT
GSUB_apply_ContextSubst(const OT_LookupList
* lookup
, const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
1076 TRACE("Context Substitution Subtable\n");
1077 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1079 const GSUB_ContextSubstFormat1
*csf1
;
1081 csf1
= (const GSUB_ContextSubstFormat1
*)GSUB_get_subtable(look
, j
);
1082 if (GET_BE_WORD(csf1
->SubstFormat
) == 1)
1085 TRACE("Context Substitution Subtable: Class 1\n");
1086 offset
= GET_BE_WORD(csf1
->Coverage
);
1087 index
= GSUB_is_glyph_covered((const BYTE
*)csf1
+offset
, glyphs
[glyph_index
]);
1088 TRACE(" Coverage index %i\n",index
);
1092 const GSUB_SubRuleSet
*srs
;
1093 offset
= GET_BE_WORD(csf1
->SubRuleSet
[index
]);
1094 srs
= (const GSUB_SubRuleSet
*)((const BYTE
*)csf1
+offset
);
1095 count
= GET_BE_WORD(srs
->SubRuleCount
);
1096 TRACE(" SubRuleSet has %i members\n",count
);
1097 for (k
= 0; k
< count
; k
++)
1099 const GSUB_SubRule_1
*sr
;
1100 const GSUB_SubRule_2
*sr_2
;
1102 int newIndex
= glyph_index
;
1104 offset
= GET_BE_WORD(srs
->SubRule
[k
]);
1105 sr
= (const GSUB_SubRule_1
*)((const BYTE
*)srs
+offset
);
1106 g_count
= GET_BE_WORD(sr
->GlyphCount
);
1107 TRACE(" SubRule has %i glyphs\n",g_count
);
1108 for (l
= 0; l
< g_count
-1; l
++)
1109 if (glyphs
[glyph_index
+ (write_dir
* (l
+1))] != GET_BE_WORD(sr
->Input
[l
])) break;
1113 TRACE(" Rule does not match\n");
1117 TRACE(" Rule matches\n");
1118 sr_2
= (const GSUB_SubRule_2
*)((const BYTE
*)sr
+
1119 FIELD_OFFSET(GSUB_SubRule_1
, Input
[g_count
-1]));
1121 for (l
= 0; l
< GET_BE_WORD(sr
->SubstCount
); l
++)
1123 int lookupIndex
= GET_BE_WORD(sr_2
->SubstLookupRecord
[l
].LookupListIndex
);
1124 int SequenceIndex
= GET_BE_WORD(sr_2
->SubstLookupRecord
[l
].SequenceIndex
) * write_dir
;
1126 TRACE(" SUBST: %i -> %i %i\n",l
, SequenceIndex
, lookupIndex
);
1127 newIndex
= GSUB_apply_lookup(lookup
, lookupIndex
, glyphs
, glyph_index
+ SequenceIndex
, write_dir
, glyph_count
);
1128 if (newIndex
== GSUB_E_NOGLYPH
)
1130 ERR(" Chain failed to generate a glyph\n");
1138 else if (GET_BE_WORD(csf1
->SubstFormat
) == 2)
1140 const GSUB_ContextSubstFormat2
*csf2
;
1141 const void *glyph_class_table
;
1144 csf2
= (const GSUB_ContextSubstFormat2
*)csf1
;
1145 TRACE("Context Substitution Subtable: Class 2\n");
1146 offset
= GET_BE_WORD(csf2
->Coverage
);
1147 index
= GSUB_is_glyph_covered((const BYTE
*)csf2
+offset
, glyphs
[glyph_index
]);
1148 TRACE(" Coverage index %i\n",index
);
1151 int k
, count
, class;
1152 const GSUB_SubClassSet
*scs
;
1154 offset
= GET_BE_WORD(csf2
->ClassDef
);
1155 glyph_class_table
= (const BYTE
*)csf2
+ offset
;
1157 class = OT_get_glyph_class(glyph_class_table
,glyphs
[glyph_index
]);
1159 offset
= GET_BE_WORD(csf2
->SubClassSet
[class]);
1162 TRACE(" No class rule table for class %i\n",class);
1165 scs
= (const GSUB_SubClassSet
*)((const BYTE
*)csf2
+offset
);
1166 count
= GET_BE_WORD(scs
->SubClassRuleCnt
);
1167 TRACE(" SubClassSet has %i members\n",count
);
1168 for (k
= 0; k
< count
; k
++)
1170 const GSUB_SubClassRule_1
*sr
;
1171 const GSUB_SubClassRule_2
*sr_2
;
1173 int newIndex
= glyph_index
;
1175 offset
= GET_BE_WORD(scs
->SubClassRule
[k
]);
1176 sr
= (const GSUB_SubClassRule_1
*)((const BYTE
*)scs
+offset
);
1177 g_count
= GET_BE_WORD(sr
->GlyphCount
);
1178 TRACE(" SubClassRule has %i glyphs classes\n",g_count
);
1179 for (l
= 0; l
< g_count
-1; l
++)
1181 int g_class
= OT_get_glyph_class(glyph_class_table
, glyphs
[glyph_index
+ (write_dir
* (l
+1))]);
1182 if (g_class
!= GET_BE_WORD(sr
->Class
[l
])) break;
1187 TRACE(" Rule does not match\n");
1191 TRACE(" Rule matches\n");
1192 sr_2
= (const GSUB_SubClassRule_2
*)((const BYTE
*)sr
+
1193 FIELD_OFFSET(GSUB_SubClassRule_1
, Class
[g_count
-1]));
1195 for (l
= 0; l
< GET_BE_WORD(sr
->SubstCount
); l
++)
1197 int lookupIndex
= GET_BE_WORD(sr_2
->SubstLookupRecord
[l
].LookupListIndex
);
1198 int SequenceIndex
= GET_BE_WORD(sr_2
->SubstLookupRecord
[l
].SequenceIndex
) * write_dir
;
1200 TRACE(" SUBST: %i -> %i %i\n",l
, SequenceIndex
, lookupIndex
);
1201 newIndex
= GSUB_apply_lookup(lookup
, lookupIndex
, glyphs
, glyph_index
+ SequenceIndex
, write_dir
, glyph_count
);
1202 if (newIndex
== GSUB_E_NOGLYPH
)
1204 ERR(" Chain failed to generate a glyph\n");
1213 FIXME("Unhandled Context Substitution Format %i\n", GET_BE_WORD(csf1
->SubstFormat
));
1215 return GSUB_E_NOGLYPH
;
1218 static INT
GSUB_apply_ChainContextSubst(const OT_LookupList
* lookup
, const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
1222 TRACE("Chaining Contextual Substitution Subtable\n");
1223 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1225 const GSUB_ChainContextSubstFormat1
*ccsf1
;
1227 int dirLookahead
= write_dir
;
1228 int dirBacktrack
= -1 * write_dir
;
1230 ccsf1
= (const GSUB_ChainContextSubstFormat1
*)GSUB_get_subtable(look
, j
);
1231 if (GET_BE_WORD(ccsf1
->SubstFormat
) == 1)
1235 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
1238 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 2)
1241 const void *backtrack_class_table
;
1242 const void *input_class_table
;
1243 const void *lookahead_class_table
;
1247 const GSUB_ChainContextSubstFormat2
*ccsf2
= (const GSUB_ChainContextSubstFormat2
*)ccsf1
;
1248 const GSUB_ChainSubClassSet
*csc
;
1250 TRACE(" subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
1252 offset
= GET_BE_WORD(ccsf2
->Coverage
);
1254 if (GSUB_is_glyph_covered((const BYTE
*)ccsf2
+offset
, glyphs
[glyph_index
]) == -1)
1256 TRACE("Glyph not covered\n");
1259 offset
= GET_BE_WORD(ccsf2
->BacktrackClassDef
);
1260 backtrack_class_table
= (const BYTE
*)ccsf2
+offset
;
1261 offset
= GET_BE_WORD(ccsf2
->InputClassDef
);
1262 input_class_table
= (const BYTE
*)ccsf2
+offset
;
1263 offset
= GET_BE_WORD(ccsf2
->LookaheadClassDef
);
1264 lookahead_class_table
= (const BYTE
*)ccsf2
+offset
;
1265 count
= GET_BE_WORD(ccsf2
->ChainSubClassSetCnt
);
1267 class = OT_get_glyph_class(input_class_table
, glyphs
[glyph_index
]);
1268 offset
= GET_BE_WORD(ccsf2
->ChainSubClassSet
[class]);
1272 TRACE("No rules for class\n");
1276 csc
= (const GSUB_ChainSubClassSet
*)((BYTE
*)ccsf2
+offset
);
1277 count
= GET_BE_WORD(csc
->ChainSubClassRuleCnt
);
1279 TRACE("%i rules to check\n",count
);
1281 for (i
= 0; i
< count
; i
++)
1283 WORD backtrack_count
, input_count
, lookahead_count
, substitute_count
;
1285 const GSUB_ChainSubClassRule_1
*backtrack
;
1286 const GSUB_ChainSubClassRule_2
*input
;
1287 const GSUB_ChainSubClassRule_3
*lookahead
;
1288 const GSUB_ChainSubClassRule_4
*substitute
;
1289 int new_index
= GSUB_E_NOGLYPH
;
1291 offset
= GET_BE_WORD(csc
->ChainSubClassRule
[i
]);
1292 backtrack
= (const GSUB_ChainSubClassRule_1
*)((BYTE
*)csc
+ offset
);
1293 backtrack_count
= GET_BE_WORD(backtrack
->BacktrackGlyphCount
);
1294 k
= glyph_index
+ dirBacktrack
* backtrack_count
;
1295 if (k
< 0 || k
>= *glyph_count
)
1298 input
= (const GSUB_ChainSubClassRule_2
*)&backtrack
->Backtrack
[backtrack_count
];
1299 input_count
= GET_BE_WORD(input
->InputGlyphCount
) - 1;
1300 k
= glyph_index
+ write_dir
* input_count
;
1301 if (k
< 0 || k
>= *glyph_count
)
1304 lookahead
= (const GSUB_ChainSubClassRule_3
*)&input
->Input
[input_count
];
1305 lookahead_count
= GET_BE_WORD(lookahead
->LookaheadGlyphCount
);
1306 k
= glyph_index
+ dirLookahead
* (input_count
+ lookahead_count
);
1307 if (k
< 0 || k
>= *glyph_count
)
1310 substitute
= (const GSUB_ChainSubClassRule_4
*)&lookahead
->LookAhead
[lookahead_count
];
1312 for (k
= 0; k
< backtrack_count
; ++k
)
1314 WORD target_class
= GET_BE_WORD(backtrack
->Backtrack
[k
]);
1315 WORD glyph_class
= OT_get_glyph_class(backtrack_class_table
, glyphs
[glyph_index
+ (dirBacktrack
* (k
+1))]);
1316 if (target_class
!= glyph_class
)
1319 if (k
!= backtrack_count
)
1321 TRACE("Matched Backtrack\n");
1323 for (k
= 0; k
< input_count
; ++k
)
1325 WORD target_class
= GET_BE_WORD(input
->Input
[k
]);
1326 WORD glyph_class
= OT_get_glyph_class(input_class_table
, glyphs
[glyph_index
+ (write_dir
* (k
+1))]);
1327 if (target_class
!= glyph_class
)
1330 if (k
!= input_count
)
1332 TRACE("Matched IndexGlyphs\n");
1334 for (k
= 0; k
< lookahead_count
; ++k
)
1336 WORD target_class
= GET_BE_WORD(lookahead
->LookAhead
[k
]);
1337 WORD glyph_class
= OT_get_glyph_class(lookahead_class_table
,
1338 glyphs
[glyph_index
+ (dirLookahead
* (input_count
+ k
+ 1))]);
1339 if (target_class
!= glyph_class
)
1342 if (k
!= lookahead_count
)
1344 TRACE("Matched LookAhead\n");
1346 substitute_count
= GET_BE_WORD(substitute
->SubstCount
);
1347 for (k
= 0; k
< substitute_count
; ++k
)
1349 WORD lookup_index
= GET_BE_WORD(substitute
->SubstLookupRecord
[k
].LookupListIndex
);
1350 WORD sequence_index
= GET_BE_WORD(substitute
->SubstLookupRecord
[k
].SequenceIndex
) * write_dir
;
1352 TRACE("SUBST: %u -> %u %u.\n", k
, sequence_index
, lookup_index
);
1353 new_index
= GSUB_apply_lookup(lookup
, lookup_index
, glyphs
,
1354 glyph_index
+ sequence_index
, write_dir
, glyph_count
);
1355 if (new_index
== GSUB_E_NOGLYPH
)
1356 ERR("Chain failed to generate a glyph.\n");
1361 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 3)
1363 WORD backtrack_count
, input_count
, lookahead_count
, substitution_count
;
1365 const GSUB_ChainContextSubstFormat3_1
*backtrack
;
1366 const GSUB_ChainContextSubstFormat3_2
*input
;
1367 const GSUB_ChainContextSubstFormat3_3
*lookahead
;
1368 const GSUB_ChainContextSubstFormat3_4
*substitute
;
1369 int new_index
= GSUB_E_NOGLYPH
;
1371 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
1373 backtrack
= (const GSUB_ChainContextSubstFormat3_1
*)ccsf1
;
1374 backtrack_count
= GET_BE_WORD(backtrack
->BacktrackGlyphCount
);
1375 k
= glyph_index
+ dirBacktrack
* backtrack_count
;
1376 if (k
< 0 || k
>= *glyph_count
)
1379 input
= (const GSUB_ChainContextSubstFormat3_2
*)&backtrack
->Coverage
[backtrack_count
];
1380 input_count
= GET_BE_WORD(input
->InputGlyphCount
);
1381 k
= glyph_index
+ write_dir
* (input_count
- 1);
1382 if (k
< 0 || k
>= *glyph_count
)
1385 lookahead
= (const GSUB_ChainContextSubstFormat3_3
*)&input
->Coverage
[input_count
];
1386 lookahead_count
= GET_BE_WORD(lookahead
->LookaheadGlyphCount
);
1387 k
= glyph_index
+ dirLookahead
* (input_count
+ lookahead_count
- 1);
1388 if (k
< 0 || k
>= *glyph_count
)
1391 substitute
= (const GSUB_ChainContextSubstFormat3_4
*)&lookahead
->Coverage
[lookahead_count
];
1393 for (k
= 0; k
< backtrack_count
; ++k
)
1395 offset
= GET_BE_WORD(backtrack
->Coverage
[k
]);
1396 if (GSUB_is_glyph_covered((const BYTE
*)ccsf1
+ offset
,
1397 glyphs
[glyph_index
+ (dirBacktrack
* (k
+ 1))]) == -1)
1400 if (k
!= backtrack_count
)
1402 TRACE("Matched Backtrack\n");
1404 for (k
= 0; k
< input_count
; ++k
)
1406 offset
= GET_BE_WORD(input
->Coverage
[k
]);
1407 if (GSUB_is_glyph_covered((const BYTE
*)ccsf1
+ offset
,
1408 glyphs
[glyph_index
+ (write_dir
* k
)]) == -1)
1411 if (k
!= input_count
)
1413 TRACE("Matched IndexGlyphs\n");
1415 for (k
= 0; k
< lookahead_count
; ++k
)
1417 offset
= GET_BE_WORD(lookahead
->Coverage
[k
]);
1418 if (GSUB_is_glyph_covered((const BYTE
*)ccsf1
+ offset
,
1419 glyphs
[glyph_index
+ (dirLookahead
* (input_count
+ k
))]) == -1)
1422 if (k
!= lookahead_count
)
1424 TRACE("Matched LookAhead\n");
1426 substitution_count
= GET_BE_WORD(substitute
->SubstCount
);
1427 for (k
= 0; k
< substitution_count
; ++k
)
1429 WORD lookup_index
= GET_BE_WORD(substitute
->SubstLookupRecord
[k
].LookupListIndex
);
1430 WORD sequence_index
= GET_BE_WORD(substitute
->SubstLookupRecord
[k
].SequenceIndex
) * write_dir
;
1432 TRACE("SUBST: %u -> %u %u.\n", k
, sequence_index
, lookup_index
);
1433 new_index
= GSUB_apply_lookup(lookup
, lookup_index
, glyphs
,
1434 glyph_index
+ sequence_index
, write_dir
, glyph_count
);
1435 if (new_index
== GSUB_E_NOGLYPH
)
1436 ERR("Chain failed to generate a glyph.\n");
1441 return GSUB_E_NOGLYPH
;
1444 static INT
GSUB_apply_lookup(const OT_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
1447 enum gsub_lookup_type type
;
1448 const OT_LookupTable
*look
;
1450 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
1451 look
= (const OT_LookupTable
*)((const BYTE
*)lookup
+ offset
);
1452 type
= GET_BE_WORD(look
->LookupType
);
1453 TRACE("type %#x, flag %#x, subtables %u.\n", type
,
1454 GET_BE_WORD(look
->LookupFlag
),GET_BE_WORD(look
->SubTableCount
));
1456 if (type
== GSUB_LOOKUP_EXTENSION
)
1458 if (GET_BE_WORD(look
->SubTableCount
))
1460 const GSUB_ExtensionPosFormat1
*ext
= (const GSUB_ExtensionPosFormat1
*)((const BYTE
*)look
+ GET_BE_WORD(look
->SubTable
[0]));
1461 if (GET_BE_WORD(ext
->SubstFormat
) == 1)
1463 type
= GET_BE_WORD(ext
->ExtensionLookupType
);
1464 TRACE("extension type %i\n",type
);
1468 FIXME("Unhandled Extension Substitution Format %i\n",GET_BE_WORD(ext
->SubstFormat
));
1473 WARN("lookup type is Extension Substitution but no extension subtable exists\n");
1478 case GSUB_LOOKUP_SINGLE
:
1479 return GSUB_apply_SingleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1480 case GSUB_LOOKUP_MULTIPLE
:
1481 return GSUB_apply_MultipleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1482 case GSUB_LOOKUP_ALTERNATE
:
1483 return GSUB_apply_AlternateSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1484 case GSUB_LOOKUP_LIGATURE
:
1485 return GSUB_apply_LigatureSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1486 case GSUB_LOOKUP_CONTEXT
:
1487 return GSUB_apply_ContextSubst(lookup
, look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1488 case GSUB_LOOKUP_CONTEXT_CHAINED
:
1489 return GSUB_apply_ChainContextSubst(lookup
, look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1490 case GSUB_LOOKUP_EXTENSION
:
1491 FIXME("Extension Substitution types not valid here\n");
1494 FIXME("Unhandled GSUB lookup type %#x.\n", type
);
1496 return GSUB_E_NOGLYPH
;
1499 int OpenType_apply_GSUB_lookup(const void *table
, unsigned int lookup_index
, WORD
*glyphs
,
1500 unsigned int glyph_index
, int write_dir
, int *glyph_count
)
1502 const GSUB_Header
*header
= (const GSUB_Header
*)table
;
1503 const OT_LookupList
*lookup
= (const OT_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
1505 return GSUB_apply_lookup(lookup
, lookup_index
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1511 static unsigned int GPOS_apply_lookup(const ScriptCache
*script_cache
, const OUTLINETEXTMETRICW
*otm
,
1512 const LOGFONTW
*logfont
, const SCRIPT_ANALYSIS
*analysis
, int *advance
, const OT_LookupList
*lookup
,
1513 unsigned int lookup_index
, const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
,
1516 static INT
GPOS_get_device_table_value(const OT_DeviceTable
*DeviceTable
, WORD ppem
)
1518 static const WORD mask
[3] = {3,0xf,0xff};
1519 if (DeviceTable
&& ppem
>= GET_BE_WORD(DeviceTable
->StartSize
) && ppem
<= GET_BE_WORD(DeviceTable
->EndSize
))
1521 WORD format
= GET_BE_WORD(DeviceTable
->DeltaFormat
);
1522 int index
= ppem
- GET_BE_WORD(DeviceTable
->StartSize
);
1525 TRACE("device table, format %#x, index %i\n", format
, index
);
1527 if (format
< 1 || format
> 3)
1529 WARN("invalid delta format %#x\n", format
);
1533 index
= index
<< format
;
1534 value
= (DeviceTable
->DeltaValue
[index
/sizeof(WORD
)] << (index
%sizeof(WORD
)))&mask
[format
-1];
1535 TRACE("offset %i, value %i\n",index
, value
);
1536 if (value
> mask
[format
-1]/2)
1537 value
= -1 * ((mask
[format
-1]+1) - value
);
1543 static void GPOS_get_anchor_values(const void *table
, POINT
*pt
, WORD ppem
)
1545 const GPOS_AnchorFormat1
* anchor1
= (const GPOS_AnchorFormat1
*)table
;
1547 switch (GET_BE_WORD(anchor1
->AnchorFormat
))
1551 TRACE("Anchor Format 1\n");
1552 pt
->x
= (short)GET_BE_WORD(anchor1
->XCoordinate
);
1553 pt
->y
= (short)GET_BE_WORD(anchor1
->YCoordinate
);
1558 const GPOS_AnchorFormat2
* anchor2
= (const GPOS_AnchorFormat2
*)table
;
1559 TRACE("Anchor Format 2\n");
1560 pt
->x
= (short)GET_BE_WORD(anchor2
->XCoordinate
);
1561 pt
->y
= (short)GET_BE_WORD(anchor2
->YCoordinate
);
1567 const GPOS_AnchorFormat3
* anchor3
= (const GPOS_AnchorFormat3
*)table
;
1568 TRACE("Anchor Format 3\n");
1569 pt
->x
= (short)GET_BE_WORD(anchor3
->XCoordinate
);
1570 pt
->y
= (short)GET_BE_WORD(anchor3
->YCoordinate
);
1571 offset
= GET_BE_WORD(anchor3
->XDeviceTable
);
1572 TRACE("ppem %i\n",ppem
);
1575 const OT_DeviceTable
* DeviceTableX
= NULL
;
1576 DeviceTableX
= (const OT_DeviceTable
*)((const BYTE
*)anchor3
+ offset
);
1577 pt
->x
+= GPOS_get_device_table_value(DeviceTableX
, ppem
);
1579 offset
= GET_BE_WORD(anchor3
->YDeviceTable
);
1582 const OT_DeviceTable
* DeviceTableY
= NULL
;
1583 DeviceTableY
= (const OT_DeviceTable
*)((const BYTE
*)anchor3
+ offset
);
1584 pt
->y
+= GPOS_get_device_table_value(DeviceTableY
, ppem
);
1589 ERR("Unknown Anchor Format %i\n",GET_BE_WORD(anchor1
->AnchorFormat
));
1595 static void GPOS_convert_design_units_to_device(const OUTLINETEXTMETRICW
*otm
, const LOGFONTW
*logfont
,
1596 int desX
, int desY
, double *devX
, double *devY
)
1598 int emHeight
= otm
->otmTextMetrics
.tmAscent
+ otm
->otmTextMetrics
.tmDescent
- otm
->otmTextMetrics
.tmInternalLeading
;
1600 TRACE("emHeight %i lfWidth %i\n",emHeight
, logfont
->lfWidth
);
1601 *devX
= (desX
* emHeight
) / (double)otm
->otmEMSquare
;
1602 *devY
= (desY
* emHeight
) / (double)otm
->otmEMSquare
;
1603 if (logfont
->lfWidth
)
1604 FIXME("Font with lfWidth set not handled properly.\n");
1607 static INT
GPOS_get_value_record(WORD ValueFormat
, const WORD data
[], GPOS_ValueRecord
*record
)
1610 if (ValueFormat
& 0x0001) { if (data
) record
->XPlacement
= GET_BE_WORD(data
[offset
]); offset
++; }
1611 if (ValueFormat
& 0x0002) { if (data
) record
->YPlacement
= GET_BE_WORD(data
[offset
]); offset
++; }
1612 if (ValueFormat
& 0x0004) { if (data
) record
->XAdvance
= GET_BE_WORD(data
[offset
]); offset
++; }
1613 if (ValueFormat
& 0x0008) { if (data
) record
->YAdvance
= GET_BE_WORD(data
[offset
]); offset
++; }
1614 if (ValueFormat
& 0x0010) { if (data
) record
->XPlaDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1615 if (ValueFormat
& 0x0020) { if (data
) record
->YPlaDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1616 if (ValueFormat
& 0x0040) { if (data
) record
->XAdvDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1617 if (ValueFormat
& 0x0080) { if (data
) record
->YAdvDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1621 static void GPOS_get_value_record_offsets(const BYTE
*head
, GPOS_ValueRecord
*ValueRecord
,
1622 WORD ValueFormat
, unsigned int ppem
, POINT
*ptPlacement
, POINT
*ptAdvance
)
1624 if (ValueFormat
& 0x0001) ptPlacement
->x
+= (short)ValueRecord
->XPlacement
;
1625 if (ValueFormat
& 0x0002) ptPlacement
->y
+= (short)ValueRecord
->YPlacement
;
1626 if (ValueFormat
& 0x0004) ptAdvance
->x
+= (short)ValueRecord
->XAdvance
;
1627 if (ValueFormat
& 0x0008) ptAdvance
->y
+= (short)ValueRecord
->YAdvance
;
1628 if (ValueFormat
& 0x0010) ptPlacement
->x
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->XPlaDevice
), ppem
);
1629 if (ValueFormat
& 0x0020) ptPlacement
->y
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->YPlaDevice
), ppem
);
1630 if (ValueFormat
& 0x0040) ptAdvance
->x
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->XAdvDevice
), ppem
);
1631 if (ValueFormat
& 0x0080) ptAdvance
->y
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->YAdvDevice
), ppem
);
1632 if (ValueFormat
& 0xFF00) FIXME("Unhandled Value Format %x\n",ValueFormat
&0xFF00);
1635 static const BYTE
*GPOS_get_subtable(const OT_LookupTable
*look
, int index
)
1637 int offset
= GET_BE_WORD(look
->SubTable
[index
]);
1639 if (GET_BE_WORD(look
->LookupType
) == GPOS_LOOKUP_POSITION_EXTENSION
)
1641 const GPOS_ExtensionPosFormat1
*ext
= (const GPOS_ExtensionPosFormat1
*)((const BYTE
*)look
+ offset
);
1642 if (GET_BE_WORD(ext
->PosFormat
) == 1)
1644 offset
+= GET_BE_DWORD(ext
->ExtensionOffset
);
1648 FIXME("Unhandled Extension Positioning Format %i\n",GET_BE_WORD(ext
->PosFormat
));
1651 return (const BYTE
*)look
+ offset
;
1654 static void GPOS_apply_SingleAdjustment(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
,
1655 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, unsigned int ppem
,
1656 POINT
*adjust
, POINT
*advance
)
1660 TRACE("Single Adjustment Positioning Subtable\n");
1662 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1664 const GPOS_SinglePosFormat1
*spf1
= (const GPOS_SinglePosFormat1
*)GPOS_get_subtable(look
, j
);
1666 if (GET_BE_WORD(spf1
->PosFormat
) == 1)
1668 offset
= GET_BE_WORD(spf1
->Coverage
);
1669 if (GSUB_is_glyph_covered((const BYTE
*)spf1
+offset
, glyphs
[glyph_index
]) != -1)
1671 GPOS_ValueRecord ValueRecord
= {0,0,0,0,0,0,0,0};
1672 WORD ValueFormat
= GET_BE_WORD(spf1
->ValueFormat
);
1673 GPOS_get_value_record(ValueFormat
, spf1
->Value
, &ValueRecord
);
1674 GPOS_get_value_record_offsets((const BYTE
*)spf1
, &ValueRecord
, ValueFormat
, ppem
, adjust
, advance
);
1675 TRACE("Glyph Adjusted by %i,%i\n",ValueRecord
.XPlacement
,ValueRecord
.YPlacement
);
1678 else if (GET_BE_WORD(spf1
->PosFormat
) == 2)
1681 const GPOS_SinglePosFormat2
*spf2
;
1682 spf2
= (const GPOS_SinglePosFormat2
*)spf1
;
1683 offset
= GET_BE_WORD(spf2
->Coverage
);
1684 index
= GSUB_is_glyph_covered((const BYTE
*)spf2
+offset
, glyphs
[glyph_index
]);
1688 GPOS_ValueRecord ValueRecord
= {0,0,0,0,0,0,0,0};
1689 WORD ValueFormat
= GET_BE_WORD(spf2
->ValueFormat
);
1690 size
= GPOS_get_value_record(ValueFormat
, spf2
->Value
, &ValueRecord
);
1693 offset
= size
* index
;
1694 GPOS_get_value_record(ValueFormat
, &spf2
->Value
[offset
], &ValueRecord
);
1696 GPOS_get_value_record_offsets((const BYTE
*)spf2
, &ValueRecord
, ValueFormat
, ppem
, adjust
, advance
);
1697 TRACE("Glyph Adjusted by %i,%i\n",ValueRecord
.XPlacement
,ValueRecord
.YPlacement
);
1701 FIXME("Single Adjustment Positioning: Format %i Unhandled\n",GET_BE_WORD(spf1
->PosFormat
));
1705 static void apply_pair_value( const void *pos_table
, WORD val_fmt1
, WORD val_fmt2
, const WORD
*pair
,
1706 INT ppem
, POINT
*adjust
, POINT
*advance
)
1708 GPOS_ValueRecord val_rec1
= {0,0,0,0,0,0,0,0};
1709 GPOS_ValueRecord val_rec2
= {0,0,0,0,0,0,0,0};
1712 size
= GPOS_get_value_record( val_fmt1
, pair
, &val_rec1
);
1713 GPOS_get_value_record( val_fmt2
, pair
+ size
, &val_rec2
);
1717 GPOS_get_value_record_offsets( pos_table
, &val_rec1
, val_fmt1
, ppem
, adjust
, advance
);
1718 TRACE( "Glyph 1 resulting cumulative offset is %s design units\n", wine_dbgstr_point(&adjust
[0]) );
1719 TRACE( "Glyph 1 resulting cumulative advance is %s design units\n", wine_dbgstr_point(&advance
[0]) );
1723 GPOS_get_value_record_offsets( pos_table
, &val_rec2
, val_fmt2
, ppem
, adjust
+ 1, advance
+ 1 );
1724 TRACE( "Glyph 2 resulting cumulative offset is %s design units\n", wine_dbgstr_point(&adjust
[1]) );
1725 TRACE( "Glyph 2 resulting cumulative advance is %s design units\n", wine_dbgstr_point(&advance
[1]) );
1729 static int GPOS_apply_PairAdjustment(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
,
1730 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, unsigned int ppem
,
1731 POINT
*adjust
, POINT
*advance
)
1734 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1736 if (glyph_index
+ write_dir
>= glyph_count
)
1739 TRACE("Pair Adjustment Positioning Subtable\n");
1741 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1743 const GPOS_PairPosFormat1
*ppf1
= (const GPOS_PairPosFormat1
*)GPOS_get_subtable(look
, j
);
1745 if (GET_BE_WORD(ppf1
->PosFormat
) == 1)
1748 WORD ValueFormat1
= GET_BE_WORD(ppf1
->ValueFormat1
);
1749 WORD ValueFormat2
= GET_BE_WORD(ppf1
->ValueFormat2
);
1750 INT val_fmt1_size
= GPOS_get_value_record( ValueFormat1
, NULL
, NULL
);
1751 INT val_fmt2_size
= GPOS_get_value_record( ValueFormat2
, NULL
, NULL
);
1752 offset
= GET_BE_WORD(ppf1
->Coverage
);
1753 index
= GSUB_is_glyph_covered((const BYTE
*)ppf1
+offset
, glyphs
[glyph_index
]);
1754 if (index
!= -1 && index
< GET_BE_WORD(ppf1
->PairSetCount
))
1758 const GPOS_PairSet
*ps
;
1759 const GPOS_PairValueRecord
*pair_val_rec
;
1760 offset
= GET_BE_WORD(ppf1
->PairSetOffset
[index
]);
1761 ps
= (const GPOS_PairSet
*)((const BYTE
*)ppf1
+offset
);
1762 pair_count
= GET_BE_WORD(ps
->PairValueCount
);
1763 pair_val_rec
= ps
->PairValueRecord
;
1764 for (k
= 0; k
< pair_count
; k
++)
1766 WORD second_glyph
= GET_BE_WORD(pair_val_rec
->SecondGlyph
);
1767 if (glyphs
[glyph_index
+write_dir
] == second_glyph
)
1770 TRACE("Format 1: Found Pair %x,%x\n",glyphs
[glyph_index
],glyphs
[glyph_index
+write_dir
]);
1771 apply_pair_value(ppf1
, ValueFormat1
, ValueFormat2
,
1772 pair_val_rec
->Value1
, ppem
, adjust
, advance
);
1773 if (ValueFormat2
) next
++;
1776 pair_val_rec
= (const GPOS_PairValueRecord
*)(pair_val_rec
->Value1
+ val_fmt1_size
+ val_fmt2_size
);
1780 else if (GET_BE_WORD(ppf1
->PosFormat
) == 2)
1782 const GPOS_PairPosFormat2
*ppf2
= (const GPOS_PairPosFormat2
*)ppf1
;
1784 WORD ValueFormat1
= GET_BE_WORD( ppf2
->ValueFormat1
);
1785 WORD ValueFormat2
= GET_BE_WORD( ppf2
->ValueFormat2
);
1786 INT val_fmt1_size
= GPOS_get_value_record( ValueFormat1
, NULL
, NULL
);
1787 INT val_fmt2_size
= GPOS_get_value_record( ValueFormat2
, NULL
, NULL
);
1788 WORD class1_count
= GET_BE_WORD( ppf2
->Class1Count
);
1789 WORD class2_count
= GET_BE_WORD( ppf2
->Class2Count
);
1791 offset
= GET_BE_WORD( ppf2
->Coverage
);
1792 index
= GSUB_is_glyph_covered( (const BYTE
*)ppf2
+ offset
, glyphs
[glyph_index
] );
1795 WORD class1
, class2
;
1796 class1
= OT_get_glyph_class( (const BYTE
*)ppf2
+ GET_BE_WORD(ppf2
->ClassDef1
), glyphs
[glyph_index
] );
1797 class2
= OT_get_glyph_class( (const BYTE
*)ppf2
+ GET_BE_WORD(ppf2
->ClassDef2
), glyphs
[glyph_index
+ write_dir
] );
1798 if (class1
< class1_count
&& class2
< class2_count
)
1800 const WORD
*pair_val
= ppf2
->Class1Record
+ (class1
* class2_count
+ class2
) * (val_fmt1_size
+ val_fmt2_size
);
1803 TRACE( "Format 2: Found Pair %x,%x\n", glyphs
[glyph_index
], glyphs
[glyph_index
+ write_dir
] );
1805 apply_pair_value(ppf2
, ValueFormat1
, ValueFormat2
, pair_val
, ppem
, adjust
, advance
);
1806 if (ValueFormat2
) next
++;
1812 FIXME("Pair Adjustment Positioning: Format %i Unhandled\n",GET_BE_WORD(ppf1
->PosFormat
));
1817 static void GPOS_apply_CursiveAttachment(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
,
1818 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, unsigned int ppem
, POINT
*pt
)
1821 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1823 if (glyph_index
+ write_dir
>= glyph_count
)
1826 TRACE("Cursive Attachment Positioning Subtable\n");
1828 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1830 const GPOS_CursivePosFormat1
*cpf1
= (const GPOS_CursivePosFormat1
*)GPOS_get_subtable(look
, j
);
1831 if (GET_BE_WORD(cpf1
->PosFormat
) == 1)
1833 int index_exit
, index_entry
;
1834 WORD offset
= GET_BE_WORD( cpf1
->Coverage
);
1835 index_exit
= GSUB_is_glyph_covered((const BYTE
*)cpf1
+offset
, glyphs
[glyph_index
]);
1836 if (index_exit
!= -1 && cpf1
->EntryExitRecord
[index_exit
].ExitAnchor
!= 0)
1838 index_entry
= GSUB_is_glyph_covered((const BYTE
*)cpf1
+offset
, glyphs
[glyph_index
+write_dir
]);
1839 if (index_entry
!= -1 && cpf1
->EntryExitRecord
[index_entry
].EntryAnchor
!= 0)
1841 POINT exit_pt
, entry_pt
;
1842 offset
= GET_BE_WORD(cpf1
->EntryExitRecord
[index_exit
].ExitAnchor
);
1843 GPOS_get_anchor_values((const BYTE
*)cpf1
+ offset
, &exit_pt
, ppem
);
1844 offset
= GET_BE_WORD(cpf1
->EntryExitRecord
[index_entry
].EntryAnchor
);
1845 GPOS_get_anchor_values((const BYTE
*)cpf1
+ offset
, &entry_pt
, ppem
);
1846 TRACE("Found linkage %x[%s] %x[%s]\n",glyphs
[glyph_index
], wine_dbgstr_point(&exit_pt
), glyphs
[glyph_index
+write_dir
], wine_dbgstr_point(&entry_pt
));
1847 pt
->x
= entry_pt
.x
- exit_pt
.x
;
1848 pt
->y
= entry_pt
.y
- exit_pt
.y
;
1854 FIXME("Cursive Attachment Positioning: Format %i Unhandled\n",GET_BE_WORD(cpf1
->PosFormat
));
1859 static int GPOS_apply_MarkToBase(const ScriptCache
*script_cache
, const OT_LookupTable
*look
,
1860 const SCRIPT_ANALYSIS
*analysis
, const WORD
*glyphs
, unsigned int glyph_index
,
1861 unsigned int glyph_count
, unsigned int ppem
, POINT
*pt
)
1864 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1865 const void *glyph_class_table
= NULL
;
1868 if (script_cache
->GDEF_Table
)
1870 const GDEF_Header
*header
= script_cache
->GDEF_Table
;
1871 WORD offset
= GET_BE_WORD( header
->GlyphClassDef
);
1873 glyph_class_table
= (const BYTE
*)script_cache
->GDEF_Table
+ offset
;
1876 TRACE("MarkToBase Attachment Positioning Subtable\n");
1878 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1880 const GPOS_MarkBasePosFormat1
*mbpf1
= (const GPOS_MarkBasePosFormat1
*)GPOS_get_subtable(look
, j
);
1881 if (GET_BE_WORD(mbpf1
->PosFormat
) == 1)
1883 int offset
= GET_BE_WORD(mbpf1
->MarkCoverage
);
1885 mark_index
= GSUB_is_glyph_covered((const BYTE
*)mbpf1
+offset
, glyphs
[glyph_index
]);
1886 if (mark_index
!= -1)
1889 int base_glyph
= glyph_index
- write_dir
;
1891 if (glyph_class_table
)
1893 while (OT_get_glyph_class(glyph_class_table
, glyphs
[base_glyph
]) == MarkGlyph
&& base_glyph
> 0 && base_glyph
< glyph_count
)
1894 base_glyph
-= write_dir
;
1897 offset
= GET_BE_WORD(mbpf1
->BaseCoverage
);
1898 base_index
= GSUB_is_glyph_covered((const BYTE
*)mbpf1
+offset
, glyphs
[base_glyph
]);
1899 if (base_index
!= -1)
1901 const GPOS_MarkArray
*ma
;
1902 const GPOS_MarkRecord
*mr
;
1903 const GPOS_BaseArray
*ba
;
1904 const GPOS_BaseRecord
*br
;
1906 int class_count
= GET_BE_WORD(mbpf1
->ClassCount
);
1907 int baserecord_size
;
1910 TRACE("Mark %x(%i) and base %x(%i)\n",glyphs
[glyph_index
], mark_index
, glyphs
[base_glyph
], base_index
);
1911 offset
= GET_BE_WORD(mbpf1
->MarkArray
);
1912 ma
= (const GPOS_MarkArray
*)((const BYTE
*)mbpf1
+ offset
);
1913 if (mark_index
> GET_BE_WORD(ma
->MarkCount
))
1915 ERR("Mark index exceeded mark count\n");
1918 mr
= &ma
->MarkRecord
[mark_index
];
1919 mark_class
= GET_BE_WORD(mr
->Class
);
1920 TRACE("Mark Class %i total classes %i\n",mark_class
,class_count
);
1921 offset
= GET_BE_WORD(mbpf1
->BaseArray
);
1922 ba
= (const GPOS_BaseArray
*)((const BYTE
*)mbpf1
+ offset
);
1923 baserecord_size
= class_count
* sizeof(WORD
);
1924 br
= (const GPOS_BaseRecord
*)((const BYTE
*)ba
+ sizeof(WORD
) + (baserecord_size
* base_index
));
1925 offset
= GET_BE_WORD(br
->BaseAnchor
[mark_class
]);
1926 GPOS_get_anchor_values((const BYTE
*)ba
+ offset
, &base_pt
, ppem
);
1927 offset
= GET_BE_WORD(mr
->MarkAnchor
);
1928 GPOS_get_anchor_values((const BYTE
*)ma
+ offset
, &mark_pt
, ppem
);
1929 TRACE("Offset on base is %s design units\n",wine_dbgstr_point(&base_pt
));
1930 TRACE("Offset on mark is %s design units\n",wine_dbgstr_point(&mark_pt
));
1931 pt
->x
+= base_pt
.x
- mark_pt
.x
;
1932 pt
->y
+= base_pt
.y
- mark_pt
.y
;
1933 TRACE("Resulting cumulative offset is %s design units\n",wine_dbgstr_point(pt
));
1939 FIXME("Unhandled Mark To Base Format %i\n",GET_BE_WORD(mbpf1
->PosFormat
));
1944 static void GPOS_apply_MarkToLigature(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
,
1945 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, unsigned int ppem
, POINT
*pt
)
1948 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1950 TRACE("MarkToLigature Attachment Positioning Subtable\n");
1952 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1954 const GPOS_MarkLigPosFormat1
*mlpf1
= (const GPOS_MarkLigPosFormat1
*)GPOS_get_subtable(look
, j
);
1955 if (GET_BE_WORD(mlpf1
->PosFormat
) == 1)
1957 int offset
= GET_BE_WORD(mlpf1
->MarkCoverage
);
1959 mark_index
= GSUB_is_glyph_covered((const BYTE
*)mlpf1
+offset
, glyphs
[glyph_index
]);
1960 if (mark_index
!= -1)
1963 offset
= GET_BE_WORD(mlpf1
->LigatureCoverage
);
1964 ligature_index
= GSUB_is_glyph_covered((const BYTE
*)mlpf1
+offset
, glyphs
[glyph_index
- write_dir
]);
1965 if (ligature_index
!= -1)
1967 const GPOS_MarkArray
*ma
;
1968 const GPOS_MarkRecord
*mr
;
1970 const GPOS_LigatureArray
*la
;
1971 const GPOS_LigatureAttach
*lt
;
1973 int class_count
= GET_BE_WORD(mlpf1
->ClassCount
);
1974 int component_count
;
1980 TRACE("Mark %x(%i) and ligature %x(%i)\n",glyphs
[glyph_index
], mark_index
, glyphs
[glyph_index
- write_dir
], ligature_index
);
1981 offset
= GET_BE_WORD(mlpf1
->MarkArray
);
1982 ma
= (const GPOS_MarkArray
*)((const BYTE
*)mlpf1
+ offset
);
1983 if (mark_index
> GET_BE_WORD(ma
->MarkCount
))
1985 ERR("Mark index exceeded mark count\n");
1988 mr
= &ma
->MarkRecord
[mark_index
];
1989 mark_class
= GET_BE_WORD(mr
->Class
);
1990 TRACE("Mark Class %i total classes %i\n",mark_class
,class_count
);
1991 offset
= GET_BE_WORD(mlpf1
->LigatureArray
);
1992 la
= (const GPOS_LigatureArray
*)((const BYTE
*)mlpf1
+ offset
);
1993 if (ligature_index
> GET_BE_WORD(la
->LigatureCount
))
1995 ERR("Ligature index exceeded ligature count\n");
1998 offset
= GET_BE_WORD(la
->LigatureAttach
[ligature_index
]);
1999 lt
= (const GPOS_LigatureAttach
*)((const BYTE
*)la
+ offset
);
2001 component_count
= GET_BE_WORD(lt
->ComponentCount
);
2002 component_size
= class_count
* sizeof(WORD
);
2004 for (i
= 0; i
< component_count
&& !offset
; i
++)
2007 const GPOS_ComponentRecord
*cr
= (const GPOS_ComponentRecord
*)((const BYTE
*)lt
->ComponentRecord
+ (component_size
* i
));
2008 for (k
= 0; k
< class_count
&& !offset
; k
++)
2009 offset
= GET_BE_WORD(cr
->LigatureAnchor
[k
]);
2010 cr
= (const GPOS_ComponentRecord
*)((const BYTE
*)cr
+ component_size
);
2014 ERR("Failed to find avalible ligature connection point\n");
2018 GPOS_get_anchor_values((const BYTE
*)lt
+ offset
, &ligature_pt
, ppem
);
2019 offset
= GET_BE_WORD(mr
->MarkAnchor
);
2020 GPOS_get_anchor_values((const BYTE
*)ma
+ offset
, &mark_pt
, ppem
);
2021 TRACE("Offset on ligature is %s design units\n",wine_dbgstr_point(&ligature_pt
));
2022 TRACE("Offset on mark is %s design units\n",wine_dbgstr_point(&mark_pt
));
2023 pt
->x
+= ligature_pt
.x
- mark_pt
.x
;
2024 pt
->y
+= ligature_pt
.y
- mark_pt
.y
;
2025 TRACE("Resulting cumulative offset is %s design units\n",wine_dbgstr_point(pt
));
2030 FIXME("Unhandled Mark To Ligature Format %i\n",GET_BE_WORD(mlpf1
->PosFormat
));
2034 static BOOL
GPOS_apply_MarkToMark(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
,
2035 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, unsigned int ppem
, POINT
*pt
)
2039 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2041 TRACE("MarkToMark Attachment Positioning Subtable\n");
2043 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
2045 const GPOS_MarkMarkPosFormat1
*mmpf1
= (const GPOS_MarkMarkPosFormat1
*)GPOS_get_subtable(look
, j
);
2046 if (GET_BE_WORD(mmpf1
->PosFormat
) == 1)
2048 int offset
= GET_BE_WORD(mmpf1
->Mark1Coverage
);
2050 mark_index
= GSUB_is_glyph_covered((const BYTE
*)mmpf1
+offset
, glyphs
[glyph_index
]);
2051 if (mark_index
!= -1)
2054 offset
= GET_BE_WORD(mmpf1
->Mark2Coverage
);
2055 mark2_index
= GSUB_is_glyph_covered((const BYTE
*)mmpf1
+offset
, glyphs
[glyph_index
- write_dir
]);
2056 if (mark2_index
!= -1)
2058 const GPOS_MarkArray
*ma
;
2059 const GPOS_MarkRecord
*mr
;
2060 const GPOS_Mark2Array
*m2a
;
2061 const GPOS_Mark2Record
*m2r
;
2063 int class_count
= GET_BE_WORD(mmpf1
->ClassCount
);
2064 int mark2record_size
;
2067 TRACE("Mark %x(%i) and Mark2 %x(%i)\n",glyphs
[glyph_index
], mark_index
, glyphs
[glyph_index
- write_dir
], mark2_index
);
2068 offset
= GET_BE_WORD(mmpf1
->Mark1Array
);
2069 ma
= (const GPOS_MarkArray
*)((const BYTE
*)mmpf1
+ offset
);
2070 if (mark_index
> GET_BE_WORD(ma
->MarkCount
))
2072 ERR("Mark index exceeded mark count\n");
2075 mr
= &ma
->MarkRecord
[mark_index
];
2076 mark_class
= GET_BE_WORD(mr
->Class
);
2077 TRACE("Mark Class %i total classes %i\n",mark_class
,class_count
);
2078 offset
= GET_BE_WORD(mmpf1
->Mark2Array
);
2079 m2a
= (const GPOS_Mark2Array
*)((const BYTE
*)mmpf1
+ offset
);
2080 mark2record_size
= class_count
* sizeof(WORD
);
2081 m2r
= (const GPOS_Mark2Record
*)((const BYTE
*)m2a
+ sizeof(WORD
) + (mark2record_size
* mark2_index
));
2082 offset
= GET_BE_WORD(m2r
->Mark2Anchor
[mark_class
]);
2083 GPOS_get_anchor_values((const BYTE
*)m2a
+ offset
, &mark2_pt
, ppem
);
2084 offset
= GET_BE_WORD(mr
->MarkAnchor
);
2085 GPOS_get_anchor_values((const BYTE
*)ma
+ offset
, &mark_pt
, ppem
);
2086 TRACE("Offset on mark2 is %s design units\n",wine_dbgstr_point(&mark2_pt
));
2087 TRACE("Offset on mark is %s design units\n",wine_dbgstr_point(&mark_pt
));
2088 pt
->x
+= mark2_pt
.x
- mark_pt
.x
;
2089 pt
->y
+= mark2_pt
.y
- mark_pt
.y
;
2090 TRACE("Resulting cumulative offset is %s design units\n",wine_dbgstr_point(pt
));
2096 FIXME("Unhandled Mark To Mark Format %i\n",GET_BE_WORD(mmpf1
->PosFormat
));
2101 static unsigned int GPOS_apply_ContextPos(const ScriptCache
*script_cache
, const OUTLINETEXTMETRICW
*otm
,
2102 const LOGFONTW
*logfont
, const SCRIPT_ANALYSIS
*analysis
, int *advance
, const OT_LookupList
*lookup
,
2103 const OT_LookupTable
*look
, const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
,
2107 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2109 TRACE("Contextual Positioning Subtable\n");
2111 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
2113 const GPOS_ContextPosFormat2
*cpf2
= (GPOS_ContextPosFormat2
*)GPOS_get_subtable(look
, j
);
2115 if (GET_BE_WORD(cpf2
->PosFormat
) == 1)
2119 FIXME(" TODO: subtype 1\n");
2122 else if (GET_BE_WORD(cpf2
->PosFormat
) == 2)
2124 WORD offset
= GET_BE_WORD(cpf2
->Coverage
);
2127 TRACE("Contextual Positioning Subtable: Format 2\n");
2129 index
= GSUB_is_glyph_covered((const BYTE
*)cpf2
+offset
, glyphs
[glyph_index
]);
2130 TRACE("Coverage index %i\n",index
);
2133 int k
, count
, class;
2134 const GPOS_PosClassSet
*pcs
;
2135 const void *glyph_class_table
= NULL
;
2137 offset
= GET_BE_WORD(cpf2
->ClassDef
);
2138 glyph_class_table
= (const BYTE
*)cpf2
+ offset
;
2140 class = OT_get_glyph_class(glyph_class_table
,glyphs
[glyph_index
]);
2142 offset
= GET_BE_WORD(cpf2
->PosClassSet
[class]);
2145 TRACE("No class rule table for class %i\n",class);
2148 pcs
= (const GPOS_PosClassSet
*)((const BYTE
*)cpf2
+offset
);
2149 count
= GET_BE_WORD(pcs
->PosClassRuleCnt
);
2150 TRACE("PosClassSet has %i members\n",count
);
2151 for (k
= 0; k
< count
; k
++)
2153 const GPOS_PosClassRule_1
*pr
;
2154 const GPOS_PosClassRule_2
*pr_2
;
2157 offset
= GET_BE_WORD(pcs
->PosClassRule
[k
]);
2158 pr
= (const GPOS_PosClassRule_1
*)((const BYTE
*)pcs
+offset
);
2159 g_count
= GET_BE_WORD(pr
->GlyphCount
);
2160 TRACE("PosClassRule has %i glyphs classes\n",g_count
);
2161 for (l
= 0; l
< g_count
-1; l
++)
2163 int g_class
= OT_get_glyph_class(glyph_class_table
, glyphs
[glyph_index
+ (write_dir
* (l
+1))]);
2164 if (g_class
!= GET_BE_WORD(pr
->Class
[l
])) break;
2169 TRACE("Rule does not match\n");
2173 TRACE("Rule matches\n");
2174 pr_2
= (const GPOS_PosClassRule_2
*)((const BYTE
*)pr
+
2175 FIELD_OFFSET(GPOS_PosClassRule_1
, Class
[g_count
-1]));
2177 for (l
= 0; l
< GET_BE_WORD(pr
->PosCount
); l
++)
2179 int lookupIndex
= GET_BE_WORD(pr_2
->PosLookupRecord
[l
].LookupListIndex
);
2180 int SequenceIndex
= GET_BE_WORD(pr_2
->PosLookupRecord
[l
].SequenceIndex
) * write_dir
;
2182 TRACE("Position: %i -> %i %i\n",l
, SequenceIndex
, lookupIndex
);
2183 GPOS_apply_lookup(script_cache
, otm
, logfont
, analysis
, advance
, lookup
, lookupIndex
,
2184 glyphs
, glyph_index
+ SequenceIndex
, glyph_count
, goffset
);
2190 TRACE("Not covered\n");
2193 else if (GET_BE_WORD(cpf2
->PosFormat
) == 3)
2197 FIXME(" TODO: subtype 3\n");
2201 FIXME("Unhandled Contextual Positioning Format %i\n",GET_BE_WORD(cpf2
->PosFormat
));
2206 static unsigned int GPOS_apply_ChainContextPos(const ScriptCache
*script_cache
, const OUTLINETEXTMETRICW
*otm
,
2207 const LOGFONTW
*logfont
, const SCRIPT_ANALYSIS
*analysis
, int *advance
, const OT_LookupList
*lookup
,
2208 const OT_LookupTable
*look
, const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
,
2212 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2214 TRACE("Chaining Contextual Positioning Subtable\n");
2216 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
2219 const GPOS_ChainContextPosFormat3_1
*backtrack
= (GPOS_ChainContextPosFormat3_1
*)GPOS_get_subtable(look
, j
);
2220 int dirLookahead
= write_dir
;
2221 int dirBacktrack
= -1 * write_dir
;
2223 if (GET_BE_WORD(backtrack
->PosFormat
) == 1)
2227 FIXME(" TODO: subtype 1 (Simple Chaining Context Glyph Positioning)\n");
2230 else if (GET_BE_WORD(backtrack
->PosFormat
) == 2)
2234 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Positioning)\n");
2237 else if (GET_BE_WORD(backtrack
->PosFormat
) == 3)
2239 WORD backtrack_count
, input_count
, lookahead_count
, positioning_count
;
2241 const GPOS_ChainContextPosFormat3_2
*input
;
2242 const GPOS_ChainContextPosFormat3_3
*lookahead
;
2243 const GPOS_ChainContextPosFormat3_4
*positioning
;
2245 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Positioning)\n");
2247 backtrack_count
= GET_BE_WORD(backtrack
->BacktrackGlyphCount
);
2248 k
= glyph_index
+ dirBacktrack
* backtrack_count
;
2249 if (k
< 0 || k
>= glyph_count
)
2252 input
= (const GPOS_ChainContextPosFormat3_2
*)&backtrack
->Coverage
[backtrack_count
];
2253 input_count
= GET_BE_WORD(input
->InputGlyphCount
);
2254 k
= glyph_index
+ write_dir
* (input_count
- 1);
2255 if (k
< 0 || k
>= glyph_count
)
2258 lookahead
= (const GPOS_ChainContextPosFormat3_3
*)&input
->Coverage
[input_count
];
2259 lookahead_count
= GET_BE_WORD(lookahead
->LookaheadGlyphCount
);
2260 k
= glyph_index
+ dirLookahead
* (input_count
+ lookahead_count
- 1);
2261 if (k
< 0 || k
>= glyph_count
)
2264 positioning
= (const GPOS_ChainContextPosFormat3_4
*)&lookahead
->Coverage
[lookahead_count
];
2266 for (k
= 0; k
< backtrack_count
; ++k
)
2268 offset
= GET_BE_WORD(backtrack
->Coverage
[k
]);
2269 if (GSUB_is_glyph_covered((const BYTE
*)backtrack
+ offset
,
2270 glyphs
[glyph_index
+ (dirBacktrack
* (k
+ 1))]) == -1)
2273 if (k
!= backtrack_count
)
2275 TRACE("Matched Backtrack\n");
2277 for (k
= 0; k
< input_count
; ++k
)
2279 offset
= GET_BE_WORD(input
->Coverage
[k
]);
2280 if (GSUB_is_glyph_covered((const BYTE
*)backtrack
+ offset
,
2281 glyphs
[glyph_index
+ (write_dir
* k
)]) == -1)
2284 if (k
!= input_count
)
2286 TRACE("Matched IndexGlyphs\n");
2288 for (k
= 0; k
< lookahead_count
; ++k
)
2290 offset
= GET_BE_WORD(lookahead
->Coverage
[k
]);
2291 if (GSUB_is_glyph_covered((const BYTE
*)backtrack
+ offset
,
2292 glyphs
[glyph_index
+ (dirLookahead
* (input_count
+ k
))]) == -1)
2295 if (k
!= lookahead_count
)
2297 TRACE("Matched LookAhead\n");
2299 if (!(positioning_count
= GET_BE_WORD(positioning
->PosCount
)))
2302 for (k
= 0; k
< positioning_count
; ++k
)
2304 WORD lookup_index
= GET_BE_WORD(positioning
->PosLookupRecord
[k
].LookupListIndex
);
2305 WORD sequence_index
= GET_BE_WORD(positioning
->PosLookupRecord
[k
].SequenceIndex
) * write_dir
;
2307 TRACE("Position: %u -> %u %u.\n", k
, sequence_index
, lookup_index
);
2308 GPOS_apply_lookup(script_cache
, otm
, logfont
, analysis
, advance
, lookup
, lookup_index
,
2309 glyphs
, glyph_index
+ sequence_index
, glyph_count
, goffset
);
2311 return input_count
+ lookahead_count
;
2314 FIXME("Unhandled Chaining Contextual Positioning Format %#x.\n", GET_BE_WORD(backtrack
->PosFormat
));
2319 static unsigned int GPOS_apply_lookup(const ScriptCache
*script_cache
, const OUTLINETEXTMETRICW
*lpotm
,
2320 const LOGFONTW
*lplogfont
, const SCRIPT_ANALYSIS
*analysis
, int *piAdvance
, const OT_LookupList
*lookup
,
2321 unsigned int lookup_index
, const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
,
2325 const OT_LookupTable
*look
;
2326 int ppem
= lpotm
->otmTextMetrics
.tmAscent
+ lpotm
->otmTextMetrics
.tmDescent
- lpotm
->otmTextMetrics
.tmInternalLeading
;
2327 enum gpos_lookup_type type
;
2329 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
2330 look
= (const OT_LookupTable
*)((const BYTE
*)lookup
+ offset
);
2331 type
= GET_BE_WORD(look
->LookupType
);
2332 TRACE("type %#x, flag %#x, subtables %u.\n", type
,
2333 GET_BE_WORD(look
->LookupFlag
), GET_BE_WORD(look
->SubTableCount
));
2335 if (type
== GPOS_LOOKUP_POSITION_EXTENSION
)
2337 if (GET_BE_WORD(look
->SubTableCount
))
2339 const GPOS_ExtensionPosFormat1
*ext
= (const GPOS_ExtensionPosFormat1
*)((const BYTE
*)look
+ GET_BE_WORD(look
->SubTable
[0]));
2340 if (GET_BE_WORD(ext
->PosFormat
) == 1)
2342 type
= GET_BE_WORD(ext
->ExtensionLookupType
);
2343 TRACE("extension type %i\n",type
);
2347 FIXME("Unhandled Extension Positioning Format %i\n",GET_BE_WORD(ext
->PosFormat
));
2352 WARN("lookup type is Extension Positioning but no extension subtable exists\n");
2357 case GPOS_LOOKUP_ADJUST_SINGLE
:
2360 POINT adjust
= {0,0};
2361 POINT advance
= {0,0};
2362 GPOS_apply_SingleAdjustment(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &adjust
, &advance
);
2363 if (adjust
.x
|| adjust
.y
)
2365 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, adjust
.x
, adjust
.y
, &devX
, &devY
);
2366 pGoffset
[glyph_index
].du
+= round(devX
);
2367 pGoffset
[glyph_index
].dv
+= round(devY
);
2369 if (advance
.x
|| advance
.y
)
2371 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, advance
.x
, advance
.y
, &devX
, &devY
);
2372 piAdvance
[glyph_index
] += round(devX
);
2374 FIXME("Unhandled adjustment to Y advancement\n");
2379 case GPOS_LOOKUP_ADJUST_PAIR
:
2381 POINT advance
[2]= {{0,0},{0,0}};
2382 POINT adjust
[2]= {{0,0},{0,0}};
2385 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2386 int offset_sign
= (analysis
->fRTL
&& analysis
->fLogicalOrder
) ? -1 : 1;
2388 index_offset
= GPOS_apply_PairAdjustment(look
, analysis
, glyphs
,
2389 glyph_index
, glyph_count
, ppem
, adjust
, advance
);
2390 if (adjust
[0].x
|| adjust
[0].y
)
2392 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, adjust
[0].x
, adjust
[0].y
, &devX
, &devY
);
2393 pGoffset
[glyph_index
].du
+= round(devX
) * offset_sign
;
2394 pGoffset
[glyph_index
].dv
+= round(devY
);
2396 if (advance
[0].x
|| advance
[0].y
)
2398 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, advance
[0].x
, advance
[0].y
, &devX
, &devY
);
2399 piAdvance
[glyph_index
] += round(devX
);
2401 if (adjust
[1].x
|| adjust
[1].y
)
2403 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, adjust
[1].x
, adjust
[1].y
, &devX
, &devY
);
2404 pGoffset
[glyph_index
+ write_dir
].du
+= round(devX
) * offset_sign
;
2405 pGoffset
[glyph_index
+ write_dir
].dv
+= round(devY
);
2407 if (advance
[1].x
|| advance
[1].y
)
2409 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, advance
[1].x
, advance
[1].y
, &devX
, &devY
);
2410 piAdvance
[glyph_index
+ write_dir
] += round(devX
);
2412 return index_offset
;
2415 case GPOS_LOOKUP_ATTACH_CURSIVE
:
2419 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2421 GPOS_apply_CursiveAttachment(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &desU
);
2422 if (desU
.x
|| desU
.y
)
2424 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
2425 /* Windows does not appear to apply X offsets here */
2426 pGoffset
[glyph_index
].dv
= round(devY
) + pGoffset
[glyph_index
+write_dir
].dv
;
2431 case GPOS_LOOKUP_ATTACH_MARK_TO_BASE
:
2435 int base_index
= GPOS_apply_MarkToBase(script_cache
, look
, analysis
,
2436 glyphs
, glyph_index
, glyph_count
, ppem
, &desU
);
2437 if (base_index
!= -1)
2439 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
2440 if (!analysis
->fRTL
) pGoffset
[glyph_index
].du
= round(devX
) - piAdvance
[base_index
];
2443 if (analysis
->fLogicalOrder
) devX
*= -1;
2444 pGoffset
[glyph_index
].du
= round(devX
);
2446 pGoffset
[glyph_index
].dv
= round(devY
);
2451 case GPOS_LOOKUP_ATTACH_MARK_TO_LIGATURE
:
2455 GPOS_apply_MarkToLigature(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &desU
);
2456 if (desU
.x
|| desU
.y
)
2458 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
2459 pGoffset
[glyph_index
].du
= (round(devX
) - piAdvance
[glyph_index
-1]);
2460 pGoffset
[glyph_index
].dv
= round(devY
);
2465 case GPOS_LOOKUP_ATTACH_MARK_TO_MARK
:
2469 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2470 if (GPOS_apply_MarkToMark(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &desU
))
2472 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
2473 if (analysis
->fRTL
&& analysis
->fLogicalOrder
) devX
*= -1;
2474 pGoffset
[glyph_index
].du
= round(devX
) + pGoffset
[glyph_index
- write_dir
].du
;
2475 pGoffset
[glyph_index
].dv
= round(devY
) + pGoffset
[glyph_index
- write_dir
].dv
;
2480 case GPOS_LOOKUP_POSITION_CONTEXT
:
2481 return GPOS_apply_ContextPos(script_cache
, lpotm
, lplogfont
, analysis
, piAdvance
,
2482 lookup
, look
, glyphs
, glyph_index
, glyph_count
, pGoffset
);
2484 case GPOS_LOOKUP_POSITION_CONTEXT_CHAINED
:
2485 return GPOS_apply_ChainContextPos(script_cache
, lpotm
, lplogfont
, analysis
, piAdvance
,
2486 lookup
, look
, glyphs
, glyph_index
, glyph_count
, pGoffset
);
2489 FIXME("Unhandled GPOS lookup type %#x.\n", type
);
2494 unsigned int OpenType_apply_GPOS_lookup(const ScriptCache
*script_cache
, const OUTLINETEXTMETRICW
*otm
,
2495 const LOGFONTW
*logfont
, const SCRIPT_ANALYSIS
*analysis
, int *advance
, unsigned int lookup_index
,
2496 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, GOFFSET
*goffset
)
2498 const GPOS_Header
*header
= (const GPOS_Header
*)script_cache
->GPOS_Table
;
2499 const OT_LookupList
*lookup
= (const OT_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
2501 return GPOS_apply_lookup(script_cache
, otm
, logfont
, analysis
, advance
, lookup
,
2502 lookup_index
, glyphs
, glyph_index
, glyph_count
, goffset
);
2505 static LoadedScript
*usp10_script_cache_get_script(ScriptCache
*script_cache
, OPENTYPE_TAG tag
)
2509 for (i
= 0; i
< script_cache
->script_count
; ++i
)
2511 if (script_cache
->scripts
[i
].tag
== tag
)
2512 return &script_cache
->scripts
[i
];
2518 static void GSUB_initialize_script_cache(ScriptCache
*psc
)
2522 if (psc
->GSUB_Table
)
2524 const OT_ScriptList
*script
;
2525 const GSUB_Header
* header
= (const GSUB_Header
*)psc
->GSUB_Table
;
2526 script
= (const OT_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
2527 psc
->script_count
= GET_BE_WORD(script
->ScriptCount
);
2528 TRACE("initializing %li scripts in this font\n",psc
->script_count
);
2529 if (psc
->script_count
)
2531 psc
->scripts
= heap_alloc_zero(psc
->script_count
* sizeof(*psc
->scripts
));
2532 for (i
= 0; i
< psc
->script_count
; i
++)
2534 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
2535 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]);
2536 psc
->scripts
[i
].gsub_table
= ((const BYTE
*)script
+ offset
);
2542 static void GPOS_expand_script_cache(ScriptCache
*psc
)
2545 const OT_ScriptList
*script
;
2546 const GPOS_Header
* header
= (const GPOS_Header
*)psc
->GPOS_Table
;
2547 LoadedScript
*loaded_script
;
2552 script
= (const OT_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
2553 count
= GET_BE_WORD(script
->ScriptCount
);
2558 if (!psc
->script_count
)
2560 psc
->script_count
= count
;
2561 TRACE("initializing %li scripts in this font\n",psc
->script_count
);
2562 if (psc
->script_count
)
2564 psc
->scripts
= heap_alloc_zero(psc
->script_count
* sizeof(*psc
->scripts
));
2565 for (i
= 0; i
< psc
->script_count
; i
++)
2567 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
2568 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]);
2569 psc
->scripts
[i
].gpos_table
= ((const BYTE
*)script
+ offset
);
2575 for (i
= 0; i
< count
; i
++)
2577 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
2578 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]);
2580 if (!(loaded_script
= usp10_script_cache_get_script(psc
, tag
)))
2582 if (!usp10_array_reserve((void **)&psc
->scripts
, &psc
->scripts_size
,
2583 psc
->script_count
+ 1, sizeof(*psc
->scripts
)))
2585 ERR("Failed grow scripts array.\n");
2589 loaded_script
= &psc
->scripts
[psc
->script_count
];
2590 ++psc
->script_count
;
2591 loaded_script
->tag
= tag
;
2593 loaded_script
->gpos_table
= (const BYTE
*)script
+ offset
;
2598 static void _initialize_script_cache(ScriptCache
*psc
)
2600 if (!psc
->scripts_initialized
)
2602 GSUB_initialize_script_cache(psc
);
2603 GPOS_expand_script_cache(psc
);
2604 psc
->scripts_initialized
= TRUE
;
2608 HRESULT
OpenType_GetFontScriptTags(ScriptCache
*psc
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pScriptTags
, int *pcTags
)
2611 const LoadedScript
*script
;
2614 _initialize_script_cache(psc
);
2616 *pcTags
= psc
->script_count
;
2620 if (!(script
= usp10_script_cache_get_script(psc
, searchingFor
)))
2621 return USP_E_SCRIPT_NOT_IN_FONT
;
2623 *pScriptTags
= script
->tag
;
2628 if (cMaxTags
< *pcTags
)
2631 cMaxTags
= min(cMaxTags
, psc
->script_count
);
2632 for (i
= 0; i
< cMaxTags
; ++i
)
2634 pScriptTags
[i
] = psc
->scripts
[i
].tag
;
2639 static LoadedLanguage
*usp10_script_get_language(LoadedScript
*script
, OPENTYPE_TAG tag
)
2643 for (i
= 0; i
< script
->language_count
; ++i
)
2645 if (script
->languages
[i
].tag
== tag
)
2646 return &script
->languages
[i
];
2652 static void GSUB_initialize_language_cache(LoadedScript
*script
)
2656 if (script
->gsub_table
)
2659 const OT_Script
* table
= script
->gsub_table
;
2660 script
->language_count
= GET_BE_WORD(table
->LangSysCount
);
2661 offset
= GET_BE_WORD(table
->DefaultLangSys
);
2664 script
->default_language
.tag
= MS_MAKE_TAG('d','f','l','t');
2665 script
->default_language
.gsub_table
= (const BYTE
*)table
+ offset
;
2668 if (script
->language_count
)
2670 TRACE("Deflang %p, LangCount %li\n",script
->default_language
.gsub_table
, script
->language_count
);
2672 script
->languages
= heap_alloc_zero(script
->language_count
* sizeof(*script
->languages
));
2674 for (i
= 0; i
< script
->language_count
; i
++)
2676 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
2677 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]);
2678 script
->languages
[i
].gsub_table
= ((const BYTE
*)table
+ offset
);
2684 static void GPOS_expand_language_cache(LoadedScript
*script
)
2687 const OT_Script
* table
= script
->gpos_table
;
2688 LoadedLanguage
*language
;
2694 offset
= GET_BE_WORD(table
->DefaultLangSys
);
2696 script
->default_language
.gpos_table
= (const BYTE
*)table
+ offset
;
2698 count
= GET_BE_WORD(table
->LangSysCount
);
2700 TRACE("Deflang %p, LangCount %i\n",script
->default_language
.gpos_table
, count
);
2705 if (!script
->language_count
)
2708 script
->language_count
= count
;
2710 script
->languages
= heap_alloc_zero(script
->language_count
* sizeof(*script
->languages
));
2712 for (i
= 0; i
< script
->language_count
; i
++)
2714 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
2715 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]);
2716 script
->languages
[i
].gpos_table
= ((const BYTE
*)table
+ offset
);
2722 for (i
= 0; i
< count
; i
++)
2724 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
2725 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]);
2727 if (!(language
= usp10_script_get_language(script
, tag
)))
2729 if (!usp10_array_reserve((void **)&script
->languages
, &script
->languages_size
,
2730 script
->language_count
+ 1, sizeof(*script
->languages
)))
2732 ERR("Failed grow languages array.\n");
2736 language
= &script
->languages
[script
->language_count
];
2737 ++script
->language_count
;
2738 language
->tag
= tag
;
2740 language
->gpos_table
= (const BYTE
*)table
+ offset
;
2745 static void _initialize_language_cache(LoadedScript
*script
)
2747 if (!script
->languages_initialized
)
2749 GSUB_initialize_language_cache(script
);
2750 GPOS_expand_language_cache(script
);
2751 script
->languages_initialized
= TRUE
;
2755 HRESULT
OpenType_GetFontLanguageTags(ScriptCache
*psc
, OPENTYPE_TAG script_tag
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pLanguageTags
, int *pcTags
)
2759 LoadedScript
*script
= NULL
;
2761 _initialize_script_cache(psc
);
2762 if (!(script
= usp10_script_cache_get_script(psc
, script_tag
)))
2763 return E_INVALIDARG
;
2765 _initialize_language_cache(script
);
2767 if (!searchingFor
&& cMaxTags
< script
->language_count
)
2769 else if (searchingFor
)
2772 *pcTags
= script
->language_count
;
2774 for (i
= 0; i
< script
->language_count
; i
++)
2777 pLanguageTags
[i
] = script
->languages
[i
].tag
;
2781 if (searchingFor
== script
->languages
[i
].tag
)
2783 pLanguageTags
[0] = script
->languages
[i
].tag
;
2791 if (script
->default_language
.gsub_table
)
2794 pLanguageTags
[i
] = script
->default_language
.tag
;
2796 if (searchingFor
&& FAILED(rc
))
2798 pLanguageTags
[0] = script
->default_language
.tag
;
2801 *pcTags
= (*pcTags
) + 1;
2807 static void usp10_language_add_feature_list(LoadedLanguage
*language
, char table_type
,
2808 const OT_LangSys
*lang
, const OT_FeatureList
*feature_list
)
2810 unsigned int count
= GET_BE_WORD(lang
->FeatureCount
);
2813 TRACE("table_type %#x, %u features.\n", table_type
, count
);
2818 if (!language
->feature_count
)
2819 language
->features
= heap_alloc(count
* sizeof(*language
->features
));
2821 language
->features
= HeapReAlloc(GetProcessHeap(), 0, language
->features
,
2822 (language
->feature_count
+ count
) * sizeof(*language
->features
));
2824 for (i
= 0; i
< count
; ++i
)
2826 const OT_FeatureRecord
*record
;
2827 LoadedFeature
*loaded_feature
;
2828 const OT_Feature
*feature
;
2830 record
= &feature_list
->FeatureRecord
[GET_BE_WORD(lang
->FeatureIndex
[i
])];
2831 feature
= (const OT_Feature
*)((const BYTE
*)feature_list
+ GET_BE_WORD(record
->Feature
));
2833 loaded_feature
= &language
->features
[language
->feature_count
+ i
];
2834 loaded_feature
->tag
= MS_MAKE_TAG(record
->FeatureTag
[0], record
->FeatureTag
[1],
2835 record
->FeatureTag
[2], record
->FeatureTag
[3]);
2836 loaded_feature
->tableType
= table_type
;
2837 loaded_feature
->feature
= feature
;
2838 loaded_feature
->lookup_count
= GET_BE_WORD(feature
->LookupCount
);
2839 loaded_feature
->lookups
= heap_alloc(loaded_feature
->lookup_count
* sizeof(*loaded_feature
->lookups
));
2840 for (j
= 0; j
< loaded_feature
->lookup_count
; ++j
)
2841 loaded_feature
->lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
2843 language
->feature_count
+= count
;
2846 static void _initialize_feature_cache(ScriptCache
*psc
, LoadedLanguage
*language
)
2848 const GSUB_Header
*gsub_header
= psc
->GSUB_Table
;
2849 const GPOS_Header
*gpos_header
= psc
->GPOS_Table
;
2850 const OT_FeatureList
*feature_list
;
2851 const OT_LangSys
*lang
;
2853 if (language
->features_initialized
)
2856 if ((lang
= language
->gsub_table
))
2858 feature_list
= (const OT_FeatureList
*)((const BYTE
*)gsub_header
+ GET_BE_WORD(gsub_header
->FeatureList
));
2859 usp10_language_add_feature_list(language
, FEATURE_GSUB_TABLE
, lang
, feature_list
);
2862 if ((lang
= language
->gpos_table
))
2864 feature_list
= (const OT_FeatureList
*)((const BYTE
*)gpos_header
+ GET_BE_WORD(gpos_header
->FeatureList
));
2865 usp10_language_add_feature_list(language
, FEATURE_GPOS_TABLE
, lang
, feature_list
);
2868 language
->features_initialized
= TRUE
;
2871 HRESULT
OpenType_GetFontFeatureTags(ScriptCache
*psc
, OPENTYPE_TAG script_tag
, OPENTYPE_TAG language_tag
, BOOL filtered
, OPENTYPE_TAG searchingFor
, char tableType
, int cMaxTags
, OPENTYPE_TAG
*pFeatureTags
, int *pcTags
, LoadedFeature
** feature
)
2874 LoadedScript
*script
;
2876 LoadedLanguage
*language
= NULL
;
2878 _initialize_script_cache(psc
);
2879 if (!(script
= usp10_script_cache_get_script(psc
, script_tag
)))
2885 return E_INVALIDARG
;
2888 _initialize_language_cache(script
);
2890 if ((script
->default_language
.gsub_table
|| script
->default_language
.gpos_table
) && script
->default_language
.tag
== language_tag
)
2891 language
= &script
->default_language
;
2893 language
= usp10_script_get_language(script
, language_tag
);
2901 _initialize_feature_cache(psc
, language
);
2906 for (i
= 0; i
< language
->feature_count
; i
++)
2907 if (language
->features
[i
].tableType
== tableType
)
2908 *pcTags
= (*pcTags
)+1;
2911 *pcTags
= language
->feature_count
;
2913 if (!searchingFor
&& cMaxTags
< *pcTags
)
2915 else if (searchingFor
)
2918 for (i
= 0; i
< language
->feature_count
; i
++)
2922 if (!tableType
|| language
->features
[i
].tableType
== tableType
)
2923 pFeatureTags
[i
] = language
->features
[i
].tag
;
2928 if ((searchingFor
== language
->features
[i
].tag
) &&
2929 (!tableType
|| language
->features
[i
].tableType
== tableType
))
2931 pFeatureTags
[0] = language
->features
[i
].tag
;
2934 *feature
= &language
->features
[i
];