summaryrefslogtreecommitdiff
path: root/src/font.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/font.rs')
-rw-r--r--src/font.rs47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/font.rs b/src/font.rs
index 978fb601..dadf6830 100644
--- a/src/font.rs
+++ b/src/font.rs
@@ -14,8 +14,7 @@ use crate::geom::Length;
use crate::loading::{FileHash, Loader};
/// A unique identifier for a loaded font face.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
-#[derive(Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct FaceId(u32);
impl FaceId {
@@ -271,7 +270,7 @@ impl Face {
/// A length in em units.
///
/// `1em` is the same as the font size.
-#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, PartialOrd)]
+#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct Em(N64);
impl Em {
@@ -343,11 +342,15 @@ impl Display for VerticalFontMetric {
}
/// A generic or named font family.
-#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
+#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum FontFamily {
+ /// A family that has "serifs", small strokes attached to letters.
Serif,
+ /// A family in which glyphs do not have "serifs", small attached strokes.
SansSerif,
+ /// A family in which (almost) all glyphs are of equal width.
Monospace,
+ /// A specific family with a name.
Named(String),
}
@@ -575,15 +578,6 @@ impl Default for FontWeight {
}
}
-impl Display for FontWeight {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- match self.to_str() {
- Some(name) => f.pad(name),
- None => write!(f, "{}", self.0),
- }
- }
-}
-
impl Debug for FontWeight {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.pad(match *self {
@@ -601,6 +595,15 @@ impl Debug for FontWeight {
}
}
+impl Display for FontWeight {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ match self.to_str() {
+ Some(name) => f.pad(name),
+ None => write!(f, "{}", self.0),
+ }
+ }
+}
+
/// The width of a font face.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[derive(Serialize, Deserialize)]
@@ -707,15 +710,6 @@ impl Default for FontStretch {
}
}
-impl Display for FontStretch {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- match self.to_str() {
- Some(name) => f.pad(name),
- None => write!(f, "{}", self.to_ratio()),
- }
- }
-}
-
impl Debug for FontStretch {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.pad(match *self {
@@ -733,6 +727,15 @@ impl Debug for FontStretch {
}
}
+impl Display for FontStretch {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ match self.to_str() {
+ Some(name) => f.pad(name),
+ None => write!(f, "{}", self.to_ratio()),
+ }
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;