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