fonts: save used fontconfig match string in the origin for better visibility

This commit is contained in:
Greg V authored and Wez Furlong committed 2021-11-03 06:57:15 -07:00
1 parent 18e969e9aa
commit a2aec889c8
4 files changed
+23 -9

No files matched your search

+1 -1
View File
@@ -167,7 +167,7 @@ impl Face {
source: self.source.source.clone(),
index: self.source.index,
variation: i,
origin: self.source.origin,
origin: self.source.origin.clone(),
coverage: self.source.coverage.clone(),
};
res.push(ParsedFont::from_face(&self, source)?);
+9 -4
View File
@@ -65,7 +65,10 @@ impl FontLocator for FontConfigFontLocator {
Ok(matches)
}
fn to_handle(pat: FontPattern) -> anyhow::Result<FontDataHandle> {
fn to_handle(
pat: FontPattern,
match_name: Option<String>,
) -> anyhow::Result<FontDataHandle> {
let file = pat.get_file()?;
let index = pat.get_integer("index")? as u32;
let variation = index >> 16;
@@ -74,7 +77,9 @@ impl FontLocator for FontConfigFontLocator {
source: FontDataSource::OnDisk(file.into()),
index,
variation,
origin: FontOrigin::FontConfig,
origin: match_name
.map(FontOrigin::FontConfigMatch)
.unwrap_or(FontOrigin::FontConfig),
coverage: pat.get_charset().ok().map(|c| c.to_range_set()),
})
}
@@ -87,7 +92,7 @@ impl FontLocator for FontConfigFontLocator {
match resolver(attr) {
Ok(matches) => {
for pat in matches {
let handle = to_handle(pat)?;
let handle = to_handle(pat, None)?;
// fontconfig will give us a boatload of random fallbacks.
// so we need to parse the returned font
@@ -130,7 +135,7 @@ impl FontLocator for FontConfigFontLocator {
// For the fallback, be very careful, only select known monospace
if let Ok(spacing) = best_match.get_integer("spacing") {
if spacing == FC_MONO || spacing == FC_DUAL {
let handle = to_handle(best_match)?;
let handle = to_handle(best_match, Some(attr.family.clone()))?;
if let Ok(parsed) = crate::parser::ParsedFont::from_locator(&handle) {
log::trace!(
"found font-config fallback match for {:?}",
+10 -1
View File
@@ -13,9 +13,10 @@ pub mod core_text;
pub mod font_config;
pub mod gdi;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd, Display)]
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
pub enum FontOrigin {
FontConfig,
FontConfigMatch(String),
CoreText,
DirectWrite,
Gdi,
@@ -23,6 +24,14 @@ pub enum FontOrigin {
BuiltIn,
}
// derived impl would just use the inner string instead of
// 'FontConfigMatch("..")', so use Debug
impl Display for FontOrigin {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
#[derive(Clone)]
pub enum FontDataSource {
OnDisk(PathBuf),
+3 -3
View File
@@ -535,13 +535,13 @@ pub(crate) fn parse_and_collect_font_info(
source: &FontDataSource,
index: u32,
font_info: &mut Vec<ParsedFont>,
origin: FontOrigin,
origin: &FontOrigin,
) -> anyhow::Result<()> {
let locator = FontDataHandle {
source: source.clone(),
index,
variation: 0,
origin,
origin: origin.clone(),
coverage: None,
};
@@ -558,7 +558,7 @@ pub(crate) fn parse_and_collect_font_info(
}
for index in 0..num_faces {
if let Err(err) = load_one(&lib, &source, index, font_info, origin) {
if let Err(err) = load_one(&lib, &source, index, font_info, &origin) {
log::trace!("error while parsing {:?} index {}: {}", source, index, err);
}
}