Move fontdb source handling to font
This commit is contained in:
parent
a3ccbd0481
commit
66885686a0
2 changed files with 16 additions and 20 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
pub struct Font<'a> {
|
pub struct Font<'a> {
|
||||||
pub info: &'a fontdb::FaceInfo,
|
pub info: &'a fontdb::FaceInfo,
|
||||||
pub data: &'a [u8],
|
pub data: &'a [u8],
|
||||||
|
|
@ -10,14 +12,23 @@ pub struct Font<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Font<'a> {
|
impl<'a> Font<'a> {
|
||||||
pub fn new(info: &'a fontdb::FaceInfo, data: &'a [u8], index: u32) -> Option<Self> {
|
pub fn new(info: &'a fontdb::FaceInfo) -> Option<Self> {
|
||||||
|
let data = match &info.source {
|
||||||
|
fontdb::Source::Binary(data) => data.deref().as_ref(),
|
||||||
|
fontdb::Source::File(path) => {
|
||||||
|
log::warn!("Unsupported fontdb Source::File('{}')", path.display());
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
fontdb::Source::SharedFile(_path, data) => data.deref().as_ref(),
|
||||||
|
};
|
||||||
|
|
||||||
Some(Self {
|
Some(Self {
|
||||||
info,
|
info,
|
||||||
data,
|
data,
|
||||||
index,
|
index: info.index,
|
||||||
rustybuzz: rustybuzz::Face::from_slice(data, index)?,
|
rustybuzz: rustybuzz::Face::from_slice(data, info.index)?,
|
||||||
#[cfg(feature = "swash")]
|
#[cfg(feature = "swash")]
|
||||||
swash: swash::FontRef::from_index(data, index as usize)?,
|
swash: swash::FontRef::from_index(data, info.index as usize)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use crate::{Attrs, Font, FontMatches};
|
use crate::{Attrs, Font, FontMatches};
|
||||||
|
|
||||||
/// Access system fonts
|
/// Access system fonts
|
||||||
|
|
@ -51,20 +49,7 @@ impl FontSystem {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let font_opt = Font::new(
|
match Font::new(face) {
|
||||||
face,
|
|
||||||
match &face.source {
|
|
||||||
fontdb::Source::Binary(data) => data.deref().as_ref(),
|
|
||||||
fontdb::Source::File(path) => {
|
|
||||||
log::warn!("Unsupported fontdb Source::File('{}')", path.display());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fontdb::Source::SharedFile(_path, data) => data.deref().as_ref(),
|
|
||||||
},
|
|
||||||
face.index,
|
|
||||||
);
|
|
||||||
|
|
||||||
match font_opt {
|
|
||||||
Some(font) => fonts.push(font),
|
Some(font) => fonts.push(font),
|
||||||
None => {
|
None => {
|
||||||
log::warn!("failed to load font '{}'", face.post_script_name);
|
log::warn!("failed to load font '{}'", face.post_script_name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue