extern crate libc;
extern crate miniz_sys;
use libc::size_t;
use std::{convert, fmt, io};
#[cfg(not(test))]
#[link(name = "ots_glue", kind = "static")]
extern "C" {}
#[derive(Debug)]
pub enum Error {
InvalidFont,
IoError(io::Error),
}
impl fmt::Display for Error {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
<Self as fmt::Debug>::fmt(self, f)
}
}
impl convert::From<io::Error> for Error {
#[inline]
fn from(e: io::Error) -> Error {
Error::IoError(e)
}
}
#[inline]
pub fn process_and_write<W>(output: &mut W, font_data: &[u8]) -> Result<(), Error>
where
W: io::Write + io::Seek,
{
let mut stream = ffi::RustOTSStream {
wr: output,
error: None,
};
unsafe {
if 0 == ffi::RustOTS_Process(&mut stream, font_data.as_ptr(), font_data.len() as size_t) {
return Err(Error::InvalidFont);
}
}
match stream.error.take() {
Some(e) => Err(Error::IoError(e)),
None => Ok(()),
}
}
#[inline]
pub fn process(font_data: &[u8]) -> Result<Vec<u8>, Error> {
let mut out = io::Cursor::new(vec![]);
process_and_write(&mut out, font_data)?;
Ok(out.into_inner())
}
#[allow(non_snake_case)]
pub mod ffi;