[librsvg: 32/53] Add code to create a FontConfig
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 32/53] Add code to create a FontConfig
- Date: Fri, 23 Oct 2020 02:19:07 +0000 (UTC)
commit 17fe8df2b4952f6826ccb316a6de510345ae8d4d
Author: Sven Neumann <sven svenfoo org>
Date: Wed Oct 21 17:08:19 2020 +0200
Add code to create a FontConfig
tests/Cargo.toml | 1 +
tests/src/utils.rs | 28 +++++++++++++++++++++++++++-
2 files changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/tests/Cargo.toml b/tests/Cargo.toml
index c482c2be..2a45fedb 100644
--- a/tests/Cargo.toml
+++ b/tests/Cargo.toml
@@ -22,6 +22,7 @@ predicates = "1.0.2"
rsvg_internals = { path = "../rsvg_internals" }
tempfile = "3"
test-generator = "0.3"
+yeslogic-fontconfig-sys = "2.11.1"
[build-dependencies]
pkg-config = "0.3.14"
diff --git a/tests/src/utils.rs b/tests/src/utils.rs
index b009cf5b..ccb9caf4 100644
--- a/tests/src/utils.rs
+++ b/tests/src/utils.rs
@@ -3,6 +3,8 @@
use std::env;
use std::path::PathBuf;
+#[cfg(have_pangoft2)]
+
/// Given a filename from `test_generator::test_resources`, computes the correct fixture filename.
///
/// The `test_resources` procedural macro works by running a filename glob starting on
@@ -22,12 +24,36 @@ pub fn fixture_path(filename_from_test_resources: &str) -> PathBuf {
#[cfg(have_pangoft2)]
pub fn setup_font_map() {
+ use fontconfig_sys::fontconfig;
use glib::prelude::*;
use pangocairo::FontMap;
+ let font_paths = [
+ "tests/resources/Roboto-Regular.ttf",
+ "tests/resources/Roboto-Italic.ttf",
+ "tests/resources/Roboto-Bold.ttf",
+ "tests/resources/Roboto-BoldItalic.ttf",
+ ];
+
+ let config = unsafe { fontconfig::FcConfigCreate() };
+
+ for path in &font_paths {
+ let path = fixture_path(path);
+ let str = path.to_str().unwrap();
+
+ unsafe {
+ if fontconfig::FcConfigAppFontAddFile(config, str.as_ptr()) == 0 {
+ panic!("Could not load font file {} for tests; aborting", str);
+ }
+ };
+ }
+
let font_map = FontMap::new_for_font_type(cairo::FontType::FontTypeFt);
- // TODO: create and apply FontConfig
+ // TODO: apply config
+ unsafe {
+ fontconfig::FcConfigDestroy(config);
+ };
FontMap::set_default(font_map.map(|m| m.downcast::<pangocairo::FontMap>().unwrap()));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]