annotate.c revision 17f11b056210f082a6d0e54ac5d68e6d72fa76b2
13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%           AAA   N   N  N   N   OOO   TTTTT   AAA   TTTTT  EEEEE             %
73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%          A   A  NN  N  NN  N  O   O    T    A   A    T    E                 %
83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%          AAAAA  N N N  N N N  O   O    T    AAAAA    T    EEE               %
93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%          A   A  N  NN  N  NN  O   O    T    A   A    T    E                 %
103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%          A   A  N   N  N   N   OOO     T    A   A    T    EEEEE             %
113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                   MagickCore Image Annotation Methods                       %
143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                              Software Design                                %
16de984cdc3631106b1cbbb8d3972b76a0fc27e8e8cristy%                                   Cristy                                    %
173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                 July 1992                                   %
183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
20b56bb24a985ca4366713bcd8ffdfacbb48a98a2fcristy%  Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization      %
213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  dedicated to making software imaging solutions freely available.           %
223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  You may not use this file except in compliance with the License.  You may  %
243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  obtain a copy of the License at                                            %
253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    http://www.imagemagick.org/script/license.php                            %
273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Unless required by applicable law or agreed to in writing, software        %
293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  distributed under the License is distributed on an "AS IS" BASIS,          %
303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  See the License for the specific language governing permissions and        %
323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  limitations under the License.                                             %
333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Digital Applications (www.digapp.com) contributed the stroked text algorithm.
373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% It was written by Leonard Rosenthol.
383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Include declarations.
443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
454c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/studio.h"
464c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/annotate.h"
475ff4eaf57b3cd47d0371f204f865cbba614674a0cristy#include "MagickCore/annotate-private.h"
484c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/attribute.h"
494c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/cache-view.h"
50c9afe1687cd4da5d2382a9ca3ca12f30d8baa96fcristy#include "MagickCore/channel.h"
514c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/client.h"
524c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/color.h"
534c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/color-private.h"
5454b92627b2e9657853beee431546d08234276477cristy#include "MagickCore/colorspace-private.h"
554c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/composite.h"
564c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/composite-private.h"
574c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/constitute.h"
584c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/draw.h"
594c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/draw-private.h"
603644bdf56f0081bcae1f4dbc69c2d06713f6203bcristy#include "MagickCore/enhance.h"
614c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/exception.h"
624c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/exception-private.h"
634c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/gem.h"
644c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/geometry.h"
654c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/image-private.h"
664c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/log.h"
674c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantum.h"
684c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantum-private.h"
694c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/pixel-accessor.h"
704c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/property.h"
714c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/resource_.h"
724c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/semaphore.h"
734c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/statistic.h"
744c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/string_.h"
754c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/token-private.h"
764c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/transform.h"
774c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/type.h"
784c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/utility.h"
79d1dd6e4fefa0810b9893e6ac9418f79c97c1b39acristy#include "MagickCore/utility-private.h"
80bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristy#include "MagickCore/xwindow.h"
814c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/xwindow-private.h"
823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_FREETYPE_DELEGATE)
8307a3cca00593c795eb8e0427f5bc4c2bcad3f0fbcristy#if defined(__MINGW32__) || defined(__MINGW64__)
843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  undef interface
853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
8603f187ee83f1927717c93c57af06d5e030a194becristy#include <ft2build.h>
873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(FT_FREETYPE_H)
883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include FT_FREETYPE_H
893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include <freetype/freetype.h>
913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(FT_GLYPH_H)
933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include FT_GLYPH_H
943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include <freetype/ftglyph.h>
963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(FT_OUTLINE_H)
983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include FT_OUTLINE_H
993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
1003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include <freetype/ftoutln.h>
1013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(FT_BBOX_H)
1033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include FT_BBOX_H
1043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
1053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include <freetype/ftbbox.h>
1063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif /* defined(FT_BBOX_H) */
1073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
110d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy  Annotate semaphores.
111d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy*/
112d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristystatic SemaphoreInfo
113d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy  *annotate_semaphore = (SemaphoreInfo *) NULL;
114d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy
115d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy/*
1163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Forward declarations.
1173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1183ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType
1195cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  RenderType(Image *,const DrawInfo *,const PointInfo *,TypeMetric *,
1205cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy    ExceptionInfo *),
1215cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  RenderPostscript(Image *,const DrawInfo *,const PointInfo *,TypeMetric *,
1225cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy    ExceptionInfo *),
1233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RenderFreetype(Image *,const DrawInfo *,const char *,const PointInfo *,
1245cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy    TypeMetric *,ExceptionInfo *),
1255cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  RenderX11(Image *,const DrawInfo *,const PointInfo *,TypeMetric *,
1265cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy    ExceptionInfo *);
1273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
1293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
133d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy+   A n n o t a t e C o m p o n e n t G e n e s i s                           %
134d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
135d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
136d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
137d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%
139d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%  AnnotateComponentGenesis() instantiates the annotate component.
140d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%
141d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%  The format of the AnnotateComponentGenesis method is:
142d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%
143d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%      MagickBooleanType AnnotateComponentGenesis(void)
144d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%
145d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy*/
1465ff4eaf57b3cd47d0371f204f865cbba614674a0cristyMagickPrivate MagickBooleanType AnnotateComponentGenesis(void)
147d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy{
1487c9770650f31145e0fe8811d10b2e0ecd47697c8cristy  if (annotate_semaphore == (SemaphoreInfo *) NULL)
1497c9770650f31145e0fe8811d10b2e0ecd47697c8cristy    annotate_semaphore=AcquireSemaphoreInfo();
150d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy  return(MagickTrue);
151d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy}
152d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy
153d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy/*
154d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
156d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
157d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
158d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy+   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                         %
159d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
160d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
161d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
162d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%
164d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%  AnnotateComponentTerminus() destroys the annotate component.
165d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%
166d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%  The format of the AnnotateComponentTerminus method is:
167d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%
168d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%      AnnotateComponentTerminus(void)
169d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%
170d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy*/
1715ff4eaf57b3cd47d0371f204f865cbba614674a0cristyMagickPrivate void AnnotateComponentTerminus(void)
172d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy{
173d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy  if (annotate_semaphore == (SemaphoreInfo *) NULL)
17404b11db5504ecdf205114ae7e9e68774a1ff0b9bcristy    ActivateSemaphoreInfo(&annotate_semaphore);
1753d162a93f537cb7cbb6d9fa3b8e73e8f992a527acristy  RelinquishSemaphoreInfo(&annotate_semaphore);
176d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy}
177d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy
178d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy/*
179d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
181d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
182d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy%                                                                             %
1833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   A n n o t a t e I m a g e                                                 %
1843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  AnnotateImage() annotates an image with text.  Optionally you can include
1903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  any of the following bits of information about the image by embedding
1913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the appropriate special characters:
1923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
193528127ac76bc2eda65c7e8407b11669b25513149cristy%    \n   newline
194528127ac76bc2eda65c7e8407b11669b25513149cristy%    \r   carriage return
195528127ac76bc2eda65c7e8407b11669b25513149cristy%    <    less-than character.
196528127ac76bc2eda65c7e8407b11669b25513149cristy%    >    greater-than character.
197528127ac76bc2eda65c7e8407b11669b25513149cristy%    &    ampersand character.
198528127ac76bc2eda65c7e8407b11669b25513149cristy%    %%   a percent sign
199528127ac76bc2eda65c7e8407b11669b25513149cristy%    %b   file size of image read in
200528127ac76bc2eda65c7e8407b11669b25513149cristy%    %c   comment meta-data property
201528127ac76bc2eda65c7e8407b11669b25513149cristy%    %d   directory component of path
202528127ac76bc2eda65c7e8407b11669b25513149cristy%    %e   filename extension or suffix
203528127ac76bc2eda65c7e8407b11669b25513149cristy%    %f   filename (including suffix)
204528127ac76bc2eda65c7e8407b11669b25513149cristy%    %g   layer canvas page geometry   (equivalent to "%Wx%H%X%Y")
205528127ac76bc2eda65c7e8407b11669b25513149cristy%    %h   current image height in pixels
206528127ac76bc2eda65c7e8407b11669b25513149cristy%    %i   image filename (note: becomes output filename for "info:")
207528127ac76bc2eda65c7e8407b11669b25513149cristy%    %k   CALCULATED: number of unique colors
208528127ac76bc2eda65c7e8407b11669b25513149cristy%    %l   label meta-data property
209528127ac76bc2eda65c7e8407b11669b25513149cristy%    %m   image file format (file magic)
210528127ac76bc2eda65c7e8407b11669b25513149cristy%    %n   number of images in current image sequence
211528127ac76bc2eda65c7e8407b11669b25513149cristy%    %o   output filename  (used for delegates)
212528127ac76bc2eda65c7e8407b11669b25513149cristy%    %p   index of image in current image list
213528127ac76bc2eda65c7e8407b11669b25513149cristy%    %q   quantum depth (compile-time constant)
214528127ac76bc2eda65c7e8407b11669b25513149cristy%    %r   image class and colorspace
215528127ac76bc2eda65c7e8407b11669b25513149cristy%    %s   scene number (from input unless re-assigned)
216528127ac76bc2eda65c7e8407b11669b25513149cristy%    %t   filename without directory or extension (suffix)
217528127ac76bc2eda65c7e8407b11669b25513149cristy%    %u   unique temporary filename (used for delegates)
218528127ac76bc2eda65c7e8407b11669b25513149cristy%    %w   current width in pixels
219528127ac76bc2eda65c7e8407b11669b25513149cristy%    %x   x resolution (density)
220528127ac76bc2eda65c7e8407b11669b25513149cristy%    %y   y resolution (density)
221528127ac76bc2eda65c7e8407b11669b25513149cristy%    %z   image depth (as read in unless modified, image save depth)
222528127ac76bc2eda65c7e8407b11669b25513149cristy%    %A   image transparency channel enabled (true/false)
223528127ac76bc2eda65c7e8407b11669b25513149cristy%    %C   image compression type
224528127ac76bc2eda65c7e8407b11669b25513149cristy%    %D   image GIF dispose method
225528127ac76bc2eda65c7e8407b11669b25513149cristy%    %G   original image size (%wx%h; before any resizes)
226528127ac76bc2eda65c7e8407b11669b25513149cristy%    %H   page (canvas) height
227528127ac76bc2eda65c7e8407b11669b25513149cristy%    %M   Magick filename (original file exactly as given,  including read mods)
228528127ac76bc2eda65c7e8407b11669b25513149cristy%    %O   page (canvas) offset ( = %X%Y )
229528127ac76bc2eda65c7e8407b11669b25513149cristy%    %P   page (canvas) size ( = %Wx%H )
230528127ac76bc2eda65c7e8407b11669b25513149cristy%    %Q   image compression quality ( 0 = default )
231528127ac76bc2eda65c7e8407b11669b25513149cristy%    %S   ?? scenes ??
232528127ac76bc2eda65c7e8407b11669b25513149cristy%    %T   image time delay (in centi-seconds)
233528127ac76bc2eda65c7e8407b11669b25513149cristy%    %U   image resolution units
234528127ac76bc2eda65c7e8407b11669b25513149cristy%    %W   page (canvas) width
235528127ac76bc2eda65c7e8407b11669b25513149cristy%    %X   page (canvas) x offset (including sign)
236528127ac76bc2eda65c7e8407b11669b25513149cristy%    %Y   page (canvas) y offset (including sign)
237528127ac76bc2eda65c7e8407b11669b25513149cristy%    %Z   unique filename (used for delegates)
238528127ac76bc2eda65c7e8407b11669b25513149cristy%    %@   CALCULATED: trim bounding box (without actually trimming)
239528127ac76bc2eda65c7e8407b11669b25513149cristy%    %#   CALCULATED: 'signature' hash of image values
2403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the AnnotateImage method is:
2423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2435cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%      MagickBooleanType AnnotateImage(Image *image,DrawInfo *draw_info,
2445cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%        ExceptionInfo *exception)
2453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
2473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
2493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o draw_info: the draw info.
2513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2525cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%    o exception: return any errors or warnings in this structure.
2535cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%
2543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2553ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport MagickBooleanType AnnotateImage(Image *image,
2565cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  const DrawInfo *draw_info,ExceptionInfo *exception)
2573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
2583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
2593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    primitive[MaxTextExtent],
2603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    **textlist;
2613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DrawInfo
2633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate,
2643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_info;
2653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GeometryInfo
2673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    geometry_info;
2683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
2703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
2713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  PointInfo
2733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    offset;
2743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RectangleInfo
2763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    geometry;
2773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
278bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
2793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
2803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_t
2823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    length;
2833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  TypeMetric
2853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    metrics;
2863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
287bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  size_t
2885846039e7fade723e168819490eb771446e4b81fcristy    height,
2893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_lines;
2903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
2923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image->signature == MagickSignature);
2933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
2943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(draw_info != (DrawInfo *) NULL);
2963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(draw_info->signature == MagickSignature);
2973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->text == (char *) NULL)
2983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
2993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (*draw_info->text == '\0')
3003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickTrue);
3013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  textlist=StringToList(draw_info->text);
3023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (textlist == (char **) NULL)
3033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
3043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  length=strlen(textlist[0]);
3053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=1; textlist[i] != (char *) NULL; i++)
3063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (strlen(textlist[i]) > length)
3073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      length=strlen(textlist[i]);
308bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  number_lines=(size_t) i;
3093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate=CloneDrawInfo((ImageInfo *) NULL,draw_info);
3103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
3113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  SetGeometry(image,&geometry);
3123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  SetGeometryInfo(&geometry_info);
3133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_info->geometry != (char *) NULL)
3143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
3153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) ParsePageGeometry(image,annotate_info->geometry,&geometry,
3165cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy        exception);
3173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) ParseGeometry(annotate_info->geometry,&geometry_info);
3183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
3195cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
321a6400b1cfc3594644a0f02f3d77d920092f078eecristy  if (IsGrayColorspace(image->colorspace) != MagickFalse)
3220c81d063030f7b30a97c7856e95534243cdc9e13cristy    (void) SetImageColorspace(image,sRGBColorspace,exception);
3233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=MagickTrue;
3243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; textlist[i] != (char *) NULL; i++)
3253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
3263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /*
3273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Position text relative to image.
3283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    */
3293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_info->affine.tx=geometry_info.xi-image->page.x;
3303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_info->affine.ty=geometry_info.psi-image->page.y;
3313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) CloneString(&annotate->text,textlist[i]);
3325cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy    (void) GetTypeMetrics(image,annotate,&metrics,exception);
333bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    height=(ssize_t) (metrics.ascent-metrics.descent+
3345846039e7fade723e168819490eb771446e4b81fcristy      draw_info->interline_spacing+0.5);
3353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    switch (annotate->gravity)
3363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
3373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case UndefinedGravity:
3383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      default:
3393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height;
3413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height;
3423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
3433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case NorthWestGravity:
3453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+i*
3473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ry*height+annotate_info->affine.ry*
3483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (metrics.ascent+metrics.descent);
3493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+i*
3503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sy*height+annotate_info->affine.sy*
3513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          metrics.ascent;
3523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
3533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case NorthGravity:
3553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+
3573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.width/2.0+i*annotate_info->affine.ry*height-
3583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)/2.0+
3593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ry*(metrics.ascent+metrics.descent);
3603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+i*
3613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sy*height+annotate_info->affine.sy*
3623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          metrics.ascent-annotate_info->affine.rx*(metrics.width-
3633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          metrics.bounds.x1)/2.0;
3643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
3653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case NorthEastGravity:
3673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=(geometry.width == 0 ? 1.0 : -1.0)*annotate_info->affine.tx+
3693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.width+i*annotate_info->affine.ry*height-
3703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)+
3713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ry*(metrics.ascent+metrics.descent)-1.0;
3723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+i*
3733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sy*height+annotate_info->affine.sy*
3743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          metrics.ascent-annotate_info->affine.rx*(metrics.width-
3753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          metrics.bounds.x1);
3763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
3773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case WestGravity:
3793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+i*
3813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ry*height+annotate_info->affine.ry*
3823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (metrics.ascent+metrics.descent-(number_lines-1.0)*height)/2.0;
3833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+
3843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.height/2.0+i*annotate_info->affine.sy*height+
3853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sy*(metrics.ascent+metrics.descent-
3863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (number_lines-1.0)*height)/2.0;
3873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
3883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case CenterGravity:
3903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+
3923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.width/2.0+i*annotate_info->affine.ry*height-
3933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)/2.0+
3943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ry*(metrics.ascent+metrics.descent-
3953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (number_lines-1)*height)/2.0;
3963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+
3973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.height/2.0+i*annotate_info->affine.sy*height-
3983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.rx*(metrics.width+metrics.bounds.x1)/2.0+
3993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sy*(metrics.ascent+metrics.descent-
4003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (number_lines-1.0)*height)/2.0;
4013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case EastGravity:
4043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
4053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=(geometry.width == 0 ? 1.0 : -1.0)*annotate_info->affine.tx+
4063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.width+i*annotate_info->affine.ry*height-
4073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)+
4083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ry*(metrics.ascent+metrics.descent-
4093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (number_lines-1.0)*height)/2.0-1.0;
4103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+
4113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.height/2.0+i*annotate_info->affine.sy*height-
4123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.rx*(metrics.width+metrics.bounds.x1)+
4133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sy*(metrics.ascent+metrics.descent-
4143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (number_lines-1.0)*height)/2.0;
4153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case SouthWestGravity:
4183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
4193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+i*
4203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ry*height-annotate_info->affine.ry*
4213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (number_lines-1.0)*height;
4223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=(geometry.height == 0 ? 1.0 : -1.0)*annotate_info->affine.ty+
4233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.height+i*annotate_info->affine.sy*height-
4243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sy*(number_lines-1.0)*height+metrics.descent;
4253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case SouthGravity:
4283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
4293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+
4303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.width/2.0+i*annotate_info->affine.ry*height-
4313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)/2.0-
4323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ry*(number_lines-1.0)*height/2.0;
4333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=(geometry.height == 0 ? 1.0 : -1.0)*annotate_info->affine.ty+
4343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.height+i*annotate_info->affine.sy*height-
4353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.rx*(metrics.width+metrics.bounds.x1)/2.0-
4363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sy*(number_lines-1.0)*height+metrics.descent;
4373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case SouthEastGravity:
4403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
4413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=(geometry.width == 0 ? 1.0 : -1.0)*annotate_info->affine.tx+
4423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.width+i*annotate_info->affine.ry*height-
4433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)-
4443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ry*(number_lines-1.0)*height-1.0;
4453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=(geometry.height == 0 ? 1.0 : -1.0)*annotate_info->affine.ty+
4463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          geometry.height+i*annotate_info->affine.sy*height-
4473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.rx*(metrics.width+metrics.bounds.x1)-
4483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sy*(number_lines-1.0)*height+metrics.descent;
4493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    switch (annotate->align)
4533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case LeftAlign:
4553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
4563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height;
4573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height;
4583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case CenterAlign:
4613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
4623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height-
4633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)/2.0;
4643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height-
4653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.rx*(metrics.width+metrics.bounds.x1)/2.0;
4663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case RightAlign:
4693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
4703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height-
4713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.sx*(metrics.width+metrics.bounds.x1);
4723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height-
4733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.rx*(metrics.width+metrics.bounds.x1);
4743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      default:
4773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
4783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4794c08aed51c5899665ade97263692328eea4af106cristy    if (draw_info->undercolor.alpha != TransparentAlpha)
4803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
4813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        DrawInfo
4823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *undercolor_info;
4833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
4853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Text box.
4863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
4873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        undercolor_info=CloneDrawInfo((ImageInfo *) NULL,(DrawInfo *) NULL);
4883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        undercolor_info->fill=draw_info->undercolor;
4893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        undercolor_info->affine=draw_info->affine;
4903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        undercolor_info->affine.tx=offset.x-draw_info->affine.ry*metrics.ascent;
4913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        undercolor_info->affine.ty=offset.y-draw_info->affine.sy*metrics.ascent;
492b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy        (void) FormatLocaleString(primitive,MaxTextExtent,
49390ceebd5f7365b207579904a7c763411b586a023cristy          "rectangle -0.5,-0.5 %g,%.20g",metrics.origin.x,(double) height);
4943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) CloneString(&undercolor_info->primitive,primitive);
495018f07f7333b25743d0afff892450cebdb905c1acristy        (void) DrawImage(image,undercolor_info,exception);
4963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) DestroyDrawInfo(undercolor_info);
4973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
4983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_info->affine.tx=offset.x;
4993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_info->affine.ty=offset.y;
500b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleString(primitive,MaxTextExtent,"stroke-width %g "
501a8549b176173db7680652304c372c64bb1a51737cristy      "line 0,0 %g,0",metrics.underline_thickness,metrics.width);
5023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (annotate->decorate == OverlineDecoration)
5033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
5043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        annotate_info->affine.ty-=(draw_info->affine.sy*(metrics.ascent+
5053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          metrics.descent-metrics.underline_position));
5063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) CloneString(&annotate_info->primitive,primitive);
507018f07f7333b25743d0afff892450cebdb905c1acristy        (void) DrawImage(image,annotate_info,exception);
5083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
5093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
5103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (annotate->decorate == UnderlineDecoration)
5113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
5123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ty-=(draw_info->affine.sy*
5133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            metrics.underline_position);
5143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) CloneString(&annotate_info->primitive,primitive);
515018f07f7333b25743d0afff892450cebdb905c1acristy          (void) DrawImage(image,annotate_info,exception);
5163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
5173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /*
5183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Annotate image with text.
5193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    */
5205cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy    status=RenderType(image,annotate,&offset,&metrics,exception);
5213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (status == MagickFalse)
5223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
5233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (annotate->decorate == LineThroughDecoration)
5243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
5253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        annotate_info->affine.ty-=(draw_info->affine.sy*(height+
5263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          metrics.underline_position+metrics.descent)/2.0);
5273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) CloneString(&annotate_info->primitive,primitive);
528018f07f7333b25743d0afff892450cebdb905c1acristy        (void) DrawImage(image,annotate_info,exception);
5293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
5303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
5313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Relinquish resources.
5333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=DestroyDrawInfo(annotate_info);
5353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate=DestroyDrawInfo(annotate);
5363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; textlist[i] != (char *) NULL; i++)
5373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    textlist[i]=DestroyString(textlist[i]);
5383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  textlist=(char **) RelinquishMagickMemory(textlist);
5393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(status);
5403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
5413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
5433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
5453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
5463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
5473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  F o r m a t M a g i c k C a p t i o n                                      %
5483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
5493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
5503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
5513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  FormatMagickCaption() formats a caption so that it fits within the image
5543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  width.  It returns the number of lines in the formatted caption.
5553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the FormatMagickCaption method is:
5573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
558bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy%      ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
5595cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%        const MagickBooleanType split,TypeMetric *metrics,char **caption,
5605cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%        ExceptionInfo *exception)
5613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows.
5633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image:  The image.
5653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o draw_info: the draw info.
5673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5686b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy%    o split: when no convenient line breaks-- insert newline.
5696b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy%
5703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o metrics: Return the font metrics in this structure.
5713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5726b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy%    o caption: the caption.
5736b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy%
5745cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%    o exception: return any errors or warnings in this structure.
5755cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%
5763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
577bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristyMagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
5785cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  const MagickBooleanType split,TypeMetric *metrics,char **caption,
5795cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  ExceptionInfo *exception)
5803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
58174966dbfe99011d1f7bea577e97a3d9a7b9836c7cristy  char
58274966dbfe99011d1f7bea577e97a3d9a7b9836c7cristy    *text;
58374966dbfe99011d1f7bea577e97a3d9a7b9836c7cristy
5843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
5853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
5863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register char
5883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p,
5893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q,
5903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *s;
5913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
592bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
5933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
5943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
595bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  size_t
5963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
5973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5986193b86c0b59030b647a10c75f37ec82d73e3695cristy  ssize_t
5996193b86c0b59030b647a10c75f37ec82d73e3695cristy    n;
6006193b86c0b59030b647a10c75f37ec82d73e3695cristy
60174966dbfe99011d1f7bea577e97a3d9a7b9836c7cristy  text=AcquireString(draw_info->text);
6023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  q=draw_info->text;
6033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  s=(char *) NULL;
6043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p))
6053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
6063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (IsUTFSpace(GetUTFCode(p)) != MagickFalse)
6073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      s=p;
6082911f2d54257d36e1086061dbcc312fdad781070cristy    if (GetUTFCode(p) == '\n')
609e2c81adf02cbe4bb92991389437a2a1daf8ed313cristy      q=draw_info->text;
610bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    for (i=0; i < (ssize_t) GetUTFOctets(p); i++)
6113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *q++=(*(p+i));
6123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q='\0';
6135cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy    status=GetTypeMetrics(image,draw_info,metrics,exception);
6143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (status == MagickFalse)
6153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
61678fed5ea9a7f0a35e641ce3bc6f835fb099c4d20cristy    width=(size_t) floor(metrics->width+draw_info->stroke_width+0.5);
61774966dbfe99011d1f7bea577e97a3d9a7b9836c7cristy    if ((width <= image->columns) || (strcmp(text,draw_info->text) == 0))
6186193b86c0b59030b647a10c75f37ec82d73e3695cristy      continue;
61974966dbfe99011d1f7bea577e97a3d9a7b9836c7cristy    (void) strcpy(text,draw_info->text);
6204aa314e7f9e09c30fcedcd112156b1dfb712b62dcristy    if ((s != (char *) NULL) && (GetUTFOctets(s) == 1))
6213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
6223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *s='\n';
6233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        p=s;
6243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
6253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
6264aa314e7f9e09c30fcedcd112156b1dfb712b62dcristy      if ((s != (char *) NULL) || (split != MagickFalse))
6276b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy        {
6286b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          char
6296b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy            *target;
6303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6316b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          /*
6326b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy            No convenient line breaks-- insert newline.
6336b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          */
6346b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          target=AcquireString(*caption);
6356b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          n=p-(*caption);
6366b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          CopyMagickString(target,*caption,n+1);
6376b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          ConcatenateMagickString(target,"\n",strlen(*caption)+1);
6386b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          ConcatenateMagickString(target,p,strlen(*caption)+2);
6396b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          (void) DestroyString(*caption);
6406b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          *caption=target;
6416b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy          p=(*caption)+n;
6426b1d05e71aed91c7f85ff155dfad281e24d16fe5cristy        }
6433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    q=draw_info->text;
6446193b86c0b59030b647a10c75f37ec82d73e3695cristy    s=(char *) NULL;
6453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
64674966dbfe99011d1f7bea577e97a3d9a7b9836c7cristy  text=DestroyString(text);
6476193b86c0b59030b647a10c75f37ec82d73e3695cristy  n=0;
6483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p))
6493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (GetUTFCode(p) == '\n')
6506193b86c0b59030b647a10c75f37ec82d73e3695cristy      n++;
6516193b86c0b59030b647a10c75f37ec82d73e3695cristy  return(n);
6523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
6533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
6553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   G e t M u l t i l i n e T y p e M e t r i c s                             %
6603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  GetMultilineTypeMetrics() returns the following information for the
6663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  specified font and text:
6673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    character width
6693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    character height
6703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    ascender
6713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    descender
6723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    text width
6733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    text height
6743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    maximum horizontal advance
6753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    bounds: x1
6763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    bounds: y1
6773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    bounds: x2
6783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    bounds: y2
6793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    origin: x
6803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    origin: y
6813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    underline position
6823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    underline thickness
6833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  This method is like GetTypeMetrics() but it returns the maximum text width
6853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  and height for multiple lines of text.
6863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the GetMultilineTypeMetrics method is:
6883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType GetMultilineTypeMetrics(Image *image,
6905cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%        const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception)
6913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
6933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
6953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o draw_info: the draw info.
6973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o metrics: Return the font metrics in this structure.
6993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7005cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%    o exception: return any errors or warnings in this structure.
7015cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%
7023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
7033ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport MagickBooleanType GetMultilineTypeMetrics(Image *image,
7045cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception)
7053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
7063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
7073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    **textlist;
7083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DrawInfo
7103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_info;
7113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
7133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
7143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
715bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
7163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
7173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  TypeMetric
7193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    extent;
7203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
7223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image->signature == MagickSignature);
7233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
7243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
7253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(draw_info != (DrawInfo *) NULL);
7263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(draw_info->text != (char *) NULL);
7273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(draw_info->signature == MagickSignature);
7283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (*draw_info->text == '\0')
7293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
7303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
7313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->text=DestroyString(annotate_info->text);
7323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
7333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Convert newlines to multiple lines of text.
7343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
7353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  textlist=StringToList(draw_info->text);
7363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (textlist == (char **) NULL)
7373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
7383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->render=MagickFalse;
739024843f38984cd26602f0b3b28a0768dfa056bb5cristy  annotate_info->direction=UndefinedDirection;
7403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(metrics,0,sizeof(*metrics));
7413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(&extent,0,sizeof(extent));
7423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
7433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Find the widest of the text lines.
7443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
7453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->text=textlist[0];
7465cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  status=GetTypeMetrics(image,annotate_info,&extent,exception);
7473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *metrics=extent;
7483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=1; textlist[i] != (char *) NULL; i++)
7493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
7503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_info->text=textlist[i];
7515cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy    status=GetTypeMetrics(image,annotate_info,&extent,exception);
7523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (extent.width > metrics->width)
7533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *metrics=extent;
7543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
755e2c81adf02cbe4bb92991389437a2a1daf8ed313cristy  metrics->height=(double) (i*(size_t) (metrics->ascent-metrics->descent+0.5)+
756e2c81adf02cbe4bb92991389437a2a1daf8ed313cristy    (i-1)*draw_info->interline_spacing);
7573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
7583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Relinquish resources.
7593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
7603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->text=(char *) NULL;
7613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=DestroyDrawInfo(annotate_info);
7623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; textlist[i] != (char *) NULL; i++)
7633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    textlist[i]=DestroyString(textlist[i]);
7643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  textlist=(char **) RelinquishMagickMemory(textlist);
7653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(status);
7663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
7673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
7693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   G e t T y p e M e t r i c s                                               %
7743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  GetTypeMetrics() returns the following information for the specified font
7803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  and text:
7813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    character width
7833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    character height
7843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    ascender
7853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    descender
7863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    text width
7873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    text height
7883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    maximum horizontal advance
7893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    bounds: x1
7903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    bounds: y1
7913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    bounds: x2
7923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    bounds: y2
7933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    origin: x
7943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    origin: y
7953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    underline position
7963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    underline thickness
7973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the GetTypeMetrics method is:
7993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType GetTypeMetrics(Image *image,const DrawInfo *draw_info,
8015cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%        TypeMetric *metrics,ExceptionInfo *exception)
8023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
8043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
8063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o draw_info: the draw info.
8083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o metrics: Return the font metrics in this structure.
8103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8115cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%    o exception: return any errors or warnings in this structure.
8125cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%
8133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8143ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport MagickBooleanType GetTypeMetrics(Image *image,
8155cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception)
8163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
8173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DrawInfo
8183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_info;
8193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
8213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
8223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  PointInfo
8243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    offset;
8253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
8273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image->signature == MagickSignature);
8283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
8293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
8303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(draw_info != (DrawInfo *) NULL);
8313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(draw_info->text != (char *) NULL);
8323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(draw_info->signature == MagickSignature);
8333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
8343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->render=MagickFalse;
835024843f38984cd26602f0b3b28a0768dfa056bb5cristy  annotate_info->direction=UndefinedDirection;
8363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(metrics,0,sizeof(*metrics));
8373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  offset.x=0.0;
8383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  offset.y=0.0;
8395cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  status=RenderType(image,annotate_info,&offset,metrics,exception);
8403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
8413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),"Metrics: text: %s; "
842e7f5109f30fc7242d04a26174a9138483dda5b6acristy      "width: %g; height: %g; ascent: %g; descent: %g; max advance: %g; "
843a8549b176173db7680652304c372c64bb1a51737cristy      "bounds: %g,%g  %g,%g; origin: %g,%g; pixels per em: %g,%g; "
844e7f5109f30fc7242d04a26174a9138483dda5b6acristy      "underline position: %g; underline thickness: %g",annotate_info->text,
8453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      metrics->width,metrics->height,metrics->ascent,metrics->descent,
8463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      metrics->max_advance,metrics->bounds.x1,metrics->bounds.y1,
8474c08aed51c5899665ade97263692328eea4af106cristy      metrics->bounds.x2,metrics->bounds.y2,metrics->origin.x,metrics->origin.y,
8484c08aed51c5899665ade97263692328eea4af106cristy      metrics->pixels_per_em.x,metrics->pixels_per_em.y,
8493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      metrics->underline_position,metrics->underline_thickness);
8503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=DestroyDrawInfo(annotate_info);
8513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(status);
8523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
8533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
8553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   R e n d e r T y p e                                                       %
8603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  RenderType() renders text on the image.  It also returns the bounding box of
8663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the text relative to the image.
8673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the RenderType method is:
8693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType RenderType(Image *image,DrawInfo *draw_info,
8715cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%        const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
8723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
8743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
8763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o draw_info: the draw info.
8783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o offset: (x,y) location of text relative to image.
8803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o metrics: bounding box of text.
8823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8835cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%    o exception: return any errors or warnings in this structure.
8845cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%
8853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8863ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType RenderType(Image *image,const DrawInfo *draw_info,
8875cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
8883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
8893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const TypeInfo
8903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *type_info;
8913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DrawInfo
8933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_info;
8943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
8963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
8973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  type_info=(const TypeInfo *) NULL;
8993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->font != (char *) NULL)
9003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
9013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (*draw_info->font == '@')
9023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
9033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          status=RenderFreetype(image,draw_info,draw_info->encoding,offset,
9045cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy            metrics,exception);
9053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return(status);
9063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
9073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (*draw_info->font == '-')
9085cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy        return(RenderX11(image,draw_info,offset,metrics,exception));
9093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (IsPathAccessible(draw_info->font) != MagickFalse)
9103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
9113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          status=RenderFreetype(image,draw_info,draw_info->encoding,offset,
9125cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy            metrics,exception);
9133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return(status);
9143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
9155cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      type_info=GetTypeInfo(draw_info->font,exception);
9163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (type_info == (const TypeInfo *) NULL)
9175cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy        (void) ThrowMagickException(exception,GetMagickModule(),TypeWarning,
918efe601ce9ea5ad34ad0e8ad6e61d9be9b148b2a3cristy          "UnableToReadFont","`%s'",draw_info->font);
9193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
9203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((type_info == (const TypeInfo *) NULL) &&
9213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (draw_info->family != (const char *) NULL))
9223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
9233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      type_info=GetTypeInfoByFamily(draw_info->family,draw_info->style,
9245cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy        draw_info->stretch,draw_info->weight,exception);
9253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (type_info == (const TypeInfo *) NULL)
9265cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy        (void) ThrowMagickException(exception,GetMagickModule(),TypeWarning,
927efe601ce9ea5ad34ad0e8ad6e61d9be9b148b2a3cristy          "UnableToReadFont","`%s'",draw_info->family);
9283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
9293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (type_info == (const TypeInfo *) NULL)
930d984f27fbbb96073787c88f4c9409d7f836cedc5cristy    type_info=GetTypeInfoByFamily("Arial",draw_info->style,
9315cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      draw_info->stretch,draw_info->weight,exception);
932d984f27fbbb96073787c88f4c9409d7f836cedc5cristy  if (type_info == (const TypeInfo *) NULL)
933cbb34a4def108d6db032ca9631a433afd3ea5a5dcristy    type_info=GetTypeInfoByFamily("Helvetica",draw_info->style,
9345cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      draw_info->stretch,draw_info->weight,exception);
9353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (type_info == (const TypeInfo *) NULL)
936704acaaebbfeec018847456e79de0ce301db126ecristy    type_info=GetTypeInfoByFamily("Century Schoolbook",draw_info->style,
9375cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      draw_info->stretch,draw_info->weight,exception);
938704acaaebbfeec018847456e79de0ce301db126ecristy  if (type_info == (const TypeInfo *) NULL)
9396193b86c0b59030b647a10c75f37ec82d73e3695cristy    type_info=GetTypeInfoByFamily("Sans",draw_info->style,
9405cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      draw_info->stretch,draw_info->weight,exception);
9416193b86c0b59030b647a10c75f37ec82d73e3695cristy  if (type_info == (const TypeInfo *) NULL)
9423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    type_info=GetTypeInfoByFamily((const char *) NULL,draw_info->style,
9435cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      draw_info->stretch,draw_info->weight,exception);
9443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (type_info == (const TypeInfo *) NULL)
9455cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy    type_info=GetTypeInfo("*",exception);
946704acaaebbfeec018847456e79de0ce301db126ecristy  if (type_info == (const TypeInfo *) NULL)
9473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
9485cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      status=RenderFreetype(image,draw_info,draw_info->encoding,offset,metrics,
9495cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy        exception);
9503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(status);
9513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
9523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
9533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->face=type_info->face;
9543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (type_info->metrics != (char *) NULL)
9553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) CloneString(&annotate_info->metrics,type_info->metrics);
9563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (type_info->glyphs != (char *) NULL)
9573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) CloneString(&annotate_info->font,type_info->glyphs);
9585cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  status=RenderFreetype(image,annotate_info,type_info->encoding,offset,metrics,
9595cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy    exception);
9603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=DestroyDrawInfo(annotate_info);
9613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(status);
9623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
9633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
9653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   R e n d e r F r e e t y p e                                               %
9703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  RenderFreetype() renders text on the image with a Truetype font.  It also
9763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  returns the bounding box of the text relative to the image.
9773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the RenderFreetype method is:
9793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType RenderFreetype(Image *image,DrawInfo *draw_info,
9815cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%        const char *encoding,const PointInfo *offset,TypeMetric *metrics,
9825cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%        ExceptionInfo *exception)
9833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
9853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
9873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o draw_info: the draw info.
9893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o encoding: the font encoding.
9913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o offset: (x,y) location of text relative to image.
9933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o metrics: bounding box of text.
9953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9965cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%    o exception: return any errors or warnings in this structure.
9975cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%
9983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_FREETYPE_DELEGATE)
10012857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy
10023ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int TraceCubicBezier(FT_Vector *p,FT_Vector *q,FT_Vector *to,
10033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DrawInfo *draw_info)
10043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
10053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  AffineMatrix
10063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    affine;
10073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
10093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    path[MaxTextExtent];
10103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  affine=draw_info->affine;
1012b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(path,MaxTextExtent,
1013a8549b176173db7680652304c372c64bb1a51737cristy    "C%g,%g %g,%g %g,%g",affine.tx+p->x/64.0,affine.ty-
10148cd5b3193212b4aebce08c4e7afbb66b09778029cristy    p->y/64.0,affine.tx+q->x/64.0,affine.ty-q->y/64.0,affine.tx+to->x/64.0,
10158cd5b3193212b4aebce08c4e7afbb66b09778029cristy    affine.ty-to->y/64.0);
10163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ConcatenateString(&draw_info->primitive,path);
10173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(0);
10183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
10193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10203ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int TraceLineTo(FT_Vector *to,DrawInfo *draw_info)
10213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
10223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  AffineMatrix
10233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    affine;
10243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
10263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    path[MaxTextExtent];
10273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  affine=draw_info->affine;
1029b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(path,MaxTextExtent,"L%g,%g",affine.tx+
10308cd5b3193212b4aebce08c4e7afbb66b09778029cristy    to->x/64.0,affine.ty-to->y/64.0);
10313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ConcatenateString(&draw_info->primitive,path);
10323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(0);
10333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
10343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10353ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int TraceMoveTo(FT_Vector *to,DrawInfo *draw_info)
10363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
10373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  AffineMatrix
10383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    affine;
10393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
10413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    path[MaxTextExtent];
10423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  affine=draw_info->affine;
1044b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(path,MaxTextExtent,"M%g,%g",affine.tx+
10458cd5b3193212b4aebce08c4e7afbb66b09778029cristy    to->x/64.0,affine.ty-to->y/64.0);
10463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ConcatenateString(&draw_info->primitive,path);
10473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(0);
10483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
10493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10503ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int TraceQuadraticBezier(FT_Vector *control,FT_Vector *to,
10513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DrawInfo *draw_info)
10523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
10533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  AffineMatrix
10543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    affine;
10553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
10573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    path[MaxTextExtent];
10583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  affine=draw_info->affine;
1060b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(path,MaxTextExtent,"Q%g,%g %g,%g",
10613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    affine.tx+control->x/64.0,affine.ty-control->y/64.0,affine.tx+to->x/64.0,
10623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    affine.ty-to->y/64.0);
10633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ConcatenateString(&draw_info->primitive,path);
10643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(0);
10653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
10663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10673ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
10685cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  const char *encoding,const PointInfo *offset,TypeMetric *metrics,
10695cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  ExceptionInfo *exception)
10703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
10713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(FT_OPEN_PATHNAME)
10723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define FT_OPEN_PATHNAME  ft_open_pathname
10733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
10743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct _GlyphInfo
10763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
10773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    FT_UInt
10783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      id;
10793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    FT_Vector
10813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      origin;
10823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    FT_Glyph
10843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image;
10853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } GlyphInfo;
10863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char
10883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *value;
10893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1090c9b129570a277337cf0e887229741497e2ead5cfcristy  double
1091c9b129570a277337cf0e887229741497e2ead5cfcristy    direction;
1092c9b129570a277337cf0e887229741497e2ead5cfcristy
10933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DrawInfo
10943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_info;
10953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FT_BBox
10973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    bounds;
10983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FT_BitmapGlyph
11003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    bitmap;
11013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FT_Encoding
11033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    encoding_type;
11043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FT_Error
1106f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    ft_status;
11073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FT_Face
11093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    face;
11103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FT_Int32
11123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    flags;
11133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FT_Library
11153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    library;
11163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FT_Matrix
11183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    affine;
11193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FT_Open_Args
11213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    args;
11223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FT_Vector
11243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    origin;
11253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GlyphInfo
11273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    glyph,
11283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    last_glyph;
11293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1130f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  MagickBooleanType
1131f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    status;
1132f8f295fde25dd8b1a50470d53b641d5265c0871fcristy
11333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  PointInfo
11343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    point,
11353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resolution;
11363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register char
11383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
11393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11409d314ff2c17a77996c05413c2013880387e50f0ecristy  ssize_t
11419d314ff2c17a77996c05413c2013880387e50f0ecristy    code,
11429d314ff2c17a77996c05413c2013880387e50f0ecristy    y;
11439d314ff2c17a77996c05413c2013880387e50f0ecristy
11443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static FT_Outline_Funcs
11453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    OutlineMethods =
11463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
11473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (FT_Outline_MoveTo_Func) TraceMoveTo,
11483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (FT_Outline_LineTo_Func) TraceLineTo,
11493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (FT_Outline_ConicTo_Func) TraceQuadraticBezier,
11503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (FT_Outline_CubicTo_Func) TraceCubicBezier,
11513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0, 0
11523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    };
11533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11542857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy  unsigned char
11552857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    *utf8;
11562857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy
11573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
11583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize Truetype library.
11593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
1160f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  ft_status=FT_Init_FreeType(&library);
1161f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  if (ft_status != 0)
11623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowBinaryException(TypeError,"UnableToInitializeFreetypeLibrary",
11633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image->filename);
11643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  args.flags=FT_OPEN_PATHNAME;
11653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->font == (char *) NULL)
11663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    args.pathname=ConstantString("helvetica");
11673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
11683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (*draw_info->font != '@')
11693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      args.pathname=ConstantString(draw_info->font);
11703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
11713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      args.pathname=ConstantString(draw_info->font+1);
11723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  face=(FT_Face) NULL;
1173f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  ft_status=FT_Open_Face(library,&args,(long) draw_info->face,&face);
11743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  args.pathname=DestroyString(args.pathname);
1175f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  if (ft_status != 0)
11763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
11773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) FT_Done_FreeType(library);
11785cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      (void) ThrowMagickException(exception,GetMagickModule(),TypeError,
1179efe601ce9ea5ad34ad0e8ad6e61d9be9b148b2a3cristy        "UnableToReadFont","`%s'",draw_info->font);
11805cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      return(RenderPostscript(image,draw_info,offset,metrics,exception));
11813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
11823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((draw_info->metrics != (char *) NULL) &&
11833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (IsPathAccessible(draw_info->metrics) != MagickFalse))
11843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) FT_Attach_File(face,draw_info->metrics);
11853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  encoding_type=ft_encoding_unicode;
1186f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  ft_status=FT_Select_Charmap(face,encoding_type);
1187f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  if ((ft_status != 0) && (face->num_charmaps != 0))
1188f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    ft_status=FT_Set_Charmap(face,face->charmaps[0]);
11893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (encoding != (const char *) NULL)
11903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
11913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"AdobeCustom") == 0)
11923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_adobe_custom;
11933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"AdobeExpert") == 0)
11943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_adobe_expert;
11953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"AdobeStandard") == 0)
11963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_adobe_standard;
11973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"AppleRoman") == 0)
11983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_apple_roman;
11993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"BIG5") == 0)
12003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_big5;
12013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"GB2312") == 0)
12023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_gb2312;
12033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"Johab") == 0)
12043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_johab;
12053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(ft_encoding_latin_1)
12063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"Latin-1") == 0)
12073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_latin_1;
12083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
12093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"Latin-2") == 0)
12103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_latin_2;
12113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"None") == 0)
12123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_none;
12133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"SJIScode") == 0)
12143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_sjis;
12153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"Symbol") == 0)
12163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_symbol;
12173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"Unicode") == 0)
12183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_unicode;
12193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(encoding,"Wansung") == 0)
12203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        encoding_type=ft_encoding_wansung;
1221f8f295fde25dd8b1a50470d53b641d5265c0871fcristy      ft_status=FT_Select_Charmap(face,encoding_type);
1222f8f295fde25dd8b1a50470d53b641d5265c0871fcristy      if (ft_status != 0)
1223e3b2bb83e885eb35642c7029cedab50c5e1b263dcristy        {
1224e3b2bb83e885eb35642c7029cedab50c5e1b263dcristy          (void) FT_Done_Face(face);
1225e3b2bb83e885eb35642c7029cedab50c5e1b263dcristy          (void) FT_Done_FreeType(library);
1226e3b2bb83e885eb35642c7029cedab50c5e1b263dcristy          ThrowBinaryException(TypeError,"UnrecognizedFontEncoding",encoding);
1227e3b2bb83e885eb35642c7029cedab50c5e1b263dcristy        }
12283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
12293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
12303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set text size.
12313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
12323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resolution.x=DefaultResolution;
12333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resolution.y=DefaultResolution;
12343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->density != (char *) NULL)
12353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
12363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      GeometryInfo
12373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        geometry_info;
12383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickStatusType
12403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        flags;
12413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      flags=ParseGeometry(draw_info->density,&geometry_info);
12433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resolution.x=geometry_info.rho;
12443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resolution.y=geometry_info.sigma;
12453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((flags & SigmaValue) == 0)
12463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resolution.y=resolution.x;
12473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
1248f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  ft_status=FT_Set_Char_Size(face,(FT_F26Dot6) (64.0*draw_info->pointsize),
12493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (FT_F26Dot6) (64.0*draw_info->pointsize),(FT_UInt) resolution.x,
12503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (FT_UInt) resolution.y);
12513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->pixels_per_em.x=face->size->metrics.x_ppem;
12523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->pixels_per_em.y=face->size->metrics.y_ppem;
12533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->ascent=(double) face->size->metrics.ascender/64.0;
12543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->descent=(double) face->size->metrics.descender/64.0;
12553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->width=0;
12563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->origin.x=0;
12573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->origin.y=0;
12583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->height=(double) face->size->metrics.height/64.0;
12593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->max_advance=0.0;
12603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (face->size->metrics.max_advance > MagickEpsilon)
12613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    metrics->max_advance=(double) face->size->metrics.max_advance/64.0;
12623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.x1=0.0;
12633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.y1=metrics->descent;
12643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.x2=metrics->ascent+metrics->descent;
12653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.y2=metrics->ascent+metrics->descent;
12663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->underline_position=face->underline_position/64.0;
12673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->underline_thickness=face->underline_thickness/64.0;
126871709bfb884744dbf7c9030810cc8599600ab7d3cristy  if ((draw_info->text == (char *) NULL) || (*draw_info->text == '\0'))
12693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
12703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) FT_Done_Face(face);
12713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) FT_Done_FreeType(library);
12723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickTrue);
12733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
12743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
12753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Compute bounding box.
12763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
12773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
12783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),"Font %s; "
1279e7f5109f30fc7242d04a26174a9138483dda5b6acristy      "font-encoding %s; text-encoding %s; pointsize %g",
12803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      draw_info->font != (char *) NULL ? draw_info->font : "none",
12813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      encoding != (char *) NULL ? encoding : "none",
12823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      draw_info->encoding != (char *) NULL ? draw_info->encoding : "none",
12833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      draw_info->pointsize);
12843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  flags=FT_LOAD_NO_BITMAP;
128555a804e2631f770f45d3a671076b0dfe29fdf188cristy  if (draw_info->text_antialias == MagickFalse)
12864f9709e37140157c7845a03f3612534081a5b540cristy    flags|=FT_LOAD_TARGET_MONO;
128755a804e2631f770f45d3a671076b0dfe29fdf188cristy  else
128855a804e2631f770f45d3a671076b0dfe29fdf188cristy    {
1289a89189d6e227db53ecff8624fb6b4388560d9b4acristy#if defined(FT_LOAD_TARGET_LIGHT)
129055a804e2631f770f45d3a671076b0dfe29fdf188cristy      flags|=FT_LOAD_TARGET_LIGHT;
1291a89189d6e227db53ecff8624fb6b4388560d9b4acristy#elif defined(FT_LOAD_TARGET_LCD)
1292a89189d6e227db53ecff8624fb6b4388560d9b4acristy      flags|=FT_LOAD_TARGET_LCD;
129355a804e2631f770f45d3a671076b0dfe29fdf188cristy#endif
129455a804e2631f770f45d3a671076b0dfe29fdf188cristy    }
1295d15e65928aec551b7388c2863de3e3e628e2e0ddcristy  value=GetImageProperty(image,"type:hinting",exception);
129633204240c3ef57786ee59c2692ffe8ffdce97bf9cristy  if ((value != (const char *) NULL) && (LocaleCompare(value,"off") == 0))
12973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    flags|=FT_LOAD_NO_HINTING;
12983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  glyph.id=0;
12993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  glyph.image=NULL;
13003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  last_glyph.id=0;
13013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  last_glyph.image=NULL;
13023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  origin.x=0;
13033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  origin.y=0;
13043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  affine.xx=65536L;
13053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  affine.yx=0L;
13063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  affine.xy=0L;
13073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  affine.yy=65536L;
13083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->render != MagickFalse)
13093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
13103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      affine.xx=(FT_Fixed) (65536L*draw_info->affine.sx+0.5);
13113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      affine.yx=(FT_Fixed) (-65536L*draw_info->affine.rx+0.5);
13123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      affine.xy=(FT_Fixed) (-65536L*draw_info->affine.ry+0.5);
13133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      affine.yy=(FT_Fixed) (65536L*draw_info->affine.sy+0.5);
13143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
13153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
13163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CloneString(&annotate_info->primitive,"path '");
13173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->render != MagickFalse)
13183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
13193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (image->storage_class != DirectClass)
13205cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy        (void) SetImageStorageClass(image,DirectClass,exception);
132117f11b056210f082a6d0e54ac5d68e6d72fa76b2cristy      if (image->alpha_trait == UndefinedPixelTrait)
1322a64d8007a138a0efeedc286de10538f2e8c7fe6bcristy        (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
13233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
1324c9b129570a277337cf0e887229741497e2ead5cfcristy  direction=1.0;
1325cf5467b5dddb5084ec79a5921b48ce9bb2a897cecristy  if (draw_info->direction == RightToLeftDirection)
1326c9b129570a277337cf0e887229741497e2ead5cfcristy    direction=(-1.0);
13273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  point.x=0.0;
13283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  point.y=0.0;
13293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (p=draw_info->text; GetUTFCode(p) != 0; p+=GetUTFOctets(p))
1330bd51246ae63047fa139606f6c6862ff989ab1fbdcristy    if (GetUTFCode(p) < 0)
1331bd51246ae63047fa139606f6c6862ff989ab1fbdcristy      break;
13322857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy  utf8=(unsigned char *) NULL;
1333d913ea1f524066a6a8bf3d046755a5c0f7eb471fcristy  if (GetUTFCode(p) == 0)
13342857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    p=draw_info->text;
13352857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy  else
1336bd51246ae63047fa139606f6c6862ff989ab1fbdcristy    {
13372857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      utf8=ConvertLatin1ToUTF8((unsigned char *) draw_info->text);
13382857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      if (utf8 != (unsigned char *) NULL)
1339c9b129570a277337cf0e887229741497e2ead5cfcristy        p=(char *) utf8;
13402857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    }
1341f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  status=MagickTrue;
13422857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy  for (code=0; GetUTFCode(p) != 0; p+=GetUTFOctets(p))
13432857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy  {
13442857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    /*
13452857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      Render UTF-8 sequence.
13462857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    */
13472857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    glyph.id=FT_Get_Char_Index(face,GetUTFCode(p));
13482857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    if (glyph.id == 0)
13492857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      glyph.id=FT_Get_Char_Index(face,'?');
13502857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    if ((glyph.id != 0) && (last_glyph.id != 0))
13512857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      {
1352914699303f48526ae3f3109ce70b37c411cdb84ecristy        if (FT_HAS_KERNING(face))
1353914699303f48526ae3f3109ce70b37c411cdb84ecristy          {
1354914699303f48526ae3f3109ce70b37c411cdb84ecristy            FT_Vector
1355914699303f48526ae3f3109ce70b37c411cdb84ecristy              kerning;
1356914699303f48526ae3f3109ce70b37c411cdb84ecristy
1357914699303f48526ae3f3109ce70b37c411cdb84ecristy            ft_status=FT_Get_Kerning(face,last_glyph.id,glyph.id,
1358914699303f48526ae3f3109ce70b37c411cdb84ecristy              ft_kerning_default,&kerning);
1359914699303f48526ae3f3109ce70b37c411cdb84ecristy            if (ft_status == 0)
1360914699303f48526ae3f3109ce70b37c411cdb84ecristy              origin.x+=(FT_Pos) (direction*kerning.x);
1361914699303f48526ae3f3109ce70b37c411cdb84ecristy          }
1362914699303f48526ae3f3109ce70b37c411cdb84ecristy        origin.x+=(FT_Pos) (64.0*direction*draw_info->kerning);
1363914699303f48526ae3f3109ce70b37c411cdb84ecristy      }
13642857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    glyph.origin=origin;
1365f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    ft_status=FT_Load_Glyph(face,glyph.id,flags);
1366f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    if (ft_status != 0)
13672857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      continue;
1368f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    ft_status=FT_Get_Glyph(face->glyph,&glyph.image);
1369f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    if (ft_status != 0)
13702857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      continue;
1371f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    ft_status=FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph.image)->outline,
13722857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      &bounds);
1373f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    if (ft_status != 0)
13742857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      continue;
13752857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    if ((p == draw_info->text) || (bounds.xMin < metrics->bounds.x1))
1376aa83c2c383e62bd5342c0d38dc5f6e746998bde8cristy      metrics->bounds.x1=(double) bounds.xMin;
13772857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    if ((p == draw_info->text) || (bounds.yMin < metrics->bounds.y1))
1378aa83c2c383e62bd5342c0d38dc5f6e746998bde8cristy      metrics->bounds.y1=(double) bounds.yMin;
13792857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    if ((p == draw_info->text) || (bounds.xMax > metrics->bounds.x2))
1380aa83c2c383e62bd5342c0d38dc5f6e746998bde8cristy      metrics->bounds.x2=(double) bounds.xMax;
13812857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    if ((p == draw_info->text) || (bounds.yMax > metrics->bounds.y2))
1382aa83c2c383e62bd5342c0d38dc5f6e746998bde8cristy      metrics->bounds.y2=(double) bounds.yMax;
1383f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    if ((draw_info->stroke.alpha != TransparentAlpha) ||
1384f8f295fde25dd8b1a50470d53b641d5265c0871fcristy        (draw_info->stroke_pattern != (Image *) NULL))
1385f8f295fde25dd8b1a50470d53b641d5265c0871fcristy      {
1386f8f295fde25dd8b1a50470d53b641d5265c0871fcristy        if ((status != MagickFalse) && (draw_info->render != MagickFalse))
1387f8f295fde25dd8b1a50470d53b641d5265c0871fcristy          {
1388f8f295fde25dd8b1a50470d53b641d5265c0871fcristy            /*
1389f8f295fde25dd8b1a50470d53b641d5265c0871fcristy              Trace the glyph.
1390f8f295fde25dd8b1a50470d53b641d5265c0871fcristy            */
1391f8f295fde25dd8b1a50470d53b641d5265c0871fcristy            annotate_info->affine.tx=glyph.origin.x/64.0;
1392f8f295fde25dd8b1a50470d53b641d5265c0871fcristy            annotate_info->affine.ty=glyph.origin.y/64.0;
1393f8f295fde25dd8b1a50470d53b641d5265c0871fcristy            (void) FT_Outline_Decompose(&((FT_OutlineGlyph) glyph.image)->
1394f8f295fde25dd8b1a50470d53b641d5265c0871fcristy              outline,&OutlineMethods,annotate_info);
1395f8f295fde25dd8b1a50470d53b641d5265c0871fcristy          }
1396bd51246ae63047fa139606f6c6862ff989ab1fbdcristy        }
13972857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    FT_Vector_Transform(&glyph.origin,&affine);
13982857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    (void) FT_Glyph_Transform(glyph.image,&affine,&glyph.origin);
1399f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    ft_status=FT_Glyph_To_Bitmap(&glyph.image,ft_render_mode_normal,
14002857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      (FT_Vector *) NULL,MagickTrue);
1401f8f295fde25dd8b1a50470d53b641d5265c0871fcristy    if (ft_status != 0)
14022857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      continue;
14032857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    bitmap=(FT_BitmapGlyph) glyph.image;
14042857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    point.x=offset->x+bitmap->left;
14052f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy    if (bitmap->bitmap.pixel_mode == ft_pixel_mode_mono)
14062f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy      point.x=offset->x+(origin.x >> 6);
14072857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    point.y=offset->y-bitmap->top;
14082857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    if (draw_info->render != MagickFalse)
14092857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      {
14102857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy        CacheView
14112857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy          *image_view;
1412bd51246ae63047fa139606f6c6862ff989ab1fbdcristy
14132f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy        register unsigned char
14142f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy          *p;
14152f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy
14162857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy        /*
14172857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy          Rasterize the glyph.
14182857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy        */
141946ff2676b1044ea4101ac7a59b83289cd8f6cfdacristy        image_view=AcquireAuthenticCacheView(image,exception);
14202f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy        p=bitmap->bitmap.buffer;
1421bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (y=0; y < (ssize_t) bitmap->bitmap.rows; y++)
14222857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy        {
1423bd51246ae63047fa139606f6c6862ff989ab1fbdcristy          MagickBooleanType
14242857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            active,
14252857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            sync;
1426bd51246ae63047fa139606f6c6862ff989ab1fbdcristy
1427a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy          double
14282857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            fill_opacity;
14292857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy
1430101ab708b0574518ac5715da4d3915400e9df79acristy          PixelInfo
14312857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            fill_color;
14322857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy
14334c08aed51c5899665ade97263692328eea4af106cristy          register Quantum
14342857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            *restrict q;
14352857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy
14368815806717c3b3e2b4f8700b4cc18b751bd3c23fcristy          register ssize_t
14378815806717c3b3e2b4f8700b4cc18b751bd3c23fcristy            x;
14388815806717c3b3e2b4f8700b4cc18b751bd3c23fcristy
143973ce31bc9ca5fc03ff0cef499e58ab2973add52ccristy          ssize_t
14402f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy            n,
144173ce31bc9ca5fc03ff0cef499e58ab2973add52ccristy            x_offset,
144273ce31bc9ca5fc03ff0cef499e58ab2973add52ccristy            y_offset;
144373ce31bc9ca5fc03ff0cef499e58ab2973add52ccristy
14442857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy          if (status == MagickFalse)
14452857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            continue;
1446bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          x_offset=(ssize_t) ceil(point.x-0.5);
1447bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          y_offset=(ssize_t) ceil(point.y+y-0.5);
1448bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          if ((y_offset < 0) || (y_offset >= (ssize_t) image->rows))
14492857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            continue;
14504c08aed51c5899665ade97263692328eea4af106cristy          q=(Quantum *) NULL;
1451bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns))
14522857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            active=MagickFalse;
14532857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy          else
14542857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            {
14552857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy              q=GetCacheViewAuthenticPixels(image_view,x_offset,y_offset,
14562857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy                bitmap->bitmap.width,1,exception);
14574c08aed51c5899665ade97263692328eea4af106cristy              active=q != (Quantum *) NULL ? MagickTrue : MagickFalse;
14582857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            }
1459854209afe797f1a6ecec8679889302af4d4b0faccristy          n=y*bitmap->bitmap.pitch-1;
1460854209afe797f1a6ecec8679889302af4d4b0faccristy          for (x=0; x < (ssize_t) bitmap->bitmap.width; x++)
1461bd51246ae63047fa139606f6c6862ff989ab1fbdcristy          {
1462854209afe797f1a6ecec8679889302af4d4b0faccristy            n++;
14632857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            x_offset++;
14642f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy            if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns))
14653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
1466ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                q+=GetPixelChannels(image);
14672857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy                continue;
14683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
14692f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy            if (bitmap->bitmap.pixel_mode != ft_pixel_mode_mono)
1470a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy              fill_opacity=(double) (p[n])/(bitmap->bitmap.num_grays-1);
14712f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy            else
14722f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy              fill_opacity=((p[(x >> 3)+y*bitmap->bitmap.pitch] &
14732f5b5c7c0813cc6f696a4dfc00aaf62e2dfb2a23cristy                (1 << (~x & 0x07)))) == 0 ? 0.0 : 1.0;
14742857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            if (draw_info->text_antialias == MagickFalse)
14752857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy              fill_opacity=fill_opacity >= 0.5 ? 1.0 : 0.0;
14762857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            if (active == MagickFalse)
14772857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy              q=GetCacheViewAuthenticPixels(image_view,x_offset,y_offset,1,1,
14782857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy                exception);
14796193b86c0b59030b647a10c75f37ec82d73e3695cristy            if (q == (Quantum *) NULL)
14809c5171c13c7186088b10ec322e199f60e455a7e1cristy              continue;
1481ec061ec752ff58a96a5de680b18e43fb8beea7c0cristy            GetPixelInfo(image,&fill_color);
14822ed42f6d7c2245432767ea446742977ee87e963ccristy            (void) GetFillColor(draw_info,x_offset,y_offset,&fill_color,
14832ed42f6d7c2245432767ea446742977ee87e963ccristy              exception);
14844c08aed51c5899665ade97263692328eea4af106cristy            fill_opacity=fill_opacity*fill_color.alpha;
14854c08aed51c5899665ade97263692328eea4af106cristy            CompositePixelOver(image,&fill_color,fill_opacity,q,
14864c08aed51c5899665ade97263692328eea4af106cristy              GetPixelAlpha(image,q),q);
14872857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            if (active == MagickFalse)
14882857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy              {
14892857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy                sync=SyncCacheViewAuthenticPixels(image_view,exception);
14902857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy                if (sync == MagickFalse)
14912857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy                  status=MagickFalse;
14922857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy              }
1493ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy            q+=GetPixelChannels(image);
14943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
14952857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy          sync=SyncCacheViewAuthenticPixels(image_view,exception);
14962857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy          if (sync == MagickFalse)
14972857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy            status=MagickFalse;
14983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
14992857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy        image_view=DestroyCacheView(image_view);
15002857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      }
15012857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    if ((bitmap->left+bitmap->bitmap.width) > metrics->width)
15022857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy      metrics->width=bitmap->left+bitmap->bitmap.width;
1503aa83c2c383e62bd5342c0d38dc5f6e746998bde8cristy    if ((fabs(draw_info->interword_spacing) >= MagickEpsilon) &&
15042857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy        (IsUTFSpace(GetUTFCode(p)) != MagickFalse) &&
15052857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy        (IsUTFSpace(code) == MagickFalse))
150694b11835effe9f2ded8638e50db5fb7acd92ea0bcristy      origin.x+=(FT_Pos) (64.0*direction*draw_info->interword_spacing);
15072857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    else
150894b11835effe9f2ded8638e50db5fb7acd92ea0bcristy      origin.x+=(FT_Pos) (direction*face->glyph->advance.x);
1509aa83c2c383e62bd5342c0d38dc5f6e746998bde8cristy    metrics->origin.x=(double) origin.x;
1510aa83c2c383e62bd5342c0d38dc5f6e746998bde8cristy    metrics->origin.y=(double) origin.y;
1511bd5a96cd2b69f218f85a7adc306296a736f91a56cristy    if (last_glyph.id != 0)
1512bd5a96cd2b69f218f85a7adc306296a736f91a56cristy      FT_Done_Glyph(last_glyph.image);
15132857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    last_glyph=glyph;
15142857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    code=GetUTFCode(p);
15152857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy  }
15162857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy  if (utf8 != (unsigned char *) NULL)
15172857ffcd46fc4d091060c7e8aa9804f4b4d6efaacristy    utf8=(unsigned char *) RelinquishMagickMemory(utf8);
1518bd5a96cd2b69f218f85a7adc306296a736f91a56cristy  if (last_glyph.id != 0)
1519bd5a96cd2b69f218f85a7adc306296a736f91a56cristy    FT_Done_Glyph(last_glyph.image);
15204c08aed51c5899665ade97263692328eea4af106cristy  if ((draw_info->stroke.alpha != TransparentAlpha) ||
15213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (draw_info->stroke_pattern != (Image *) NULL))
15223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
1523f8f295fde25dd8b1a50470d53b641d5265c0871fcristy      if ((status != MagickFalse) && (draw_info->render != MagickFalse))
15243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
15253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
15263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Draw text stroke.
15273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
15283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->linejoin=RoundJoin;
15293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.tx=offset->x;
15303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          annotate_info->affine.ty=offset->y;
15313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) ConcatenateString(&annotate_info->primitive,"'");
1532018f07f7333b25743d0afff892450cebdb905c1acristy          (void) DrawImage(image,annotate_info,exception);
15333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
15343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
15353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
15363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine font metrics.
15373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
15383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  glyph.id=FT_Get_Char_Index(face,'_');
15393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  glyph.origin=origin;
1540f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  ft_status=FT_Load_Glyph(face,glyph.id,flags);
1541f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  if (ft_status == 0)
15423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
1543f8f295fde25dd8b1a50470d53b641d5265c0871fcristy      ft_status=FT_Get_Glyph(face->glyph,&glyph.image);
1544f8f295fde25dd8b1a50470d53b641d5265c0871fcristy      if (ft_status == 0)
15453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
1546f8f295fde25dd8b1a50470d53b641d5265c0871fcristy          ft_status=FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph.image)->
1547f8f295fde25dd8b1a50470d53b641d5265c0871fcristy            outline,&bounds);
1548f8f295fde25dd8b1a50470d53b641d5265c0871fcristy          if (ft_status == 0)
15493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
15503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              FT_Vector_Transform(&glyph.origin,&affine);
15513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) FT_Glyph_Transform(glyph.image,&affine,&glyph.origin);
1552f8f295fde25dd8b1a50470d53b641d5265c0871fcristy              ft_status=FT_Glyph_To_Bitmap(&glyph.image,ft_render_mode_normal,
15533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (FT_Vector *) NULL,MagickTrue);
15543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bitmap=(FT_BitmapGlyph) glyph.image;
15553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (bitmap->left > metrics->width)
15563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                metrics->width=bitmap->left;
15573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
15583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
1559e2c81adf02cbe4bb92991389437a2a1daf8ed313cristy      FT_Done_Glyph(glyph.image);
15603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
15613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->width-=metrics->bounds.x1/64.0;
156255cb9f15b804f98ac7d37615b8f5f8888fc792f4cristy  metrics->width+=annotate_info->stroke_width;
15633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.x1/=64.0;
15643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.y1/=64.0;
15653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.x2/=64.0;
15663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.y2/=64.0;
15673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->origin.x/=64.0;
15683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->origin.y/=64.0;
15693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
15703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Relinquish resources.
15713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
15723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=DestroyDrawInfo(annotate_info);
15733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) FT_Done_Face(face);
15743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) FT_Done_FreeType(library);
1575f8f295fde25dd8b1a50470d53b641d5265c0871fcristy  return(status);
15763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
15773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
15783ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
15793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *magick_unused(encoding),const PointInfo *offset,
15805cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  TypeMetric *metrics,ExceptionInfo *exception)
15813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
15825cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  (void) ThrowMagickException(exception,GetMagickModule(),
1583e5b39652d8d21bc3940d83b8d6088d4070a8a34aanthony    MissingDelegateWarning,"DelegateLibrarySupportNotBuiltIn","'%s' (Freetype)",
1584ee08182aae410ed78e712a845bee7e51eedf73f3cristy    draw_info->font != (char *) NULL ? draw_info->font : "none");
1585e3b062a2f84bdc16645c3ef9de153b2c6f44d04ccristy  return(RenderPostscript(image,draw_info,offset,metrics,exception));
15863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
15873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
15883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
15893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
15903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   R e n d e r P o s t s c r i p t                                           %
15953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  RenderPostscript() renders text on the image with a Postscript font.  It
16013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  also returns the bounding box of the text relative to the image.
16023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the RenderPostscript method is:
16043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType RenderPostscript(Image *image,DrawInfo *draw_info,
16065cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%        const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
16073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
16093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
16113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o draw_info: the draw info.
16133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o offset: (x,y) location of text relative to image.
16153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o metrics: bounding box of text.
16173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16185cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%    o exception: return any errors or warnings in this structure.
16195cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%
16203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
16213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16223ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic inline size_t MagickMin(const size_t x,const size_t y)
16233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
16243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (x < y)
16253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(x);
16263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(y);
16273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
16283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16293ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic char *EscapeParenthesis(const char *text)
16303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
16313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
16323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *buffer;
16333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register char
16353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
16363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1637bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
16383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
16393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_t
16413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    escapes;
16423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  escapes=0;
16443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  buffer=AcquireString(text);
16453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=buffer;
1646bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  for (i=0; i < (ssize_t) MagickMin(strlen(text),MaxTextExtent-escapes-1); i++)
16473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
16483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((text[i] == '(') || (text[i] == ')'))
16493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
16503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *p++='\\';
16513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        escapes++;
16523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
16533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p++=text[i];
16543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
16553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *p='\0';
16563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(buffer);
16573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
16583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16593ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType RenderPostscript(Image *image,
16605cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
16615cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  ExceptionInfo *exception)
16623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
16633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
16643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    filename[MaxTextExtent],
16653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    geometry[MaxTextExtent],
16663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *text;
16673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FILE
16693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *file;
16703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
16723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_image;
16733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ImageInfo
16753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_info;
16763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
16783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unique_file;
16793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
16813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    identity;
16823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  PointInfo
16843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    extent,
16853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    point,
16863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resolution;
16873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1688bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
16893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
16903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
169114d712974a2c2cd2aebf8db11c7ca686bb67596fcristy  size_t
169214d712974a2c2cd2aebf8db11c7ca686bb67596fcristy    length;
169314d712974a2c2cd2aebf8db11c7ca686bb67596fcristy
16949d314ff2c17a77996c05413c2013880387e50f0ecristy  ssize_t
16959d314ff2c17a77996c05413c2013880387e50f0ecristy    y;
16969d314ff2c17a77996c05413c2013880387e50f0ecristy
16973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
16983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Render label with a Postscript font.
16993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
17003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
17013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),
1702e7f5109f30fc7242d04a26174a9138483dda5b6acristy      "Font %s; pointsize %g",draw_info->font != (char *) NULL ?
17033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      draw_info->font : "none",draw_info->pointsize);
17043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  file=(FILE *) NULL;
17053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unique_file=AcquireUniqueFileResource(filename);
17063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (unique_file != -1)
17073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    file=fdopen(unique_file,"wb");
17083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((unique_file == -1) || (file == (FILE *) NULL))
17093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
17105cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      ThrowFileException(exception,FileOpenError,"UnableToOpenFile",filename);
17113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
17123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
1713b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"%%!PS-Adobe-3.0\n");
1714b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"/ReencodeType\n");
1715b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"{\n");
1716b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"  findfont dup length\n");
1717b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,
17183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "  dict begin { 1 index /FID ne {def} {pop pop} ifelse } forall\n");
1719b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,
17203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "  /Encoding ISOLatin1Encoding def currentdict end definefont pop\n");
1721b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"} bind def\n");
17223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
17233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Sample to compute bounding box.
17243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
1725aa83c2c383e62bd5342c0d38dc5f6e746998bde8cristy  identity=(fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) &&
1726aa83c2c383e62bd5342c0d38dc5f6e746998bde8cristy    (fabs(draw_info->affine.rx) < MagickEpsilon) &&
1727aa83c2c383e62bd5342c0d38dc5f6e746998bde8cristy    (fabs(draw_info->affine.ry) < MagickEpsilon) ? MagickTrue : MagickFalse;
17283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  extent.x=0.0;
17293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  extent.y=0.0;
173014d712974a2c2cd2aebf8db11c7ca686bb67596fcristy  length=strlen(draw_info->text);
173114d712974a2c2cd2aebf8db11c7ca686bb67596fcristy  for (i=0; i <= (ssize_t) (length+2); i++)
17323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
17333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    point.x=fabs(draw_info->affine.sx*i*draw_info->pointsize+
17343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      draw_info->affine.ry*2.0*draw_info->pointsize);
17353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    point.y=fabs(draw_info->affine.rx*i*draw_info->pointsize+
17363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      draw_info->affine.sy*2.0*draw_info->pointsize);
17373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (point.x > extent.x)
17383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      extent.x=point.x;
17393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (point.y > extent.y)
17403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      extent.y=point.y;
17413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
1742b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"%g %g moveto\n",identity  != MagickFalse ? 0.0 :
17433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    extent.x/2.0,extent.y/2.0);
1744b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"%g %g scale\n",draw_info->pointsize,
17453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_info->pointsize);
17463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((draw_info->font == (char *) NULL) || (*draw_info->font == '\0') ||
17473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (strchr(draw_info->font,'/') != (char *) NULL))
1748b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,
17493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "/Times-Roman-ISO dup /Times-Roman ReencodeType findfont setfont\n");
17503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
17511e604812fad85bb96f757a2393015ae3d061c39acristy    (void) FormatLocaleFile(file,
17521e604812fad85bb96f757a2393015ae3d061c39acristy      "/%s-ISO dup /%s ReencodeType findfont setfont\n",draw_info->font,
17531e604812fad85bb96f757a2393015ae3d061c39acristy      draw_info->font);
1754b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"[%g %g %g %g 0 0] concat\n",
17558cd5b3193212b4aebce08c4e7afbb66b09778029cristy    draw_info->affine.sx,-draw_info->affine.rx,-draw_info->affine.ry,
17568cd5b3193212b4aebce08c4e7afbb66b09778029cristy    draw_info->affine.sy);
17573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  text=EscapeParenthesis(draw_info->text);
17583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (identity == MagickFalse)
17591e604812fad85bb96f757a2393015ae3d061c39acristy    (void) FormatLocaleFile(file,"(%s) stringwidth pop -0.5 mul -0.5 rmoveto\n",
17601e604812fad85bb96f757a2393015ae3d061c39acristy      text);
1761b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"(%s) show\n",text);
17623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  text=DestroyString(text);
1763b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"showpage\n");
17643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) fclose(file);
1765b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(geometry,MaxTextExtent,"%.20gx%.20g+0+0!",
1766e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy    floor(extent.x+0.5),floor(extent.y+0.5));
17673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=AcquireImageInfo();
1768b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(annotate_info->filename,MaxTextExtent,"ps:%s",
17693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    filename);
17703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CloneString(&annotate_info->page,geometry);
17713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->density != (char *) NULL)
17723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) CloneString(&annotate_info->density,draw_info->density);
17733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->antialias=draw_info->text_antialias;
17745cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  annotate_image=ReadImage(annotate_info,exception);
17755cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy  CatchException(exception);
17763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info=DestroyImageInfo(annotate_info);
17773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) RelinquishUniqueFileResource(filename);
17783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_image == (Image *) NULL)
17793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
178055cb9f15b804f98ac7d37615b8f5f8888fc792f4cristy  (void) NegateImage(annotate_image,MagickFalse,exception);
17813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resolution.x=DefaultResolution;
17823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resolution.y=DefaultResolution;
17833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->density != (char *) NULL)
17843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
17853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      GeometryInfo
17863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        geometry_info;
17873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
17883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickStatusType
17893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        flags;
17903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
17913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      flags=ParseGeometry(draw_info->density,&geometry_info);
17923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resolution.x=geometry_info.rho;
17933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resolution.y=geometry_info.sigma;
17943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((flags & SigmaValue) == 0)
17953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resolution.y=resolution.x;
17963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
17973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (identity == MagickFalse)
1798e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy    (void) TransformImage(&annotate_image,"0x0",(char *) NULL,exception);
17993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
18003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
18013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      RectangleInfo
18023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        crop_info;
18033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18045cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy      crop_info=GetImageBoundingBox(annotate_image,exception);
1805bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.height=(size_t) ((resolution.y/DefaultResolution)*
18063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ExpandAffine(&draw_info->affine)*draw_info->pointsize+0.5);
1807bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.y=(ssize_t) ceil((resolution.y/DefaultResolution)*extent.y/8.0-
180806609eef311d5af857f65f20ed3af6860c1994becristy        0.5);
1809b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleString(geometry,MaxTextExtent,
18106d8abbae64da926477182d86d5007bc2c5a8b979cristy        "%.20gx%.20g%+.20g%+.20g",(double) crop_info.width,(double)
1811e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy        crop_info.height,(double) crop_info.x,(double) crop_info.y);
1812e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy      (void) TransformImage(&annotate_image,geometry,(char *) NULL,exception);
18133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
18143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->pixels_per_em.x=(resolution.y/DefaultResolution)*
18153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ExpandAffine(&draw_info->affine)*draw_info->pointsize;
18163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->pixels_per_em.y=metrics->pixels_per_em.x;
18173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->ascent=metrics->pixels_per_em.x;
18183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->descent=metrics->pixels_per_em.y/-5.0;
18193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->width=(double) annotate_image->columns/
18203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ExpandAffine(&draw_info->affine);
18213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->height=1.152*metrics->pixels_per_em.x;
18223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->max_advance=metrics->pixels_per_em.x;
18233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.x1=0.0;
18243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.y1=metrics->descent;
18253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.x2=metrics->ascent+metrics->descent;
18263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->bounds.y2=metrics->ascent+metrics->descent;
18273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->underline_position=(-2.0);
18283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  metrics->underline_thickness=1.0;
18293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->render == MagickFalse)
18303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
18313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      annotate_image=DestroyImage(annotate_image);
18323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickTrue);
18333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
18344c08aed51c5899665ade97263692328eea4af106cristy  if (draw_info->fill.alpha != TransparentAlpha)
18353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
1836bd65948def60e897a2641d9503470945c304f46fcristy      CacheView
1837bd65948def60e897a2641d9503470945c304f46fcristy        *annotate_view;
1838bd65948def60e897a2641d9503470945c304f46fcristy
18393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickBooleanType
18403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sync;
18413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1842101ab708b0574518ac5715da4d3915400e9df79acristy      PixelInfo
18433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        fill_color;
18443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
18463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Render fill color.
18473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
184817f11b056210f082a6d0e54ac5d68e6d72fa76b2cristy      if (image->alpha_trait == UndefinedPixelTrait)
184963240888c3975789a09c2494a4654b523931df96cristy        (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
185017f11b056210f082a6d0e54ac5d68e6d72fa76b2cristy      if (annotate_image->alpha_trait == UndefinedPixelTrait)
185163240888c3975789a09c2494a4654b523931df96cristy        (void) SetImageAlphaChannel(annotate_image,OpaqueAlphaChannel,
185263240888c3975789a09c2494a4654b523931df96cristy          exception);
18533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      fill_color=draw_info->fill;
185446ff2676b1044ea4101ac7a59b83289cd8f6cfdacristy      annotate_view=AcquireAuthenticCacheView(annotate_image,exception);
1855bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      for (y=0; y < (ssize_t) annotate_image->rows; y++)
18563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
1857bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        register ssize_t
18583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x;
18593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18604c08aed51c5899665ade97263692328eea4af106cristy        register Quantum
1861c47d1f8ecfe7d04f0f003cca0fe175658bbf0fb2cristy          *restrict q;
18623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q=GetCacheViewAuthenticPixels(annotate_view,0,y,annotate_image->columns,
18643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          1,exception);
18656193b86c0b59030b647a10c75f37ec82d73e3695cristy        if (q == (Quantum *) NULL)
18663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
1867bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (x=0; x < (ssize_t) annotate_image->columns; x++)
18683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
18692ed42f6d7c2245432767ea446742977ee87e963ccristy          (void) GetFillColor(draw_info,x,y,&fill_color,exception);
187055cb9f15b804f98ac7d37615b8f5f8888fc792f4cristy          SetPixelAlpha(annotate_image,ClampToQuantum((((double) QuantumScale*
187155cb9f15b804f98ac7d37615b8f5f8888fc792f4cristy            GetPixelIntensity(annotate_image,q)*fill_color.alpha))),q);
18724c08aed51c5899665ade97263692328eea4af106cristy          SetPixelRed(annotate_image,fill_color.red,q);
18734c08aed51c5899665ade97263692328eea4af106cristy          SetPixelGreen(annotate_image,fill_color.green,q);
18744c08aed51c5899665ade97263692328eea4af106cristy          SetPixelBlue(annotate_image,fill_color.blue,q);
1875ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy          q+=GetPixelChannels(annotate_image);
18763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
18773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sync=SyncCacheViewAuthenticPixels(annotate_view,exception);
18783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (sync == MagickFalse)
18793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
18803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
18813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      annotate_view=DestroyCacheView(annotate_view);
188239172408bad7ef2ef00a815fa9abf9979e7857cbcristy      (void) CompositeImage(image,annotate_image,OverCompositeOp,MagickTrue,
1883bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        (ssize_t) ceil(offset->x-0.5),(ssize_t) ceil(offset->y-(metrics->ascent+
1884e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy        metrics->descent)-0.5),exception);
18853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
18863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_image=DestroyImage(annotate_image);
18873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
18883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
18893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
18913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   R e n d e r X 1 1                                                         %
18963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  RenderX11() renders text on the image with an X11 font.  It also returns the
19023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  bounding box of the text relative to the image.
19033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the RenderX11 method is:
19053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType RenderX11(Image *image,DrawInfo *draw_info,
19075cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%        const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
19083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
19103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
19123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o draw_info: the draw info.
19143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o offset: (x,y) location of text relative to image.
19163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o metrics: bounding box of text.
19183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19195cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%    o exception: return any errors or warnings in this structure.
19205cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy%
19213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1922cc168c2dcad169c22f123761f2f53d867fb2f149cristystatic MagickBooleanType RenderX11(Image *image,const DrawInfo *draw_info,
1923cc168c2dcad169c22f123761f2f53d867fb2f149cristy  const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
19243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
19253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
19263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
19273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1928d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy  if (annotate_semaphore == (SemaphoreInfo *) NULL)
192904b11db5504ecdf205114ae7e9e68774a1ff0b9bcristy    ActivateSemaphoreInfo(&annotate_semaphore);
1930d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy  LockSemaphoreInfo(annotate_semaphore);
1931534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  status=XRenderImage(image,draw_info,offset,metrics,exception);
1932d7ecaca521e2840f1308b758f7b3a3a9fd2dce38cristy  UnlockSemaphoreInfo(annotate_semaphore);
1933534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  return(status);
19343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
1935