diff options
Diffstat (limited to 'font/src/ft/fc/mod.rs')
-rw-r--r-- | font/src/ft/fc/mod.rs | 195 |
1 files changed, 165 insertions, 30 deletions
diff --git a/font/src/ft/fc/mod.rs b/font/src/ft/fc/mod.rs index d0a55fad..c4cb40eb 100644 --- a/font/src/ft/fc/mod.rs +++ b/font/src/ft/fc/mod.rs @@ -13,6 +13,7 @@ // limitations under the License. // use std::ptr; +use std::fmt; use foreign_types::{ForeignType, ForeignTypeRef}; @@ -27,19 +28,19 @@ use self::ffi::{FC_WEIGHT_THIN, FC_WEIGHT_EXTRALIGHT, FC_WEIGHT_LIGHT}; use self::ffi::{FC_WEIGHT_BOOK, FC_WEIGHT_REGULAR, FC_WEIGHT_MEDIUM, FC_WEIGHT_SEMIBOLD}; use self::ffi::{FC_WEIGHT_BOLD, FC_WEIGHT_EXTRABOLD, FC_WEIGHT_BLACK, FC_WEIGHT_EXTRABLACK}; -mod config; +pub mod config; pub use self::config::{Config, ConfigRef}; -mod font_set; +pub mod font_set; pub use self::font_set::{FontSet, FontSetRef}; -mod object_set; +pub mod object_set; pub use self::object_set::{ObjectSet, ObjectSetRef}; -mod char_set; +pub mod char_set; pub use self::char_set::{CharSet, CharSetRef}; -mod pattern; +pub mod pattern; pub use self::pattern::{Pattern, PatternRef}; /// Find the font closest matching the provided pattern. @@ -162,6 +163,143 @@ pub enum Weight { Extrablack = FC_WEIGHT_EXTRABLACK as isize, } +#[derive(Debug, Copy, Clone)] +pub enum Width { + Ultracondensed, + Extracondensed, + Condensed, + Semicondensed, + Normal, + Semiexpanded, + Expanded, + Extraexpanded, + Ultraexpanded, + Other(i32) +} + +impl Width { + fn to_isize(&self) -> isize { + use self::Width::*; + match *self { + Ultracondensed => 50, + Extracondensed => 63, + Condensed => 75, + Semicondensed => 87, + Normal => 100, + Semiexpanded => 113, + Expanded => 125, + Extraexpanded => 150, + Ultraexpanded => 200, + Other(value) => value as isize + } + } +} + +impl From<isize> for Width { + fn from(value: isize) -> Self { + match value { + 50 => Width::Ultracondensed, + 63 => Width::Extracondensed, + 75 => Width::Condensed, + 87 => Width::Semicondensed, + 100 => Width::Normal, + 113 => Width::Semiexpanded, + 125 => Width::Expanded, + 150 => Width::Extraexpanded, + 200 => Width::Ultraexpanded, + _ => Width::Other(value as _) + } + } +} + +/// Subpixel geometry +pub enum Rgba { + Unknown, + Rgb, + Bgr, + Vrgb, + Vbgr, + None +} + +impl Rgba { + fn to_isize(&self) -> isize { + match *self { + Rgba::Unknown => 0, + Rgba::Rgb => 1, + Rgba::Bgr => 2, + Rgba::Vrgb => 3, + Rgba::Vbgr => 4, + Rgba::None => 5 + } + } +} + +impl fmt::Display for Rgba { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use self::Rgba::*; + f.write_str(match *self { + Unknown => "unknown", + Rgb => "rgb", + Bgr => "bgr", + Vrgb => "vrgb", + Vbgr => "vbgr", + None => "none", + }) + } +} + +impl From<isize> for Rgba { + fn from(val: isize) -> Rgba { + match val { + 1 => Rgba::Rgb, + 2 => Rgba::Bgr, + 3 => Rgba::Vrgb, + 4 => Rgba::Vbgr, + 5 => Rgba::None, + _ => Rgba::Unknown, + } + } +} + +/// Hinting Style +#[derive(Debug, Copy, Clone)] +pub enum HintStyle { + None, + Slight, + Medium, + Full +} + +impl fmt::Display for HintStyle { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(match *self { + HintStyle::None => "none", + HintStyle::Slight => "slight", + HintStyle::Medium => "medium", + HintStyle::Full => "full", + }) + } +} + +/// Lcd filter, used to reduce color fringing with subpixel rendering +pub enum LcdFilter { + None, + Default, + Light, + Legacy +} + +impl fmt::Display for LcdFilter { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(match *self { + LcdFilter::None => "none", + LcdFilter::Default => "default", + LcdFilter::Light => "light", + LcdFilter::Legacy => "legacy", + }) + } +} #[cfg(test)] mod tests { @@ -176,15 +314,17 @@ mod tests { let config = Config::get_current(); let font = super::font_match(config, &mut pattern).expect("match font monospace"); - print!("family={:?}", font.family(0)); - for i in 0.. { - if let Some(style) = font.style(i) { - print!(", style={:?}, ", style); - } else { - break; - } - } - info!(""); + print!("index={:?}; ", font.index()); + print!("family={:?}; ", font.family()); + print!("style={:?}; ", font.style()); + print!("antialias={:?}; ", font.antialias()); + print!("autohint={:?}; ", font.autohint()); + print!("hinting={:?}; ", font.hinting()); + print!("rgba={:?}; ", font.rgba()); + print!("embeddedbitmap={:?}; ", font.embeddedbitmap()); + print!("lcdfilter={:?}; ", font.lcdfilter()); + print!("hintstyle={:?}", font.hintstyle()); + println!(""); } #[test] @@ -198,14 +338,12 @@ mod tests { .expect("sort font monospace"); for font in fonts.into_iter().take(10) { - print!("family={:?}", font.family(0)); - for i in 0.. { - if let Some(style) = font.style(i) { - print!(", style={:?}", style); - } else { - break; - } - } + let font = font.render_prepare(&config, &pattern); + print!("index={:?}; ", font.index()); + print!("family={:?}; ", font.family()); + print!("style={:?}; ", font.style()); + print!("rgba={:?}", font.rgba()); + print!("rgba={:?}", font.rgba()); println!(""); } } @@ -222,14 +360,11 @@ mod tests { let fonts = super::font_sort(config, &mut pattern).expect("font_sort"); for font in fonts.into_iter().take(10) { - print!("family={:?}", font.family(0)); - for i in 0.. { - if let Some(style) = font.style(i) { - print!(", style={:?}", style); - } else { - break; - } - } + let font = font.render_prepare(&config, &pattern); + print!("index={:?}; ", font.index()); + print!("family={:?}; ", font.family()); + print!("style={:?}; ", font.style()); + print!("rgba={:?}", font.rgba()); println!(""); } } |