Fix font fallback list on macOS with default family

Even with an empty font family we should produce a font fallback list, and we can.
Fixes the missing checkmark (when not affected by clipping).
This commit is contained in:
Simon Hausmann 2021-06-30 15:46:30 +02:00
parent 6ffe456fd8
commit 8dc6ee6fb1

View file

@ -142,30 +142,28 @@ pub(crate) fn font_fallbacks_for_request(
_request: &FontRequest, _request: &FontRequest,
_reference_text: &str, _reference_text: &str,
) -> Vec<FontRequest> { ) -> Vec<FontRequest> {
_request let requested_font = match core_text::font::new_from_name(
.family &_request.family.as_ref().map_or_else(|| "", |s| s.as_str()),
.as_ref() _request.pixel_size.unwrap_or_default() as f64,
.and_then(|family| { ) {
core_text::font::new_from_name(&family, _request.pixel_size.unwrap_or_default() as f64) Ok(f) => f,
.ok() Err(_) => return vec![],
}) };
.map(|requested_font| {
core_text::font::cascade_list_for_languages( core_text::font::cascade_list_for_languages(
&requested_font, &requested_font,
&core_foundation::array::CFArray::from_CFTypes(&[]), &core_foundation::array::CFArray::from_CFTypes(&[]),
) )
.iter() .iter()
.map(|fallback_descriptor| FontRequest { .map(|fallback_descriptor| FontRequest {
family: Some(fallback_descriptor.family_name().into()), family: Some(fallback_descriptor.family_name().into()),
weight: _request.weight, weight: _request.weight,
pixel_size: _request.pixel_size, pixel_size: _request.pixel_size,
letter_spacing: _request.letter_spacing, letter_spacing: _request.letter_spacing,
}) })
.filter(|fallback| !fallback.family.as_ref().unwrap().starts_with(".")) // font-kit asserts when loading `.Apple Fallback` .filter(|fallback| !fallback.family.as_ref().unwrap().starts_with(".")) // font-kit asserts when loading `.Apple Fallback`
.take(1) // Take only the top from the fallback list until we mmap the llaaarge font files .take(1) // Take only the top from the fallback list until we mmap the llaaarge font files
.collect::<Vec<_>>() .collect::<Vec<_>>()
})
.unwrap_or_default()
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]