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 		static if ( MagickLibVersion >= 0x693 )
276 		{
277 			MagickRealType
278 				angle;
279 
280 			PointInfo
281 				radii;
282 		}
283 	}
284 
285 	struct ElementReference
286 	{
287 		char*
288 			id;
289 
290 		ReferenceType
291 			type;
292 
293 		GradientInfo
294 			gradient;
295 
296 		size_t
297 			signature;
298 
299 		ElementReference*
300 			previous,
301 			next;
302 	}
303 
304 	struct DrawInfo
305 	{
306 		char*
307 			primitive,
308 			geometry;
309 
310 		RectangleInfo
311 			viewbox;
312 
313 		AffineMatrix
314 			affine;
315 
316 		GravityType
317 			gravity;
318 
319 		PixelPacket
320 			fill,
321 			stroke;
322 
323 		double
324 			stroke_width;
325 
326 		GradientInfo
327 			gradient;
328 
329 		Image*
330 			fill_pattern,
331 			tile,
332 			stroke_pattern;
333 
334 		MagickBooleanType
335 			stroke_antialias,
336 			text_antialias;
337 
338 		FillRule
339 			fill_rule;
340 
341 		LineCap
342 			linecap;
343 
344 		LineJoin
345 			linejoin;
346 
347 		size_t
348 			miterlimit;
349 
350 		double
351 			dash_offset;
352 
353 		DecorationType
354 			decorate;
355 
356 		CompositeOperator
357 			compose;
358 
359 		char*
360 			text;
361 
362 		size_t
363 			face;
364 
365 		char*
366 			font,
367 			metrics,
368 			family;
369 
370 		StyleType
371 			style;
372 
373 		StretchType
374 			stretch;
375 
376 		size_t
377 			weight;
378 
379 		char*
380 			encoding;
381 
382 		double
383 			pointsize;
384 
385 		char*
386 			density;
387 
388 		AlignType
389 			aalign;
390 
391 		PixelPacket
392 			undercolor,
393 			border_color;
394 
395 		char*
396 			server_name;
397 
398 		double*
399 			dash_pattern;
400 
401 		char*
402 			clip_mask;
403 
404 		SegmentInfo
405 			bounds;
406 
407 		ClipPathUnits
408 			clip_units;
409 
410 		Quantum
411 			opacity;
412 
413 		MagickBooleanType
414 			render;
415 
416 		ElementReference
417 			element_reference;
418 
419 		MagickBooleanType
420 			ddebug;
421 
422 		size_t
423 			signature;
424 
425 		double
426 			kerning,
427 			interword_spacing,
428 			interline_spacing;
429 
430 		static if (MagickLibVersion >= 0x662)
431 		{
432 			DirectionType
433 				direction;
434 		}
435 		else static if (MagickLibVersion == 0x661)
436 		{
437 			double
438 				direction;
439 		}
440 
441 		static if (MagickLibVersion >= 0x695)
442 		{
443 			double
444 				fill_opacity,
445 				stroke_opacity;
446 		}
447 	}
448 
449 	struct PrimitiveInfo
450 	{
451 		PointInfo
452 			point;
453 
454 		size_t
455 			coordinates;
456 
457 		PrimitiveType
458 			primitive;
459 
460 		PaintMethod
461 			method;
462 
463 		char*
464 			text;
465 	}
466 
467 	/**
468 	 * This is used to reprecent text/font mesurements.
469 	 */
470 	struct TypeMetric
471 	{
472 		/**
473 		 * Horizontal (x) and vertical (y) pixels per em.
474 		 */
475 		PointInfo pixels_per_em;
476 
477 		/**
478 		 * The distance in pixels from the text baseline to the
479 		 * highest/upper grid coordinate used to place an outline point.
480 		 * Always a positive value.
481 		 */
482 		double ascent;
483 
484 		/**
485 		 * The distance in pixels from the baseline to the lowest grid
486 		 * coordinate used to place an outline point.
487 		 * Always a negative value.
488 		 */
489 		double descent;
490 
491 		/**
492 		 * Text width in pixels.
493 		 */
494 		double width;
495 
496 		/**
497 		 * Text height in pixels.
498 		 */
499 		double height;
500 
501 		/**
502 		 * The maximum horizontal advance (advance from the beginning
503 		 * of a character to the beginning of the next character) in
504 		 * pixels.
505 		 */
506 		double max_advance;
507 
508 		double underline_position;  ///
509 		double underline_thickness; ///
510 
511 		/**
512 		 * This is an imaginary box that encloses all glyphs from the font,
513 		 * usually as tightly as possible.
514 		 */
515 		SegmentInfo bounds;
516 
517 		/**
518 		 * A virtual point, located on the baseline, used to locate glyphs.
519 		 */
520 		PointInfo origin;
521 	}
522 
523 	DrawInfo* AcquireDrawInfo();
524 	DrawInfo* CloneDrawInfo(const(ImageInfo)*, const(DrawInfo)*);
525 	DrawInfo* DestroyDrawInfo(DrawInfo*);
526 
527 	MagickBooleanType DrawAffineImage(Image*, const(Image)*, const(AffineMatrix)*);
528 	MagickBooleanType DrawClipPath(Image*, const(DrawInfo)*, const(char)*);
529 	MagickBooleanType DrawGradientImage(Image*, const(DrawInfo)*);
530 	MagickBooleanType DrawImage(Image*, const(DrawInfo)*);
531 	MagickBooleanType DrawPatternPath(Image*, const(DrawInfo)*, const(char)*, Image**);
532 	MagickBooleanType DrawPrimitive(Image*, const(DrawInfo)*, const(PrimitiveInfo)*);
533 
534 	void GetAffineMatrix(AffineMatrix*);
535 	void GetDrawInfo(const(ImageInfo)*, DrawInfo*);
536 }