Add freetype feature

Uses the upstream "imgui_freetype" to "Build font atlases using FreeType instead of stb_truetype (which is the default font rasterizer)"

Closes #359
This commit is contained in:
dbr 2021-06-10 23:50:44 +10:00
parent 774f8f46a7
commit fca87575fd
4 changed files with 21 additions and 0 deletions

View File

@ -18,7 +18,9 @@ chlorine = "1.0.7"
[build-dependencies]
cc = "1.0"
pkg-config = { version="0.3", optional=true }
[features]
default = []
wasm = []
freetype = ["pkg-config"]

View File

@ -48,6 +48,20 @@ fn main() -> io::Result<()> {
build.define(key, *value);
}
// Freetype font rasterizer feature
if std::env::var_os("CARGO_FEATURE_FREETYPE").is_some() {
let freetype = pkg_config::Config::new().find("freetype2").unwrap();
for include in freetype.include_paths.iter() {
build.include(include);
}
build.define("IMGUI_ENABLE_FREETYPE", None);
println!("cargo:DEFINE_{}={}", "IMGUI_ENABLE_FREETYPE", "");
// imgui_freetype.cpp needs access to imgui.h
build.include(
manifest_dir.join("third-party/imgui/"));
}
let compiler = build.get_compiler();
// Avoid the if-supported flag functions for easy cases, as they're
// kinda costly.

View File

@ -9,4 +9,8 @@
#include "./third-party/imgui/imgui_tables.cpp"
#include "./third-party/cimgui.cpp"
#ifdef IMGUI_ENABLE_FREETYPE
#include "./third-party/imgui/misc/freetype/imgui_freetype.cpp"
#endif

View File

@ -19,6 +19,7 @@ parking_lot = "0.11"
[features]
wasm = ["imgui-sys/wasm"]
freetype = ["imgui-sys/freetype"]
[dev-dependencies]
memoffset = "0.6"