1use std::ffi::{CStr, CString};
17use std::fmt;
18
19use crate::bindings;
20
21use crate::result::MagickError;
22use crate::result::Result;
23use crate::{
24 AlignType, ClipPathUnits, DecorationType, DirectionType, FillRule, GravityType, LineCap,
25 LineJoin, StretchType, StyleType,
26};
27
28wand_common!(
29 DrawingWand,
30 NewDrawingWand,
31 ClearDrawingWand,
32 IsDrawingWand,
33 CloneDrawingWand,
34 DestroyDrawingWand,
35 DrawClearException,
36 DrawGetExceptionType,
37 DrawGetException
38);
39
40impl DrawingWand {
41 pub fn draw_annotation(&mut self, x: f64, y: f64, text: &str) -> Result<()> {
42 let c_string = CString::new(text).map_err(|_| "could not convert to cstring")?;
43 unsafe { bindings::DrawAnnotation(self.wand, x, y, c_string.as_ptr() as *const _) };
44 Ok(())
45 }
46
47 pub fn draw_circle(&mut self, ox: f64, oy: f64, px: f64, py: f64) {
48 unsafe {
49 bindings::DrawCircle(self.wand, ox, oy, px, py);
50 }
51 }
52
53 pub fn draw_rectangle(
54 &mut self,
55 upper_left_x: f64,
56 upper_left_y: f64,
57 lower_right_x: f64,
58 lower_right_y: f64,
59 ) {
60 unsafe {
61 bindings::DrawRectangle(
62 self.wand,
63 upper_left_x,
64 upper_left_y,
65 lower_right_x,
66 lower_right_y,
67 );
68 }
69 }
70
71 string_set_get!(
72 get_font, set_font, DrawGetFont, DrawSetFont
73 get_font_family, set_font_family, DrawGetFontFamily, DrawSetFontFamily
74 get_vector_graphics, set_vector_graphics, DrawGetVectorGraphics, DrawSetVectorGraphics
75 get_clip_path, set_clip_path, DrawGetClipPath, DrawSetClipPath
76 );
77
78 string_set_get_unchecked!(
79 get_text_encoding,
80 set_text_encoding,
81 DrawGetTextEncoding,
82 DrawSetTextEncoding
83 );
84
85 pixel_set_get!(
86 get_border_color, set_border_color, DrawGetBorderColor, DrawSetBorderColor
87 get_fill_color, set_fill_color, DrawGetFillColor, DrawSetFillColor
88 get_stroke_color, set_stroke_color, DrawGetStrokeColor, DrawSetStrokeColor
89 get_text_under_color, set_text_under_color, DrawGetTextUnderColor, DrawSetTextUnderColor
90 );
91
92 set_get_unchecked!(
93 get_gravity, set_gravity, DrawGetGravity, DrawSetGravity, GravityType
94 get_opacity, set_opacity, DrawGetOpacity, DrawSetOpacity, f64
95 get_clip_rule, set_clip_rule, DrawGetClipRule, DrawSetClipRule, FillRule
96 get_clip_units, set_clip_units, DrawGetClipUnits, DrawSetClipUnits, ClipPathUnits
97 get_fill_rule, set_fill_rule, DrawGetFillRule, DrawSetFillRule, FillRule
98 get_fill_opacity, set_fill_opacity, DrawGetFillOpacity, DrawSetFillOpacity, f64
99
100 get_font_size, set_font_size, DrawGetFontSize, DrawSetFontSize, f64
101 get_font_style, set_font_style, DrawGetFontStyle, DrawSetFontStyle, StyleType
102 get_font_weight, set_font_weight, DrawGetFontWeight, DrawSetFontWeight, usize
103 get_font_stretch, set_font_stretch, DrawGetFontStretch, DrawSetFontStretch, StretchType
104
105 get_stroke_dash_offset, set_stroke_dash_offset, DrawGetStrokeDashOffset, DrawSetStrokeDashOffset, f64
106 get_stroke_line_cap, set_stroke_line_cap, DrawGetStrokeLineCap, DrawSetStrokeLineCap, LineCap
107 get_stroke_line_join, set_stroke_line_join, DrawGetStrokeLineJoin, DrawSetStrokeLineJoin, LineJoin
108 get_stroke_miter_limit, set_stroke_miter_limit, DrawGetStrokeMiterLimit, DrawSetStrokeMiterLimit, usize
109 get_stroke_opacity, set_stroke_opacity, DrawGetStrokeOpacity, DrawSetStrokeOpacity, f64
110 get_stroke_width, set_stroke_width, DrawGetStrokeWidth, DrawSetStrokeWidth, f64
111 get_stroke_antialias, set_stroke_antialias, DrawGetStrokeAntialias, DrawSetStrokeAntialias, bindings::MagickBooleanType
112
113 get_text_alignment, set_text_alignment, DrawGetTextAlignment, DrawSetTextAlignment, AlignType
114 get_text_antialias, set_text_antialias, DrawGetTextAntialias, DrawSetTextAntialias, bindings::MagickBooleanType
115 get_text_decoration, set_text_decoration, DrawGetTextDecoration, DrawSetTextDecoration, DecorationType
116 get_text_direction, set_text_direction, DrawGetTextDirection, DrawSetTextDirection, DirectionType
117 get_text_kerning, set_text_kerning, DrawGetTextKerning, DrawSetTextKerning, f64
118 get_text_interline_spacing, set_text_interline_spacing, DrawGetTextInterlineSpacing, DrawSetTextInterlineSpacing, f64
119 get_text_interword_spacing, set_text_interword_spacing, DrawGetTextInterwordSpacing, DrawSetTextInterwordSpacing, f64
120 );
121}
122
123impl fmt::Debug for DrawingWand {
124 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
125 writeln!(f, "DrawingWand {{")?;
126 writeln!(f, " Exception: {:?}", self.get_exception())?;
127 writeln!(f, " IsWand: {:?}", self.is_wand())?;
128 self.fmt_unchecked_settings(f, " ")?;
129 self.fmt_string_settings(f, " ")?;
130 self.fmt_string_unchecked_settings(f, " ")?;
131 self.fmt_pixel_settings(f, " ")?;
132 writeln!(f, "}}")
133 }
134}