This source file includes following definitions.
- IsPFA
- IsTTF
- ReadTTFImage
- RegisterTTFImage
- UnregisterTTFImage
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/draw.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/type.h"
#include "wand/MagickWand.h"
#if defined(MAGICKCORE_FREETYPE_DELEGATE)
#include <ft2build.h>
#if defined(FT_FREETYPE_H)
# include FT_FREETYPE_H
#else
# include <freetype/freetype.h>
#endif
#endif
static MagickBooleanType IsPFA(const unsigned char *magick,const size_t length)
{
if (length < 14)
return(MagickFalse);
if (LocaleNCompare((char *) magick,"%!PS-AdobeFont",14) == 0)
return(MagickTrue);
return(MagickFalse);
}
static MagickBooleanType IsTTF(const unsigned char *magick,const size_t length)
{
if (length < 5)
return(MagickFalse);
if (((int) magick[0] == 0x00) && ((int) magick[1] == 0x01) &&
((int) magick[2] == 0x00) && ((int) magick[3] == 0x00) &&
((int) magick[4] == 0x00))
return(MagickTrue);
return(MagickFalse);
}
#if defined(MAGICKCORE_FREETYPE_DELEGATE)
static Image *ReadTTFImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
char
buffer[MaxTextExtent],
*text;
const char
*Text = (char *)
"abcdefghijklmnopqrstuvwxyz\n"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
"0123456789.:,;(*!?}^)#${%^&-+@\n";
const TypeInfo
*type_info;
DrawInfo
*draw_info;
Image
*image;
MagickBooleanType
status;
PixelPacket
background_color;
register ssize_t
i,
x;
register PixelPacket
*q;
ssize_t
y;
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
image=AcquireImage(image_info);
image->columns=800;
image->rows=480;
type_info=GetTypeInfo(image_info->filename,exception);
if ((type_info != (const TypeInfo *) NULL) &&
(type_info->glyphs != (char *) NULL))
(void) CopyMagickString(image->filename,type_info->glyphs,MaxTextExtent);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
status=SetImageExtent(image,image->columns,image->rows);
if (status == MagickFalse)
{
InheritException(exception,&image->exception);
return(DestroyImageList(image));
}
background_color=image_info->background_color;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
*q++=background_color;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
(void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
(void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
y=20;
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
draw_info->font=AcquireString(image->filename);
ConcatenateString(&draw_info->primitive,"push graphic-context\n");
(void) FormatLocaleString(buffer,MaxTextExtent," viewbox 0 0 %.20g %.20g\n",
(double) image->columns,(double) image->rows);
ConcatenateString(&draw_info->primitive,buffer);
ConcatenateString(&draw_info->primitive," font-size 18\n");
(void) FormatLocaleString(buffer,MaxTextExtent," text 10,%.20g '",(double) y);
ConcatenateString(&draw_info->primitive,buffer);
text=EscapeString(Text,'"');
ConcatenateString(&draw_info->primitive,text);
text=DestroyString(text);
(void) FormatLocaleString(buffer,MaxTextExtent,"'\n");
ConcatenateString(&draw_info->primitive,buffer);
y+=20*(ssize_t) MultilineCensus((char *) Text)+20;
for (i=12; i <= 72; i+=6)
{
y+=i+12;
ConcatenateString(&draw_info->primitive," font-size 18\n");
(void) FormatLocaleString(buffer,MaxTextExtent," text 10,%.20g '%.20g'\n",
(double) y,(double) i);
ConcatenateString(&draw_info->primitive,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent," font-size %.20g\n",
(double) i);
ConcatenateString(&draw_info->primitive,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent," text 50,%.20g "
"'That which does not destroy me, only makes me stronger.'\n",(double) y);
ConcatenateString(&draw_info->primitive,buffer);
if (i >= 24)
i+=6;
}
ConcatenateString(&draw_info->primitive,"pop graphic-context");
(void) DrawImage(image,draw_info);
draw_info=DestroyDrawInfo(draw_info);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
#endif
ModuleExport size_t RegisterTTFImage(void)
{
char
version[MaxTextExtent];
MagickInfo
*entry;
*version='\0';
#if defined(FREETYPE_MAJOR) && defined(FREETYPE_MINOR) && defined(FREETYPE_PATCH)
(void) FormatLocaleString(version,MaxTextExtent,"Freetype %d.%d.%d",
FREETYPE_MAJOR,FREETYPE_MINOR,FREETYPE_PATCH);
#endif
entry=SetMagickInfo("DFONT");
#if defined(MAGICKCORE_FREETYPE_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadTTFImage;
#endif
entry->magick=(IsImageFormatHandler *) IsTTF;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Multi-face font package");
if (*version != '\0')
entry->version=ConstantString(version);
entry->module=ConstantString("TTF");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("PFA");
#if defined(MAGICKCORE_FREETYPE_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadTTFImage;
#endif
entry->magick=(IsImageFormatHandler *) IsPFA;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Postscript Type 1 font (ASCII)");
if (*version != '\0')
entry->version=ConstantString(version);
entry->module=ConstantString("TTF");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("PFB");
#if defined(MAGICKCORE_FREETYPE_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadTTFImage;
#endif
entry->magick=(IsImageFormatHandler *) IsPFA;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Postscript Type 1 font (binary)");
if (*version != '\0')
entry->version=ConstantString(version);
entry->module=ConstantString("TTF");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("OTF");
#if defined(MAGICKCORE_FREETYPE_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadTTFImage;
#endif
entry->magick=(IsImageFormatHandler *) IsTTF;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Open Type font");
if (*version != '\0')
entry->version=ConstantString(version);
entry->module=ConstantString("TTF");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("TTC");
#if defined(MAGICKCORE_FREETYPE_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadTTFImage;
#endif
entry->magick=(IsImageFormatHandler *) IsTTF;
entry->adjoin=MagickFalse;
entry->description=ConstantString("TrueType font collection");
if (*version != '\0')
entry->version=ConstantString(version);
entry->module=ConstantString("TTF");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("TTF");
#if defined(MAGICKCORE_FREETYPE_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadTTFImage;
#endif
entry->magick=(IsImageFormatHandler *) IsTTF;
entry->adjoin=MagickFalse;
entry->description=ConstantString("TrueType font");
if (*version != '\0')
entry->version=ConstantString(version);
entry->module=ConstantString("TTF");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterTTFImage(void)
{
(void) UnregisterMagickInfo("TTF");
(void) UnregisterMagickInfo("TTC");
(void) UnregisterMagickInfo("OTF");
(void) UnregisterMagickInfo("PFA");
(void) UnregisterMagickInfo("PFB");
(void) UnregisterMagickInfo("PFA");
(void) UnregisterMagickInfo("DFONT");
}