diff options
author | Joe Wilm <joe@jwilm.com> | 2017-01-02 18:52:41 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2017-01-02 19:49:38 -0800 |
commit | 86301856391b05047f1fd9f2e8999d61b26d982e (patch) | |
tree | 2163b2fead9d1c45bb72670b32558cb781f2d4a5 /font/src/lib.rs | |
parent | 04d69e3c2902bca56605ad59e60b2ae1e5ce91a3 (diff) | |
download | alacritty-86301856391b05047f1fd9f2e8999d61b26d982e.tar.gz alacritty-86301856391b05047f1fd9f2e8999d61b26d982e.zip |
Rework font loading
This work started because we wanted to be able to simply say "monospace"
on Linux and have it give us some sort of font. The config format for
fonts changed to accomodate this new paradigm. As a result, italic and
bold can have different families from the normal (roman) face.
The fontconfig based font resolution probably works a lot better than
the CoreText version at this point. With CoreText, we simply iterate
over fonts and check it they match the requested properties. What's
worse is that the CoreText version requires a valid family. With
fontconfig, it will just provide the closest matching thing and use it
(unless a specific style is requested).
Diffstat (limited to 'font/src/lib.rs')
-rw-r--r-- | font/src/lib.rs | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/font/src/lib.rs b/font/src/lib.rs index afe2b94f..bc4a2006 100644 --- a/font/src/lib.rs +++ b/font/src/lib.rs @@ -57,16 +57,47 @@ pub use darwin::*; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FontDesc { name: String, - style: String, + style: Style, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum Slant { + Normal, + Italic, + Oblique, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum Weight { + Normal, + Bold +} + +/// Style of font +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum Style { + Specific(String), + Description { slant: Slant, weight: Weight } +} + +impl fmt::Display for Style { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Style::Specific(ref s) => f.write_str(&s), + Style::Description { slant, weight } => { + write!(f, "slant={:?}, weight={:?}", slant, weight) + }, + } + } } impl FontDesc { - pub fn new<S>(name: S, style: S) -> FontDesc + pub fn new<S>(name: S, style: Style) -> FontDesc where S: Into<String> { FontDesc { name: name.into(), - style: style.into() + style: style } } } |