Skip to content

Commit

Permalink
use font-loader instead of andrew's fontconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
elinorbgr committed Mar 4, 2021
1 parent 9cb00e9 commit de22104
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ wayland-client = "0.28"
wayland-protocols = { version = "0.28" , features = ["client", "unstable_protocols"] }
wayland-cursor = "0.28"
calloop = { version = "0.6.1", optional = true }
font-loader = { version = "0.11", optional = true }

[features]
default = ["frames", "calloop", "dlopen"]
dlopen = ["wayland-client/dlopen"]
frames = ["andrew"]
frames = ["andrew", "font-loader"]

[dev-dependencies]
image = "0.23"
23 changes: 7 additions & 16 deletions src/window/concept_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::cell::RefCell;
use std::cmp::max;
use std::rc::Rc;

use font_loader::system_fonts::{FontPropertyBuilder, get};

use andrew::line;
use andrew::shapes::rectangle;
use andrew::text;
use andrew::text::fontconfig;
use andrew::{Canvas, Endian};

use wayland_client::protocol::{
Expand Down Expand Up @@ -335,7 +336,7 @@ pub struct ConceptFrame {
surface_version: u32,
config: ConceptConfig,
title: Option<String>,
font_data: Option<Result<Vec<u8>, ()>>,
font_data: Option<Result<(Vec<u8>, i32), ()>>,
}

impl Frame for ConceptFrame {
Expand Down Expand Up @@ -640,20 +641,10 @@ impl Frame for ConceptFrame {
// If theres no stored font data, find the first ttf regular sans font and
// store it
if self.font_data.is_none() {
let font_bytes = fontconfig::FontConfig::new()
.ok()
.and_then(|font_config| {
font_config.get_regular_family_fonts(&font_face).ok()
})
.and_then(|regular_family_fonts| {
regular_family_fonts
.iter()
.cloned()
.find(|p| p.extension().map_or(false, |e| e == "ttf"))
})
.and_then(|font| std::fs::read(font).ok());
let property = FontPropertyBuilder::new().build();
let font_bytes = get(&property);
match font_bytes {
Some(bytes) => self.font_data = Some(Ok(bytes)),
Some((bytes, index)) => self.font_data = Some(Ok((bytes, index))),
None => {
error!("No font could be found");
self.font_data = Some(Err(()))
Expand All @@ -672,7 +663,7 @@ impl Frame for ConceptFrame {
* header_scale as usize,
),
title_color.into(),
font_data,
&font_data.0,
font_size * header_scale as f32,
1.0,
title,
Expand Down

0 comments on commit de22104

Please sign in to comment.