From 37915033559fbe867d5652b42a45f3b0ba062f0b Mon Sep 17 00:00:00 2001 From: Mika Vatanen Date: Mon, 13 Sep 2021 21:03:35 +0300 Subject: [PATCH 1/3] Windows fixes? --- fonts/.gitignore | 1 + src/lib.rs | 20 ++++++++++++++++++-- src/ttf.rs | 2 +- ttf2mesh-sys/build.rs | 3 ++- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 fonts/.gitignore diff --git a/fonts/.gitignore b/fonts/.gitignore new file mode 100644 index 0000000..6dba6e8 --- /dev/null +++ b/fonts/.gitignore @@ -0,0 +1 @@ +FiraMono-Medium.obj \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 8f5c26d..3106796 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ //! let mut ttf = TTFFile::from_file("./fonts/FiraMono-Medium.ttf").unwrap(); //! //! // export all glyphs as 2d meshes to a .obj file -//! ttf.export_to_obj("/dev/null", Quality::Low).unwrap(); +//! ttf.export_to_obj("./fonts/FiraMono-Medium.obj", Quality::Low).unwrap(); //! //! // generate 2d mesh for a glyph //! let mut glyph = ttf.glyph_from_char('€').unwrap(); @@ -29,7 +29,7 @@ //! ``` #![cfg_attr(feature = "unstable", feature(test))] -use std::{ffi::CString, os::unix::prelude::OsStrExt, path::Path}; +use std::{ffi::CString, path::Path}; mod error; mod glyph; @@ -47,10 +47,26 @@ pub use ttf::TTFFile; // TODO: support TTF_FEATURE_IGN_ERR as bitflag +#[cfg(not(windows))] fn path_to_cstring>(path: P) -> CString { + use os::unix::prelude::OsStrExt; CString::new(path.as_ref().as_os_str().as_bytes()).unwrap() } +#[cfg(windows)] +fn path_to_cstring>(path: P) -> CString { + // TODO: is this really ok? + CString::new( + path.as_ref() + .to_str() + .unwrap() + .to_string() + .as_bytes() + .to_vec(), + ) + .unwrap() +} + #[cfg(test)] mod tests { use std::path::PathBuf; diff --git a/src/ttf.rs b/src/ttf.rs index 995dc8c..2775005 100644 --- a/src/ttf.rs +++ b/src/ttf.rs @@ -23,7 +23,7 @@ use crate::{path_to_cstring, Error, Glyph, Quality}; /// assert_eq!(ttf.glyph_count(), 1485); /// /// // export all glyphs as 2d meshes to a .obj file -/// ttf.export_to_obj("/dev/null", Quality::Low).unwrap(); +/// ttf.export_to_obj("./fonts/FiraMono-Medium.obj", Quality::Low).unwrap(); /// /// // generate 2d mesh for a glyph /// let mut glyph = ttf.glyph_from_char('€').unwrap(); diff --git a/ttf2mesh-sys/build.rs b/ttf2mesh-sys/build.rs index 741bc6c..9db58ce 100644 --- a/ttf2mesh-sys/build.rs +++ b/ttf2mesh-sys/build.rs @@ -6,6 +6,8 @@ use std::path::PathBuf; fn main() { println!("cargo:rerun-if-changed=wrapper.h"); println!("cargo:rerun-if-changed=ttf2mesh/ttf2mesh.c"); + + #[cfg(unix)] println!("cargo:rustc-link-lib=m"); let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); @@ -50,7 +52,6 @@ fn main() { cc::Build::new() .flag("-Wall") - .flag("-Wextra") .flag("-pedantic") .flag("-std=c99") .flag("-D_POSIX_C_SOURCE=199309L") From e3121f1244a7d2640d4c66894761b54eda1f75c9 Mon Sep 17 00:00:00 2001 From: Mika Vatanen Date: Mon, 13 Sep 2021 22:45:10 +0300 Subject: [PATCH 2/3] Fix test --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 3106796..f1e238a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,7 @@ pub use ttf::TTFFile; #[cfg(not(windows))] fn path_to_cstring>(path: P) -> CString { - use os::unix::prelude::OsStrExt; + use std::os::unix::ffi::OsStrExt; CString::new(path.as_ref().as_os_str().as_bytes()).unwrap() } From 16c5948973e7af3e94f9cd1598db7c052d360c73 Mon Sep 17 00:00:00 2001 From: Mika Vatanen Date: Mon, 27 Sep 2021 20:36:40 +0300 Subject: [PATCH 3/3] Windows cstring --- src/lib.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f1e238a..51c9538 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,16 +55,7 @@ fn path_to_cstring>(path: P) -> CString { #[cfg(windows)] fn path_to_cstring>(path: P) -> CString { - // TODO: is this really ok? - CString::new( - path.as_ref() - .to_str() - .unwrap() - .to_string() - .as_bytes() - .to_vec(), - ) - .unwrap() + CString::new(path.as_ref().as_os_str().to_str().unwrap()).unwrap() } #[cfg(test)]