Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/fonts/platform/windows/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ impl PlatformFontMethods for PlatformFont {
pt_size: Option<Au>,
) -> Result<PlatformFont, &'static str> {
let font_face = FontCollection::system()
.get_font_from_descriptor(&font_identifier.font_descriptor)
.font_from_descriptor(&font_identifier.font_descriptor)
.ok()
.flatten()
.ok_or("Could not create Font from descriptor")?
.create_font_face();
Self::new(font_face, pt_size)
Expand Down
22 changes: 16 additions & 6 deletions components/fonts/platform/windows/font_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ where
{
let system_fc = FontCollection::system();
for family in system_fc.families_iter() {
callback(family.name());
if let Ok(family_name) = family.family_name() {
callback(family_name);
}
}
}

Expand All @@ -40,13 +42,17 @@ pub struct LocalFontIdentifier {
impl LocalFontIdentifier {
pub fn index(&self) -> u32 {
FontCollection::system()
.get_font_from_descriptor(&self.font_descriptor)
.font_from_descriptor(&self.font_descriptor)
.ok()
.flatten()
.map_or(0, |font| font.create_font_face().get_index())
}

pub(crate) fn native_font_handle(&self) -> NativeFontHandle {
let face = FontCollection::system()
.get_font_from_descriptor(&self.font_descriptor)
.font_from_descriptor(&self.font_descriptor)
.ok()
.flatten()
.expect("Could not create Font from FontDescriptor")
.create_font_face();
let path = face
Expand All @@ -62,7 +68,9 @@ impl LocalFontIdentifier {
}

pub(crate) fn read_data_from_file(&self) -> Option<Vec<u8>> {
let font = FontCollection::system().get_font_from_descriptor(&self.font_descriptor)?;
let font = FontCollection::system()
.font_from_descriptor(&self.font_descriptor)
.ok()??;
let face = font.create_font_face();
let files = face.get_files();
assert!(!files.is_empty());
Expand All @@ -86,10 +94,12 @@ where
F: FnMut(FontTemplate),
{
let system_fc = FontCollection::system();
if let Some(family) = system_fc.get_font_family_by_name(family_name) {
if let Ok(Some(family)) = system_fc.font_family_by_name(family_name) {
let count = family.get_font_count();
for i in 0..count {
let font = family.get_font(i);
let Ok(font) = family.font(i) else {
continue;
};
let template_descriptor = (&font).into();
let local_font_identifier = LocalFontIdentifier {
font_descriptor: Arc::new(font.to_descriptor()),
Expand Down
Loading