Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ready for Review: Fix font-config crash #168

Merged
merged 22 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 36 additions & 15 deletions src/window/concept_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use wayland_client::protocol::{
};
use wayland_client::{Attached, DispatchData};

use log::error;

use super::{
ARGBColor, ButtonColorSpec, ButtonState, ColorSpec, Frame, FrameRequest, State, WindowState,
};
Expand Down Expand Up @@ -639,21 +641,40 @@ 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() {
if let Some(font) = fontconfig::FontConfig::new()
.unwrap()
.get_regular_family_fonts(&font_face)
.unwrap()
.iter()
.find(|p| p.extension().map(|e| e == "ttf").unwrap_or(false))
{
let mut font_data = Vec::new();
if let Ok(mut file) = ::std::fs::File::open(font) {
match file.read_to_end(&mut font_data) {
Ok(_) => self.font_data = Some(font_data),
Err(err) => {
log::error!("Could not read font file: {}", err)
match fontconfig::FontConfig::new() {
Ok(font_config) => match font_config
.get_regular_family_fonts(&font_face)
{
Ok(regular_family_fonts) => match regular_family_fonts
.iter()
.find(|p| {
p.extension().map(|e| e == "ttf").unwrap_or(false)
}) {
Some(font) => {
let mut font_data = Vec::new();
match std::fs::File::open(font) {
Ok(mut file) => match file
.read_to_end(&mut font_data)
{
Ok(_) => self.font_data = Some(font_data),
Err(err) => error!(
"Could not read font file: {}",
err
),
},
Err(err) => {
error!("Could not open font file: {}", err)
}
}
}
None => error!("No ttf font found"),
},
Err(err) => {
error!("No regular sans font family found: {}", err)
}
},
Err(_) => {
error!("Could not load font config file")
brightly-salty marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -714,7 +735,7 @@ impl Frame for ConceptFrame {
}
}
if let Err(err) = mmap.flush() {
log::error!("Failed to flush frame memory map: {}", err);
error!("Failed to flush frame memory map: {}", err);
}
}

Expand Down Expand Up @@ -928,7 +949,7 @@ fn change_pointer(pointer: &ThemedPointer, inner: &Inner, location: Location, se
};

if pointer.set_cursor(name, serial).is_err() {
log::error!("Failed to set cursor");
error!("Failed to set cursor");
}
}

Expand Down
1 change: 1 addition & 0 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl<F: Frame + 'static> Window<F> {
///
/// Providing non `None` value for `theme_manager` should prevent theming pointer
/// over the `surface`.
#[allow(clippy::match_like_matches_macro)]
brightly-salty marked this conversation as resolved.
Show resolved Hide resolved
fn init_with_decorations<Impl, E>(
env: &crate::environment::Environment<E>,
surface: wl_surface::WlSurface,
Expand Down