diff --git a/src/types/decoration_type.rs b/src/types/decoration_type.rs new file mode 100644 index 0000000..a5d8efb --- /dev/null +++ b/src/types/decoration_type.rs @@ -0,0 +1,40 @@ +use crate::bindings; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u32)] +pub enum DecorationType { + Undefined = bindings::DecorationType_UndefinedDecoration, + No = bindings::DecorationType_NoDecoration, + Underline = bindings::DecorationType_UnderlineDecoration, + Overline = bindings::DecorationType_OverlineDecoration, + LineThrough = bindings::DecorationType_LineThroughDecoration, +} + +impl Default for DecorationType { + fn default() -> Self { + return DecorationType::Undefined; + } +} + +impl From for bindings::DecorationType { + fn from(value: DecorationType) -> Self { + return value as bindings::DecorationType; + } +} + +impl From for DecorationType { + fn from(value: bindings::DecorationType) -> Self { + /* + * SAFETY: + * + * `DecorationType` has the same repr as `bindings::DecorationType` - u32 + * + * If `value` is less than LineThrough than it is in the vaild range and can be safely + * reinterpreted as `DecorationType` + */ + if value <= bindings::DecorationType_LineThroughDecoration { + return unsafe { std::mem::transmute(value) }; + } + return DecorationType::default(); + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index ca01e03..a50eacc 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -4,6 +4,7 @@ mod clip_path_units; mod colorspace_type; mod composite_operator; mod compression_type; +mod decoration_type; mod dispose_type; mod dither_method; mod endian_type; @@ -30,6 +31,7 @@ pub use self::clip_path_units::ClipPathUnits; pub use self::colorspace_type::ColorspaceType; pub use self::composite_operator::CompositeOperator; pub use self::compression_type::CompressionType; +pub use self::decoration_type::DecorationType; pub use self::dispose_type::DisposeType; pub use self::dither_method::DitherMethod; pub use self::endian_type::EndianType; diff --git a/src/wand/drawing.rs b/src/wand/drawing.rs index a4d3b99..3637368 100644 --- a/src/wand/drawing.rs +++ b/src/wand/drawing.rs @@ -23,6 +23,7 @@ use crate::result::Result; use crate::{ AlignType, ClipPathUnits, + DecorationType, FillRule, GravityType, LineCap, @@ -118,7 +119,7 @@ impl DrawingWand { get_text_alignment, set_text_alignment, DrawGetTextAlignment, DrawSetTextAlignment, AlignType get_text_antialias, set_text_antialias, DrawGetTextAntialias, DrawSetTextAntialias, bindings::MagickBooleanType - get_text_decoration, set_text_decoration, DrawGetTextDecoration, DrawSetTextDecoration, bindings::DecorationType + get_text_decoration, set_text_decoration, DrawGetTextDecoration, DrawSetTextDecoration, DecorationType get_text_direction, set_text_direction, DrawGetTextDirection, DrawSetTextDirection, bindings::DirectionType get_text_kerning, set_text_kerning, DrawGetTextKerning, DrawSetTextKerning, f64 get_text_interline_spacing, set_text_interline_spacing, DrawGetTextInterlineSpacing, DrawSetTextInterlineSpacing, f64