Skip to content

Commit 01fb648

Browse files
authored
Update HarfBuzz glue code for Bidi_Mirroring_Glyph data (#3229)
1 parent b885551 commit 01fb648

File tree

1 file changed

+40
-5
lines changed
  • experimental/harfbuzz/src

1 file changed

+40
-5
lines changed

experimental/harfbuzz/src/lib.rs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ use icu_normalizer::provider::CanonicalCompositionsV1Marker;
3535
use icu_normalizer::provider::CanonicalDecompositionDataV1Marker;
3636
use icu_normalizer::provider::CanonicalDecompositionTablesV1Marker;
3737
use icu_normalizer::provider::NonRecursiveDecompositionSupplementV1Marker;
38+
use icu_properties::bidi_data::BidiAuxiliaryProperties;
3839
use icu_properties::maps::CodePointMapData;
40+
use icu_properties::provider::bidi_data::BidiAuxiliaryPropertiesV1Marker;
3941
use icu_properties::provider::GeneralCategoryV1Marker;
4042
use icu_properties::GeneralCategory;
4143
use icu_provider::prelude::*;
@@ -120,6 +122,31 @@ unsafe extern "C" fn icu4x_hb_unicode_general_category_destroy(user_data: *mut c
120122
let _ = Box::from_raw(user_data as *mut CodePointMapData<GeneralCategory>);
121123
}
122124

125+
/// Returns the Bidi_Mirroring_Glyph, but adjusting the return value
126+
/// to fix HarfBuzz expected behavior for code points whose property value
127+
/// for Bidi_Mirroring_Glyph is the undefined value.
128+
///
129+
/// From HarfBuzz docs on `hb_unicode_mirroring_func_t`:
130+
/// <note>Note: If a code point does not have a specified
131+
/// Bi-Directional Mirroring Glyph defined, the method should
132+
/// return the original code point.</note>
133+
unsafe extern "C" fn icu4x_hb_unicode_mirroring(
134+
_ufuncs: *mut hb_unicode_funcs_t,
135+
unicode: hb_codepoint_t,
136+
user_data: *mut c_void,
137+
) -> hb_codepoint_t {
138+
(*(user_data as *mut BidiAuxiliaryProperties))
139+
.as_borrowed()
140+
.get32_mirroring_props(unicode)
141+
.mirroring_glyph
142+
.map(u32::from)
143+
.unwrap_or(unicode) as hb_codepoint_t
144+
}
145+
146+
unsafe extern "C" fn icu4x_hb_unicode_mirroring_destroy(user_data: *mut c_void) {
147+
let _ = Box::from_raw(user_data as *mut BidiAuxiliaryProperties);
148+
}
149+
123150
unsafe extern "C" fn icu4x_hb_unicode_compose(
124151
_ufuncs: *mut hb_unicode_funcs_t,
125152
a: hb_codepoint_t,
@@ -252,7 +279,8 @@ impl Drop for UnicodeFuncs {
252279
// are violated in principle.
253280
pub fn new_hb_unicode_funcs_unstable<D>(data_provider: &D) -> Result<UnicodeFuncs, HarfBuzzError>
254281
where
255-
D: DataProvider<CanonicalCompositionsV1Marker>
282+
D: DataProvider<BidiAuxiliaryPropertiesV1Marker>
283+
+ DataProvider<CanonicalCompositionsV1Marker>
256284
+ DataProvider<CanonicalDecompositionDataV1Marker>
257285
+ DataProvider<CanonicalDecompositionTablesV1Marker>
258286
+ DataProvider<NonRecursiveDecompositionSupplementV1Marker>
@@ -266,7 +294,9 @@ where
266294
Box::new(CanonicalCombiningClassMap::try_new_unstable(data_provider)?);
267295
let general_category_map =
268296
Box::new(icu_properties::maps::load_general_category(data_provider)?);
269-
// TODO(#2833): mirroring
297+
let bidi_auxiliary_props_map = Box::new(
298+
icu_properties::bidi_data::load_bidi_auxiliary_properties_unstable(data_provider)?,
299+
);
270300
// TODO(#2832): script
271301
let canonical_composition = Box::new(CanonicalComposition::try_new_unstable(data_provider)?);
272302
let canonical_decomposition =
@@ -289,7 +319,8 @@ where
289319
Box::into_raw(canonical_combining_class_map);
290320
let general_category_map_ptr: *mut CodePointMapData<GeneralCategory> =
291321
Box::into_raw(general_category_map);
292-
// TODO(#2833): mirroring
322+
let bidi_auxiliary_props_map_ptr: *mut BidiAuxiliaryProperties =
323+
Box::into_raw(bidi_auxiliary_props_map);
293324
// TODO(#2832): script
294325
let canonical_composition_ptr: *mut CanonicalComposition =
295326
Box::into_raw(canonical_composition);
@@ -308,9 +339,13 @@ where
308339
general_category_map_ptr as *mut c_void,
309340
Some(icu4x_hb_unicode_general_category_destroy),
310341
);
342+
hb_unicode_funcs_set_mirroring_func(
343+
ufuncs,
344+
Some(icu4x_hb_unicode_mirroring),
345+
bidi_auxiliary_props_map_ptr as *mut c_void,
346+
Some(icu4x_hb_unicode_mirroring_destroy),
347+
);
311348

312-
// TODO(#2833):
313-
// hb_unicode_funcs_set_mirroring_func();
314349
// TODO(#2832):
315350
// hb_unicode_funcs_set_script_func();
316351

0 commit comments

Comments
 (0)