MagickCore  7.1.0
annotate.c
Go to the documentation of this file.
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % %
6 % AAA N N N N OOO TTTTT AAA TTTTT EEEEE %
7 % A A NN N NN N O O T A A T E %
8 % AAAAA N N N N N N O O T AAAAA T EEE %
9 % A A N NN N NN O O T A A T E %
10 % A A N N N N OOO T A A T EEEEE %
11 % %
12 % %
13 % MagickCore Image Annotation Methods %
14 % %
15 % Software Design %
16 % Cristy %
17 % July 1992 %
18 % %
19 % %
20 % Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
22 % %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
25 % %
26 % https://imagemagick.org/script/license.php %
27 % %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
33 % %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 % Digital Applications (www.digapp.com) contributed the stroked text algorithm.
37 % It was written by Leonard Rosenthol.
38 %
39 %
40 */
41 
42 /*
43  Include declarations.
44 */
45 #include "MagickCore/studio.h"
46 #include "MagickCore/annotate.h"
48 #include "MagickCore/attribute.h"
50 #include "MagickCore/cache-view.h"
51 #include "MagickCore/channel.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/color.h"
56 #include "MagickCore/composite.h"
58 #include "MagickCore/constitute.h"
59 #include "MagickCore/draw.h"
61 #include "MagickCore/enhance.h"
62 #include "MagickCore/exception.h"
64 #include "MagickCore/gem.h"
65 #include "MagickCore/geometry.h"
67 #include "MagickCore/log.h"
68 #include "MagickCore/quantum.h"
71 #include "MagickCore/policy.h"
72 #include "MagickCore/property.h"
73 #include "MagickCore/resource_.h"
74 #include "MagickCore/semaphore.h"
75 #include "MagickCore/statistic.h"
76 #include "MagickCore/string_.h"
77 #include "MagickCore/token.h"
79 #include "MagickCore/transform.h"
81 #include "MagickCore/type.h"
82 #include "MagickCore/utility.h"
84 #include "MagickCore/xwindow.h"
86 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
87 #if defined(__MINGW32__)
88 # undef interface
89 #endif
90 #include <ft2build.h>
91 #if defined(FT_FREETYPE_H)
92 # include FT_FREETYPE_H
93 #else
94 # include <freetype/freetype.h>
95 #endif
96 #if defined(FT_GLYPH_H)
97 # include FT_GLYPH_H
98 #else
99 # include <freetype/ftglyph.h>
100 #endif
101 #if defined(FT_OUTLINE_H)
102 # include FT_OUTLINE_H
103 #else
104 # include <freetype/ftoutln.h>
105 #endif
106 #if defined(FT_BBOX_H)
107 # include FT_BBOX_H
108 #else
109 # include <freetype/ftbbox.h>
110 #endif /* defined(FT_BBOX_H) */
111 #endif
112 #if defined(MAGICKCORE_RAQM_DELEGATE)
113 #include <raqm.h>
114 #endif
115 typedef struct _GraphemeInfo
116 {
117  size_t
119  x_offset,
120  x_advance,
121  y_offset;
122 
123  size_t
125 } GraphemeInfo;
126 
127 /*
128  Annotate semaphores.
129 */
130 static SemaphoreInfo
132 
133 /*
134  Forward declarations.
135 */
136 static MagickBooleanType
137  RenderType(Image *,const DrawInfo *,const PointInfo *,TypeMetric *,
138  ExceptionInfo *),
139  RenderPostscript(Image *,const DrawInfo *,const PointInfo *,TypeMetric *,
140  ExceptionInfo *),
141  RenderFreetype(Image *,const DrawInfo *,const char *,const PointInfo *,
143  RenderX11(Image *,const DrawInfo *,const PointInfo *,TypeMetric *,
144  ExceptionInfo *);
145 
146 /*
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 % %
149 % %
150 % %
151 + A n n o t a t e C o m p o n e n t G e n e s i s %
152 % %
153 % %
154 % %
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 %
157 % AnnotateComponentGenesis() instantiates the annotate component.
158 %
159 % The format of the AnnotateComponentGenesis method is:
160 %
161 % MagickBooleanType AnnotateComponentGenesis(void)
162 %
163 */
165 {
166  if (annotate_semaphore == (SemaphoreInfo *) NULL)
168  return(MagickTrue);
169 }
170 
171 /*
172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 % %
174 % %
175 % %
176 + A n n o t a t e C o m p o n e n t T e r m i n u s %
177 % %
178 % %
179 % %
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 %
182 % AnnotateComponentTerminus() destroys the annotate component.
183 %
184 % The format of the AnnotateComponentTerminus method is:
185 %
186 % AnnotateComponentTerminus(void)
187 %
188 */
190 {
191  if (annotate_semaphore == (SemaphoreInfo *) NULL)
194 }
195 
196 /*
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 % %
199 % %
200 % %
201 % A n n o t a t e I m a g e %
202 % %
203 % %
204 % %
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 %
207 % AnnotateImage() annotates an image with text.
208 %
209 % The format of the AnnotateImage method is:
210 %
211 % MagickBooleanType AnnotateImage(Image *image,DrawInfo *draw_info,
212 % ExceptionInfo *exception)
213 %
214 % A description of each parameter follows:
215 %
216 % o image: the image.
217 %
218 % o draw_info: the draw info.
219 %
220 % o exception: return any errors or warnings in this structure.
221 %
222 */
224  const DrawInfo *draw_info,ExceptionInfo *exception)
225 {
226  char
227  *p,
228  color[MagickPathExtent],
229  primitive[MagickPathExtent],
230  *text,
231  **textlist;
232 
233  DrawInfo
234  *annotate,
235  *annotate_info;
236 
238  geometry_info;
239 
241  status;
242 
243  PixelInfo
244  pixel;
245 
246  PointInfo
247  offset;
248 
250  geometry;
251 
252  ssize_t
253  i;
254 
255  TypeMetric
256  metrics;
257 
258  size_t
259  height,
260  number_lines;
261 
262  assert(image != (Image *) NULL);
263  assert(image->signature == MagickCoreSignature);
264  if (image->debug != MagickFalse)
265  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
266  assert(draw_info != (DrawInfo *) NULL);
267  assert(draw_info->signature == MagickCoreSignature);
268  if (draw_info->text == (char *) NULL)
269  return(MagickFalse);
270  if (*draw_info->text == '\0')
271  return(MagickTrue);
272  annotate=CloneDrawInfo((ImageInfo *) NULL,draw_info);
273  text=annotate->text;
274  annotate->text=(char *) NULL;
275  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
276  number_lines=1;
277  for (p=text; *p != '\0'; p++)
278  if (*p == '\n')
279  number_lines++;
280  textlist=(char **) AcquireQuantumMemory(number_lines+1,sizeof(*textlist));
281  if (textlist == (char **) NULL)
282  {
283  annotate_info=DestroyDrawInfo(annotate_info);
284  annotate=DestroyDrawInfo(annotate);
285  text=DestroyString(text);
286  return(MagickFalse);
287  }
288  p=text;
289  for (i=0; i < (ssize_t) number_lines; i++)
290  {
291  char
292  *q;
293 
294  textlist[i]=p;
295  for (q=p; *q != '\0'; q++)
296  if ((*q == '\r') || (*q == '\n'))
297  break;
298  if (*q == '\r')
299  {
300  *q='\0';
301  q++;
302  }
303  *q='\0';
304  p=q+1;
305  }
306  textlist[i]=(char *) NULL;
307  SetGeometry(image,&geometry);
308  SetGeometryInfo(&geometry_info);
309  if (annotate_info->geometry != (char *) NULL)
310  {
311  (void) ParsePageGeometry(image,annotate_info->geometry,&geometry,
312  exception);
313  (void) ParseGeometry(annotate_info->geometry,&geometry_info);
314  }
315  if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
316  {
317  annotate_info=DestroyDrawInfo(annotate_info);
318  annotate=DestroyDrawInfo(annotate);
319  textlist=(char **) RelinquishMagickMemory(textlist);
320  text=DestroyString(text);
321  return(MagickFalse);
322  }
323  if (IsGrayColorspace(image->colorspace) != MagickFalse)
324  (void) SetImageColorspace(image,sRGBColorspace,exception);
325  status=MagickTrue;
326  (void) memset(&metrics,0,sizeof(metrics));
327  for (i=0; textlist[i] != (char *) NULL; i++)
328  {
329  if (*textlist[i] == '\0')
330  continue;
331  /*
332  Position text relative to image.
333  */
334  annotate_info->affine.tx=geometry_info.xi-image->page.x;
335  annotate_info->affine.ty=geometry_info.psi-image->page.y;
336  (void) CloneString(&annotate->text,textlist[i]);
337  if ((metrics.width == 0) || (annotate->gravity != NorthWestGravity))
338  (void) GetTypeMetrics(image,annotate,&metrics,exception);
339  height=(size_t) floor(metrics.ascent-metrics.descent+0.5);
340  if (height == 0)
341  height=draw_info->pointsize;
342  height+=(size_t) floor(draw_info->interline_spacing+0.5);
343  switch (annotate->gravity)
344  {
345  case UndefinedGravity:
346  default:
347  {
348  offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height;
349  offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height;
350  break;
351  }
352  case NorthWestGravity:
353  {
354  offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+i*
355  annotate_info->affine.ry*height+annotate_info->affine.ry*
356  (metrics.ascent+metrics.descent);
357  offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+i*
358  annotate_info->affine.sy*height+annotate_info->affine.sy*
359  metrics.ascent;
360  break;
361  }
362  case NorthGravity:
363  {
364  offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+
365  geometry.width/2.0+i*annotate_info->affine.ry*height-
366  annotate_info->affine.sx*metrics.width/2.0+annotate_info->affine.ry*
367  (metrics.ascent+metrics.descent);
368  offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+i*
369  annotate_info->affine.sy*height+annotate_info->affine.sy*
370  metrics.ascent-annotate_info->affine.rx*metrics.width/2.0;
371  break;
372  }
373  case NorthEastGravity:
374  {
375  offset.x=(geometry.width == 0 ? 1.0 : -1.0)*annotate_info->affine.tx+
376  geometry.width+i*annotate_info->affine.ry*height-
377  annotate_info->affine.sx*metrics.width+annotate_info->affine.ry*
378  (metrics.ascent+metrics.descent)-1.0;
379  offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+i*
380  annotate_info->affine.sy*height+annotate_info->affine.sy*
381  metrics.ascent-annotate_info->affine.rx*metrics.width;
382  break;
383  }
384  case WestGravity:
385  {
386  offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+i*
387  annotate_info->affine.ry*height+annotate_info->affine.ry*
388  (metrics.ascent+metrics.descent-(number_lines-1.0)*height)/2.0;
389  offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+
390  geometry.height/2.0+i*annotate_info->affine.sy*height+
391  annotate_info->affine.sy*(metrics.ascent+metrics.descent-
392  (number_lines-1.0)*height)/2.0;
393  break;
394  }
395  case CenterGravity:
396  {
397  offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+
398  geometry.width/2.0+i*annotate_info->affine.ry*height-
399  annotate_info->affine.sx*metrics.width/2.0+annotate_info->affine.ry*
400  (metrics.ascent+metrics.descent-(number_lines-1.0)*height)/2.0;
401  offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+
402  geometry.height/2.0+i*annotate_info->affine.sy*height-
403  annotate_info->affine.rx*metrics.width/2.0+annotate_info->affine.sy*
404  (metrics.ascent+metrics.descent-(number_lines-1.0)*height)/2.0;
405  break;
406  }
407  case EastGravity:
408  {
409  offset.x=(geometry.width == 0 ? 1.0 : -1.0)*annotate_info->affine.tx+
410  geometry.width+i*annotate_info->affine.ry*height-
411  annotate_info->affine.sx*metrics.width+
412  annotate_info->affine.ry*(metrics.ascent+metrics.descent-
413  (number_lines-1.0)*height)/2.0-1.0;
414  offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+
415  geometry.height/2.0+i*annotate_info->affine.sy*height-
416  annotate_info->affine.rx*metrics.width+
417  annotate_info->affine.sy*(metrics.ascent+metrics.descent-
418  (number_lines-1.0)*height)/2.0;
419  break;
420  }
421  case SouthWestGravity:
422  {
423  offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+i*
424  annotate_info->affine.ry*height-annotate_info->affine.ry*
425  (number_lines-1.0)*height;
426  offset.y=(geometry.height == 0 ? 1.0 : -1.0)*annotate_info->affine.ty+
427  geometry.height+i*annotate_info->affine.sy*height-
428  annotate_info->affine.sy*(number_lines-1.0)*height+metrics.descent;
429  break;
430  }
431  case SouthGravity:
432  {
433  offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+
434  geometry.width/2.0+i*annotate_info->affine.ry*height-
435  annotate_info->affine.sx*metrics.width/2.0-
436  annotate_info->affine.ry*(number_lines-1.0)*height/2.0;
437  offset.y=(geometry.height == 0 ? 1.0 : -1.0)*annotate_info->affine.ty+
438  geometry.height+i*annotate_info->affine.sy*height-
439  annotate_info->affine.rx*metrics.width/2.0-
440  annotate_info->affine.sy*(number_lines-1.0)*height+metrics.descent;
441  break;
442  }
443  case SouthEastGravity:
444  {
445  offset.x=(geometry.width == 0 ? 1.0 : -1.0)*annotate_info->affine.tx+
446  geometry.width+i*annotate_info->affine.ry*height-
447  annotate_info->affine.sx*metrics.width-
448  annotate_info->affine.ry*(number_lines-1.0)*height-1.0;
449  offset.y=(geometry.height == 0 ? 1.0 : -1.0)*annotate_info->affine.ty+
450  geometry.height+i*annotate_info->affine.sy*height-
451  annotate_info->affine.rx*metrics.width-
452  annotate_info->affine.sy*(number_lines-1.0)*height+metrics.descent;
453  break;
454  }
455  }
456  switch (annotate->align)
457  {
458  case LeftAlign:
459  {
460  offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height;
461  offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height;
462  break;
463  }
464  case CenterAlign:
465  {
466  offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height-
467  annotate_info->affine.sx*metrics.width/2.0;
468  offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height-
469  annotate_info->affine.rx*metrics.width/2.0;
470  break;
471  }
472  case RightAlign:
473  {
474  offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height-
475  annotate_info->affine.sx*metrics.width;
476  offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height-
477  annotate_info->affine.rx*metrics.width;
478  break;
479  }
480  default:
481  break;
482  }
483  if (draw_info->undercolor.alpha != TransparentAlpha)
484  {
485  DrawInfo
486  *undercolor_info;
487 
488  /*
489  Text box.
490  */
491  undercolor_info=CloneDrawInfo((ImageInfo *) NULL,(DrawInfo *) NULL);
492  undercolor_info->fill=draw_info->undercolor;
493  undercolor_info->affine=draw_info->affine;
494  undercolor_info->affine.tx=offset.x-draw_info->affine.ry*metrics.ascent;
495  undercolor_info->affine.ty=offset.y-draw_info->affine.sy*metrics.ascent;
496  (void) FormatLocaleString(primitive,MagickPathExtent,
497  "rectangle 0.0,0.0 %g,%g",metrics.origin.x,(double) height);
498  (void) CloneString(&undercolor_info->primitive,primitive);
499  (void) DrawImage(image,undercolor_info,exception);
500  (void) DestroyDrawInfo(undercolor_info);
501  }
502  annotate_info->affine.tx=offset.x;
503  annotate_info->affine.ty=offset.y;
504  pixel=annotate_info->fill;
505  if (annotate_info->stroke.alpha != TransparentAlpha)
506  pixel=annotate_info->stroke;
507  (void) QueryColorname(image,&pixel,AllCompliance,color,exception);
508  (void) FormatLocaleString(primitive,MagickPathExtent,"stroke %s "
509  "stroke-width %g line 0,0 %g,0",color,(double)
510  metrics.underline_thickness,(double) metrics.width);
511  /*
512  Annotate image with text.
513  */
514  switch (annotate->decorate)
515  {
516  case OverlineDecoration:
517  {
518  annotate_info->affine.ty-=(draw_info->affine.sy*(metrics.ascent+
519  metrics.descent-metrics.underline_position));
520  (void) CloneString(&annotate_info->primitive,primitive);
521  (void) DrawImage(image,annotate_info,exception);
522  break;
523  }
524  case UnderlineDecoration:
525  {
526  annotate_info->affine.ty-=(draw_info->affine.sy*
527  metrics.underline_position);
528  (void) CloneString(&annotate_info->primitive,primitive);
529  (void) DrawImage(image,annotate_info,exception);
530  break;
531  }
532  default:
533  break;
534  }
535  status=RenderType(image,annotate,&offset,&metrics,exception);
536  if (status == MagickFalse)
537  break;
538 
539  if (annotate->decorate == LineThroughDecoration) {
540  annotate_info->affine.ty-=(draw_info->affine.sy*(height+
541  metrics.underline_position+metrics.descent*2)/2.0);
542  (void) CloneString(&annotate_info->primitive,primitive);
543  (void) DrawImage(image,annotate_info,exception);
544  }
545  }
546  /*
547  Relinquish resources.
548  */
549  annotate_info=DestroyDrawInfo(annotate_info);
550  annotate=DestroyDrawInfo(annotate);
551  textlist=(char **) RelinquishMagickMemory(textlist);
552  text=DestroyString(text);
553  return(status);
554 }
555 
556 /*
557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
558 % %
559 % %
560 % %
561 % F o r m a t M a g i c k C a p t i o n %
562 % %
563 % %
564 % %
565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
566 %
567 % FormatMagickCaption() formats a caption so that it fits within the image
568 % width. It returns the number of lines in the formatted caption.
569 %
570 % The format of the FormatMagickCaption method is:
571 %
572 % ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
573 % const MagickBooleanType split,TypeMetric *metrics,char **caption,
574 % ExceptionInfo *exception)
575 %
576 % A description of each parameter follows.
577 %
578 % o image: The image.
579 %
580 % o draw_info: the draw info.
581 %
582 % o split: when no convenient line breaks-- insert newline.
583 %
584 % o metrics: Return the font metrics in this structure.
585 %
586 % o caption: the caption.
587 %
588 % o exception: return any errors or warnings in this structure.
589 %
590 */
591 
592 static inline char *ReplaceSpaceWithNewline(char **caption,char *space)
593 {
594  size_t
595  octets;
596 
597  octets=(size_t) GetUTFOctets(space);
598  if (octets == 1)
599  *space='\n';
600  else
601  {
602  char
603  *target;
604 
605  size_t
606  length,
607  offset;
608 
609  length=strlen(*caption);
610  *space='\n';
611  offset=space-(*caption);
612  target=AcquireString(*caption);
613  CopyMagickString(target,*caption,offset+2);
614  ConcatenateMagickString(target,space+octets,length);
615  (void) DestroyString(*caption);
616  *caption=target;
617  space=(*caption)+offset;
618  }
619  return(space);
620 }
621 
622 MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
623  const MagickBooleanType split,TypeMetric *metrics,char **caption,
624  ExceptionInfo *exception)
625 {
627  status;
628 
629  char
630  *p,
631  *q,
632  *s;
633 
634  size_t
635  width;
636 
637  ssize_t
638  i,
639  n;
640 
641  q=draw_info->text;
642  s=(char *) NULL;
643  width=0;
644  for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p))
645  {
646  int
647  code;
648 
649  code=GetUTFCode(p);
650  if (code == '\n')
651  {
652  q=draw_info->text;
653  continue;
654  }
655  if ((IsUTFSpace(code) != MagickFalse) &&
657  {
658  s=p;
659  if (width > image->columns)
660  p=ReplaceSpaceWithNewline(caption,s);
661  }
662  for (i=0; i < (ssize_t) GetUTFOctets(p); i++)
663  *q++=(*(p+i));
664  *q='\0';
665  status=GetTypeMetrics(image,draw_info,metrics,exception);
666  if (status == MagickFalse)
667  break;
668  width=(size_t) floor(metrics->width+draw_info->stroke_width+0.5);
669  if (width <= image->columns)
670  continue;
671  if (s != (char *) NULL)
672  p=ReplaceSpaceWithNewline(caption,s);
673  else
674  if ((split != MagickFalse) || (GetUTFOctets(p) > 2))
675  {
676  /*
677  No convenient line breaks-- insert newline.
678  */
679  n=p-(*caption);
680  if ((n > 0) && ((*caption)[n-1] != '\n'))
681  {
682  char
683  *target;
684 
685  target=AcquireString(*caption);
686  CopyMagickString(target,*caption,n+1);
687  ConcatenateMagickString(target,"\n",strlen(*caption)+1);
688  ConcatenateMagickString(target,p,strlen(*caption)+2);
689  (void) DestroyString(*caption);
690  *caption=target;
691  p=(*caption)+n;
692  }
693  }
694  q=draw_info->text;
695  s=(char *) NULL;
696  }
697  n=0;
698  for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p))
699  if (GetUTFCode(p) == '\n')
700  n++;
701  return(n);
702 }
703 
704 /*
705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
706 % %
707 % %
708 % %
709 % G e t M u l t i l i n e T y p e M e t r i c s %
710 % %
711 % %
712 % %
713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
714 %
715 % GetMultilineTypeMetrics() returns the following information for the
716 % specified font and text:
717 %
718 % character width
719 % character height
720 % ascender
721 % descender
722 % text width
723 % text height
724 % maximum horizontal advance
725 % bounds: x1
726 % bounds: y1
727 % bounds: x2
728 % bounds: y2
729 % origin: x
730 % origin: y
731 % underline position
732 % underline thickness
733 %
734 % This method is like GetTypeMetrics() but it returns the maximum text width
735 % and height for multiple lines of text.
736 %
737 % The format of the GetMultilineTypeMetrics method is:
738 %
739 % MagickBooleanType GetMultilineTypeMetrics(Image *image,
740 % const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception)
741 %
742 % A description of each parameter follows:
743 %
744 % o image: the image.
745 %
746 % o draw_info: the draw info.
747 %
748 % o metrics: Return the font metrics in this structure.
749 %
750 % o exception: return any errors or warnings in this structure.
751 %
752 */
754  const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception)
755 {
756  char
757  **textlist;
758 
759  double
760  height;
761 
762  DrawInfo
763  *annotate_info;
764 
766  status;
767 
769  size;
770 
771  ssize_t
772  i;
773 
774  size_t
775  count;
776 
777  TypeMetric
778  extent;
779 
780  assert(image != (Image *) NULL);
781  assert(image->signature == MagickCoreSignature);
782  if (image->debug != MagickFalse)
783  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
784  assert(draw_info != (DrawInfo *) NULL);
785  assert(draw_info->text != (char *) NULL);
786  assert(draw_info->signature == MagickCoreSignature);
787  if (*draw_info->text == '\0')
788  return(MagickFalse);
789  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
790  annotate_info->text=DestroyString(annotate_info->text);
791  /*
792  Convert newlines to multiple lines of text.
793  */
794  textlist=StringToStrings(draw_info->text,&count);
795  if (textlist == (char **) NULL)
796  return(MagickFalse);
797  annotate_info->render=MagickFalse;
798  annotate_info->direction=UndefinedDirection;
799  (void) memset(metrics,0,sizeof(*metrics));
800  (void) memset(&extent,0,sizeof(extent));
801  /*
802  Find the widest of the text lines.
803  */
804  annotate_info->text=textlist[0];
805  status=GetTypeMetrics(image,annotate_info,&extent,exception);
806  *metrics=extent;
807  height=(count*(size_t) (metrics->ascent-metrics->descent+
808  0.5)+(count-1)*draw_info->interline_spacing);
809  size=(MagickSizeType) fabs(height);
811  {
813  "WidthOrHeightExceedsLimit","`%s'",image->filename);
814  status=MagickFalse;
815  }
816  else
817  {
818  for (i=1; i < (ssize_t) count; i++)
819  {
820  annotate_info->text=textlist[i];
821  status=GetTypeMetrics(image,annotate_info,&extent,exception);
822  if (status == MagickFalse)
823  break;
824  if (extent.width > metrics->width)
825  *metrics=extent;
826  size=(MagickSizeType) fabs(extent.width);
828  {
830  "WidthOrHeightExceedsLimit","`%s'",image->filename);
831  status=MagickFalse;
832  break;
833  }
834  }
835  metrics->height=(double) height;
836  }
837  /*
838  Relinquish resources.
839  */
840  annotate_info->text=(char *) NULL;
841  annotate_info=DestroyDrawInfo(annotate_info);
842  for (i=0; i < (ssize_t) count; i++)
843  textlist[i]=DestroyString(textlist[i]);
844  textlist=(char **) RelinquishMagickMemory(textlist);
845  return(status);
846 }
847 
848 /*
849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
850 % %
851 % %
852 % %
853 % G e t T y p e M e t r i c s %
854 % %
855 % %
856 % %
857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
858 %
859 % GetTypeMetrics() returns the following information for the specified font
860 % and text:
861 %
862 % character width
863 % character height
864 % ascender
865 % descender
866 % text width
867 % text height
868 % maximum horizontal advance
869 % bounds: x1
870 % bounds: y1
871 % bounds: x2
872 % bounds: y2
873 % origin: x
874 % origin: y
875 % underline position
876 % underline thickness
877 %
878 % The format of the GetTypeMetrics method is:
879 %
880 % MagickBooleanType GetTypeMetrics(Image *image,const DrawInfo *draw_info,
881 % TypeMetric *metrics,ExceptionInfo *exception)
882 %
883 % A description of each parameter follows:
884 %
885 % o image: the image.
886 %
887 % o draw_info: the draw info.
888 %
889 % o metrics: Return the font metrics in this structure.
890 %
891 % o exception: return any errors or warnings in this structure.
892 %
893 */
895  const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception)
896 {
897  DrawInfo
898  *annotate_info;
899 
901  status;
902 
903  PointInfo
904  offset;
905 
906  assert(image != (Image *) NULL);
907  assert(image->signature == MagickCoreSignature);
908  if (image->debug != MagickFalse)
909  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
910  assert(draw_info != (DrawInfo *) NULL);
911  assert(draw_info->text != (char *) NULL);
912  assert(draw_info->signature == MagickCoreSignature);
913  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
914  annotate_info->render=MagickFalse;
915  annotate_info->direction=UndefinedDirection;
916  (void) memset(metrics,0,sizeof(*metrics));
917  offset.x=0.0;
918  offset.y=0.0;
919  status=RenderType(image,annotate_info,&offset,metrics,exception);
920  if (image->debug != MagickFalse)
921  (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),"Metrics: text: %s; "
922  "width: %g; height: %g; ascent: %g; descent: %g; max advance: %g; "
923  "bounds: %g,%g %g,%g; origin: %g,%g; pixels per em: %g,%g; "
924  "underline position: %g; underline thickness: %g",annotate_info->text,
925  metrics->width,metrics->height,metrics->ascent,metrics->descent,
926  metrics->max_advance,metrics->bounds.x1,metrics->bounds.y1,
927  metrics->bounds.x2,metrics->bounds.y2,metrics->origin.x,metrics->origin.y,
928  metrics->pixels_per_em.x,metrics->pixels_per_em.y,
929  metrics->underline_position,metrics->underline_thickness);
930  annotate_info=DestroyDrawInfo(annotate_info);
931  return(status);
932 }
933 
934 /*
935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
936 % %
937 % %
938 % %
939 + R e n d e r T y p e %
940 % %
941 % %
942 % %
943 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
944 %
945 % RenderType() renders text on the image. It also returns the bounding box of
946 % the text relative to the image.
947 %
948 % The format of the RenderType method is:
949 %
950 % MagickBooleanType RenderType(Image *image,DrawInfo *draw_info,
951 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
952 %
953 % A description of each parameter follows:
954 %
955 % o image: the image.
956 %
957 % o draw_info: the draw info.
958 %
959 % o offset: (x,y) location of text relative to image.
960 %
961 % o metrics: bounding box of text.
962 %
963 % o exception: return any errors or warnings in this structure.
964 %
965 */
966 static MagickBooleanType RenderType(Image *image,const DrawInfo *draw_info,
967  const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
968 {
969  char
970  *font;
971 
972  const TypeInfo
973  *type_info;
974 
975  DrawInfo
976  *annotate_info;
977 
979  *sans_exception;
980 
982  status;
983 
984  type_info=(const TypeInfo *) NULL;
985  if (draw_info->font != (char *) NULL)
986  {
987  if (*draw_info->font == '@')
988  {
989  status=RenderFreetype(image,draw_info,draw_info->encoding,offset,
990  metrics,exception);
991  return(status);
992  }
993  if (*draw_info->font == '-')
994  return(RenderX11(image,draw_info,offset,metrics,exception));
995  if (*draw_info->font == '^')
996  return(RenderPostscript(image,draw_info,offset,metrics,exception));
997  if (IsPathAccessible(draw_info->font) != MagickFalse)
998  {
999  status=RenderFreetype(image,draw_info,draw_info->encoding,offset,
1000  metrics,exception);
1001  return(status);
1002  }
1003  type_info=GetTypeInfo(draw_info->font,exception);
1004  if (type_info == (const TypeInfo *) NULL)
1006  "UnableToReadFont","`%s'",draw_info->font);
1007  }
1008  if ((type_info == (const TypeInfo *) NULL) &&
1009  (draw_info->family != (const char *) NULL))
1010  {
1011  if (strchr(draw_info->family,',') == (char *) NULL)
1012  type_info=GetTypeInfoByFamily(draw_info->family,draw_info->style,
1013  draw_info->stretch,draw_info->weight,exception);
1014  if (type_info == (const TypeInfo *) NULL)
1015  {
1016  char
1017  **family;
1018 
1019  int
1020  number_families;
1021 
1022  ssize_t
1023  i;
1024 
1025  /*
1026  Parse font family list.
1027  */
1028  family=StringToArgv(draw_info->family,&number_families);
1029  for (i=1; i < (ssize_t) number_families; i++)
1030  {
1031  type_info=GetTypeInfoByFamily(family[i],draw_info->style,
1032  draw_info->stretch,draw_info->weight,exception);
1033  if ((type_info != (const TypeInfo *) NULL) &&
1034  (LocaleCompare(family[i],type_info->family) == 0))
1035  break;
1036  }
1037  for (i=0; i < (ssize_t) number_families; i++)
1038  family[i]=DestroyString(family[i]);
1039  family=(char **) RelinquishMagickMemory(family);
1040  if (type_info == (const TypeInfo *) NULL)
1042  "UnableToReadFont","`%s'",draw_info->family);
1043  }
1044  }
1045  font=GetPolicyValue("system:font");
1046  if (font != (char *) NULL)
1047  {
1048  if (IsPathAccessible(font) != MagickFalse)
1049  {
1050  /*
1051  Render with default system font.
1052  */
1053  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1054  annotate_info->font=font;
1055  status=RenderFreetype(image,annotate_info,annotate_info->encoding,
1056  offset,metrics,exception);
1057  annotate_info=DestroyDrawInfo(annotate_info);
1058  return(status);
1059  }
1060  font=DestroyString(font);
1061  }
1062  sans_exception=AcquireExceptionInfo();
1063  if (type_info == (const TypeInfo *) NULL)
1064  type_info=GetTypeInfoByFamily("Open Sans",draw_info->style,
1065  draw_info->stretch,draw_info->weight,sans_exception);
1066  if (type_info == (const TypeInfo *) NULL)
1067  type_info=GetTypeInfoByFamily("Sans Serif",draw_info->style,
1068  draw_info->stretch,draw_info->weight,sans_exception);
1069  if (type_info == (const TypeInfo *) NULL)
1070  type_info=GetTypeInfoByFamily((const char *) NULL,draw_info->style,
1071  draw_info->stretch,draw_info->weight,sans_exception);
1072  if (type_info == (const TypeInfo *) NULL)
1073  type_info=GetTypeInfo("*",sans_exception);
1074  sans_exception=DestroyExceptionInfo(sans_exception);
1075  if (type_info == (const TypeInfo *) NULL)
1076  {
1077  status=RenderFreetype(image,draw_info,draw_info->encoding,offset,metrics,
1078  exception);
1079  return(status);
1080  }
1081  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1082  annotate_info->face=type_info->face;
1083  if (type_info->metrics != (char *) NULL)
1084  (void) CloneString(&annotate_info->metrics,type_info->metrics);
1085  if (type_info->glyphs != (char *) NULL)
1086  (void) CloneString(&annotate_info->font,type_info->glyphs);
1087  status=RenderFreetype(image,annotate_info,type_info->encoding,offset,metrics,
1088  exception);
1089  annotate_info=DestroyDrawInfo(annotate_info);
1090  return(status);
1091 }
1092 
1093 /*
1094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1095 % %
1096 % %
1097 % %
1098 + R e n d e r F r e e t y p e %
1099 % %
1100 % %
1101 % %
1102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1103 %
1104 % RenderFreetype() renders text on the image with a Truetype font. It also
1105 % returns the bounding box of the text relative to the image.
1106 %
1107 % The format of the RenderFreetype method is:
1108 %
1109 % MagickBooleanType RenderFreetype(Image *image,DrawInfo *draw_info,
1110 % const char *encoding,const PointInfo *offset,TypeMetric *metrics,
1111 % ExceptionInfo *exception)
1112 %
1113 % A description of each parameter follows:
1114 %
1115 % o image: the image.
1116 %
1117 % o draw_info: the draw info.
1118 %
1119 % o encoding: the font encoding.
1120 %
1121 % o offset: (x,y) location of text relative to image.
1122 %
1123 % o metrics: bounding box of text.
1124 %
1125 % o exception: return any errors or warnings in this structure.
1126 %
1127 */
1128 
1129 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
1130 
1131 static size_t ComplexTextLayout(const Image *image,const DrawInfo *draw_info,
1132  const char *text,const size_t length,const FT_Face face,const FT_Int32 flags,
1133  GraphemeInfo **grapheme,ExceptionInfo *exception)
1134 {
1135 #if defined(MAGICKCORE_RAQM_DELEGATE)
1136  const char
1137  *features;
1138 
1139  raqm_t
1140  *rq;
1141 
1142  raqm_glyph_t
1143  *glyphs;
1144 
1145  ssize_t
1146  i;
1147 
1148  size_t
1149  extent;
1150 
1151  magick_unreferenced(flags);
1152  extent=0;
1153  rq=raqm_create();
1154  if (rq == (raqm_t *) NULL)
1155  goto cleanup;
1156  if (raqm_set_text_utf8(rq,text,length) == 0)
1157  goto cleanup;
1158  if (raqm_set_par_direction(rq,(raqm_direction_t) draw_info->direction) == 0)
1159  goto cleanup;
1160  if (raqm_set_freetype_face(rq,face) == 0)
1161  goto cleanup;
1162  features=GetImageProperty(image,"type:features",exception);
1163  if (features != (const char *) NULL)
1164  {
1165  char
1166  breaker,
1167  quote,
1168  *token;
1169 
1170  int
1171  next,
1172  status_token;
1173 
1174  TokenInfo
1175  *token_info;
1176 
1177  next=0;
1178  token_info=AcquireTokenInfo();
1179  token=AcquireString("");
1180  status_token=Tokenizer(token_info,0,token,50,features,"",",","",'\0',
1181  &breaker,&next,&quote);
1182  while (status_token == 0)
1183  {
1184  raqm_add_font_feature(rq,token,(int) strlen(token));
1185  status_token=Tokenizer(token_info,0,token,50,features,"",",","",'\0',
1186  &breaker,&next,&quote);
1187  }
1188  token_info=DestroyTokenInfo(token_info);
1189  token=DestroyString(token);
1190  }
1191  if (raqm_layout(rq) == 0)
1192  goto cleanup;
1193  glyphs=raqm_get_glyphs(rq,&extent);
1194  if (glyphs == (raqm_glyph_t *) NULL)
1195  {
1196  extent=0;
1197  goto cleanup;
1198  }
1199  *grapheme=(GraphemeInfo *) AcquireQuantumMemory(extent,sizeof(**grapheme));
1200  if (*grapheme == (GraphemeInfo *) NULL)
1201  {
1202  extent=0;
1203  goto cleanup;
1204  }
1205  for (i=0; i < (ssize_t) extent; i++)
1206  {
1207  (*grapheme)[i].index=glyphs[i].index;
1208  (*grapheme)[i].x_offset=glyphs[i].x_offset;
1209  (*grapheme)[i].x_advance=glyphs[i].x_advance;
1210  (*grapheme)[i].y_offset=glyphs[i].y_offset;
1211  (*grapheme)[i].cluster=glyphs[i].cluster;
1212  }
1213 
1214 cleanup:
1215  raqm_destroy(rq);
1216  return(extent);
1217 #else
1218  const char
1219  *p;
1220 
1221  FT_Error
1222  ft_status;
1223 
1224  ssize_t
1225  i;
1226 
1227  ssize_t
1228  last_glyph;
1229 
1230  /*
1231  Simple layout for bi-directional text (right-to-left or left-to-right).
1232  */
1233  magick_unreferenced(image);
1234  magick_unreferenced(exception);
1235  *grapheme=(GraphemeInfo *) AcquireQuantumMemory(length+1,sizeof(**grapheme));
1236  if (*grapheme == (GraphemeInfo *) NULL)
1237  return(0);
1238  last_glyph=0;
1239  p=text;
1240  for (i=0; GetUTFCode(p) != 0; p+=GetUTFOctets(p), i++)
1241  {
1242  (*grapheme)[i].index=(ssize_t) FT_Get_Char_Index(face,GetUTFCode(p));
1243  (*grapheme)[i].x_offset=0;
1244  (*grapheme)[i].y_offset=0;
1245  if (((*grapheme)[i].index != 0) && (last_glyph != 0))
1246  {
1247  if (FT_HAS_KERNING(face))
1248  {
1249  FT_Vector
1250  kerning;
1251 
1252  ft_status=FT_Get_Kerning(face,(FT_UInt) last_glyph,(FT_UInt)
1253  (*grapheme)[i].index,ft_kerning_default,&kerning);
1254  if (ft_status == 0)
1255  (*grapheme)[i-1].x_advance+=(FT_Pos) ((draw_info->direction ==
1256  RightToLeftDirection ? -1.0 : 1.0)*kerning.x);
1257  }
1258  }
1259  ft_status=FT_Load_Glyph(face,(FT_UInt) (*grapheme)[i].index,flags);
1260  (*grapheme)[i].x_advance=face->glyph->advance.x;
1261  (*grapheme)[i].cluster=p-text;
1262  last_glyph=(*grapheme)[i].index;
1263  }
1264  return((size_t) i);
1265 #endif
1266 }
1267 
1268 static inline MagickBooleanType IsEmptyOutline(FT_Outline outline)
1269 {
1270  return((outline.n_points == 0) || (outline.n_contours <= 0) ? MagickTrue :
1271  MagickFalse);
1272 }
1273 
1274 static int TraceCubicBezier(FT_Vector *p,FT_Vector *q,FT_Vector *to,
1275  DrawInfo *draw_info)
1276 {
1277  AffineMatrix
1278  affine;
1279 
1280  char
1281  path[MagickPathExtent];
1282 
1283  affine=draw_info->affine;
1284  (void) FormatLocaleString(path,MagickPathExtent,"C%g,%g %g,%g %g,%g",
1285  affine.tx+p->x/64.0,affine.ty-p->y/64.0,affine.tx+q->x/64.0,affine.ty-
1286  q->y/64.0,affine.tx+to->x/64.0,affine.ty-to->y/64.0);
1287  (void) ConcatenateString(&draw_info->primitive,path);
1288  return(0);
1289 }
1290 
1291 static int TraceLineTo(FT_Vector *to,DrawInfo *draw_info)
1292 {
1293  AffineMatrix
1294  affine;
1295 
1296  char
1297  path[MagickPathExtent];
1298 
1299  affine=draw_info->affine;
1300  (void) FormatLocaleString(path,MagickPathExtent,"L%g,%g",affine.tx+to->x/64.0,
1301  affine.ty-to->y/64.0);
1302  (void) ConcatenateString(&draw_info->primitive,path);
1303  return(0);
1304 }
1305 
1306 static int TraceMoveTo(FT_Vector *to,DrawInfo *draw_info)
1307 {
1308  AffineMatrix
1309  affine;
1310 
1311  char
1312  path[MagickPathExtent];
1313 
1314  affine=draw_info->affine;
1315  (void) FormatLocaleString(path,MagickPathExtent,"M%g,%g",affine.tx+to->x/64.0,
1316  affine.ty-to->y/64.0);
1317  (void) ConcatenateString(&draw_info->primitive,path);
1318  return(0);
1319 }
1320 
1321 static int TraceQuadraticBezier(FT_Vector *control,FT_Vector *to,
1322  DrawInfo *draw_info)
1323 {
1324  AffineMatrix
1325  affine;
1326 
1327  char
1328  path[MagickPathExtent];
1329 
1330  affine=draw_info->affine;
1331  (void) FormatLocaleString(path,MagickPathExtent,"Q%g,%g %g,%g",affine.tx+
1332  control->x/64.0,affine.ty-control->y/64.0,affine.tx+to->x/64.0,affine.ty-
1333  to->y/64.0);
1334  (void) ConcatenateString(&draw_info->primitive,path);
1335  return(0);
1336 }
1337 
1338 static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
1339  const char *encoding,const PointInfo *offset,TypeMetric *metrics,
1340  ExceptionInfo *exception)
1341 {
1342 #if !defined(FT_OPEN_PATHNAME)
1343 #define FT_OPEN_PATHNAME ft_open_pathname
1344 #endif
1345 
1346  typedef struct _GlyphInfo
1347  {
1348  FT_UInt
1349  id;
1350 
1351  FT_Vector
1352  origin;
1353 
1354  FT_Glyph
1355  image;
1356  } GlyphInfo;
1357 
1358  const char
1359  *value;
1360 
1361  DrawInfo
1362  *annotate_info;
1363 
1364  FT_BBox
1365  bounds;
1366 
1367  FT_BitmapGlyph
1368  bitmap;
1369 
1370  FT_Encoding
1371  encoding_type;
1372 
1373  FT_Error
1374  ft_status;
1375 
1376  FT_Face
1377  face;
1378 
1379  FT_Int32
1380  flags;
1381 
1382  FT_Library
1383  library;
1384 
1385  FT_Matrix
1386  affine;
1387 
1388  FT_Open_Args
1389  args;
1390 
1391  FT_UInt
1392  first_glyph_id,
1393  last_glyph_id,
1394  missing_glyph_id;
1395 
1396  FT_Vector
1397  origin;
1398 
1399  GlyphInfo
1400  glyph;
1401 
1402  GraphemeInfo
1403  *grapheme;
1404 
1406  status;
1407 
1408  PointInfo
1409  point,
1410  resolution;
1411 
1412  char
1413  *p;
1414 
1415  ssize_t
1416  i;
1417 
1418  size_t
1419  length;
1420 
1421  ssize_t
1422  code,
1423  last_character,
1424  y;
1425 
1426  static FT_Outline_Funcs
1427  OutlineMethods =
1428  {
1429  (FT_Outline_MoveTo_Func) TraceMoveTo,
1430  (FT_Outline_LineTo_Func) TraceLineTo,
1431  (FT_Outline_ConicTo_Func) TraceQuadraticBezier,
1432  (FT_Outline_CubicTo_Func) TraceCubicBezier,
1433  0, 0
1434  };
1435 
1436  unsigned char
1437  *utf8;
1438 
1439  /*
1440  Initialize Truetype library.
1441  */
1442  ft_status=FT_Init_FreeType(&library);
1443  if (ft_status != 0)
1444  ThrowBinaryException(TypeError,"UnableToInitializeFreetypeLibrary",
1445  image->filename);
1446  args.flags=FT_OPEN_PATHNAME;
1447  if (draw_info->font == (char *) NULL)
1448  args.pathname=ConstantString("helvetica");
1449  else
1450  if (*draw_info->font != '@')
1451  args.pathname=ConstantString(draw_info->font);
1452  else
1453  args.pathname=ConstantString(draw_info->font+1);
1454  face=(FT_Face) NULL;
1455  ft_status=FT_Open_Face(library,&args,(long) draw_info->face,&face);
1456  if (ft_status != 0)
1457  {
1458  (void) FT_Done_FreeType(library);
1459  (void) ThrowMagickException(exception,GetMagickModule(),TypeError,
1460  "UnableToReadFont","`%s'",args.pathname);
1461  args.pathname=DestroyString(args.pathname);
1462  return(MagickFalse);
1463  }
1464  args.pathname=DestroyString(args.pathname);
1465  if ((draw_info->metrics != (char *) NULL) &&
1466  (IsPathAccessible(draw_info->metrics) != MagickFalse))
1467  (void) FT_Attach_File(face,draw_info->metrics);
1468  encoding_type=FT_ENCODING_UNICODE;
1469  ft_status=FT_Select_Charmap(face,encoding_type);
1470  if ((ft_status != 0) && (face->num_charmaps != 0))
1471  ft_status=FT_Set_Charmap(face,face->charmaps[0]);
1472  if (encoding != (const char *) NULL)
1473  {
1474  if (LocaleCompare(encoding,"AdobeCustom") == 0)
1475  encoding_type=FT_ENCODING_ADOBE_CUSTOM;
1476  if (LocaleCompare(encoding,"AdobeExpert") == 0)
1477  encoding_type=FT_ENCODING_ADOBE_EXPERT;
1478  if (LocaleCompare(encoding,"AdobeStandard") == 0)
1479  encoding_type=FT_ENCODING_ADOBE_STANDARD;
1480  if (LocaleCompare(encoding,"AppleRoman") == 0)
1481  encoding_type=FT_ENCODING_APPLE_ROMAN;
1482  if (LocaleCompare(encoding,"BIG5") == 0)
1483  encoding_type=FT_ENCODING_BIG5;
1484 #if defined(FT_ENCODING_PRC)
1485  if (LocaleCompare(encoding,"GB2312") == 0)
1486  encoding_type=FT_ENCODING_PRC;
1487 #endif
1488 #if defined(FT_ENCODING_JOHAB)
1489  if (LocaleCompare(encoding,"Johab") == 0)
1490  encoding_type=FT_ENCODING_JOHAB;
1491 #endif
1492 #if defined(FT_ENCODING_ADOBE_LATIN_1)
1493  if (LocaleCompare(encoding,"Latin-1") == 0)
1494  encoding_type=FT_ENCODING_ADOBE_LATIN_1;
1495 #endif
1496 #if defined(FT_ENCODING_ADOBE_LATIN_2)
1497  if (LocaleCompare(encoding,"Latin-2") == 0)
1498  encoding_type=FT_ENCODING_OLD_LATIN_2;
1499 #endif
1500  if (LocaleCompare(encoding,"None") == 0)
1501  encoding_type=FT_ENCODING_NONE;
1502  if (LocaleCompare(encoding,"SJIScode") == 0)
1503  encoding_type=FT_ENCODING_SJIS;
1504  if (LocaleCompare(encoding,"Symbol") == 0)
1505  encoding_type=FT_ENCODING_MS_SYMBOL;
1506  if (LocaleCompare(encoding,"Unicode") == 0)
1507  encoding_type=FT_ENCODING_UNICODE;
1508  if (LocaleCompare(encoding,"Wansung") == 0)
1509  encoding_type=FT_ENCODING_WANSUNG;
1510  ft_status=FT_Select_Charmap(face,encoding_type);
1511  if (ft_status != 0)
1512  {
1513  (void) FT_Done_Face(face);
1514  (void) FT_Done_FreeType(library);
1515  ThrowBinaryException(TypeError,"UnrecognizedFontEncoding",encoding);
1516  }
1517  }
1518  /*
1519  Set text size.
1520  */
1521  resolution.x=DefaultResolution;
1522  resolution.y=DefaultResolution;
1523  if (draw_info->density != (char *) NULL)
1524  {
1525  GeometryInfo
1526  geometry_info;
1527 
1529  geometry_flags;
1530 
1531  geometry_flags=ParseGeometry(draw_info->density,&geometry_info);
1532  if ((geometry_flags & RhoValue) != 0)
1533  resolution.x=geometry_info.rho;
1534  resolution.y=resolution.x;
1535  if ((geometry_flags & SigmaValue) != 0)
1536  resolution.y=geometry_info.sigma;
1537  }
1538  ft_status=FT_Set_Char_Size(face,(FT_F26Dot6) (64.0*draw_info->pointsize),
1539  (FT_F26Dot6) (64.0*draw_info->pointsize),(FT_UInt) resolution.x,
1540  (FT_UInt) resolution.y);
1541  if (ft_status != 0)
1542  {
1543  (void) FT_Done_Face(face);
1544  (void) FT_Done_FreeType(library);
1545  ThrowBinaryException(TypeError,"UnableToReadFont",draw_info->font);
1546  }
1547  metrics->pixels_per_em.x=face->size->metrics.x_ppem;
1548  metrics->pixels_per_em.y=face->size->metrics.y_ppem;
1549  metrics->ascent=(double) face->size->metrics.ascender/64.0;
1550  metrics->descent=(double) face->size->metrics.descender/64.0;
1551  if (face->size->metrics.ascender == 0)
1552  {
1553  /*
1554  Sanitize buggy ascender and descender values.
1555  */
1556  metrics->ascent=face->size->metrics.y_ppem;
1557  if (face->size->metrics.descender == 0)
1558  metrics->descent=face->size->metrics.y_ppem/-3.5;
1559  }
1560  metrics->width=0;
1561  metrics->origin.x=0;
1562  metrics->origin.y=0;
1563  metrics->height=(double) face->size->metrics.height/64.0;
1564  metrics->max_advance=0.0;
1565  if (face->size->metrics.max_advance > MagickEpsilon)
1566  metrics->max_advance=(double) face->size->metrics.max_advance/64.0;
1567  metrics->bounds.x1=0.0;
1568  metrics->bounds.y1=metrics->descent;
1569  metrics->bounds.x2=metrics->ascent+metrics->descent;
1570  metrics->bounds.y2=metrics->ascent+metrics->descent;
1571  metrics->underline_position=face->underline_position*
1572  (metrics->pixels_per_em.x*PerceptibleReciprocal(face->units_per_EM));
1573  metrics->underline_thickness=face->underline_thickness*
1574  (metrics->pixels_per_em.x*PerceptibleReciprocal(face->units_per_EM));
1575  first_glyph_id=0;
1576  FT_Get_First_Char(face,&first_glyph_id);
1577  if ((draw_info->text == (char *) NULL) || (*draw_info->text == '\0') ||
1578  (first_glyph_id == 0))
1579  {
1580  (void) FT_Done_Face(face);
1581  (void) FT_Done_FreeType(library);
1582  return(MagickTrue);
1583  }
1584  /*
1585  Compute bounding box.
1586  */
1587  if (image->debug != MagickFalse)
1588  (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),"Font %s; "
1589  "font-encoding %s; text-encoding %s; pointsize %g",
1590  draw_info->font != (char *) NULL ? draw_info->font : "none",
1591  encoding != (char *) NULL ? encoding : "none",
1592  draw_info->encoding != (char *) NULL ? draw_info->encoding : "none",
1593  draw_info->pointsize);
1594  flags=FT_LOAD_DEFAULT;
1595  if (draw_info->render == MagickFalse)
1596  flags=FT_LOAD_NO_BITMAP;
1597  if (draw_info->text_antialias == MagickFalse)
1598  flags|=FT_LOAD_RENDER | FT_LOAD_TARGET_MONO;
1599  else
1600  {
1601 #if defined(FT_LOAD_TARGET_LIGHT)
1602  flags|=FT_LOAD_TARGET_LIGHT;
1603 #elif defined(FT_LOAD_TARGET_LCD)
1604  flags|=FT_LOAD_TARGET_LCD;
1605 #endif
1606  }
1607  value=GetImageProperty(image,"type:hinting",exception);
1608  if ((value != (const char *) NULL) && (LocaleCompare(value,"off") == 0))
1609  flags|=FT_LOAD_NO_HINTING;
1610  glyph.id=0;
1611  glyph.image=(FT_Glyph) NULL;
1612  last_glyph_id=0;
1613  origin.x=0;
1614  origin.y=0;
1615  affine.xx=65536L;
1616  affine.yx=0L;
1617  affine.xy=0L;
1618  affine.yy=65536L;
1619  if (draw_info->render != MagickFalse)
1620  {
1621  affine.xx=(FT_Fixed) (65536L*draw_info->affine.sx+0.5);
1622  affine.yx=(FT_Fixed) (-65536L*draw_info->affine.rx+0.5);
1623  affine.xy=(FT_Fixed) (-65536L*draw_info->affine.ry+0.5);
1624  affine.yy=(FT_Fixed) (65536L*draw_info->affine.sy+0.5);
1625  }
1626  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1627  if (annotate_info->dash_pattern != (double *) NULL)
1628  annotate_info->dash_pattern[0]=0.0;
1629  (void) CloneString(&annotate_info->primitive,"path '");
1630  status=MagickTrue;
1631  if (draw_info->render != MagickFalse)
1632  {
1633  if (image->storage_class != DirectClass)
1634  (void) SetImageStorageClass(image,DirectClass,exception);
1635  if (image->alpha_trait == UndefinedPixelTrait)
1636  (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
1637  }
1638  for (p=draw_info->text; GetUTFCode(p) != 0; p+=GetUTFOctets(p))
1639  if (GetUTFCode(p) < 0)
1640  break;
1641  utf8=(unsigned char *) NULL;
1642  if (GetUTFCode(p) == 0)
1643  p=draw_info->text;
1644  else
1645  {
1646  utf8=ConvertLatin1ToUTF8((unsigned char *) draw_info->text);
1647  if (utf8 != (unsigned char *) NULL)
1648  p=(char *) utf8;
1649  }
1650  grapheme=(GraphemeInfo *) NULL;
1651  length=ComplexTextLayout(image,draw_info,p,strlen(p),face,flags,&grapheme,
1652  exception);
1653  missing_glyph_id=FT_Get_Char_Index(face,' ');
1654  code=0;
1655  last_character=(ssize_t) length-1;
1656  for (i=0; i < (ssize_t) length; i++)
1657  {
1658  FT_Outline
1659  outline;
1660 
1661  /*
1662  Render UTF-8 sequence.
1663  */
1664  glyph.id=(FT_UInt) grapheme[i].index;
1665  if (glyph.id == 0)
1666  glyph.id=missing_glyph_id;
1667  if ((glyph.id != 0) && (last_glyph_id != 0))
1668  origin.x+=(FT_Pos) (64.0*draw_info->kerning);
1669  glyph.origin=origin;
1670  glyph.origin.x+=(FT_Pos) grapheme[i].x_offset;
1671  glyph.origin.y+=(FT_Pos) grapheme[i].y_offset;
1672  if (glyph.image != (FT_Glyph) NULL)
1673  {
1674  FT_Done_Glyph(glyph.image);
1675  glyph.image=(FT_Glyph) NULL;
1676  }
1677  ft_status=FT_Load_Glyph(face,glyph.id,flags);
1678  if (ft_status != 0)
1679  continue;
1680  ft_status=FT_Get_Glyph(face->glyph,&glyph.image);
1681  if (ft_status != 0)
1682  continue;
1683  outline=((FT_OutlineGlyph) glyph.image)->outline;
1684  if ((glyph.image->format != FT_GLYPH_FORMAT_OUTLINE) &&
1685  (IsEmptyOutline(outline) == MagickFalse))
1686  continue;
1687  ft_status=FT_Outline_Get_BBox(&outline,&bounds);
1688  if (ft_status != 0)
1689  continue;
1690  if ((bounds.xMin < metrics->bounds.x1) && (bounds.xMin != 0))
1691  metrics->bounds.x1=(double) bounds.xMin;
1692  if ((bounds.yMin < metrics->bounds.y1) && (bounds.yMin != 0))
1693  metrics->bounds.y1=(double) bounds.yMin;
1694  if ((bounds.xMax > metrics->bounds.x2) && (bounds.xMax != 0))
1695  metrics->bounds.x2=(double) bounds.xMax;
1696  if ((bounds.yMax > metrics->bounds.y2) && (bounds.yMax != 0))
1697  metrics->bounds.y2=(double) bounds.yMax;
1698  if (((draw_info->stroke.alpha != TransparentAlpha) ||
1699  (draw_info->stroke_pattern != (Image *) NULL)) &&
1700  ((status != MagickFalse) && (draw_info->render != MagickFalse)))
1701  {
1702  /*
1703  Trace the glyph.
1704  */
1705  annotate_info->affine.tx=glyph.origin.x/64.0;
1706  annotate_info->affine.ty=(-glyph.origin.y/64.0);
1707  if (IsEmptyOutline(outline) == MagickFalse)
1708  ft_status=FT_Outline_Decompose(&outline,&OutlineMethods,
1709  annotate_info);
1710  }
1711  FT_Vector_Transform(&glyph.origin,&affine);
1712  (void) FT_Glyph_Transform(glyph.image,&affine,&glyph.origin);
1713  ft_status=FT_Glyph_To_Bitmap(&glyph.image,FT_RENDER_MODE_NORMAL,
1714  (FT_Vector *) NULL,MagickTrue);
1715  if (ft_status != 0)
1716  continue;
1717  bitmap=(FT_BitmapGlyph) glyph.image;
1718  point.x=offset->x+bitmap->left;
1719  if (bitmap->bitmap.pixel_mode == ft_pixel_mode_mono)
1720  point.x+=(origin.x/64.0);
1721  point.y=offset->y-bitmap->top;
1722  if (draw_info->render != MagickFalse)
1723  {
1724  CacheView
1725  *image_view;
1726 
1728  transparent_fill;
1729 
1730  unsigned char
1731  *r;
1732 
1733  /*
1734  Rasterize the glyph.
1735  */
1736  transparent_fill=((draw_info->fill.alpha == TransparentAlpha) &&
1737  (draw_info->fill_pattern == (Image *) NULL) &&
1738  (draw_info->stroke.alpha == TransparentAlpha) &&
1739  (draw_info->stroke_pattern == (Image *) NULL)) ? MagickTrue :
1740  MagickFalse;
1741  image_view=AcquireAuthenticCacheView(image,exception);
1742  r=bitmap->bitmap.buffer;
1743  for (y=0; y < (ssize_t) bitmap->bitmap.rows; y++)
1744  {
1745  double
1746  fill_opacity;
1747 
1749  active,
1750  sync;
1751 
1752  PixelInfo
1753  fill_color;
1754 
1755  Quantum
1756  *magick_restrict q;
1757 
1758  ssize_t
1759  x;
1760 
1761  ssize_t
1762  n,
1763  x_offset,
1764  y_offset;
1765 
1766  if (status == MagickFalse)
1767  continue;
1768  x_offset=CastDoubleToLong(ceil(point.x-0.5));
1769  y_offset=CastDoubleToLong(ceil(point.y+y-0.5));
1770  if ((y_offset < 0) || (y_offset >= (ssize_t) image->rows))
1771  continue;
1772  q=(Quantum *) NULL;
1773  if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns))
1774  active=MagickFalse;
1775  else
1776  {
1777  q=GetCacheViewAuthenticPixels(image_view,x_offset,y_offset,
1778  bitmap->bitmap.width,1,exception);
1779  active=q != (Quantum *) NULL ? MagickTrue : MagickFalse;
1780  }
1781  n=y*bitmap->bitmap.pitch;
1782  for (x=0; x < (ssize_t) bitmap->bitmap.width; x++, n++)
1783  {
1784  x_offset=CastDoubleToLong(ceil(point.x+x-0.5));
1785  if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns))
1786  {
1787  if (q != (Quantum *) NULL)
1788  q+=GetPixelChannels(image);
1789  continue;
1790  }
1791  fill_opacity=1.0;
1792  if (bitmap->bitmap.buffer != (unsigned char *) NULL)
1793  {
1794  if (bitmap->bitmap.pixel_mode == ft_pixel_mode_grays)
1795  fill_opacity=(double) (r[n])/(bitmap->bitmap.num_grays-1);
1796  else
1797  if (bitmap->bitmap.pixel_mode == ft_pixel_mode_mono)
1798  fill_opacity=((r[(x >> 3)+y*bitmap->bitmap.pitch] &
1799  (1 << (~x & 0x07)))) == 0 ? 0.0 : 1.0;
1800  }
1801  if (draw_info->text_antialias == MagickFalse)
1802  fill_opacity=fill_opacity >= 0.5 ? 1.0 : 0.0;
1803  if (active == MagickFalse)
1804  q=GetCacheViewAuthenticPixels(image_view,x_offset,y_offset,1,1,
1805  exception);
1806  if (q == (Quantum *) NULL)
1807  continue;
1808  if (transparent_fill == MagickFalse)
1809  {
1810  GetPixelInfo(image,&fill_color);
1811  GetFillColor(draw_info,x_offset,y_offset,&fill_color,exception);
1812  fill_opacity=fill_opacity*fill_color.alpha;
1813  CompositePixelOver(image,&fill_color,fill_opacity,q,
1814  GetPixelAlpha(image,q),q);
1815  }
1816  else
1817  {
1818  double
1819  Sa,
1820  Da;
1821 
1822  Da=1.0-(QuantumScale*GetPixelAlpha(image,q));
1823  Sa=fill_opacity;
1824  fill_opacity=(1.0-RoundToUnity(Sa+Da-Sa*Da))*QuantumRange;
1825  SetPixelAlpha(image,fill_opacity,q);
1826  }
1827  if (active == MagickFalse)
1828  {
1829  sync=SyncCacheViewAuthenticPixels(image_view,exception);
1830  if (sync == MagickFalse)
1831  status=MagickFalse;
1832  }
1833  q+=GetPixelChannels(image);
1834  }
1835  sync=SyncCacheViewAuthenticPixels(image_view,exception);
1836  if (sync == MagickFalse)
1837  status=MagickFalse;
1838  }
1839  image_view=DestroyCacheView(image_view);
1840  if (((draw_info->stroke.alpha != TransparentAlpha) ||
1841  (draw_info->stroke_pattern != (Image *) NULL)) &&
1842  (status != MagickFalse))
1843  {
1844  /*
1845  Draw text stroke.
1846  */
1847  annotate_info->linejoin=RoundJoin;
1848  annotate_info->affine.tx=offset->x;
1849  annotate_info->affine.ty=offset->y;
1850  (void) ConcatenateString(&annotate_info->primitive,"'");
1851  if (strlen(annotate_info->primitive) > 7)
1852  (void) DrawImage(image,annotate_info,exception);
1853  (void) CloneString(&annotate_info->primitive,"path '");
1854  }
1855  }
1856  if ((fabs(draw_info->interword_spacing) >= MagickEpsilon) &&
1857  (IsUTFSpace(GetUTFCode(p+grapheme[i].cluster)) != MagickFalse) &&
1858  (IsUTFSpace(code) == MagickFalse))
1859  origin.x+=(FT_Pos) (64.0*draw_info->interword_spacing);
1860  else
1861  if (i == last_character)
1862  origin.x+=MagickMax((FT_Pos) grapheme[i].x_advance,bounds.xMax);
1863  else
1864  origin.x+=(FT_Pos) grapheme[i].x_advance;
1865  metrics->origin.x=(double) origin.x;
1866  metrics->origin.y=(double) origin.y;
1867  if (metrics->origin.x > metrics->width)
1868  metrics->width=metrics->origin.x;
1869  last_glyph_id=glyph.id;
1870  code=GetUTFCode(p+grapheme[i].cluster);
1871  }
1872  if (grapheme != (GraphemeInfo *) NULL)
1873  grapheme=(GraphemeInfo *) RelinquishMagickMemory(grapheme);
1874  if (utf8 != (unsigned char *) NULL)
1875  utf8=(unsigned char *) RelinquishMagickMemory(utf8);
1876  if (glyph.image != (FT_Glyph) NULL)
1877  {
1878  FT_Done_Glyph(glyph.image);
1879  glyph.image=(FT_Glyph) NULL;
1880  }
1881  /*
1882  Determine font metrics.
1883  */
1884  metrics->bounds.x1/=64.0;
1885  metrics->bounds.y1/=64.0;
1886  metrics->bounds.x2/=64.0;
1887  metrics->bounds.y2/=64.0;
1888  metrics->origin.x/=64.0;
1889  metrics->origin.y/=64.0;
1890  metrics->width=ceil(metrics->width/64.0);
1891  /*
1892  Relinquish resources.
1893  */
1894  annotate_info=DestroyDrawInfo(annotate_info);
1895  (void) FT_Done_Face(face);
1896  (void) FT_Done_FreeType(library);
1897  return(status);
1898 }
1899 #else
1900 static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
1901  const char *magick_unused(encoding),const PointInfo *offset,
1902  TypeMetric *metrics,ExceptionInfo *exception)
1903 {
1904  (void) ThrowMagickException(exception,GetMagickModule(),
1905  MissingDelegateWarning,"DelegateLibrarySupportNotBuiltIn","'%s' (Freetype)",
1906  draw_info->font != (char *) NULL ? draw_info->font : "none");
1907  return(RenderPostscript(image,draw_info,offset,metrics,exception));
1908 }
1909 #endif
1910 
1911 /*
1912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1913 % %
1914 % %
1915 % %
1916 + R e n d e r P o s t s c r i p t %
1917 % %
1918 % %
1919 % %
1920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1921 %
1922 % RenderPostscript() renders text on the image with a Postscript font. It
1923 % also returns the bounding box of the text relative to the image.
1924 %
1925 % The format of the RenderPostscript method is:
1926 %
1927 % MagickBooleanType RenderPostscript(Image *image,DrawInfo *draw_info,
1928 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
1929 %
1930 % A description of each parameter follows:
1931 %
1932 % o image: the image.
1933 %
1934 % o draw_info: the draw info.
1935 %
1936 % o offset: (x,y) location of text relative to image.
1937 %
1938 % o metrics: bounding box of text.
1939 %
1940 % o exception: return any errors or warnings in this structure.
1941 %
1942 */
1943 
1944 static char *EscapeParenthesis(const char *source)
1945 {
1946  char
1947  *destination;
1948 
1949  char
1950  *q;
1951 
1952  const char
1953  *p;
1954 
1955  size_t
1956  length;
1957 
1958  assert(source != (const char *) NULL);
1959  length=0;
1960  for (p=source; *p != '\0'; p++)
1961  {
1962  if ((*p == '\\') || (*p == '(') || (*p == ')'))
1963  {
1964  if (~length < 1)
1965  ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
1966  length++;
1967  }
1968  length++;
1969  }
1970  destination=(char *) NULL;
1971  if (~length >= (MagickPathExtent-1))
1972  destination=(char *) AcquireQuantumMemory(length+MagickPathExtent,
1973  sizeof(*destination));
1974  if (destination == (char *) NULL)
1975  ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
1976  *destination='\0';
1977  q=destination;
1978  for (p=source; *p != '\0'; p++)
1979  {
1980  if ((*p == '\\') || (*p == '(') || (*p == ')'))
1981  *q++='\\';
1982  *q++=(*p);
1983  }
1984  *q='\0';
1985  return(destination);
1986 }
1987 
1989  const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
1990  ExceptionInfo *exception)
1991 {
1992  char
1993  filename[MagickPathExtent],
1994  geometry[MagickPathExtent],
1995  *text;
1996 
1997  FILE
1998  *file;
1999 
2000  Image
2001  *annotate_image;
2002 
2003  ImageInfo
2004  *annotate_info;
2005 
2006  int
2007  unique_file;
2008 
2010  identity;
2011 
2012  PointInfo
2013  extent,
2014  point,
2015  resolution;
2016 
2017  ssize_t
2018  i;
2019 
2020  size_t
2021  length;
2022 
2023  ssize_t
2024  y;
2025 
2026  /*
2027  Render label with a Postscript font.
2028  */
2029  if (image->debug != MagickFalse)
2031  "Font %s; pointsize %g",draw_info->font != (char *) NULL ?
2032  draw_info->font : "none",draw_info->pointsize);
2033  file=(FILE *) NULL;
2034  unique_file=AcquireUniqueFileResource(filename);
2035  if (unique_file != -1)
2036  file=fdopen(unique_file,"wb");
2037  if ((unique_file == -1) || (file == (FILE *) NULL))
2038  {
2039  ThrowFileException(exception,FileOpenError,"UnableToOpenFile",filename);
2040  return(MagickFalse);
2041  }
2042  (void) FormatLocaleFile(file,"%%!PS-Adobe-3.0\n");
2043  (void) FormatLocaleFile(file,"/ReencodeType\n");
2044  (void) FormatLocaleFile(file,"{\n");
2045  (void) FormatLocaleFile(file," findfont dup length\n");
2046  (void) FormatLocaleFile(file,
2047  " dict begin { 1 index /FID ne {def} {pop pop} ifelse } forall\n");
2048  (void) FormatLocaleFile(file,
2049  " /Encoding ISOLatin1Encoding def currentdict end definefont pop\n");
2050  (void) FormatLocaleFile(file,"} bind def\n");
2051  /*
2052  Sample to compute bounding box.
2053  */
2054  identity=(fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) &&
2055  (fabs(draw_info->affine.rx) < MagickEpsilon) &&
2056  (fabs(draw_info->affine.ry) < MagickEpsilon) ? MagickTrue : MagickFalse;
2057  extent.x=0.0;
2058  extent.y=0.0;
2059  length=strlen(draw_info->text);
2060  for (i=0; i <= (ssize_t) (length+2); i++)
2061  {
2062  point.x=fabs(draw_info->affine.sx*i*draw_info->pointsize+
2063  draw_info->affine.ry*2.0*draw_info->pointsize);
2064  point.y=fabs(draw_info->affine.rx*i*draw_info->pointsize+
2065  draw_info->affine.sy*2.0*draw_info->pointsize);
2066  if (point.x > extent.x)
2067  extent.x=point.x;
2068  if (point.y > extent.y)
2069  extent.y=point.y;
2070  }
2071  (void) FormatLocaleFile(file,"%g %g moveto\n",identity != MagickFalse ? 0.0 :
2072  extent.x/2.0,extent.y/2.0);
2073  (void) FormatLocaleFile(file,"%g %g scale\n",draw_info->pointsize,
2074  draw_info->pointsize);
2075  if ((draw_info->font == (char *) NULL) || (*draw_info->font == '\0') ||
2076  (strchr(draw_info->font,'/') != (char *) NULL))
2077  (void) FormatLocaleFile(file,
2078  "/Times-Roman-ISO dup /Times-Roman ReencodeType findfont setfont\n");
2079  else
2080  (void) FormatLocaleFile(file,
2081  "/%s-ISO dup /%s ReencodeType findfont setfont\n",draw_info->font,
2082  draw_info->font);
2083  (void) FormatLocaleFile(file,"[%g %g %g %g 0 0] concat\n",
2084  draw_info->affine.sx,-draw_info->affine.rx,-draw_info->affine.ry,
2085  draw_info->affine.sy);
2086  text=EscapeParenthesis(draw_info->text);
2087  if (identity == MagickFalse)
2088  (void) FormatLocaleFile(file,"(%s) stringwidth pop -0.5 mul -0.5 rmoveto\n",
2089  text);
2090  (void) FormatLocaleFile(file,"(%s) show\n",text);
2091  text=DestroyString(text);
2092  (void) FormatLocaleFile(file,"showpage\n");
2093  (void) fclose(file);
2094  (void) FormatLocaleString(geometry,MagickPathExtent,"%.20gx%.20g+0+0!",
2095  floor(extent.x+0.5),floor(extent.y+0.5));
2096  annotate_info=AcquireImageInfo();
2097  (void) FormatLocaleString(annotate_info->filename,MagickPathExtent,"ps:%s",
2098  filename);
2099  (void) CloneString(&annotate_info->page,geometry);
2100  if (draw_info->density != (char *) NULL)
2101  (void) CloneString(&annotate_info->density,draw_info->density);
2102  annotate_info->antialias=draw_info->text_antialias;
2103  annotate_image=ReadImage(annotate_info,exception);
2104  CatchException(exception);
2105  annotate_info=DestroyImageInfo(annotate_info);
2106  (void) RelinquishUniqueFileResource(filename);
2107  if (annotate_image == (Image *) NULL)
2108  return(MagickFalse);
2109  (void) NegateImage(annotate_image,MagickFalse,exception);
2110  resolution.x=DefaultResolution;
2111  resolution.y=DefaultResolution;
2112  if (draw_info->density != (char *) NULL)
2113  {
2114  GeometryInfo
2115  geometry_info;
2116 
2118  flags;
2119 
2120  flags=ParseGeometry(draw_info->density,&geometry_info);
2121  if ((flags & RhoValue) != 0)
2122  resolution.x=geometry_info.rho;
2123  resolution.y=resolution.x;
2124  if ((flags & SigmaValue) != 0)
2125  resolution.y=geometry_info.sigma;
2126  }
2127  if (identity == MagickFalse)
2128  (void) TransformImage(&annotate_image,"0x0",(char *) NULL,exception);
2129  else
2130  {
2132  crop_info;
2133 
2134  crop_info=GetImageBoundingBox(annotate_image,exception);
2135  crop_info.height=(size_t) ((resolution.y/DefaultResolution)*
2136  ExpandAffine(&draw_info->affine)*draw_info->pointsize+0.5);
2137  crop_info.y=CastDoubleToLong(ceil((resolution.y/DefaultResolution)*
2138  extent.y/8.0-0.5));
2139  (void) FormatLocaleString(geometry,MagickPathExtent,
2140  "%.20gx%.20g%+.20g%+.20g",(double) crop_info.width,(double)
2141  crop_info.height,(double) crop_info.x,(double) crop_info.y);
2142  (void) TransformImage(&annotate_image,geometry,(char *) NULL,exception);
2143  }
2144  metrics->pixels_per_em.x=(resolution.y/DefaultResolution)*
2145  ExpandAffine(&draw_info->affine)*draw_info->pointsize;
2146  metrics->pixels_per_em.y=metrics->pixels_per_em.x;
2147  metrics->ascent=metrics->pixels_per_em.y;
2148  metrics->descent=metrics->pixels_per_em.y/-5.0;
2149  metrics->width=(double) annotate_image->columns/
2150  ExpandAffine(&draw_info->affine);
2151  metrics->height=floor(metrics->ascent-metrics->descent+0.5);
2152  metrics->max_advance=metrics->pixels_per_em.x;
2153  metrics->bounds.x1=0.0;
2154  metrics->bounds.y1=metrics->descent;
2155  metrics->bounds.x2=metrics->ascent+metrics->descent;
2156  metrics->bounds.y2=metrics->ascent+metrics->descent;
2157  metrics->underline_position=(-2.0);
2158  metrics->underline_thickness=1.0;
2159  if (draw_info->render == MagickFalse)
2160  {
2161  annotate_image=DestroyImage(annotate_image);
2162  return(MagickTrue);
2163  }
2164  if (draw_info->fill.alpha != TransparentAlpha)
2165  {
2166  CacheView
2167  *annotate_view;
2168 
2170  sync;
2171 
2172  PixelInfo
2173  fill_color;
2174 
2175  /*
2176  Render fill color.
2177  */
2178  if (image->alpha_trait == UndefinedPixelTrait)
2179  (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
2180  if (annotate_image->alpha_trait == UndefinedPixelTrait)
2181  (void) SetImageAlphaChannel(annotate_image,OpaqueAlphaChannel,
2182  exception);
2183  fill_color=draw_info->fill;
2184  annotate_view=AcquireAuthenticCacheView(annotate_image,exception);
2185  for (y=0; y < (ssize_t) annotate_image->rows; y++)
2186  {
2187  ssize_t
2188  x;
2189 
2190  Quantum
2191  *magick_restrict q;
2192 
2193  q=GetCacheViewAuthenticPixels(annotate_view,0,y,annotate_image->columns,
2194  1,exception);
2195  if (q == (Quantum *) NULL)
2196  break;
2197  for (x=0; x < (ssize_t) annotate_image->columns; x++)
2198  {
2199  GetFillColor(draw_info,x,y,&fill_color,exception);
2200  SetPixelAlpha(annotate_image,ClampToQuantum((((double) QuantumScale*
2201  GetPixelIntensity(annotate_image,q)*fill_color.alpha))),q);
2202  SetPixelRed(annotate_image,fill_color.red,q);
2203  SetPixelGreen(annotate_image,fill_color.green,q);
2204  SetPixelBlue(annotate_image,fill_color.blue,q);
2205  q+=GetPixelChannels(annotate_image);
2206  }
2207  sync=SyncCacheViewAuthenticPixels(annotate_view,exception);
2208  if (sync == MagickFalse)
2209  break;
2210  }
2211  annotate_view=DestroyCacheView(annotate_view);
2212  (void) CompositeImage(image,annotate_image,OverCompositeOp,MagickTrue,
2213  (ssize_t) ceil(offset->x-0.5),(ssize_t) ceil(offset->y-(metrics->ascent+
2214  metrics->descent)-0.5),exception);
2215  }
2216  annotate_image=DestroyImage(annotate_image);
2217  return(MagickTrue);
2218 }
2219 
2220 /*
2221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2222 % %
2223 % %
2224 % %
2225 + R e n d e r X 1 1 %
2226 % %
2227 % %
2228 % %
2229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2230 %
2231 % RenderX11() renders text on the image with an X11 font. It also returns the
2232 % bounding box of the text relative to the image.
2233 %
2234 % The format of the RenderX11 method is:
2235 %
2236 % MagickBooleanType RenderX11(Image *image,DrawInfo *draw_info,
2237 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
2238 %
2239 % A description of each parameter follows:
2240 %
2241 % o image: the image.
2242 %
2243 % o draw_info: the draw info.
2244 %
2245 % o offset: (x,y) location of text relative to image.
2246 %
2247 % o metrics: bounding box of text.
2248 %
2249 % o exception: return any errors or warnings in this structure.
2250 %
2251 */
2252 static MagickBooleanType RenderX11(Image *image,const DrawInfo *draw_info,
2253  const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
2254 {
2256  status;
2257 
2258  if (annotate_semaphore == (SemaphoreInfo *) NULL)
2261  status=XRenderImage(image,draw_info,offset,metrics,exception);
2263  return(status);
2264 }
double psi
Definition: geometry.h:108
size_t rows
Definition: image.h:172
#define magick_restrict
Definition: MagickCore.h:41
size_t face
Definition: type.h:53
PixelInfo fill
Definition: draw.h:214
MagickExport MagickBooleanType NegateImage(Image *image, const MagickBooleanType grayscale, ExceptionInfo *exception)
Definition: enhance.c:3923
MagickExport CacheView * DestroyCacheView(CacheView *cache_view)
Definition: cache-view.c:252
PixelInfo undercolor
Definition: draw.h:214
MagickExport TokenInfo * DestroyTokenInfo(TokenInfo *token_info)
Definition: token.c:129
#define TransparentAlpha
Definition: image.h:26
char * primitive
Definition: draw.h:204
double x2
Definition: image.h:107
double rx
Definition: geometry.h:97
MagickExport MagickBooleanType QueryColorname(const Image *magick_unused(image), const PixelInfo *color, const ComplianceType compliance, char *name, ExceptionInfo *exception)
Definition: color.c:2661
MagickExport ImageInfo * AcquireImageInfo(void)
Definition: image.c:326
MagickPrivate void AnnotateComponentTerminus(void)
Definition: annotate.c:189
double interword_spacing
Definition: draw.h:312
MagickExport size_t ConcatenateMagickString(char *magick_restrict destination, const char *magick_restrict source, const size_t length)
Definition: string.c:392
static Quantum GetPixelAlpha(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
GravityType gravity
Definition: draw.h:285
MagickExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:449
MagickExport const TypeInfo * GetTypeInfo(const char *name, ExceptionInfo *exception)
Definition: type.c:274
double interline_spacing
Definition: draw.h:312
static int GetUTFCode(const char *magick_restrict text)
static MagickBooleanType IsNonBreakingUTFSpace(const int code)
#define ThrowFatalException(severity, tag)
PixelInfo stroke
Definition: draw.h:214
double ty
Definition: geometry.h:97
size_t cluster
Definition: annotate.c:124
char * metrics
Definition: type.h:71
double kerning
Definition: draw.h:312
Definition: draw.h:90
double rho
Definition: geometry.h:108
static void GetFillColor(const DrawInfo *draw_info, const ssize_t x, const ssize_t y, PixelInfo *fill, ExceptionInfo *exception)
Definition: draw-private.h:29
MagickExport void SetGeometryInfo(GeometryInfo *geometry_info)
Definition: geometry.c:1748
Image * fill_pattern
Definition: draw.h:220
MagickExport SemaphoreInfo * AcquireSemaphoreInfo(void)
Definition: semaphore.c:192
MagickBooleanType render
Definition: draw.h:306
MagickRealType red
Definition: pixel.h:193
MagickBooleanType antialias
Definition: image.h:384
double pointsize
Definition: draw.h:276
MagickExport ExceptionInfo * AcquireExceptionInfo(void)
Definition: exception.c:115
StyleType style
Definition: draw.h:264
DecorationType decorate
Definition: draw.h:249
MagickExport ssize_t FormatLocaleString(char *magick_restrict string, const size_t length, const char *magick_restrict format,...)
Definition: locale.c:465
static MagickBooleanType IsGrayColorspace(const ColorspaceType colorspace)
MagickExport size_t CopyMagickString(char *magick_restrict destination, const char *magick_restrict source, const size_t length)
Definition: string.c:731
#define DefaultResolution
Definition: image-private.h:27
static MagickBooleanType RenderPostscript(Image *, const DrawInfo *, const PointInfo *, TypeMetric *, ExceptionInfo *)
Definition: annotate.c:1988
size_t y_offset
Definition: annotate.c:118
MagickRealType alpha
Definition: pixel.h:193
Definition: draw.h:34
#define MagickEpsilon
Definition: magick-type.h:114
double sigma
Definition: geometry.h:108
ClassType storage_class
Definition: image.h:154
MagickExport MagickBooleanType CompositeImage(Image *image, const Image *composite, const CompositeOperator compose, const MagickBooleanType clip_to_self, const ssize_t x_offset, const ssize_t y_offset, ExceptionInfo *exception)
Definition: composite.c:528
AffineMatrix affine
Definition: draw.h:211
size_t width
Definition: geometry.h:132
MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type, const MagickSizeType size)
Definition: resource.c:188
#define ThrowBinaryException(severity, tag, context)
Definition: log.h:52
static Quantum ClampToQuantum(const MagickRealType quantum)
Definition: quantum.h:85
MagickExport void GetPixelInfo(const Image *image, PixelInfo *pixel)
Definition: pixel.c:2175
Definition: image.h:151
double tx
Definition: geometry.h:97
double x
Definition: geometry.h:125
MagickExport TokenInfo * AcquireTokenInfo(void)
Definition: token.c:96
#define MagickCoreSignature
MagickExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:293
MagickExport Quantum * GetCacheViewAuthenticPixels(CacheView *cache_view, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
Definition: cache-view.c:299
static MagickBooleanType RenderType(Image *, const DrawInfo *, const PointInfo *, TypeMetric *, ExceptionInfo *)
Definition: annotate.c:966
double stroke_width
Definition: draw.h:224
MagickExport double ExpandAffine(const AffineMatrix *affine)
Definition: gem.c:1470
MagickExport ssize_t FormatMagickCaption(Image *image, DrawInfo *draw_info, const MagickBooleanType split, TypeMetric *metrics, char **caption, ExceptionInfo *exception)
Definition: annotate.c:622
Image * stroke_pattern
Definition: draw.h:220
MagickExport ssize_t FormatLocaleFile(FILE *file, const char *magick_restrict format,...)
Definition: locale.c:370
MagickExport MagickBooleanType SetImageAlphaChannel(Image *image, const AlphaChannelOption alpha_type, ExceptionInfo *exception)
Definition: channel.c:974
MagickBooleanType
Definition: magick-type.h:161
unsigned int MagickStatusType
Definition: magick-type.h:125
MagickExport char * AcquireString(const char *source)
Definition: string.c:94
MagickExport MagickStatusType ParsePageGeometry(const Image *image, const char *geometry, RectangleInfo *region_info, ExceptionInfo *exception)
Definition: geometry.c:1606
static double PerceptibleReciprocal(const double x)
MagickExport int AcquireUniqueFileResource(char *path)
Definition: resource.c:551
LineJoin linejoin
Definition: draw.h:240
MagickExport MagickBooleanType AnnotateImage(Image *image, const DrawInfo *draw_info, ExceptionInfo *exception)
Definition: annotate.c:223
char * family
Definition: type.h:56
double width
Definition: draw.h:372
static MagickBooleanType IsUTFSpace(const int code)
PointInfo origin
Definition: draw.h:384
double height
Definition: draw.h:372
double x1
Definition: image.h:107
double descent
Definition: draw.h:372
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:665
char filename[MagickPathExtent]
Definition: image.h:480
char * metrics
Definition: draw.h:255
size_t face
Definition: draw.h:261
double y
Definition: geometry.h:125
MagickExport MagickBooleanType RelinquishUniqueFileResource(const char *path)
Definition: resource.c:1098
#define magick_unused(x)
RectangleInfo page
Definition: image.h:212
MagickPrivate MagickBooleanType XRenderImage(Image *, const DrawInfo *, const PointInfo *, TypeMetric *, ExceptionInfo *)
Definition: xwindow.c:9977
size_t x_advance
Definition: annotate.c:118
char * family
Definition: draw.h:255
size_t MagickSizeType
Definition: magick-type.h:134
#define MagickPathExtent
double ry
Definition: geometry.h:97
char * glyphs
Definition: type.h:71
MagickExport MagickBooleanType DrawImage(Image *image, const DrawInfo *draw_info, ExceptionInfo *exception)
Definition: draw.c:4471
Definition: type.h:50
static SemaphoreInfo * annotate_semaphore
Definition: annotate.c:131
#define ThrowFileException(exception, severity, tag, context)
PixelTrait alpha_trait
Definition: image.h:280
MagickRealType blue
Definition: pixel.h:193
PointInfo pixels_per_em
Definition: draw.h:369
MagickExport Image * ReadImage(const ImageInfo *image_info, ExceptionInfo *exception)
Definition: constitute.c:429
static MagickBooleanType RenderX11(Image *, const DrawInfo *, const PointInfo *, TypeMetric *, ExceptionInfo *)
Definition: annotate.c:2252
double sx
Definition: geometry.h:97
double y2
Definition: image.h:107
MagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *tag, const char *format,...)
Definition: exception.c:1145
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1662
MagickExport MagickBooleanType IsPathAccessible(const char *path)
Definition: utility.c:1492
char * density
Definition: draw.h:279
size_t signature
Definition: image.h:354
#define QuantumScale
Definition: magick-type.h:119
size_t columns
Definition: image.h:172
MagickExport const TypeInfo * GetTypeInfoByFamily(const char *family, const StyleType style, const StretchType stretch, const size_t weight, ExceptionInfo *exception)
Definition: type.c:320
ssize_t x
Definition: geometry.h:136
StretchType stretch
Definition: draw.h:267
MagickExport DrawInfo * CloneDrawInfo(const ImageInfo *image_info, const DrawInfo *draw_info)
Definition: draw.c:269
size_t height
Definition: geometry.h:132
static void SetPixelBlue(const Image *magick_restrict image, const Quantum blue, Quantum *magick_restrict pixel)
MagickPrivate MagickBooleanType AnnotateComponentGenesis(void)
Definition: annotate.c:164
MagickExport MagickBooleanType SetImageStorageClass(Image *image, const ClassType storage_class, ExceptionInfo *exception)
Definition: image.c:2613
MagickExport void CatchException(ExceptionInfo *exception)
Definition: exception.c:203
static double RoundToUnity(const double value)
char * encoding
Definition: draw.h:273
#define MagickMax(x, y)
Definition: image-private.h:36
static size_t GetPixelChannels(const Image *magick_restrict image)
MagickExport int LocaleCompare(const char *p, const char *q)
Definition: locale.c:1401
static ssize_t CastDoubleToLong(const double value)
Definition: image-private.h:53
char filename[MagickPathExtent]
Definition: image.h:319
double max_advance
Definition: draw.h:372
#define GetMagickModule()
Definition: log.h:28
double sy
Definition: geometry.h:97
double underline_thickness
Definition: draw.h:372
MagickExport MagickBooleanType GetMultilineTypeMetrics(Image *image, const DrawInfo *draw_info, TypeMetric *metrics, ExceptionInfo *exception)
Definition: annotate.c:753
char * density
Definition: image.h:413
SegmentInfo bounds
Definition: draw.h:381
MagickExport ImageInfo * DestroyImageInfo(ImageInfo *image_info)
Definition: image.c:1247
size_t signature
Definition: draw.h:323
MagickExport MagickBooleanType GetTypeMetrics(Image *image, const DrawInfo *draw_info, TypeMetric *metrics, ExceptionInfo *exception)
Definition: annotate.c:894
char * geometry
Definition: draw.h:204
unsigned short Quantum
Definition: magick-type.h:86
double xi
Definition: geometry.h:108
MagickExport RectangleInfo GetImageBoundingBox(const Image *image, ExceptionInfo *exception)
Definition: attribute.c:389
MagickExport MagickBooleanType SetImageColorspace(Image *image, const ColorspaceType colorspace, ExceptionInfo *exception)
Definition: colorspace.c:1419
MagickExport DrawInfo * DestroyDrawInfo(DrawInfo *draw_info)
Definition: draw.c:966
MagickExport char * DestroyString(char *string)
Definition: string.c:788
MagickExport void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:98
size_t index
Definition: annotate.c:118
MagickExport const char * GetImageProperty(const Image *image, const char *property, ExceptionInfo *exception)
Definition: property.c:2216
AlignType align
Definition: draw.h:282
double underline_position
Definition: draw.h:372
static char * EscapeParenthesis(const char *source)
Definition: annotate.c:1944
MagickBooleanType text_antialias
Definition: draw.h:230
MagickExport MagickStatusType ParseGeometry(const char *geometry, GeometryInfo *geometry_info)
Definition: geometry.c:866
size_t x_offset
Definition: annotate.c:118
MagickExport char * GetPolicyValue(const char *name)
Definition: policy.c:531
static void SetPixelAlpha(const Image *magick_restrict image, const Quantum alpha, Quantum *magick_restrict pixel)
MagickExport void SetGeometry(const Image *image, RectangleInfo *geometry)
Definition: geometry.c:1714
MagickExport MagickBooleanType ConcatenateString(char **magick_restrict destination, const char *magick_restrict source)
Definition: string.c:458
static MagickBooleanType RenderFreetype(Image *, const DrawInfo *, const char *, const PointInfo *, TypeMetric *, ExceptionInfo *)
char * text
Definition: draw.h:255
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1162
#define magick_unreferenced(x)
double ascent
Definition: draw.h:372
static unsigned int GetUTFOctets(const char *magick_restrict text)
char * encoding
Definition: type.h:71
MagickRealType green
Definition: pixel.h:193
MagickExport char * CloneString(char **destination, const char *source)
Definition: string.c:250
MagickExport char ** StringToStrings(const char *text, size_t *count)
Definition: string.c:2329
static void SetPixelRed(const Image *magick_restrict image, const Quantum red, Quantum *magick_restrict pixel)
#define MagickPrivate
static unsigned char * ConvertLatin1ToUTF8(const unsigned char *magick_restrict content)
Definition: token-private.h:54
#define MagickExport
MagickExport MagickBooleanType SyncCacheViewAuthenticPixels(CacheView *magick_restrict cache_view, ExceptionInfo *exception)
Definition: cache-view.c:1100
ssize_t y
Definition: geometry.h:136
MagickExport CacheView * AcquireAuthenticCacheView(const Image *image, ExceptionInfo *exception)
Definition: cache-view.c:112
double y1
Definition: image.h:107
MagickExport char ** StringToArgv(const char *text, int *argc)
Definition: string.c:2021
static char * ReplaceSpaceWithNewline(char **caption, char *space)
Definition: annotate.c:592
char * page
Definition: image.h:390
double * dash_pattern
Definition: draw.h:291
MagickExport MagickRealType GetPixelIntensity(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
Definition: pixel.c:2363
char * font
Definition: draw.h:255
MagickExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:351
DirectionType direction
Definition: draw.h:317
MagickExport Image * DestroyImage(Image *image)
Definition: image.c:1176
MagickExport char * ConstantString(const char *source)
Definition: string.c:678
ColorspaceType colorspace
Definition: image.h:157
#define QuantumRange
Definition: magick-type.h:87
MagickExport int Tokenizer(TokenInfo *token_info, const unsigned flag, char *token, const size_t max_token_length, const char *line, const char *white, const char *break_set, const char *quote, const char escape, char *breaker, int *next, char *quoted)
Definition: token.c:833
static void CompositePixelOver(const Image *image, const PixelInfo *p, const double alpha, const Quantum *q, const double beta, Quantum *composite)
MagickBooleanType debug
Definition: image.h:334
MagickExport ExceptionInfo * DestroyExceptionInfo(ExceptionInfo *exception)
Definition: exception.c:418
static void SetPixelGreen(const Image *magick_restrict image, const Quantum green, Quantum *magick_restrict pixel)
struct _GraphemeInfo GraphemeInfo
size_t weight
Definition: draw.h:270
MagickPrivate MagickBooleanType TransformImage(Image **, const char *, const char *, ExceptionInfo *)
Definition: transform.c:2034