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