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 MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
592  const MagickBooleanType split,TypeMetric *metrics,char **caption,
593  ExceptionInfo *exception)
594 {
596  status;
597 
598  char
599  *p = (*caption),
600  *q = draw_info->text,
601  *s = (char *) NULL;
602 
603  size_t
604  width = 0;
605 
606  ssize_t
607  i,
608  n;
609 
610  for ( ; GetUTFCode(p) != 0; p+=GetUTFOctets(p))
611  {
612  if (GetUTFCode(p) == '\n')
613  {
614  q=draw_info->text;
615  continue;
616  }
617  if (IsUTFSpace(GetUTFCode(p)) != MagickFalse)
618  {
619  s=p;
620  if (width > image->columns)
621  {
622  for (i=0; i < (ssize_t) GetUTFOctets(s); i++)
623  *(s+i)=' ';
624  *s='\n';
625  p=s;
626  }
627  }
628  for (i=0; i < (ssize_t) GetUTFOctets(p); i++)
629  *q++=(*(p+i));
630  *q='\0';
631  status=GetTypeMetrics(image,draw_info,metrics,exception);
632  if (status == MagickFalse)
633  break;
634  width=(size_t) floor(metrics->width+draw_info->stroke_width+0.5);
635  if (width <= image->columns)
636  continue;
637  if (s != (char *) NULL)
638  {
639  for (i=0; i < (ssize_t) GetUTFOctets(s); i++)
640  *(s+i)=' ';
641  *s='\n';
642  p=s;
643  }
644  else
645  if ((split != MagickFalse) || (GetUTFOctets(p) > 2))
646  {
647  /*
648  No convenient line breaks-- insert newline.
649  */
650  n=p-(*caption);
651  if ((n > 0) && ((*caption)[n-1] != '\n'))
652  {
653  char
654  *target;
655 
656  target=AcquireString(*caption);
657  CopyMagickString(target,*caption,n+1);
658  ConcatenateMagickString(target,"\n",strlen(*caption)+1);
659  ConcatenateMagickString(target,p,strlen(*caption)+2);
660  (void) DestroyString(*caption);
661  *caption=target;
662  p=(*caption)+n;
663  }
664  }
665  q=draw_info->text;
666  s=(char *) NULL;
667  }
668  n=0;
669  for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p))
670  if (GetUTFCode(p) == '\n')
671  n++;
672  return(n);
673 }
674 
675 /*
676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
677 % %
678 % %
679 % %
680 % G e t M u l t i l i n e T y p e M e t r i c s %
681 % %
682 % %
683 % %
684 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
685 %
686 % GetMultilineTypeMetrics() returns the following information for the
687 % specified font and text:
688 %
689 % character width
690 % character height
691 % ascender
692 % descender
693 % text width
694 % text height
695 % maximum horizontal advance
696 % bounds: x1
697 % bounds: y1
698 % bounds: x2
699 % bounds: y2
700 % origin: x
701 % origin: y
702 % underline position
703 % underline thickness
704 %
705 % This method is like GetTypeMetrics() but it returns the maximum text width
706 % and height for multiple lines of text.
707 %
708 % The format of the GetMultilineTypeMetrics method is:
709 %
710 % MagickBooleanType GetMultilineTypeMetrics(Image *image,
711 % const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception)
712 %
713 % A description of each parameter follows:
714 %
715 % o image: the image.
716 %
717 % o draw_info: the draw info.
718 %
719 % o metrics: Return the font metrics in this structure.
720 %
721 % o exception: return any errors or warnings in this structure.
722 %
723 */
725  const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception)
726 {
727  char
728  **textlist;
729 
730  double
731  height;
732 
733  DrawInfo
734  *annotate_info;
735 
737  status;
738 
740  size;
741 
742  ssize_t
743  i;
744 
745  size_t
746  count;
747 
748  TypeMetric
749  extent;
750 
751  assert(image != (Image *) NULL);
752  assert(image->signature == MagickCoreSignature);
753  if (image->debug != MagickFalse)
754  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
755  assert(draw_info != (DrawInfo *) NULL);
756  assert(draw_info->text != (char *) NULL);
757  assert(draw_info->signature == MagickCoreSignature);
758  if (*draw_info->text == '\0')
759  return(MagickFalse);
760  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
761  annotate_info->text=DestroyString(annotate_info->text);
762  /*
763  Convert newlines to multiple lines of text.
764  */
765  textlist=StringToStrings(draw_info->text,&count);
766  if (textlist == (char **) NULL)
767  return(MagickFalse);
768  annotate_info->render=MagickFalse;
769  annotate_info->direction=UndefinedDirection;
770  (void) memset(metrics,0,sizeof(*metrics));
771  (void) memset(&extent,0,sizeof(extent));
772  /*
773  Find the widest of the text lines.
774  */
775  annotate_info->text=textlist[0];
776  status=GetTypeMetrics(image,annotate_info,&extent,exception);
777  *metrics=extent;
778  height=(count*(size_t) (metrics->ascent-metrics->descent+
779  0.5)+(count-1)*draw_info->interline_spacing);
780  size=(MagickSizeType) fabs(height);
782  {
784  "WidthOrHeightExceedsLimit","`%s'",image->filename);
785  status=MagickFalse;
786  }
787  else
788  {
789  for (i=1; i < (ssize_t) count; i++)
790  {
791  annotate_info->text=textlist[i];
792  status=GetTypeMetrics(image,annotate_info,&extent,exception);
793  if (status == MagickFalse)
794  break;
795  if (extent.width > metrics->width)
796  *metrics=extent;
797  size=(MagickSizeType) fabs(extent.width);
799  {
801  "WidthOrHeightExceedsLimit","`%s'",image->filename);
802  status=MagickFalse;
803  break;
804  }
805  }
806  metrics->height=(double) height;
807  }
808  /*
809  Relinquish resources.
810  */
811  annotate_info->text=(char *) NULL;
812  annotate_info=DestroyDrawInfo(annotate_info);
813  for (i=0; i < (ssize_t) count; i++)
814  textlist[i]=DestroyString(textlist[i]);
815  textlist=(char **) RelinquishMagickMemory(textlist);
816  return(status);
817 }
818 
819 /*
820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821 % %
822 % %
823 % %
824 % G e t T y p e M e t r i c s %
825 % %
826 % %
827 % %
828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
829 %
830 % GetTypeMetrics() returns the following information for the specified font
831 % and text:
832 %
833 % character width
834 % character height
835 % ascender
836 % descender
837 % text width
838 % text height
839 % maximum horizontal advance
840 % bounds: x1
841 % bounds: y1
842 % bounds: x2
843 % bounds: y2
844 % origin: x
845 % origin: y
846 % underline position
847 % underline thickness
848 %
849 % The format of the GetTypeMetrics method is:
850 %
851 % MagickBooleanType GetTypeMetrics(Image *image,const DrawInfo *draw_info,
852 % TypeMetric *metrics,ExceptionInfo *exception)
853 %
854 % A description of each parameter follows:
855 %
856 % o image: the image.
857 %
858 % o draw_info: the draw info.
859 %
860 % o metrics: Return the font metrics in this structure.
861 %
862 % o exception: return any errors or warnings in this structure.
863 %
864 */
866  const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception)
867 {
868  DrawInfo
869  *annotate_info;
870 
872  status;
873 
874  PointInfo
875  offset;
876 
877  assert(image != (Image *) NULL);
878  assert(image->signature == MagickCoreSignature);
879  if (image->debug != MagickFalse)
880  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
881  assert(draw_info != (DrawInfo *) NULL);
882  assert(draw_info->text != (char *) NULL);
883  assert(draw_info->signature == MagickCoreSignature);
884  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
885  annotate_info->render=MagickFalse;
886  annotate_info->direction=UndefinedDirection;
887  (void) memset(metrics,0,sizeof(*metrics));
888  offset.x=0.0;
889  offset.y=0.0;
890  status=RenderType(image,annotate_info,&offset,metrics,exception);
891  if (image->debug != MagickFalse)
892  (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),"Metrics: text: %s; "
893  "width: %g; height: %g; ascent: %g; descent: %g; max advance: %g; "
894  "bounds: %g,%g %g,%g; origin: %g,%g; pixels per em: %g,%g; "
895  "underline position: %g; underline thickness: %g",annotate_info->text,
896  metrics->width,metrics->height,metrics->ascent,metrics->descent,
897  metrics->max_advance,metrics->bounds.x1,metrics->bounds.y1,
898  metrics->bounds.x2,metrics->bounds.y2,metrics->origin.x,metrics->origin.y,
899  metrics->pixels_per_em.x,metrics->pixels_per_em.y,
900  metrics->underline_position,metrics->underline_thickness);
901  annotate_info=DestroyDrawInfo(annotate_info);
902  return(status);
903 }
904 
905 /*
906 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
907 % %
908 % %
909 % %
910 + R e n d e r T y p e %
911 % %
912 % %
913 % %
914 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
915 %
916 % RenderType() renders text on the image. It also returns the bounding box of
917 % the text relative to the image.
918 %
919 % The format of the RenderType method is:
920 %
921 % MagickBooleanType RenderType(Image *image,DrawInfo *draw_info,
922 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
923 %
924 % A description of each parameter follows:
925 %
926 % o image: the image.
927 %
928 % o draw_info: the draw info.
929 %
930 % o offset: (x,y) location of text relative to image.
931 %
932 % o metrics: bounding box of text.
933 %
934 % o exception: return any errors or warnings in this structure.
935 %
936 */
937 static MagickBooleanType RenderType(Image *image,const DrawInfo *draw_info,
938  const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
939 {
940  char
941  *font;
942 
943  const TypeInfo
944  *type_info;
945 
946  DrawInfo
947  *annotate_info;
948 
950  *sans_exception;
951 
953  status;
954 
955  type_info=(const TypeInfo *) NULL;
956  if (draw_info->font != (char *) NULL)
957  {
958  if (*draw_info->font == '@')
959  {
960  status=RenderFreetype(image,draw_info,draw_info->encoding,offset,
961  metrics,exception);
962  return(status);
963  }
964  if (*draw_info->font == '-')
965  return(RenderX11(image,draw_info,offset,metrics,exception));
966  if (*draw_info->font == '^')
967  return(RenderPostscript(image,draw_info,offset,metrics,exception));
968  if (IsPathAccessible(draw_info->font) != MagickFalse)
969  {
970  status=RenderFreetype(image,draw_info,draw_info->encoding,offset,
971  metrics,exception);
972  return(status);
973  }
974  type_info=GetTypeInfo(draw_info->font,exception);
975  if (type_info == (const TypeInfo *) NULL)
977  "UnableToReadFont","`%s'",draw_info->font);
978  }
979  if ((type_info == (const TypeInfo *) NULL) &&
980  (draw_info->family != (const char *) NULL))
981  {
982  if (strchr(draw_info->family,',') == (char *) NULL)
983  type_info=GetTypeInfoByFamily(draw_info->family,draw_info->style,
984  draw_info->stretch,draw_info->weight,exception);
985  if (type_info == (const TypeInfo *) NULL)
986  {
987  char
988  **family;
989 
990  int
991  number_families;
992 
993  ssize_t
994  i;
995 
996  /*
997  Parse font family list.
998  */
999  family=StringToArgv(draw_info->family,&number_families);
1000  for (i=1; i < (ssize_t) number_families; i++)
1001  {
1002  type_info=GetTypeInfoByFamily(family[i],draw_info->style,
1003  draw_info->stretch,draw_info->weight,exception);
1004  if ((type_info != (const TypeInfo *) NULL) &&
1005  (LocaleCompare(family[i],type_info->family) == 0))
1006  break;
1007  }
1008  for (i=0; i < (ssize_t) number_families; i++)
1009  family[i]=DestroyString(family[i]);
1010  family=(char **) RelinquishMagickMemory(family);
1011  if (type_info == (const TypeInfo *) NULL)
1013  "UnableToReadFont","`%s'",draw_info->family);
1014  }
1015  }
1016  font=GetPolicyValue("system:font");
1017  if (font != (char *) NULL)
1018  {
1019  if (IsPathAccessible(font) != MagickFalse)
1020  {
1021  /*
1022  Render with default system font.
1023  */
1024  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1025  annotate_info->font=font;
1026  status=RenderFreetype(image,annotate_info,annotate_info->encoding,
1027  offset,metrics,exception);
1028  annotate_info=DestroyDrawInfo(annotate_info);
1029  return(status);
1030  }
1031  font=DestroyString(font);
1032  }
1033  sans_exception=AcquireExceptionInfo();
1034  if (type_info == (const TypeInfo *) NULL)
1035  type_info=GetTypeInfoByFamily("Open Sans",draw_info->style,
1036  draw_info->stretch,draw_info->weight,sans_exception);
1037  if (type_info == (const TypeInfo *) NULL)
1038  type_info=GetTypeInfoByFamily("Sans Serif",draw_info->style,
1039  draw_info->stretch,draw_info->weight,sans_exception);
1040  if (type_info == (const TypeInfo *) NULL)
1041  type_info=GetTypeInfoByFamily((const char *) NULL,draw_info->style,
1042  draw_info->stretch,draw_info->weight,sans_exception);
1043  if (type_info == (const TypeInfo *) NULL)
1044  type_info=GetTypeInfo("*",sans_exception);
1045  sans_exception=DestroyExceptionInfo(sans_exception);
1046  if (type_info == (const TypeInfo *) NULL)
1047  {
1048  status=RenderFreetype(image,draw_info,draw_info->encoding,offset,metrics,
1049  exception);
1050  return(status);
1051  }
1052  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1053  annotate_info->face=type_info->face;
1054  if (type_info->metrics != (char *) NULL)
1055  (void) CloneString(&annotate_info->metrics,type_info->metrics);
1056  if (type_info->glyphs != (char *) NULL)
1057  (void) CloneString(&annotate_info->font,type_info->glyphs);
1058  status=RenderFreetype(image,annotate_info,type_info->encoding,offset,metrics,
1059  exception);
1060  annotate_info=DestroyDrawInfo(annotate_info);
1061  return(status);
1062 }
1063 
1064 /*
1065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1066 % %
1067 % %
1068 % %
1069 + R e n d e r F r e e t y p e %
1070 % %
1071 % %
1072 % %
1073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1074 %
1075 % RenderFreetype() renders text on the image with a Truetype font. It also
1076 % returns the bounding box of the text relative to the image.
1077 %
1078 % The format of the RenderFreetype method is:
1079 %
1080 % MagickBooleanType RenderFreetype(Image *image,DrawInfo *draw_info,
1081 % const char *encoding,const PointInfo *offset,TypeMetric *metrics,
1082 % ExceptionInfo *exception)
1083 %
1084 % A description of each parameter follows:
1085 %
1086 % o image: the image.
1087 %
1088 % o draw_info: the draw info.
1089 %
1090 % o encoding: the font encoding.
1091 %
1092 % o offset: (x,y) location of text relative to image.
1093 %
1094 % o metrics: bounding box of text.
1095 %
1096 % o exception: return any errors or warnings in this structure.
1097 %
1098 */
1099 
1100 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
1101 
1102 static size_t ComplexTextLayout(const Image *image,const DrawInfo *draw_info,
1103  const char *text,const size_t length,const FT_Face face,const FT_Int32 flags,
1104  GraphemeInfo **grapheme,ExceptionInfo *exception)
1105 {
1106 #if defined(MAGICKCORE_RAQM_DELEGATE)
1107  const char
1108  *features;
1109 
1110  raqm_t
1111  *rq;
1112 
1113  raqm_glyph_t
1114  *glyphs;
1115 
1116  ssize_t
1117  i;
1118 
1119  size_t
1120  extent;
1121 
1122  magick_unreferenced(flags);
1123  extent=0;
1124  rq=raqm_create();
1125  if (rq == (raqm_t *) NULL)
1126  goto cleanup;
1127  if (raqm_set_text_utf8(rq,text,length) == 0)
1128  goto cleanup;
1129  if (raqm_set_par_direction(rq,(raqm_direction_t) draw_info->direction) == 0)
1130  goto cleanup;
1131  if (raqm_set_freetype_face(rq,face) == 0)
1132  goto cleanup;
1133  features=GetImageProperty(image,"type:features",exception);
1134  if (features != (const char *) NULL)
1135  {
1136  char
1137  breaker,
1138  quote,
1139  *token;
1140 
1141  int
1142  next,
1143  status_token;
1144 
1145  TokenInfo
1146  *token_info;
1147 
1148  next=0;
1149  token_info=AcquireTokenInfo();
1150  token=AcquireString("");
1151  status_token=Tokenizer(token_info,0,token,50,features,"",",","",'\0',
1152  &breaker,&next,&quote);
1153  while (status_token == 0)
1154  {
1155  raqm_add_font_feature(rq,token,(int) strlen(token));
1156  status_token=Tokenizer(token_info,0,token,50,features,"",",","",'\0',
1157  &breaker,&next,&quote);
1158  }
1159  token_info=DestroyTokenInfo(token_info);
1160  token=DestroyString(token);
1161  }
1162  if (raqm_layout(rq) == 0)
1163  goto cleanup;
1164  glyphs=raqm_get_glyphs(rq,&extent);
1165  if (glyphs == (raqm_glyph_t *) NULL)
1166  {
1167  extent=0;
1168  goto cleanup;
1169  }
1170  *grapheme=(GraphemeInfo *) AcquireQuantumMemory(extent,sizeof(**grapheme));
1171  if (*grapheme == (GraphemeInfo *) NULL)
1172  {
1173  extent=0;
1174  goto cleanup;
1175  }
1176  for (i=0; i < (ssize_t) extent; i++)
1177  {
1178  (*grapheme)[i].index=glyphs[i].index;
1179  (*grapheme)[i].x_offset=glyphs[i].x_offset;
1180  (*grapheme)[i].x_advance=glyphs[i].x_advance;
1181  (*grapheme)[i].y_offset=glyphs[i].y_offset;
1182  (*grapheme)[i].cluster=glyphs[i].cluster;
1183  }
1184 
1185 cleanup:
1186  raqm_destroy(rq);
1187  return(extent);
1188 #else
1189  const char
1190  *p;
1191 
1192  FT_Error
1193  ft_status;
1194 
1195  ssize_t
1196  i;
1197 
1198  ssize_t
1199  last_glyph;
1200 
1201  /*
1202  Simple layout for bi-directional text (right-to-left or left-to-right).
1203  */
1204  magick_unreferenced(image);
1205  magick_unreferenced(exception);
1206  *grapheme=(GraphemeInfo *) AcquireQuantumMemory(length+1,sizeof(**grapheme));
1207  if (*grapheme == (GraphemeInfo *) NULL)
1208  return(0);
1209  last_glyph=0;
1210  p=text;
1211  for (i=0; GetUTFCode(p) != 0; p+=GetUTFOctets(p), i++)
1212  {
1213  (*grapheme)[i].index=(ssize_t) FT_Get_Char_Index(face,GetUTFCode(p));
1214  (*grapheme)[i].x_offset=0;
1215  (*grapheme)[i].y_offset=0;
1216  if (((*grapheme)[i].index != 0) && (last_glyph != 0))
1217  {
1218  if (FT_HAS_KERNING(face))
1219  {
1220  FT_Vector
1221  kerning;
1222 
1223  ft_status=FT_Get_Kerning(face,(FT_UInt) last_glyph,(FT_UInt)
1224  (*grapheme)[i].index,ft_kerning_default,&kerning);
1225  if (ft_status == 0)
1226  (*grapheme)[i-1].x_advance+=(FT_Pos) ((draw_info->direction ==
1227  RightToLeftDirection ? -1.0 : 1.0)*kerning.x);
1228  }
1229  }
1230  ft_status=FT_Load_Glyph(face,(FT_UInt) (*grapheme)[i].index,flags);
1231  (*grapheme)[i].x_advance=face->glyph->advance.x;
1232  (*grapheme)[i].cluster=p-text;
1233  last_glyph=(*grapheme)[i].index;
1234  }
1235  return((size_t) i);
1236 #endif
1237 }
1238 
1239 static inline MagickBooleanType IsEmptyOutline(FT_Outline outline)
1240 {
1241  return((outline.n_points == 0) || (outline.n_contours <= 0) ? MagickTrue :
1242  MagickFalse);
1243 }
1244 
1245 static int TraceCubicBezier(FT_Vector *p,FT_Vector *q,FT_Vector *to,
1246  DrawInfo *draw_info)
1247 {
1248  AffineMatrix
1249  affine;
1250 
1251  char
1252  path[MagickPathExtent];
1253 
1254  affine=draw_info->affine;
1255  (void) FormatLocaleString(path,MagickPathExtent,"C%g,%g %g,%g %g,%g",
1256  affine.tx+p->x/64.0,affine.ty-p->y/64.0,affine.tx+q->x/64.0,affine.ty-
1257  q->y/64.0,affine.tx+to->x/64.0,affine.ty-to->y/64.0);
1258  (void) ConcatenateString(&draw_info->primitive,path);
1259  return(0);
1260 }
1261 
1262 static int TraceLineTo(FT_Vector *to,DrawInfo *draw_info)
1263 {
1264  AffineMatrix
1265  affine;
1266 
1267  char
1268  path[MagickPathExtent];
1269 
1270  affine=draw_info->affine;
1271  (void) FormatLocaleString(path,MagickPathExtent,"L%g,%g",affine.tx+to->x/64.0,
1272  affine.ty-to->y/64.0);
1273  (void) ConcatenateString(&draw_info->primitive,path);
1274  return(0);
1275 }
1276 
1277 static int TraceMoveTo(FT_Vector *to,DrawInfo *draw_info)
1278 {
1279  AffineMatrix
1280  affine;
1281 
1282  char
1283  path[MagickPathExtent];
1284 
1285  affine=draw_info->affine;
1286  (void) FormatLocaleString(path,MagickPathExtent,"M%g,%g",affine.tx+to->x/64.0,
1287  affine.ty-to->y/64.0);
1288  (void) ConcatenateString(&draw_info->primitive,path);
1289  return(0);
1290 }
1291 
1292 static int TraceQuadraticBezier(FT_Vector *control,FT_Vector *to,
1293  DrawInfo *draw_info)
1294 {
1295  AffineMatrix
1296  affine;
1297 
1298  char
1299  path[MagickPathExtent];
1300 
1301  affine=draw_info->affine;
1302  (void) FormatLocaleString(path,MagickPathExtent,"Q%g,%g %g,%g",affine.tx+
1303  control->x/64.0,affine.ty-control->y/64.0,affine.tx+to->x/64.0,affine.ty-
1304  to->y/64.0);
1305  (void) ConcatenateString(&draw_info->primitive,path);
1306  return(0);
1307 }
1308 
1309 static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
1310  const char *encoding,const PointInfo *offset,TypeMetric *metrics,
1311  ExceptionInfo *exception)
1312 {
1313 #if !defined(FT_OPEN_PATHNAME)
1314 #define FT_OPEN_PATHNAME ft_open_pathname
1315 #endif
1316 
1317  typedef struct _GlyphInfo
1318  {
1319  FT_UInt
1320  id;
1321 
1322  FT_Vector
1323  origin;
1324 
1325  FT_Glyph
1326  image;
1327  } GlyphInfo;
1328 
1329  const char
1330  *value;
1331 
1332  DrawInfo
1333  *annotate_info;
1334 
1335  FT_BBox
1336  bounds;
1337 
1338  FT_BitmapGlyph
1339  bitmap;
1340 
1341  FT_Encoding
1342  encoding_type;
1343 
1344  FT_Error
1345  ft_status;
1346 
1347  FT_Face
1348  face;
1349 
1350  FT_Int32
1351  flags;
1352 
1353  FT_Library
1354  library;
1355 
1356  FT_Matrix
1357  affine;
1358 
1359  FT_Open_Args
1360  args;
1361 
1362  FT_UInt
1363  first_glyph_id,
1364  last_glyph_id,
1365  missing_glyph_id;
1366 
1367  FT_Vector
1368  origin;
1369 
1370  GlyphInfo
1371  glyph;
1372 
1373  GraphemeInfo
1374  *grapheme;
1375 
1377  status;
1378 
1379  PointInfo
1380  point,
1381  resolution;
1382 
1383  char
1384  *p;
1385 
1386  ssize_t
1387  i;
1388 
1389  size_t
1390  length;
1391 
1392  ssize_t
1393  code,
1394  last_character,
1395  y;
1396 
1397  static FT_Outline_Funcs
1398  OutlineMethods =
1399  {
1400  (FT_Outline_MoveTo_Func) TraceMoveTo,
1401  (FT_Outline_LineTo_Func) TraceLineTo,
1402  (FT_Outline_ConicTo_Func) TraceQuadraticBezier,
1403  (FT_Outline_CubicTo_Func) TraceCubicBezier,
1404  0, 0
1405  };
1406 
1407  unsigned char
1408  *utf8;
1409 
1410  /*
1411  Initialize Truetype library.
1412  */
1413  ft_status=FT_Init_FreeType(&library);
1414  if (ft_status != 0)
1415  ThrowBinaryException(TypeError,"UnableToInitializeFreetypeLibrary",
1416  image->filename);
1417  args.flags=FT_OPEN_PATHNAME;
1418  if (draw_info->font == (char *) NULL)
1419  args.pathname=ConstantString("helvetica");
1420  else
1421  if (*draw_info->font != '@')
1422  args.pathname=ConstantString(draw_info->font);
1423  else
1424  args.pathname=ConstantString(draw_info->font+1);
1425  face=(FT_Face) NULL;
1426  ft_status=FT_Open_Face(library,&args,(long) draw_info->face,&face);
1427  if (ft_status != 0)
1428  {
1429  (void) FT_Done_FreeType(library);
1430  (void) ThrowMagickException(exception,GetMagickModule(),TypeError,
1431  "UnableToReadFont","`%s'",args.pathname);
1432  args.pathname=DestroyString(args.pathname);
1433  return(MagickFalse);
1434  }
1435  args.pathname=DestroyString(args.pathname);
1436  if ((draw_info->metrics != (char *) NULL) &&
1437  (IsPathAccessible(draw_info->metrics) != MagickFalse))
1438  (void) FT_Attach_File(face,draw_info->metrics);
1439  encoding_type=FT_ENCODING_UNICODE;
1440  ft_status=FT_Select_Charmap(face,encoding_type);
1441  if ((ft_status != 0) && (face->num_charmaps != 0))
1442  ft_status=FT_Set_Charmap(face,face->charmaps[0]);
1443  if (encoding != (const char *) NULL)
1444  {
1445  if (LocaleCompare(encoding,"AdobeCustom") == 0)
1446  encoding_type=FT_ENCODING_ADOBE_CUSTOM;
1447  if (LocaleCompare(encoding,"AdobeExpert") == 0)
1448  encoding_type=FT_ENCODING_ADOBE_EXPERT;
1449  if (LocaleCompare(encoding,"AdobeStandard") == 0)
1450  encoding_type=FT_ENCODING_ADOBE_STANDARD;
1451  if (LocaleCompare(encoding,"AppleRoman") == 0)
1452  encoding_type=FT_ENCODING_APPLE_ROMAN;
1453  if (LocaleCompare(encoding,"BIG5") == 0)
1454  encoding_type=FT_ENCODING_BIG5;
1455 #if defined(FT_ENCODING_PRC)
1456  if (LocaleCompare(encoding,"GB2312") == 0)
1457  encoding_type=FT_ENCODING_PRC;
1458 #endif
1459 #if defined(FT_ENCODING_JOHAB)
1460  if (LocaleCompare(encoding,"Johab") == 0)
1461  encoding_type=FT_ENCODING_JOHAB;
1462 #endif
1463 #if defined(FT_ENCODING_ADOBE_LATIN_1)
1464  if (LocaleCompare(encoding,"Latin-1") == 0)
1465  encoding_type=FT_ENCODING_ADOBE_LATIN_1;
1466 #endif
1467 #if defined(FT_ENCODING_ADOBE_LATIN_2)
1468  if (LocaleCompare(encoding,"Latin-2") == 0)
1469  encoding_type=FT_ENCODING_OLD_LATIN_2;
1470 #endif
1471  if (LocaleCompare(encoding,"None") == 0)
1472  encoding_type=FT_ENCODING_NONE;
1473  if (LocaleCompare(encoding,"SJIScode") == 0)
1474  encoding_type=FT_ENCODING_SJIS;
1475  if (LocaleCompare(encoding,"Symbol") == 0)
1476  encoding_type=FT_ENCODING_MS_SYMBOL;
1477  if (LocaleCompare(encoding,"Unicode") == 0)
1478  encoding_type=FT_ENCODING_UNICODE;
1479  if (LocaleCompare(encoding,"Wansung") == 0)
1480  encoding_type=FT_ENCODING_WANSUNG;
1481  ft_status=FT_Select_Charmap(face,encoding_type);
1482  if (ft_status != 0)
1483  {
1484  (void) FT_Done_Face(face);
1485  (void) FT_Done_FreeType(library);
1486  ThrowBinaryException(TypeError,"UnrecognizedFontEncoding",encoding);
1487  }
1488  }
1489  /*
1490  Set text size.
1491  */
1492  resolution.x=DefaultResolution;
1493  resolution.y=DefaultResolution;
1494  if (draw_info->density != (char *) NULL)
1495  {
1496  GeometryInfo
1497  geometry_info;
1498 
1500  geometry_flags;
1501 
1502  geometry_flags=ParseGeometry(draw_info->density,&geometry_info);
1503  resolution.x=geometry_info.rho;
1504  resolution.y=geometry_info.sigma;
1505  if ((geometry_flags & SigmaValue) == 0)
1506  resolution.y=resolution.x;
1507  }
1508  ft_status=FT_Set_Char_Size(face,(FT_F26Dot6) (64.0*draw_info->pointsize),
1509  (FT_F26Dot6) (64.0*draw_info->pointsize),(FT_UInt) resolution.x,
1510  (FT_UInt) resolution.y);
1511  if (ft_status != 0)
1512  {
1513  (void) FT_Done_Face(face);
1514  (void) FT_Done_FreeType(library);
1515  ThrowBinaryException(TypeError,"UnableToReadFont",draw_info->font);
1516  }
1517  metrics->pixels_per_em.x=face->size->metrics.x_ppem;
1518  metrics->pixels_per_em.y=face->size->metrics.y_ppem;
1519  metrics->ascent=(double) face->size->metrics.ascender/64.0;
1520  metrics->descent=(double) face->size->metrics.descender/64.0;
1521  if (face->size->metrics.ascender == 0)
1522  {
1523  /*
1524  Sanitize buggy ascender and descender values.
1525  */
1526  metrics->ascent=face->size->metrics.y_ppem;
1527  if (face->size->metrics.descender == 0)
1528  metrics->descent=face->size->metrics.y_ppem/-3.5;
1529  }
1530  metrics->width=0;
1531  metrics->origin.x=0;
1532  metrics->origin.y=0;
1533  metrics->height=(double) face->size->metrics.height/64.0;
1534  metrics->max_advance=0.0;
1535  if (face->size->metrics.max_advance > MagickEpsilon)
1536  metrics->max_advance=(double) face->size->metrics.max_advance/64.0;
1537  metrics->bounds.x1=0.0;
1538  metrics->bounds.y1=metrics->descent;
1539  metrics->bounds.x2=metrics->ascent+metrics->descent;
1540  metrics->bounds.y2=metrics->ascent+metrics->descent;
1541  metrics->underline_position=face->underline_position*
1542  (metrics->pixels_per_em.x*PerceptibleReciprocal(face->units_per_EM));
1543  metrics->underline_thickness=face->underline_thickness*
1544  (metrics->pixels_per_em.x*PerceptibleReciprocal(face->units_per_EM));
1545  first_glyph_id=0;
1546  FT_Get_First_Char(face,&first_glyph_id);
1547  if ((draw_info->text == (char *) NULL) || (*draw_info->text == '\0') ||
1548  (first_glyph_id == 0))
1549  {
1550  (void) FT_Done_Face(face);
1551  (void) FT_Done_FreeType(library);
1552  return(MagickTrue);
1553  }
1554  /*
1555  Compute bounding box.
1556  */
1557  if (image->debug != MagickFalse)
1558  (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),"Font %s; "
1559  "font-encoding %s; text-encoding %s; pointsize %g",
1560  draw_info->font != (char *) NULL ? draw_info->font : "none",
1561  encoding != (char *) NULL ? encoding : "none",
1562  draw_info->encoding != (char *) NULL ? draw_info->encoding : "none",
1563  draw_info->pointsize);
1564  flags=FT_LOAD_DEFAULT;
1565  if (draw_info->render == MagickFalse)
1566  flags=FT_LOAD_NO_BITMAP;
1567  if (draw_info->text_antialias == MagickFalse)
1568  flags|=FT_LOAD_RENDER | FT_LOAD_TARGET_MONO;
1569  else
1570  {
1571 #if defined(FT_LOAD_TARGET_LIGHT)
1572  flags|=FT_LOAD_TARGET_LIGHT;
1573 #elif defined(FT_LOAD_TARGET_LCD)
1574  flags|=FT_LOAD_TARGET_LCD;
1575 #endif
1576  }
1577  value=GetImageProperty(image,"type:hinting",exception);
1578  if ((value != (const char *) NULL) && (LocaleCompare(value,"off") == 0))
1579  flags|=FT_LOAD_NO_HINTING;
1580  glyph.id=0;
1581  glyph.image=(FT_Glyph) NULL;
1582  last_glyph_id=0;
1583  origin.x=0;
1584  origin.y=0;
1585  affine.xx=65536L;
1586  affine.yx=0L;
1587  affine.xy=0L;
1588  affine.yy=65536L;
1589  if (draw_info->render != MagickFalse)
1590  {
1591  affine.xx=(FT_Fixed) (65536L*draw_info->affine.sx+0.5);
1592  affine.yx=(FT_Fixed) (-65536L*draw_info->affine.rx+0.5);
1593  affine.xy=(FT_Fixed) (-65536L*draw_info->affine.ry+0.5);
1594  affine.yy=(FT_Fixed) (65536L*draw_info->affine.sy+0.5);
1595  }
1596  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1597  if (annotate_info->dash_pattern != (double *) NULL)
1598  annotate_info->dash_pattern[0]=0.0;
1599  (void) CloneString(&annotate_info->primitive,"path '");
1600  status=MagickTrue;
1601  if (draw_info->render != MagickFalse)
1602  {
1603  if (image->storage_class != DirectClass)
1604  (void) SetImageStorageClass(image,DirectClass,exception);
1605  if (image->alpha_trait == UndefinedPixelTrait)
1606  (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
1607  }
1608  for (p=draw_info->text; GetUTFCode(p) != 0; p+=GetUTFOctets(p))
1609  if (GetUTFCode(p) < 0)
1610  break;
1611  utf8=(unsigned char *) NULL;
1612  if (GetUTFCode(p) == 0)
1613  p=draw_info->text;
1614  else
1615  {
1616  utf8=ConvertLatin1ToUTF8((unsigned char *) draw_info->text);
1617  if (utf8 != (unsigned char *) NULL)
1618  p=(char *) utf8;
1619  }
1620  grapheme=(GraphemeInfo *) NULL;
1621  length=ComplexTextLayout(image,draw_info,p,strlen(p),face,flags,&grapheme,
1622  exception);
1623  missing_glyph_id=FT_Get_Char_Index(face,' ');
1624  code=0;
1625  last_character=(ssize_t) length-1;
1626  for (i=0; i < (ssize_t) length; i++)
1627  {
1628  FT_Outline
1629  outline;
1630 
1631  /*
1632  Render UTF-8 sequence.
1633  */
1634  glyph.id=(FT_UInt) grapheme[i].index;
1635  if (glyph.id == 0)
1636  glyph.id=missing_glyph_id;
1637  if ((glyph.id != 0) && (last_glyph_id != 0))
1638  origin.x+=(FT_Pos) (64.0*draw_info->kerning);
1639  glyph.origin=origin;
1640  glyph.origin.x+=(FT_Pos) grapheme[i].x_offset;
1641  glyph.origin.y+=(FT_Pos) grapheme[i].y_offset;
1642  if (glyph.image != (FT_Glyph) NULL)
1643  {
1644  FT_Done_Glyph(glyph.image);
1645  glyph.image=(FT_Glyph) NULL;
1646  }
1647  ft_status=FT_Load_Glyph(face,glyph.id,flags);
1648  if (ft_status != 0)
1649  continue;
1650  ft_status=FT_Get_Glyph(face->glyph,&glyph.image);
1651  if (ft_status != 0)
1652  continue;
1653  outline=((FT_OutlineGlyph) glyph.image)->outline;
1654  if ((glyph.image->format != FT_GLYPH_FORMAT_OUTLINE) &&
1655  (IsEmptyOutline(outline) == MagickFalse))
1656  continue;
1657  ft_status=FT_Outline_Get_BBox(&outline,&bounds);
1658  if (ft_status != 0)
1659  continue;
1660  if ((p == draw_info->text) || (bounds.xMin < metrics->bounds.x1))
1661  if (bounds.xMin != 0)
1662  metrics->bounds.x1=(double) bounds.xMin;
1663  if ((p == draw_info->text) || (bounds.yMin < metrics->bounds.y1))
1664  if (bounds.yMin != 0)
1665  metrics->bounds.y1=(double) bounds.yMin;
1666  if ((p == draw_info->text) || (bounds.xMax > metrics->bounds.x2))
1667  if (bounds.xMax != 0)
1668  metrics->bounds.x2=(double) bounds.xMax;
1669  if ((p == draw_info->text) || (bounds.yMax > metrics->bounds.y2))
1670  if (bounds.yMax != 0)
1671  metrics->bounds.y2=(double) bounds.yMax;
1672  if (((draw_info->stroke.alpha != TransparentAlpha) ||
1673  (draw_info->stroke_pattern != (Image *) NULL)) &&
1674  ((status != MagickFalse) && (draw_info->render != MagickFalse)))
1675  {
1676  /*
1677  Trace the glyph.
1678  */
1679  annotate_info->affine.tx=glyph.origin.x/64.0;
1680  annotate_info->affine.ty=(-glyph.origin.y/64.0);
1681  if (IsEmptyOutline(outline) == MagickFalse)
1682  ft_status=FT_Outline_Decompose(&outline,&OutlineMethods,
1683  annotate_info);
1684  }
1685  FT_Vector_Transform(&glyph.origin,&affine);
1686  (void) FT_Glyph_Transform(glyph.image,&affine,&glyph.origin);
1687  ft_status=FT_Glyph_To_Bitmap(&glyph.image,FT_RENDER_MODE_NORMAL,
1688  (FT_Vector *) NULL,MagickTrue);
1689  if (ft_status != 0)
1690  continue;
1691  bitmap=(FT_BitmapGlyph) glyph.image;
1692  point.x=offset->x+bitmap->left;
1693  if (bitmap->bitmap.pixel_mode == ft_pixel_mode_mono)
1694  point.x+=(origin.x/64.0);
1695  point.y=offset->y-bitmap->top;
1696  if (draw_info->render != MagickFalse)
1697  {
1698  CacheView
1699  *image_view;
1700 
1702  transparent_fill;
1703 
1704  unsigned char
1705  *r;
1706 
1707  /*
1708  Rasterize the glyph.
1709  */
1710  transparent_fill=((draw_info->fill.alpha == TransparentAlpha) &&
1711  (draw_info->fill_pattern == (Image *) NULL) &&
1712  (draw_info->stroke.alpha == TransparentAlpha) &&
1713  (draw_info->stroke_pattern == (Image *) NULL)) ? MagickTrue :
1714  MagickFalse;
1715  image_view=AcquireAuthenticCacheView(image,exception);
1716  r=bitmap->bitmap.buffer;
1717  for (y=0; y < (ssize_t) bitmap->bitmap.rows; y++)
1718  {
1719  double
1720  fill_opacity;
1721 
1723  active,
1724  sync;
1725 
1726  PixelInfo
1727  fill_color;
1728 
1729  Quantum
1730  *magick_restrict q;
1731 
1732  ssize_t
1733  x;
1734 
1735  ssize_t
1736  n,
1737  x_offset,
1738  y_offset;
1739 
1740  if (status == MagickFalse)
1741  continue;
1742  x_offset=CastDoubleToLong(ceil(point.x-0.5));
1743  y_offset=CastDoubleToLong(ceil(point.y+y-0.5));
1744  if ((y_offset < 0) || (y_offset >= (ssize_t) image->rows))
1745  continue;
1746  q=(Quantum *) NULL;
1747  if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns))
1748  active=MagickFalse;
1749  else
1750  {
1751  q=GetCacheViewAuthenticPixels(image_view,x_offset,y_offset,
1752  bitmap->bitmap.width,1,exception);
1753  active=q != (Quantum *) NULL ? MagickTrue : MagickFalse;
1754  }
1755  n=y*bitmap->bitmap.pitch;
1756  for (x=0; x < (ssize_t) bitmap->bitmap.width; x++, n++)
1757  {
1758  x_offset=CastDoubleToLong(ceil(point.x+x-0.5));
1759  if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns))
1760  {
1761  if (q != (Quantum *) NULL)
1762  q+=GetPixelChannels(image);
1763  continue;
1764  }
1765  fill_opacity=1.0;
1766  if (bitmap->bitmap.buffer != (unsigned char *) NULL)
1767  {
1768  if (bitmap->bitmap.pixel_mode == ft_pixel_mode_grays)
1769  fill_opacity=(double) (r[n])/(bitmap->bitmap.num_grays-1);
1770  else
1771  if (bitmap->bitmap.pixel_mode == ft_pixel_mode_mono)
1772  fill_opacity=((r[(x >> 3)+y*bitmap->bitmap.pitch] &
1773  (1 << (~x & 0x07)))) == 0 ? 0.0 : 1.0;
1774  }
1775  if (draw_info->text_antialias == MagickFalse)
1776  fill_opacity=fill_opacity >= 0.5 ? 1.0 : 0.0;
1777  if (active == MagickFalse)
1778  q=GetCacheViewAuthenticPixels(image_view,x_offset,y_offset,1,1,
1779  exception);
1780  if (q == (Quantum *) NULL)
1781  continue;
1782  if (transparent_fill == MagickFalse)
1783  {
1784  GetPixelInfo(image,&fill_color);
1785  GetFillColor(draw_info,x_offset,y_offset,&fill_color,exception);
1786  fill_opacity=fill_opacity*fill_color.alpha;
1787  CompositePixelOver(image,&fill_color,fill_opacity,q,
1788  GetPixelAlpha(image,q),q);
1789  }
1790  else
1791  {
1792  double
1793  Sa,
1794  Da;
1795 
1796  Da=1.0-(QuantumScale*GetPixelAlpha(image,q));
1797  Sa=fill_opacity;
1798  fill_opacity=(1.0-RoundToUnity(Sa+Da-Sa*Da))*QuantumRange;
1799  SetPixelAlpha(image,fill_opacity,q);
1800  }
1801  if (active == MagickFalse)
1802  {
1803  sync=SyncCacheViewAuthenticPixels(image_view,exception);
1804  if (sync == MagickFalse)
1805  status=MagickFalse;
1806  }
1807  q+=GetPixelChannels(image);
1808  }
1809  sync=SyncCacheViewAuthenticPixels(image_view,exception);
1810  if (sync == MagickFalse)
1811  status=MagickFalse;
1812  }
1813  image_view=DestroyCacheView(image_view);
1814  if (((draw_info->stroke.alpha != TransparentAlpha) ||
1815  (draw_info->stroke_pattern != (Image *) NULL)) &&
1816  (status != MagickFalse))
1817  {
1818  /*
1819  Draw text stroke.
1820  */
1821  annotate_info->linejoin=RoundJoin;
1822  annotate_info->affine.tx=offset->x;
1823  annotate_info->affine.ty=offset->y;
1824  (void) ConcatenateString(&annotate_info->primitive,"'");
1825  if (strlen(annotate_info->primitive) > 7)
1826  (void) DrawImage(image,annotate_info,exception);
1827  (void) CloneString(&annotate_info->primitive,"path '");
1828  }
1829  }
1830  if ((fabs(draw_info->interword_spacing) >= MagickEpsilon) &&
1831  (IsUTFSpace(GetUTFCode(p+grapheme[i].cluster)) != MagickFalse) &&
1832  (IsUTFSpace(code) == MagickFalse))
1833  origin.x+=(FT_Pos) (64.0*draw_info->interword_spacing);
1834  else
1835  if (i == last_character)
1836  origin.x+=MagickMax((FT_Pos) grapheme[i].x_advance,bounds.xMax);
1837  else
1838  origin.x+=(FT_Pos) grapheme[i].x_advance;
1839  metrics->origin.x=(double) origin.x;
1840  metrics->origin.y=(double) origin.y;
1841  if (metrics->origin.x > metrics->width)
1842  metrics->width=metrics->origin.x;
1843  last_glyph_id=glyph.id;
1844  code=GetUTFCode(p+grapheme[i].cluster);
1845  }
1846  if (grapheme != (GraphemeInfo *) NULL)
1847  grapheme=(GraphemeInfo *) RelinquishMagickMemory(grapheme);
1848  if (utf8 != (unsigned char *) NULL)
1849  utf8=(unsigned char *) RelinquishMagickMemory(utf8);
1850  if (glyph.image != (FT_Glyph) NULL)
1851  {
1852  FT_Done_Glyph(glyph.image);
1853  glyph.image=(FT_Glyph) NULL;
1854  }
1855  /*
1856  Determine font metrics.
1857  */
1858  metrics->bounds.x1/=64.0;
1859  metrics->bounds.y1/=64.0;
1860  metrics->bounds.x2/=64.0;
1861  metrics->bounds.y2/=64.0;
1862  metrics->origin.x/=64.0;
1863  metrics->origin.y/=64.0;
1864  metrics->width=ceil(metrics->width/64.0);
1865  /*
1866  Relinquish resources.
1867  */
1868  annotate_info=DestroyDrawInfo(annotate_info);
1869  (void) FT_Done_Face(face);
1870  (void) FT_Done_FreeType(library);
1871  return(status);
1872 }
1873 #else
1874 static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
1875  const char *magick_unused(encoding),const PointInfo *offset,
1876  TypeMetric *metrics,ExceptionInfo *exception)
1877 {
1878  (void) ThrowMagickException(exception,GetMagickModule(),
1879  MissingDelegateWarning,"DelegateLibrarySupportNotBuiltIn","'%s' (Freetype)",
1880  draw_info->font != (char *) NULL ? draw_info->font : "none");
1881  return(RenderPostscript(image,draw_info,offset,metrics,exception));
1882 }
1883 #endif
1884 
1885 /*
1886 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1887 % %
1888 % %
1889 % %
1890 + R e n d e r P o s t s c r i p t %
1891 % %
1892 % %
1893 % %
1894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1895 %
1896 % RenderPostscript() renders text on the image with a Postscript font. It
1897 % also returns the bounding box of the text relative to the image.
1898 %
1899 % The format of the RenderPostscript method is:
1900 %
1901 % MagickBooleanType RenderPostscript(Image *image,DrawInfo *draw_info,
1902 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
1903 %
1904 % A description of each parameter follows:
1905 %
1906 % o image: the image.
1907 %
1908 % o draw_info: the draw info.
1909 %
1910 % o offset: (x,y) location of text relative to image.
1911 %
1912 % o metrics: bounding box of text.
1913 %
1914 % o exception: return any errors or warnings in this structure.
1915 %
1916 */
1917 
1918 static char *EscapeParenthesis(const char *source)
1919 {
1920  char
1921  *destination;
1922 
1923  char
1924  *q;
1925 
1926  const char
1927  *p;
1928 
1929  size_t
1930  length;
1931 
1932  assert(source != (const char *) NULL);
1933  length=0;
1934  for (p=source; *p != '\0'; p++)
1935  {
1936  if ((*p == '\\') || (*p == '(') || (*p == ')'))
1937  {
1938  if (~length < 1)
1939  ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
1940  length++;
1941  }
1942  length++;
1943  }
1944  destination=(char *) NULL;
1945  if (~length >= (MagickPathExtent-1))
1946  destination=(char *) AcquireQuantumMemory(length+MagickPathExtent,
1947  sizeof(*destination));
1948  if (destination == (char *) NULL)
1949  ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
1950  *destination='\0';
1951  q=destination;
1952  for (p=source; *p != '\0'; p++)
1953  {
1954  if ((*p == '\\') || (*p == '(') || (*p == ')'))
1955  *q++='\\';
1956  *q++=(*p);
1957  }
1958  *q='\0';
1959  return(destination);
1960 }
1961 
1963  const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
1964  ExceptionInfo *exception)
1965 {
1966  char
1967  filename[MagickPathExtent],
1968  geometry[MagickPathExtent],
1969  *text;
1970 
1971  FILE
1972  *file;
1973 
1974  Image
1975  *annotate_image;
1976 
1977  ImageInfo
1978  *annotate_info;
1979 
1980  int
1981  unique_file;
1982 
1984  identity;
1985 
1986  PointInfo
1987  extent,
1988  point,
1989  resolution;
1990 
1991  ssize_t
1992  i;
1993 
1994  size_t
1995  length;
1996 
1997  ssize_t
1998  y;
1999 
2000  /*
2001  Render label with a Postscript font.
2002  */
2003  if (image->debug != MagickFalse)
2005  "Font %s; pointsize %g",draw_info->font != (char *) NULL ?
2006  draw_info->font : "none",draw_info->pointsize);
2007  file=(FILE *) NULL;
2008  unique_file=AcquireUniqueFileResource(filename);
2009  if (unique_file != -1)
2010  file=fdopen(unique_file,"wb");
2011  if ((unique_file == -1) || (file == (FILE *) NULL))
2012  {
2013  ThrowFileException(exception,FileOpenError,"UnableToOpenFile",filename);
2014  return(MagickFalse);
2015  }
2016  (void) FormatLocaleFile(file,"%%!PS-Adobe-3.0\n");
2017  (void) FormatLocaleFile(file,"/ReencodeType\n");
2018  (void) FormatLocaleFile(file,"{\n");
2019  (void) FormatLocaleFile(file," findfont dup length\n");
2020  (void) FormatLocaleFile(file,
2021  " dict begin { 1 index /FID ne {def} {pop pop} ifelse } forall\n");
2022  (void) FormatLocaleFile(file,
2023  " /Encoding ISOLatin1Encoding def currentdict end definefont pop\n");
2024  (void) FormatLocaleFile(file,"} bind def\n");
2025  /*
2026  Sample to compute bounding box.
2027  */
2028  identity=(fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) &&
2029  (fabs(draw_info->affine.rx) < MagickEpsilon) &&
2030  (fabs(draw_info->affine.ry) < MagickEpsilon) ? MagickTrue : MagickFalse;
2031  extent.x=0.0;
2032  extent.y=0.0;
2033  length=strlen(draw_info->text);
2034  for (i=0; i <= (ssize_t) (length+2); i++)
2035  {
2036  point.x=fabs(draw_info->affine.sx*i*draw_info->pointsize+
2037  draw_info->affine.ry*2.0*draw_info->pointsize);
2038  point.y=fabs(draw_info->affine.rx*i*draw_info->pointsize+
2039  draw_info->affine.sy*2.0*draw_info->pointsize);
2040  if (point.x > extent.x)
2041  extent.x=point.x;
2042  if (point.y > extent.y)
2043  extent.y=point.y;
2044  }
2045  (void) FormatLocaleFile(file,"%g %g moveto\n",identity != MagickFalse ? 0.0 :
2046  extent.x/2.0,extent.y/2.0);
2047  (void) FormatLocaleFile(file,"%g %g scale\n",draw_info->pointsize,
2048  draw_info->pointsize);
2049  if ((draw_info->font == (char *) NULL) || (*draw_info->font == '\0') ||
2050  (strchr(draw_info->font,'/') != (char *) NULL))
2051  (void) FormatLocaleFile(file,
2052  "/Times-Roman-ISO dup /Times-Roman ReencodeType findfont setfont\n");
2053  else
2054  (void) FormatLocaleFile(file,
2055  "/%s-ISO dup /%s ReencodeType findfont setfont\n",draw_info->font,
2056  draw_info->font);
2057  (void) FormatLocaleFile(file,"[%g %g %g %g 0 0] concat\n",
2058  draw_info->affine.sx,-draw_info->affine.rx,-draw_info->affine.ry,
2059  draw_info->affine.sy);
2060  text=EscapeParenthesis(draw_info->text);
2061  if (identity == MagickFalse)
2062  (void) FormatLocaleFile(file,"(%s) stringwidth pop -0.5 mul -0.5 rmoveto\n",
2063  text);
2064  (void) FormatLocaleFile(file,"(%s) show\n",text);
2065  text=DestroyString(text);
2066  (void) FormatLocaleFile(file,"showpage\n");
2067  (void) fclose(file);
2068  (void) FormatLocaleString(geometry,MagickPathExtent,"%.20gx%.20g+0+0!",
2069  floor(extent.x+0.5),floor(extent.y+0.5));
2070  annotate_info=AcquireImageInfo();
2071  (void) FormatLocaleString(annotate_info->filename,MagickPathExtent,"ps:%s",
2072  filename);
2073  (void) CloneString(&annotate_info->page,geometry);
2074  if (draw_info->density != (char *) NULL)
2075  (void) CloneString(&annotate_info->density,draw_info->density);
2076  annotate_info->antialias=draw_info->text_antialias;
2077  annotate_image=ReadImage(annotate_info,exception);
2078  CatchException(exception);
2079  annotate_info=DestroyImageInfo(annotate_info);
2080  (void) RelinquishUniqueFileResource(filename);
2081  if (annotate_image == (Image *) NULL)
2082  return(MagickFalse);
2083  (void) NegateImage(annotate_image,MagickFalse,exception);
2084  resolution.x=DefaultResolution;
2085  resolution.y=DefaultResolution;
2086  if (draw_info->density != (char *) NULL)
2087  {
2088  GeometryInfo
2089  geometry_info;
2090 
2092  flags;
2093 
2094  flags=ParseGeometry(draw_info->density,&geometry_info);
2095  resolution.x=geometry_info.rho;
2096  resolution.y=geometry_info.sigma;
2097  if ((flags & SigmaValue) == 0)
2098  resolution.y=resolution.x;
2099  }
2100  if (identity == MagickFalse)
2101  (void) TransformImage(&annotate_image,"0x0",(char *) NULL,exception);
2102  else
2103  {
2105  crop_info;
2106 
2107  crop_info=GetImageBoundingBox(annotate_image,exception);
2108  crop_info.height=(size_t) ((resolution.y/DefaultResolution)*
2109  ExpandAffine(&draw_info->affine)*draw_info->pointsize+0.5);
2110  crop_info.y=CastDoubleToLong(ceil((resolution.y/DefaultResolution)*
2111  extent.y/8.0-0.5));
2112  (void) FormatLocaleString(geometry,MagickPathExtent,
2113  "%.20gx%.20g%+.20g%+.20g",(double) crop_info.width,(double)
2114  crop_info.height,(double) crop_info.x,(double) crop_info.y);
2115  (void) TransformImage(&annotate_image,geometry,(char *) NULL,exception);
2116  }
2117  metrics->pixels_per_em.x=(resolution.y/DefaultResolution)*
2118  ExpandAffine(&draw_info->affine)*draw_info->pointsize;
2119  metrics->pixels_per_em.y=metrics->pixels_per_em.x;
2120  metrics->ascent=metrics->pixels_per_em.y;
2121  metrics->descent=metrics->pixels_per_em.y/-5.0;
2122  metrics->width=(double) annotate_image->columns/
2123  ExpandAffine(&draw_info->affine);
2124  metrics->height=floor(metrics->ascent-metrics->descent+0.5);
2125  metrics->max_advance=metrics->pixels_per_em.x;
2126  metrics->bounds.x1=0.0;
2127  metrics->bounds.y1=metrics->descent;
2128  metrics->bounds.x2=metrics->ascent+metrics->descent;
2129  metrics->bounds.y2=metrics->ascent+metrics->descent;
2130  metrics->underline_position=(-2.0);
2131  metrics->underline_thickness=1.0;
2132  if (draw_info->render == MagickFalse)
2133  {
2134  annotate_image=DestroyImage(annotate_image);
2135  return(MagickTrue);
2136  }
2137  if (draw_info->fill.alpha != TransparentAlpha)
2138  {
2139  CacheView
2140  *annotate_view;
2141 
2143  sync;
2144 
2145  PixelInfo
2146  fill_color;
2147 
2148  /*
2149  Render fill color.
2150  */
2151  if (image->alpha_trait == UndefinedPixelTrait)
2152  (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
2153  if (annotate_image->alpha_trait == UndefinedPixelTrait)
2154  (void) SetImageAlphaChannel(annotate_image,OpaqueAlphaChannel,
2155  exception);
2156  fill_color=draw_info->fill;
2157  annotate_view=AcquireAuthenticCacheView(annotate_image,exception);
2158  for (y=0; y < (ssize_t) annotate_image->rows; y++)
2159  {
2160  ssize_t
2161  x;
2162 
2163  Quantum
2164  *magick_restrict q;
2165 
2166  q=GetCacheViewAuthenticPixels(annotate_view,0,y,annotate_image->columns,
2167  1,exception);
2168  if (q == (Quantum *) NULL)
2169  break;
2170  for (x=0; x < (ssize_t) annotate_image->columns; x++)
2171  {
2172  GetFillColor(draw_info,x,y,&fill_color,exception);
2173  SetPixelAlpha(annotate_image,ClampToQuantum((((double) QuantumScale*
2174  GetPixelIntensity(annotate_image,q)*fill_color.alpha))),q);
2175  SetPixelRed(annotate_image,fill_color.red,q);
2176  SetPixelGreen(annotate_image,fill_color.green,q);
2177  SetPixelBlue(annotate_image,fill_color.blue,q);
2178  q+=GetPixelChannels(annotate_image);
2179  }
2180  sync=SyncCacheViewAuthenticPixels(annotate_view,exception);
2181  if (sync == MagickFalse)
2182  break;
2183  }
2184  annotate_view=DestroyCacheView(annotate_view);
2185  (void) CompositeImage(image,annotate_image,OverCompositeOp,MagickTrue,
2186  (ssize_t) ceil(offset->x-0.5),(ssize_t) ceil(offset->y-(metrics->ascent+
2187  metrics->descent)-0.5),exception);
2188  }
2189  annotate_image=DestroyImage(annotate_image);
2190  return(MagickTrue);
2191 }
2192 
2193 /*
2194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2195 % %
2196 % %
2197 % %
2198 + R e n d e r X 1 1 %
2199 % %
2200 % %
2201 % %
2202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2203 %
2204 % RenderX11() renders text on the image with an X11 font. It also returns the
2205 % bounding box of the text relative to the image.
2206 %
2207 % The format of the RenderX11 method is:
2208 %
2209 % MagickBooleanType RenderX11(Image *image,DrawInfo *draw_info,
2210 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
2211 %
2212 % A description of each parameter follows:
2213 %
2214 % o image: the image.
2215 %
2216 % o draw_info: the draw info.
2217 %
2218 % o offset: (x,y) location of text relative to image.
2219 %
2220 % o metrics: bounding box of text.
2221 %
2222 % o exception: return any errors or warnings in this structure.
2223 %
2224 */
2225 static MagickBooleanType RenderX11(Image *image,const DrawInfo *draw_info,
2226  const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
2227 {
2229  status;
2230 
2231  if (annotate_semaphore == (SemaphoreInfo *) NULL)
2234  status=XRenderImage(image,draw_info,offset,metrics,exception);
2236  return(status);
2237 }
double psi
Definition: geometry.h:107
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:3924
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:96
MagickExport MagickBooleanType QueryColorname(const Image *magick_unused(image), const PixelInfo *color, const ComplianceType compliance, char *name, ExceptionInfo *exception)
Definition: color.c:2659
MagickExport ImageInfo * AcquireImageInfo(void)
Definition: image.c:327
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:272
double interline_spacing
Definition: draw.h:312
static int GetUTFCode(const char *magick_restrict text)
#define ThrowFatalException(severity, tag)
PixelInfo stroke
Definition: draw.h:214
double ty
Definition: geometry.h:96
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:107
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:1730
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
static MagickBooleanType IsUTFSpace(int code)
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:463
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:1962
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:107
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:131
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:2170
Definition: image.h:151
double tx
Definition: geometry.h:96
double x
Definition: geometry.h:124
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:937
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:591
Image * stroke_pattern
Definition: draw.h:220
MagickExport ssize_t FormatLocaleFile(FILE *file, const char *magick_restrict format,...)
Definition: locale.c:368
MagickExport MagickBooleanType SetImageAlphaChannel(Image *image, const AlphaChannelOption alpha_type, ExceptionInfo *exception)
Definition: channel.c:974
MagickBooleanType
Definition: magick-type.h:165
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:1588
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
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:124
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:9976
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:96
char * glyphs
Definition: type.h:71
MagickExport MagickBooleanType DrawImage(Image *image, const DrawInfo *draw_info, ExceptionInfo *exception)
Definition: draw.c:4470
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:2225
double sx
Definition: geometry.h:96
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:1660
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:318
ssize_t x
Definition: geometry.h:135
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:131
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:2614
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:1399
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:96
double underline_thickness
Definition: draw.h:372
MagickExport MagickBooleanType GetMultilineTypeMetrics(Image *image, const DrawInfo *draw_info, TypeMetric *metrics, ExceptionInfo *exception)
Definition: annotate.c:724
char * density
Definition: image.h:413
SegmentInfo bounds
Definition: draw.h:381
MagickExport ImageInfo * DestroyImageInfo(ImageInfo *image_info)
Definition: image.c:1248
size_t signature
Definition: draw.h:323
MagickExport MagickBooleanType GetTypeMetrics(Image *image, const DrawInfo *draw_info, TypeMetric *metrics, ExceptionInfo *exception)
Definition: annotate.c:865
char * geometry
Definition: draw.h:204
unsigned short Quantum
Definition: magick-type.h:86
double xi
Definition: geometry.h:107
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:1420
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:1918
MagickBooleanType text_antialias
Definition: draw.h:230
MagickExport MagickStatusType ParseGeometry(const char *geometry, GeometryInfo *geometry_info)
Definition: geometry.c:860
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:1696
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:135
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
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:2358
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:1177
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