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 6 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
Binary file added .DS_Store
Binary file not shown.
36 changes: 18 additions & 18 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,22 +641,20 @@ 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)
}
}
}
let font_bytes: Option<Vec<u8>> = fontconfig::FontConfig::new()
.and_then(|font_config: fontconfig::FontConfig| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the type annotations in these and_then calls necessary? I'd be surprised if they are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they aren't. I just included them to aid my understanding through the implementation. Hopefully this next commit will compile, and then it will be ready (but maybe need to squash b/c so many were failing)

font_config.get_regular_family_fonts(&font_face)
})
.ok()
.and_then(|regular_family_fonts: Vec<std::path::PathBuf>| {
regular_family_fonts.iter().find(|p| {
p.extension().map(|e| e == "ttf").unwrap_or(false)
})
})
.and_then(|font: std::path::PathBuf| std::fs::read(font).ok());
match font_bytes {
Some(bytes) => self.font_data = bytes,
None => error!("No font could be found"),
}
}

Expand Down Expand Up @@ -714,7 +714,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 +928,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