2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Return A Preview For A TrueType or Postscript Font %
20 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/draw.h"
46 #include "magick/exception.h"
47 #include "magick/exception-private.h"
48 #include "magick/image.h"
49 #include "magick/image-private.h"
50 #include "magick/list.h"
51 #include "magick/magick.h"
52 #include "magick/memory_.h"
53 #include "magick/quantum-private.h"
54 #include "magick/static.h"
55 #include "magick/string_.h"
56 #include "magick/module.h"
57 #include "magick/type.h"
58 #include "wand/MagickWand.h"
59 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
60 #if defined(MAGICKCORE_HAVE_FT2BUILD_H)
61 # include <ft2build.h>
63 #if defined(FT_FREETYPE_H)
64 # include FT_FREETYPE_H
66 # include <freetype/freetype.h>
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 % IsPFA()() returns MagickTrue if the image format type, identified by the
82 % magick string, is PFA.
84 % The format of the IsPFA method is:
86 % MagickBooleanType IsPFA(const unsigned char *magick,const size_t length)
88 % A description of each parameter follows:
90 % o magick: compare image format pattern against these bytes.
92 % o length: Specifies the length of the magick string.
96 static MagickBooleanType IsPFA(const unsigned char *magick,const size_t length)
100 if (LocaleNCompare((char *) magick,"%!PS-AdobeFont",14) == 0)
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 % IsTTF()() returns MagickTrue if the image format type, identified by the
117 % magick string, is TTF.
119 % The format of the IsTTF method is:
121 % MagickBooleanType IsTTF(const unsigned char *magick,const size_t length)
123 % A description of each parameter follows:
125 % o magick: compare image format pattern against these bytes.
127 % o length: Specifies the length of the magick string.
131 static MagickBooleanType IsTTF(const unsigned char *magick,const size_t length)
135 if (((int) magick[0] == 0x00) && ((int) magick[1] == 0x01) &&
136 ((int) magick[2] == 0x00) && ((int) magick[3] == 0x00) &&
137 ((int) magick[4] == 0x00))
142 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 % R e a d T T F I m a g e %
152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 % ReadTTFImage() reads a TrueType font file and returns it. It
155 % allocates the memory necessary for the new Image structure and returns a
156 % pointer to the new image.
158 % The format of the ReadTTFImage method is:
160 % Image *ReadTTFImage(const ImageInfo *image_info,ExceptionInfo *exception)
162 % A description of each parameter follows:
164 % o image_info: the image info.
166 % o exception: return any errors or warnings in this structure.
169 static Image *ReadTTFImage(const ImageInfo *image_info,ExceptionInfo *exception)
172 buffer[MaxTextExtent],
177 "abcdefghijklmnopqrstuvwxyz\n"
178 "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
179 "0123456789.:,;(*!?}^)#${%^&-+@\n";
209 assert(image_info != (const ImageInfo *) NULL);
210 assert(image_info->signature == MagickSignature);
211 if (image_info->debug != MagickFalse)
212 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
213 image_info->filename);
214 assert(exception != (ExceptionInfo *) NULL);
215 assert(exception->signature == MagickSignature);
216 image=AcquireImage(image_info);
219 type_info=GetTypeInfo(image_info->filename,exception);
220 if ((type_info != (const TypeInfo *) NULL) &&
221 (type_info->glyphs != (char *) NULL))
222 (void) CopyMagickString(image->filename,type_info->glyphs,MaxTextExtent);
223 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
224 if (status == MagickFalse)
226 image=DestroyImageList(image);
227 return((Image *) NULL);
230 Color canvas with background color
232 background_color=image_info->background_color;
233 for (y=0; y < (ssize_t) image->rows; y++)
235 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
236 if (q == (PixelPacket *) NULL)
238 for (x=0; x < (ssize_t) image->columns; x++)
239 *q++=background_color;
240 if (SyncAuthenticPixels(image,exception) == MagickFalse)
243 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
244 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
246 Prepare drawing commands
249 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
250 draw_info->font=AcquireString(image->filename);
251 ConcatenateString(&draw_info->primitive,"push graphic-context\n");
252 (void) FormatMagickString(buffer,MaxTextExtent," viewbox 0 0 %.20g %.20g\n",
253 (double) image->columns,(double) image->rows);
254 ConcatenateString(&draw_info->primitive,buffer);
255 ConcatenateString(&draw_info->primitive," font-size 18\n");
256 (void) FormatMagickString(buffer,MaxTextExtent," text 10,%.20g '",(double) y);
257 ConcatenateString(&draw_info->primitive,buffer);
258 text=EscapeString(Text,'"');
259 ConcatenateString(&draw_info->primitive,text);
260 text=DestroyString(text);
261 (void) FormatMagickString(buffer,MaxTextExtent,"'\n");
262 ConcatenateString(&draw_info->primitive,buffer);
263 y+=20*(ssize_t) MultilineCensus((char *) Text)+20;
264 for (i=12; i <= 72; i+=6)
267 ConcatenateString(&draw_info->primitive," font-size 18\n");
268 (void) FormatMagickString(buffer,MaxTextExtent," text 10,%.20g '%.20g'\n",
269 (double) y,(double) i);
270 ConcatenateString(&draw_info->primitive,buffer);
271 (void) FormatMagickString(buffer,MaxTextExtent," font-size %.20g\n",
273 ConcatenateString(&draw_info->primitive,buffer);
274 (void) FormatMagickString(buffer,MaxTextExtent," text 50,%.20g "
275 "'That which does not destroy me, only makes me stronger.'\n",(double) y);
276 ConcatenateString(&draw_info->primitive,buffer);
280 ConcatenateString(&draw_info->primitive,"pop graphic-context");
281 (void) DrawImage(image,draw_info);
283 Relinquish resources.
285 draw_info=DestroyDrawInfo(draw_info);
286 (void) CloseBlob(image);
287 return(GetFirstImageInList(image));
289 #endif /* MAGICKCORE_FREETYPE_DELEGATE */
292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 % R e g i s t e r T T F I m a g e %
300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 % RegisterTTFImage() adds attributes for the TTF image format to
303 % the list of supported formats. The attributes include the image format
304 % tag, a method to read and/or write the format, whether the format
305 % supports the saving of more than one frame to the same file or blob,
306 % whether the format supports native in-memory I/O, and a brief
307 % description of the format.
309 % The format of the RegisterTTFImage method is:
311 % size_t RegisterTTFImage(void)
314 ModuleExport size_t RegisterTTFImage(void)
317 version[MaxTextExtent];
323 #if defined(FREETYPE_MAJOR) && defined(FREETYPE_MINOR) && defined(FREETYPE_PATCH)
324 (void) FormatMagickString(version,MaxTextExtent,"Freetype %d.%d.%d",
325 FREETYPE_MAJOR,FREETYPE_MINOR,FREETYPE_PATCH);
327 entry=SetMagickInfo("DFONT");
328 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
329 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
331 entry->magick=(IsImageFormatHandler *) IsTTF;
332 entry->adjoin=MagickFalse;
333 entry->description=ConstantString("Multi-face font package");
334 if (*version != '\0')
335 entry->version=ConstantString(version);
336 entry->module=ConstantString("TTF");
337 (void) RegisterMagickInfo(entry);
338 entry=SetMagickInfo("PFA");
339 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
340 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
342 entry->magick=(IsImageFormatHandler *) IsPFA;
343 entry->adjoin=MagickFalse;
344 entry->description=ConstantString("Postscript Type 1 font (ASCII)");
345 if (*version != '\0')
346 entry->version=ConstantString(version);
347 entry->module=ConstantString("TTF");
348 (void) RegisterMagickInfo(entry);
349 entry=SetMagickInfo("PFB");
350 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
351 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
353 entry->magick=(IsImageFormatHandler *) IsPFA;
354 entry->adjoin=MagickFalse;
355 entry->description=ConstantString("Postscript Type 1 font (binary)");
356 if (*version != '\0')
357 entry->version=ConstantString(version);
358 entry->module=ConstantString("TTF");
359 (void) RegisterMagickInfo(entry);
360 entry=SetMagickInfo("OTF");
361 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
362 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
364 entry->magick=(IsImageFormatHandler *) IsTTF;
365 entry->adjoin=MagickFalse;
366 entry->description=ConstantString("Open Type font");
367 if (*version != '\0')
368 entry->version=ConstantString(version);
369 entry->module=ConstantString("TTF");
370 (void) RegisterMagickInfo(entry);
371 entry=SetMagickInfo("TTC");
372 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
373 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
375 entry->magick=(IsImageFormatHandler *) IsTTF;
376 entry->adjoin=MagickFalse;
377 entry->description=ConstantString("TrueType font collection");
378 if (*version != '\0')
379 entry->version=ConstantString(version);
380 entry->module=ConstantString("TTF");
381 (void) RegisterMagickInfo(entry);
382 entry=SetMagickInfo("TTF");
383 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
384 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
386 entry->magick=(IsImageFormatHandler *) IsTTF;
387 entry->adjoin=MagickFalse;
388 entry->description=ConstantString("TrueType font");
389 if (*version != '\0')
390 entry->version=ConstantString(version);
391 entry->module=ConstantString("TTF");
392 (void) RegisterMagickInfo(entry);
393 return(MagickImageCoderSignature);
397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401 % U n r e g i s t e r T T F I m a g e %
405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407 % UnregisterTTFImage() removes format registrations made by the
408 % TTF module from the list of supported formats.
410 % The format of the UnregisterTTFImage method is:
412 % UnregisterTTFImage(void)
415 ModuleExport void UnregisterTTFImage(void)
417 (void) UnregisterMagickInfo("TTF");
418 (void) UnregisterMagickInfo("TTC");
419 (void) UnregisterMagickInfo("OTF");
420 (void) UnregisterMagickInfo("PFA");
421 (void) UnregisterMagickInfo("PFB");
422 (void) UnregisterMagickInfo("PFA");
423 (void) UnregisterMagickInfo("DFONT");