doom3-bfg/neo/swf/SWF_Load.cpp

1266 lines
40 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2013-03-25 17:52:29 +00:00
Copyright (C) 2013 Robert Beckebans
2012-11-26 18:58:24 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
2012-11-26 18:58:24 +00:00
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#pragma hdrstop
#include "precompiled.h"
2012-11-26 18:58:24 +00:00
#include "../renderer/Font.h"
2013-11-10 13:27:18 +00:00
#include "../renderer/Image.h"
2012-11-26 18:58:24 +00:00
#pragma warning(disable: 4355) // 'this' : used in base member initializer list
#define BSWF_VERSION 16 // bumped to 16 for storing atlas image dimensions for unbuffered loads
#define BSWF_MAGIC ( ( 'B' << 24 ) | ( 'S' << 16 ) | ( 'W' << 8 ) | BSWF_VERSION )
2013-03-25 17:52:29 +00:00
// RB begin
#define XSWF_VERSION 16
// RB end
2012-11-26 18:58:24 +00:00
/*
===================
idSWF::LoadSWF
===================
*/
bool idSWF::LoadSWF( const char* fullpath )
{
2012-11-26 18:58:24 +00:00
idFile* rawfile = fileSystem->OpenFileRead( fullpath );
if( rawfile == NULL )
{
2012-11-26 18:58:24 +00:00
idLib::Printf( "SWF File not found %s\n", fullpath );
return false;
}
2012-11-26 18:58:24 +00:00
swfHeader_t header;
rawfile->Read( &header, sizeof( header ) );
if( header.W != 'W' || header.S != 'S' )
{
2012-11-26 18:58:24 +00:00
idLib::Warning( "Wrong signature bytes" );
delete rawfile;
return false;
}
if( header.version > 9 )
{
2012-11-26 18:58:24 +00:00
idLib::Warning( "Unsupported version %d", header.version );
delete rawfile;
return false;
}
2012-11-26 18:58:24 +00:00
bool compressed;
if( header.compression == 'F' )
{
2012-11-26 18:58:24 +00:00
compressed = false;
}
else if( header.compression == 'C' )
{
2012-11-26 18:58:24 +00:00
compressed = true;
}
else
{
2012-11-26 18:58:24 +00:00
idLib::Warning( "Unsupported compression type %c", header.compression );
delete rawfile;
return false;
}
idSwap::Little( header.fileLength );
2012-11-26 18:58:24 +00:00
// header.fileLength somewhat annoyingly includes the size of the header
uint32 fileLength2 = header.fileLength - ( uint32 )sizeof( swfHeader_t );
2012-11-26 18:58:24 +00:00
// slurp the raw file into a giant array, which is somewhat atrocious when loading from the preload since it's already an idFile_Memory
byte* fileData = ( byte* )Mem_Alloc( fileLength2, TAG_SWF );
2012-11-26 18:58:24 +00:00
size_t fileSize = rawfile->Read( fileData, fileLength2 );
delete rawfile;
if( compressed )
{
byte* uncompressed = ( byte* )Mem_Alloc( fileLength2, TAG_SWF );
if( !Inflate( fileData, ( int )fileSize, uncompressed, fileLength2 ) )
{
2012-11-26 18:58:24 +00:00
idLib::Warning( "Inflate error" );
Mem_Free( uncompressed );
return false;
}
Mem_Free( fileData );
fileData = uncompressed;
}
idSWFBitStream bitstream( fileData, fileLength2, false );
2012-11-26 18:58:24 +00:00
swfRect_t frameSize;
bitstream.ReadRect( frameSize );
if( !frameSize.tl.Compare( vec2_zero ) )
{
2012-11-26 18:58:24 +00:00
idLib::Warning( "Invalid frameSize top left" );
Mem_Free( fileData );
return false;
}
2012-11-26 18:58:24 +00:00
frameWidth = frameSize.br.x;
frameHeight = frameSize.br.y;
frameRate = bitstream.ReadU16();
2012-11-26 18:58:24 +00:00
// parse everything
mainsprite->Load( bitstream, true );
2012-11-26 18:58:24 +00:00
// now that all images have been loaded, write out the combined image
idStr atlasFileName = "generated/";
atlasFileName += fullpath;
atlasFileName.SetFileExtension( ".tga" );
2012-11-26 18:58:24 +00:00
WriteSwfImageAtlas( atlasFileName );
2012-11-26 18:58:24 +00:00
Mem_Free( fileData );
2012-11-26 18:58:24 +00:00
return true;
}
2013-11-10 13:27:18 +00:00
// RB: write new .swf with only the information we care about
void idSWF::WriteSWF( const char* swfFilename, const byte* atlasImageRGBA, int atlasImageWidth, int atlasImageHeight )
2013-10-30 10:44:24 +00:00
{
2013-11-10 13:27:18 +00:00
idFile_SWF file( fileSystem->OpenFileWrite( swfFilename, "fs_basepath" ) );
2013-10-30 10:44:24 +00:00
if( file == NULL )
{
return;
}
swfHeader_t header;
header.W = 'W';
header.S = 'S';
header.version = 9;
2013-11-06 20:46:35 +00:00
header.compression = 'F';
2013-10-30 10:44:24 +00:00
2013-11-06 20:46:35 +00:00
file.Write( &header, sizeof( header ) );
2013-10-30 10:44:24 +00:00
swfRect_t frameSize;
2013-11-06 20:46:35 +00:00
frameSize.br.x = frameWidth;
frameSize.br.y = frameHeight;
2013-10-30 10:44:24 +00:00
2013-11-10 13:27:18 +00:00
//int fileSize1 = file->Length();
2013-11-09 23:34:51 +00:00
2013-11-06 20:46:35 +00:00
file.WriteRect( frameSize );
2013-10-30 10:44:24 +00:00
2013-11-10 13:27:18 +00:00
//int fileSize2 = file->Length();
2013-11-09 23:34:51 +00:00
2013-11-06 20:46:35 +00:00
file.WriteU16( frameRate );
2013-10-30 10:44:24 +00:00
2013-11-09 23:34:51 +00:00
file.WriteU16( mainsprite->GetFrameCount() );
2013-11-10 13:27:18 +00:00
// write FileAttributes tag required for Flash version >= 8
2013-11-09 23:34:51 +00:00
file.WriteTagHeader( Tag_FileAttributes, 4 );
file.WriteUBits( 0, 1 ); // Reserved, must be 0
file.WriteUBits( 0, 1 ); // UseDirectBlit
file.WriteUBits( 0, 1 ); // UseGPU
file.WriteUBits( 0, 1 ); // HasMetadata
file.WriteUBits( 0, 1 ); // ActionScript3
file.WriteUBits( 0, 1 ); // Reserved, must be 0
file.WriteUBits( 0, 1 ); // UseNetwork
file.WriteUBits( 0, 24 ); // Reserved, must be 0
file.ByteAlign();
for( int i = 0; i < dictionary.Num(); i++ )
{
const idSWFDictionaryEntry& entry = dictionary[i];
switch( dictionary[i].type )
{
case SWF_DICT_IMAGE:
{
2013-11-10 13:27:18 +00:00
int width = entry.imageSize[0];
int height = entry.imageSize[1];
uint32 colorDataSize = width * height * 4;
idTempArray<byte> colorData( colorDataSize );
idTempArray<byte> pngData( colorDataSize );
for( int h = 0; h < height; h++ )
{
for( int w = 0; w < width; w++ )
{
int atlasPixelOfs = ( entry.imageAtlasOffset[0] + w + ( ( entry.imageAtlasOffset[1] + h ) * atlasImageWidth ) ) * 4;
//atlasPixelOfs = idMath::ClampInt( atlasPixelOfs
const byte* atlasPixel = atlasImageRGBA + atlasPixelOfs;
byte* pixel = &colorData[( w + ( h * width ) ) * 4];
pixel[0] = atlasPixel[3];
pixel[1] = atlasPixel[0];
pixel[2] = atlasPixel[1];
pixel[3] = atlasPixel[2];
pixel = &pngData[( w + ( h * width ) ) * 4];
pixel[0] = atlasPixel[0];
pixel[1] = atlasPixel[1];
pixel[2] = atlasPixel[2];
pixel[3] = atlasPixel[3];
}
}
idStr imageExportFileName;
idStr filenameWithoutExt = filename;
filenameWithoutExt.StripFileExtension();
sprintf( imageExportFileName, "exported/%s/image_characterid_%i.png", filenameWithoutExt.c_str(), i );
2013-11-10 13:27:18 +00:00
R_WritePNG( imageExportFileName.c_str(), pngData.Ptr(), 4, width, height, true, "fs_basepath" );
2013-11-09 23:34:51 +00:00
// RB: add some extra space for zlib
2013-11-10 13:27:18 +00:00
idTempArray<byte> compressedData( width * height * 4 * 1.02 + 12 );
int compressedDataSize = compressedData.Size();
if( !Deflate( colorData.Ptr(), colorDataSize, ( byte* )compressedData.Ptr(), compressedDataSize ) )
2013-11-09 23:34:51 +00:00
{
idLib::Warning( "DefineBitsLossless: Failed to deflate bitmap data" );
//return;
}
int tagLength = ( 2 + 1 + 2 + 2 ) + compressedDataSize;
2013-11-10 13:27:18 +00:00
file.WriteTagHeader( Tag_DefineBitsLossless2, tagLength );
2013-11-09 23:34:51 +00:00
file.WriteU16( i ); // characterID
file.WriteU8( 5 ); // format
2013-11-10 13:27:18 +00:00
file.WriteU16( width ); // width
file.WriteU16( height ); // height
file->Write( compressedData.Ptr(), compressedDataSize );
2013-11-12 22:05:59 +00:00
break;
}
#if 0
2013-11-12 22:05:59 +00:00
case SWF_DICT_SHAPE:
{
idSWFShape* shape = dictionary[i].shape;
2013-11-09 23:34:51 +00:00
2013-11-12 22:05:59 +00:00
int numFillDraws = 0;
for( int d = 0; d < shape->fillDraws.Num(); d++ )
2013-11-09 23:34:51 +00:00
{
2013-11-12 22:05:59 +00:00
idSWFShapeDrawFill& fillDraw = shape->fillDraws[d];
2013-11-13 12:59:58 +00:00
if( fillDraw.style.type == 0 /* || fillDraw.style.type == 4 */ )
2013-11-12 22:05:59 +00:00
{
numFillDraws++;
}
2013-11-09 23:34:51 +00:00
}
2013-11-12 22:05:59 +00:00
if( numFillDraws == 0 )
2013-11-09 23:34:51 +00:00
{
2013-11-12 22:05:59 +00:00
continue;
2013-11-09 23:34:51 +00:00
}
2013-11-12 22:05:59 +00:00
idFile_Memory* tagMem = new idFile_Memory( "shapeTag" );
idFile_SWF tag( tagMem );
2013-11-09 23:34:51 +00:00
2013-11-12 22:05:59 +00:00
tag.WriteU16( i ); // characterID
tag.WriteRect( shape->startBounds );
2013-11-09 23:34:51 +00:00
2013-11-13 12:59:58 +00:00
if( numFillDraws >= 0xFF )
{
tag.WriteU8( 0xFF );
tag.WriteU16( numFillDraws );
}
else
{
tag.WriteU8( numFillDraws );
}
2013-11-12 22:05:59 +00:00
for( int d = 0; d < shape->fillDraws.Num(); d++ )
{
idSWFShapeDrawFill& fillDraw = shape->fillDraws[d];
if( fillDraw.style.type == 0 )
{
2013-11-13 12:59:58 +00:00
// solid
tag.WriteU8( 0x00 );
2013-11-12 22:05:59 +00:00
tag.WriteColorRGBA( fillDraw.style.startColor );
}
/*
else
2013-11-13 12:59:58 +00:00
if( fillDraw.style.type == 4 )
2013-11-12 22:05:59 +00:00
{
2013-11-13 12:59:58 +00:00
// bitmap
2013-11-12 22:05:59 +00:00
tag.WriteU8( 0x40 );
tag.WriteU16( fillDraw.style.bitmapID );
tag.WriteMatrix( fillDraw.style.startMatrix );
}
*/
2013-11-13 12:59:58 +00:00
2013-11-12 22:05:59 +00:00
// type: 0 = solid, 1 = gradient, 4 = bitmap
//if( fillDraw.style.type == 0 )
//file->WriteBig( fillDraw.style.type );
//file->WriteBig( fillDraw.style.subType );
//file->Write( &fillDraw.style.startColor, 4 );
//file->Write( &fillDraw.style.endColor, 4 );
/*file->WriteBigArray( ( float* )&fillDraw.style.startMatrix, 6 );
file->WriteBigArray( ( float* )&fillDraw.style.endMatrix, 6 );
file->WriteBig( fillDraw.style.gradient.numGradients );
for( int g = 0; g < fillDraw.style.gradient.numGradients; g++ )
{
file->WriteBig( fillDraw.style.gradient.gradientRecords[g].startRatio );
file->WriteBig( fillDraw.style.gradient.gradientRecords[g].endRatio );
file->Write( &fillDraw.style.gradient.gradientRecords[g].startColor, 4 );
file->Write( &fillDraw.style.gradient.gradientRecords[g].endColor, 4 );
}
file->WriteBig( fillDraw.style.focalPoint );
file->WriteBig( fillDraw.style.bitmapID );
file->WriteBig( fillDraw.startVerts.Num() );
file->WriteBigArray( fillDraw.startVerts.Ptr(), fillDraw.startVerts.Num() );
file->WriteBig( fillDraw.endVerts.Num() );
file->WriteBigArray( fillDraw.endVerts.Ptr(), fillDraw.endVerts.Num() );
file->WriteBig( fillDraw.indices.Num() );
file->WriteBigArray( fillDraw.indices.Ptr(), fillDraw.indices.Num() );*/
}
// TODO
2013-11-13 12:59:58 +00:00
tag.WriteU8( 0 ); // no lines
tag.WriteU8( 1 ); // no shapes
2013-11-12 22:05:59 +00:00
/*
file->WriteBig( shape->lineDraws.Num() );
for( int d = 0; d < shape->lineDraws.Num(); d++ )
{
idSWFShapeDrawLine& lineDraw = shape->lineDraws[d];
file->WriteBig( lineDraw.style.startWidth );
file->WriteBig( lineDraw.style.endWidth );
file->Write( &lineDraw.style.startColor, 4 );
file->Write( &lineDraw.style.endColor, 4 );
file->WriteBig( lineDraw.startVerts.Num() );
file->WriteBigArray( lineDraw.startVerts.Ptr(), lineDraw.startVerts.Num() );
file->WriteBig( lineDraw.endVerts.Num() );
file->WriteBigArray( lineDraw.endVerts.Ptr(), lineDraw.endVerts.Num() );
file->WriteBig( lineDraw.indices.Num() );
file->WriteBigArray( lineDraw.indices.Ptr(), lineDraw.indices.Num() );
}
2013-11-09 23:34:51 +00:00
*/
2013-11-12 22:05:59 +00:00
2013-11-13 12:59:58 +00:00
file.WriteTagHeader( Tag_DefineShape3, tagMem->Length() );
2013-11-12 22:05:59 +00:00
file.Write( tagMem->GetDataPtr(), tagMem->Length() );
2013-11-09 23:34:51 +00:00
break;
}
2013-11-12 22:05:59 +00:00
#endif
2013-11-12 17:17:03 +00:00
case SWF_DICT_SPRITE:
{
dictionary[i].sprite->WriteSWF( file, i );
2013-11-12 17:17:03 +00:00
break;
}
2013-11-09 23:34:51 +00:00
}
}
mainsprite->WriteSWF( file, dictionary.Num() );
2013-10-30 10:44:24 +00:00
// add Tag_End
2013-11-09 23:34:51 +00:00
file.WriteTagHeader( Tag_End, 0 );
2013-10-30 10:44:24 +00:00
// go back and write filesize into header
uint32 fileSize = file->Length();
2013-11-10 13:27:18 +00:00
file->Seek( offsetof( swfHeader_t, fileLength ), FS_SEEK_SET );
2013-11-09 23:34:51 +00:00
file.WriteU32( fileSize );
2013-10-30 10:44:24 +00:00
}
2013-11-10 13:27:18 +00:00
// RB end
2013-10-30 10:44:24 +00:00
2012-11-26 18:58:24 +00:00
/*
===================
idSWF::LoadBinary
===================
*/
bool idSWF::LoadBinary( const char* bfilename, ID_TIME_T sourceTimeStamp )
{
idFile* f = fileSystem->OpenFileReadMemory( bfilename );
if( f == NULL || f->Length() <= 0 )
{
2012-11-26 18:58:24 +00:00
return false;
}
2012-11-26 18:58:24 +00:00
uint32 magic = 0;
ID_TIME_T btimestamp = 0;
f->ReadBig( magic );
f->ReadBig( btimestamp );
// RB: source might be from .resources, so we ignore the time stamp and assume a release build
if( magic != BSWF_MAGIC || ( !fileSystem->InProductionMode() && ( sourceTimeStamp != FILE_NOT_FOUND_TIMESTAMP ) && ( sourceTimeStamp != 0 ) && ( sourceTimeStamp != btimestamp ) ) )
{
2012-11-26 18:58:24 +00:00
delete f;
return false;
}
// RB end
2012-11-26 18:58:24 +00:00
f->ReadBig( frameWidth );
f->ReadBig( frameHeight );
f->ReadBig( frameRate );
if( mouseX == -1 )
{
2012-11-26 18:58:24 +00:00
mouseX = ( frameWidth / 2 );
}
if( mouseY == -1 )
{
2012-11-26 18:58:24 +00:00
mouseY = ( frameHeight / 2 );
}
2012-11-26 18:58:24 +00:00
mainsprite->Read( f );
2012-11-26 18:58:24 +00:00
int num = 0;
f->ReadBig( num );
dictionary.SetNum( num );
for( int i = 0; i < dictionary.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
f->ReadBig( dictionary[i].type );
switch( dictionary[i].type )
{
case SWF_DICT_IMAGE:
{
2012-11-26 18:58:24 +00:00
idStr imageName;
f->ReadString( imageName );
if( imageName[0] == '.' )
{
2012-11-26 18:58:24 +00:00
// internal image in the atlas
dictionary[i].material = NULL;
}
else
{
2012-11-26 18:58:24 +00:00
dictionary[i].material = declManager->FindMaterial( imageName );
}
for( int j = 0 ; j < 2 ; j++ )
{
2012-11-26 18:58:24 +00:00
f->ReadBig( dictionary[i].imageSize[j] );
f->ReadBig( dictionary[i].imageAtlasOffset[j] );
}
for( int j = 0 ; j < 4 ; j++ )
{
2012-11-26 18:58:24 +00:00
f->ReadBig( dictionary[i].channelScale[j] );
}
break;
}
case SWF_DICT_MORPH:
case SWF_DICT_SHAPE:
{
dictionary[i].shape = new( TAG_SWF ) idSWFShape;
idSWFShape* shape = dictionary[i].shape;
2012-11-26 18:58:24 +00:00
f->ReadBig( shape->startBounds.tl );
f->ReadBig( shape->startBounds.br );
f->ReadBig( shape->endBounds.tl );
f->ReadBig( shape->endBounds.br );
f->ReadBig( num );
shape->fillDraws.SetNum( num );
for( int d = 0; d < shape->fillDraws.Num(); d++ )
{
idSWFShapeDrawFill& fillDraw = shape->fillDraws[d];
2012-11-26 18:58:24 +00:00
f->ReadBig( fillDraw.style.type );
f->ReadBig( fillDraw.style.subType );
f->Read( &fillDraw.style.startColor, 4 );
f->Read( &fillDraw.style.endColor, 4 );
f->ReadBigArray( ( float* )&fillDraw.style.startMatrix, 6 );
f->ReadBigArray( ( float* )&fillDraw.style.endMatrix, 6 );
2012-11-26 18:58:24 +00:00
f->ReadBig( fillDraw.style.gradient.numGradients );
for( int g = 0; g < fillDraw.style.gradient.numGradients; g++ )
{
2012-11-26 18:58:24 +00:00
f->ReadBig( fillDraw.style.gradient.gradientRecords[g].startRatio );
f->ReadBig( fillDraw.style.gradient.gradientRecords[g].endRatio );
f->Read( &fillDraw.style.gradient.gradientRecords[g].startColor, 4 );
f->Read( &fillDraw.style.gradient.gradientRecords[g].endColor, 4 );
}
f->ReadBig( fillDraw.style.focalPoint );
f->ReadBig( fillDraw.style.bitmapID );
f->ReadBig( num );
fillDraw.startVerts.SetNum( num );
2012-11-26 18:58:24 +00:00
f->ReadBigArray( fillDraw.startVerts.Ptr(), fillDraw.startVerts.Num() );
f->ReadBig( num );
fillDraw.endVerts.SetNum( num );
2012-11-26 18:58:24 +00:00
f->ReadBigArray( fillDraw.endVerts.Ptr(), fillDraw.endVerts.Num() );
f->ReadBig( num );
fillDraw.indices.SetNum( num );
2012-11-26 18:58:24 +00:00
f->ReadBigArray( fillDraw.indices.Ptr(), fillDraw.indices.Num() );
}
f->ReadBig( num );
shape->lineDraws.SetNum( num );
for( int d = 0; d < shape->lineDraws.Num(); d++ )
{
idSWFShapeDrawLine& lineDraw = shape->lineDraws[d];
2012-11-26 18:58:24 +00:00
f->ReadBig( lineDraw.style.startWidth );
f->ReadBig( lineDraw.style.endWidth );
f->Read( &lineDraw.style.startColor, 4 );
f->Read( &lineDraw.style.endColor, 4 );
f->ReadBig( num );
lineDraw.startVerts.SetNum( num );
2012-11-26 18:58:24 +00:00
f->ReadBigArray( lineDraw.startVerts.Ptr(), lineDraw.startVerts.Num() );
f->ReadBig( num );
lineDraw.endVerts.SetNum( num );
2012-11-26 18:58:24 +00:00
f->ReadBigArray( lineDraw.endVerts.Ptr(), lineDraw.endVerts.Num() );
f->ReadBig( num );
lineDraw.indices.SetNum( num );
2012-11-26 18:58:24 +00:00
f->ReadBigArray( lineDraw.indices.Ptr(), lineDraw.indices.Num() );
}
break;
}
case SWF_DICT_SPRITE:
{
dictionary[i].sprite = new( TAG_SWF ) idSWFSprite( this );
2012-11-26 18:58:24 +00:00
dictionary[i].sprite->Read( f );
break;
}
case SWF_DICT_FONT:
{
dictionary[i].font = new( TAG_SWF ) idSWFFont;
idSWFFont* font = dictionary[i].font;
2012-11-26 18:58:24 +00:00
idStr fontName;
f->ReadString( fontName );
font->fontID = renderSystem->RegisterFont( fontName );
f->ReadBig( font->ascent );
f->ReadBig( font->descent );
f->ReadBig( font->leading );
f->ReadBig( num );
font->glyphs.SetNum( num );
for( int g = 0; g < font->glyphs.Num(); g++ )
{
2012-11-26 18:58:24 +00:00
f->ReadBig( font->glyphs[g].code );
f->ReadBig( font->glyphs[g].advance );
f->ReadBig( num );
font->glyphs[g].verts.SetNum( num );
2012-11-26 18:58:24 +00:00
f->ReadBigArray( font->glyphs[g].verts.Ptr(), font->glyphs[g].verts.Num() );
f->ReadBig( num );
font->glyphs[g].indices.SetNum( num );
2012-11-26 18:58:24 +00:00
f->ReadBigArray( font->glyphs[g].indices.Ptr(), font->glyphs[g].indices.Num() );
}
break;
}
case SWF_DICT_TEXT:
{
dictionary[i].text = new( TAG_SWF ) idSWFText;
idSWFText* text = dictionary[i].text;
2012-11-26 18:58:24 +00:00
f->ReadBig( text->bounds.tl );
f->ReadBig( text->bounds.br );
f->ReadBigArray( ( float* )&text->matrix, 6 );
f->ReadBig( num );
text->textRecords.SetNum( num );
for( int t = 0; t < text->textRecords.Num(); t++ )
{
idSWFTextRecord& textRecord = text->textRecords[t];
2012-11-26 18:58:24 +00:00
f->ReadBig( textRecord.fontID );
f->Read( &textRecord.color, 4 );
f->ReadBig( textRecord.xOffset );
f->ReadBig( textRecord.yOffset );
f->ReadBig( textRecord.textHeight );
f->ReadBig( textRecord.firstGlyph );
f->ReadBig( textRecord.numGlyphs );
}
f->ReadBig( num );
text->glyphs.SetNum( num );
for( int g = 0; g < text->glyphs.Num(); g++ )
{
2012-11-26 18:58:24 +00:00
f->ReadBig( text->glyphs[g].index );
f->ReadBig( text->glyphs[g].advance );
}
break;
}
case SWF_DICT_EDITTEXT:
{
dictionary[i].edittext = new( TAG_SWF ) idSWFEditText;
idSWFEditText* edittext = dictionary[i].edittext;
2012-11-26 18:58:24 +00:00
f->ReadBig( edittext->bounds.tl );
f->ReadBig( edittext->bounds.br );
f->ReadBig( edittext->flags );
f->ReadBig( edittext->fontID );
f->ReadBig( edittext->fontHeight );
f->Read( &edittext->color, 4 );
f->ReadBig( edittext->maxLength );
f->ReadBig( edittext->align );
f->ReadBig( edittext->leftMargin );
f->ReadBig( edittext->rightMargin );
f->ReadBig( edittext->indent );
f->ReadBig( edittext->leading );
f->ReadString( edittext->variable );
f->ReadString( edittext->initialText );
break;
}
}
}
delete f;
2012-11-26 18:58:24 +00:00
return true;
}
/*
===================
idSWF::WriteBinary
===================
*/
void idSWF::WriteBinary( const char* bfilename )
{
2012-11-26 18:58:24 +00:00
idFileLocal file( fileSystem->OpenFileWrite( bfilename, "fs_basepath" ) );
if( file == NULL )
{
2012-11-26 18:58:24 +00:00
return;
}
file->WriteBig( BSWF_MAGIC );
file->WriteBig( timestamp );
2012-11-26 18:58:24 +00:00
file->WriteBig( frameWidth );
file->WriteBig( frameHeight );
file->WriteBig( frameRate );
2012-11-26 18:58:24 +00:00
mainsprite->Write( file );
2012-11-26 18:58:24 +00:00
file->WriteBig( dictionary.Num() );
for( int i = 0; i < dictionary.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
file->WriteBig( dictionary[i].type );
switch( dictionary[i].type )
{
case SWF_DICT_IMAGE:
{
if( dictionary[i].material )
{
2012-11-26 18:58:24 +00:00
file->WriteString( dictionary[i].material->GetName() );
}
else
{
2012-11-26 18:58:24 +00:00
file->WriteString( "." );
}
for( int j = 0 ; j < 2 ; j++ )
{
2012-11-26 18:58:24 +00:00
file->WriteBig( dictionary[i].imageSize[j] );
file->WriteBig( dictionary[i].imageAtlasOffset[j] );
}
for( int j = 0 ; j < 4 ; j++ )
{
2012-11-26 18:58:24 +00:00
file->WriteBig( dictionary[i].channelScale[j] );
}
break;
}
case SWF_DICT_MORPH:
case SWF_DICT_SHAPE:
{
idSWFShape* shape = dictionary[i].shape;
2012-11-26 18:58:24 +00:00
file->WriteBig( shape->startBounds.tl );
file->WriteBig( shape->startBounds.br );
file->WriteBig( shape->endBounds.tl );
file->WriteBig( shape->endBounds.br );
file->WriteBig( shape->fillDraws.Num() );
for( int d = 0; d < shape->fillDraws.Num(); d++ )
{
idSWFShapeDrawFill& fillDraw = shape->fillDraws[d];
2012-11-26 18:58:24 +00:00
file->WriteBig( fillDraw.style.type );
file->WriteBig( fillDraw.style.subType );
file->Write( &fillDraw.style.startColor, 4 );
file->Write( &fillDraw.style.endColor, 4 );
file->WriteBigArray( ( float* )&fillDraw.style.startMatrix, 6 );
file->WriteBigArray( ( float* )&fillDraw.style.endMatrix, 6 );
2012-11-26 18:58:24 +00:00
file->WriteBig( fillDraw.style.gradient.numGradients );
for( int g = 0; g < fillDraw.style.gradient.numGradients; g++ )
{
2012-11-26 18:58:24 +00:00
file->WriteBig( fillDraw.style.gradient.gradientRecords[g].startRatio );
file->WriteBig( fillDraw.style.gradient.gradientRecords[g].endRatio );
file->Write( &fillDraw.style.gradient.gradientRecords[g].startColor, 4 );
file->Write( &fillDraw.style.gradient.gradientRecords[g].endColor, 4 );
}
file->WriteBig( fillDraw.style.focalPoint );
file->WriteBig( fillDraw.style.bitmapID );
file->WriteBig( fillDraw.startVerts.Num() );
file->WriteBigArray( fillDraw.startVerts.Ptr(), fillDraw.startVerts.Num() );
file->WriteBig( fillDraw.endVerts.Num() );
file->WriteBigArray( fillDraw.endVerts.Ptr(), fillDraw.endVerts.Num() );
file->WriteBig( fillDraw.indices.Num() );
file->WriteBigArray( fillDraw.indices.Ptr(), fillDraw.indices.Num() );
}
file->WriteBig( shape->lineDraws.Num() );
for( int d = 0; d < shape->lineDraws.Num(); d++ )
{
idSWFShapeDrawLine& lineDraw = shape->lineDraws[d];
2012-11-26 18:58:24 +00:00
file->WriteBig( lineDraw.style.startWidth );
file->WriteBig( lineDraw.style.endWidth );
file->Write( &lineDraw.style.startColor, 4 );
file->Write( &lineDraw.style.endColor, 4 );
file->WriteBig( lineDraw.startVerts.Num() );
file->WriteBigArray( lineDraw.startVerts.Ptr(), lineDraw.startVerts.Num() );
file->WriteBig( lineDraw.endVerts.Num() );
file->WriteBigArray( lineDraw.endVerts.Ptr(), lineDraw.endVerts.Num() );
file->WriteBig( lineDraw.indices.Num() );
file->WriteBigArray( lineDraw.indices.Ptr(), lineDraw.indices.Num() );
}
break;
}
case SWF_DICT_SPRITE:
{
2012-11-26 18:58:24 +00:00
dictionary[i].sprite->Write( file );
break;
}
case SWF_DICT_FONT:
{
idSWFFont* font = dictionary[i].font;
2012-11-26 18:58:24 +00:00
file->WriteString( font->fontID->GetName() );
file->WriteBig( font->ascent );
file->WriteBig( font->descent );
file->WriteBig( font->leading );
file->WriteBig( font->glyphs.Num() );
for( int g = 0; g < font->glyphs.Num(); g++ )
{
2012-11-26 18:58:24 +00:00
file->WriteBig( font->glyphs[g].code );
file->WriteBig( font->glyphs[g].advance );
file->WriteBig( font->glyphs[g].verts.Num() );
file->WriteBigArray( font->glyphs[g].verts.Ptr(), font->glyphs[g].verts.Num() );
file->WriteBig( font->glyphs[g].indices.Num() );
file->WriteBigArray( font->glyphs[g].indices.Ptr(), font->glyphs[g].indices.Num() );
}
break;
}
case SWF_DICT_TEXT:
{
idSWFText* text = dictionary[i].text;
2012-11-26 18:58:24 +00:00
file->WriteBig( text->bounds.tl );
file->WriteBig( text->bounds.br );
file->WriteBigArray( ( float* )&text->matrix, 6 );
2012-11-26 18:58:24 +00:00
file->WriteBig( text->textRecords.Num() );
for( int t = 0; t < text->textRecords.Num(); t++ )
{
idSWFTextRecord& textRecord = text->textRecords[t];
2012-11-26 18:58:24 +00:00
file->WriteBig( textRecord.fontID );
file->Write( &textRecord.color, 4 );
file->WriteBig( textRecord.xOffset );
file->WriteBig( textRecord.yOffset );
file->WriteBig( textRecord.textHeight );
file->WriteBig( textRecord.firstGlyph );
file->WriteBig( textRecord.numGlyphs );
}
file->WriteBig( text->glyphs.Num() );
for( int g = 0; g < text->glyphs.Num(); g++ )
{
2012-11-26 18:58:24 +00:00
file->WriteBig( text->glyphs[g].index );
file->WriteBig( text->glyphs[g].advance );
}
break;
}
case SWF_DICT_EDITTEXT:
{
idSWFEditText* edittext = dictionary[i].edittext;
2012-11-26 18:58:24 +00:00
file->WriteBig( edittext->bounds.tl );
file->WriteBig( edittext->bounds.br );
file->WriteBig( edittext->flags );
file->WriteBig( edittext->fontID );
file->WriteBig( edittext->fontHeight );
file->Write( &edittext->color, 4 );
file->WriteBig( edittext->maxLength );
file->WriteBig( edittext->align );
file->WriteBig( edittext->leftMargin );
file->WriteBig( edittext->rightMargin );
file->WriteBig( edittext->indent );
file->WriteBig( edittext->leading );
file->WriteString( edittext->variable );
file->WriteString( edittext->initialText );
break;
}
}
}
}
2013-03-25 17:52:29 +00:00
<<<<<<< HEAD
/*
===================
idSWF::FileAttributes
Extra data that won't fit in a SWF header
===================
*/
void idSWF::FileAttributes( idSWFBitStream& bitstream )
{
bitstream.Seek( 5 ); // 5 booleans
}
/*
===================
idSWF::Metadata
===================
*/
void idSWF::Metadata( idSWFBitStream& bitstream )
{
bitstream.ReadString(); // XML string
}
/*
===================
idSWF::SetBackgroundColor
===================
*/
void idSWF::SetBackgroundColor( idSWFBitStream& bitstream )
{
bitstream.Seek( 4 ); // int
}
2013-03-25 17:52:29 +00:00
=======
// RB begin
/*
===================
2015-06-06 21:28:51 +00:00
idSWF::WriteJSON
2013-03-25 17:52:29 +00:00
===================
*/
2015-06-06 21:28:51 +00:00
void idSWF::WriteJSON( const char* filename )
2013-03-25 17:52:29 +00:00
{
2014-05-15 14:58:48 +00:00
const bool exportBitmapShapesOnly = false;
2013-03-25 17:52:29 +00:00
idFileLocal file( fileSystem->OpenFileWrite( filename, "fs_basepath" ) );
if( file == NULL )
{
return;
}
2015-06-06 21:28:51 +00:00
//file->WriteFloatString( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" );
file->WriteFloatString( "{\n \t\"version\": %i,\n \t\"timestamp\": %i,\n \t\"frameWidth\": %f,\n \t\"frameHeight\": %f,\n \t\"frameRate\": %i,\n", XSWF_VERSION, timestamp, frameWidth, frameHeight, frameRate );
2013-03-25 17:52:29 +00:00
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\"dict\":\n\t[\n" );
2013-03-25 17:52:29 +00:00
for( int i = 0; i < dictionary.Num(); i++ )
{
const idSWFDictionaryEntry& entry = dictionary[i];
2015-06-06 21:28:51 +00:00
if( dictionary[i].type != SWF_DICT_NULL )
{
file->WriteFloatString( "\t\t{\n" );
file->WriteFloatString( "\t\t\t\"type\": \"%s\",\n", idSWF::GetDictTypeName( dictionary[i].type ) );
file->WriteFloatString( "\t\t\t\"characterID\": %i,\n", i );
}
2013-03-25 17:52:29 +00:00
switch( dictionary[i].type )
{
case SWF_DICT_IMAGE:
{
if( dictionary[i].material )
{
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\"material\": \"%s\"", dictionary[i].material->GetName() );
2013-03-25 17:52:29 +00:00
}
else
{
2015-06-06 21:28:51 +00:00
idStr filenameWithoutExt = filename;
filenameWithoutExt.StripFileExtension();
2015-06-06 23:07:13 +00:00
file->WriteFloatString( "\t\t\t\"imagefile\": \"%s/image_characterid_%i.png\",\n", filenameWithoutExt.c_str(), i );
2013-03-25 17:52:29 +00:00
}
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\"width\": %i, \"height\": %i, \"atlasOffsetX\": %i, \"atlasOffsetY\": %i,\n",
2013-03-25 17:52:29 +00:00
entry.imageSize[0], entry.imageSize[1], entry.imageAtlasOffset[0], entry.imageAtlasOffset[1] );
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\"channelScale\": { \"x\": %f, \"y\": %f, \"z\": %f, \"w\": %f }\n", entry.channelScale.x, entry.channelScale.y, entry.channelScale.z, entry.channelScale.w );
2013-03-25 17:52:29 +00:00
break;
}
2015-06-06 21:28:51 +00:00
#if 1
2013-03-25 17:52:29 +00:00
case SWF_DICT_MORPH:
case SWF_DICT_SHAPE:
{
idSWFShape* shape = dictionary[i].shape;
float x = shape->startBounds.tl.y;
float y = shape->startBounds.tl.x;
float width = fabs( shape->startBounds.br.y - shape->startBounds.tl.y );
float height = fabs( shape->startBounds.br.x - shape->startBounds.tl.x );
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\"startBounds\": { \"x\": %f, \"y\": %f, \"width\": %f, \"height\": %f },\n", x, y, width, height );
2013-03-25 17:52:29 +00:00
x = shape->endBounds.tl.y;
y = shape->endBounds.tl.x;
width = fabs( shape->endBounds.br.y - shape->endBounds.tl.y );
height = fabs( shape->endBounds.br.x - shape->endBounds.tl.x );
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\"endBounds\": { \"x\": %f, \"y\": %f, \"width\": %f, \"height\": %f },\n", x, y, width, height );
2013-03-25 17:52:29 +00:00
2013-03-25 20:17:11 +00:00
// export fill draws
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\"fillDraws\":\n\t\t\t[\n" );
2013-03-25 20:17:11 +00:00
2013-03-25 17:52:29 +00:00
for( int d = 0; d < shape->fillDraws.Num(); d++ )
{
idSWFShapeDrawFill& fillDraw = shape->fillDraws[d];
2014-05-15 14:58:48 +00:00
if( exportBitmapShapesOnly && fillDraw.style.type != 4 )
2013-03-27 12:15:09 +00:00
{
continue;
}
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\t{\n" );
2013-03-27 12:15:09 +00:00
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\t\t\"style\":\n\t\t\t\t\t{\n\t\t\t\t\t\t\"type\": " );
2013-03-25 17:52:29 +00:00
// 0 = solid, 1 = gradient, 4 = bitmap
if( fillDraw.style.type == 0 )
{
file->WriteFloatString( "\"solid\"" );
}
else if( fillDraw.style.type == 1 )
{
file->WriteFloatString( "\"gradient\"" );
}
else if( fillDraw.style.type == 4 )
{
file->WriteFloatString( "\"bitmap\"" );
}
else
{
file->WriteFloatString( "\"%i\"", fillDraw.style.type );
}
// 0 = linear, 2 = radial, 3 = focal; 0 = repeat, 1 = clamp, 2 = near repeat, 3 = near clamp
2015-06-06 21:28:51 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\t\"subType\": " );
2013-03-25 17:52:29 +00:00
if( fillDraw.style.subType == 0 )
{
file->WriteFloatString( "\"linear\"" );
}
else if( fillDraw.style.subType == 1 )
{
file->WriteFloatString( "\"radial\"" );
}
else if( fillDraw.style.subType == 2 )
{
file->WriteFloatString( "\"focal\"" );
}
else if( fillDraw.style.subType == 3 )
{
file->WriteFloatString( "\"near clamp\"" );
}
else
{
file->WriteFloatString( "\"%i\"", fillDraw.style.subType );
}
if( fillDraw.style.type == 1 && fillDraw.style.subType == 3 )
{
2015-06-06 21:28:51 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\t\"focalPoint\": %f", fillDraw.style.focalPoint );
2013-03-25 17:52:29 +00:00
}
if( fillDraw.style.type == 4 )
{
2015-06-06 21:28:51 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\t\"bitmapID\": %i", fillDraw.style.bitmapID );
2013-03-25 17:52:29 +00:00
}
if( fillDraw.style.type == 0 )
{
idVec4 color = fillDraw.style.startColor.ToVec4();
2015-06-06 21:28:51 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\t\"startColor\": [ %f, %f, %f, %f ]", color.x, color.y, color.z, color.w );
2013-03-25 17:52:29 +00:00
color = fillDraw.style.endColor.ToVec4();
2015-06-06 21:28:51 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\t\"endColor\": [ %f, %f, %f, %f ],\n", color.x, color.y, color.z, color.w );
2013-03-25 17:52:29 +00:00
}
if( fillDraw.style.type > 0 )
{
swfMatrix_t m = fillDraw.style.startMatrix;
2015-06-06 21:28:51 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\t\"startMatrix\": [ %f, %f, %f, %f, %f, %f ]", m.xx, m.yy, m.xy, m.yx, m.tx, m.ty );
2014-05-15 14:58:48 +00:00
if( fillDraw.style.startMatrix != fillDraw.style.endMatrix )
{
m = fillDraw.style.endMatrix;
2015-06-06 21:28:51 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\t\"endMatrix\": [ %f, %f, %f, %f, %f, %f ],\n", m.xx, m.yy, m.xy, m.yx, m.tx, m.ty );
2014-05-15 14:58:48 +00:00
}
2013-03-25 17:52:29 +00:00
}
2015-06-06 21:28:51 +00:00
if( fillDraw.style.gradient.numGradients )
2013-03-25 17:52:29 +00:00
{
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\t\t\"gradients\":\n\t\t\t\t\t[\n" );
2013-03-25 17:52:29 +00:00
2015-06-06 21:28:51 +00:00
for( int g = 0; g < fillDraw.style.gradient.numGradients; g++ )
2014-05-15 14:58:48 +00:00
{
2015-06-06 21:28:51 +00:00
swfGradientRecord_t gr = fillDraw.style.gradient.gradientRecords[g];
file->WriteFloatString( "\t\t\t\t\t<GradientRecord startRatio=\"%i\" endRatio=\"%i\">\n", gr.startRatio, gr.endRatio );
idVec4 color = gr.startColor.ToVec4();
file->WriteFloatString( "\t\t\t\t\t\t<StartColor r=\"%f\" g=\"%f\" b=\"%f\" a=\"%f\"/>\n",
color.x, color.y, color.z, color.w );
idVec4 endColor = gr.endColor.ToVec4();
if( color != endColor )
{
file->WriteFloatString( "\t\t\t\t\t\t<EndColor r=\"%f\" g=\"%f\" b=\"%f\" a=\"%f\"/>\n",
color.x, color.y, color.z, endColor.w );
}
file->WriteFloatString( "\t\t\t\t\t\t}%s\n", ( g == ( fillDraw.style.gradient.numGradients - 1 ) ) ? "" : "," );
2014-05-15 14:58:48 +00:00
}
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\t\t\t],\n" );
2013-03-25 17:52:29 +00:00
}
2015-06-06 23:07:13 +00:00
file->WriteFloatString( "\n\t\t\t\t\t},\n" );
2013-03-25 17:52:29 +00:00
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\t\t\"startVerts\":\n\t\t\t\t\t[\n" );
2013-03-25 17:52:29 +00:00
for( int v = 0; v < fillDraw.startVerts.Num(); v++ )
{
const idVec2& vert = fillDraw.startVerts[v];
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\t\t\t{ \"v\": [ %f, %f ] }%s\n", vert.x, vert.y, ( v == ( fillDraw.startVerts.Num() - 1 ) ) ? "" : "," );
2013-03-25 17:52:29 +00:00
}
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\t\t],\n" );
2013-03-25 17:52:29 +00:00
2015-06-06 21:28:51 +00:00
if( fillDraw.endVerts.Num() )
2013-03-25 17:52:29 +00:00
{
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\t\t\"endVerts\":\n\t\t\t\t\t[\n" );
for( int v = 0; v < fillDraw.endVerts.Num(); v++ )
{
const idVec2& vert = fillDraw.endVerts[v];
file->WriteFloatString( "\t\t\t\t\t\t{ \"v\": [ %f, %f ] }%s\n", vert.x, vert.y, ( v == ( fillDraw.endVerts.Num() - 1 ) ) ? "" : "," );
}
file->WriteFloatString( "\t\t\t\t\t],\n" );
2013-03-25 17:52:29 +00:00
}
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\t\t\"indices\": [ " );
2013-03-25 17:52:29 +00:00
for( int v = 0; v < fillDraw.indices.Num(); v++ )
{
const uint16& vert = fillDraw.indices[v];
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "%i%s", vert, ( v == fillDraw.indices.Num() - 1 ) ? "" : ", " );
2013-03-25 17:52:29 +00:00
}
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "]\n" );
2013-03-25 17:52:29 +00:00
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t\t}%s\n", ( d == ( shape->fillDraws.Num() - 1 ) ) ? "" : "," );
2013-03-25 17:52:29 +00:00
}
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t\t\t]\n" );
2013-03-25 20:17:11 +00:00
// export line draws
2015-06-06 21:28:51 +00:00
#if 0
2013-03-25 20:17:11 +00:00
for( int d = 0; d < shape->lineDraws.Num(); d++ )
2013-03-25 17:52:29 +00:00
{
2013-03-25 20:17:11 +00:00
const idSWFShapeDrawLine& lineDraw = shape->lineDraws[d];
file->WriteFloatString( "\t\t\t<LineDraw>\n" );
file->WriteFloatString( "\t\t\t\t<LineStyle startWidth=\"%i\" endWidth=\"%i\">\n", lineDraw.style.startWidth, lineDraw.style.endWidth );
idVec4 color = lineDraw.style.startColor.ToVec4();
file->WriteFloatString( "\t\t\t\t\t<StartColor r=\"%f\" g=\"%f\" b=\"%f\" a=\"%f\"/>\n",
color.x, color.y, color.z, color.w );
2014-05-15 14:58:48 +00:00
idVec4 endColor = lineDraw.style.endColor.ToVec4();
if( color != endColor )
{
file->WriteFloatString( "\t\t\t\t\t<EndColor r=\"%f\" g=\"%f\" b=\"%f\" a=\"%f\"/>\n",
endColor.x, endColor.y, endColor.z, endColor.w );
2014-05-15 14:58:48 +00:00
}
2013-03-25 20:17:11 +00:00
file->WriteFloatString( "\t\t\t\t</LineStyle>\n" );
for( int v = 0; v < lineDraw.startVerts.Num(); v++ )
2013-03-25 17:52:29 +00:00
{
2013-03-25 20:17:11 +00:00
const idVec2& vert = lineDraw.startVerts[v];
file->WriteFloatString( "\t\t\t\t<StartVertex x=\"%f\" y=\"%f\"/>\n", vert.x, vert.y );
2013-03-25 17:52:29 +00:00
}
2013-03-25 20:17:11 +00:00
for( int v = 0; v < lineDraw.endVerts.Num(); v++ )
{
const idVec2& vert = lineDraw.endVerts[v];
file->WriteFloatString( "\t\t\t\t<EndVertex x=\"%f\" y=\"%f\"/>\n", vert.x, vert.y );
}
file->WriteFloatString( "\t\t\t\t<Indices num=\"%i\">", lineDraw.indices.Num() );
for( int v = 0; v < lineDraw.indices.Num(); v++ )
{
const uint16& vert = lineDraw.indices[v];
file->WriteFloatString( "%i ", vert );
}
file->WriteFloatString( "</Indices>\n" );
2013-03-25 17:52:29 +00:00
}
2013-03-27 12:15:09 +00:00
#endif
2013-03-25 17:52:29 +00:00
break;
}
2015-06-06 21:28:51 +00:00
#endif
2013-03-25 20:17:11 +00:00
case SWF_DICT_SPRITE:
{
2015-06-06 23:07:13 +00:00
dictionary[i].sprite->WriteJSON( file, i );
2013-03-25 17:52:29 +00:00
break;
}
2013-03-25 23:06:38 +00:00
2013-03-25 17:52:29 +00:00
case SWF_DICT_FONT:
{
2013-03-25 23:06:38 +00:00
const idSWFFont* font = dictionary[i].font;
2013-03-26 17:07:01 +00:00
file->WriteFloatString( "\t\t<Font characterID=\"%i\" name=\"%s\" ascent=\"%i\" descent=\"%i\" leading=\"%i\" glyphsNum=\"%i\">\n",
i, font->fontID->GetName(), font->ascent, font->descent, font->leading, font->glyphs.Num() );
2013-03-25 23:06:38 +00:00
2014-05-15 14:58:48 +00:00
#if 0
2013-03-25 17:52:29 +00:00
for( int g = 0; g < font->glyphs.Num(); g++ )
{
2013-03-25 23:06:38 +00:00
file->WriteFloatString( "\t\t\t<Glyph code=\"%i\" advance=\"%i\"/>\n", font->glyphs[g].code, font->glyphs[g].advance );
#if 0
for( int v = 0; v < font->glyphs[g].verts.Num(); v++ )
{
const idVec2& vert = font->glyphs[g].verts[v];
file->WriteFloatString( "\t\t\t\t<Vertex x=\"%f\" y=\"%f\"/>\n", vert.x, vert.y );
}
file->WriteFloatString( "\t\t\t\t<Indices num=\"%i\">", font->glyphs[g].indices.Num() );
for( int v = 0; v < font->glyphs[g].indices.Num(); v++ )
{
const uint16& vert = font->glyphs[g].indices[v];
file->WriteFloatString( "%i ", vert );
}
file->WriteFloatString( "</Indices>\n" );
file->WriteFloatString( "\t\t\t</Glyph>\n" );
#endif
2013-03-25 17:52:29 +00:00
}
2014-05-15 14:58:48 +00:00
#endif
2013-03-25 23:27:58 +00:00
file->WriteFloatString( "\t\t</Font>\n" );
2013-03-25 17:52:29 +00:00
break;
}
2013-03-25 23:06:38 +00:00
2013-03-25 17:52:29 +00:00
case SWF_DICT_TEXT:
{
2013-03-25 23:06:38 +00:00
const idSWFText* text = dictionary[i].text;
2013-03-26 17:07:01 +00:00
file->WriteFloatString( "\t\t<Text characterID=\"%i\">\n", i );
2013-03-25 23:06:38 +00:00
float x = text->bounds.tl.y;
float y = text->bounds.tl.x;
float width = fabs( text->bounds.br.y - text->bounds.tl.y );
float height = fabs( text->bounds.br.x - text->bounds.tl.x );
2013-03-25 23:27:58 +00:00
file->WriteFloatString( "\t\t\t<Bounds x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" />\n", x, y, width, height );
2013-03-25 23:06:38 +00:00
//file->WriteBig( text->bounds.tl );
//file->WriteBig( text->bounds.br );
//file->WriteBigArray( ( float* )&text->matrix, 6 );
swfMatrix_t m = text->matrix;
2013-03-25 23:27:58 +00:00
file->WriteFloatString( "\t\t\t<Matrix>%f %f %f %f %f %f</Matrix>\n",
2013-03-25 23:06:38 +00:00
m.xx, m.yy, m.xy, m.yx, m.tx, m.ty );
//file->WriteBig( text->textRecords.Num() );
2013-03-25 17:52:29 +00:00
for( int t = 0; t < text->textRecords.Num(); t++ )
{
2013-03-25 23:06:38 +00:00
const idSWFTextRecord& textRecord = text->textRecords[t];
file->WriteFloatString( "\t\t\t\t<Record fontID=\"%i\" xOffet=\"%i\" yOffset=\"%i\" textHeight=\"%f\" firstGlyph=\"%i\" numGlyphs=\"%i\">\n",
textRecord.fontID, textRecord.xOffset, textRecord.yOffset, textRecord.textHeight, textRecord.firstGlyph, textRecord.numGlyphs );
idVec4 color = textRecord.color.ToVec4();
file->WriteFloatString( "\t\t\t\t\t<Color r=\"%f\" g=\"%f\" b=\"%f\" a=\"%f\"/>\n",
color.x, color.y, color.z, color.w );
file->WriteFloatString( "\t\t\t\t</Record>\n" );
/*file->WriteBig( textRecord.fontID );
2013-03-25 17:52:29 +00:00
file->Write( &textRecord.color, 4 );
file->WriteBig( textRecord.xOffset );
file->WriteBig( textRecord.yOffset );
file->WriteBig( textRecord.textHeight );
file->WriteBig( textRecord.firstGlyph );
2013-03-25 23:06:38 +00:00
file->WriteBig( textRecord.numGlyphs );*/
2013-03-25 17:52:29 +00:00
}
2013-03-25 23:06:38 +00:00
for( int g = 0; g < text->glyphs.Num(); g++ )
{
file->WriteFloatString( "\t\t\t\t<Glyph index=\"%i\" advance=\"%i\">\n", text->glyphs[g].index, text->glyphs[g].advance );
}
/*
2013-03-25 17:52:29 +00:00
file->WriteBig( text->glyphs.Num() );
for( int g = 0; g < text->glyphs.Num(); g++ )
{
file->WriteBig( text->glyphs[g].index );
file->WriteBig( text->glyphs[g].advance );
}
2013-03-25 23:06:38 +00:00
*/
2013-03-25 23:27:58 +00:00
file->WriteFloatString( "\t\t</Text>\n" );
2013-03-25 17:52:29 +00:00
break;
}
2013-03-25 23:06:38 +00:00
2013-03-25 17:52:29 +00:00
case SWF_DICT_EDITTEXT:
{
2013-03-25 23:06:38 +00:00
const idSWFEditText* et = dictionary[i].edittext;
2013-03-26 17:07:01 +00:00
file->WriteFloatString( "\t\t<EditText characterID=\"%i\" flags=\"%i\" fontID=\"%i\" fontHeight=\"%i\" maxLength=\"%i\" align=\"%s\" leftMargin=\"%i\" rightMargin=\"%i\" indent=\"%i\" leading=\"%i\" variable=\"%s\" initialText=\"%s\">\n",
i,
2013-03-25 23:06:38 +00:00
et->flags, et->fontID, et->fontHeight, et->maxLength, idSWF::GetEditTextAlignName( et->align ),
et->leftMargin, et->rightMargin, et->indent, et->leading,
et->variable.c_str(), et->initialText.c_str() );
float x = et->bounds.tl.y;
float y = et->bounds.tl.x;
float width = fabs( et->bounds.br.y - et->bounds.tl.y );
float height = fabs( et->bounds.br.x - et->bounds.tl.x );
2013-03-25 23:27:58 +00:00
file->WriteFloatString( "\t\t\t<Bounds x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" />\n", x, y, width, height );
2013-03-25 23:06:38 +00:00
idVec4 color = et->color.ToVec4();
2013-03-25 23:27:58 +00:00
file->WriteFloatString( "\t\t\t<Color r=\"%f\" g=\"%f\" b=\"%f\" a=\"%f\"/>\n",
2013-03-25 23:06:38 +00:00
color.x, color.y, color.z, color.w );
2013-03-25 23:27:58 +00:00
file->WriteFloatString( "\t\t</EditText>\n" );
2013-03-25 23:06:38 +00:00
//file->WriteBig( et->bounds.tl );
//file->WriteBig( et->bounds.br );
//file->WriteBig( et->flags );
//file->WriteBig( et->fontID );
//file->WriteBig( et->fontHeight );
//file->Write( &et->color, 4 );
//file->WriteBig( et->maxLength );
//file->WriteBig( et->align );
//file->WriteBig( et->leftMargin );
//file->WriteBig( et->rightMargin );
//file->WriteBig( et->indent );
//file->WriteBig( et->leading );
//file->WriteString( et->variable );
//file->WriteString( et->initialText );
2013-03-25 17:52:29 +00:00
break;
}
}
2013-03-25 23:06:38 +00:00
2015-06-06 21:28:51 +00:00
if( dictionary[i].type != SWF_DICT_NULL )
{
file->WriteFloatString( "\t\t}%s\n", ( i == ( dictionary.Num() - 1 ) ) ? "" : "," );
}
2013-03-25 17:52:29 +00:00
}
2013-03-25 23:06:38 +00:00
2015-06-06 21:28:51 +00:00
file->WriteFloatString( "\t],\n" );
2013-03-25 17:52:29 +00:00
2015-06-06 23:07:13 +00:00
file->WriteFloatString( "\t\"mainsprite\":\n\t{\n" );
mainsprite->WriteJSON( file, dictionary.Num() );
file->WriteFloatString( "\t}\n}\n" );
2013-03-25 17:52:29 +00:00
}
// RB end
>>>>>>> c4098bc... XML Flash part 1