1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-10 15:04:32 +03:00

fonts: remove last use of ttf_parser::fonts_in_collection

improve some diagnostics around fonts on windows
This commit is contained in:
Wez Furlong 2021-04-08 08:46:10 -07:00
parent 024f66ba87
commit e59e17d773
3 changed files with 21 additions and 35 deletions

View File

@ -30,7 +30,8 @@ impl Entry {
}
};
let face = Face::from_slice(&data, index)?;
let face = Face::from_slice(&data, index)
.with_context(|| format!("ttf_parser parsing {:?}", self.handle))?;
let mut coverage = RangeSet::new();
for table in face.character_mapping_subtables() {
@ -51,7 +52,7 @@ impl Entry {
let mut coverage = self.coverage.lock().unwrap();
if coverage.is_none() {
let t = std::time::Instant::now();
coverage.replace(self.compute_coverage()?);
coverage.replace(self.compute_coverage().context("compute_coverage")?);
let elapsed = t.elapsed();
metrics::histogram!("font.compute.codepoint.coverage", elapsed);
log::debug!(
@ -173,7 +174,9 @@ impl FontDatabase {
let mut matches = vec![];
for entry in self.by_full_name.values() {
let covered = entry.coverage_intersection(&wanted_range)?;
let covered = entry
.coverage_intersection(&wanted_range)
.with_context(|| format!("coverage_interaction for {:?}", entry.parsed))?;
let len = covered.len();
if len > 0 {
matches.push((len, entry.handle.clone()));

View File

@ -212,7 +212,7 @@ impl FontConfigInner {
match font_dirs.locate_fallback_for_codepoints(&no_glyphs) {
Ok(ref mut handles) => extra_handles.append(handles),
Err(err) => log::error!(
"Error: {} while resolving fallback for {} from font_dirs",
"Error: {:#} while resolving fallback for {} from font_dirs",
err,
fallback_str.escape_unicode()
),
@ -221,7 +221,7 @@ impl FontConfigInner {
match built_in.locate_fallback_for_codepoints(&no_glyphs) {
Ok(ref mut handles) => extra_handles.append(handles),
Err(err) => log::error!(
"Error: {} while resolving fallback for {} for built-in fonts",
"Error: {:#} while resolving fallback for {} for built-in fonts",
err,
fallback_str.escape_unicode()
),
@ -230,7 +230,7 @@ impl FontConfigInner {
match locator.locate_fallback_for_codepoints(&no_glyphs) {
Ok(ref mut handles) => extra_handles.append(handles),
Err(err) => log::error!(
"Error: {} while resolving fallback for {} from font-locator",
"Error: {:#} while resolving fallback for {} from font-locator",
err,
fallback_str.escape_unicode()
),

View File

@ -1,12 +1,11 @@
#![cfg(windows)]
use crate::locator::{FontDataHandle, FontLocator};
use crate::parser::FontMatch;
use crate::parser::{parse_and_collect_font_info, FontMatch};
use config::FontAttributes;
use dwrote::{FontDescriptor, FontStretch, FontStyle, FontWeight};
use std::borrow::Cow;
use std::collections::HashSet;
use ttf_parser::fonts_in_collection;
use winapi::shared::windef::HFONT;
use winapi::um::dwrite::*;
use winapi::um::wingdi::{
@ -140,6 +139,7 @@ fn attributes_to_descriptor(font_attr: &FontAttributes) -> FontDescriptor {
}
fn handle_from_descriptor(
attr: &FontAttributes,
collection: &dwrote::FontCollection,
descriptor: &FontDescriptor,
) -> Option<FontDataHandle> {
@ -148,32 +148,13 @@ fn handle_from_descriptor(
for file in face.get_files() {
if let Some(path) = file.get_font_file_path() {
let family_name = font.family_name();
let mut font_info = vec![];
log::debug!("{} -> {}", family_name, path.display());
if let Ok(data) = std::fs::read(&path) {
let size = fonts_in_collection(&data).unwrap_or(1);
let mut handle = FontDataHandle::Memory {
data: Cow::Owned(data),
name: family_name.clone(),
index: 0,
variation: 0,
};
for index in 0..size {
if let FontDataHandle::Memory { index: idx, .. } = &mut handle {
*idx = index;
}
let parsed = crate::parser::ParsedFont::from_locator(&handle).ok()?;
let names = parsed.names();
if names.full_name == family_name || names.family.as_ref() == Some(&family_name)
{
// Switch to an OnDisk handle so that we don't hold
// all of the fallback fonts in memory
return Some(FontDataHandle::OnDisk {
path,
index,
variation: 0,
});
if parse_and_collect_font_info(&path, &mut font_info).is_ok() {
for (parsed, handle) in font_info {
if parsed.matches_attributes(attr) != FontMatch::NoMatch {
return Some(handle);
}
}
}
@ -218,7 +199,7 @@ impl FontLocator for GdiFontLocator {
}
}
match handle_from_descriptor(&collection, &descriptor) {
match handle_from_descriptor(font_attr, &collection, &descriptor) {
Some(handle) => {
log::debug!("Got {:?} from dwrote", handle);
if try_handle(font_attr, handle, &mut fonts, loaded) {
@ -326,7 +307,9 @@ impl FontLocator for GdiFontLocator {
resolved.insert(attr.clone());
let descriptor = attributes_to_descriptor(&attr);
if let Some(handle) = handle_from_descriptor(&collection, &descriptor) {
if let Some(handle) =
handle_from_descriptor(&attr, &collection, &descriptor)
{
handles.push(handle);
}
}