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
;
1103 int newIndex
= glyph_index
;
1105 offset
= GET_BE_WORD(srs
->SubRule
[k
]);
1106 sr
= (const GSUB_SubRule_1
*)((const BYTE
*)srs
+offset
);
1107 g_count
= GET_BE_WORD(sr
->GlyphCount
);
1108 TRACE(" SubRule has %i glyphs\n",g_count
);
1110 g
= glyph_index
+ write_dir
* (g_count
- 1);
1111 if (g
>= *glyph_count
)
1114 for (l
= 0; l
< g_count
-1; l
++)
1115 if (glyphs
[glyph_index
+ (write_dir
* (l
+1))] != GET_BE_WORD(sr
->Input
[l
])) break;
1119 TRACE(" Rule does not match\n");
1123 TRACE(" Rule matches\n");
1124 sr_2
= (const GSUB_SubRule_2
*)&sr
->Input
[g_count
- 1];
1126 for (l
= 0; l
< GET_BE_WORD(sr
->SubstCount
); l
++)
1128 unsigned int lookup_index
= GET_BE_WORD(sr_2
->SubstLookupRecord
[l
].LookupListIndex
);
1129 unsigned int sequence_index
= GET_BE_WORD(sr_2
->SubstLookupRecord
[l
].SequenceIndex
);
1131 g
= glyph_index
+ write_dir
* sequence_index
;
1132 if (g
>= *glyph_count
)
1134 WARN("Invalid sequence index %u (glyph index %u, write dir %d).\n",
1135 sequence_index
, glyph_index
, write_dir
);
1139 TRACE(" SUBST: %u -> %u %u.\n", l
, sequence_index
, lookup_index
);
1140 newIndex
= GSUB_apply_lookup(lookup
, lookup_index
, glyphs
, g
, write_dir
, glyph_count
);
1141 if (newIndex
== GSUB_E_NOGLYPH
)
1143 ERR(" Chain failed to generate a glyph\n");
1151 else if (GET_BE_WORD(csf1
->SubstFormat
) == 2)
1153 const GSUB_ContextSubstFormat2
*csf2
;
1154 const void *glyph_class_table
;
1157 csf2
= (const GSUB_ContextSubstFormat2
*)csf1
;
1158 TRACE("Context Substitution Subtable: Class 2\n");
1159 offset
= GET_BE_WORD(csf2
->Coverage
);
1160 index
= GSUB_is_glyph_covered((const BYTE
*)csf2
+offset
, glyphs
[glyph_index
]);
1161 TRACE(" Coverage index %i\n",index
);
1164 int k
, count
, class;
1165 const GSUB_SubClassSet
*scs
;
1167 offset
= GET_BE_WORD(csf2
->ClassDef
);
1168 glyph_class_table
= (const BYTE
*)csf2
+ offset
;
1170 class = OT_get_glyph_class(glyph_class_table
,glyphs
[glyph_index
]);
1172 offset
= GET_BE_WORD(csf2
->SubClassSet
[class]);
1175 TRACE(" No class rule table for class %i\n",class);
1178 scs
= (const GSUB_SubClassSet
*)((const BYTE
*)csf2
+offset
);
1179 count
= GET_BE_WORD(scs
->SubClassRuleCnt
);
1180 TRACE(" SubClassSet has %i members\n",count
);
1181 for (k
= 0; k
< count
; k
++)
1183 const GSUB_SubClassRule_1
*sr
;
1184 const GSUB_SubClassRule_2
*sr_2
;
1187 int newIndex
= glyph_index
;
1189 offset
= GET_BE_WORD(scs
->SubClassRule
[k
]);
1190 sr
= (const GSUB_SubClassRule_1
*)((const BYTE
*)scs
+offset
);
1191 g_count
= GET_BE_WORD(sr
->GlyphCount
);
1192 TRACE(" SubClassRule has %i glyphs classes\n",g_count
);
1194 g
= glyph_index
+ write_dir
* (g_count
- 1);
1195 if (g
>= *glyph_count
)
1198 for (l
= 0; l
< g_count
-1; l
++)
1200 int g_class
= OT_get_glyph_class(glyph_class_table
, glyphs
[glyph_index
+ (write_dir
* (l
+1))]);
1201 if (g_class
!= GET_BE_WORD(sr
->Class
[l
])) break;
1206 TRACE(" Rule does not match\n");
1210 TRACE(" Rule matches\n");
1211 sr_2
= (const GSUB_SubClassRule_2
*)&sr
->Class
[g_count
- 1];
1213 for (l
= 0; l
< GET_BE_WORD(sr
->SubstCount
); l
++)
1215 unsigned int lookup_index
= GET_BE_WORD(sr_2
->SubstLookupRecord
[l
].LookupListIndex
);
1216 unsigned int sequence_index
= GET_BE_WORD(sr_2
->SubstLookupRecord
[l
].SequenceIndex
);
1218 g
= glyph_index
+ write_dir
* sequence_index
;
1219 if (g
>= *glyph_count
)
1221 WARN("Invalid sequence index %u (glyph index %u, write dir %d).\n",
1222 sequence_index
, glyph_index
, write_dir
);
1226 TRACE(" SUBST: %u -> %u %u.\n", l
, sequence_index
, lookup_index
);
1227 newIndex
= GSUB_apply_lookup(lookup
, lookup_index
, glyphs
, g
, write_dir
, glyph_count
);
1228 if (newIndex
== GSUB_E_NOGLYPH
)
1230 ERR(" Chain failed to generate a glyph\n");
1239 FIXME("Unhandled Context Substitution Format %i\n", GET_BE_WORD(csf1
->SubstFormat
));
1241 return GSUB_E_NOGLYPH
;
1244 static INT
GSUB_apply_ChainContextSubst(const OT_LookupList
* lookup
, const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
1248 TRACE("Chaining Contextual Substitution Subtable\n");
1249 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1251 const GSUB_ChainContextSubstFormat1
*ccsf1
;
1253 int dirLookahead
= write_dir
;
1254 int dirBacktrack
= -1 * write_dir
;
1256 ccsf1
= (const GSUB_ChainContextSubstFormat1
*)GSUB_get_subtable(look
, j
);
1257 if (GET_BE_WORD(ccsf1
->SubstFormat
) == 1)
1261 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
1264 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 2)
1267 const void *backtrack_class_table
;
1268 const void *input_class_table
;
1269 const void *lookahead_class_table
;
1273 const GSUB_ChainContextSubstFormat2
*ccsf2
= (const GSUB_ChainContextSubstFormat2
*)ccsf1
;
1274 const GSUB_ChainSubClassSet
*csc
;
1276 TRACE(" subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
1278 offset
= GET_BE_WORD(ccsf2
->Coverage
);
1280 if (GSUB_is_glyph_covered((const BYTE
*)ccsf2
+offset
, glyphs
[glyph_index
]) == -1)
1282 TRACE("Glyph not covered\n");
1285 offset
= GET_BE_WORD(ccsf2
->BacktrackClassDef
);
1286 backtrack_class_table
= (const BYTE
*)ccsf2
+offset
;
1287 offset
= GET_BE_WORD(ccsf2
->InputClassDef
);
1288 input_class_table
= (const BYTE
*)ccsf2
+offset
;
1289 offset
= GET_BE_WORD(ccsf2
->LookaheadClassDef
);
1290 lookahead_class_table
= (const BYTE
*)ccsf2
+offset
;
1291 count
= GET_BE_WORD(ccsf2
->ChainSubClassSetCnt
);
1293 class = OT_get_glyph_class(input_class_table
, glyphs
[glyph_index
]);
1294 offset
= GET_BE_WORD(ccsf2
->ChainSubClassSet
[class]);
1298 TRACE("No rules for class\n");
1302 csc
= (const GSUB_ChainSubClassSet
*)((BYTE
*)ccsf2
+offset
);
1303 count
= GET_BE_WORD(csc
->ChainSubClassRuleCnt
);
1305 TRACE("%i rules to check\n",count
);
1307 for (i
= 0; i
< count
; i
++)
1309 WORD backtrack_count
, input_count
, lookahead_count
, substitute_count
;
1311 const GSUB_ChainSubClassRule_1
*backtrack
;
1312 const GSUB_ChainSubClassRule_2
*input
;
1313 const GSUB_ChainSubClassRule_3
*lookahead
;
1314 const GSUB_ChainSubClassRule_4
*substitute
;
1315 int new_index
= GSUB_E_NOGLYPH
;
1317 offset
= GET_BE_WORD(csc
->ChainSubClassRule
[i
]);
1318 backtrack
= (const GSUB_ChainSubClassRule_1
*)((BYTE
*)csc
+ offset
);
1319 backtrack_count
= GET_BE_WORD(backtrack
->BacktrackGlyphCount
);
1320 k
= glyph_index
+ dirBacktrack
* backtrack_count
;
1321 if (k
< 0 || k
>= *glyph_count
)
1324 input
= (const GSUB_ChainSubClassRule_2
*)&backtrack
->Backtrack
[backtrack_count
];
1325 input_count
= GET_BE_WORD(input
->InputGlyphCount
) - 1;
1326 k
= glyph_index
+ write_dir
* input_count
;
1327 if (k
< 0 || k
>= *glyph_count
)
1330 lookahead
= (const GSUB_ChainSubClassRule_3
*)&input
->Input
[input_count
];
1331 lookahead_count
= GET_BE_WORD(lookahead
->LookaheadGlyphCount
);
1332 k
= glyph_index
+ dirLookahead
* (input_count
+ lookahead_count
);
1333 if (k
< 0 || k
>= *glyph_count
)
1336 substitute
= (const GSUB_ChainSubClassRule_4
*)&lookahead
->LookAhead
[lookahead_count
];
1338 for (k
= 0; k
< backtrack_count
; ++k
)
1340 WORD target_class
= GET_BE_WORD(backtrack
->Backtrack
[k
]);
1341 WORD glyph_class
= OT_get_glyph_class(backtrack_class_table
, glyphs
[glyph_index
+ (dirBacktrack
* (k
+1))]);
1342 if (target_class
!= glyph_class
)
1345 if (k
!= backtrack_count
)
1347 TRACE("Matched Backtrack\n");
1349 for (k
= 0; k
< input_count
; ++k
)
1351 WORD target_class
= GET_BE_WORD(input
->Input
[k
]);
1352 WORD glyph_class
= OT_get_glyph_class(input_class_table
, glyphs
[glyph_index
+ (write_dir
* (k
+1))]);
1353 if (target_class
!= glyph_class
)
1356 if (k
!= input_count
)
1358 TRACE("Matched IndexGlyphs\n");
1360 for (k
= 0; k
< lookahead_count
; ++k
)
1362 WORD target_class
= GET_BE_WORD(lookahead
->LookAhead
[k
]);
1363 WORD glyph_class
= OT_get_glyph_class(lookahead_class_table
,
1364 glyphs
[glyph_index
+ (dirLookahead
* (input_count
+ k
+ 1))]);
1365 if (target_class
!= glyph_class
)
1368 if (k
!= lookahead_count
)
1370 TRACE("Matched LookAhead\n");
1372 substitute_count
= GET_BE_WORD(substitute
->SubstCount
);
1373 for (k
= 0; k
< substitute_count
; ++k
)
1375 unsigned int lookup_index
= GET_BE_WORD(substitute
->SubstLookupRecord
[k
].LookupListIndex
);
1376 unsigned int sequence_index
= GET_BE_WORD(substitute
->SubstLookupRecord
[k
].SequenceIndex
);
1377 unsigned int g
= glyph_index
+ write_dir
* sequence_index
;
1379 if (g
>= *glyph_count
)
1381 WARN("Skipping invalid sequence index %u (glyph index %u, write dir %d).\n",
1382 sequence_index
, glyph_index
, write_dir
);
1386 TRACE("SUBST: %u -> %u %u.\n", k
, sequence_index
, lookup_index
);
1387 new_index
= GSUB_apply_lookup(lookup
, lookup_index
, glyphs
, g
, write_dir
, glyph_count
);
1388 if (new_index
== GSUB_E_NOGLYPH
)
1389 ERR("Chain failed to generate a glyph.\n");
1394 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 3)
1396 WORD backtrack_count
, input_count
, lookahead_count
, substitution_count
;
1398 const GSUB_ChainContextSubstFormat3_1
*backtrack
;
1399 const GSUB_ChainContextSubstFormat3_2
*input
;
1400 const GSUB_ChainContextSubstFormat3_3
*lookahead
;
1401 const GSUB_ChainContextSubstFormat3_4
*substitute
;
1402 int new_index
= GSUB_E_NOGLYPH
;
1404 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
1406 backtrack
= (const GSUB_ChainContextSubstFormat3_1
*)ccsf1
;
1407 backtrack_count
= GET_BE_WORD(backtrack
->BacktrackGlyphCount
);
1408 k
= glyph_index
+ dirBacktrack
* backtrack_count
;
1409 if (k
< 0 || k
>= *glyph_count
)
1412 input
= (const GSUB_ChainContextSubstFormat3_2
*)&backtrack
->Coverage
[backtrack_count
];
1413 input_count
= GET_BE_WORD(input
->InputGlyphCount
);
1414 k
= glyph_index
+ write_dir
* (input_count
- 1);
1415 if (k
< 0 || k
>= *glyph_count
)
1418 lookahead
= (const GSUB_ChainContextSubstFormat3_3
*)&input
->Coverage
[input_count
];
1419 lookahead_count
= GET_BE_WORD(lookahead
->LookaheadGlyphCount
);
1420 k
= glyph_index
+ dirLookahead
* (input_count
+ lookahead_count
- 1);
1421 if (k
< 0 || k
>= *glyph_count
)
1424 substitute
= (const GSUB_ChainContextSubstFormat3_4
*)&lookahead
->Coverage
[lookahead_count
];
1426 for (k
= 0; k
< backtrack_count
; ++k
)
1428 offset
= GET_BE_WORD(backtrack
->Coverage
[k
]);
1429 if (GSUB_is_glyph_covered((const BYTE
*)ccsf1
+ offset
,
1430 glyphs
[glyph_index
+ (dirBacktrack
* (k
+ 1))]) == -1)
1433 if (k
!= backtrack_count
)
1435 TRACE("Matched Backtrack\n");
1437 for (k
= 0; k
< input_count
; ++k
)
1439 offset
= GET_BE_WORD(input
->Coverage
[k
]);
1440 if (GSUB_is_glyph_covered((const BYTE
*)ccsf1
+ offset
,
1441 glyphs
[glyph_index
+ (write_dir
* k
)]) == -1)
1444 if (k
!= input_count
)
1446 TRACE("Matched IndexGlyphs\n");
1448 for (k
= 0; k
< lookahead_count
; ++k
)
1450 offset
= GET_BE_WORD(lookahead
->Coverage
[k
]);
1451 if (GSUB_is_glyph_covered((const BYTE
*)ccsf1
+ offset
,
1452 glyphs
[glyph_index
+ (dirLookahead
* (input_count
+ k
))]) == -1)
1455 if (k
!= lookahead_count
)
1457 TRACE("Matched LookAhead\n");
1459 substitution_count
= GET_BE_WORD(substitute
->SubstCount
);
1460 for (k
= 0; k
< substitution_count
; ++k
)
1462 unsigned int lookup_index
= GET_BE_WORD(substitute
->SubstLookupRecord
[k
].LookupListIndex
);
1463 unsigned int sequence_index
= GET_BE_WORD(substitute
->SubstLookupRecord
[k
].SequenceIndex
);
1464 unsigned int g
= glyph_index
+ write_dir
* sequence_index
;
1466 if (g
>= *glyph_count
)
1468 WARN("Skipping invalid sequence index %u (glyph index %u, write dir %d).\n",
1469 sequence_index
, glyph_index
, write_dir
);
1473 TRACE("SUBST: %u -> %u %u.\n", k
, sequence_index
, lookup_index
);
1474 new_index
= GSUB_apply_lookup(lookup
, lookup_index
, glyphs
, g
, write_dir
, glyph_count
);
1475 if (new_index
== GSUB_E_NOGLYPH
)
1476 ERR("Chain failed to generate a glyph.\n");
1481 return GSUB_E_NOGLYPH
;
1484 static INT
GSUB_apply_lookup(const OT_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
1487 enum gsub_lookup_type type
;
1488 const OT_LookupTable
*look
;
1490 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
1491 look
= (const OT_LookupTable
*)((const BYTE
*)lookup
+ offset
);
1492 type
= GET_BE_WORD(look
->LookupType
);
1493 TRACE("type %#x, flag %#x, subtables %u.\n", type
,
1494 GET_BE_WORD(look
->LookupFlag
),GET_BE_WORD(look
->SubTableCount
));
1496 if (type
== GSUB_LOOKUP_EXTENSION
)
1498 if (GET_BE_WORD(look
->SubTableCount
))
1500 const GSUB_ExtensionPosFormat1
*ext
= (const GSUB_ExtensionPosFormat1
*)((const BYTE
*)look
+ GET_BE_WORD(look
->SubTable
[0]));
1501 if (GET_BE_WORD(ext
->SubstFormat
) == 1)
1503 type
= GET_BE_WORD(ext
->ExtensionLookupType
);
1504 TRACE("extension type %i\n",type
);
1508 FIXME("Unhandled Extension Substitution Format %i\n",GET_BE_WORD(ext
->SubstFormat
));
1513 WARN("lookup type is Extension Substitution but no extension subtable exists\n");
1518 case GSUB_LOOKUP_SINGLE
:
1519 return GSUB_apply_SingleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1520 case GSUB_LOOKUP_MULTIPLE
:
1521 return GSUB_apply_MultipleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1522 case GSUB_LOOKUP_ALTERNATE
:
1523 return GSUB_apply_AlternateSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1524 case GSUB_LOOKUP_LIGATURE
:
1525 return GSUB_apply_LigatureSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1526 case GSUB_LOOKUP_CONTEXT
:
1527 return GSUB_apply_ContextSubst(lookup
, look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1528 case GSUB_LOOKUP_CONTEXT_CHAINED
:
1529 return GSUB_apply_ChainContextSubst(lookup
, look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1530 case GSUB_LOOKUP_EXTENSION
:
1531 FIXME("Extension Substitution types not valid here\n");
1534 FIXME("Unhandled GSUB lookup type %#x.\n", type
);
1536 return GSUB_E_NOGLYPH
;
1539 int OpenType_apply_GSUB_lookup(const void *table
, unsigned int lookup_index
, WORD
*glyphs
,
1540 unsigned int glyph_index
, int write_dir
, int *glyph_count
)
1542 const GSUB_Header
*header
= (const GSUB_Header
*)table
;
1543 const OT_LookupList
*lookup
= (const OT_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
1545 return GSUB_apply_lookup(lookup
, lookup_index
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1551 static unsigned int GPOS_apply_lookup(const ScriptCache
*script_cache
, const OUTLINETEXTMETRICW
*otm
,
1552 const LOGFONTW
*logfont
, const SCRIPT_ANALYSIS
*analysis
, int *advance
, const OT_LookupList
*lookup
,
1553 unsigned int lookup_index
, const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
,
1556 static INT
GPOS_get_device_table_value(const OT_DeviceTable
*DeviceTable
, WORD ppem
)
1558 static const WORD mask
[3] = {3,0xf,0xff};
1559 if (DeviceTable
&& ppem
>= GET_BE_WORD(DeviceTable
->StartSize
) && ppem
<= GET_BE_WORD(DeviceTable
->EndSize
))
1561 WORD format
= GET_BE_WORD(DeviceTable
->DeltaFormat
);
1562 int index
= ppem
- GET_BE_WORD(DeviceTable
->StartSize
);
1565 TRACE("device table, format %#x, index %i\n", format
, index
);
1567 if (format
< 1 || format
> 3)
1569 WARN("invalid delta format %#x\n", format
);
1573 index
= index
<< format
;
1574 value
= (DeviceTable
->DeltaValue
[index
/sizeof(WORD
)] << (index
%sizeof(WORD
)))&mask
[format
-1];
1575 TRACE("offset %i, value %i\n",index
, value
);
1576 if (value
> mask
[format
-1]/2)
1577 value
= -1 * ((mask
[format
-1]+1) - value
);
1583 static void GPOS_get_anchor_values(const void *table
, POINT
*pt
, WORD ppem
)
1585 const GPOS_AnchorFormat1
* anchor1
= (const GPOS_AnchorFormat1
*)table
;
1587 switch (GET_BE_WORD(anchor1
->AnchorFormat
))
1591 TRACE("Anchor Format 1\n");
1592 pt
->x
= (short)GET_BE_WORD(anchor1
->XCoordinate
);
1593 pt
->y
= (short)GET_BE_WORD(anchor1
->YCoordinate
);
1598 const GPOS_AnchorFormat2
* anchor2
= (const GPOS_AnchorFormat2
*)table
;
1599 TRACE("Anchor Format 2\n");
1600 pt
->x
= (short)GET_BE_WORD(anchor2
->XCoordinate
);
1601 pt
->y
= (short)GET_BE_WORD(anchor2
->YCoordinate
);
1607 const GPOS_AnchorFormat3
* anchor3
= (const GPOS_AnchorFormat3
*)table
;
1608 TRACE("Anchor Format 3\n");
1609 pt
->x
= (short)GET_BE_WORD(anchor3
->XCoordinate
);
1610 pt
->y
= (short)GET_BE_WORD(anchor3
->YCoordinate
);
1611 offset
= GET_BE_WORD(anchor3
->XDeviceTable
);
1612 TRACE("ppem %i\n",ppem
);
1615 const OT_DeviceTable
* DeviceTableX
= NULL
;
1616 DeviceTableX
= (const OT_DeviceTable
*)((const BYTE
*)anchor3
+ offset
);
1617 pt
->x
+= GPOS_get_device_table_value(DeviceTableX
, ppem
);
1619 offset
= GET_BE_WORD(anchor3
->YDeviceTable
);
1622 const OT_DeviceTable
* DeviceTableY
= NULL
;
1623 DeviceTableY
= (const OT_DeviceTable
*)((const BYTE
*)anchor3
+ offset
);
1624 pt
->y
+= GPOS_get_device_table_value(DeviceTableY
, ppem
);
1629 ERR("Unknown Anchor Format %i\n",GET_BE_WORD(anchor1
->AnchorFormat
));
1635 static void GPOS_convert_design_units_to_device(const OUTLINETEXTMETRICW
*otm
, const LOGFONTW
*logfont
,
1636 int desX
, int desY
, double *devX
, double *devY
)
1638 int emHeight
= otm
->otmTextMetrics
.tmAscent
+ otm
->otmTextMetrics
.tmDescent
- otm
->otmTextMetrics
.tmInternalLeading
;
1640 TRACE("emHeight %i lfWidth %i\n",emHeight
, logfont
->lfWidth
);
1641 *devX
= (desX
* emHeight
) / (double)otm
->otmEMSquare
;
1642 *devY
= (desY
* emHeight
) / (double)otm
->otmEMSquare
;
1643 if (logfont
->lfWidth
)
1644 FIXME("Font with lfWidth set not handled properly.\n");
1647 static INT
GPOS_get_value_record(WORD ValueFormat
, const WORD data
[], GPOS_ValueRecord
*record
)
1650 if (ValueFormat
& 0x0001) { if (data
) record
->XPlacement
= GET_BE_WORD(data
[offset
]); offset
++; }
1651 if (ValueFormat
& 0x0002) { if (data
) record
->YPlacement
= GET_BE_WORD(data
[offset
]); offset
++; }
1652 if (ValueFormat
& 0x0004) { if (data
) record
->XAdvance
= GET_BE_WORD(data
[offset
]); offset
++; }
1653 if (ValueFormat
& 0x0008) { if (data
) record
->YAdvance
= GET_BE_WORD(data
[offset
]); offset
++; }
1654 if (ValueFormat
& 0x0010) { if (data
) record
->XPlaDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1655 if (ValueFormat
& 0x0020) { if (data
) record
->YPlaDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1656 if (ValueFormat
& 0x0040) { if (data
) record
->XAdvDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1657 if (ValueFormat
& 0x0080) { if (data
) record
->YAdvDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1661 static void GPOS_get_value_record_offsets(const BYTE
*head
, GPOS_ValueRecord
*ValueRecord
,
1662 WORD ValueFormat
, unsigned int ppem
, POINT
*ptPlacement
, POINT
*ptAdvance
)
1664 if (ValueFormat
& 0x0001) ptPlacement
->x
+= (short)ValueRecord
->XPlacement
;
1665 if (ValueFormat
& 0x0002) ptPlacement
->y
+= (short)ValueRecord
->YPlacement
;
1666 if (ValueFormat
& 0x0004) ptAdvance
->x
+= (short)ValueRecord
->XAdvance
;
1667 if (ValueFormat
& 0x0008) ptAdvance
->y
+= (short)ValueRecord
->YAdvance
;
1668 if (ValueFormat
& 0x0010) ptPlacement
->x
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->XPlaDevice
), ppem
);
1669 if (ValueFormat
& 0x0020) ptPlacement
->y
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->YPlaDevice
), ppem
);
1670 if (ValueFormat
& 0x0040) ptAdvance
->x
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->XAdvDevice
), ppem
);
1671 if (ValueFormat
& 0x0080) ptAdvance
->y
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->YAdvDevice
), ppem
);
1672 if (ValueFormat
& 0xFF00) FIXME("Unhandled Value Format %x\n",ValueFormat
&0xFF00);
1675 static const BYTE
*GPOS_get_subtable(const OT_LookupTable
*look
, int index
)
1677 int offset
= GET_BE_WORD(look
->SubTable
[index
]);
1679 if (GET_BE_WORD(look
->LookupType
) == GPOS_LOOKUP_POSITION_EXTENSION
)
1681 const GPOS_ExtensionPosFormat1
*ext
= (const GPOS_ExtensionPosFormat1
*)((const BYTE
*)look
+ offset
);
1682 if (GET_BE_WORD(ext
->PosFormat
) == 1)
1684 offset
+= GET_BE_DWORD(ext
->ExtensionOffset
);
1688 FIXME("Unhandled Extension Positioning Format %i\n",GET_BE_WORD(ext
->PosFormat
));
1691 return (const BYTE
*)look
+ offset
;
1694 static void GPOS_apply_SingleAdjustment(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
,
1695 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, unsigned int ppem
,
1696 POINT
*adjust
, POINT
*advance
)
1700 TRACE("Single Adjustment Positioning Subtable\n");
1702 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1704 const GPOS_SinglePosFormat1
*spf1
= (const GPOS_SinglePosFormat1
*)GPOS_get_subtable(look
, j
);
1706 if (GET_BE_WORD(spf1
->PosFormat
) == 1)
1708 offset
= GET_BE_WORD(spf1
->Coverage
);
1709 if (GSUB_is_glyph_covered((const BYTE
*)spf1
+offset
, glyphs
[glyph_index
]) != -1)
1711 GPOS_ValueRecord ValueRecord
= {0,0,0,0,0,0,0,0};
1712 WORD ValueFormat
= GET_BE_WORD(spf1
->ValueFormat
);
1713 GPOS_get_value_record(ValueFormat
, spf1
->Value
, &ValueRecord
);
1714 GPOS_get_value_record_offsets((const BYTE
*)spf1
, &ValueRecord
, ValueFormat
, ppem
, adjust
, advance
);
1715 TRACE("Glyph Adjusted by %i,%i\n",ValueRecord
.XPlacement
,ValueRecord
.YPlacement
);
1718 else if (GET_BE_WORD(spf1
->PosFormat
) == 2)
1721 const GPOS_SinglePosFormat2
*spf2
;
1722 spf2
= (const GPOS_SinglePosFormat2
*)spf1
;
1723 offset
= GET_BE_WORD(spf2
->Coverage
);
1724 index
= GSUB_is_glyph_covered((const BYTE
*)spf2
+offset
, glyphs
[glyph_index
]);
1728 GPOS_ValueRecord ValueRecord
= {0,0,0,0,0,0,0,0};
1729 WORD ValueFormat
= GET_BE_WORD(spf2
->ValueFormat
);
1730 size
= GPOS_get_value_record(ValueFormat
, spf2
->Value
, &ValueRecord
);
1733 offset
= size
* index
;
1734 GPOS_get_value_record(ValueFormat
, &spf2
->Value
[offset
], &ValueRecord
);
1736 GPOS_get_value_record_offsets((const BYTE
*)spf2
, &ValueRecord
, ValueFormat
, ppem
, adjust
, advance
);
1737 TRACE("Glyph Adjusted by %i,%i\n",ValueRecord
.XPlacement
,ValueRecord
.YPlacement
);
1741 FIXME("Single Adjustment Positioning: Format %i Unhandled\n",GET_BE_WORD(spf1
->PosFormat
));
1745 static void apply_pair_value( const void *pos_table
, WORD val_fmt1
, WORD val_fmt2
, const WORD
*pair
,
1746 INT ppem
, POINT
*adjust
, POINT
*advance
)
1748 GPOS_ValueRecord val_rec1
= {0,0,0,0,0,0,0,0};
1749 GPOS_ValueRecord val_rec2
= {0,0,0,0,0,0,0,0};
1752 size
= GPOS_get_value_record( val_fmt1
, pair
, &val_rec1
);
1753 GPOS_get_value_record( val_fmt2
, pair
+ size
, &val_rec2
);
1757 GPOS_get_value_record_offsets( pos_table
, &val_rec1
, val_fmt1
, ppem
, adjust
, advance
);
1758 TRACE( "Glyph 1 resulting cumulative offset is %s design units\n", wine_dbgstr_point(&adjust
[0]) );
1759 TRACE( "Glyph 1 resulting cumulative advance is %s design units\n", wine_dbgstr_point(&advance
[0]) );
1763 GPOS_get_value_record_offsets( pos_table
, &val_rec2
, val_fmt2
, ppem
, adjust
+ 1, advance
+ 1 );
1764 TRACE( "Glyph 2 resulting cumulative offset is %s design units\n", wine_dbgstr_point(&adjust
[1]) );
1765 TRACE( "Glyph 2 resulting cumulative advance is %s design units\n", wine_dbgstr_point(&advance
[1]) );
1769 static int GPOS_apply_PairAdjustment(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
,
1770 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, unsigned int ppem
,
1771 POINT
*adjust
, POINT
*advance
)
1774 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1776 if (glyph_index
+ write_dir
>= glyph_count
)
1779 TRACE("Pair Adjustment Positioning Subtable\n");
1781 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1783 const GPOS_PairPosFormat1
*ppf1
= (const GPOS_PairPosFormat1
*)GPOS_get_subtable(look
, j
);
1785 if (GET_BE_WORD(ppf1
->PosFormat
) == 1)
1788 WORD ValueFormat1
= GET_BE_WORD(ppf1
->ValueFormat1
);
1789 WORD ValueFormat2
= GET_BE_WORD(ppf1
->ValueFormat2
);
1790 INT val_fmt1_size
= GPOS_get_value_record( ValueFormat1
, NULL
, NULL
);
1791 INT val_fmt2_size
= GPOS_get_value_record( ValueFormat2
, NULL
, NULL
);
1792 offset
= GET_BE_WORD(ppf1
->Coverage
);
1793 index
= GSUB_is_glyph_covered((const BYTE
*)ppf1
+offset
, glyphs
[glyph_index
]);
1794 if (index
!= -1 && index
< GET_BE_WORD(ppf1
->PairSetCount
))
1798 const GPOS_PairSet
*ps
;
1799 const GPOS_PairValueRecord
*pair_val_rec
;
1800 offset
= GET_BE_WORD(ppf1
->PairSetOffset
[index
]);
1801 ps
= (const GPOS_PairSet
*)((const BYTE
*)ppf1
+offset
);
1802 pair_count
= GET_BE_WORD(ps
->PairValueCount
);
1803 pair_val_rec
= ps
->PairValueRecord
;
1804 for (k
= 0; k
< pair_count
; k
++)
1806 WORD second_glyph
= GET_BE_WORD(pair_val_rec
->SecondGlyph
);
1807 if (glyphs
[glyph_index
+write_dir
] == second_glyph
)
1810 TRACE("Format 1: Found Pair %x,%x\n",glyphs
[glyph_index
],glyphs
[glyph_index
+write_dir
]);
1811 apply_pair_value(ppf1
, ValueFormat1
, ValueFormat2
,
1812 pair_val_rec
->Value1
, ppem
, adjust
, advance
);
1813 if (ValueFormat2
) next
++;
1816 pair_val_rec
= (const GPOS_PairValueRecord
*)(pair_val_rec
->Value1
+ val_fmt1_size
+ val_fmt2_size
);
1820 else if (GET_BE_WORD(ppf1
->PosFormat
) == 2)
1822 const GPOS_PairPosFormat2
*ppf2
= (const GPOS_PairPosFormat2
*)ppf1
;
1824 WORD ValueFormat1
= GET_BE_WORD( ppf2
->ValueFormat1
);
1825 WORD ValueFormat2
= GET_BE_WORD( ppf2
->ValueFormat2
);
1826 INT val_fmt1_size
= GPOS_get_value_record( ValueFormat1
, NULL
, NULL
);
1827 INT val_fmt2_size
= GPOS_get_value_record( ValueFormat2
, NULL
, NULL
);
1828 WORD class1_count
= GET_BE_WORD( ppf2
->Class1Count
);
1829 WORD class2_count
= GET_BE_WORD( ppf2
->Class2Count
);
1831 offset
= GET_BE_WORD( ppf2
->Coverage
);
1832 index
= GSUB_is_glyph_covered( (const BYTE
*)ppf2
+ offset
, glyphs
[glyph_index
] );
1835 WORD class1
, class2
;
1836 class1
= OT_get_glyph_class( (const BYTE
*)ppf2
+ GET_BE_WORD(ppf2
->ClassDef1
), glyphs
[glyph_index
] );
1837 class2
= OT_get_glyph_class( (const BYTE
*)ppf2
+ GET_BE_WORD(ppf2
->ClassDef2
), glyphs
[glyph_index
+ write_dir
] );
1838 if (class1
< class1_count
&& class2
< class2_count
)
1840 const WORD
*pair_val
= ppf2
->Class1Record
+ (class1
* class2_count
+ class2
) * (val_fmt1_size
+ val_fmt2_size
);
1843 TRACE( "Format 2: Found Pair %x,%x\n", glyphs
[glyph_index
], glyphs
[glyph_index
+ write_dir
] );
1845 apply_pair_value(ppf2
, ValueFormat1
, ValueFormat2
, pair_val
, ppem
, adjust
, advance
);
1846 if (ValueFormat2
) next
++;
1852 FIXME("Pair Adjustment Positioning: Format %i Unhandled\n",GET_BE_WORD(ppf1
->PosFormat
));
1857 static void GPOS_apply_CursiveAttachment(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
,
1858 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, unsigned int ppem
, POINT
*pt
)
1861 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1863 if (glyph_index
+ write_dir
>= glyph_count
)
1866 TRACE("Cursive Attachment Positioning Subtable\n");
1868 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1870 const GPOS_CursivePosFormat1
*cpf1
= (const GPOS_CursivePosFormat1
*)GPOS_get_subtable(look
, j
);
1871 if (GET_BE_WORD(cpf1
->PosFormat
) == 1)
1873 int index_exit
, index_entry
;
1874 WORD offset
= GET_BE_WORD( cpf1
->Coverage
);
1875 index_exit
= GSUB_is_glyph_covered((const BYTE
*)cpf1
+offset
, glyphs
[glyph_index
]);
1876 if (index_exit
!= -1 && cpf1
->EntryExitRecord
[index_exit
].ExitAnchor
!= 0)
1878 index_entry
= GSUB_is_glyph_covered((const BYTE
*)cpf1
+offset
, glyphs
[glyph_index
+write_dir
]);
1879 if (index_entry
!= -1 && cpf1
->EntryExitRecord
[index_entry
].EntryAnchor
!= 0)
1881 POINT exit_pt
, entry_pt
;
1882 offset
= GET_BE_WORD(cpf1
->EntryExitRecord
[index_exit
].ExitAnchor
);
1883 GPOS_get_anchor_values((const BYTE
*)cpf1
+ offset
, &exit_pt
, ppem
);
1884 offset
= GET_BE_WORD(cpf1
->EntryExitRecord
[index_entry
].EntryAnchor
);
1885 GPOS_get_anchor_values((const BYTE
*)cpf1
+ offset
, &entry_pt
, ppem
);
1886 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
));
1887 pt
->x
= entry_pt
.x
- exit_pt
.x
;
1888 pt
->y
= entry_pt
.y
- exit_pt
.y
;
1894 FIXME("Cursive Attachment Positioning: Format %i Unhandled\n",GET_BE_WORD(cpf1
->PosFormat
));
1899 static int GPOS_apply_MarkToBase(const ScriptCache
*script_cache
, const OT_LookupTable
*look
,
1900 const SCRIPT_ANALYSIS
*analysis
, const WORD
*glyphs
, unsigned int glyph_index
,
1901 unsigned int glyph_count
, unsigned int ppem
, POINT
*pt
)
1904 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1905 const void *glyph_class_table
= NULL
;
1908 if (script_cache
->GDEF_Table
)
1910 const GDEF_Header
*header
= script_cache
->GDEF_Table
;
1911 WORD offset
= GET_BE_WORD( header
->GlyphClassDef
);
1913 glyph_class_table
= (const BYTE
*)script_cache
->GDEF_Table
+ offset
;
1916 TRACE("MarkToBase Attachment Positioning Subtable\n");
1918 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1920 const GPOS_MarkBasePosFormat1
*mbpf1
= (const GPOS_MarkBasePosFormat1
*)GPOS_get_subtable(look
, j
);
1921 if (GET_BE_WORD(mbpf1
->PosFormat
) == 1)
1923 int offset
= GET_BE_WORD(mbpf1
->MarkCoverage
);
1925 mark_index
= GSUB_is_glyph_covered((const BYTE
*)mbpf1
+offset
, glyphs
[glyph_index
]);
1926 if (mark_index
!= -1)
1929 int base_glyph
= glyph_index
- write_dir
;
1931 if (glyph_class_table
)
1933 while (OT_get_glyph_class(glyph_class_table
, glyphs
[base_glyph
]) == MarkGlyph
&& base_glyph
> 0 && base_glyph
< glyph_count
)
1934 base_glyph
-= write_dir
;
1937 offset
= GET_BE_WORD(mbpf1
->BaseCoverage
);
1938 base_index
= GSUB_is_glyph_covered((const BYTE
*)mbpf1
+offset
, glyphs
[base_glyph
]);
1939 if (base_index
!= -1)
1941 const GPOS_MarkArray
*ma
;
1942 const GPOS_MarkRecord
*mr
;
1943 const GPOS_BaseArray
*ba
;
1944 const GPOS_BaseRecord
*br
;
1946 int class_count
= GET_BE_WORD(mbpf1
->ClassCount
);
1947 int baserecord_size
;
1950 TRACE("Mark %x(%i) and base %x(%i)\n",glyphs
[glyph_index
], mark_index
, glyphs
[base_glyph
], base_index
);
1951 offset
= GET_BE_WORD(mbpf1
->MarkArray
);
1952 ma
= (const GPOS_MarkArray
*)((const BYTE
*)mbpf1
+ offset
);
1953 if (mark_index
> GET_BE_WORD(ma
->MarkCount
))
1955 ERR("Mark index exceeded mark count\n");
1958 mr
= &ma
->MarkRecord
[mark_index
];
1959 mark_class
= GET_BE_WORD(mr
->Class
);
1960 TRACE("Mark Class %i total classes %i\n",mark_class
,class_count
);
1961 offset
= GET_BE_WORD(mbpf1
->BaseArray
);
1962 ba
= (const GPOS_BaseArray
*)((const BYTE
*)mbpf1
+ offset
);
1963 baserecord_size
= class_count
* sizeof(WORD
);
1964 br
= (const GPOS_BaseRecord
*)((const BYTE
*)ba
+ sizeof(WORD
) + (baserecord_size
* base_index
));
1965 offset
= GET_BE_WORD(br
->BaseAnchor
[mark_class
]);
1966 GPOS_get_anchor_values((const BYTE
*)ba
+ offset
, &base_pt
, ppem
);
1967 offset
= GET_BE_WORD(mr
->MarkAnchor
);
1968 GPOS_get_anchor_values((const BYTE
*)ma
+ offset
, &mark_pt
, ppem
);
1969 TRACE("Offset on base is %s design units\n",wine_dbgstr_point(&base_pt
));
1970 TRACE("Offset on mark is %s design units\n",wine_dbgstr_point(&mark_pt
));
1971 pt
->x
+= base_pt
.x
- mark_pt
.x
;
1972 pt
->y
+= base_pt
.y
- mark_pt
.y
;
1973 TRACE("Resulting cumulative offset is %s design units\n",wine_dbgstr_point(pt
));
1979 FIXME("Unhandled Mark To Base Format %i\n",GET_BE_WORD(mbpf1
->PosFormat
));
1984 static void GPOS_apply_MarkToLigature(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
,
1985 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, unsigned int ppem
, POINT
*pt
)
1988 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1990 TRACE("MarkToLigature Attachment Positioning Subtable\n");
1992 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1994 const GPOS_MarkLigPosFormat1
*mlpf1
= (const GPOS_MarkLigPosFormat1
*)GPOS_get_subtable(look
, j
);
1995 if (GET_BE_WORD(mlpf1
->PosFormat
) == 1)
1997 int offset
= GET_BE_WORD(mlpf1
->MarkCoverage
);
1999 mark_index
= GSUB_is_glyph_covered((const BYTE
*)mlpf1
+offset
, glyphs
[glyph_index
]);
2000 if (mark_index
!= -1)
2003 offset
= GET_BE_WORD(mlpf1
->LigatureCoverage
);
2004 ligature_index
= GSUB_is_glyph_covered((const BYTE
*)mlpf1
+offset
, glyphs
[glyph_index
- write_dir
]);
2005 if (ligature_index
!= -1)
2007 const GPOS_MarkArray
*ma
;
2008 const GPOS_MarkRecord
*mr
;
2010 const GPOS_LigatureArray
*la
;
2011 const GPOS_LigatureAttach
*lt
;
2013 int class_count
= GET_BE_WORD(mlpf1
->ClassCount
);
2014 int component_count
;
2020 TRACE("Mark %x(%i) and ligature %x(%i)\n",glyphs
[glyph_index
], mark_index
, glyphs
[glyph_index
- write_dir
], ligature_index
);
2021 offset
= GET_BE_WORD(mlpf1
->MarkArray
);
2022 ma
= (const GPOS_MarkArray
*)((const BYTE
*)mlpf1
+ offset
);
2023 if (mark_index
> GET_BE_WORD(ma
->MarkCount
))
2025 ERR("Mark index exceeded mark count\n");
2028 mr
= &ma
->MarkRecord
[mark_index
];
2029 mark_class
= GET_BE_WORD(mr
->Class
);
2030 TRACE("Mark Class %i total classes %i\n",mark_class
,class_count
);
2031 offset
= GET_BE_WORD(mlpf1
->LigatureArray
);
2032 la
= (const GPOS_LigatureArray
*)((const BYTE
*)mlpf1
+ offset
);
2033 if (ligature_index
> GET_BE_WORD(la
->LigatureCount
))
2035 ERR("Ligature index exceeded ligature count\n");
2038 offset
= GET_BE_WORD(la
->LigatureAttach
[ligature_index
]);
2039 lt
= (const GPOS_LigatureAttach
*)((const BYTE
*)la
+ offset
);
2041 component_count
= GET_BE_WORD(lt
->ComponentCount
);
2042 component_size
= class_count
* sizeof(WORD
);
2044 for (i
= 0; i
< component_count
&& !offset
; i
++)
2047 const GPOS_ComponentRecord
*cr
= (const GPOS_ComponentRecord
*)((const BYTE
*)lt
->ComponentRecord
+ (component_size
* i
));
2048 for (k
= 0; k
< class_count
&& !offset
; k
++)
2049 offset
= GET_BE_WORD(cr
->LigatureAnchor
[k
]);
2050 cr
= (const GPOS_ComponentRecord
*)((const BYTE
*)cr
+ component_size
);
2054 ERR("Failed to find avalible ligature connection point\n");
2058 GPOS_get_anchor_values((const BYTE
*)lt
+ offset
, &ligature_pt
, ppem
);
2059 offset
= GET_BE_WORD(mr
->MarkAnchor
);
2060 GPOS_get_anchor_values((const BYTE
*)ma
+ offset
, &mark_pt
, ppem
);
2061 TRACE("Offset on ligature is %s design units\n",wine_dbgstr_point(&ligature_pt
));
2062 TRACE("Offset on mark is %s design units\n",wine_dbgstr_point(&mark_pt
));
2063 pt
->x
+= ligature_pt
.x
- mark_pt
.x
;
2064 pt
->y
+= ligature_pt
.y
- mark_pt
.y
;
2065 TRACE("Resulting cumulative offset is %s design units\n",wine_dbgstr_point(pt
));
2070 FIXME("Unhandled Mark To Ligature Format %i\n",GET_BE_WORD(mlpf1
->PosFormat
));
2074 static BOOL
GPOS_apply_MarkToMark(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
,
2075 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, unsigned int ppem
, POINT
*pt
)
2079 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2081 TRACE("MarkToMark Attachment Positioning Subtable\n");
2083 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
2085 const GPOS_MarkMarkPosFormat1
*mmpf1
= (const GPOS_MarkMarkPosFormat1
*)GPOS_get_subtable(look
, j
);
2086 if (GET_BE_WORD(mmpf1
->PosFormat
) == 1)
2088 int offset
= GET_BE_WORD(mmpf1
->Mark1Coverage
);
2090 mark_index
= GSUB_is_glyph_covered((const BYTE
*)mmpf1
+offset
, glyphs
[glyph_index
]);
2091 if (mark_index
!= -1)
2094 offset
= GET_BE_WORD(mmpf1
->Mark2Coverage
);
2095 mark2_index
= GSUB_is_glyph_covered((const BYTE
*)mmpf1
+offset
, glyphs
[glyph_index
- write_dir
]);
2096 if (mark2_index
!= -1)
2098 const GPOS_MarkArray
*ma
;
2099 const GPOS_MarkRecord
*mr
;
2100 const GPOS_Mark2Array
*m2a
;
2101 const GPOS_Mark2Record
*m2r
;
2103 int class_count
= GET_BE_WORD(mmpf1
->ClassCount
);
2104 int mark2record_size
;
2107 TRACE("Mark %x(%i) and Mark2 %x(%i)\n",glyphs
[glyph_index
], mark_index
, glyphs
[glyph_index
- write_dir
], mark2_index
);
2108 offset
= GET_BE_WORD(mmpf1
->Mark1Array
);
2109 ma
= (const GPOS_MarkArray
*)((const BYTE
*)mmpf1
+ offset
);
2110 if (mark_index
> GET_BE_WORD(ma
->MarkCount
))
2112 ERR("Mark index exceeded mark count\n");
2115 mr
= &ma
->MarkRecord
[mark_index
];
2116 mark_class
= GET_BE_WORD(mr
->Class
);
2117 TRACE("Mark Class %i total classes %i\n",mark_class
,class_count
);
2118 offset
= GET_BE_WORD(mmpf1
->Mark2Array
);
2119 m2a
= (const GPOS_Mark2Array
*)((const BYTE
*)mmpf1
+ offset
);
2120 mark2record_size
= class_count
* sizeof(WORD
);
2121 m2r
= (const GPOS_Mark2Record
*)((const BYTE
*)m2a
+ sizeof(WORD
) + (mark2record_size
* mark2_index
));
2122 offset
= GET_BE_WORD(m2r
->Mark2Anchor
[mark_class
]);
2123 GPOS_get_anchor_values((const BYTE
*)m2a
+ offset
, &mark2_pt
, ppem
);
2124 offset
= GET_BE_WORD(mr
->MarkAnchor
);
2125 GPOS_get_anchor_values((const BYTE
*)ma
+ offset
, &mark_pt
, ppem
);
2126 TRACE("Offset on mark2 is %s design units\n",wine_dbgstr_point(&mark2_pt
));
2127 TRACE("Offset on mark is %s design units\n",wine_dbgstr_point(&mark_pt
));
2128 pt
->x
+= mark2_pt
.x
- mark_pt
.x
;
2129 pt
->y
+= mark2_pt
.y
- mark_pt
.y
;
2130 TRACE("Resulting cumulative offset is %s design units\n",wine_dbgstr_point(pt
));
2136 FIXME("Unhandled Mark To Mark Format %i\n",GET_BE_WORD(mmpf1
->PosFormat
));
2141 static unsigned int GPOS_apply_ContextPos(const ScriptCache
*script_cache
, const OUTLINETEXTMETRICW
*otm
,
2142 const LOGFONTW
*logfont
, const SCRIPT_ANALYSIS
*analysis
, int *advance
, const OT_LookupList
*lookup
,
2143 const OT_LookupTable
*look
, const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
,
2147 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2149 TRACE("Contextual Positioning Subtable\n");
2151 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
2153 const GPOS_ContextPosFormat2
*cpf2
= (GPOS_ContextPosFormat2
*)GPOS_get_subtable(look
, j
);
2155 if (GET_BE_WORD(cpf2
->PosFormat
) == 1)
2159 FIXME(" TODO: subtype 1\n");
2162 else if (GET_BE_WORD(cpf2
->PosFormat
) == 2)
2164 WORD offset
= GET_BE_WORD(cpf2
->Coverage
);
2167 TRACE("Contextual Positioning Subtable: Format 2\n");
2169 index
= GSUB_is_glyph_covered((const BYTE
*)cpf2
+offset
, glyphs
[glyph_index
]);
2170 TRACE("Coverage index %i\n",index
);
2173 int k
, count
, class;
2174 const GPOS_PosClassSet
*pcs
;
2175 const void *glyph_class_table
= NULL
;
2177 offset
= GET_BE_WORD(cpf2
->ClassDef
);
2178 glyph_class_table
= (const BYTE
*)cpf2
+ offset
;
2180 class = OT_get_glyph_class(glyph_class_table
,glyphs
[glyph_index
]);
2182 offset
= GET_BE_WORD(cpf2
->PosClassSet
[class]);
2185 TRACE("No class rule table for class %i\n",class);
2188 pcs
= (const GPOS_PosClassSet
*)((const BYTE
*)cpf2
+offset
);
2189 count
= GET_BE_WORD(pcs
->PosClassRuleCnt
);
2190 TRACE("PosClassSet has %i members\n",count
);
2191 for (k
= 0; k
< count
; k
++)
2193 const GPOS_PosClassRule_1
*pr
;
2194 const GPOS_PosClassRule_2
*pr_2
;
2198 offset
= GET_BE_WORD(pcs
->PosClassRule
[k
]);
2199 pr
= (const GPOS_PosClassRule_1
*)((const BYTE
*)pcs
+offset
);
2200 g_count
= GET_BE_WORD(pr
->GlyphCount
);
2201 TRACE("PosClassRule has %i glyphs classes\n",g_count
);
2203 g
= glyph_index
+ write_dir
* (g_count
- 1);
2204 if (g
>= glyph_count
)
2207 for (l
= 0; l
< g_count
-1; l
++)
2209 int g_class
= OT_get_glyph_class(glyph_class_table
, glyphs
[glyph_index
+ (write_dir
* (l
+1))]);
2210 if (g_class
!= GET_BE_WORD(pr
->Class
[l
])) break;
2215 TRACE("Rule does not match\n");
2219 TRACE("Rule matches\n");
2220 pr_2
= (const GPOS_PosClassRule_2
*)&pr
->Class
[g_count
- 1];
2222 for (l
= 0; l
< GET_BE_WORD(pr
->PosCount
); l
++)
2224 unsigned int lookup_index
= GET_BE_WORD(pr_2
->PosLookupRecord
[l
].LookupListIndex
);
2225 unsigned int sequence_index
= GET_BE_WORD(pr_2
->PosLookupRecord
[l
].SequenceIndex
);
2227 g
= glyph_index
+ write_dir
* sequence_index
;
2228 if (g
>= glyph_count
)
2230 WARN("Invalid sequence index %u (glyph index %u, write dir %d).\n",
2231 sequence_index
, glyph_index
, write_dir
);
2235 TRACE("Position: %u -> %u %u.\n", l
, sequence_index
, lookup_index
);
2237 GPOS_apply_lookup(script_cache
, otm
, logfont
, analysis
, advance
,
2238 lookup
, lookup_index
, glyphs
, g
, glyph_count
, goffset
);
2244 TRACE("Not covered\n");
2247 else if (GET_BE_WORD(cpf2
->PosFormat
) == 3)
2251 FIXME(" TODO: subtype 3\n");
2255 FIXME("Unhandled Contextual Positioning Format %i\n",GET_BE_WORD(cpf2
->PosFormat
));
2260 static unsigned int GPOS_apply_ChainContextPos(const ScriptCache
*script_cache
, const OUTLINETEXTMETRICW
*otm
,
2261 const LOGFONTW
*logfont
, const SCRIPT_ANALYSIS
*analysis
, int *advance
, const OT_LookupList
*lookup
,
2262 const OT_LookupTable
*look
, const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
,
2266 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2268 TRACE("Chaining Contextual Positioning Subtable\n");
2270 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
2273 const GPOS_ChainContextPosFormat3_1
*backtrack
= (GPOS_ChainContextPosFormat3_1
*)GPOS_get_subtable(look
, j
);
2274 int dirLookahead
= write_dir
;
2275 int dirBacktrack
= -1 * write_dir
;
2277 if (GET_BE_WORD(backtrack
->PosFormat
) == 1)
2281 FIXME(" TODO: subtype 1 (Simple Chaining Context Glyph Positioning)\n");
2284 else if (GET_BE_WORD(backtrack
->PosFormat
) == 2)
2288 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Positioning)\n");
2291 else if (GET_BE_WORD(backtrack
->PosFormat
) == 3)
2293 WORD backtrack_count
, input_count
, lookahead_count
, positioning_count
;
2295 const GPOS_ChainContextPosFormat3_2
*input
;
2296 const GPOS_ChainContextPosFormat3_3
*lookahead
;
2297 const GPOS_ChainContextPosFormat3_4
*positioning
;
2299 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Positioning)\n");
2301 backtrack_count
= GET_BE_WORD(backtrack
->BacktrackGlyphCount
);
2302 k
= glyph_index
+ dirBacktrack
* backtrack_count
;
2303 if (k
< 0 || k
>= glyph_count
)
2306 input
= (const GPOS_ChainContextPosFormat3_2
*)&backtrack
->Coverage
[backtrack_count
];
2307 input_count
= GET_BE_WORD(input
->InputGlyphCount
);
2308 k
= glyph_index
+ write_dir
* (input_count
- 1);
2309 if (k
< 0 || k
>= glyph_count
)
2312 lookahead
= (const GPOS_ChainContextPosFormat3_3
*)&input
->Coverage
[input_count
];
2313 lookahead_count
= GET_BE_WORD(lookahead
->LookaheadGlyphCount
);
2314 k
= glyph_index
+ dirLookahead
* (input_count
+ lookahead_count
- 1);
2315 if (k
< 0 || k
>= glyph_count
)
2318 positioning
= (const GPOS_ChainContextPosFormat3_4
*)&lookahead
->Coverage
[lookahead_count
];
2320 for (k
= 0; k
< backtrack_count
; ++k
)
2322 offset
= GET_BE_WORD(backtrack
->Coverage
[k
]);
2323 if (GSUB_is_glyph_covered((const BYTE
*)backtrack
+ offset
,
2324 glyphs
[glyph_index
+ (dirBacktrack
* (k
+ 1))]) == -1)
2327 if (k
!= backtrack_count
)
2329 TRACE("Matched Backtrack\n");
2331 for (k
= 0; k
< input_count
; ++k
)
2333 offset
= GET_BE_WORD(input
->Coverage
[k
]);
2334 if (GSUB_is_glyph_covered((const BYTE
*)backtrack
+ offset
,
2335 glyphs
[glyph_index
+ (write_dir
* k
)]) == -1)
2338 if (k
!= input_count
)
2340 TRACE("Matched IndexGlyphs\n");
2342 for (k
= 0; k
< lookahead_count
; ++k
)
2344 offset
= GET_BE_WORD(lookahead
->Coverage
[k
]);
2345 if (GSUB_is_glyph_covered((const BYTE
*)backtrack
+ offset
,
2346 glyphs
[glyph_index
+ (dirLookahead
* (input_count
+ k
))]) == -1)
2349 if (k
!= lookahead_count
)
2351 TRACE("Matched LookAhead\n");
2353 if (!(positioning_count
= GET_BE_WORD(positioning
->PosCount
)))
2356 for (k
= 0; k
< positioning_count
; ++k
)
2358 unsigned int lookup_index
= GET_BE_WORD(positioning
->PosLookupRecord
[k
].LookupListIndex
);
2359 unsigned int sequence_index
= GET_BE_WORD(positioning
->PosLookupRecord
[k
].SequenceIndex
);
2360 unsigned int g
= glyph_index
+ write_dir
* sequence_index
;
2362 if (g
>= glyph_count
)
2364 WARN("Skipping invalid sequence index %u (glyph index %u, write dir %d).\n",
2365 sequence_index
, glyph_index
, write_dir
);
2369 TRACE("Position: %u -> %u %u.\n", k
, sequence_index
, lookup_index
);
2370 GPOS_apply_lookup(script_cache
, otm
, logfont
, analysis
, advance
, lookup
, lookup_index
,
2371 glyphs
, g
, glyph_count
, goffset
);
2373 return input_count
+ lookahead_count
;
2376 FIXME("Unhandled Chaining Contextual Positioning Format %#x.\n", GET_BE_WORD(backtrack
->PosFormat
));
2381 static unsigned int GPOS_apply_lookup(const ScriptCache
*script_cache
, const OUTLINETEXTMETRICW
*lpotm
,
2382 const LOGFONTW
*lplogfont
, const SCRIPT_ANALYSIS
*analysis
, int *piAdvance
, const OT_LookupList
*lookup
,
2383 unsigned int lookup_index
, const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
,
2387 const OT_LookupTable
*look
;
2388 int ppem
= lpotm
->otmTextMetrics
.tmAscent
+ lpotm
->otmTextMetrics
.tmDescent
- lpotm
->otmTextMetrics
.tmInternalLeading
;
2389 enum gpos_lookup_type type
;
2391 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
2392 look
= (const OT_LookupTable
*)((const BYTE
*)lookup
+ offset
);
2393 type
= GET_BE_WORD(look
->LookupType
);
2394 TRACE("type %#x, flag %#x, subtables %u.\n", type
,
2395 GET_BE_WORD(look
->LookupFlag
), GET_BE_WORD(look
->SubTableCount
));
2397 if (type
== GPOS_LOOKUP_POSITION_EXTENSION
)
2399 if (GET_BE_WORD(look
->SubTableCount
))
2401 const GPOS_ExtensionPosFormat1
*ext
= (const GPOS_ExtensionPosFormat1
*)((const BYTE
*)look
+ GET_BE_WORD(look
->SubTable
[0]));
2402 if (GET_BE_WORD(ext
->PosFormat
) == 1)
2404 type
= GET_BE_WORD(ext
->ExtensionLookupType
);
2405 TRACE("extension type %i\n",type
);
2409 FIXME("Unhandled Extension Positioning Format %i\n",GET_BE_WORD(ext
->PosFormat
));
2414 WARN("lookup type is Extension Positioning but no extension subtable exists\n");
2419 case GPOS_LOOKUP_ADJUST_SINGLE
:
2422 POINT adjust
= {0,0};
2423 POINT advance
= {0,0};
2424 GPOS_apply_SingleAdjustment(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &adjust
, &advance
);
2425 if (adjust
.x
|| adjust
.y
)
2427 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, adjust
.x
, adjust
.y
, &devX
, &devY
);
2428 pGoffset
[glyph_index
].du
+= round(devX
);
2429 pGoffset
[glyph_index
].dv
+= round(devY
);
2431 if (advance
.x
|| advance
.y
)
2433 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, advance
.x
, advance
.y
, &devX
, &devY
);
2434 piAdvance
[glyph_index
] += round(devX
);
2436 FIXME("Unhandled adjustment to Y advancement\n");
2441 case GPOS_LOOKUP_ADJUST_PAIR
:
2443 POINT advance
[2]= {{0,0},{0,0}};
2444 POINT adjust
[2]= {{0,0},{0,0}};
2447 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2448 int offset_sign
= (analysis
->fRTL
&& analysis
->fLogicalOrder
) ? -1 : 1;
2450 index_offset
= GPOS_apply_PairAdjustment(look
, analysis
, glyphs
,
2451 glyph_index
, glyph_count
, ppem
, adjust
, advance
);
2452 if (adjust
[0].x
|| adjust
[0].y
)
2454 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, adjust
[0].x
, adjust
[0].y
, &devX
, &devY
);
2455 pGoffset
[glyph_index
].du
+= round(devX
) * offset_sign
;
2456 pGoffset
[glyph_index
].dv
+= round(devY
);
2458 if (advance
[0].x
|| advance
[0].y
)
2460 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, advance
[0].x
, advance
[0].y
, &devX
, &devY
);
2461 piAdvance
[glyph_index
] += round(devX
);
2463 if (adjust
[1].x
|| adjust
[1].y
)
2465 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, adjust
[1].x
, adjust
[1].y
, &devX
, &devY
);
2466 pGoffset
[glyph_index
+ write_dir
].du
+= round(devX
) * offset_sign
;
2467 pGoffset
[glyph_index
+ write_dir
].dv
+= round(devY
);
2469 if (advance
[1].x
|| advance
[1].y
)
2471 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, advance
[1].x
, advance
[1].y
, &devX
, &devY
);
2472 piAdvance
[glyph_index
+ write_dir
] += round(devX
);
2474 return index_offset
;
2477 case GPOS_LOOKUP_ATTACH_CURSIVE
:
2481 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2483 GPOS_apply_CursiveAttachment(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &desU
);
2484 if (desU
.x
|| desU
.y
)
2486 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
2487 /* Windows does not appear to apply X offsets here */
2488 pGoffset
[glyph_index
].dv
= round(devY
) + pGoffset
[glyph_index
+write_dir
].dv
;
2493 case GPOS_LOOKUP_ATTACH_MARK_TO_BASE
:
2497 int base_index
= GPOS_apply_MarkToBase(script_cache
, look
, analysis
,
2498 glyphs
, glyph_index
, glyph_count
, ppem
, &desU
);
2499 if (base_index
!= -1)
2501 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
2502 if (!analysis
->fRTL
) pGoffset
[glyph_index
].du
= round(devX
) - piAdvance
[base_index
];
2505 if (analysis
->fLogicalOrder
) devX
*= -1;
2506 pGoffset
[glyph_index
].du
= round(devX
);
2508 pGoffset
[glyph_index
].dv
= round(devY
);
2513 case GPOS_LOOKUP_ATTACH_MARK_TO_LIGATURE
:
2517 GPOS_apply_MarkToLigature(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &desU
);
2518 if (desU
.x
|| desU
.y
)
2520 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
2521 pGoffset
[glyph_index
].du
= (round(devX
) - piAdvance
[glyph_index
-1]);
2522 pGoffset
[glyph_index
].dv
= round(devY
);
2527 case GPOS_LOOKUP_ATTACH_MARK_TO_MARK
:
2531 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
2532 if (GPOS_apply_MarkToMark(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &desU
))
2534 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
2535 if (analysis
->fRTL
&& analysis
->fLogicalOrder
) devX
*= -1;
2536 pGoffset
[glyph_index
].du
= round(devX
) + pGoffset
[glyph_index
- write_dir
].du
;
2537 pGoffset
[glyph_index
].dv
= round(devY
) + pGoffset
[glyph_index
- write_dir
].dv
;
2542 case GPOS_LOOKUP_POSITION_CONTEXT
:
2543 return GPOS_apply_ContextPos(script_cache
, lpotm
, lplogfont
, analysis
, piAdvance
,
2544 lookup
, look
, glyphs
, glyph_index
, glyph_count
, pGoffset
);
2546 case GPOS_LOOKUP_POSITION_CONTEXT_CHAINED
:
2547 return GPOS_apply_ChainContextPos(script_cache
, lpotm
, lplogfont
, analysis
, piAdvance
,
2548 lookup
, look
, glyphs
, glyph_index
, glyph_count
, pGoffset
);
2551 FIXME("Unhandled GPOS lookup type %#x.\n", type
);
2556 unsigned int OpenType_apply_GPOS_lookup(const ScriptCache
*script_cache
, const OUTLINETEXTMETRICW
*otm
,
2557 const LOGFONTW
*logfont
, const SCRIPT_ANALYSIS
*analysis
, int *advance
, unsigned int lookup_index
,
2558 const WORD
*glyphs
, unsigned int glyph_index
, unsigned int glyph_count
, GOFFSET
*goffset
)
2560 const GPOS_Header
*header
= (const GPOS_Header
*)script_cache
->GPOS_Table
;
2561 const OT_LookupList
*lookup
= (const OT_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
2563 return GPOS_apply_lookup(script_cache
, otm
, logfont
, analysis
, advance
, lookup
,
2564 lookup_index
, glyphs
, glyph_index
, glyph_count
, goffset
);
2567 static LoadedScript
*usp10_script_cache_get_script(ScriptCache
*script_cache
, OPENTYPE_TAG tag
)
2571 for (i
= 0; i
< script_cache
->script_count
; ++i
)
2573 if (script_cache
->scripts
[i
].tag
== tag
)
2574 return &script_cache
->scripts
[i
];
2580 static void GSUB_initialize_script_cache(ScriptCache
*psc
)
2584 if (psc
->GSUB_Table
)
2586 const OT_ScriptList
*script
;
2587 const GSUB_Header
* header
= (const GSUB_Header
*)psc
->GSUB_Table
;
2588 script
= (const OT_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
2589 psc
->script_count
= GET_BE_WORD(script
->ScriptCount
);
2590 TRACE("initializing %li scripts in this font\n",psc
->script_count
);
2591 if (psc
->script_count
)
2593 psc
->scripts
= heap_alloc_zero(psc
->script_count
* sizeof(*psc
->scripts
));
2594 for (i
= 0; i
< psc
->script_count
; i
++)
2596 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
2597 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]);
2598 psc
->scripts
[i
].gsub_table
= ((const BYTE
*)script
+ offset
);
2604 static void GPOS_expand_script_cache(ScriptCache
*psc
)
2607 const OT_ScriptList
*script
;
2608 const GPOS_Header
* header
= (const GPOS_Header
*)psc
->GPOS_Table
;
2609 LoadedScript
*loaded_script
;
2614 script
= (const OT_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
2615 count
= GET_BE_WORD(script
->ScriptCount
);
2620 if (!psc
->script_count
)
2622 psc
->script_count
= count
;
2623 TRACE("initializing %li scripts in this font\n",psc
->script_count
);
2624 if (psc
->script_count
)
2626 psc
->scripts
= heap_alloc_zero(psc
->script_count
* sizeof(*psc
->scripts
));
2627 for (i
= 0; i
< psc
->script_count
; i
++)
2629 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
2630 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]);
2631 psc
->scripts
[i
].gpos_table
= ((const BYTE
*)script
+ offset
);
2637 for (i
= 0; i
< count
; i
++)
2639 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
2640 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]);
2642 if (!(loaded_script
= usp10_script_cache_get_script(psc
, tag
)))
2644 if (!usp10_array_reserve((void **)&psc
->scripts
, &psc
->scripts_size
,
2645 psc
->script_count
+ 1, sizeof(*psc
->scripts
)))
2647 ERR("Failed grow scripts array.\n");
2651 loaded_script
= &psc
->scripts
[psc
->script_count
];
2652 ++psc
->script_count
;
2653 loaded_script
->tag
= tag
;
2655 loaded_script
->gpos_table
= (const BYTE
*)script
+ offset
;
2660 static void _initialize_script_cache(ScriptCache
*psc
)
2662 if (!psc
->scripts_initialized
)
2664 GSUB_initialize_script_cache(psc
);
2665 GPOS_expand_script_cache(psc
);
2666 psc
->scripts_initialized
= TRUE
;
2670 HRESULT
OpenType_GetFontScriptTags(ScriptCache
*psc
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pScriptTags
, int *pcTags
)
2673 const LoadedScript
*script
;
2676 _initialize_script_cache(psc
);
2678 *pcTags
= psc
->script_count
;
2682 if (!(script
= usp10_script_cache_get_script(psc
, searchingFor
)))
2683 return USP_E_SCRIPT_NOT_IN_FONT
;
2685 *pScriptTags
= script
->tag
;
2690 if (cMaxTags
< *pcTags
)
2693 cMaxTags
= min(cMaxTags
, psc
->script_count
);
2694 for (i
= 0; i
< cMaxTags
; ++i
)
2696 pScriptTags
[i
] = psc
->scripts
[i
].tag
;
2701 static LoadedLanguage
*usp10_script_get_language(LoadedScript
*script
, OPENTYPE_TAG tag
)
2705 for (i
= 0; i
< script
->language_count
; ++i
)
2707 if (script
->languages
[i
].tag
== tag
)
2708 return &script
->languages
[i
];
2714 static void GSUB_initialize_language_cache(LoadedScript
*script
)
2718 if (script
->gsub_table
)
2721 const OT_Script
* table
= script
->gsub_table
;
2722 script
->language_count
= GET_BE_WORD(table
->LangSysCount
);
2723 offset
= GET_BE_WORD(table
->DefaultLangSys
);
2726 script
->default_language
.tag
= MS_MAKE_TAG('d','f','l','t');
2727 script
->default_language
.gsub_table
= (const BYTE
*)table
+ offset
;
2730 if (script
->language_count
)
2732 TRACE("Deflang %p, LangCount %li\n",script
->default_language
.gsub_table
, script
->language_count
);
2734 script
->languages
= heap_alloc_zero(script
->language_count
* sizeof(*script
->languages
));
2736 for (i
= 0; i
< script
->language_count
; i
++)
2738 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
2739 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]);
2740 script
->languages
[i
].gsub_table
= ((const BYTE
*)table
+ offset
);
2746 static void GPOS_expand_language_cache(LoadedScript
*script
)
2749 const OT_Script
* table
= script
->gpos_table
;
2750 LoadedLanguage
*language
;
2756 offset
= GET_BE_WORD(table
->DefaultLangSys
);
2758 script
->default_language
.gpos_table
= (const BYTE
*)table
+ offset
;
2760 count
= GET_BE_WORD(table
->LangSysCount
);
2762 TRACE("Deflang %p, LangCount %i\n",script
->default_language
.gpos_table
, count
);
2767 if (!script
->language_count
)
2770 script
->language_count
= count
;
2772 script
->languages
= heap_alloc_zero(script
->language_count
* sizeof(*script
->languages
));
2774 for (i
= 0; i
< script
->language_count
; i
++)
2776 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
2777 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]);
2778 script
->languages
[i
].gpos_table
= ((const BYTE
*)table
+ offset
);
2784 for (i
= 0; i
< count
; i
++)
2786 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
2787 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]);
2789 if (!(language
= usp10_script_get_language(script
, tag
)))
2791 if (!usp10_array_reserve((void **)&script
->languages
, &script
->languages_size
,
2792 script
->language_count
+ 1, sizeof(*script
->languages
)))
2794 ERR("Failed grow languages array.\n");
2798 language
= &script
->languages
[script
->language_count
];
2799 ++script
->language_count
;
2800 language
->tag
= tag
;
2802 language
->gpos_table
= (const BYTE
*)table
+ offset
;
2807 static void _initialize_language_cache(LoadedScript
*script
)
2809 if (!script
->languages_initialized
)
2811 GSUB_initialize_language_cache(script
);
2812 GPOS_expand_language_cache(script
);
2813 script
->languages_initialized
= TRUE
;
2817 HRESULT
OpenType_GetFontLanguageTags(ScriptCache
*psc
, OPENTYPE_TAG script_tag
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pLanguageTags
, int *pcTags
)
2821 LoadedScript
*script
= NULL
;
2823 _initialize_script_cache(psc
);
2824 if (!(script
= usp10_script_cache_get_script(psc
, script_tag
)))
2825 return E_INVALIDARG
;
2827 _initialize_language_cache(script
);
2829 if (!searchingFor
&& cMaxTags
< script
->language_count
)
2831 else if (searchingFor
)
2834 *pcTags
= script
->language_count
;
2836 for (i
= 0; i
< script
->language_count
; i
++)
2839 pLanguageTags
[i
] = script
->languages
[i
].tag
;
2843 if (searchingFor
== script
->languages
[i
].tag
)
2845 pLanguageTags
[0] = script
->languages
[i
].tag
;
2853 if (script
->default_language
.gsub_table
)
2856 pLanguageTags
[i
] = script
->default_language
.tag
;
2858 if (searchingFor
&& FAILED(rc
))
2860 pLanguageTags
[0] = script
->default_language
.tag
;
2863 *pcTags
= (*pcTags
) + 1;
2869 static void usp10_language_add_feature_list(LoadedLanguage
*language
, char table_type
,
2870 const OT_LangSys
*lang
, const OT_FeatureList
*feature_list
)
2872 unsigned int count
= GET_BE_WORD(lang
->FeatureCount
);
2875 TRACE("table_type %#x, %u features.\n", table_type
, count
);
2880 if (!language
->feature_count
)
2881 language
->features
= heap_alloc(count
* sizeof(*language
->features
));
2883 language
->features
= HeapReAlloc(GetProcessHeap(), 0, language
->features
,
2884 (language
->feature_count
+ count
) * sizeof(*language
->features
));
2886 for (i
= 0; i
< count
; ++i
)
2888 const OT_FeatureRecord
*record
;
2889 LoadedFeature
*loaded_feature
;
2890 const OT_Feature
*feature
;
2892 record
= &feature_list
->FeatureRecord
[GET_BE_WORD(lang
->FeatureIndex
[i
])];
2893 feature
= (const OT_Feature
*)((const BYTE
*)feature_list
+ GET_BE_WORD(record
->Feature
));
2895 loaded_feature
= &language
->features
[language
->feature_count
+ i
];
2896 loaded_feature
->tag
= MS_MAKE_TAG(record
->FeatureTag
[0], record
->FeatureTag
[1],
2897 record
->FeatureTag
[2], record
->FeatureTag
[3]);
2898 loaded_feature
->tableType
= table_type
;
2899 loaded_feature
->feature
= feature
;
2900 loaded_feature
->lookup_count
= GET_BE_WORD(feature
->LookupCount
);
2901 loaded_feature
->lookups
= heap_alloc(loaded_feature
->lookup_count
* sizeof(*loaded_feature
->lookups
));
2902 for (j
= 0; j
< loaded_feature
->lookup_count
; ++j
)
2903 loaded_feature
->lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
2905 language
->feature_count
+= count
;
2908 static void _initialize_feature_cache(ScriptCache
*psc
, LoadedLanguage
*language
)
2910 const GSUB_Header
*gsub_header
= psc
->GSUB_Table
;
2911 const GPOS_Header
*gpos_header
= psc
->GPOS_Table
;
2912 const OT_FeatureList
*feature_list
;
2913 const OT_LangSys
*lang
;
2915 if (language
->features_initialized
)
2918 if ((lang
= language
->gsub_table
))
2920 feature_list
= (const OT_FeatureList
*)((const BYTE
*)gsub_header
+ GET_BE_WORD(gsub_header
->FeatureList
));
2921 usp10_language_add_feature_list(language
, FEATURE_GSUB_TABLE
, lang
, feature_list
);
2924 if ((lang
= language
->gpos_table
))
2926 feature_list
= (const OT_FeatureList
*)((const BYTE
*)gpos_header
+ GET_BE_WORD(gpos_header
->FeatureList
));
2927 usp10_language_add_feature_list(language
, FEATURE_GPOS_TABLE
, lang
, feature_list
);
2930 language
->features_initialized
= TRUE
;
2933 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
)
2936 LoadedScript
*script
;
2938 LoadedLanguage
*language
= NULL
;
2940 _initialize_script_cache(psc
);
2941 if (!(script
= usp10_script_cache_get_script(psc
, script_tag
)))
2947 return E_INVALIDARG
;
2950 _initialize_language_cache(script
);
2952 if ((script
->default_language
.gsub_table
|| script
->default_language
.gpos_table
) && script
->default_language
.tag
== language_tag
)
2953 language
= &script
->default_language
;
2955 language
= usp10_script_get_language(script
, language_tag
);
2963 _initialize_feature_cache(psc
, language
);
2968 for (i
= 0; i
< language
->feature_count
; i
++)
2969 if (language
->features
[i
].tableType
== tableType
)
2970 *pcTags
= (*pcTags
)+1;
2973 *pcTags
= language
->feature_count
;
2975 if (!searchingFor
&& cMaxTags
< *pcTags
)
2977 else if (searchingFor
)
2980 for (i
= 0; i
< language
->feature_count
; i
++)
2984 if (!tableType
|| language
->features
[i
].tableType
== tableType
)
2985 pFeatureTags
[i
] = language
->features
[i
].tag
;
2990 if ((searchingFor
== language
->features
[i
].tag
) &&
2991 (!tableType
|| language
->features
[i
].tableType
== tableType
))
2993 pFeatureTags
[0] = language
->features
[i
].tag
;
2996 *feature
= &language
->features
[i
];