2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Return A Preview For A TrueType or Postscript Font %
20 % Copyright 1999-2015 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 "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/draw.h"
46 #include "MagickCore/exception.h"
47 #include "MagickCore/exception-private.h"
48 #include "MagickCore/image.h"
49 #include "MagickCore/image-private.h"
50 #include "MagickCore/list.h"
51 #include "MagickCore/magick.h"
52 #include "MagickCore/memory_.h"
53 #include "MagickCore/quantum-private.h"
54 #include "MagickCore/static.h"
55 #include "MagickCore/string_.h"
56 #include "MagickCore/module.h"
57 #include "MagickCore/type.h"
58 #include "MagickWand/MagickWand.h"
59 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
61 #if defined(FT_FREETYPE_H)
62 # include FT_FREETYPE_H
64 # include <freetype/freetype.h>
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % IsPFA()() returns MagickTrue if the image format type, identified by the
80 % magick string, is PFA.
82 % The format of the IsPFA method is:
84 % MagickBooleanType IsPFA(const unsigned char *magick,const size_t length)
86 % A description of each parameter follows:
88 % o magick: compare image format pattern against these bytes.
90 % o length: Specifies the length of the magick string.
94 static MagickBooleanType IsPFA(const unsigned char *magick,const size_t length)
98 if (LocaleNCompare((char *) magick,"%!PS-AdobeFont",14) == 0)
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 % IsTTF()() returns MagickTrue if the image format type, identified by the
115 % magick string, is TTF.
117 % The format of the IsTTF method is:
119 % MagickBooleanType IsTTF(const unsigned char *magick,const size_t length)
121 % A description of each parameter follows:
123 % o magick: compare image format pattern against these bytes.
125 % o length: Specifies the length of the magick string.
129 static MagickBooleanType IsTTF(const unsigned char *magick,const size_t length)
133 if (((int) magick[0] == 0x00) && ((int) magick[1] == 0x01) &&
134 ((int) magick[2] == 0x00) && ((int) magick[3] == 0x00) &&
135 ((int) magick[4] == 0x00))
140 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 % R e a d T T F I m a g e %
150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 % ReadTTFImage() reads a TrueType font file and returns it. It
153 % allocates the memory necessary for the new Image structure and returns a
154 % pointer to the new image.
156 % The format of the ReadTTFImage method is:
158 % Image *ReadTTFImage(const ImageInfo *image_info,ExceptionInfo *exception)
160 % A description of each parameter follows:
162 % o image_info: the image info.
164 % o exception: return any errors or warnings in this structure.
167 static Image *ReadTTFImage(const ImageInfo *image_info,ExceptionInfo *exception)
170 buffer[MagickPathExtent],
175 "abcdefghijklmnopqrstuvwxyz\n"
176 "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
177 "0123456789.:,;(*!?}^)#${%^&-+@\n";
207 assert(image_info != (const ImageInfo *) NULL);
208 assert(image_info->signature == MagickCoreSignature);
209 if (image_info->debug != MagickFalse)
210 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
211 image_info->filename);
212 assert(exception != (ExceptionInfo *) NULL);
213 assert(exception->signature == MagickCoreSignature);
214 image=AcquireImage(image_info,exception);
217 type_info=GetTypeInfo(image_info->filename,exception);
218 if ((type_info != (const TypeInfo *) NULL) &&
219 (type_info->glyphs != (char *) NULL))
220 (void) CopyMagickString(image->filename,type_info->glyphs,MagickPathExtent);
221 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
222 if (status == MagickFalse)
224 image=DestroyImageList(image);
225 return((Image *) NULL);
227 status=SetImageExtent(image,image->columns,image->rows,exception);
228 if (status == MagickFalse)
229 return(DestroyImageList(image));
231 Color canvas with background color
233 background_color=image_info->background_color;
234 for (y=0; y < (ssize_t) image->rows; y++)
236 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
237 if (q == (Quantum *) NULL)
239 for (x=0; x < (ssize_t) image->columns; x++)
241 SetPixelViaPixelInfo(image,&background_color,q);
242 q+=GetPixelChannels(image);
244 if (SyncAuthenticPixels(image,exception) == MagickFalse)
247 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
248 (void) CopyMagickString(image->filename,image_info->filename,MagickPathExtent);
250 Prepare drawing commands
253 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
254 draw_info->font=AcquireString(image->filename);
255 ConcatenateString(&draw_info->primitive,"push graphic-context\n");
256 (void) FormatLocaleString(buffer,MagickPathExtent," viewbox 0 0 %.20g %.20g\n",
257 (double) image->columns,(double) image->rows);
258 ConcatenateString(&draw_info->primitive,buffer);
259 ConcatenateString(&draw_info->primitive," font-size 18\n");
260 (void) FormatLocaleString(buffer,MagickPathExtent," text 10,%.20g '",(double) y);
261 ConcatenateString(&draw_info->primitive,buffer);
262 text=EscapeString(Text,'"');
263 ConcatenateString(&draw_info->primitive,text);
264 text=DestroyString(text);
265 (void) FormatLocaleString(buffer,MagickPathExtent,"'\n");
266 ConcatenateString(&draw_info->primitive,buffer);
267 y+=20*(ssize_t) MultilineCensus((char *) Text)+20;
268 for (i=12; i <= 72; i+=6)
271 ConcatenateString(&draw_info->primitive," font-size 18\n");
272 (void) FormatLocaleString(buffer,MagickPathExtent," text 10,%.20g '%.20g'\n",
273 (double) y,(double) i);
274 ConcatenateString(&draw_info->primitive,buffer);
275 (void) FormatLocaleString(buffer,MagickPathExtent," font-size %.20g\n",
277 ConcatenateString(&draw_info->primitive,buffer);
278 (void) FormatLocaleString(buffer,MagickPathExtent," text 50,%.20g "
279 "'That which does not destroy me, only makes me stronger.'\n",(double) y);
280 ConcatenateString(&draw_info->primitive,buffer);
284 ConcatenateString(&draw_info->primitive,"pop graphic-context");
285 (void) DrawImage(image,draw_info,exception);
287 Relinquish resources.
289 draw_info=DestroyDrawInfo(draw_info);
290 (void) CloseBlob(image);
291 return(GetFirstImageInList(image));
293 #endif /* MAGICKCORE_FREETYPE_DELEGATE */
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 % R e g i s t e r T T F I m a g e %
304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 % RegisterTTFImage() adds attributes for the TTF image format to
307 % the list of supported formats. The attributes include the image format
308 % tag, a method to read and/or write the format, whether the format
309 % supports the saving of more than one frame to the same file or blob,
310 % whether the format supports native in-memory I/O, and a brief
311 % description of the format.
313 % The format of the RegisterTTFImage method is:
315 % size_t RegisterTTFImage(void)
318 ModuleExport size_t RegisterTTFImage(void)
321 version[MagickPathExtent];
327 #if defined(FREETYPE_MAJOR) && defined(FREETYPE_MINOR) && defined(FREETYPE_PATCH)
328 (void) FormatLocaleString(version,MagickPathExtent,"Freetype %d.%d.%d",
329 FREETYPE_MAJOR,FREETYPE_MINOR,FREETYPE_PATCH);
331 entry=AcquireMagickInfo("TTF","DFONT","Multi-face font package");
332 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
333 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
335 entry->magick=(IsImageFormatHandler *) IsTTF;
336 entry->flags^=CoderAdjoinFlag;
337 if (*version != '\0')
338 entry->version=ConstantString(version);
339 (void) RegisterMagickInfo(entry);
340 entry=AcquireMagickInfo("TTF","PFA","Postscript Type 1 font (ASCII)");
341 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
342 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
344 entry->magick=(IsImageFormatHandler *) IsPFA;
345 entry->flags^=CoderAdjoinFlag;
346 if (*version != '\0')
347 entry->version=ConstantString(version);
348 (void) RegisterMagickInfo(entry);
349 entry=AcquireMagickInfo("TTF","PFB","Postscript Type 1 font (binary)");
350 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
351 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
353 entry->magick=(IsImageFormatHandler *) IsPFA;
354 entry->flags^=CoderAdjoinFlag;
355 if (*version != '\0')
356 entry->version=ConstantString(version);
357 (void) RegisterMagickInfo(entry);
358 entry=AcquireMagickInfo("TTF","OTF","Open Type font");
359 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
360 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
362 entry->magick=(IsImageFormatHandler *) IsTTF;
363 entry->flags^=CoderAdjoinFlag;
364 if (*version != '\0')
365 entry->version=ConstantString(version);
366 (void) RegisterMagickInfo(entry);
367 entry=AcquireMagickInfo("TTF","TTC","TrueType font collection");
368 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
369 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
371 entry->magick=(IsImageFormatHandler *) IsTTF;
372 entry->flags^=CoderAdjoinFlag;
373 if (*version != '\0')
374 entry->version=ConstantString(version);
375 (void) RegisterMagickInfo(entry);
376 entry=AcquireMagickInfo("TTF","TTF","TrueType font");
377 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
378 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
380 entry->magick=(IsImageFormatHandler *) IsTTF;
381 entry->flags^=CoderAdjoinFlag;
382 if (*version != '\0')
383 entry->version=ConstantString(version);
384 (void) RegisterMagickInfo(entry);
385 return(MagickImageCoderSignature);
389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393 % U n r e g i s t e r T T F I m a g e %
397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
399 % UnregisterTTFImage() removes format registrations made by the
400 % TTF module from the list of supported formats.
402 % The format of the UnregisterTTFImage method is:
404 % UnregisterTTFImage(void)
407 ModuleExport void UnregisterTTFImage(void)
409 (void) UnregisterMagickInfo("TTF");
410 (void) UnregisterMagickInfo("TTC");
411 (void) UnregisterMagickInfo("OTF");
412 (void) UnregisterMagickInfo("PFA");
413 (void) UnregisterMagickInfo("PFB");
414 (void) UnregisterMagickInfo("PFA");
415 (void) UnregisterMagickInfo("DFONT");