Toshihiro Shimizu 890ddd
// Copyright © 1999 Middlesoft, Inc. All rights reserved.
Toshihiro Shimizu 890ddd
// First Created By Lee Thomason.
Toshihiro Shimizu 890ddd
// First Created On 09/08/1999.
Toshihiro Shimizu 890ddd
// Last Modified On 11/09/1999.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/****************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				File Summary: FDTFonts.cpp
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  This source file contains the definition for all low-level font-related functions,
Toshihiro Shimizu 890ddd
  grouped by classes:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  		Class						Member Function
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FDTDefineFont				FDTDefineFont();
Toshihiro Shimizu 890ddd
								~FDTDefineFont();
Toshihiro Shimizu 890ddd
								U16 ID();
Toshihiro Shimizu 890ddd
								void AddShapeGlyph(FShape*);
Toshihiro Shimizu 890ddd
								void WriteToSWFStream(FSWFStream*);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FDTDefineFont2				FDTDefineFont2(char*, U16, U16, U16);
Toshihiro Shimizu 890ddd
								FDTDefineFont2(char*, U16, U16, U16, S16, S16, S16);
Toshihiro Shimizu 890ddd
								~FDTDefineFont2();
Toshihiro Shimizu 890ddd
								void AddShapeGlyph(FShape*, U16, S16, FRect*);
Toshihiro Shimizu 890ddd
								void AddKerningRec(FKerningRec*);
Toshihiro Shimizu 890ddd
								U16 nIndexBits();
Toshihiro Shimizu 890ddd
								U16 ID(void);
Toshihiro Shimizu 890ddd
								void WriteToSWFStream(FSWFStream*);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FDTDefineFontInfo			FDTDefineFontInfo(const char*, U16, U16, U16, U16);
Toshihiro Shimizu 890ddd
								void FDTDefineFontInfo::AddCode(U16);
Toshihiro Shimizu 890ddd
								U16 FDTDefineFontInfo::ID();
Toshihiro Shimizu 890ddd
								void WriteToSWFStream(FSWFStream*);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//	FGlyphEntry					FGlyphEntry(U16, S16);
Toshihiro Shimizu 890ddd
//								S16 AdvanceValue();
Toshihiro Shimizu 890ddd
//								void IncludeNBitInfo(U16, U16);
Toshihiro Shimizu 890ddd
//								void WriteToSWFStream(FSWFStream*);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FKerningRec					FKerningRec (U16, U16, short);
Toshihiro Shimizu 890ddd
								void CodesWide (U16);
Toshihiro Shimizu 890ddd
								void WriteToSWFStream(FSWFStream*);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	
Toshihiro Shimizu 890ddd
	Note: All member functions of FGlyphEntry have been commented out. Need to fix.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
****************************************************************************************/
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4786)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "FDTFonts.h"
Toshihiro Shimizu 890ddd
#include "FDTShapes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
//  --------  FButtonRecord1 ---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FDTDefineFont::FDTDefineFont()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	characterID = FObjCollection::Increment();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	nFillBits = 1;
Toshihiro Shimizu 890ddd
	nLineBits = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FDTDefineFont::~FDTDefineFont()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (!shapeGlyphs.empty()) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		delete shapeGlyphs.front();
Toshihiro Shimizu 890ddd
		shapeGlyphs.pop_front();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
U16 FDTDefineFont::ID()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return (U8)characterID;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FDTDefineFont::AddShapeGlyph(FShape *_shape)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	_shape->SetFillBits(nFillBits);
Toshihiro Shimizu 890ddd
	_shape->SetLineBits(nLineBits);
Toshihiro Shimizu 890ddd
	shapeGlyphs.push_back(_shape);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FDTDefineFont::WriteToSWFStream(FSWFStream *_SWFStream)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	U32 offsetsBufferSize = shapeGlyphs.size() * 2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FSWFStream body;
