diff --git a/src/types/align_type.rs b/src/types/align_type.rs new file mode 100644 index 0000000..c6a8c99 --- /dev/null +++ b/src/types/align_type.rs @@ -0,0 +1,39 @@ +use crate::bindings; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u32)] +pub enum AlignType { + Undefined = bindings::AlignType_UndefinedAlign, + Left = bindings::AlignType_LeftAlign, + Center = bindings::AlignType_CenterAlign, + Right = bindings::AlignType_RightAlign, +} + +impl Default for AlignType { + fn default() -> Self { + return AlignType::Undefined; + } +} + +impl From for bindings::AlignType { + fn from(value: AlignType) -> Self { + return value as bindings::AlignType; + } +} + +impl From for AlignType { + fn from(value: bindings::AlignType) -> Self { + /* + * SAFETY: + * + * `AlignType` has the same repr as `bindings::AlignType` - u32 + * + * If `value` is less than Right than it is in the vaild range and can be safely + * reinterpreted as `AlignType` + */ + if value <= bindings::AlignType_RightAlign { + return unsafe { std::mem::transmute(value) }; + } + return AlignType::default(); + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index f3c0a33..ca01e03 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,3 +1,4 @@ +mod align_type; mod alpha_channel_option; mod clip_path_units; mod colorspace_type; @@ -23,6 +24,7 @@ mod statistic_type; mod stretch_type; mod style_type; +pub use self::align_type::AlignType; pub use self::alpha_channel_option::AlphaChannelOption; pub use self::clip_path_units::ClipPathUnits; pub use self::colorspace_type::ColorspaceType; diff --git a/src/wand/drawing.rs b/src/wand/drawing.rs index 805458f..a4d3b99 100644 --- a/src/wand/drawing.rs +++ b/src/wand/drawing.rs @@ -21,6 +21,7 @@ use bindings; use crate::result::MagickError; use crate::result::Result; use crate::{ + AlignType, ClipPathUnits, FillRule, GravityType, @@ -115,7 +116,7 @@ impl DrawingWand { get_stroke_width, set_stroke_width, DrawGetStrokeWidth, DrawSetStrokeWidth, f64 get_stroke_antialias, set_stroke_antialias, DrawGetStrokeAntialias, DrawSetStrokeAntialias, bindings::MagickBooleanType - get_text_alignment, set_text_alignment, DrawGetTextAlignment, DrawSetTextAlignment, bindings::AlignType + 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_direction, set_text_direction, DrawGetTextDirection, DrawSetTextDirection, bindings::DirectionType