From 0156379d8a20928f0090862fa616c81a067cd839 Mon Sep 17 00:00:00 2001 From: 5ohue <86558263+5ohue@users.noreply.github.com> Date: Sat, 11 May 2024 21:59:54 +0300 Subject: [PATCH] Add `LineCap` type --- src/types/line_cap.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/types/mod.rs | 2 ++ src/wand/drawing.rs | 3 ++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/types/line_cap.rs diff --git a/src/types/line_cap.rs b/src/types/line_cap.rs new file mode 100644 index 0000000..a5384ac --- /dev/null +++ b/src/types/line_cap.rs @@ -0,0 +1,39 @@ +use crate::bindings; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u32)] +pub enum LineCap { + Undefined = bindings::LineCap_UndefinedCap, + Butt = bindings::LineCap_ButtCap, + Round = bindings::LineCap_RoundCap, + Square = bindings::LineCap_SquareCap, +} + +impl Default for LineCap { + fn default() -> Self { + return LineCap::Undefined; + } +} + +impl From for bindings::LineCap { + fn from(value: LineCap) -> Self { + return value as bindings::LineCap; + } +} + +impl From for LineCap { + fn from(value: bindings::LineCap) -> Self { + /* + * SAFETY: + * + * `LineCap` has the same repr as `bindings::LineCap` - u32 + * + * If `value` is less than Square than it is in the vaild range and can be safely + * reinterpreted as `LineCap` + */ + if value <= bindings::LineCap_SquareCap { + return unsafe { std::mem::transmute(value) }; + } + return LineCap::default(); + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index 606b2f7..f3c0a33 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -11,6 +11,7 @@ mod filter_type; mod gravity_type; mod image_type; mod interlace_type; +mod line_cap; mod line_join; mod metric_type; mod orientation_type; @@ -35,6 +36,7 @@ pub use self::filter_type::FilterType; pub use self::gravity_type::GravityType; pub use self::image_type::ImageType; pub use self::interlace_type::InterlaceType; +pub use self::line_cap::LineCap; pub use self::line_join::LineJoin; pub use self::metric_type::MetricType; pub use self::orientation_type::OrientationType; diff --git a/src/wand/drawing.rs b/src/wand/drawing.rs index 60a4184..805458f 100644 --- a/src/wand/drawing.rs +++ b/src/wand/drawing.rs @@ -24,6 +24,7 @@ use crate::{ ClipPathUnits, FillRule, GravityType, + LineCap, LineJoin, StretchType, StyleType, @@ -107,7 +108,7 @@ impl DrawingWand { get_font_stretch, set_font_stretch, DrawGetFontStretch, DrawSetFontStretch, StretchType get_stroke_dash_offset, set_stroke_dash_offset, DrawGetStrokeDashOffset, DrawSetStrokeDashOffset, f64 - get_stroke_line_cap, set_stroke_line_cap, DrawGetStrokeLineCap, DrawSetStrokeLineCap, bindings::LineCap + get_stroke_line_cap, set_stroke_line_cap, DrawGetStrokeLineCap, DrawSetStrokeLineCap, LineCap get_stroke_line_join, set_stroke_line_join, DrawGetStrokeLineJoin, DrawSetStrokeLineJoin, LineJoin get_stroke_miter_limit, set_stroke_miter_limit, DrawGetStrokeMiterLimit, DrawSetStrokeMiterLimit, usize get_stroke_opacity, set_stroke_opacity, DrawGetStrokeOpacity, DrawSetStrokeOpacity, f64