summaryrefslogtreecommitdiff
path: root/src/font
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-06-26 13:57:21 +0200
committerLaurenz <laurmaedje@gmail.com>2023-06-27 18:40:17 +0200
commit7b92bd7c340d9f9c094ed2fa57912049317d9b20 (patch)
treeb91399526ba94d87309d09d864df2935dd7a4d0a /src/font
parent9c7f31870b4e1bf37df79ebbe1df9a56df83d878 (diff)
Basic package management
Diffstat (limited to 'src/font')
-rw-r--r--src/font/mod.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/font/mod.rs b/src/font/mod.rs
index 032783e4..2353e51c 100644
--- a/src/font/mod.rs
+++ b/src/font/mod.rs
@@ -15,9 +15,11 @@ use ttf_parser::GlyphId;
use self::book::find_name;
use crate::eval::Cast;
use crate::geom::Em;
-use crate::util::Buffer;
+use crate::util::Bytes;
/// An OpenType font.
+///
+/// Values of this type are cheap to clone and hash.
#[derive(Clone)]
pub struct Font(Arc<Repr>);
@@ -26,7 +28,7 @@ struct Repr {
/// The raw font data, possibly shared with other fonts from the same
/// collection. The vector's allocation must not move, because `ttf` points
/// into it using unsafe code.
- data: Buffer,
+ data: Bytes,
/// The font's index in the buffer.
index: u32,
/// Metadata about the font.
@@ -41,7 +43,7 @@ struct Repr {
impl Font {
/// Parse a font from data and collection index.
- pub fn new(data: Buffer, index: u32) -> Option<Self> {
+ pub fn new(data: Bytes, index: u32) -> Option<Self> {
// Safety:
// - The slices's location is stable in memory:
// - We don't move the underlying vector
@@ -60,13 +62,13 @@ impl Font {
}
/// Parse all fonts in the given data.
- pub fn iter(data: Buffer) -> impl Iterator<Item = Self> {
+ pub fn iter(data: Bytes) -> impl Iterator<Item = Self> {
let count = ttf_parser::fonts_in_collection(&data).unwrap_or(1);
(0..count).filter_map(move |index| Self::new(data.clone(), index))
}
/// The underlying buffer.
- pub fn data(&self) -> &Buffer {
+ pub fn data(&self) -> &Bytes {
&self.0.data
}