Skip to content

Commit

Permalink
Merge pull request #2 from blaind/fix-windows
Browse files Browse the repository at this point in the history
Fix compilation on windows
  • Loading branch information
blaind authored Sep 27, 2021
2 parents b45fa85 + 16c5948 commit e7f0c03
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions fonts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FiraMono-Medium.obj
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -47,10 +47,17 @@ pub use ttf::TTFFile;

// TODO: support TTF_FEATURE_IGN_ERR as bitflag

#[cfg(not(windows))]
fn path_to_cstring<P: AsRef<Path>>(path: P) -> CString {
use std::os::unix::ffi::OsStrExt;
CString::new(path.as_ref().as_os_str().as_bytes()).unwrap()
}

#[cfg(windows)]
fn path_to_cstring<P: AsRef<Path>>(path: P) -> CString {
CString::new(path.as_ref().as_os_str().to_str().unwrap()).unwrap()
}

#[cfg(test)]
mod tests {
use std::path::PathBuf;
Expand Down
2 changes: 1 addition & 1 deletion src/ttf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion ttf2mesh-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -50,7 +52,6 @@ fn main() {

cc::Build::new()
.flag("-Wall")
.flag("-Wextra")
.flag("-pedantic")
.flag("-std=c99")
.flag("-D_POSIX_C_SOURCE=199309L")
Expand Down

0 comments on commit e7f0c03

Please sign in to comment.