aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs71
-rw-r--r--src/renderer/mod.rs33
2 files changed, 59 insertions, 45 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!
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index d800a1b5..81ac7fd4 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -166,13 +166,29 @@ impl GlyphCache {
let size = font.size();
// Load regular font
- let regular_desc = FontDesc::new(font.family(), font.style());
+ let regular_desc = if let Some(ref style) = font.normal.style {
+ FontDesc::new(&font.normal.family[..], font::Style::Specific(style.to_owned()))
+ } else {
+ let style = font::Style::Description {
+ slant: font::Slant::Normal,
+ weight: font::Weight::Normal
+ };
+ FontDesc::new(&font.normal.family[..], style)
+ };
+
let regular = rasterizer
.load_font(&regular_desc, size)?;
// Load bold font
- let bold_style = font.bold_style().unwrap_or("Bold");
- let bold_desc = FontDesc::new(font.family(), bold_style);
+ let bold_desc = if let Some(ref style) = font.bold.style {
+ FontDesc::new(&font.bold.family[..], font::Style::Specific(style.to_owned()))
+ } else {
+ let style = font::Style::Description {
+ slant: font::Slant::Normal,
+ weight: font::Weight::Bold
+ };
+ FontDesc::new(&font.bold.family[..], style)
+ };
let bold = if bold_desc == regular_desc {
regular
@@ -181,8 +197,15 @@ impl GlyphCache {
};
// Load italic font
- let italic_style = font.italic_style().unwrap_or("Italic");
- let italic_desc = FontDesc::new(font.family(), italic_style);
+ let italic_desc = if let Some(ref style) = font.italic.style {
+ FontDesc::new(&font.italic.family[..], font::Style::Specific(style.to_owned()))
+ } else {
+ let style = font::Style::Description {
+ slant: font::Slant::Italic,
+ weight: font::Weight::Normal
+ };
+ FontDesc::new(&font.italic.family[..], style)
+ };
let italic = if italic_desc == regular_desc {
regular