The FONT attachment (Embedded Font) is used for embedding custom fonts into a layer; this is primarily used for text layers. The metadata consists of a host-defined fixed-length header followed by type-specific font data of an arbitrary length that is provided in the header:
#define META_FONT_VERSION 0x0001
#define META_FONT_TYPE_RAW_SFNT 0x00
struct meta_FONT_Obj
{
unsigned short version; //FONT version
unsigned short unused_1; //unused, set to zero
unsigned char type;
unsigned char unused_2[15];
unsigned long payload_size; //size of payload data
char unused_3[256-(4+16+4)];
};
The format and meaning of the data that follows the header is defined by type. Currently, only the following values are supported for this parameter:
META_FONT_TYPE_RAW_SFNT
The payload is just raw data representing the contents of the font file in a supported “sfnt” standard format, such as TrueType or OpenType. Chasys Draw IES will pass the data to the OS as is, so it essential that the format in use be one that the OS understands.
There is currently no support for WOFF fonts, but converting these the SFNT is fairly trivial and should be handled by the plug-in or application that is generating the FONT attachment.
The embedded font must be in a format that is understood by the operating system, e.g. Windows supports TrueType fonts but doesn’t support WOFF fonts. It is strongly recommended that you only use TrueType and OpenType fonts for this element. For WOFF fonts, it is recommended that the raw data is converted to “sfnt” format (this conversion is fairly trivial).
Sample Code
Here’s some sample code that creates FONT metadata:
TAGS: Chasys Draw IES Source Code, Attachment, Metadata, FONT
unsigned long sz_mem;
void *lp_mem;
meta_FONT_Obj* font;
... ...
//insert FONT attachment
lp_mem=ReadBinaryFileIntoMemory("C:\\Windows\\Fonts\\BRITANIC.ttf",&sz_mem);
if(lp_mem)
{
data->meta_data=0;
if(data->meta_write(data,"FONT",sz_mem+sizeof(meta_FONT_Obj))) //total size
{
font=(meta_FONT_Obj*)(data->meta_data);
font->version=META_FONT_VERSION;
font->type=META_FONT_TYPE_RAW_SFNT;
font->payload_size=sz_mem; //size of raw data from font file
memcpy(data->meta_data+sizeof(meta_FONT_Obj),p_mem,sz_mem);
}
GlobalFree(lp_mem);
}