[fontations] Implement font_h_extents

This commit is contained in:
Behdad Esfahbod 2025-03-04 17:45:00 -07:00 committed by Khaled Hosny
parent b9a4d148c9
commit bc2851b407

View file

@ -152,6 +152,31 @@ extern "C" fn _hb_fontations_get_glyph_extents(
true as hb_bool_t
}
extern "C" fn _hb_fontations_get_font_h_extents(
_font: *mut hb_font_t,
font_data: *mut ::std::os::raw::c_void,
extents: *mut hb_font_extents_t,
_user_data: *mut ::std::os::raw::c_void,
) -> hb_bool_t {
let data = unsafe { &*(font_data as *const FontationsData) };
let font_ref = &data.font_ref;
let size = &data.y_size;
let location = &data.location;
let metrics = font_ref.metrics(*size, location);
unsafe {
(*extents).ascender = metrics.ascent as hb_position_t;
}
unsafe {
(*extents).descender = metrics.descent as hb_position_t;
}
unsafe {
(*extents).line_gap = metrics.leading as hb_position_t;
}
true as hb_bool_t
}
fn _hb_fontations_font_funcs_create() -> *mut hb_font_funcs_t {
static static_ffuncs: AtomicPtr<hb_font_funcs_t> = AtomicPtr::new(null_mut());
@ -189,6 +214,12 @@ fn _hb_fontations_font_funcs_create() -> *mut hb_font_funcs_t {
null_mut(),
None,
);
hb_font_funcs_set_font_h_extents_func(
ffuncs,
Some(_hb_fontations_get_font_h_extents),
null_mut(),
None,
);
}
if (static_ffuncs.compare_exchange(null_mut(), ffuncs, Ordering::SeqCst, Ordering::Relaxed))