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 /src/config.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 'src/config.rs')
-rw-r--r-- | src/config.rs | 71 |
1 files changed, 31 insertions, 40 deletions
diff --git a/src/config.rs b/src/config.rs index abf0bdf5..59b9f5ea 100644 --- a/src/config.rs +++ b/src/config.rs @@ -977,16 +977,13 @@ impl DeserializeFromF32 for Size { #[derive(Debug, Deserialize)] pub struct Font { /// Font family - family: String, + pub normal: FontDescription, - /// Font style - style: String, + #[serde(default="default_italic_desc")] + pub italic: FontDescription, - /// Bold font style - bold_style: Option<String>, - - /// Italic font style - italic_style: Option<String>, + #[serde(default="default_bold_desc")] + pub bold: FontDescription, // Font size in points #[serde(deserialize_with="DeserializeFromF32::deserialize_from_f32")] @@ -996,35 +993,31 @@ pub struct Font { offset: FontOffset, } -impl Font { - /// Get the font family - #[inline] - pub fn family(&self) -> &str { - &self.family[..] - } +fn default_bold_desc() -> FontDescription { + Font::default().bold +} - /// Get the font style - #[inline] - pub fn style(&self) -> &str { - &self.style[..] - } +fn default_italic_desc() -> FontDescription { + Font::default().italic +} - /// Get italic font style; assumes same family - #[inline] - pub fn italic_style(&self) -> Option<&str> { - self.italic_style - .as_ref() - .map(|s| s.as_str()) - } +/// Description of a single font +#[derive(Debug, Deserialize)] +pub struct FontDescription { + pub family: String, + pub style: Option<String>, +} - /// Get bold font style; assumes same family - #[inline] - pub fn bold_style(&self) -> Option<&str> { - self.bold_style - .as_ref() - .map(|s| s.as_str()) +impl FontDescription { + fn new_with_family<S: Into<String>>(family: S) -> FontDescription { + FontDescription { + family: family.into(), + style: None, + } } +} +impl Font { /// Get the font size in points #[inline] pub fn size(&self) -> Size { @@ -1042,11 +1035,10 @@ impl Font { impl Default for Font { fn default() -> Font { Font { - family: String::from("Menlo"), - style: String::from("Regular"), + normal: FontDescription::new_with_family("Menlo"), + bold: FontDescription::new_with_family("Menlo"), + italic: FontDescription::new_with_family("Menlo"), size: Size::new(11.0), - bold_style: Some(String::from("Bold")), - italic_style: Some(String::from("Italic")), offset: FontOffset { x: 0.0, y: 0.0 @@ -1059,11 +1051,10 @@ impl Default for Font { impl Default for Font { fn default() -> Font { Font { - family: String::from("DejaVu Sans Mono"), - style: String::from("Book"), + normal: FontDescription::new_with_family("monospace"), + bold: FontDescription::new_with_family("monospace"), + italic: FontDescription::new_with_family("monospace"), size: Size::new(11.0), - bold_style: Some(String::from("Bold")), - italic_style: Some(String::from("Italic")), offset: FontOffset { // TODO should improve freetype metrics... shouldn't need such // drastic offsets for the default! |