diff --git a/src/types/fill_rule.rs b/src/types/fill_rule.rs new file mode 100644 index 0000000..d48bf66 --- /dev/null +++ b/src/types/fill_rule.rs @@ -0,0 +1,38 @@ +use crate::bindings; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u32)] +pub enum FillRule { + Undefined = bindings::FillRule_UndefinedRule, + EvenOdd = bindings::FillRule_EvenOddRule, + NonZero = bindings::FillRule_NonZeroRule, +} + +impl Default for FillRule { + fn default() -> Self { + return FillRule::Undefined; + } +} + +impl From for bindings::FillRule { + fn from(value: FillRule) -> Self { + return value as bindings::FillRule; + } +} + +impl From for FillRule { + fn from(value: bindings::FillRule) -> Self { + /* + * SAFETY: + * + * `FillRule` has the same repr as `bindings::FillRule` - u32 + * + * If `value` is less than NonZero than it is in the vaild range and can be safely + * reinterpreted as `FillRule` + */ + if value <= bindings::FillRule_NonZeroRule { + return unsafe { std::mem::transmute(value) }; + } + return FillRule::default(); + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index ccc17b5..c21e5ed 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -5,6 +5,7 @@ mod compression_type; mod dispose_type; mod dither_method; mod endian_type; +mod fill_rule; mod filter_type; mod gravity_type; mod image_type; @@ -24,6 +25,7 @@ pub use self::compression_type::CompressionType; pub use self::dispose_type::DisposeType; pub use self::dither_method::DitherMethod; pub use self::endian_type::EndianType; +pub use self::fill_rule::FillRule; pub use self::filter_type::FilterType; pub use self::gravity_type::GravityType; pub use self::image_type::ImageType; diff --git a/src/wand/drawing.rs b/src/wand/drawing.rs index 16012d8..39b6bbf 100644 --- a/src/wand/drawing.rs +++ b/src/wand/drawing.rs @@ -20,7 +20,10 @@ use bindings; use crate::result::MagickError; use crate::result::Result; -use crate::GravityType; +use crate::{ + FillRule, + GravityType, +}; wand_common!( DrawingWand, @@ -89,9 +92,9 @@ impl DrawingWand { set_get_unchecked!( get_gravity, set_gravity, DrawGetGravity, DrawSetGravity, GravityType get_opacity, set_opacity, DrawGetOpacity, DrawSetOpacity, f64 - get_clip_rule, set_clip_rule, DrawGetClipRule, DrawSetClipRule, bindings::FillRule + get_clip_rule, set_clip_rule, DrawGetClipRule, DrawSetClipRule, FillRule get_clip_units, set_clip_units, DrawGetClipUnits, DrawSetClipUnits, bindings::ClipPathUnits - get_fill_rule, set_fill_rule, DrawGetFillRule, DrawSetFillRule, bindings::FillRule + get_fill_rule, set_fill_rule, DrawGetFillRule, DrawSetFillRule, FillRule get_fill_opacity, set_fill_opacity, DrawGetFillOpacity, DrawSetFillOpacity, f64 get_font_size, set_font_size, DrawGetFontSize, DrawSetFontSize, f64