mirror of
https://github.com/wez/wezterm.git
synced 2024-11-10 15:04:32 +03:00
eliminate dep on rental
Trading a lot of gross for a single line of gross
This commit is contained in:
parent
5696ce6304
commit
ad72362cbc
@ -32,7 +32,6 @@ leb128 = "0.2"
|
||||
libc = "0.2"
|
||||
log = "0.4"
|
||||
open = "1.2"
|
||||
rental = "0.5"
|
||||
native-tls = "0.2"
|
||||
# file change notification
|
||||
notify = "4.0"
|
||||
|
@ -5,6 +5,7 @@
|
||||
use crate::config::Config;
|
||||
use crate::config::FontAttributes;
|
||||
use crate::font::locator::FontDataHandle;
|
||||
use allsorts::binary::read::{ReadScope, ReadScopeOwned};
|
||||
use allsorts::fontfile::FontFile;
|
||||
use allsorts::tables::{
|
||||
FontTableProvider, HeadTable, MaxpTable, NameTable, OffsetTable, OpenTypeFont, TTCHeader,
|
||||
@ -16,8 +17,11 @@ use std::path::{Path, PathBuf};
|
||||
/// Represents a parsed font
|
||||
pub struct ParsedFont {
|
||||
index: usize,
|
||||
file: gah::OwnedFontFile,
|
||||
file: FontFile<'static>,
|
||||
names: Names,
|
||||
|
||||
// Must be last: this keeps the 'static items alive
|
||||
_scope: ReadScopeOwned,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -97,15 +101,20 @@ impl ParsedFont {
|
||||
|
||||
let index = index as usize;
|
||||
|
||||
let file = parse(data)?;
|
||||
let owned_scope = ReadScopeOwned::new(ReadScope::new(&data));
|
||||
|
||||
let names = file.rent(|file| -> Fallible<Names> {
|
||||
let name_table = name_table_data(file, index)?;
|
||||
let file: FontFile<'static> =
|
||||
unsafe { std::mem::transmute(owned_scope.scope().read::<FontFile>()?) };
|
||||
|
||||
let name_table = name_table_data(&file, index)?;
|
||||
let names = Names::from_name_table_data(name_table)?;
|
||||
Ok(names)
|
||||
})?;
|
||||
|
||||
Ok(Self { index, file, names })
|
||||
Ok(Self {
|
||||
index,
|
||||
file,
|
||||
names,
|
||||
_scope: owned_scope,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn names(&self) -> &Names {
|
||||
@ -113,30 +122,6 @@ impl ParsedFont {
|
||||
}
|
||||
}
|
||||
|
||||
rental! {
|
||||
/// This is horrible, but I don't see an obvious way to
|
||||
/// end up with an owned FontFile instance from the standard
|
||||
/// set of functions exported by allsorts
|
||||
mod gah {
|
||||
use super::*;
|
||||
#[rental]
|
||||
pub struct OwnedFontFile {
|
||||
head: Vec<u8>,
|
||||
file: FontFile<'head>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse bytes into an OwnedFontFile
|
||||
fn parse(data: Vec<u8>) -> Fallible<gah::OwnedFontFile> {
|
||||
gah::OwnedFontFile::try_new(data, |data| {
|
||||
let scope = allsorts::binary::read::ReadScope::new(&data);
|
||||
let file = scope.read::<FontFile>()?;
|
||||
Ok(file)
|
||||
})
|
||||
.map_err(|e| e.0)
|
||||
}
|
||||
|
||||
fn collect_font_info(
|
||||
name_table_data: &[u8],
|
||||
path: &Path,
|
||||
|
@ -1,9 +1,6 @@
|
||||
// Don't create a new standard console window when launched from the windows GUI.
|
||||
#![windows_subsystem = "windows"]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rental;
|
||||
|
||||
use failure::{err_msg, format_err, Error, Fallible};
|
||||
use promise::Future;
|
||||
use std::ffi::OsString;
|
||||
|
Loading…
Reference in New Issue
Block a user