2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Return A Preview For A TrueType or Postscript Font %
20 % Copyright 1999-2011 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)
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",
180 *Phrase = (char *) "The five boxing wizards jump quickly!";
181 /* NOTE: These are Pangrams, which contain every letter in English
182 See http://www.artlebedev.ru/kovodstvo/sections/33/
184 "A quick brown fox jumps over the lazy dog.";
185 "The quick onyx goblin jumps over the lazy dwarf!";
186 "Pack my box with five dozen liquor jugs.";
187 "Grumpy wizards make toxic brew for the evil Queen and Jack.";
189 IMv6 used this well known phrase, but it is not a pangram!
190 "That which does not destroy me, only makes me stronger.";
221 assert(image_info != (const ImageInfo *) NULL);
222 assert(image_info->signature == MagickSignature);
223 if (image_info->debug != MagickFalse)
224 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
225 image_info->filename);
226 assert(exception != (ExceptionInfo *) NULL);
227 assert(exception->signature == MagickSignature);
228 image=AcquireImage(image_info,exception);
231 type_info=GetTypeInfo(image_info->filename,exception);
232 if ((type_info != (const TypeInfo *) NULL) &&
233 (type_info->glyphs != (char *) NULL))
234 (void) CopyMagickString(image->filename,type_info->glyphs,MaxTextExtent);
235 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
236 if (status == MagickFalse)
238 image=DestroyImageList(image);
239 return((Image *) NULL);
242 Color canvas with background color
244 background_color=image_info->background_color;
245 for (y=0; y < (ssize_t) image->rows; y++)
247 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
248 if (q == (Quantum *) NULL)
250 for (x=0; x < (ssize_t) image->columns; x++)
252 SetPixelPixelInfo(image,&background_color,q);
253 q+=GetPixelChannels(image);
255 if (SyncAuthenticPixels(image,exception) == MagickFalse)
258 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
259 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
261 Prepare drawing commands
264 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
265 draw_info->font=AcquireString(image->filename);
266 ConcatenateString(&draw_info->primitive,"push graphic-context\n");
267 (void) FormatLocaleString(buffer,MaxTextExtent," viewbox 0 0 %.20g %.20g\n",
268 (double) image->columns,(double) image->rows);
269 ConcatenateString(&draw_info->primitive,buffer);
270 ConcatenateString(&draw_info->primitive," font-size 18\n");
271 (void) FormatLocaleString(buffer,MaxTextExtent," text 10,%.20g '",(double) y);
272 ConcatenateString(&draw_info->primitive,buffer);
273 text=EscapeString(Text,'"');
274 ConcatenateString(&draw_info->primitive,text);
275 text=DestroyString(text);
276 (void) FormatLocaleString(buffer,MaxTextExtent,"'\n");
277 ConcatenateString(&draw_info->primitive,buffer);
278 y+=12*(ssize_t) MultilineCensus((char *) Text);
279 /* FUTURE: A setting to specify the text to use */
282 y += (i+2>12) ? i+2 : 12; /* line spacing */
283 ConcatenateString(&draw_info->primitive," font-size 12\n");
284 (void) FormatLocaleString(buffer,MaxTextExtent," text 10,%g '%-2g'\n",
285 (double) y,(double) i);
286 ConcatenateString(&draw_info->primitive,buffer);
287 (void) FormatLocaleString(buffer,MaxTextExtent," font-size %g\n",
289 ConcatenateString(&draw_info->primitive,buffer);
290 (void) FormatLocaleString(buffer,MaxTextExtent," text 50,%g '%s'\n",
292 ConcatenateString(&draw_info->primitive,buffer);
300 ConcatenateString(&draw_info->primitive,"pop graphic-context");
301 (void) DrawImage(image,draw_info,exception);
303 Relinquish resources.
305 draw_info=DestroyDrawInfo(draw_info);
306 (void) CloseBlob(image);
307 return(GetFirstImageInList(image));
309 #endif /* MAGICKCORE_FREETYPE_DELEGATE */
312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 % R e g i s t e r T T F I m a g e %
320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322 % RegisterTTFImage() adds attributes for the TTF image format to
323 % the list of supported formats. The attributes include the image format
324 % tag, a method to read and/or write the format, whether the format
325 % supports the saving of more than one frame to the same file or blob,
326 % whether the format supports native in-memory I/O, and a brief
327 % description of the format.
329 % The format of the RegisterTTFImage method is:
331 % size_t RegisterTTFImage(void)
334 ModuleExport size_t RegisterTTFImage(void)
337 version[MaxTextExtent];
343 #if defined(FREETYPE_MAJOR) && defined(FREETYPE_MINOR) && defined(FREETYPE_PATCH)
344 (void) FormatLocaleString(version,MaxTextExtent,"Freetype %d.%d.%d",
345 FREETYPE_MAJOR,FREETYPE_MINOR,FREETYPE_PATCH);
347 entry=SetMagickInfo("DFONT");
348 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
349 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
351 entry->magick=(IsImageFormatHandler *) IsTTF;
352 entry->adjoin=MagickFalse;
353 entry->description=ConstantString("Multi-face font package");
354 if (*version != '\0')
355 entry->version=ConstantString(version);
356 entry->module=ConstantString("TTF");
357 (void) RegisterMagickInfo(entry);
358 entry=SetMagickInfo("PFA");
359 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
360 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
362 entry->magick=(IsImageFormatHandler *) IsPFA;
363 entry->adjoin=MagickFalse;
364 entry->description=ConstantString("Postscript Type 1 font (ASCII)");
365 if (*version != '\0')
366 entry->version=ConstantString(version);
367 entry->module=ConstantString("TTF");
368 (void) RegisterMagickInfo(entry);
369 entry=SetMagickInfo("PFB");
370 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
371 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
373 entry->magick=(IsImageFormatHandler *) IsPFA;
374 entry->adjoin=MagickFalse;
375 entry->description=ConstantString("Postscript Type 1 font (binary)");
376 if (*version != '\0')
377 entry->version=ConstantString(version);
378 entry->module=ConstantString("TTF");
379 (void) RegisterMagickInfo(entry);
380 entry=SetMagickInfo("OTF");
381 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
382 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
384 entry->magick=(IsImageFormatHandler *) IsTTF;
385 entry->adjoin=MagickFalse;
386 entry->description=ConstantString("Open Type font");
387 if (*version != '\0')
388 entry->version=ConstantString(version);
389 entry->module=ConstantString("TTF");
390 (void) RegisterMagickInfo(entry);
391 entry=SetMagickInfo("TTC");
392 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
393 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
395 entry->magick=(IsImageFormatHandler *) IsTTF;
396 entry->adjoin=MagickFalse;
397 entry->description=ConstantString("TrueType font collection");
398 if (*version != '\0')
399 entry->version=ConstantString(version);
400 entry->module=ConstantString("TTF");
401 (void) RegisterMagickInfo(entry);
402 entry=SetMagickInfo("TTF");
403 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
404 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
406 entry->magick=(IsImageFormatHandler *) IsTTF;
407 entry->adjoin=MagickFalse;
408 entry->description=ConstantString("TrueType font");
409 if (*version != '\0')
410 entry->version=ConstantString(version);
411 entry->module=ConstantString("TTF");
412 (void) RegisterMagickInfo(entry);
413 return(MagickImageCoderSignature);
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 % U n r e g i s t e r T T F I m a g e %
425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427 % UnregisterTTFImage() removes format registrations made by the
428 % TTF module from the list of supported formats.
430 % The format of the UnregisterTTFImage method is:
432 % UnregisterTTFImage(void)
435 ModuleExport void UnregisterTTFImage(void)
437 (void) UnregisterMagickInfo("TTF");
438 (void) UnregisterMagickInfo("TTC");
439 (void) UnregisterMagickInfo("OTF");
440 (void) UnregisterMagickInfo("PFA");
441 (void) UnregisterMagickInfo("PFB");
442 (void) UnregisterMagickInfo("PFA");
443 (void) UnregisterMagickInfo("DFONT");