MagickWand  7.0.8
Convert, Edit, Or Compose Bitmap Images
magick-wand.c
Go to the documentation of this file.
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % %
6 % M M AAA GGGG IIIII CCCC K K %
7 % MM MM A A G I C K K %
8 % M M M AAAAA G GGG I C KKK %
9 % M M A A G G I C K K %
10 % M M A A GGGG IIIII CCCC K K %
11 % %
12 % W W AAA N N DDDD %
13 % W W A A NN N D D %
14 % W W W AAAAA N N N D D %
15 % WW WW A A N NN D D %
16 % W W A A N N DDDD %
17 % %
18 % %
19 % MagickWand Wand Methods %
20 % %
21 % Software Design %
22 % Cristy %
23 % August 2003 %
24 % %
25 % %
26 % Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
27 % dedicated to making software imaging solutions freely available. %
28 % %
29 % You may not use this file except in compliance with the License. You may %
30 % obtain a copy of the License at %
31 % %
32 % https://imagemagick.org/script/license.php %
33 % %
34 % Unless required by applicable law or agreed to in writing, software %
35 % distributed under the License is distributed on an "AS IS" BASIS, %
36 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
37 % See the License for the specific language governing permissions and %
38 % limitations under the License. %
39 % %
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %
42 %
43 %
44 */
45 
46 /*
47  Include declarations.
48 */
49 #include "MagickWand/studio.h"
50 #include "MagickWand/MagickWand.h"
52 #include "MagickWand/wand.h"
53 
54 /*
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 % %
57 % %
58 % %
59 % C l e a r M a g i c k W a n d %
60 % %
61 % %
62 % %
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %
65 % ClearMagickWand() clears resources associated with the wand, leaving the
66 % wand blank, and ready to be used for a new set of images.
67 %
68 % The format of the ClearMagickWand method is:
69 %
70 % void ClearMagickWand(MagickWand *wand)
71 %
72 % A description of each parameter follows:
73 %
74 % o wand: the magick wand.
75 %
76 */
78 {
79  assert(wand != (MagickWand *) NULL);
80  assert(wand->signature == MagickWandSignature);
81  if (wand->debug != MagickFalse)
82  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
83  wand->image_info=DestroyImageInfo(wand->image_info);
84  wand->images=DestroyImageList(wand->images);
85  wand->image_info=AcquireImageInfo();
86  wand->insert_before=MagickFalse;
87  wand->image_pending=MagickFalse;
88  ClearMagickException(wand->exception);
89  wand->debug=IsEventLogging();
90 }
91 
92 /*
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 % %
95 % %
96 % %
97 % C l o n e M a g i c k W a n d %
98 % %
99 % %
100 % %
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 %
103 % CloneMagickWand() makes an exact copy of the specified wand.
104 %
105 % The format of the CloneMagickWand method is:
106 %
107 % MagickWand *CloneMagickWand(const MagickWand *wand)
108 %
109 % A description of each parameter follows:
110 %
111 % o wand: the magick wand.
112 %
113 */
115 {
116  MagickWand
117  *clone_wand;
118 
119  assert(wand != (MagickWand *) NULL);
120  assert(wand->signature == MagickWandSignature);
121  if (wand->debug != MagickFalse)
122  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
123  clone_wand=(MagickWand *) AcquireMagickMemory(sizeof(*clone_wand));
124  if (clone_wand == (MagickWand *) NULL)
125  ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
126  wand->name);
127  (void) memset(clone_wand,0,sizeof(*clone_wand));
128  clone_wand->id=AcquireWandId();
129  (void) FormatLocaleString(clone_wand->name,MagickPathExtent,"%s-%.20g",
130  MagickWandId,(double) clone_wand->id);
131  clone_wand->exception=AcquireExceptionInfo();
132  InheritException(clone_wand->exception,wand->exception);
133  clone_wand->image_info=CloneImageInfo(wand->image_info);
134  clone_wand->images=CloneImageList(wand->images,clone_wand->exception);
135  clone_wand->insert_before=MagickFalse;
136  clone_wand->image_pending=MagickFalse;
137  clone_wand->debug=IsEventLogging();
138  if (clone_wand->debug != MagickFalse)
139  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
140  clone_wand->signature=MagickWandSignature;
141  return(clone_wand);
142 }
143 
144 /*
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 % %
147 % %
148 % %
149 % D e s t r o y M a g i c k W a n d %
150 % %
151 % %
152 % %
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 %
155 % DestroyMagickWand() deallocates memory associated with an MagickWand.
156 %
157 % The format of the DestroyMagickWand method is:
158 %
159 % MagickWand *DestroyMagickWand(MagickWand *wand)
160 %
161 % A description of each parameter follows:
162 %
163 % o wand: the magick wand.
164 %
165 */
167 {
168  assert(wand != (MagickWand *) NULL);
169  assert(wand->signature == MagickWandSignature);
170  if (wand->debug != MagickFalse)
171  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
172  wand->images=DestroyImageList(wand->images);
173  if (wand->image_info != (ImageInfo *) NULL )
174  wand->image_info=DestroyImageInfo(wand->image_info);
175  if (wand->exception != (ExceptionInfo *) NULL )
176  wand->exception=DestroyExceptionInfo(wand->exception);
177  RelinquishWandId(wand->id);
179  wand=(MagickWand *) RelinquishMagickMemory(wand);
180  return(wand);
181 }
182 
183 /*
184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 % %
186 % %
187 % %
188 % I s M a g i c k W a n d %
189 % %
190 % %
191 % %
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 %
194 % IsMagickWand() returns MagickTrue if the wand is verified as a magick wand.
195 %
196 % The format of the IsMagickWand method is:
197 %
198 % MagickBooleanType IsMagickWand(const MagickWand *wand)
199 %
200 % A description of each parameter follows:
201 %
202 % o wand: the magick wand.
203 %
204 */
205 WandExport MagickBooleanType IsMagickWand(const MagickWand *wand)
206 {
207  if (wand == (const MagickWand *) NULL)
208  return(MagickFalse);
209  if (wand->signature != MagickWandSignature)
210  return(MagickFalse);
211  if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
212  return(MagickFalse);
213  return(MagickTrue);
214 }
215 
216 /*
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 % %
219 % %
220 % %
221 % M a g i c k C l e a r E x c e p t i o n %
222 % %
223 % %
224 % %
225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 %
227 % MagickClearException() clears any exceptions associated with the wand.
228 %
229 % The format of the MagickClearException method is:
230 %
231 % MagickBooleanType MagickClearException(MagickWand *wand)
232 %
233 % A description of each parameter follows:
234 %
235 % o wand: the magick wand.
236 %
237 */
239 {
240  assert(wand != (MagickWand *) NULL);
241  assert(wand->signature == MagickWandSignature);
242  if (wand->debug != MagickFalse)
243  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
244  ClearMagickException(wand->exception);
245  return(MagickTrue);
246 }
247 
248 /*
249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 % %
251 % %
252 % %
253 % M a g i c k G e t E x c e p t i o n %
254 % %
255 % %
256 % %
257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 %
259 % MagickGetException() returns the severity, reason, and description of any
260 % error that occurs when using other methods in this API.
261 %
262 % The format of the MagickGetException method is:
263 %
264 % char *MagickGetException(const MagickWand *wand,ExceptionType *severity)
265 %
266 % A description of each parameter follows:
267 %
268 % o wand: the magick wand.
269 %
270 % o severity: the severity of the error is returned here.
271 %
272 */
274  ExceptionType *severity)
275 {
276  char
277  *description;
278 
279  assert(wand != (const MagickWand *) NULL);
280  assert(wand->signature == MagickWandSignature);
281  if (wand->debug != MagickFalse)
282  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
283  assert(severity != (ExceptionType *) NULL);
284  *severity=wand->exception->severity;
285  description=(char *) AcquireQuantumMemory(2UL*MagickPathExtent,
286  sizeof(*description));
287  if (description == (char *) NULL)
288  {
289  (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
290  "MemoryAllocationFailed","`%s'",wand->name);
291  return((char *) NULL);
292  }
293  *description='\0';
294  if (wand->exception->reason != (char *) NULL)
295  (void) CopyMagickString(description,GetLocaleExceptionMessage(
296  wand->exception->severity,wand->exception->reason),MagickPathExtent);
297  if (wand->exception->description != (char *) NULL)
298  {
299  (void) ConcatenateMagickString(description," (",MagickPathExtent);
300  (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
301  wand->exception->severity,wand->exception->description),MagickPathExtent);
302  (void) ConcatenateMagickString(description,")",MagickPathExtent);
303  }
304  return(description);
305 }
306 
307 /*
308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 % %
310 % %
311 % %
312 % M a g i c k G e t E x c e p t i o n T y p e %
313 % %
314 % %
315 % %
316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317 %
318 % MagickGetExceptionType() returns the exception type associated with the
319 % wand. If no exception has occurred, UndefinedExceptionType is returned.
320 %
321 % The format of the MagickGetExceptionType method is:
322 %
323 % ExceptionType MagickGetExceptionType(const MagickWand *wand)
324 %
325 % A description of each parameter follows:
326 %
327 % o wand: the magick wand.
328 %
329 */
330 WandExport ExceptionType MagickGetExceptionType(const MagickWand *wand)
331 {
332  assert(wand != (MagickWand *) NULL);
333  assert(wand->signature == MagickWandSignature);
334  if (wand->debug != MagickFalse)
335  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
336  return(wand->exception->severity);
337 }
338 
339 /*
340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 % %
342 % %
343 % %
344 % M a g i c k G e t I t e r a t o r I n d e x %
345 % %
346 % %
347 % %
348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349 %
350 % MagickGetIteratorIndex() returns the position of the iterator in the image
351 % list.
352 %
353 % The format of the MagickGetIteratorIndex method is:
354 %
355 % ssize_t MagickGetIteratorIndex(MagickWand *wand)
356 %
357 % A description of each parameter follows:
358 %
359 % o wand: the magick wand.
360 %
361 */
363 {
364  assert(wand != (MagickWand *) NULL);
365  assert(wand->signature == MagickWandSignature);
366  if (wand->debug != MagickFalse)
367  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
368  if (wand->images == (Image *) NULL)
369  {
370  (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
371  "ContainsNoIterators","`%s'",wand->name);
372  return(-1);
373  }
374  return(GetImageIndexInList(wand->images));
375 }
376 
377 /*
378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 % %
380 % %
381 % %
382 % M a g i c k Q u e r y C o n f i g u r e O p t i o n %
383 % %
384 % %
385 % %
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387 %
388 % MagickQueryConfigureOption() returns the value associated with the specified
389 % configure option.
390 %
391 % The format of the MagickQueryConfigureOption function is:
392 %
393 % char *MagickQueryConfigureOption(const char *option)
394 %
395 % A description of each parameter follows:
396 %
397 % o option: the option name.
398 %
399 */
400 WandExport char *MagickQueryConfigureOption(const char *option)
401 {
402  char
403  *value;
404 
405  const ConfigureInfo
406  **configure_info;
407 
408  ExceptionInfo
409  *exception;
410 
411  size_t
412  number_options;
413 
414  exception=AcquireExceptionInfo();
415  configure_info=GetConfigureInfoList(option,&number_options,exception);
416  exception=DestroyExceptionInfo(exception);
417  if (configure_info == (const ConfigureInfo **) NULL)
418  return((char *) NULL);
419  value=(char *) NULL;
420  if (number_options != 0)
421  value=AcquireString(configure_info[0]->value);
422  configure_info=(const ConfigureInfo **)
423  RelinquishMagickMemory((void *) configure_info);
424  return(value);
425 }
426 
427 /*
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 % %
430 % %
431 % %
432 % M a g i c k Q u e r y C o n f i g u r e O p t i o n s %
433 % %
434 % %
435 % %
436 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
437 %
438 % MagickQueryConfigureOptions() returns any configure options that match the
439 % specified pattern (e.g. "*" for all). Options include NAME, VERSION,
440 % LIB_VERSION, etc.
441 %
442 % The format of the MagickQueryConfigureOptions function is:
443 %
444 % char **MagickQueryConfigureOptions(const char *pattern,
445 % size_t *number_options)
446 %
447 % A description of each parameter follows:
448 %
449 % o pattern: Specifies a pointer to a text string containing a pattern.
450 %
451 % o number_options: Returns the number of configure options in the list.
452 %
453 %
454 */
455 WandExport char **MagickQueryConfigureOptions(const char *pattern,
456  size_t *number_options)
457 {
458  char
459  **options;
460 
461  ExceptionInfo
462  *exception;
463 
464  exception=AcquireExceptionInfo();
465  options=GetConfigureList(pattern,number_options,exception);
466  exception=DestroyExceptionInfo(exception);
467  return(options);
468 }
469 
470 /*
471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
472 % %
473 % %
474 % %
475 % M a g i c k Q u e r y F o n t M e t r i c s %
476 % %
477 % %
478 % %
479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480 %
481 % MagickQueryFontMetrics() returns a 13 element array representing the
482 % following font metrics:
483 %
484 % Element Description
485 % -------------------------------------------------
486 % 0 character width
487 % 1 character height
488 % 2 ascender
489 % 3 descender
490 % 4 text width
491 % 5 text height
492 % 6 maximum horizontal advance
493 % 7 bounding box: x1
494 % 8 bounding box: y1
495 % 9 bounding box: x2
496 % 10 bounding box: y2
497 % 11 origin: x
498 % 12 origin: y
499 %
500 % The format of the MagickQueryFontMetrics method is:
501 %
502 % double *MagickQueryFontMetrics(MagickWand *wand,
503 % const DrawingWand *drawing_wand,const char *text)
504 %
505 % A description of each parameter follows:
506 %
507 % o wand: the Magick wand.
508 %
509 % o drawing_wand: the drawing wand.
510 %
511 % o text: the text.
512 %
513 */
515  const DrawingWand *drawing_wand,const char *text)
516 {
517  double
518  *font_metrics;
519 
520  DrawInfo
521  *draw_info;
522 
523  MagickBooleanType
524  status;
525 
526  TypeMetric
527  metrics;
528 
529  assert(wand != (MagickWand *) NULL);
530  assert(wand->signature == MagickWandSignature);
531  if (wand->debug != MagickFalse)
532  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
533  assert(drawing_wand != (const DrawingWand *) NULL);
534  if (wand->images == (Image *) NULL)
535  {
536  (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
537  "ContainsNoImages","`%s'",wand->name);
538  return((double *) NULL);
539  }
540  font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
541  if (font_metrics == (double *) NULL)
542  return((double *) NULL);
543  draw_info=PeekDrawingWand(drawing_wand);
544  if (draw_info == (DrawInfo *) NULL)
545  {
546  font_metrics=(double *) RelinquishMagickMemory(font_metrics);
547  return((double *) NULL);
548  }
549  (void) CloneString(&draw_info->text,text);
550  (void) memset(&metrics,0,sizeof(metrics));
551  status=GetTypeMetrics(wand->images,draw_info,&metrics,wand->exception);
552  draw_info=DestroyDrawInfo(draw_info);
553  if (status == MagickFalse)
554  {
555  font_metrics=(double *) RelinquishMagickMemory(font_metrics);
556  return((double *) NULL);
557  }
558  font_metrics[0]=metrics.pixels_per_em.x;
559  font_metrics[1]=metrics.pixels_per_em.y;
560  font_metrics[2]=metrics.ascent;
561  font_metrics[3]=metrics.descent;
562  font_metrics[4]=metrics.width;
563  font_metrics[5]=metrics.height;
564  font_metrics[6]=metrics.max_advance;
565  font_metrics[7]=metrics.bounds.x1;
566  font_metrics[8]=metrics.bounds.y1;
567  font_metrics[9]=metrics.bounds.x2;
568  font_metrics[10]=metrics.bounds.y2;
569  font_metrics[11]=metrics.origin.x;
570  font_metrics[12]=metrics.origin.y;
571  return(font_metrics);
572 }
573 
574 /*
575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
576 % %
577 % %
578 % %
579 % M a g i c k Q u e r y M u l t i l i n e F o n t M e t r i c s %
580 % %
581 % %
582 % %
583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
584 %
585 % MagickQueryMultilineFontMetrics() returns a 13 element array representing the
586 % following font metrics:
587 %
588 % Element Description
589 % -------------------------------------------------
590 % 0 character width
591 % 1 character height
592 % 2 ascender
593 % 3 descender
594 % 4 text width
595 % 5 text height
596 % 6 maximum horizontal advance
597 % 7 bounding box: x1
598 % 8 bounding box: y1
599 % 9 bounding box: x2
600 % 10 bounding box: y2
601 % 11 origin: x
602 % 12 origin: y
603 %
604 % This method is like MagickQueryFontMetrics() but it returns the maximum text
605 % width and height for multiple lines of text.
606 %
607 % The format of the MagickQueryFontMetrics method is:
608 %
609 % double *MagickQueryMultilineFontMetrics(MagickWand *wand,
610 % const DrawingWand *drawing_wand,const char *text)
611 %
612 % A description of each parameter follows:
613 %
614 % o wand: the Magick wand.
615 %
616 % o drawing_wand: the drawing wand.
617 %
618 % o text: the text.
619 %
620 */
622  const DrawingWand *drawing_wand,const char *text)
623 {
624  double
625  *font_metrics;
626 
627  DrawInfo
628  *draw_info;
629 
630  MagickBooleanType
631  status;
632 
633  TypeMetric
634  metrics;
635 
636  assert(wand != (MagickWand *) NULL);
637  assert(wand->signature == MagickWandSignature);
638  if (wand->debug != MagickFalse)
639  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
640  assert(drawing_wand != (const DrawingWand *) NULL);
641  if (wand->images == (Image *) NULL)
642  {
643  (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
644  "ContainsNoImages","`%s'",wand->name);
645  return((double *) NULL);
646  }
647  font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
648  if (font_metrics == (double *) NULL)
649  return((double *) NULL);
650  draw_info=PeekDrawingWand(drawing_wand);
651  if (draw_info == (DrawInfo *) NULL)
652  {
653  font_metrics=(double *) RelinquishMagickMemory(font_metrics);
654  return((double *) NULL);
655  }
656  (void) CloneString(&draw_info->text,text);
657  (void) memset(&metrics,0,sizeof(metrics));
658  status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics,
659  wand->exception);
660  draw_info=DestroyDrawInfo(draw_info);
661  if (status == MagickFalse)
662  {
663  font_metrics=(double *) RelinquishMagickMemory(font_metrics);
664  return((double *) NULL);
665  }
666  font_metrics[0]=metrics.pixels_per_em.x;
667  font_metrics[1]=metrics.pixels_per_em.y;
668  font_metrics[2]=metrics.ascent;
669  font_metrics[3]=metrics.descent;
670  font_metrics[4]=metrics.width;
671  font_metrics[5]=metrics.height;
672  font_metrics[6]=metrics.max_advance;
673  font_metrics[7]=metrics.bounds.x1;
674  font_metrics[8]=metrics.bounds.y1;
675  font_metrics[9]=metrics.bounds.x2;
676  font_metrics[10]=metrics.bounds.y2;
677  font_metrics[11]=metrics.origin.x;
678  font_metrics[12]=metrics.origin.y;
679  return(font_metrics);
680 }
681 
682 /*
683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
684 % %
685 % %
686 % %
687 % M a g i c k Q u e r y F o n t s %
688 % %
689 % %
690 % %
691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
692 %
693 % MagickQueryFonts() returns any font that match the specified pattern (e.g.
694 % "*" for all).
695 %
696 % The format of the MagickQueryFonts function is:
697 %
698 % char **MagickQueryFonts(const char *pattern,size_t *number_fonts)
699 %
700 % A description of each parameter follows:
701 %
702 % o pattern: Specifies a pointer to a text string containing a pattern.
703 %
704 % o number_fonts: Returns the number of fonts in the list.
705 %
706 %
707 */
708 WandExport char **MagickQueryFonts(const char *pattern,
709  size_t *number_fonts)
710 {
711  char
712  **fonts;
713 
714  ExceptionInfo
715  *exception;
716 
717  exception=AcquireExceptionInfo();
718  fonts=GetTypeList(pattern,number_fonts,exception);
719  exception=DestroyExceptionInfo(exception);
720  return(fonts);
721 }
722 
723 /*
724 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
725 % %
726 % %
727 % %
728 % M a g i c k Q u e r y F o r m a t s %
729 % %
730 % %
731 % %
732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
733 %
734 % MagickQueryFormats() returns any image formats that match the specified
735 % pattern (e.g. "*" for all).
736 %
737 % The format of the MagickQueryFormats function is:
738 %
739 % char **MagickQueryFormats(const char *pattern,size_t *number_formats)
740 %
741 % A description of each parameter follows:
742 %
743 % o pattern: Specifies a pointer to a text string containing a pattern.
744 %
745 % o number_formats: This integer returns the number of image formats in the
746 % list.
747 %
748 */
749 WandExport char **MagickQueryFormats(const char *pattern,
750  size_t *number_formats)
751 {
752  char
753  **formats;
754 
755  ExceptionInfo
756  *exception;
757 
758  exception=AcquireExceptionInfo();
759  formats=GetMagickList(pattern,number_formats,exception);
760  exception=DestroyExceptionInfo(exception);
761  return(formats);
762 }
763 
764 /*
765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
766 % %
767 % %
768 % %
769 % M a g i c k R e l i n q u i s h M e m o r y %
770 % %
771 % %
772 % %
773 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
774 %
775 % MagickRelinquishMemory() relinquishes memory resources returned by such
776 % methods as MagickIdentifyImage(), MagickGetException(), etc.
777 %
778 % The format of the MagickRelinquishMemory method is:
779 %
780 % void *MagickRelinquishMemory(void *resource)
781 %
782 % A description of each parameter follows:
783 %
784 % o resource: Relinquish the memory associated with this resource.
785 %
786 */
788 {
789  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
790  return(RelinquishMagickMemory(memory));
791 }
792 
793 /*
794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
795 % %
796 % %
797 % %
798 % M a g i c k R e s e t I t e r a t o r %
799 % %
800 % %
801 % %
802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
803 %
804 % MagickResetIterator() resets the wand iterator.
805 %
806 % It is typically used either before iterating though images, or before
807 % calling specific functions such as MagickAppendImages() to append all
808 % images together.
809 %
810 % Afterward you can use MagickNextImage() to iterate over all the images
811 % in a wand container, starting with the first image.
812 %
813 % Using this before MagickAddImages() or MagickReadImages() will cause
814 % new images to be inserted between the first and second image.
815 %
816 % The format of the MagickResetIterator method is:
817 %
818 % void MagickResetIterator(MagickWand *wand)
819 %
820 % A description of each parameter follows:
821 %
822 % o wand: the magick wand.
823 %
824 */
826 {
827  assert(wand != (MagickWand *) NULL);
828  assert(wand->signature == MagickWandSignature);
829  if (wand->debug != MagickFalse)
830  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
831  wand->images=GetFirstImageInList(wand->images);
832  wand->insert_before=MagickFalse; /* Insert/add after current (first) image */
833  wand->image_pending=MagickTrue; /* NextImage will set first image */
834 }
835 
836 /*
837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838 % %
839 % %
840 % %
841 % M a g i c k S e t F i r s t I t e r a t o r %
842 % %
843 % %
844 % %
845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
846 %
847 % MagickSetFirstIterator() sets the wand iterator to the first image.
848 %
849 % After using any images added to the wand using MagickAddImage() or
850 % MagickReadImage() will be prepended before any image in the wand.
851 %
852 % Also the current image has been set to the first image (if any) in the
853 % Magick Wand. Using MagickNextImage() will then set teh current image
854 % to the second image in the list (if present).
855 %
856 % This operation is similar to MagickResetIterator() but differs in how
857 % MagickAddImage(), MagickReadImage(), and MagickNextImage() behaves
858 % afterward.
859 %
860 % The format of the MagickSetFirstIterator method is:
861 %
862 % void MagickSetFirstIterator(MagickWand *wand)
863 %
864 % A description of each parameter follows:
865 %
866 % o wand: the magick wand.
867 %
868 */
870 {
871  assert(wand != (MagickWand *) NULL);
872  assert(wand->signature == MagickWandSignature);
873  if (wand->debug != MagickFalse)
874  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
875  wand->images=GetFirstImageInList(wand->images);
876  wand->insert_before=MagickTrue; /* Insert/add before the first image */
877  wand->image_pending=MagickFalse; /* NextImage will set next image */
878 }
879 
880 /*
881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882 % %
883 % %
884 % %
885 % M a g i c k S e t I t e r a t o r I n d e x %
886 % %
887 % %
888 % %
889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
890 %
891 % MagickSetIteratorIndex() set the iterator to the given position in the
892 % image list specified with the index parameter. A zero index will set
893 % the first image as current, and so on. Negative indexes can be used
894 % to specify an image relative to the end of the images in the wand, with
895 % -1 being the last image in the wand.
896 %
897 % If the index is invalid (range too large for number of images in wand)
898 % the function will return MagickFalse, but no 'exception' will be raised,
899 % as it is not actually an error. In that case the current image will not
900 % change.
901 %
902 % After using any images added to the wand using MagickAddImage() or
903 % MagickReadImage() will be added after the image indexed, regardless
904 % of if a zero (first image in list) or negative index (from end) is used.
905 %
906 % Jumping to index 0 is similar to MagickResetIterator() but differs in how
907 % MagickNextImage() behaves afterward.
908 %
909 % The format of the MagickSetIteratorIndex method is:
910 %
911 % MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
912 % const ssize_t index)
913 %
914 % A description of each parameter follows:
915 %
916 % o wand: the magick wand.
917 %
918 % o index: the scene number.
919 %
920 */
922  const ssize_t index)
923 {
924  Image
925  *image;
926 
927  assert(wand != (MagickWand *) NULL);
928  assert(wand->signature == MagickWandSignature);
929  if (wand->debug != MagickFalse)
930  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
931  if (wand->images == (Image *) NULL)
932  return(MagickFalse);
933  image=GetImageFromList(wand->images,index);
934  if (image == (Image *) NULL)
935  return(MagickFalse); /* this is not an exception! Just range error. */
936  wand->images=image;
937  wand->insert_before=MagickFalse; /* Insert/Add after (this) image */
938  wand->image_pending=MagickFalse; /* NextImage will set next image */
939  return(MagickTrue);
940 }
941 /*
942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
943 % %
944 % %
945 % %
946 % M a g i c k S e t L a s t I t e r a t o r %
947 % %
948 % %
949 % %
950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
951 %
952 % MagickSetLastIterator() sets the wand iterator to the last image.
953 %
954 % The last image is actually the current image, and the next use of
955 % MagickPreviousImage() will not change this allowing this function to be
956 % used to iterate over the images in the reverse direction. In this sense it
957 % is more like MagickResetIterator() than MagickSetFirstIterator().
958 %
959 % Typically this function is used before MagickAddImage(), MagickReadImage()
960 % functions to ensure new images are appended to the very end of wand's image
961 % list.
962 %
963 % The format of the MagickSetLastIterator method is:
964 %
965 % void MagickSetLastIterator(MagickWand *wand)
966 %
967 % A description of each parameter follows:
968 %
969 % o wand: the magick wand.
970 %
971 */
973 {
974  assert(wand != (MagickWand *) NULL);
975  assert(wand->signature == MagickWandSignature);
976  if (wand->debug != MagickFalse)
977  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
978  wand->images=GetLastImageInList(wand->images);
979  wand->insert_before=MagickFalse; /* Insert/add after current (last) image */
980  wand->image_pending=MagickTrue; /* PreviousImage will return last image */
981 }
982 
983 /*
984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
985 % %
986 % %
987 % %
988 % M a g i c k W a n d G e n e s i s %
989 % %
990 % %
991 % %
992 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
993 %
994 % MagickWandGenesis() initializes the MagickWand environment.
995 %
996 % The format of the MagickWandGenesis method is:
997 %
998 % void MagickWandGenesis(void)
999 %
1000 */
1002 {
1003  if (IsMagickCoreInstantiated() == MagickFalse)
1004  MagickCoreGenesis((char *) NULL,MagickFalse);
1005 }
1006 
1007 /*
1008 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009 % %
1010 % %
1011 % %
1012 % M a g i c k W a n d T e r m i n u s %
1013 % %
1014 % %
1015 % %
1016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1017 %
1018 % MagickWandTerminus() terminates the MagickWand environment.
1019 %
1020 % The format of the MaickWandTerminus method is:
1021 %
1022 % void MagickWandTerminus(void)
1023 %
1024 */
1026 {
1027  DestroyWandIds();
1028  MagickCoreTerminus();
1029 }
1030 
1031 /*
1032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1033 % %
1034 % %
1035 % %
1036 % N e w M a g i c k W a n d %
1037 % %
1038 % %
1039 % %
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1041 %
1042 % NewMagickWand() returns a wand required for all other methods in the API.
1043 % A fatal exception is thrown if there is not enough memory to allocate the
1044 % wand. Use DestroyMagickWand() to dispose of the wand when it is no longer
1045 % needed.
1046 %
1047 % The format of the NewMagickWand method is:
1048 %
1049 % MagickWand *NewMagickWand(void)
1050 %
1051 */
1053 {
1054  const char
1055  *quantum;
1056 
1057  MagickWand
1058  *wand;
1059 
1060  size_t
1061  depth;
1062 
1063  depth=MAGICKCORE_QUANTUM_DEPTH;
1064  quantum=GetMagickQuantumDepth(&depth);
1065  if (depth != MAGICKCORE_QUANTUM_DEPTH)
1066  ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
1067  wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand));
1068  if (wand == (MagickWand *) NULL)
1069  ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
1070  GetExceptionMessage(errno));
1071  (void) memset(wand,0,sizeof(*wand));
1072  wand->id=AcquireWandId();
1073  (void) FormatLocaleString(wand->name,MagickPathExtent,"%s-%.20g",MagickWandId,
1074  (double) wand->id);
1075  wand->images=NewImageList();
1076  wand->image_info=AcquireImageInfo();
1077  wand->exception=AcquireExceptionInfo();
1078  wand->debug=IsEventLogging();
1079  if (wand->debug != MagickFalse)
1080  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
1082  return(wand);
1083 }
1084 
1085 /*
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 % %
1088 % %
1089 % %
1090 % N e w M a g i c k W a n d F r o m I m a g e %
1091 % %
1092 % %
1093 % %
1094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1095 %
1096 % NewMagickWandFromImage() returns a wand with an image.
1097 %
1098 % The format of the NewMagickWandFromImage method is:
1099 %
1100 % MagickWand *NewMagickWandFromImage(const Image *image)
1101 %
1102 % A description of each parameter follows:
1103 %
1104 % o image: the image.
1105 %
1106 */
1108 {
1109  MagickWand
1110  *wand;
1111 
1112  wand=NewMagickWand();
1113  wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
1114  return(wand);
1115 }
1116 
1117 /*
1118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1119 % %
1120 % %
1121 % %
1122 % I s M a g i c k W a n d I n s t a n t i a t e d %
1123 % %
1124 % %
1125 % %
1126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1127 %
1128 % IsMagickWandInstantiated() returns MagickTrue if the ImageMagick environment
1129 % is currently instantiated-- that is, MagickWandGenesis() has been called but
1130 % MagickWandTerminus() has not.
1131 %
1132 % The format of the IsMagickWandInstantiated method is:
1133 %
1134 % MagickBooleanType IsMagickWandInstantiated(void)
1135 %
1136 */
1137 MagickExport MagickBooleanType IsMagickWandInstantiated(void)
1138 {
1139  return(IsMagickCoreInstantiated());
1140 }
#define ThrowWandFatalException(severity, tag, context)
WandExport double * MagickQueryFontMetrics(MagickWand *wand, const DrawingWand *drawing_wand, const char *text)
Definition: magick-wand.c:514
WandExport void ClearMagickWand(MagickWand *wand)
Definition: magick-wand.c:77
#define MagickWandSignature
WandExport void * MagickRelinquishMemory(void *memory)
Definition: magick-wand.c:787
WandExport size_t AcquireWandId(void)
Definition: wand.c:74
WandExport char * MagickQueryConfigureOption(const char *option)
Definition: magick-wand.c:400
MagickExport MagickBooleanType IsMagickWandInstantiated(void)
Definition: magick-wand.c:1137
#define WandExport
WandExport MagickWand * NewMagickWand(void)
Definition: magick-wand.c:1052
MagickBooleanType insert_before
WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand, const ssize_t index)
Definition: magick-wand.c:921
WandExport void MagickSetLastIterator(MagickWand *wand)
Definition: magick-wand.c:972
WandExport DrawInfo * PeekDrawingWand(const DrawingWand *wand)
WandExport void RelinquishWandId(const size_t id)
Definition: wand.c:150
MagickBooleanType debug
#define MagickPathExtent
MagickBooleanType image_pending
WandExport double * MagickQueryMultilineFontMetrics(MagickWand *wand, const DrawingWand *drawing_wand, const char *text)
Definition: magick-wand.c:621
WandExport void MagickWandTerminus(void)
Definition: magick-wand.c:1025
WandExport void MagickWandGenesis(void)
Definition: magick-wand.c:1001
ImageInfo * image_info
WandExport void DestroyWandIds(void)
Definition: wand.c:116
WandExport char ** MagickQueryFormats(const char *pattern, size_t *number_formats)
Definition: magick-wand.c:749
char name[MagickPathExtent]
#define MagickWandId
Definition: magick-image.c:59
WandExport void MagickResetIterator(MagickWand *wand)
Definition: magick-wand.c:825
WandExport char ** MagickQueryConfigureOptions(const char *pattern, size_t *number_options)
Definition: magick-wand.c:455
WandExport char ** MagickQueryFonts(const char *pattern, size_t *number_fonts)
Definition: magick-wand.c:708
WandExport MagickBooleanType IsMagickWand(const MagickWand *wand)
Definition: magick-wand.c:205
WandExport MagickWand * NewMagickWandFromImage(const Image *image)
Definition: magick-wand.c:1107
WandExport MagickWand * CloneMagickWand(const MagickWand *wand)
Definition: magick-wand.c:114
WandExport MagickWand * DestroyMagickWand(MagickWand *wand)
Definition: magick-wand.c:166
WandExport ssize_t MagickGetIteratorIndex(MagickWand *wand)
Definition: magick-wand.c:362
WandExport MagickBooleanType MagickClearException(MagickWand *wand)
Definition: magick-wand.c:238
WandExport ExceptionType MagickGetExceptionType(const MagickWand *wand)
Definition: magick-wand.c:330
WandExport void MagickSetFirstIterator(MagickWand *wand)
Definition: magick-wand.c:869
WandExport char * MagickGetException(const MagickWand *wand, ExceptionType *severity)
Definition: magick-wand.c:273
ExceptionInfo * exception