Toshihiro Shimizu 890ddd
	FSWFStream shapeBuffer;
Toshihiro Shimizu 890ddd
	std::list<u32> offsetsList;</u32>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// get values for offsets and place them in a list
Toshihiro Shimizu 890ddd
	// write list of shapeGlyphs to shape buffer
Toshihiro Shimizu 890ddd
	offsetsList.push_back(offsetsBufferSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::list<fshape *="">::iterator cursor;</fshape>
Toshihiro Shimizu 890ddd
	std::list<fshape *="">::iterator nextToLast = shapeGlyphs.end();</fshape>
Toshihiro Shimizu 890ddd
	nextToLast--;
Toshihiro Shimizu 890ddd
	for (cursor = shapeGlyphs.begin(); cursor != nextToLast; cursor++) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		(*cursor)->WriteToSWFStream(&shapeBuffer);
Toshihiro Shimizu 890ddd
		offsetsList.push_back(offsetsBufferSize + shapeBuffer.Size());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	(*cursor)->WriteToSWFStream(&shapeBuffer);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	body.WriteWord((U32)characterID);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// write offsetsList to body
Toshihiro Shimizu 890ddd
	while (!offsetsList.empty()) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		body.WriteWord((U32)offsetsList.front());
Toshihiro Shimizu 890ddd
		offsetsList.pop_front();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//write shape buffer to body
Toshihiro Shimizu 890ddd
	body.Append(&shapeBuffer);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//put tag on body and write to stream
Toshihiro Shimizu 890ddd
	_SWFStream->AppendTag(stagDefineFont, body.Size(), &body);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
//  --------  FDTDefineFont2 ---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FDTDefineFont2::FDTDefineFont2(const char *_fontName, U16 _encodeType, U16 _italicFlag, U16 _boldFlag)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	fontID = FObjCollection::Increment();
Toshihiro Shimizu 890ddd
	hasLayoutFlag = 1;
Toshihiro Shimizu 890ddd
	encodeType = _encodeType;
Toshihiro Shimizu 890ddd
	italicFlag = _italicFlag;
Toshihiro Shimizu 890ddd
	boldFlag = _boldFlag;
Toshihiro Shimizu 890ddd
	fontName = new FString((U8 *)_fontName);
Toshihiro Shimizu 890ddd
	nFillBits = 1;
Toshihiro Shimizu 890ddd
	nLineBits = 0;
Toshihiro Shimizu 890ddd
	ascenderHeight = 0;
Toshihiro Shimizu 890ddd
	descenderHeight = 0;
Toshihiro Shimizu 890ddd
	leadingHeight = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FDTDefineFont2::FDTDefineFont2(const char *_fontName, U16 _encodeType, U16 _italicFlag,
Toshihiro Shimizu 890ddd
							   U16 _boldFlag, S16 _ascenderHeight,
Toshihiro Shimizu 890ddd
							   S16 _descenderHeight, S16 _leadingHeight)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	fontID = FObjCollection::Increment();
Toshihiro Shimizu 890ddd
	hasLayoutFlag = 1;
Toshihiro Shimizu 890ddd
	encodeType = _encodeType;
Toshihiro Shimizu 890ddd
	italicFlag = _italicFlag;
Toshihiro Shimizu 890ddd
	boldFlag = _boldFlag;
Toshihiro Shimizu 890ddd
	fontName = new FString((U8 *)_fontName);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ascenderHeight = _ascenderHeight;
Toshihiro Shimizu 890ddd
	descenderHeight = _descenderHeight;
Toshihiro Shimizu 890ddd
	leadingHeight = _leadingHeight;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	nFillBits = 1;
Toshihiro Shimizu 890ddd
	nLineBits = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FDTDefineFont2::~FDTDefineFont2()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	delete fontName;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (!glyphs.empty()) {
Toshihiro Shimizu 890ddd
		delete glyphs.front().shape;
Toshihiro Shimizu 890ddd
		delete glyphs.front().bounds;
Toshihiro Shimizu 890ddd
		glyphs.pop_front();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (!kerningTable.empty()) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		delete kerningTable.front();
Toshihiro Shimizu 890ddd
		kerningTable.pop_front();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FDTDefineFont2::AddShapeGlyph(FShape *_shape, U16 _shapeCode, S16 _shapeAdvance,
Toshihiro Shimizu 890ddd
								   FRect *_shapeBounds)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// FIXME, don't know what nFillBits and nLineBits are
Toshihiro Shimizu 890ddd
	_shape->SetFillBits(nFillBits);
Toshihiro Shimizu 890ddd
	_shape->SetLineBits(nLineBits);
Toshihiro Shimizu 890ddd
	Glyph g;
Toshihiro Shimizu 890ddd
	g.advance = _shapeAdvance;
Toshihiro Shimizu 890ddd
	g.bounds = _shapeBounds;
Toshihiro Shimizu 890ddd
	g.code = _shapeCode;
Toshihiro Shimizu 890ddd
	g.shape = _shape;
Toshihiro Shimizu 890ddd
	glyphs.push_back(g);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FDTDefineFont2::AddKerningRec(FKerningRec *_kerningRecord)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (hasLayoutFlag)
Toshihiro Shimizu 890ddd
		kerningTable.push_back(_kerningRecord);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
U16 FDTDefineFont2::nIndexBits()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return (U16)FSWFStream::MinBits(glyphs.size() - 1, false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
U16 FDTDefineFont2::ID(void)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return fontID;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FDTDefineFont2::WriteToSWFStream(FSWFStream *_SWFStream)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//	U32 offsetsSize		= (glyphs.size() * 2);
Toshihiro Shimizu 890ddd
	//	U32 offsetsSizeWide = glyphs.size() * 4;
Toshihiro Shimizu 890ddd
	//	U16 wideOffsetsFlag = 0;
Toshihiro Shimizu 890ddd
	//	U16 wideCodesFlag	= 0;
Toshihiro Shimizu 890ddd
	//	std::list<u32> offsetsList;</u32>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// FIXME: add wide offset later
Toshihiro Shimizu 890ddd
	S16 *offsetTable;
Toshihiro Shimizu 890ddd
	if (glyphs.size() > 0)
Toshihiro Shimizu 890ddd
		offsetTable = new S16[glyphs.size()];
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		offsetTable = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FSWFStream body;
Toshihiro Shimizu 890ddd
	FSWFStream shapeBuffer;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::list<glyph>::iterator glyphCursor;</glyph>
Toshihiro Shimizu 890ddd
	for (glyphCursor = glyphs.begin(), i = 0; glyphCursor != glyphs.end(); glyphCursor++, i++) {
Toshihiro Shimizu 890ddd
		offsetTable[i] = (S8)shapeBuffer.Size();
Toshihiro Shimizu 890ddd
		glyphCursor->shape->WriteToSWFStream(&shapeBuffer);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	body.WriteWord((U32)fontID);
Toshihiro Shimizu 890ddd
	//write flags to body
Toshihiro Shimizu 890ddd
	body.WriteBits((U32)hasLayoutFlag, 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	switch (encodeType) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	case ShiftJIS:
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)1, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case Unicode:
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)1, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case ANSI:
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)1, 1);
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	body.WriteBits((U32)0, 1); // 0 for narrowOffsetFlag
Toshihiro Shimizu 890ddd
	body.WriteBits((U32)0, 1); // 0 for narrowOffsetCode
Toshihiro Shimizu 890ddd
	body.WriteBits((U32)italicFlag, 1);
Toshihiro Shimizu 890ddd
	body.WriteBits((U32)boldFlag, 1);
Toshihiro Shimizu 890ddd
	body.WriteByte(0); // FontFlagsReserved UB[8]
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	body.WriteByte((U32)fontName->Length());
Toshihiro Shimizu 890ddd
	fontName->WriteToSWFStream(&body, false); // write the name
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	body.WriteWord((U32)glyphs.size());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// write offsetsList to body
Toshihiro Shimizu 890ddd
	if (glyphs.size() > 0)
Toshihiro Shimizu 890ddd
		body.WriteLargeData((U8 *)offsetTable, 2 * glyphs.size());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//write shape glyph buffer to body
Toshihiro Shimizu 890ddd
	body.Append(&shapeBuffer);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (glyphCursor = glyphs.begin(), i = 0; glyphCursor != glyphs.end(); glyphCursor++, i++) {
Toshihiro Shimizu 890ddd
		body.WriteWord(glyphCursor->code);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// write layout information to body
Toshihiro Shimizu 890ddd
	if (hasLayoutFlag) {
Toshihiro Shimizu 890ddd
		body.WriteWord((U32)ascenderHeight);
Toshihiro Shimizu 890ddd
		body.WriteWord((U32)descenderHeight);
Toshihiro Shimizu 890ddd
		body.WriteWord((U32)leadingHeight);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (glyphCursor = glyphs.begin(), i = 0; glyphCursor != glyphs.end(); glyphCursor++, i++) {
Toshihiro Shimizu 890ddd
			body.WriteWord(glyphCursor->advance);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (glyphCursor = glyphs.begin(), i = 0; glyphCursor != glyphs.end(); glyphCursor++, i++) {
Toshihiro Shimizu 890ddd
			glyphCursor->bounds->WriteToSWFStream(&body);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		body.WriteWord((U32)kerningTable.size());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		std::list<fkerningrec *="">::iterator kernCursor;</fkerningrec>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (kernCursor = kerningTable.begin(); kernCursor != kerningTable.end(); kernCursor++) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			(*kernCursor)->CodesWide(0); // 0 is narraw offset flag
Toshihiro Shimizu 890ddd
			(*kernCursor)->WriteToSWFStream(&body);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// create entire tag with record header
Toshihiro Shimizu 890ddd
	_SWFStream->AppendTag(stagDefineFont2, body.Size(), &body);
Toshihiro Shimizu 890ddd
	delete[] offsetTable;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
//  --------  FButtonRecord1 ---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FDTDefineFontInfo::FDTDefineFontInfo(const char *_fontName, U16 _fontID,
Toshihiro Shimizu 890ddd
									 U16 _encodeType, U16 _italicFlag,
Toshihiro Shimizu 890ddd
									 U16 _boldFlag)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	characterID = FObjCollection::Increment();
Toshihiro Shimizu 890ddd
	encodeType = _encodeType;
Toshihiro Shimizu 890ddd
	italicFlag = _italicFlag;
Toshihiro Shimizu 890ddd
	boldFlag = _boldFlag;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	fontID = _fontID;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	fontName = new FString((U8 *)_fontName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FDTDefineFontInfo::~FDTDefineFontInfo()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete fontName;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FDTDefineFontInfo::AddCode(U16 _someCode)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	codeTable.push_back(_someCode);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
U16 FDTDefineFontInfo::ID()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return (U8)characterID;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FDTDefineFontInfo::WriteToSWFStream(FSWFStream *_SWFStream)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	U16 wideCodesFlag = 0;
Toshihiro Shimizu 890ddd
	FSWFStream body;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//determine whether 8 or 16 bit code fields are needed
Toshihiro Shimizu 890ddd
	std::list<u16>::iterator cursor;</u16>
Toshihiro Shimizu 890ddd
	for (cursor = codeTable.begin(); (cursor != codeTable.end()) && (wideCodesFlag == 0) // fixed from DV
Toshihiro Shimizu 890ddd
		 ;
Toshihiro Shimizu 890ddd
		 cursor++) {
Toshihiro Shimizu 890ddd
		if ((*cursor) > 65530)
Toshihiro Shimizu 890ddd
			wideCodesFlag = 1;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	body.WriteWord((U32)fontID);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	body.WriteByte((U32)fontName->Length());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	fontName->WriteToSWFStream(&body, false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// 	body.WriteBits((U32) reservedFlags, 2);
Toshihiro Shimizu 890ddd
	body.WriteBits((U32)0, 2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	switch (encodeType) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	case ShiftJIS:
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)1, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case Unicode:
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)1, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case ANSI:
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)0, 1);
Toshihiro Shimizu 890ddd
		body.WriteBits((U32)1, 1);
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	body.WriteBits((U32)italicFlag, 1);
Toshihiro Shimizu 890ddd
	body.WriteBits((U32)boldFlag, 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	body.WriteBits((U32)wideCodesFlag, 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//write code table to body
Toshihiro Shimizu 890ddd
	while (!codeTable.empty()) {
Toshihiro Shimizu 890ddd
		if (wideCodesFlag) {
Toshihiro Shimizu 890ddd
			body.WriteWord((U32)codeTable.front());
Toshihiro Shimizu 890ddd
			codeTable.pop_front();
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			body.WriteByte((U32)codeTable.front());
Toshihiro Shimizu 890ddd
			codeTable.pop_front();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// create entire tag with record header
Toshihiro Shimizu 890ddd
	_SWFStream->AppendTag(stagDefineFontInfo, body.Size(), &body);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
//  --------  FGlyphEntry ------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// FGlyphEntry::FGlyphEntry(U16 index, S16 advance)
Toshihiro Shimizu 890ddd
// {
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// 	glyphIndex = index;
Toshihiro Shimizu 890ddd
// 	glyphAdvance = advance;
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// }
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// S16 FGlyphEntry::AdvanceValue()
Toshihiro Shimizu 890ddd
// {
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// 	return glyphAdvance;
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//	Used to specify the nBit info for the entries.  This is determined and passed to
Toshihiro Shimizu 890ddd
//	the glyph entry just before write time.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// void FGlyphEntry::IncludeNBitInfo(U16 _nIndexBits, U16 _nAdvanceBits)
Toshihiro Shimizu 890ddd
// {
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// 	nIndexBits = _nIndexBits;
Toshihiro Shimizu 890ddd
// 	nAdvanceBits = _nAdvanceBits;
Toshihiro Shimizu 890ddd
// }
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// void FGlyphEntry::WriteToSWFStream(FSWFStream *_SWFStream)
Toshihiro Shimizu 890ddd
// {
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// 	_SWFStream->WriteBits((U32) glyphIndex, nIndexBits);
Toshihiro Shimizu 890ddd
// 	_SWFStream->WriteBits((U32) glyphAdvance, nAdvanceBits);
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
//  --------  FKerningRec ------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FKerningRec::FKerningRec(U16 cd1, U16 cd2, short krnAdj)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	wideCodesFlag = 0; // default not wide
Toshihiro Shimizu 890ddd
	code1 = cd1;
Toshihiro Shimizu 890ddd
	code2 = cd2;
Toshihiro Shimizu 890ddd
	kerningAdjust = krnAdj;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FKerningRec::CodesWide(U16 _flag)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (_flag)
Toshihiro Shimizu 890ddd
		wideCodesFlag = 1;
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		wideCodesFlag = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FKerningRec::WriteToSWFStream(FSWFStream *b)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (wideCodesFlag) {
Toshihiro Shimizu 890ddd
		b->WriteWord((U32)code1);
Toshihiro Shimizu 890ddd
		b->WriteWord((U32)code2);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		b->WriteByte((U32)code1);
Toshihiro Shimizu 890ddd
		b->WriteByte((U32)code2);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	b->WriteWord((U32)kerningAdjust);
Toshihiro Shimizu 890ddd
}