2 * Opentype font interfaces for the Uniscribe Script Processor (usp10.dll)
4 * Copyright 2012 CodeWeavers, Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "usp10_internal.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe
);
38 #ifdef WORDS_BIGENDIAN
39 #define GET_BE_WORD(x) (x)
40 #define GET_BE_DWORD(x) (x)
42 #define GET_BE_WORD(x) RtlUshortByteSwap(x)
43 #define GET_BE_DWORD(x) RtlUlongByteSwap(x)
46 #define round(x) (((x) < 0) ? (int)((x) - 0.5) : (int)((x) + 0.5))
48 /* These are all structures needed for the cmap format 12 table */
49 #define CMAP_TAG MS_MAKE_TAG('c', 'm', 'a', 'p')
55 } CMAP_EncodingRecord
;
60 CMAP_EncodingRecord tables
[1];
67 } CMAP_SegmentedCoverage_group
;
75 CMAP_SegmentedCoverage_group groups
[1];
76 } CMAP_SegmentedCoverage
;
78 /* These are all structures needed for the GDEF table */
79 enum {BaseGlyph
=1, LigatureGlyph
, MarkGlyph
, ComponentGlyph
};
86 WORD MarkAttachClassDef
;
93 WORD ClassValueArray
[1];
100 } OT_ClassRangeRecord
;
104 WORD ClassRangeCount
;
105 OT_ClassRangeRecord ClassRangeRecord
[1];
106 } OT_ClassDefFormat2
;
108 /* These are all structures needed for the GSUB table */
124 OT_ScriptRecord ScriptRecord
[1];
135 OT_LangSysRecord LangSysRecord
[1];
139 WORD LookupOrder
; /* Reserved */
140 WORD ReqFeatureIndex
;
142 WORD FeatureIndex
[1];
152 OT_FeatureRecord FeatureRecord
[1];
156 WORD FeatureParams
; /* Reserved */
158 WORD LookupListIndex
[1];
177 } OT_CoverageFormat1
;
182 WORD StartCoverageIndex
;
188 OT_RangeRecord RangeRecord
[1];
189 } OT_CoverageFormat2
;
192 WORD SubstFormat
; /* = 1 */
195 } GSUB_SingleSubstFormat1
;
198 WORD SubstFormat
; /* = 2 */
202 }GSUB_SingleSubstFormat2
;
205 WORD SubstFormat
; /* = 1 */
209 }GSUB_MultipleSubstFormat1
;
217 WORD SubstFormat
; /* = 1 */
221 }GSUB_LigatureSubstFormat1
;
236 WORD LookupListIndex
;
238 }GSUB_SubstLookupRecord
;
241 WORD SubstFormat
; /* = 1 */
243 WORD ChainSubRuleSetCount
;
244 WORD ChainSubRuleSet
[1];
245 }GSUB_ChainContextSubstFormat1
;
248 WORD SubstFormat
; /* = 3 */
249 WORD BacktrackGlyphCount
;
251 }GSUB_ChainContextSubstFormat3_1
;
254 WORD InputGlyphCount
;
256 }GSUB_ChainContextSubstFormat3_2
;
259 WORD LookaheadGlyphCount
;
261 }GSUB_ChainContextSubstFormat3_3
;
265 GSUB_SubstLookupRecord SubstLookupRecord
[1];
266 }GSUB_ChainContextSubstFormat3_4
;
269 WORD SubstFormat
; /* = 1 */
271 WORD AlternateSetCount
;
272 WORD AlternateSet
[1];
273 } GSUB_AlternateSubstFormat1
;
280 /* These are all structures needed for the GPOS table */
300 } GPOS_AnchorFormat1
;
307 } GPOS_AnchorFormat2
;
315 } GPOS_AnchorFormat3
;
333 } GPOS_SinglePosFormat1
;
341 } GPOS_SinglePosFormat2
;
349 WORD PairSetOffset
[1];
350 } GPOS_PairPosFormat1
;
361 WORD Class1Record
[1];
362 } GPOS_PairPosFormat2
;
368 } GPOS_PairValueRecord
;
372 GPOS_PairValueRecord PairValueRecord
[1];
378 } GPOS_EntryExitRecord
;
384 GPOS_EntryExitRecord EntryExitRecord
[1];
385 } GPOS_CursivePosFormat1
;
394 } GPOS_MarkBasePosFormat1
;
402 GPOS_BaseRecord BaseRecord
[1];
412 GPOS_MarkRecord MarkRecord
[1];
418 WORD LigatureCoverage
;
422 } GPOS_MarkLigPosFormat1
;
426 WORD LigatureAttach
[1];
427 } GPOS_LigatureArray
;
430 WORD LigatureAnchor
[1];
431 } GPOS_ComponentRecord
;
435 GPOS_ComponentRecord ComponentRecord
[1];
436 } GPOS_LigatureAttach
;
445 } GPOS_MarkMarkPosFormat1
;
453 GPOS_Mark2Record Mark2Record
[1];
458 WORD LookupListIndex
;
459 } GPOS_PosLookupRecord
;
463 WORD BacktrackGlyphCount
;
465 } GPOS_ChainContextPosFormat3_1
;
468 WORD InputGlyphCount
;
470 } GPOS_ChainContextPosFormat3_2
;
473 WORD LookaheadGlyphCount
;
475 } GPOS_ChainContextPosFormat3_3
;
479 GPOS_PosLookupRecord PosLookupRecord
[1];
480 } GPOS_ChainContextPosFormat3_4
;
486 static VOID
*load_CMAP_format12_table(HDC hdc
, ScriptCache
*psc
)
488 CMAP_Header
*CMAP_Table
= NULL
;
492 if (!psc
->CMAP_Table
)
494 length
= GetFontData(hdc
, CMAP_TAG
, 0, NULL
, 0);
495 if (length
!= GDI_ERROR
)
497 psc
->CMAP_Table
= HeapAlloc(GetProcessHeap(),0,length
);
498 GetFontData(hdc
, CMAP_TAG
, 0, psc
->CMAP_Table
, length
);
499 TRACE("Loaded cmap table of %i bytes\n",length
);
505 CMAP_Table
= psc
->CMAP_Table
;
507 for (i
= 0; i
< GET_BE_WORD(CMAP_Table
->numTables
); i
++)
509 if ( (GET_BE_WORD(CMAP_Table
->tables
[i
].platformID
) == 3) &&
510 (GET_BE_WORD(CMAP_Table
->tables
[i
].encodingID
) == 10) )
512 CMAP_SegmentedCoverage
*format
= (CMAP_SegmentedCoverage
*)(((BYTE
*)CMAP_Table
) + GET_BE_DWORD(CMAP_Table
->tables
[i
].offset
));
513 if (GET_BE_WORD(format
->format
) == 12)
520 static int compare_group(const void *a
, const void* b
)
522 const DWORD
*chr
= a
;
523 const CMAP_SegmentedCoverage_group
*group
= b
;
525 if (*chr
< GET_BE_DWORD(group
->startCharCode
))
527 if (*chr
> GET_BE_DWORD(group
->endCharCode
))
532 DWORD
OpenType_CMAP_GetGlyphIndex(HDC hdc
, ScriptCache
*psc
, DWORD utf32c
, LPWORD pgi
, DWORD flags
)
534 /* BMP: use gdi32 for ease */
535 if (utf32c
< 0x10000)
538 return GetGlyphIndicesW(hdc
,&ch
, 1, pgi
, flags
);
541 if (!psc
->CMAP_format12_Table
)
542 psc
->CMAP_format12_Table
= load_CMAP_format12_table(hdc
, psc
);
544 if (flags
& GGI_MARK_NONEXISTING_GLYPHS
)
549 if (psc
->CMAP_format12_Table
)
551 CMAP_SegmentedCoverage
*format
= NULL
;
552 CMAP_SegmentedCoverage_group
*group
= NULL
;
554 format
= (CMAP_SegmentedCoverage
*)psc
->CMAP_format12_Table
;
556 group
= bsearch(&utf32c
, format
->groups
, GET_BE_DWORD(format
->nGroups
),
557 sizeof(CMAP_SegmentedCoverage_group
), compare_group
);
561 DWORD offset
= utf32c
- GET_BE_DWORD(group
->startCharCode
);
562 *pgi
= GET_BE_DWORD(group
->startGlyphID
) + offset
;
573 static WORD
OT_get_glyph_class(const void *table
, WORD glyph
)
576 const OT_ClassDefFormat1
*cf1
= table
;
578 if (!table
) return 0;
580 if (GET_BE_WORD(cf1
->ClassFormat
) == 1)
582 if (glyph
>= GET_BE_WORD(cf1
->StartGlyph
))
584 int index
= glyph
- GET_BE_WORD(cf1
->StartGlyph
);
585 if (index
< GET_BE_WORD(cf1
->GlyphCount
))
586 class = GET_BE_WORD(cf1
->ClassValueArray
[index
]);
589 else if (GET_BE_WORD(cf1
->ClassFormat
) == 2)
591 const OT_ClassDefFormat2
*cf2
= table
;
593 top
= GET_BE_WORD(cf2
->ClassRangeCount
);
594 for (i
= 0; i
< top
; i
++)
596 if (glyph
>= GET_BE_WORD(cf2
->ClassRangeRecord
[i
].Start
) &&
597 glyph
<= GET_BE_WORD(cf2
->ClassRangeRecord
[i
].End
))
599 class = GET_BE_WORD(cf2
->ClassRangeRecord
[i
].Class
);
605 ERR("Unknown Class Format %i\n",GET_BE_WORD(cf1
->ClassFormat
));
610 void OpenType_GDEF_UpdateGlyphProps(ScriptCache
*psc
, const WORD
*pwGlyphs
, const WORD cGlyphs
, WORD
* pwLogClust
, const WORD cChars
, SCRIPT_GLYPHPROP
*pGlyphProp
)
613 void *glyph_class_table
= NULL
;
617 const GDEF_Header
*header
= psc
->GDEF_Table
;
618 WORD offset
= GET_BE_WORD( header
->GlyphClassDef
);
620 glyph_class_table
= (BYTE
*)psc
->GDEF_Table
+ offset
;
623 for (i
= 0; i
< cGlyphs
; i
++)
629 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
632 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
636 class = OT_get_glyph_class( glyph_class_table
, pwGlyphs
[i
] );
642 pGlyphProp
[i
].sva
.fClusterStart
= 1;
643 pGlyphProp
[i
].sva
.fDiacritic
= 0;
644 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
647 pGlyphProp
[i
].sva
.fClusterStart
= 1;
648 pGlyphProp
[i
].sva
.fDiacritic
= 0;
649 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
652 pGlyphProp
[i
].sva
.fClusterStart
= 0;
653 pGlyphProp
[i
].sva
.fDiacritic
= 1;
654 pGlyphProp
[i
].sva
.fZeroWidth
= 1;
657 pGlyphProp
[i
].sva
.fClusterStart
= 0;
658 pGlyphProp
[i
].sva
.fDiacritic
= 0;
659 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
662 ERR("Unknown glyph class %i\n",class);
663 pGlyphProp
[i
].sva
.fClusterStart
= 1;
664 pGlyphProp
[i
].sva
.fDiacritic
= 0;
665 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
669 pGlyphProp
[i
].sva
.fClusterStart
= 0;
676 static INT
GSUB_apply_lookup(const OT_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
);
678 static INT
GSUB_is_glyph_covered(LPCVOID table
, UINT glyph
)
680 const OT_CoverageFormat1
* cf1
;
684 if (GET_BE_WORD(cf1
->CoverageFormat
) == 1)
686 int count
= GET_BE_WORD(cf1
->GlyphCount
);
688 TRACE("Coverage Format 1, %i glyphs\n",count
);
689 for (i
= 0; i
< count
; i
++)
690 if (glyph
== GET_BE_WORD(cf1
->GlyphArray
[i
]))
694 else if (GET_BE_WORD(cf1
->CoverageFormat
) == 2)
696 const OT_CoverageFormat2
* cf2
;
699 cf2
= (const OT_CoverageFormat2
*)cf1
;
701 count
= GET_BE_WORD(cf2
->RangeCount
);
702 TRACE("Coverage Format 2, %i ranges\n",count
);
703 for (i
= 0; i
< count
; i
++)
705 if (glyph
< GET_BE_WORD(cf2
->RangeRecord
[i
].Start
))
707 if ((glyph
>= GET_BE_WORD(cf2
->RangeRecord
[i
].Start
)) &&
708 (glyph
<= GET_BE_WORD(cf2
->RangeRecord
[i
].End
)))
710 return (GET_BE_WORD(cf2
->RangeRecord
[i
].StartCoverageIndex
) +
711 glyph
- GET_BE_WORD(cf2
->RangeRecord
[i
].Start
));
717 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1
->CoverageFormat
));
722 static INT
GSUB_apply_SingleSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
725 TRACE("Single Substitution Subtable\n");
727 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
730 const GSUB_SingleSubstFormat1
*ssf1
;
731 offset
= GET_BE_WORD(look
->SubTable
[j
]);
732 ssf1
= (const GSUB_SingleSubstFormat1
*)((const BYTE
*)look
+offset
);
733 if (GET_BE_WORD(ssf1
->SubstFormat
) == 1)
735 int offset
= GET_BE_WORD(ssf1
->Coverage
);
736 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1
->DeltaGlyphID
));
737 if (GSUB_is_glyph_covered((const BYTE
*)ssf1
+offset
, glyphs
[glyph_index
]) != -1)
739 TRACE(" Glyph 0x%x ->",glyphs
[glyph_index
]);
740 glyphs
[glyph_index
] = glyphs
[glyph_index
] + GET_BE_WORD(ssf1
->DeltaGlyphID
);
741 TRACE(" 0x%x\n",glyphs
[glyph_index
]);
742 return glyph_index
+ write_dir
;
747 const GSUB_SingleSubstFormat2
*ssf2
;
751 ssf2
= (const GSUB_SingleSubstFormat2
*)ssf1
;
752 offset
= GET_BE_WORD(ssf1
->Coverage
);
753 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2
->GlyphCount
));
754 index
= GSUB_is_glyph_covered((const BYTE
*)ssf2
+offset
, glyphs
[glyph_index
]);
755 TRACE(" Coverage index %i\n",index
);
758 if (glyphs
[glyph_index
] == GET_BE_WORD(ssf2
->Substitute
[index
]))
759 return GSUB_E_NOGLYPH
;
761 TRACE(" Glyph is 0x%x ->",glyphs
[glyph_index
]);
762 glyphs
[glyph_index
] = GET_BE_WORD(ssf2
->Substitute
[index
]);
763 TRACE("0x%x\n",glyphs
[glyph_index
]);
764 return glyph_index
+ write_dir
;
768 return GSUB_E_NOGLYPH
;
771 static INT
GSUB_apply_MultipleSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
774 TRACE("Multiple Substitution Subtable\n");
776 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
779 const GSUB_MultipleSubstFormat1
*msf1
;
780 offset
= GET_BE_WORD(look
->SubTable
[j
]);
781 msf1
= (const GSUB_MultipleSubstFormat1
*)((const BYTE
*)look
+offset
);
783 offset
= GET_BE_WORD(msf1
->Coverage
);
784 index
= GSUB_is_glyph_covered((const BYTE
*)msf1
+offset
, glyphs
[glyph_index
]);
787 const GSUB_Sequence
*seq
;
790 offset
= GET_BE_WORD(msf1
->Sequence
[index
]);
791 seq
= (const GSUB_Sequence
*)((const BYTE
*)msf1
+offset
);
792 sub_count
= GET_BE_WORD(seq
->GlyphCount
);
793 TRACE(" Glyph 0x%x (+%i)->",glyphs
[glyph_index
],(sub_count
-1));
795 for (j
= (*glyph_count
)+(sub_count
-1); j
> glyph_index
; j
--)
796 glyphs
[j
] =glyphs
[j
-(sub_count
-1)];
798 for (j
= 0; j
< sub_count
; j
++)
800 glyphs
[glyph_index
+ (sub_count
-1) - j
] = GET_BE_WORD(seq
->Substitute
[j
]);
802 glyphs
[glyph_index
+ j
] = GET_BE_WORD(seq
->Substitute
[j
]);
804 *glyph_count
= *glyph_count
+ (sub_count
- 1);
806 if (TRACE_ON(uniscribe
))
808 for (j
= 0; j
< sub_count
; j
++)
809 TRACE(" 0x%x",glyphs
[glyph_index
+j
]);
813 return glyph_index
+ (sub_count
* write_dir
);
816 return GSUB_E_NOGLYPH
;
819 static INT
GSUB_apply_AlternateSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
822 TRACE("Alternate Substitution Subtable\n");
824 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
827 const GSUB_AlternateSubstFormat1
*asf1
;
830 offset
= GET_BE_WORD(look
->SubTable
[j
]);
831 asf1
= (const GSUB_AlternateSubstFormat1
*)((const BYTE
*)look
+offset
);
832 offset
= GET_BE_WORD(asf1
->Coverage
);
834 index
= GSUB_is_glyph_covered((const BYTE
*)asf1
+offset
, glyphs
[glyph_index
]);
837 const GSUB_AlternateSet
*as
;
838 offset
= GET_BE_WORD(asf1
->AlternateSet
[index
]);
839 as
= (const GSUB_AlternateSet
*)((const BYTE
*)asf1
+offset
);
840 FIXME("%i alternates, picking index 0\n",GET_BE_WORD(as
->GlyphCount
));
841 if (glyphs
[glyph_index
] == GET_BE_WORD(as
->Alternate
[0]))
842 return GSUB_E_NOGLYPH
;
844 TRACE(" Glyph 0x%x ->",glyphs
[glyph_index
]);
845 glyphs
[glyph_index
] = GET_BE_WORD(as
->Alternate
[0]);
846 TRACE(" 0x%x\n",glyphs
[glyph_index
]);
847 return glyph_index
+ write_dir
;
850 return GSUB_E_NOGLYPH
;
853 static INT
GSUB_apply_LigatureSubst(const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
857 TRACE("Ligature Substitution Subtable\n");
858 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
860 const GSUB_LigatureSubstFormat1
*lsf1
;
863 offset
= GET_BE_WORD(look
->SubTable
[j
]);
864 lsf1
= (const GSUB_LigatureSubstFormat1
*)((const BYTE
*)look
+offset
);
865 offset
= GET_BE_WORD(lsf1
->Coverage
);
866 index
= GSUB_is_glyph_covered((const BYTE
*)lsf1
+offset
, glyphs
[glyph_index
]);
867 TRACE(" Coverage index %i\n",index
);
870 const GSUB_LigatureSet
*ls
;
873 offset
= GET_BE_WORD(lsf1
->LigatureSet
[index
]);
874 ls
= (const GSUB_LigatureSet
*)((const BYTE
*)lsf1
+offset
);
875 count
= GET_BE_WORD(ls
->LigatureCount
);
876 TRACE(" LigatureSet has %i members\n",count
);
877 for (k
= 0; k
< count
; k
++)
879 const GSUB_Ligature
*lig
;
880 int CompCount
,l
,CompIndex
;
882 offset
= GET_BE_WORD(ls
->Ligature
[k
]);
883 lig
= (const GSUB_Ligature
*)((const BYTE
*)ls
+offset
);
884 CompCount
= GET_BE_WORD(lig
->CompCount
) - 1;
885 CompIndex
= glyph_index
+write_dir
;
886 for (l
= 0; l
< CompCount
&& CompIndex
>= 0 && CompIndex
< *glyph_count
; l
++)
889 CompGlyph
= GET_BE_WORD(lig
->Component
[l
]);
890 if (CompGlyph
!= glyphs
[CompIndex
])
892 CompIndex
+= write_dir
;
896 int replaceIdx
= glyph_index
;
898 replaceIdx
= glyph_index
- CompCount
;
900 TRACE(" Glyph is 0x%x (+%i) ->",glyphs
[glyph_index
],CompCount
);
901 glyphs
[replaceIdx
] = GET_BE_WORD(lig
->LigGlyph
);
902 TRACE("0x%x\n",glyphs
[replaceIdx
]);
906 for (j
= replaceIdx
+ 1; j
< *glyph_count
; j
++)
907 glyphs
[j
] =glyphs
[j
+CompCount
];
908 *glyph_count
= *glyph_count
- CompCount
;
910 return replaceIdx
+ write_dir
;
915 return GSUB_E_NOGLYPH
;
918 static INT
GSUB_apply_ChainContextSubst(const OT_LookupList
* lookup
, const OT_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
923 TRACE("Chaining Contextual Substitution Subtable\n");
924 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
) && !done
; j
++)
926 const GSUB_ChainContextSubstFormat1
*ccsf1
;
928 int dirLookahead
= write_dir
;
929 int dirBacktrack
= -1 * write_dir
;
931 offset
= GET_BE_WORD(look
->SubTable
[j
]);
932 ccsf1
= (const GSUB_ChainContextSubstFormat1
*)((const BYTE
*)look
+offset
);
933 if (GET_BE_WORD(ccsf1
->SubstFormat
) == 1)
935 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
938 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 2)
940 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
943 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 3)
947 const GSUB_ChainContextSubstFormat3_1
*ccsf3_1
;
948 const GSUB_ChainContextSubstFormat3_2
*ccsf3_2
;
949 const GSUB_ChainContextSubstFormat3_3
*ccsf3_3
;
950 const GSUB_ChainContextSubstFormat3_4
*ccsf3_4
;
951 int newIndex
= glyph_index
;
953 ccsf3_1
= (const GSUB_ChainContextSubstFormat3_1
*)ccsf1
;
955 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
957 for (k
= 0; k
< GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
); k
++)
959 offset
= GET_BE_WORD(ccsf3_1
->Coverage
[k
]);
960 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (dirBacktrack
* (k
+1))]) == -1)
963 if (k
!= GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
))
965 TRACE("Matched Backtrack\n");
967 ccsf3_2
= (const GSUB_ChainContextSubstFormat3_2
*)((BYTE
*)ccsf1
+
968 FIELD_OFFSET(GSUB_ChainContextSubstFormat3_1
, Coverage
[GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
)]));
970 indexGlyphs
= GET_BE_WORD(ccsf3_2
->InputGlyphCount
);
971 for (k
= 0; k
< indexGlyphs
; k
++)
973 offset
= GET_BE_WORD(ccsf3_2
->Coverage
[k
]);
974 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (write_dir
* k
)]) == -1)
977 if (k
!= indexGlyphs
)
979 TRACE("Matched IndexGlyphs\n");
981 ccsf3_3
= (const GSUB_ChainContextSubstFormat3_3
*)((BYTE
*)ccsf3_2
+
982 FIELD_OFFSET(GSUB_ChainContextSubstFormat3_2
, Coverage
[GET_BE_WORD(ccsf3_2
->InputGlyphCount
)]));
984 for (k
= 0; k
< GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
); k
++)
986 offset
= GET_BE_WORD(ccsf3_3
->Coverage
[k
]);
987 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (dirLookahead
* (indexGlyphs
+ k
))]) == -1)
990 if (k
!= GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
))
992 TRACE("Matched LookAhead\n");
994 ccsf3_4
= (const GSUB_ChainContextSubstFormat3_4
*)((BYTE
*)ccsf3_3
+
995 FIELD_OFFSET(GSUB_ChainContextSubstFormat3_3
, Coverage
[GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
)]));
997 if (GET_BE_WORD(ccsf3_4
->SubstCount
))
999 for (k
= 0; k
< GET_BE_WORD(ccsf3_4
->SubstCount
); k
++)
1001 int lookupIndex
= GET_BE_WORD(ccsf3_4
->SubstLookupRecord
[k
].LookupListIndex
);
1002 int SequenceIndex
= GET_BE_WORD(ccsf3_4
->SubstLookupRecord
[k
].SequenceIndex
) * write_dir
;
1004 TRACE("SUBST: %i -> %i %i\n",k
, SequenceIndex
, lookupIndex
);
1005 newIndex
= GSUB_apply_lookup(lookup
, lookupIndex
, glyphs
, glyph_index
+ SequenceIndex
, write_dir
, glyph_count
);
1008 ERR("Chain failed to generate a glyph\n");
1014 else return GSUB_E_NOGLYPH
;
1020 static INT
GSUB_apply_lookup(const OT_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
1023 const OT_LookupTable
*look
;
1025 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
1026 look
= (const OT_LookupTable
*)((const BYTE
*)lookup
+ offset
);
1027 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look
->LookupType
),GET_BE_WORD(look
->LookupFlag
),GET_BE_WORD(look
->SubTableCount
));
1028 switch(GET_BE_WORD(look
->LookupType
))
1031 return GSUB_apply_SingleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1033 return GSUB_apply_MultipleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1035 return GSUB_apply_AlternateSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1037 return GSUB_apply_LigatureSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1039 return GSUB_apply_ChainContextSubst(lookup
, look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1041 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look
->LookupType
));
1043 return GSUB_E_NOGLYPH
;
1046 INT
OpenType_apply_GSUB_lookup(LPCVOID table
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
1048 const GSUB_Header
*header
= (const GSUB_Header
*)table
;
1049 const OT_LookupList
*lookup
= (const OT_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
1051 return GSUB_apply_lookup(lookup
, lookup_index
, glyphs
, glyph_index
, write_dir
, glyph_count
);
1057 static INT
GPOS_apply_lookup(ScriptCache
*psc
, LPOUTLINETEXTMETRICW lpotm
, LPLOGFONTW lplogfont
, const SCRIPT_ANALYSIS
*analysis
, INT
* piAdvance
,
1058 const OT_LookupList
* lookup
, INT lookup_index
, const WORD
*glyphs
, INT glyph_index
, INT glyph_count
, GOFFSET
*pGoffset
);
1060 static INT
GPOS_get_device_table_value(const OT_DeviceTable
*DeviceTable
, WORD ppem
)
1062 static const WORD mask
[3] = {3,0xf,0xff};
1063 if (DeviceTable
&& ppem
>= GET_BE_WORD(DeviceTable
->StartSize
) && ppem
<= GET_BE_WORD(DeviceTable
->EndSize
))
1065 int format
= GET_BE_WORD(DeviceTable
->DeltaFormat
);
1066 int index
= ppem
- GET_BE_WORD(DeviceTable
->StartSize
);
1068 TRACE("device table, format %i, index %i\n",format
, index
);
1069 index
= index
<< format
;
1070 value
= (DeviceTable
->DeltaValue
[index
/sizeof(WORD
)] << (index
%sizeof(WORD
)))&mask
[format
-1];
1071 TRACE("offset %i, value %i\n",index
, value
);
1072 if (value
> mask
[format
-1]/2)
1073 value
= -1 * ((mask
[format
-1]+1) - value
);
1079 static VOID
GPOS_get_anchor_values(LPCVOID table
, LPPOINT pt
, WORD ppem
)
1081 const GPOS_AnchorFormat1
* anchor1
= (const GPOS_AnchorFormat1
*)table
;
1083 switch (GET_BE_WORD(anchor1
->AnchorFormat
))
1087 TRACE("Anchor Format 1\n");
1088 pt
->x
= (short)GET_BE_WORD(anchor1
->XCoordinate
);
1089 pt
->y
= (short)GET_BE_WORD(anchor1
->YCoordinate
);
1094 const GPOS_AnchorFormat2
* anchor2
= (const GPOS_AnchorFormat2
*)table
;
1095 TRACE("Anchor Format 2\n");
1096 pt
->x
= (short)GET_BE_WORD(anchor2
->XCoordinate
);
1097 pt
->y
= (short)GET_BE_WORD(anchor2
->YCoordinate
);
1103 const GPOS_AnchorFormat3
* anchor3
= (const GPOS_AnchorFormat3
*)table
;
1104 TRACE("Anchor Format 3\n");
1105 pt
->x
= (short)GET_BE_WORD(anchor3
->XCoordinate
);
1106 pt
->y
= (short)GET_BE_WORD(anchor3
->YCoordinate
);
1107 offset
= GET_BE_WORD(anchor3
->XDeviceTable
);
1108 TRACE("ppem %i\n",ppem
);
1111 const OT_DeviceTable
* DeviceTableX
= NULL
;
1112 DeviceTableX
= (const OT_DeviceTable
*)((const BYTE
*)anchor3
+ offset
);
1113 pt
->x
+= GPOS_get_device_table_value(DeviceTableX
, ppem
);
1115 offset
= GET_BE_WORD(anchor3
->YDeviceTable
);
1118 const OT_DeviceTable
* DeviceTableY
= NULL
;
1119 DeviceTableY
= (const OT_DeviceTable
*)((const BYTE
*)anchor3
+ offset
);
1120 pt
->y
+= GPOS_get_device_table_value(DeviceTableY
, ppem
);
1125 ERR("Unknown Anchor Format %i\n",GET_BE_WORD(anchor1
->AnchorFormat
));
1131 static void GPOS_convert_design_units_to_device(LPOUTLINETEXTMETRICW lpotm
, LPLOGFONTW lplogfont
, int desX
, int desY
, double *devX
, double *devY
)
1133 int emHeight
= lpotm
->otmTextMetrics
.tmAscent
+ lpotm
->otmTextMetrics
.tmDescent
- lpotm
->otmTextMetrics
.tmInternalLeading
;
1135 TRACE("emHeight %i lfWidth %i\n",emHeight
, lplogfont
->lfWidth
);
1136 *devX
= (desX
* emHeight
) / (double)lpotm
->otmEMSquare
;
1137 *devY
= (desY
* emHeight
) / (double)lpotm
->otmEMSquare
;
1138 if (lplogfont
->lfWidth
)
1139 FIXME("Font with lfWidth set no handled properly\n");
1142 static INT
GPOS_get_value_record(WORD ValueFormat
, const WORD data
[], GPOS_ValueRecord
*record
)
1145 if (ValueFormat
& 0x0001) { if (data
) record
->XPlacement
= GET_BE_WORD(data
[offset
]); offset
++; }
1146 if (ValueFormat
& 0x0002) { if (data
) record
->YPlacement
= GET_BE_WORD(data
[offset
]); offset
++; }
1147 if (ValueFormat
& 0x0004) { if (data
) record
->XAdvance
= GET_BE_WORD(data
[offset
]); offset
++; }
1148 if (ValueFormat
& 0x0008) { if (data
) record
->YAdvance
= GET_BE_WORD(data
[offset
]); offset
++; }
1149 if (ValueFormat
& 0x0010) { if (data
) record
->XPlaDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1150 if (ValueFormat
& 0x0020) { if (data
) record
->YPlaDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1151 if (ValueFormat
& 0x0040) { if (data
) record
->XAdvDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1152 if (ValueFormat
& 0x0080) { if (data
) record
->YAdvDevice
= GET_BE_WORD(data
[offset
]); offset
++; }
1156 static VOID
GPOS_get_value_record_offsets(const BYTE
* head
, GPOS_ValueRecord
*ValueRecord
, WORD ValueFormat
, INT ppem
, LPPOINT ptPlacement
, LPPOINT ptAdvance
)
1158 if (ValueFormat
& 0x0001) ptPlacement
->x
+= (short)ValueRecord
->XPlacement
;
1159 if (ValueFormat
& 0x0002) ptPlacement
->y
+= (short)ValueRecord
->YPlacement
;
1160 if (ValueFormat
& 0x0004) ptAdvance
->x
+= (short)ValueRecord
->XAdvance
;
1161 if (ValueFormat
& 0x0008) ptAdvance
->y
+= (short)ValueRecord
->YAdvance
;
1162 if (ValueFormat
& 0x0010) ptPlacement
->x
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->XPlaDevice
), ppem
);
1163 if (ValueFormat
& 0x0020) ptPlacement
->y
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->YPlaDevice
), ppem
);
1164 if (ValueFormat
& 0x0040) ptAdvance
->x
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->XAdvDevice
), ppem
);
1165 if (ValueFormat
& 0x0080) ptAdvance
->y
+= GPOS_get_device_table_value((const OT_DeviceTable
*)(head
+ ValueRecord
->YAdvDevice
), ppem
);
1166 if (ValueFormat
& 0xFF00) FIXME("Unhandled Value Format %x\n",ValueFormat
&0xFF00);
1169 static VOID
GPOS_apply_SingleAdjustment(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
, const WORD
*glyphs
, INT glyph_index
,
1170 INT glyph_count
, INT ppem
, LPPOINT ptAdjust
, LPPOINT ptAdvance
)
1174 TRACE("Single Adjustment Positioning Subtable\n");
1176 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1178 const GPOS_SinglePosFormat1
*spf1
;
1179 WORD offset
= GET_BE_WORD(look
->SubTable
[j
]);
1180 spf1
= (const GPOS_SinglePosFormat1
*)((const BYTE
*)look
+offset
);
1181 if (GET_BE_WORD(spf1
->PosFormat
) == 1)
1183 offset
= GET_BE_WORD(spf1
->Coverage
);
1184 if (GSUB_is_glyph_covered((const BYTE
*)spf1
+offset
, glyphs
[glyph_index
]) != -1)
1186 GPOS_ValueRecord ValueRecord
= {0,0,0,0,0,0,0,0};
1187 WORD ValueFormat
= GET_BE_WORD(spf1
->ValueFormat
);
1188 GPOS_get_value_record(ValueFormat
, spf1
->Value
, &ValueRecord
);
1189 GPOS_get_value_record_offsets((const BYTE
*)spf1
, &ValueRecord
, ValueFormat
, ppem
, ptAdjust
, ptAdvance
);
1190 TRACE("Glyph Adjusted by %i,%i\n",ValueRecord
.XPlacement
,ValueRecord
.YPlacement
);
1193 else if (GET_BE_WORD(spf1
->PosFormat
) == 2)
1196 const GPOS_SinglePosFormat2
*spf2
;
1197 spf2
= (const GPOS_SinglePosFormat2
*)spf1
;
1198 offset
= GET_BE_WORD(spf2
->Coverage
);
1199 index
= GSUB_is_glyph_covered((const BYTE
*)spf2
+offset
, glyphs
[glyph_index
]);
1203 GPOS_ValueRecord ValueRecord
= {0,0,0,0,0,0,0,0};
1204 WORD ValueFormat
= GET_BE_WORD(spf2
->ValueFormat
);
1205 size
= GPOS_get_value_record(ValueFormat
, spf2
->Value
, &ValueRecord
);
1208 offset
= size
* index
;
1209 GPOS_get_value_record(ValueFormat
, &spf2
->Value
[offset
], &ValueRecord
);
1211 GPOS_get_value_record_offsets((const BYTE
*)spf2
, &ValueRecord
, ValueFormat
, ppem
, ptAdjust
, ptAdvance
);
1212 TRACE("Glyph Adjusted by %i,%i\n",ValueRecord
.XPlacement
,ValueRecord
.YPlacement
);
1216 FIXME("Single Adjustment Positioning: Format %i Unhandled\n",GET_BE_WORD(spf1
->PosFormat
));
1220 static void apply_pair_value( const void *pos_table
, WORD val_fmt1
, WORD val_fmt2
, const WORD
*pair
,
1221 INT ppem
, POINT
*adjust
, POINT
*advance
)
1223 GPOS_ValueRecord val_rec1
= {0,0,0,0,0,0,0,0};
1224 GPOS_ValueRecord val_rec2
= {0,0,0,0,0,0,0,0};
1227 size
= GPOS_get_value_record( val_fmt1
, pair
, &val_rec1
);
1228 GPOS_get_value_record( val_fmt2
, pair
+ size
, &val_rec2
);
1232 GPOS_get_value_record_offsets( pos_table
, &val_rec1
, val_fmt1
, ppem
, adjust
, advance
);
1233 TRACE( "Glyph 1 resulting cumulative offset is %i,%i design units\n", adjust
[0].x
, adjust
[0].y
);
1234 TRACE( "Glyph 1 resulting cumulative advance is %i,%i design units\n", advance
[0].x
, advance
[0].y
);
1238 GPOS_get_value_record_offsets( pos_table
, &val_rec2
, val_fmt2
, ppem
, adjust
+ 1, advance
+ 1 );
1239 TRACE( "Glyph 2 resulting cumulative offset is %i,%i design units\n", adjust
[1].x
, adjust
[1].y
);
1240 TRACE( "Glyph 2 resulting cumulative advance is %i,%i design units\n", advance
[1].x
, advance
[1].y
);
1244 static INT
GPOS_apply_PairAdjustment(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
, const WORD
*glyphs
, INT glyph_index
,
1245 INT glyph_count
, INT ppem
, LPPOINT ptAdjust
, LPPOINT ptAdvance
)
1248 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1250 if (glyph_index
+ write_dir
< 0 || glyph_index
+ write_dir
>= glyph_count
) return glyph_index
+ 1;
1252 TRACE("Pair Adjustment Positioning Subtable\n");
1254 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1256 const GPOS_PairPosFormat1
*ppf1
;
1257 WORD offset
= GET_BE_WORD(look
->SubTable
[j
]);
1258 ppf1
= (const GPOS_PairPosFormat1
*)((const BYTE
*)look
+offset
);
1259 if (GET_BE_WORD(ppf1
->PosFormat
) == 1)
1262 WORD ValueFormat1
= GET_BE_WORD(ppf1
->ValueFormat1
);
1263 WORD ValueFormat2
= GET_BE_WORD(ppf1
->ValueFormat2
);
1264 INT val_fmt1_size
= GPOS_get_value_record( ValueFormat1
, NULL
, NULL
);
1265 INT val_fmt2_size
= GPOS_get_value_record( ValueFormat2
, NULL
, NULL
);
1266 offset
= GET_BE_WORD(ppf1
->Coverage
);
1267 index
= GSUB_is_glyph_covered((const BYTE
*)ppf1
+offset
, glyphs
[glyph_index
]);
1268 if (index
!= -1 && index
< GET_BE_WORD(ppf1
->PairSetCount
))
1272 const GPOS_PairSet
*ps
;
1273 const GPOS_PairValueRecord
*pair_val_rec
;
1274 offset
= GET_BE_WORD(ppf1
->PairSetOffset
[index
]);
1275 ps
= (const GPOS_PairSet
*)((const BYTE
*)ppf1
+offset
);
1276 pair_count
= GET_BE_WORD(ps
->PairValueCount
);
1277 pair_val_rec
= ps
->PairValueRecord
;
1278 for (k
= 0; k
< pair_count
; k
++)
1280 WORD second_glyph
= GET_BE_WORD(pair_val_rec
->SecondGlyph
);
1281 if (glyphs
[glyph_index
+write_dir
] == second_glyph
)
1284 TRACE("Format 1: Found Pair %x,%x\n",glyphs
[glyph_index
],glyphs
[glyph_index
+write_dir
]);
1285 apply_pair_value( ppf1
, ValueFormat1
, ValueFormat2
, pair_val_rec
->Value1
, ppem
, ptAdjust
, ptAdvance
);
1286 if (ValueFormat2
) next
++;
1287 return glyph_index
+ next
;
1289 pair_val_rec
= (const GPOS_PairValueRecord
*)(pair_val_rec
->Value1
+ val_fmt1_size
+ val_fmt2_size
);
1293 else if (GET_BE_WORD(ppf1
->PosFormat
) == 2)
1295 const GPOS_PairPosFormat2
*ppf2
= (const GPOS_PairPosFormat2
*)((const BYTE
*)look
+ offset
);
1297 WORD ValueFormat1
= GET_BE_WORD( ppf2
->ValueFormat1
);
1298 WORD ValueFormat2
= GET_BE_WORD( ppf2
->ValueFormat2
);
1299 INT val_fmt1_size
= GPOS_get_value_record( ValueFormat1
, NULL
, NULL
);
1300 INT val_fmt2_size
= GPOS_get_value_record( ValueFormat2
, NULL
, NULL
);
1301 WORD class1_count
= GET_BE_WORD( ppf2
->Class1Count
);
1302 WORD class2_count
= GET_BE_WORD( ppf2
->Class2Count
);
1304 offset
= GET_BE_WORD( ppf2
->Coverage
);
1305 index
= GSUB_is_glyph_covered( (const BYTE
*)ppf2
+ offset
, glyphs
[glyph_index
] );
1308 WORD class1
, class2
;
1309 class1
= OT_get_glyph_class( (const BYTE
*)ppf2
+ GET_BE_WORD(ppf2
->ClassDef1
), glyphs
[glyph_index
] );
1310 class2
= OT_get_glyph_class( (const BYTE
*)ppf2
+ GET_BE_WORD(ppf2
->ClassDef2
), glyphs
[glyph_index
+ write_dir
] );
1311 if (class1
< class1_count
&& class2
< class2_count
)
1313 const WORD
*pair_val
= ppf2
->Class1Record
+ (class1
* class2_count
+ class2
) * (val_fmt1_size
+ val_fmt2_size
);
1316 TRACE( "Format 2: Found Pair %x,%x\n", glyphs
[glyph_index
], glyphs
[glyph_index
+ write_dir
] );
1318 apply_pair_value( ppf2
, ValueFormat1
, ValueFormat2
, pair_val
, ppem
, ptAdjust
, ptAdvance
);
1319 if (ValueFormat2
) next
++;
1320 return glyph_index
+ next
;
1325 FIXME("Pair Adjustment Positioning: Format %i Unhandled\n",GET_BE_WORD(ppf1
->PosFormat
));
1327 return glyph_index
+1;
1330 static VOID
GPOS_apply_CursiveAttachment(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
, const WORD
*glyphs
, INT glyph_index
,
1331 INT glyph_count
, INT ppem
, LPPOINT pt
)
1334 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1336 if (glyph_index
+ write_dir
< 0 || glyph_index
+ write_dir
>= glyph_count
) return;
1338 TRACE("Cursive Attachment Positioning Subtable\n");
1340 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1342 const GPOS_CursivePosFormat1
*cpf1
;
1343 WORD offset
= GET_BE_WORD(look
->SubTable
[j
]);
1344 cpf1
= (const GPOS_CursivePosFormat1
*)((const BYTE
*)look
+offset
);
1345 if (GET_BE_WORD(cpf1
->PosFormat
) == 1)
1347 int index_exit
, index_entry
;
1348 offset
= GET_BE_WORD( cpf1
->Coverage
);
1349 index_exit
= GSUB_is_glyph_covered((const BYTE
*)cpf1
+offset
, glyphs
[glyph_index
]);
1350 if (index_exit
!= -1 && cpf1
->EntryExitRecord
[index_exit
].ExitAnchor
!= 0)
1352 index_entry
= GSUB_is_glyph_covered((const BYTE
*)cpf1
+offset
, glyphs
[glyph_index
+write_dir
]);
1353 if (index_entry
!= -1 && cpf1
->EntryExitRecord
[index_entry
].EntryAnchor
!= 0)
1355 POINT exit_pt
, entry_pt
;
1356 offset
= GET_BE_WORD(cpf1
->EntryExitRecord
[index_exit
].ExitAnchor
);
1357 GPOS_get_anchor_values((const BYTE
*)cpf1
+ offset
, &exit_pt
, ppem
);
1358 offset
= GET_BE_WORD(cpf1
->EntryExitRecord
[index_entry
].EntryAnchor
);
1359 GPOS_get_anchor_values((const BYTE
*)cpf1
+ offset
, &entry_pt
, ppem
);
1360 TRACE("Found linkage %x[%i,%i] %x[%i,%i]\n",glyphs
[glyph_index
], exit_pt
.x
,exit_pt
.y
, glyphs
[glyph_index
+write_dir
], entry_pt
.x
, entry_pt
.y
);
1361 pt
->x
= entry_pt
.x
- exit_pt
.x
;
1362 pt
->y
= entry_pt
.y
- exit_pt
.y
;
1368 FIXME("Cursive Attachment Positioning: Format %i Unhandled\n",GET_BE_WORD(cpf1
->PosFormat
));
1373 static int GPOS_apply_MarkToBase(ScriptCache
*psc
, const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
, const WORD
*glyphs
, INT glyph_index
, INT glyph_count
, INT ppem
, LPPOINT pt
)
1376 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1377 void *glyph_class_table
= NULL
;
1380 if (psc
->GDEF_Table
)
1382 const GDEF_Header
*header
= psc
->GDEF_Table
;
1383 WORD offset
= GET_BE_WORD( header
->GlyphClassDef
);
1385 glyph_class_table
= (BYTE
*)psc
->GDEF_Table
+ offset
;
1388 TRACE("MarkToBase Attachment Positioning Subtable\n");
1390 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1393 const GPOS_MarkBasePosFormat1
*mbpf1
;
1394 offset
= GET_BE_WORD(look
->SubTable
[j
]);
1395 mbpf1
= (const GPOS_MarkBasePosFormat1
*)((const BYTE
*)look
+offset
);
1396 if (GET_BE_WORD(mbpf1
->PosFormat
) == 1)
1398 int offset
= GET_BE_WORD(mbpf1
->MarkCoverage
);
1400 mark_index
= GSUB_is_glyph_covered((const BYTE
*)mbpf1
+offset
, glyphs
[glyph_index
]);
1401 if (mark_index
!= -1)
1404 int base_glyph
= glyph_index
- write_dir
;
1406 if (glyph_class_table
)
1408 while (OT_get_glyph_class(glyph_class_table
, glyphs
[base_glyph
]) == MarkGlyph
&& base_glyph
> 0 && base_glyph
< glyph_count
)
1409 base_glyph
-= write_dir
;
1412 offset
= GET_BE_WORD(mbpf1
->BaseCoverage
);
1413 base_index
= GSUB_is_glyph_covered((const BYTE
*)mbpf1
+offset
, glyphs
[base_glyph
]);
1414 if (base_index
!= -1)
1416 const GPOS_MarkArray
*ma
;
1417 const GPOS_MarkRecord
*mr
;
1418 const GPOS_BaseArray
*ba
;
1419 const GPOS_BaseRecord
*br
;
1421 int class_count
= GET_BE_WORD(mbpf1
->ClassCount
);
1422 int baserecord_size
;
1425 TRACE("Mark %x(%i) and base %x(%i)\n",glyphs
[glyph_index
], mark_index
, glyphs
[base_glyph
], base_index
);
1426 offset
= GET_BE_WORD(mbpf1
->MarkArray
);
1427 ma
= (const GPOS_MarkArray
*)((const BYTE
*)mbpf1
+ offset
);
1428 if (mark_index
> GET_BE_WORD(ma
->MarkCount
))
1430 ERR("Mark index exeeded mark count\n");
1433 mr
= &ma
->MarkRecord
[mark_index
];
1434 mark_class
= GET_BE_WORD(mr
->Class
);
1435 TRACE("Mark Class %i total classes %i\n",mark_class
,class_count
);
1436 offset
= GET_BE_WORD(mbpf1
->BaseArray
);
1437 ba
= (const GPOS_BaseArray
*)((const BYTE
*)mbpf1
+ offset
);
1438 baserecord_size
= class_count
* sizeof(WORD
);
1439 br
= (const GPOS_BaseRecord
*)((const BYTE
*)ba
+ sizeof(WORD
) + (baserecord_size
* base_index
));
1440 offset
= GET_BE_WORD(br
->BaseAnchor
[mark_class
]);
1441 GPOS_get_anchor_values((const BYTE
*)ba
+ offset
, &base_pt
, ppem
);
1442 offset
= GET_BE_WORD(mr
->MarkAnchor
);
1443 GPOS_get_anchor_values((const BYTE
*)ma
+ offset
, &mark_pt
, ppem
);
1444 TRACE("Offset on base is %i,%i design units\n",base_pt
.x
,base_pt
.y
);
1445 TRACE("Offset on mark is %i,%i design units\n",mark_pt
.x
, mark_pt
.y
);
1446 pt
->x
+= base_pt
.x
- mark_pt
.x
;
1447 pt
->y
+= base_pt
.y
- mark_pt
.y
;
1448 TRACE("Resulting cumulative offset is %i,%i design units\n",pt
->x
,pt
->y
);
1454 FIXME("Unhandled Mark To Base Format %i\n",GET_BE_WORD(mbpf1
->PosFormat
));
1459 static VOID
GPOS_apply_MarkToLigature(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
, const WORD
*glyphs
, INT glyph_index
,
1460 INT glyph_count
, INT ppem
, LPPOINT pt
)
1463 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1465 TRACE("MarkToLigature Attachment Positioning Subtable\n");
1467 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1470 const GPOS_MarkLigPosFormat1
*mlpf1
;
1471 offset
= GET_BE_WORD(look
->SubTable
[j
]);
1472 mlpf1
= (const GPOS_MarkLigPosFormat1
*)((const BYTE
*)look
+offset
);
1473 if (GET_BE_WORD(mlpf1
->PosFormat
) == 1)
1475 int offset
= GET_BE_WORD(mlpf1
->MarkCoverage
);
1477 mark_index
= GSUB_is_glyph_covered((const BYTE
*)mlpf1
+offset
, glyphs
[glyph_index
]);
1478 if (mark_index
!= -1)
1481 offset
= GET_BE_WORD(mlpf1
->LigatureCoverage
);
1482 ligature_index
= GSUB_is_glyph_covered((const BYTE
*)mlpf1
+offset
, glyphs
[glyph_index
- write_dir
]);
1483 if (ligature_index
!= -1)
1485 const GPOS_MarkArray
*ma
;
1486 const GPOS_MarkRecord
*mr
;
1488 const GPOS_LigatureArray
*la
;
1489 const GPOS_LigatureAttach
*lt
;
1491 int class_count
= GET_BE_WORD(mlpf1
->ClassCount
);
1492 int component_count
;
1498 TRACE("Mark %x(%i) and ligature %x(%i)\n",glyphs
[glyph_index
], mark_index
, glyphs
[glyph_index
- write_dir
], ligature_index
);
1499 offset
= GET_BE_WORD(mlpf1
->MarkArray
);
1500 ma
= (const GPOS_MarkArray
*)((const BYTE
*)mlpf1
+ offset
);
1501 if (mark_index
> GET_BE_WORD(ma
->MarkCount
))
1503 ERR("Mark index exeeded mark count\n");
1506 mr
= &ma
->MarkRecord
[mark_index
];
1507 mark_class
= GET_BE_WORD(mr
->Class
);
1508 TRACE("Mark Class %i total classes %i\n",mark_class
,class_count
);
1509 offset
= GET_BE_WORD(mlpf1
->LigatureArray
);
1510 la
= (const GPOS_LigatureArray
*)((const BYTE
*)mlpf1
+ offset
);
1511 if (ligature_index
> GET_BE_WORD(la
->LigatureCount
))
1513 ERR("Ligature index exeeded ligature count\n");
1516 offset
= GET_BE_WORD(la
->LigatureAttach
[ligature_index
]);
1517 lt
= (const GPOS_LigatureAttach
*)((const BYTE
*)la
+ offset
);
1519 component_count
= GET_BE_WORD(lt
->ComponentCount
);
1520 component_size
= class_count
* sizeof(WORD
);
1522 for (i
= 0; i
< component_count
&& !offset
; i
++)
1525 const GPOS_ComponentRecord
*cr
= (const GPOS_ComponentRecord
*)((const BYTE
*)lt
->ComponentRecord
+ (component_size
* i
));
1526 for (k
= 0; k
< class_count
&& !offset
; k
++)
1527 offset
= GET_BE_WORD(cr
->LigatureAnchor
[k
]);
1528 cr
= (const GPOS_ComponentRecord
*)((const BYTE
*)cr
+ component_size
);
1532 ERR("Failed to find avalible ligature connection point\n");
1536 GPOS_get_anchor_values((const BYTE
*)lt
+ offset
, &ligature_pt
, ppem
);
1537 offset
= GET_BE_WORD(mr
->MarkAnchor
);
1538 GPOS_get_anchor_values((const BYTE
*)ma
+ offset
, &mark_pt
, ppem
);
1539 TRACE("Offset on ligature is %i,%i design units\n",ligature_pt
.x
,ligature_pt
.y
);
1540 TRACE("Offset on mark is %i,%i design units\n",mark_pt
.x
, mark_pt
.y
);
1541 pt
->x
+= ligature_pt
.x
- mark_pt
.x
;
1542 pt
->y
+= ligature_pt
.y
- mark_pt
.y
;
1543 TRACE("Resulting cumulative offset is %i,%i design units\n",pt
->x
,pt
->y
);
1548 FIXME("Unhandled Mark To Ligature Format %i\n",GET_BE_WORD(mlpf1
->PosFormat
));
1552 static BOOL
GPOS_apply_MarkToMark(const OT_LookupTable
*look
, const SCRIPT_ANALYSIS
*analysis
, const WORD
*glyphs
, INT glyph_index
,
1553 INT glyph_count
, INT ppem
, LPPOINT pt
)
1557 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1559 TRACE("MarkToMark Attachment Positioning Subtable\n");
1561 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1564 const GPOS_MarkMarkPosFormat1
*mmpf1
;
1565 offset
= GET_BE_WORD(look
->SubTable
[j
]);
1566 mmpf1
= (const GPOS_MarkMarkPosFormat1
*)((const BYTE
*)look
+offset
);
1567 if (GET_BE_WORD(mmpf1
->PosFormat
) == 1)
1569 int offset
= GET_BE_WORD(mmpf1
->Mark1Coverage
);
1571 mark_index
= GSUB_is_glyph_covered((const BYTE
*)mmpf1
+offset
, glyphs
[glyph_index
]);
1572 if (mark_index
!= -1)
1575 offset
= GET_BE_WORD(mmpf1
->Mark2Coverage
);
1576 mark2_index
= GSUB_is_glyph_covered((const BYTE
*)mmpf1
+offset
, glyphs
[glyph_index
- write_dir
]);
1577 if (mark2_index
!= -1)
1579 const GPOS_MarkArray
*ma
;
1580 const GPOS_MarkRecord
*mr
;
1581 const GPOS_Mark2Array
*m2a
;
1582 const GPOS_Mark2Record
*m2r
;
1584 int class_count
= GET_BE_WORD(mmpf1
->ClassCount
);
1585 int mark2record_size
;
1588 TRACE("Mark %x(%i) and Mark2 %x(%i)\n",glyphs
[glyph_index
], mark_index
, glyphs
[glyph_index
- write_dir
], mark2_index
);
1589 offset
= GET_BE_WORD(mmpf1
->Mark1Array
);
1590 ma
= (const GPOS_MarkArray
*)((const BYTE
*)mmpf1
+ offset
);
1591 if (mark_index
> GET_BE_WORD(ma
->MarkCount
))
1593 ERR("Mark index exeeded mark count\n");
1596 mr
= &ma
->MarkRecord
[mark_index
];
1597 mark_class
= GET_BE_WORD(mr
->Class
);
1598 TRACE("Mark Class %i total classes %i\n",mark_class
,class_count
);
1599 offset
= GET_BE_WORD(mmpf1
->Mark2Array
);
1600 m2a
= (const GPOS_Mark2Array
*)((const BYTE
*)mmpf1
+ offset
);
1601 mark2record_size
= class_count
* sizeof(WORD
);
1602 m2r
= (const GPOS_Mark2Record
*)((const BYTE
*)m2a
+ sizeof(WORD
) + (mark2record_size
* mark2_index
));
1603 offset
= GET_BE_WORD(m2r
->Mark2Anchor
[mark_class
]);
1604 GPOS_get_anchor_values((const BYTE
*)m2a
+ offset
, &mark2_pt
, ppem
);
1605 offset
= GET_BE_WORD(mr
->MarkAnchor
);
1606 GPOS_get_anchor_values((const BYTE
*)ma
+ offset
, &mark_pt
, ppem
);
1607 TRACE("Offset on mark2 is %i,%i design units\n",mark2_pt
.x
,mark2_pt
.y
);
1608 TRACE("Offset on mark is %i,%i design units\n",mark_pt
.x
, mark_pt
.y
);
1609 pt
->x
+= mark2_pt
.x
- mark_pt
.x
;
1610 pt
->y
+= mark2_pt
.y
- mark_pt
.y
;
1611 TRACE("Resulting cumulative offset is %i,%i design units\n",pt
->x
,pt
->y
);
1617 FIXME("Unhandled Mark To Mark Format %i\n",GET_BE_WORD(mmpf1
->PosFormat
));
1622 static INT
GPOS_apply_ChainContextPos(ScriptCache
*psc
, LPOUTLINETEXTMETRICW lpotm
, LPLOGFONTW lplogfont
, const SCRIPT_ANALYSIS
*analysis
, INT
* piAdvance
,
1623 const OT_LookupList
*lookup
, const OT_LookupTable
*look
, const WORD
*glyphs
, INT glyph_index
,
1624 INT glyph_count
, INT ppem
, GOFFSET
*pGoffset
)
1627 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1629 TRACE("Chaining Contextual Positioning Subtable\n");
1631 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
1634 const GPOS_ChainContextPosFormat3_1
*ccpf3
;
1635 int dirLookahead
= write_dir
;
1636 int dirBacktrack
= -1 * write_dir
;
1638 offset
= GET_BE_WORD(look
->SubTable
[j
]);
1639 ccpf3
= (const GPOS_ChainContextPosFormat3_1
*)((const BYTE
*)look
+offset
);
1641 if (GET_BE_WORD(ccpf3
->PosFormat
) == 1)
1643 FIXME(" TODO: subtype 1 (Simple Chaining Context Glyph Positioning)\n");
1646 else if (GET_BE_WORD(ccpf3
->PosFormat
) == 2)
1648 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Positioning)\n");
1651 else if (GET_BE_WORD(ccpf3
->PosFormat
) == 3)
1655 const GPOS_ChainContextPosFormat3_2
*ccpf3_2
;
1656 const GPOS_ChainContextPosFormat3_3
*ccpf3_3
;
1657 const GPOS_ChainContextPosFormat3_4
*ccpf3_4
;
1659 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Positioning)\n");
1661 for (k
= 0; k
< GET_BE_WORD(ccpf3
->BacktrackGlyphCount
); k
++)
1663 offset
= GET_BE_WORD(ccpf3
->Coverage
[k
]);
1664 if (GSUB_is_glyph_covered((const BYTE
*)ccpf3
+offset
, glyphs
[glyph_index
+ (dirBacktrack
* (k
+1))]) == -1)
1667 if (k
!= GET_BE_WORD(ccpf3
->BacktrackGlyphCount
))
1669 TRACE("Matched Backtrack\n");
1671 ccpf3_2
= (const GPOS_ChainContextPosFormat3_2
*)((BYTE
*)ccpf3
+
1672 FIELD_OFFSET(GPOS_ChainContextPosFormat3_1
, Coverage
[GET_BE_WORD(ccpf3
->BacktrackGlyphCount
)]));
1674 indexGlyphs
= GET_BE_WORD(ccpf3_2
->InputGlyphCount
);
1675 for (k
= 0; k
< indexGlyphs
; k
++)
1677 offset
= GET_BE_WORD(ccpf3_2
->Coverage
[k
]);
1678 if (GSUB_is_glyph_covered((const BYTE
*)ccpf3
+offset
, glyphs
[glyph_index
+ (write_dir
* k
)]) == -1)
1681 if (k
!= indexGlyphs
)
1683 TRACE("Matched IndexGlyphs\n");
1685 ccpf3_3
= (const GPOS_ChainContextPosFormat3_3
*)((BYTE
*)ccpf3_2
+
1686 FIELD_OFFSET(GPOS_ChainContextPosFormat3_2
, Coverage
[GET_BE_WORD(ccpf3_2
->InputGlyphCount
)]));
1688 for (k
= 0; k
< GET_BE_WORD(ccpf3_3
->LookaheadGlyphCount
); k
++)
1690 offset
= GET_BE_WORD(ccpf3_3
->Coverage
[k
]);
1691 if (GSUB_is_glyph_covered((const BYTE
*)ccpf3
+offset
, glyphs
[glyph_index
+ (dirLookahead
* (indexGlyphs
+ k
))]) == -1)
1694 if (k
!= GET_BE_WORD(ccpf3_3
->LookaheadGlyphCount
))
1696 TRACE("Matched LookAhead\n");
1698 ccpf3_4
= (const GPOS_ChainContextPosFormat3_4
*)((BYTE
*)ccpf3_3
+
1699 FIELD_OFFSET(GPOS_ChainContextPosFormat3_3
, Coverage
[GET_BE_WORD(ccpf3_3
->LookaheadGlyphCount
)]));
1701 if (GET_BE_WORD(ccpf3_4
->PosCount
))
1703 for (k
= 0; k
< GET_BE_WORD(ccpf3_4
->PosCount
); k
++)
1705 int lookupIndex
= GET_BE_WORD(ccpf3_4
->PosLookupRecord
[k
].LookupListIndex
);
1706 int SequenceIndex
= GET_BE_WORD(ccpf3_4
->PosLookupRecord
[k
].SequenceIndex
) * write_dir
;
1708 TRACE("Position: %i -> %i %i\n",k
, SequenceIndex
, lookupIndex
);
1709 GPOS_apply_lookup(psc
, lpotm
, lplogfont
, analysis
, piAdvance
, lookup
, lookupIndex
, glyphs
, glyph_index
+ SequenceIndex
, glyph_count
, pGoffset
);
1711 return glyph_index
+ indexGlyphs
+ GET_BE_WORD(ccpf3_3
->LookaheadGlyphCount
);
1713 else return glyph_index
+ 1;
1716 FIXME("Unhandled Chaining Contextual Positioning Format %i\n",GET_BE_WORD(ccpf3
->PosFormat
));
1718 return glyph_index
+ 1;
1721 static INT
GPOS_apply_lookup(ScriptCache
*psc
, LPOUTLINETEXTMETRICW lpotm
, LPLOGFONTW lplogfont
, const SCRIPT_ANALYSIS
*analysis
, INT
* piAdvance
, const OT_LookupList
* lookup
, INT lookup_index
, const WORD
*glyphs
, INT glyph_index
, INT glyph_count
, GOFFSET
*pGoffset
)
1724 const OT_LookupTable
*look
;
1725 int ppem
= lpotm
->otmTextMetrics
.tmAscent
+ lpotm
->otmTextMetrics
.tmDescent
- lpotm
->otmTextMetrics
.tmInternalLeading
;
1727 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
1728 look
= (const OT_LookupTable
*)((const BYTE
*)lookup
+ offset
);
1729 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look
->LookupType
),GET_BE_WORD(look
->LookupFlag
),GET_BE_WORD(look
->SubTableCount
));
1730 switch(GET_BE_WORD(look
->LookupType
))
1735 POINT adjust
= {0,0};
1736 POINT advance
= {0,0};
1737 GPOS_apply_SingleAdjustment(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &adjust
, &advance
);
1738 if (adjust
.x
|| adjust
.y
)
1740 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, adjust
.x
, adjust
.y
, &devX
, &devY
);
1741 pGoffset
[glyph_index
].du
+= round(devX
);
1742 pGoffset
[glyph_index
].dv
+= round(devY
);
1744 if (advance
.x
|| advance
.y
)
1746 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, advance
.x
, advance
.y
, &devX
, &devY
);
1747 piAdvance
[glyph_index
] += round(devX
);
1749 FIXME("Unhandled adjustment to Y advancement\n");
1755 POINT advance
[2]= {{0,0},{0,0}};
1756 POINT adjust
[2]= {{0,0},{0,0}};
1759 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1760 int offset_sign
= (analysis
->fRTL
&& analysis
->fLogicalOrder
) ? -1 : 1;
1762 index
= GPOS_apply_PairAdjustment(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, adjust
, advance
);
1763 if (adjust
[0].x
|| adjust
[0].y
)
1765 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, adjust
[0].x
, adjust
[0].y
, &devX
, &devY
);
1766 pGoffset
[glyph_index
].du
+= round(devX
) * offset_sign
;
1767 pGoffset
[glyph_index
].dv
+= round(devY
);
1769 if (advance
[0].x
|| advance
[0].y
)
1771 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, advance
[0].x
, advance
[0].y
, &devX
, &devY
);
1772 piAdvance
[glyph_index
] += round(devX
);
1774 if (adjust
[1].x
|| adjust
[1].y
)
1776 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, adjust
[1].x
, adjust
[1].y
, &devX
, &devY
);
1777 pGoffset
[glyph_index
+ write_dir
].du
+= round(devX
) * offset_sign
;
1778 pGoffset
[glyph_index
+ write_dir
].dv
+= round(devY
);
1780 if (advance
[1].x
|| advance
[1].y
)
1782 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, advance
[1].x
, advance
[1].y
, &devX
, &devY
);
1783 piAdvance
[glyph_index
+ write_dir
] += round(devX
);
1791 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1793 GPOS_apply_CursiveAttachment(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &desU
);
1794 if (desU
.x
|| desU
.y
)
1796 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
1797 /* Windows does not appear to apply X offsets here */
1798 pGoffset
[glyph_index
].dv
= round(devY
) + pGoffset
[glyph_index
+write_dir
].dv
;
1806 int base_index
= GPOS_apply_MarkToBase(psc
, look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &desU
);
1807 if (base_index
!= -1)
1809 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
1810 if (!analysis
->fRTL
) pGoffset
[glyph_index
].du
= round(devX
) - piAdvance
[base_index
];
1813 if (analysis
->fLogicalOrder
) devX
*= -1;
1814 pGoffset
[glyph_index
].du
= round(devX
);
1816 pGoffset
[glyph_index
].dv
= round(devY
);
1824 GPOS_apply_MarkToLigature(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &desU
);
1825 if (desU
.x
|| desU
.y
)
1827 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
1828 pGoffset
[glyph_index
].du
= (round(devX
) - piAdvance
[glyph_index
-1]);
1829 pGoffset
[glyph_index
].dv
= round(devY
);
1837 int write_dir
= (analysis
->fRTL
&& !analysis
->fLogicalOrder
) ? -1 : 1;
1838 if (GPOS_apply_MarkToMark(look
, analysis
, glyphs
, glyph_index
, glyph_count
, ppem
, &desU
))
1840 GPOS_convert_design_units_to_device(lpotm
, lplogfont
, desU
.x
, desU
.y
, &devX
, &devY
);
1841 if (analysis
->fRTL
&& analysis
->fLogicalOrder
) devX
*= -1;
1842 pGoffset
[glyph_index
].du
= round(devX
) + pGoffset
[glyph_index
- write_dir
].du
;
1843 pGoffset
[glyph_index
].dv
= round(devY
) + pGoffset
[glyph_index
- write_dir
].dv
;
1849 return GPOS_apply_ChainContextPos(psc
, lpotm
, lplogfont
, analysis
, piAdvance
, lookup
, look
, glyphs
, glyph_index
, glyph_count
, ppem
, pGoffset
);
1852 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look
->LookupType
));
1854 return glyph_index
+1;
1857 INT
OpenType_apply_GPOS_lookup(ScriptCache
*psc
, LPOUTLINETEXTMETRICW lpotm
, LPLOGFONTW lplogfont
, const SCRIPT_ANALYSIS
*analysis
, INT
* piAdvance
, INT lookup_index
, const WORD
*glyphs
, INT glyph_index
, INT glyph_count
, GOFFSET
*pGoffset
)
1859 const GPOS_Header
*header
= (const GPOS_Header
*)psc
->GPOS_Table
;
1860 const OT_LookupList
*lookup
= (const OT_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
1862 return GPOS_apply_lookup(psc
, lpotm
, lplogfont
, analysis
, piAdvance
, lookup
, lookup_index
, glyphs
, glyph_index
, glyph_count
, pGoffset
);
1865 static void GSUB_initialize_script_cache(ScriptCache
*psc
)
1869 if (psc
->GSUB_Table
)
1871 const OT_ScriptList
*script
;
1872 const GSUB_Header
* header
= (const GSUB_Header
*)psc
->GSUB_Table
;
1873 script
= (const OT_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
1874 psc
->script_count
= GET_BE_WORD(script
->ScriptCount
);
1875 TRACE("initializing %i scripts in this font\n",psc
->script_count
);
1876 if (psc
->script_count
)
1878 psc
->scripts
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LoadedScript
) * psc
->script_count
);
1879 for (i
= 0; i
< psc
->script_count
; i
++)
1881 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
1882 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]);
1883 psc
->scripts
[i
].gsub_table
= ((const BYTE
*)script
+ offset
);
1889 static void GPOS_expand_script_cache(ScriptCache
*psc
)
1892 const OT_ScriptList
*script
;
1893 const GPOS_Header
* header
= (const GPOS_Header
*)psc
->GPOS_Table
;
1898 script
= (const OT_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
1899 count
= GET_BE_WORD(script
->ScriptCount
);
1904 if (!psc
->script_count
)
1906 psc
->script_count
= count
;
1907 TRACE("initializing %i scripts in this font\n",psc
->script_count
);
1908 if (psc
->script_count
)
1910 psc
->scripts
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LoadedScript
) * psc
->script_count
);
1911 for (i
= 0; i
< psc
->script_count
; i
++)
1913 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
1914 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]);
1915 psc
->scripts
[i
].gpos_table
= ((const BYTE
*)script
+ offset
);
1921 for (i
= 0; i
< count
; i
++)
1924 int offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
1925 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]);
1926 for (j
= 0; j
< psc
->script_count
; j
++)
1928 if (psc
->scripts
[j
].tag
== tag
)
1930 psc
->scripts
[j
].gpos_table
= ((const BYTE
*)script
+ offset
);
1934 if (j
== psc
->script_count
)
1936 psc
->script_count
++;
1937 psc
->scripts
= HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,psc
->scripts
, sizeof(LoadedScript
) * psc
->script_count
);
1938 psc
->scripts
[j
].tag
= tag
;
1939 psc
->scripts
[j
].gpos_table
= ((const BYTE
*)script
+ offset
);
1945 static void _initialize_script_cache(ScriptCache
*psc
)
1947 if (!psc
->scripts_initialized
)
1949 GSUB_initialize_script_cache(psc
);
1950 GPOS_expand_script_cache(psc
);
1951 psc
->scripts_initialized
= TRUE
;
1955 HRESULT
OpenType_GetFontScriptTags(ScriptCache
*psc
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pScriptTags
, int *pcTags
)
1960 _initialize_script_cache(psc
);
1962 *pcTags
= psc
->script_count
;
1964 if (!searchingFor
&& cMaxTags
< *pcTags
)
1966 else if (searchingFor
)
1967 rc
= USP_E_SCRIPT_NOT_IN_FONT
;
1969 for (i
= 0; i
< psc
->script_count
; i
++)
1972 pScriptTags
[i
] = psc
->scripts
[i
].tag
;
1976 if (searchingFor
== psc
->scripts
[i
].tag
)
1978 pScriptTags
[0] = psc
->scripts
[i
].tag
;
1988 static void GSUB_initialize_language_cache(LoadedScript
*script
)
1992 if (script
->gsub_table
)
1995 const OT_Script
* table
= script
->gsub_table
;
1996 script
->language_count
= GET_BE_WORD(table
->LangSysCount
);
1997 offset
= GET_BE_WORD(table
->DefaultLangSys
);
2000 script
->default_language
.tag
= MS_MAKE_TAG('d','f','l','t');
2001 script
->default_language
.gsub_table
= (const BYTE
*)table
+ offset
;
2004 if (script
->language_count
)
2006 TRACE("Deflang %p, LangCount %i\n",script
->default_language
.gsub_table
, script
->language_count
);
2008 script
->languages
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LoadedLanguage
) * script
->language_count
);
2010 for (i
= 0; i
< script
->language_count
; i
++)
2012 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
2013 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]);
2014 script
->languages
[i
].gsub_table
= ((const BYTE
*)table
+ offset
);
2020 static void GPOS_expand_language_cache(LoadedScript
*script
)
2023 const OT_Script
* table
= script
->gpos_table
;
2029 offset
= GET_BE_WORD(table
->DefaultLangSys
);
2031 script
->default_language
.gpos_table
= (const BYTE
*)table
+ offset
;
2033 count
= GET_BE_WORD(table
->LangSysCount
);
2035 TRACE("Deflang %p, LangCount %i\n",script
->default_language
.gpos_table
, count
);
2040 if (!script
->language_count
)
2043 script
->language_count
= count
;
2045 script
->languages
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LoadedLanguage
) * script
->language_count
);
2047 for (i
= 0; i
< script
->language_count
; i
++)
2049 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
2050 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]);
2051 script
->languages
[i
].gpos_table
= ((const BYTE
*)table
+ offset
);
2057 for (i
= 0; i
< count
; i
++)
2059 int offset
= GET_BE_WORD(table
->LangSysRecord
[i
].LangSys
);
2060 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]);
2062 for (j
= 0; j
< script
->language_count
; j
++)
2064 if (script
->languages
[j
].tag
== tag
)
2066 script
->languages
[j
].gpos_table
= ((const BYTE
*)table
+ offset
);
2070 if (j
== script
->language_count
)
2072 script
->language_count
++;
2073 script
->languages
= HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,script
->languages
, sizeof(LoadedLanguage
) * script
->language_count
);
2074 script
->languages
[j
].tag
= tag
;
2075 script
->languages
[j
].gpos_table
= ((const BYTE
*)table
+ offset
);
2081 static void _initialize_language_cache(LoadedScript
*script
)
2083 if (!script
->languages_initialized
)
2085 GSUB_initialize_language_cache(script
);
2086 GPOS_expand_language_cache(script
);
2087 script
->languages_initialized
= TRUE
;
2091 HRESULT
OpenType_GetFontLanguageTags(ScriptCache
*psc
, OPENTYPE_TAG script_tag
, OPENTYPE_TAG searchingFor
, int cMaxTags
, OPENTYPE_TAG
*pLanguageTags
, int *pcTags
)
2095 LoadedScript
*script
= NULL
;
2097 _initialize_script_cache(psc
);
2099 for (i
= 0; i
< psc
->script_count
; i
++)
2101 if (psc
->scripts
[i
].tag
== script_tag
)
2103 script
= &psc
->scripts
[i
];
2109 return E_INVALIDARG
;
2111 _initialize_language_cache(script
);
2113 if (!searchingFor
&& cMaxTags
< script
->language_count
)
2115 else if (searchingFor
)
2118 *pcTags
= script
->language_count
;
2120 for (i
= 0; i
< script
->language_count
; i
++)
2123 pLanguageTags
[i
] = script
->languages
[i
].tag
;
2127 if (searchingFor
== script
->languages
[i
].tag
)
2129 pLanguageTags
[0] = script
->languages
[i
].tag
;
2137 if (script
->default_language
.gsub_table
)
2140 pLanguageTags
[i
] = script
->default_language
.tag
;
2142 if (searchingFor
&& FAILED(rc
))
2144 pLanguageTags
[0] = script
->default_language
.tag
;
2147 *pcTags
= (*pcTags
) + 1;
2154 static void GSUB_initialize_feature_cache(LPCVOID table
, LoadedLanguage
*language
)
2158 if (language
->gsub_table
)
2160 const OT_LangSys
*lang
= language
->gsub_table
;
2161 const GSUB_Header
*header
= (const GSUB_Header
*)table
;
2162 const OT_FeatureList
*feature_list
;
2164 language
->feature_count
= GET_BE_WORD(lang
->FeatureCount
);
2165 TRACE("%i features\n",language
->feature_count
);
2167 if (language
->feature_count
)
2169 language
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(LoadedFeature
)*language
->feature_count
);
2171 feature_list
= (const OT_FeatureList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->FeatureList
));
2173 for (i
= 0; i
< language
->feature_count
; i
++)
2175 const OT_Feature
*feature
;
2177 int index
= GET_BE_WORD(lang
->FeatureIndex
[i
]);
2179 language
->features
[i
].tag
= MS_MAKE_TAG(feature_list
->FeatureRecord
[index
].FeatureTag
[0], feature_list
->FeatureRecord
[index
].FeatureTag
[1], feature_list
->FeatureRecord
[index
].FeatureTag
[2], feature_list
->FeatureRecord
[index
].FeatureTag
[3]);
2180 language
->features
[i
].feature
= ((const BYTE
*)feature_list
+ GET_BE_WORD(feature_list
->FeatureRecord
[index
].Feature
));
2181 feature
= (const OT_Feature
*)language
->features
[i
].feature
;
2182 language
->features
[i
].lookup_count
= GET_BE_WORD(feature
->LookupCount
);
2183 language
->features
[i
].lookups
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
) * language
->features
[i
].lookup_count
);
2184 for (j
= 0; j
< language
->features
[i
].lookup_count
; j
++)
2185 language
->features
[i
].lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
2186 language
->features
[i
].tableType
= FEATURE_GSUB_TABLE
;
2192 static void GPOS_expand_feature_cache(LPCVOID table
, LoadedLanguage
*language
)
2195 const OT_LangSys
*lang
= language
->gpos_table
;
2196 const GPOS_Header
*header
= (const GPOS_Header
*)table
;
2197 const OT_FeatureList
*feature_list
;
2202 count
= GET_BE_WORD(lang
->FeatureCount
);
2203 feature_list
= (const OT_FeatureList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->FeatureList
));
2205 TRACE("%i features\n",count
);
2210 if (!language
->feature_count
)
2212 language
->feature_count
= count
;
2214 if (language
->feature_count
)
2216 language
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(LoadedFeature
)*language
->feature_count
);
2218 for (i
= 0; i
< language
->feature_count
; i
++)
2220 const OT_Feature
*feature
;
2222 int index
= GET_BE_WORD(lang
->FeatureIndex
[i
]);
2224 language
->features
[i
].tag
= MS_MAKE_TAG(feature_list
->FeatureRecord
[index
].FeatureTag
[0], feature_list
->FeatureRecord
[index
].FeatureTag
[1], feature_list
->FeatureRecord
[index
].FeatureTag
[2], feature_list
->FeatureRecord
[index
].FeatureTag
[3]);
2225 language
->features
[i
].feature
= ((const BYTE
*)feature_list
+ GET_BE_WORD(feature_list
->FeatureRecord
[index
].Feature
));
2226 feature
= (const OT_Feature
*)language
->features
[i
].feature
;
2227 language
->features
[i
].lookup_count
= GET_BE_WORD(feature
->LookupCount
);
2228 language
->features
[i
].lookups
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
) * language
->features
[i
].lookup_count
);
2229 for (j
= 0; j
< language
->features
[i
].lookup_count
; j
++)
2230 language
->features
[i
].lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
2231 language
->features
[i
].tableType
= FEATURE_GPOS_TABLE
;
2237 language
->features
= HeapReAlloc(GetProcessHeap(),0,language
->features
, sizeof(LoadedFeature
)*(language
->feature_count
+ count
));
2239 for (i
= 0; i
< count
; i
++)
2241 const OT_Feature
*feature
;
2243 int index
= GET_BE_WORD(lang
->FeatureIndex
[i
]);
2244 int idx
= language
->feature_count
+ i
;
2246 language
->features
[idx
].tag
= MS_MAKE_TAG(feature_list
->FeatureRecord
[index
].FeatureTag
[0], feature_list
->FeatureRecord
[index
].FeatureTag
[1], feature_list
->FeatureRecord
[index
].FeatureTag
[2], feature_list
->FeatureRecord
[index
].FeatureTag
[3]);
2247 language
->features
[idx
].feature
= ((const BYTE
*)feature_list
+ GET_BE_WORD(feature_list
->FeatureRecord
[index
].Feature
));
2248 feature
= (const OT_Feature
*)language
->features
[idx
].feature
;
2249 language
->features
[idx
].lookup_count
= GET_BE_WORD(feature
->LookupCount
);
2250 language
->features
[idx
].lookups
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
) * language
->features
[idx
].lookup_count
);
2251 for (j
= 0; j
< language
->features
[idx
].lookup_count
; j
++)
2252 language
->features
[idx
].lookups
[j
] = GET_BE_WORD(feature
->LookupListIndex
[j
]);
2253 language
->features
[idx
].tableType
= FEATURE_GPOS_TABLE
;
2255 language
->feature_count
+= count
;
2259 static void _initialize_feature_cache(ScriptCache
*psc
, LoadedLanguage
*language
)
2261 if (!language
->features_initialized
)
2263 GSUB_initialize_feature_cache(psc
->GSUB_Table
, language
);
2264 GPOS_expand_feature_cache(psc
->GPOS_Table
, language
);
2265 language
->features_initialized
= TRUE
;
2269 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
)
2273 LoadedScript
*script
= NULL
;
2274 LoadedLanguage
*language
= NULL
;
2276 _initialize_script_cache(psc
);
2278 for (i
= 0; i
< psc
->script_count
; i
++)
2280 if (psc
->scripts
[i
].tag
== script_tag
)
2282 script
= &psc
->scripts
[i
];
2293 return E_INVALIDARG
;
2296 _initialize_language_cache(script
);
2298 if ((script
->default_language
.gsub_table
|| script
->default_language
.gpos_table
) && script
->default_language
.tag
== language_tag
)
2299 language
= &script
->default_language
;
2302 for (i
= 0; i
< script
->language_count
; i
++)
2304 if (script
->languages
[i
].tag
== language_tag
)
2306 language
= &script
->languages
[i
];
2318 _initialize_feature_cache(psc
, language
);
2323 for (i
= 0; i
< language
->feature_count
; i
++)
2324 if (language
->features
[i
].tableType
== tableType
)
2325 *pcTags
= (*pcTags
)+1;
2328 *pcTags
= language
->feature_count
;
2330 if (!searchingFor
&& cMaxTags
< *pcTags
)
2332 else if (searchingFor
)
2335 for (i
= 0; i
< language
->feature_count
; i
++)
2339 if (!tableType
|| language
->features
[i
].tableType
== tableType
)
2340 pFeatureTags
[i
] = language
->features
[i
].tag
;
2345 if ((searchingFor
== language
->features
[i
].tag
) &&
2346 (!tableType
|| language
->features
[i
].tableType
== tableType
))
2348 pFeatureTags
[0] = language
->features
[i
].tag
;
2351 *feature
= &language
->features
[i
];