summaryrefslogtreecommitdiff
path: root/src/loading
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-09-19 11:31:37 +0200
committerLaurenz <laurmaedje@gmail.com>2022-09-19 11:36:59 +0200
commit30be75c6687f1e03cf867d258b3ddba353cc7aa2 (patch)
tree51afd42ae8875811ae51974e66681a17990de7f2 /src/loading
parent4ec3bcee487c1567bc6551f81d4f69eee4379076 (diff)
Renaming
`Face` -> `Font` `FaceId` -> `FontId` `SourceFile` -> `Source`
Diffstat (limited to 'src/loading')
-rw-r--r--src/loading/fs.rs16
-rw-r--r--src/loading/mem.rs18
-rw-r--r--src/loading/mod.rs8
3 files changed, 21 insertions, 21 deletions
diff --git a/src/loading/fs.rs b/src/loading/fs.rs
index c1576e86..70ab5e53 100644
--- a/src/loading/fs.rs
+++ b/src/loading/fs.rs
@@ -7,19 +7,19 @@ use same_file::Handle;
use walkdir::WalkDir;
use super::{FileHash, Loader};
-use crate::font::FaceInfo;
+use crate::font::FontInfo;
/// Loads fonts and files from the local file system.
///
/// _This is only available when the `fs` feature is enabled._
pub struct FsLoader {
- faces: Vec<FaceInfo>,
+ fonts: Vec<FontInfo>,
}
impl FsLoader {
/// Create a new loader without any fonts.
pub fn new() -> Self {
- Self { faces: vec![] }
+ Self { fonts: vec![] }
}
/// Builder-style variant of [`search_system`](Self::search_system).
@@ -100,24 +100,24 @@ impl FsLoader {
}
}
- /// Index the font faces in the file at the given path.
+ /// Index the fonts in the file at the given path.
///
- /// The file may form a font collection and contain multiple font faces,
+ /// The file may form a font collection and contain multiple fonts,
/// which will then all be indexed.
fn search_file(&mut self, path: impl AsRef<Path>) {
let path = path.as_ref();
let path = path.strip_prefix(".").unwrap_or(path);
if let Ok(file) = File::open(path) {
if let Ok(mmap) = unsafe { Mmap::map(&file) } {
- self.faces.extend(FaceInfo::from_data(path, &mmap));
+ self.fonts.extend(FontInfo::from_data(path, &mmap));
}
}
}
}
impl Loader for FsLoader {
- fn faces(&self) -> &[FaceInfo] {
- &self.faces
+ fn fonts(&self) -> &[FontInfo] {
+ &self.fonts
}
fn resolve(&self, path: &Path) -> io::Result<FileHash> {
diff --git a/src/loading/mem.rs b/src/loading/mem.rs
index 7208e6e2..320de349 100644
--- a/src/loading/mem.rs
+++ b/src/loading/mem.rs
@@ -4,20 +4,20 @@ use std::io;
use std::path::{Path, PathBuf};
use super::{FileHash, Loader};
-use crate::font::FaceInfo;
+use crate::font::FontInfo;
use crate::util::PathExt;
/// Loads fonts and files from an in-memory storage.
#[derive(Default)]
pub struct MemLoader {
- faces: Vec<FaceInfo>,
+ fonts: Vec<FontInfo>,
files: HashMap<PathBuf, Cow<'static, [u8]>>,
}
impl MemLoader {
/// Create a new from-memory loader.
pub fn new() -> Self {
- Self { faces: vec![], files: HashMap::new() }
+ Self { fonts: vec![], files: HashMap::new() }
}
/// Builder-style variant of [`insert`](Self::insert).
@@ -42,14 +42,14 @@ impl MemLoader {
{
let path = path.as_ref().normalize();
let data = data.into();
- self.faces.extend(FaceInfo::from_data(&path, &data));
+ self.fonts.extend(FontInfo::from_data(&path, &data));
self.files.insert(path, data);
}
}
impl Loader for MemLoader {
- fn faces(&self) -> &[FaceInfo] {
- &self.faces
+ fn fonts(&self) -> &[FontInfo] {
+ &self.fonts
}
fn resolve(&self, path: &Path) -> io::Result<FileHash> {
@@ -80,13 +80,13 @@ mod tests {
let path = Path::new("PTSans.ttf");
let loader = MemLoader::new().with(path, &data[..]);
- // Test that the face was found.
- let info = &loader.faces[0];
+ // Test that the font was found.
+ let info = &loader.fonts[0];
assert_eq!(info.path, path);
assert_eq!(info.index, 0);
assert_eq!(info.family, "PT Sans");
assert_eq!(info.variant, FontVariant::default());
- assert_eq!(loader.faces.len(), 1);
+ assert_eq!(loader.fonts.len(), 1);
// Test that the file can be loaded.
assert_eq!(
diff --git a/src/loading/mod.rs b/src/loading/mod.rs
index 4841e752..d37dd1fc 100644
--- a/src/loading/mod.rs
+++ b/src/loading/mod.rs
@@ -11,7 +11,7 @@ pub use mem::*;
use std::io;
use std::path::Path;
-use crate::font::FaceInfo;
+use crate::font::FontInfo;
/// A hash that identifies a file.
///
@@ -21,8 +21,8 @@ pub struct FileHash(pub u64);
/// Loads resources from a local or remote source.
pub trait Loader {
- /// Descriptions of all font faces this loader serves.
- fn faces(&self) -> &[FaceInfo];
+ /// Descriptions of all fonts this loader serves.
+ fn fonts(&self) -> &[FontInfo];
/// Resolve a hash that is the same for this and all other paths pointing to
/// the same file.
@@ -36,7 +36,7 @@ pub trait Loader {
pub struct BlankLoader;
impl Loader for BlankLoader {
- fn faces(&self) -> &[FaceInfo] {
+ fn fonts(&self) -> &[FontInfo] {
&[]
}