2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Return A Preview For A TrueType or Postscript Font %
20 % Copyright 1999-2014 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[MaxTextExtent],
175 "abcdefghijklmnopqrstuvwxyz\n"
176 "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
177 "0123456789.:,;(*!?}^)#${%^&-+@\n";
207 assert(image_info != (const ImageInfo *) NULL);
208 assert(image_info->signature == MagickSignature);
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 == MagickSignature);
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,MaxTextExtent);
221 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
222 if (status == MagickFalse)
224 image=DestroyImageList(image);
225 return((Image *) NULL);
228 Color canvas with background color
230 background_color=image_info->background_color;
231 for (y=0; y < (ssize_t) image->rows; y++)
233 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
234 if (q == (Quantum *) NULL)
236 for (x=0; x < (ssize_t) image->columns; x++)
238 SetPixelInfoPixel(image,&background_color,q);
239 q+=GetPixelChannels(image);
241 if (SyncAuthenticPixels(image,exception) == MagickFalse)
244 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
245 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
247 Prepare drawing commands
250 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
251 draw_info->font=AcquireString(image->filename);
252 ConcatenateString(&draw_info->primitive,"push graphic-context\n");
253 (void) FormatLocaleString(buffer,MaxTextExtent," viewbox 0 0 %.20g %.20g\n",
254 (double) image->columns,(double) image->rows);
255 ConcatenateString(&draw_info->primitive,buffer);
256 ConcatenateString(&draw_info->primitive," font-size 18\n");
257 (void) FormatLocaleString(buffer,MaxTextExtent," text 10,%.20g '",(double) y);
258 ConcatenateString(&draw_info->primitive,buffer);
259 text=EscapeString(Text,'"');
260 ConcatenateString(&draw_info->primitive,text);
261 text=DestroyString(text);
262 (void) FormatLocaleString(buffer,MaxTextExtent,"'\n");
263 ConcatenateString(&draw_info->primitive,buffer);
264 y+=20*(ssize_t) MultilineCensus((char *) Text)+20;
265 for (i=12; i <= 72; i+=6)
268 ConcatenateString(&draw_info->primitive," font-size 18\n");
269 (void) FormatLocaleString(buffer,MaxTextExtent," text 10,%.20g '%.20g'\n",
270 (double) y,(double) i);
271 ConcatenateString(&draw_info->primitive,buffer);
272 (void) FormatLocaleString(buffer,MaxTextExtent," font-size %.20g\n",
274 ConcatenateString(&draw_info->primitive,buffer);
275 (void) FormatLocaleString(buffer,MaxTextExtent," text 50,%.20g "
276 "'That which does not destroy me, only makes me stronger.'\n",(double) y);
277 ConcatenateString(&draw_info->primitive,buffer);
281 ConcatenateString(&draw_info->primitive,"pop graphic-context");
282 (void) DrawImage(image,draw_info,exception);
284 Relinquish resources.
286 draw_info=DestroyDrawInfo(draw_info);
287 (void) CloseBlob(image);
288 return(GetFirstImageInList(image));
290 #endif /* MAGICKCORE_FREETYPE_DELEGATE */
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 % R e g i s t e r T T F I m a g e %
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 % RegisterTTFImage() adds attributes for the TTF image format to
304 % the list of supported formats. The attributes include the image format
305 % tag, a method to read and/or write the format, whether the format
306 % supports the saving of more than one frame to the same file or blob,
307 % whether the format supports native in-memory I/O, and a brief
308 % description of the format.
310 % The format of the RegisterTTFImage method is:
312 % size_t RegisterTTFImage(void)
315 ModuleExport size_t RegisterTTFImage(void)
318 version[MaxTextExtent];
324 #if defined(FREETYPE_MAJOR) && defined(FREETYPE_MINOR) && defined(FREETYPE_PATCH)
325 (void) FormatLocaleString(version,MaxTextExtent,"Freetype %d.%d.%d",
326 FREETYPE_MAJOR,FREETYPE_MINOR,FREETYPE_PATCH);
328 entry=SetMagickInfo("DFONT");
329 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
330 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
332 entry->magick=(IsImageFormatHandler *) IsTTF;
333 entry->adjoin=MagickFalse;
334 entry->description=ConstantString("Multi-face font package");
335 if (*version != '\0')
336 entry->version=ConstantString(version);
337 entry->module=ConstantString("TTF");
338 (void) RegisterMagickInfo(entry);
339 entry=SetMagickInfo("PFA");
340 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
341 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
343 entry->magick=(IsImageFormatHandler *) IsPFA;
344 entry->adjoin=MagickFalse;
345 entry->description=ConstantString("Postscript Type 1 font (ASCII)");
346 if (*version != '\0')
347 entry->version=ConstantString(version);
348 entry->module=ConstantString("TTF");
349 (void) RegisterMagickInfo(entry);
350 entry=SetMagickInfo("PFB");
351 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
352 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
354 entry->magick=(IsImageFormatHandler *) IsPFA;
355 entry->adjoin=MagickFalse;
356 entry->description=ConstantString("Postscript Type 1 font (binary)");
357 if (*version != '\0')
358 entry->version=ConstantString(version);
359 entry->module=ConstantString("TTF");
360 (void) RegisterMagickInfo(entry);
361 entry=SetMagickInfo("OTF");
362 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
363 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
365 entry->magick=(IsImageFormatHandler *) IsTTF;
366 entry->adjoin=MagickFalse;
367 entry->description=ConstantString("Open Type font");
368 if (*version != '\0')
369 entry->version=ConstantString(version);
370 entry->module=ConstantString("TTF");
371 (void) RegisterMagickInfo(entry);
372 entry=SetMagickInfo("TTC");
373 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
374 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
376 entry->magick=(IsImageFormatHandler *) IsTTF;
377 entry->adjoin=MagickFalse;
378 entry->description=ConstantString("TrueType font collection");
379 if (*version != '\0')
380 entry->version=ConstantString(version);
381 entry->module=ConstantString("TTF");
382 (void) RegisterMagickInfo(entry);
383 entry=SetMagickInfo("TTF");
384 #if defined(MAGICKCORE_FREETYPE_DELEGATE)
385 entry->decoder=(DecodeImageHandler *) ReadTTFImage;
387 entry->magick=(IsImageFormatHandler *) IsTTF;
388 entry->adjoin=MagickFalse;
389 entry->description=ConstantString("TrueType font");
390 if (*version != '\0')
391 entry->version=ConstantString(version);
392 entry->module=ConstantString("TTF");
393 (void) RegisterMagickInfo(entry);
394 return(MagickImageCoderSignature);
398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 % U n r e g i s t e r T T F I m a g e %
406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408 % UnregisterTTFImage() removes format registrations made by the
409 % TTF module from the list of supported formats.
411 % The format of the UnregisterTTFImage method is:
413 % UnregisterTTFImage(void)
416 ModuleExport void UnregisterTTFImage(void)
418 (void) UnregisterMagickInfo("TTF");
419 (void) UnregisterMagickInfo("TTC");
420 (void) UnregisterMagickInfo("OTF");
421 (void) UnregisterMagickInfo("PFA");
422 (void) UnregisterMagickInfo("PFB");
423 (void) UnregisterMagickInfo("PFA");
424 (void) UnregisterMagickInfo("DFONT");