1 module dmagick.c.draw;
2 
3 import dmagick.c.composite;
4 import dmagick.c.geometry;
5 import dmagick.c.image;
6 import dmagick.c.magickType;
7 import dmagick.c.magickVersion;
8 import dmagick.c.pixel;
9 import dmagick.c.type;
10 
11 extern(C)
12 {
13 	/**
14 	 * Specify text alignment.
15 	 */
16 	enum AlignType
17 	{
18 		UndefinedAlign, /// No alignment specified. Equivalent to LeftAlign.
19 		LeftAlign,      /// Align the leftmost part of the text to the starting point.
20 		CenterAlign,    /// Center the text around the starting point.
21 		RightAlign      /// Align the rightmost part of the text to the starting point.
22 	}
23 
24 	/**
25 	 * Defines the coordinate system for the contents of a clip path.
26 	 */
27 	enum ClipPathUnits
28 	{
29 		/** */
30 		UndefinedPathUnits,
31 
32 		/**
33 		 * The contents of the clipPath represent values in the current
34 		 * user coordinate system.
35 		 */
36 		UserSpace,
37 
38 		/**
39 		 * The contents of the clipPath represent values in the current
40 		 * user coordinate system in place at the time when the clipPath
41 		 * element is referenced.
42 		 */
43 		UserSpaceOnUse,
44 
45 		/**
46 		 * The user coordinate system for the contents of the clipPath
47 		 * element is established using the bounding box of the element to
48 		 * which the clipping path is applied.
49 		 */
50 		ObjectBoundingBox
51 	}
52 
53 	/**
54 	 * Specify the text decoration.
55 	 */
56 	enum DecorationType
57 	{
58 		UndefinedDecoration,   ///
59 		NoDecoration,          /// Don't decorate the text.
60 		UnderlineDecoration,   /// Underline the text.
61 		OverlineDecoration,    /// Overline the text.
62 		LineThroughDecoration  /// Draw a horizontal line through the middle of the text.
63 	}
64 
65 	static if (MagickLibVersion >= 0x662)
66 	{
67 		/**
68 		 * Defines the text direction.
69 		 */
70 		enum DirectionType
71 		{
72 			UndefinedDirection,    ///
73 			RightToLeftDirection,  /// ditto
74 			LeftToRightDirection   /// ditto
75 		}
76 	}
77 	else
78 	{
79 		enum DirectionType
80 		{
81 			UndefinedDirection,
82 			LeftToRightDirection,
83 			RightToLeftDirection
84 		}
85 	}
86 
87 	/**
88 	 * FillRule indicates the algorithm which is to be used to determine
89 	 * what parts of the canvas are included inside the shape.
90 	 */
91 	enum FillRule
92 	{
93 		/** */
94 		UndefinedRule,
95 
96 		/**
97 		 * This rule determines the "insideness" of a point on the canvas by
98 		 * drawing a ray from that point to infinity in any direction and
99 		 * counting the number of path segments from the given shape that
100 		 * the ray crosses. If this number is odd, the point is inside; if
101 		 * even, the point is outside.
102 		 */
103 		EvenOddRule,
104 
105 		/**
106 		 * This rule determines the "insideness" of a point on the canvas by
107 		 * drawing a ray from that point to infinity in any direction and
108 		 * then examining the places where a segment of the shape crosses
109 		 * the ray. Starting with a count of zero, add one each time a path
110 		 * segment crosses the ray from left to right and subtract one each
111 		 * time a path segment crosses the ray from right to left. After
112 		 * counting the crossings, if the result is zero then the point is
113 		 * outside the path. Otherwise, it is inside.
114 		 */
115 		NonZeroRule
116 	}
117 
118 	enum GradientType
119 	{
120 		UndefinedGradient,
121 		LinearGradient,
122 		RadialGradient
123 	}
124 
125 	/**
126 	 * Specifies the shape to be used at the end of open subpaths when they
127 	 * are stroked.
128 	 * 
129 	 * See_Also: $(LINK2 http://www.w3.org/TR/SVG/painting.html#StrokeLinecapProperty,
130 	 *     the 'stroke-linecap' property) in the Scalable Vector Graphics (SVG)
131 	 *     1.1 Specification.
132 	 */
133 	enum LineCap
134 	{
135 		UndefinedCap, ///
136 		ButtCap,      /// ditto
137 		RoundCap,     /// ditto
138 		SquareCap     /// ditto
139 	}
140 
141 	/**
142 	 * Specifies the shape to be used at the corners of paths or basic
143 	 * shapes when they are stroked.
144 	 * 
145 	 * See_Also: $(LINK2 http://www.w3.org/TR/SVG/painting.html#StrokeLinejoinProperty,
146 	 *     the 'stroke-linejoin' property) in the Scalable Vector Graphics (SVG)
147 	 *     1.1 Specification.
148 	 */
149 	enum LineJoin
150 	{
151 		UndefinedJoin, ///
152 		MiterJoin,     /// ditto
153 		RoundJoin,     /// ditto
154 		BevelJoin      /// ditto
155 	}
156 
157 	/**
158 	 * Specify how pixel colors are to be replaced in the image.
159 	 */
160 	enum PaintMethod
161 	{
162 		/** */
163 		UndefinedMethod,
164 
165 		/**
166 		 * Replace pixel color at point.
167 		 */
168 		PointMethod,
169 
170 		/**
171 		 * Replace color for all image pixels matching color at point.
172 		 */
173 		ReplaceMethod,
174 
175 		/**
176 		 * Replace color for pixels surrounding point until encountering
177 		 * pixel that fails to match color at point.
178 		 */
179 		FloodfillMethod,
180 
181 		/**
182 		 * Replace color for pixels surrounding point until encountering
183 		 * pixels matching border color.
184 		 */
185 		FillToBorderMethod,
186 
187 		/**
188 		 * Replace colors for all pixels in image with fill color.
189 		 */
190 		ResetMethod
191 	}
192 
193 	enum PrimitiveType
194 	{
195 		UndefinedPrimitive,
196 		PointPrimitive,
197 		LinePrimitive,
198 		RectanglePrimitive,
199 		RoundRectanglePrimitive,
200 		ArcPrimitive,
201 		EllipsePrimitive,
202 		CirclePrimitive,
203 		PolylinePrimitive,
204 		PolygonPrimitive,
205 		BezierPrimitive,
206 		ColorPrimitive,
207 		MattePrimitive,
208 		TextPrimitive,
209 		ImagePrimitive,
210 		PathPrimitive
211 	}
212 
213 	enum ReferenceType
214 	{
215 		UndefinedReference,
216 		GradientReference
217 	}
218 
219 	enum SpreadMethod
220 	{
221 		UndefinedSpread,
222 		PadSpread,
223 		ReflectSpread,
224 		RepeatSpread
225 	}
226 
227 	struct PointInfo
228 	{
229 		double
230 			x,
231 			y;
232 	}
233 
234 	struct StopInfo
235 	{
236 		MagickPixelPacket
237 			color;
238 
239 		MagickRealType
240 			offset;
241 	}
242 
243 	struct GradientInfo
244 	{
245 		GradientType
246 			type;
247 
248 		RectangleInfo
249 			bounding_box;
250 
251 		SegmentInfo
252 			gradient_vector;
253 
254 		StopInfo*
255 			stops;
256 
257 		size_t
258 			number_stops;
259 
260 		SpreadMethod
261 			spread;
262 
263 		MagickBooleanType
264 			ddebug;
265 
266 		size_t
267 			signature;
268 
269 		PointInfo
270 			center;
271 
272 		MagickRealType
273 			radius;
274 	}
275 
276 	struct ElementReference
277 	{
278 		char*
279 			id;
280 
281 		ReferenceType
282 			type;
283 
284 		GradientInfo
285 			gradient;
286 
287 		size_t
288 			signature;
289 
290 		ElementReference*
291 			previous,
292 			next;
293 	}
294 
295 	struct DrawInfo
296 	{
297 		char*
298 			primitive,
299 			geometry;
300 
301 		RectangleInfo
302 			viewbox;
303 
304 		AffineMatrix
305 			affine;
306 
307 		GravityType
308 			gravity;
309 
310 		PixelPacket
311 			fill,
312 			stroke;
313 
314 		double
315 			stroke_width;
316 
317 		GradientInfo
318 			gradient;
319 
320 		Image*
321 			fill_pattern,
322 			tile,
323 			stroke_pattern;
324 
325 		MagickBooleanType
326 			stroke_antialias,
327 			text_antialias;
328 
329 		FillRule
330 			fill_rule;
331 
332 		LineCap
333 			linecap;
334 
335 		LineJoin
336 			linejoin;
337 
338 		size_t
339 			miterlimit;
340 
341 		double
342 			dash_offset;
343 
344 		DecorationType
345 			decorate;
346 
347 		CompositeOperator
348 			compose;
349 
350 		char*
351 			text;
352 
353 		size_t
354 			face;
355 
356 		char*
357 			font,
358 			metrics,
359 			family;
360 
361 		StyleType
362 			style;
363 
364 		StretchType
365 			stretch;
366 
367 		size_t
368 			weight;
369 
370 		char*
371 			encoding;
372 
373 		double
374 			pointsize;
375 
376 		char*
377 			density;
378 
379 		AlignType
380 			aalign;
381 
382 		PixelPacket
383 			undercolor,
384 			border_color;
385 
386 		char*
387 			server_name;
388 
389 		double*
390 			dash_pattern;
391 
392 		char*
393 			clip_mask;
394 
395 		SegmentInfo
396 			bounds;
397 
398 		ClipPathUnits
399 			clip_units;
400 
401 		Quantum
402 			opacity;
403 
404 		MagickBooleanType
405 			render;
406 
407 		ElementReference
408 			element_reference;
409 
410 		MagickBooleanType
411 			ddebug;
412 
413 		size_t
414 			signature;
415 
416 		double
417 			kerning,
418 			interword_spacing,
419 			interline_spacing;
420 
421 		static if (MagickLibVersion >= 0x662)
422 		{
423 			DirectionType
424 				direction;
425 		}
426 		else static if (MagickLibVersion == 0x661)
427 		{
428 			double
429 				direction;
430 		}
431 	}
432 
433 	struct PrimitiveInfo
434 	{
435 		PointInfo
436 			point;
437 
438 		size_t
439 			coordinates;
440 
441 		PrimitiveType
442 			primitive;
443 
444 		PaintMethod
445 			method;
446 
447 		char*
448 			text;
449 	}
450 
451 	/**
452 	 * This is used to reprecent text/font mesurements.
453 	 */
454 	struct TypeMetric
455 	{
456 		/**
457 		 * Horizontal (x) and vertical (y) pixels per em.
458 		 */
459 		PointInfo pixels_per_em;
460 
461 		/**
462 		 * The distance in pixels from the text baseline to the
463 		 * highest/upper grid coordinate used to place an outline point.
464 		 * Always a positive value.
465 		 */
466 		double ascent;
467 
468 		/**
469 		 * The distance in pixels from the baseline to the lowest grid
470 		 * coordinate used to place an outline point.
471 		 * Always a negative value.
472 		 */
473 		double descent;
474 
475 		/**
476 		 * Text width in pixels.
477 		 */
478 		double width;
479 
480 		/**
481 		 * Text height in pixels.
482 		 */
483 		double height;
484 
485 		/**
486 		 * The maximum horizontal advance (advance from the beginning
487 		 * of a character to the beginning of the next character) in
488 		 * pixels.
489 		 */
490 		double max_advance;
491 
492 		double underline_position;  ///
493 		double underline_thickness; ///
494 
495 		/**
496 		 * This is an imaginary box that encloses all glyphs from the font,
497 		 * usually as tightly as possible.
498 		 */
499 		SegmentInfo bounds;
500 
501 		/**
502 		 * A virtual point, located on the baseline, used to locate glyphs.
503 		 */
504 		PointInfo origin;
505 	}
506 
507 	DrawInfo* AcquireDrawInfo();
508 	DrawInfo* CloneDrawInfo(const(ImageInfo)*, const(DrawInfo)*);
509 	DrawInfo* DestroyDrawInfo(DrawInfo*);
510 
511 	MagickBooleanType DrawAffineImage(Image*, const(Image)*, const(AffineMatrix)*);
512 	MagickBooleanType DrawClipPath(Image*, const(DrawInfo)*, const(char)*);
513 	MagickBooleanType DrawGradientImage(Image*, const(DrawInfo)*);
514 	MagickBooleanType DrawImage(Image*, const(DrawInfo)*);
515 	MagickBooleanType DrawPatternPath(Image*, const(DrawInfo)*, const(char)*, Image**);
516 	MagickBooleanType DrawPrimitive(Image*, const(DrawInfo)*, const(PrimitiveInfo)*);
517 
518 	void GetAffineMatrix(AffineMatrix*);
519 	void GetDrawInfo(const(ImageInfo)*, DrawInfo*);
520 }