diff --git a/src/types/direction_type.rs b/src/types/direction_type.rs new file mode 100644 index 0000000..7bcaa2b --- /dev/null +++ b/src/types/direction_type.rs @@ -0,0 +1,39 @@ +use crate::bindings; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u32)] +pub enum DirectionType { + Undefined = bindings::DirectionType_UndefinedDirection, + RightToLeft = bindings::DirectionType_RightToLeftDirection, + LeftToRight = bindings::DirectionType_LeftToRightDirection, + TopToBottom = bindings::DirectionType_TopToBottomDirection, +} + +impl Default for DirectionType { + fn default() -> Self { + return DirectionType::Undefined; + } +} + +impl From for bindings::DirectionType { + fn from(value: DirectionType) -> Self { + return value as bindings::DirectionType; + } +} + +impl From for DirectionType { + fn from(value: bindings::DirectionType) -> Self { + /* + * SAFETY: + * + * `DirectionType` has the same repr as `bindings::DirectionType` - u32 + * + * If `value` is less than TopToBottom than it is in the vaild range and can be safely + * reinterpreted as `DirectionType` + */ + if value <= bindings::DirectionType_TopToBottomDirection { + return unsafe { std::mem::transmute(value) }; + } + return DirectionType::default(); + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index a50eacc..762c77a 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -5,6 +5,7 @@ mod colorspace_type; mod composite_operator; mod compression_type; mod decoration_type; +mod direction_type; mod dispose_type; mod dither_method; mod endian_type; @@ -32,6 +33,7 @@ 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::direction_type::DirectionType; 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 3637368..c918703 100644 --- a/src/wand/drawing.rs +++ b/src/wand/drawing.rs @@ -24,6 +24,7 @@ use crate::{ AlignType, ClipPathUnits, DecorationType, + DirectionType, FillRule, GravityType, LineCap, @@ -120,7 +121,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, DecorationType - get_text_direction, set_text_direction, DrawGetTextDirection, DrawSetTextDirection, bindings::DirectionType + get_text_direction, set_text_direction, DrawGetTextDirection, DrawSetTextDirection, DirectionType get_text_kerning, set_text_kerning, DrawGetTextKerning, DrawSetTextKerning, f64 get_text_interline_spacing, set_text_interline_spacing, DrawGetTextInterlineSpacing, DrawSetTextInterlineSpacing, f64 get_text_interword_spacing, set_text_interword_spacing, DrawGetTextInterwordSpacing, DrawSetTextInterwordSpacing, f64