Made to Order Software Corporation Logo

DefineFont2

Tag Info
Tag Number: 
48
Tag Type: 
Define
Tag Flash Version: 
3
Unknown SWF Tag: 
This tag is defined by the Flash documentation by Adobe
Brief Description: 

Define a list of glyphs using shapes and other font metric information.

Tag Structure: 
struct swf_definefont2 {
	swf_tag			f_tag;		/* 48 or 75 */
	unsigned short		f_font2_id;
	unsigned		f_font2_has_layout : 1;
	if(version >= 6) {
		unsigned	f_font2_reserved : 1;
		if(version >= 7) {
			unsigned	f_font2_small_text : 1;
		}
		unsigned	f_font2_reserved : 1;
	}
	else {
		unsigned	f_font2_shiftjis : 1;
		unsigned	f_font2_unicode : 1;
		unsigned	f_font2_ansii : 1;
	}
	unsigned		f_font2_wide_offsets : 1;
	unsigned		f_font2_wide : 1;	/* always 1 in v6.x+ */
	unsigned		f_font2_italic : 1;
	unsigned		f_font2_bold : 1;
	if(version >= 6) {
		unsigned char	f_font2_language;
	}
	else {
		unsigned char	f_font2_reserved;
	}
	unsigned char		f_font2_name_length;
	unsigned char		f_font2_name[f_font2_name_length];
	unsigned short		f_font2_glyphs_count;
	if(f_font2_wide_offsets) {
		unsigned long		f_font2_offsets[f_font2_glyphs_count];
		unsigned long		f_font2_map_offset;
	}
	else {
		unsigned short		f_font2_offsets[f_font2_glyphs_count];
		unsigned short		f_font2_map_offset;
	}
	swf_shape		f_font2_shapes[f_font2_glyphs_count];
	if(f_font_info_wide) {
		unsigned short		f_font2_map[f_font2_glyphs_count];
	}
	else {
		unsigned char		f_font2_map[f_font2_glyphs_count];
	}
	if(f_font2_has_layout) {
		signed short		f_font2_ascent;
		signed short		f_font2_descent;
		signed short		f_font2_leading_height;
		signed short		f_font2_advance[f_font2_glyphs_count];
		swf_rect		f_font2_bounds[f_font2_glyphs_count];
		signed short		f_font2_kerning_count;
		swf_kerning		f_font2_kerning[f_font2_kerning_count];
	}
};
/* DefineFont3 is the same as DefineFont2 */
typedef struct swf_definefont2 swf_definefont3;

It is common to use the DefineFont2 tag in order to create an array of shapes later re-used to draw strings of text on the screen. This tag must be used whenever a DefineEditText references a font; and in that case it is suggested you include a full description of the font with layouts.

The array of glyphs must be ordered in ascending order (the smaller glyph number saved first; thus 'a' must be saved before 'b', etc.).

All the characters should be defined in a 1024x1024 square (in pixels) to be drawn with the best possible quality. This square is called the EM square.

The DefineFont3 tag has the exact same definition as the DefineFont2 tag. The difference lies in the shapes being referenced. These have a precision 20 times higher. This gives you a font with that much higher precision (each pixel can be divided in a 400 sub-pixels.) The other difference is that a DefineFont3 can be referenced by a DefineFontAlignZones tag. That one can be used to properly align characters on a pixel boundary.

Note that an embedded font can be rotated. A system font (also called a device font) cannot be rotated. Also, the scaling and translation of a system font does not always respect the exact position. It is likely that the font will be moved to the next pixel left or right to avoid bluriness. That means it will look quite jaggy if you try to have a quite smooth move.

Since V6.x the f_font2_wide must always be set to 1.

The f_font2_shiftjis, f_font2_unicode and f_font2_ansii flags are for older movies (SWF 5 or older). Note that these are still defined as is in the Macromedia documentation (except for the Unicode flag which is implied and was replaced by another flag in version 7.) I strongly suggest that you follow my structure and totally ignore these flags (set them to 0) in newer movies.

The f_offsets array is a list of byte offsets given from the beginning of the f_offsets array itself (and not the beginning of the tag) to the beginning of the corresponding shape.

f_font2_map_offset is the offset to the f_font2_map table. This offset is relative to the position of the f_offsets array. It very much looks like it is part of that table. This offset should always be present, though if the font is not used in a DefineEditText tag, older version of the Flash player would still work just fine.

The f_font2_kerning_count and f_font2_kerning are used since version 8. Before that, just put the kerning count to zero and do not save any kerning.

(If it were possible to write such a structure as is in C, then ...) In C one would write the following to find the shape in the font tag:

	struct swf_definefont2	*df;

	df = ...
	character67 = (struct swf_shape *) ((char *) df->f_offsets + df->f_offsets[67]);