#![no_std]
#![warn(clippy::pedantic)]
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]
#![allow(clippy::must_use_candidate)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::match_wildcard_for_single_variants)]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
mod accessor;
mod animation;
mod canvas;
mod error;
mod gradient;
mod lottie;
mod paint;
mod picture;
mod saver;
mod scene;
mod shape;
mod text;
pub use accessor::Accessor;
pub use animation::Animation;
pub use canvas::{ColorSpace, EngineOption, GlCanvas, SwCanvas, WgCanvas, WgTargetType};
pub use error::{Error, Result};
pub use gradient::{ColorStop, FillSpread, LinearGradient, RadialGradient};
pub use lottie::{LottieAnimation, Marker};
pub use paint::{BlendMethod, MaskMethod, Matrix, Paint, PaintType, Point};
pub use picture::{FilterMethod, Picture};
pub use saver::Saver;
pub use scene::Scene;
pub use shape::{FillRule, Shape, StrokeCap, StrokeJoin};
pub use text::{GlyphMetrics, Text, TextMetrics, TextWrap};
use thorvg_sys as ffi;
#[cfg(test)]
mod tests;
pub struct Thorvg {
_not_send_sync: core::marker::PhantomData<*const ()>,
}
impl Thorvg {
pub fn init(threads: u32) -> Result<Self> {
let result = unsafe { ffi::tvg_engine_init(threads) };
Error::from_raw(result)?;
Ok(Self {
_not_send_sync: core::marker::PhantomData,
})
}
pub fn version() -> Result<(u32, u32, u32, alloc::string::String)> {
let mut major: u32 = 0;
let mut minor: u32 = 0;
let mut micro: u32 = 0;
let mut version: *const core::ffi::c_char = core::ptr::null();
let result = unsafe {
ffi::tvg_engine_version(
&raw mut major,
&raw mut minor,
&raw mut micro,
&raw mut version,
)
};
Error::from_raw(result)?;
let version_str = if version.is_null() {
alloc::string::String::new()
} else {
unsafe { core::ffi::CStr::from_ptr(version) }
.to_string_lossy()
.into_owned()
};
Ok((major, minor, micro, version_str))
}
pub fn shape(&self) -> Shape<'_> {
Shape::new()
}
pub fn scene(&self) -> Scene<'_> {
Scene::new()
}
pub fn picture(&self) -> Picture<'_> {
Picture::new()
}
pub fn text(&self) -> Text<'_> {
Text::new()
}
pub fn linear_gradient(&self) -> LinearGradient<'_> {
LinearGradient::new()
}
pub fn radial_gradient(&self) -> RadialGradient<'_> {
RadialGradient::new()
}
pub fn sw_canvas(&self, option: EngineOption) -> Result<SwCanvas<'_>> {
SwCanvas::new(option)
}
pub fn gl_canvas(&self, option: EngineOption) -> Result<GlCanvas<'_>> {
GlCanvas::new(option)
}
pub fn wg_canvas(&self, option: EngineOption) -> Result<WgCanvas<'_>> {
WgCanvas::new(option)
}
pub fn animation(&self) -> Animation<'_> {
Animation::new()
}
pub fn lottie_animation(&self) -> LottieAnimation<'_> {
LottieAnimation::new()
}
pub fn saver(&self) -> Saver<'_> {
Saver::new()
}
pub fn accessor(&self) -> Accessor<'_> {
Accessor::new()
}
}
impl Drop for Thorvg {
fn drop(&mut self) {
unsafe {
ffi::tvg_engine_term();
}
}
}