@@ -5,7 +5,8 @@ use crate::hb::aat::layout_common::{
55 START_OF_TEXT ,
66} ;
77use crate :: hb:: ot_layout:: MAX_CONTEXT_LENGTH ;
8- use crate :: hb:: { hb_font_t, GlyphInfo } ;
8+ use crate :: hb:: tag:: lang_matches;
9+ use crate :: hb:: { hb_font_t, GlyphInfo , Language } ;
910use crate :: U32Set ;
1011use alloc:: { vec, vec:: Vec } ;
1112use read_fonts:: tables:: aat:: { self , ExtendedStateTable , NoPayload , StateEntry , StateTable } ;
@@ -66,10 +67,32 @@ pub fn compile_flags(face: &hb_font_t, builder: &AatMapBuilder, map: &mut AatMap
6667 } )
6768 . is_ok ( )
6869 } ;
70+ let language_matches = |setting : u16 | {
71+ let Some ( index) = setting. checked_sub ( 1 ) else {
72+ return false ;
73+ } ;
74+ let Some ( requested) = builder. language . as_ref ( ) else {
75+ return false ;
76+ } ;
77+ let Some ( ltag) = face. aat_tables . ltag . as_ref ( ) else {
78+ return false ;
79+ } ;
80+ let Some ( tag) = ltag
81+ . tag_indices ( )
82+ . find_map ( |( tag_index, tag) | ( tag_index == u32:: from ( index) ) . then_some ( tag) )
83+ else {
84+ return false ;
85+ } ;
86+ let Some ( language) = Language :: new ( tag) else {
87+ return false ;
88+ } ;
89+ lang_matches ( requested. as_bytes ( ) , language. as_bytes ( ) )
90+ } ;
6991
7092 fn compile_chain (
7193 chain : & impl MorphChain ,
7294 has_feature : & impl Fn ( u16 , u16 ) -> bool ,
95+ language_matches : & impl Fn ( u16 ) -> bool ,
7396 chain_flags : & mut Vec < RangeFlags > ,
7497 builder : & AatMapBuilder ,
7598 ) {
@@ -93,8 +116,12 @@ pub fn compile_flags(face: &hb_font_t, builder: &AatMapBuilder, map: &mut AatMap
93116 flags &= disable_flags;
94117 flags |= enable_flags;
95118 }
119+ } else if feature_type == FEATURE_TYPE_LANGUAGE_TAG_TYPE as u16
120+ && language_matches ( feature_setting)
121+ {
122+ flags &= disable_flags;
123+ flags |= enable_flags;
96124 }
97- // TODO: Port the following commit: https://github.com/harfbuzz/harfbuzz/commit/2124ad890
98125 } ,
99126 ) ;
100127
@@ -110,15 +137,27 @@ pub fn compile_flags(face: &hb_font_t, builder: &AatMapBuilder, map: &mut AatMap
110137 map. chain_flags . resize ( chains. iter ( ) . count ( ) , vec ! [ ] ) ;
111138 for ( chain, chain_flags) in chains. iter ( ) . zip ( map. chain_flags . iter_mut ( ) ) {
112139 if let Ok ( chain) = chain {
113- compile_chain ( & chain, & has_feature, chain_flags, builder) ;
140+ compile_chain (
141+ & chain,
142+ & has_feature,
143+ & language_matches,
144+ chain_flags,
145+ builder,
146+ ) ;
114147 }
115148 }
116149 } else {
117150 let chains = face. aat_tables . mort . as_ref ( ) ?. 0 . chains ( ) ;
118151 map. chain_flags . resize ( chains. iter ( ) . count ( ) , vec ! [ ] ) ;
119152 for ( chain, chain_flags) in chains. iter ( ) . zip ( map. chain_flags . iter_mut ( ) ) {
120153 if let Ok ( chain) = chain {
121- compile_chain ( & chain, & has_feature, chain_flags, builder) ;
154+ compile_chain (
155+ & chain,
156+ & has_feature,
157+ & language_matches,
158+ chain_flags,
159+ builder,
160+ ) ;
122161 }
123162 }
124163 }
0 commit comments