doom3-bfg/neo/swf/SWF_Load.cpp

1033 lines
32 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"
#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-10-30 10:44:24 +00:00
/*
===================
idSWF::WriteSWF
RB: bring .bswf back to .swf
===================
*/
2013-11-06 20:46:35 +00:00
void idSWF::WriteSWF( const char* filename )
2013-10-30 10:44:24 +00:00
{
2013-11-06 20:46:35 +00:00
idFile_SWF file( fileSystem->OpenFileWrite( filename, "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
// TODO
2013-11-06 20:46:35 +00:00
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-06 20:46:35 +00:00
file.WriteRect( frameSize );
2013-10-30 10:44:24 +00:00
2013-11-06 20:46:35 +00:00
file.WriteU16( frameRate );
2013-10-30 10:44:24 +00:00
// parse everything
2013-11-06 20:46:35 +00:00
//mainsprite->Load( bitstream, true );
2013-10-30 10:44:24 +00:00
// now that all images have been loaded, write out the combined image
2013-11-06 20:46:35 +00:00
//idStr atlasFileName = "generated/";
//atlasFileName += fullpath;
//atlasFileName.SetFileExtension( ".tga" );
2013-10-30 10:44:24 +00:00
2013-11-06 20:46:35 +00:00
//WriteSwfImageAtlas( atlasFileName );
2013-10-30 10:44:24 +00:00
2013-11-06 20:46:35 +00:00
//Mem_Free( fileData );
2013-10-30 10:44:24 +00:00
// add Tag_End
2013-11-06 20:46:35 +00:00
file.WriteU16( Tag_End );
2013-10-30 10:44:24 +00:00
// go back and write filesize into header
uint32 fileSize = file->Length();
file->Seek( offsetof( swfHeader_t, fileLength ), FS_SEEK_SET );
file->WriteBig( fileSize );
}
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
/*
===================
idSWF::WriteXML
===================
*/
void idSWF::WriteXML( const char* filename )
{
idFileLocal file( fileSystem->OpenFileWrite( filename, "fs_basepath" ) );
if( file == NULL )
{
return;
}
file->WriteFloatString( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" );
file->WriteFloatString( "<XSWF version=\"%i\" timestamp=\"%i\" frameWidth=\"%f\" frameHeight=\"%f\" frameRate=\"%i\">\n", XSWF_VERSION, timestamp, frameWidth, frameHeight, frameRate );
file->WriteFloatString( "\t<Dictionary>\n" );
for( int i = 0; i < dictionary.Num(); i++ )
{
const idSWFDictionaryEntry& entry = dictionary[i];
//file->WriteFloatString( "\t<DictionaryEntry type=\"%s\">\n", idSWF::GetDictTypeName( dictionary[i].type ) );
switch( dictionary[i].type )
{
case SWF_DICT_IMAGE:
{
2013-03-26 17:07:01 +00:00
file->WriteFloatString( "\t\t<Image characterID=\"%i\" material=\"", i );
2013-03-25 17:52:29 +00:00
if( dictionary[i].material )
{
file->WriteFloatString( "%s\"", dictionary[i].material->GetName() );
}
else
{
file->WriteFloatString( ".\"" );
}
file->WriteFloatString( " width=\"%i\" height=\"%i\" atlasOffsetX=\"%i\" atlasOffsetY=\"%i\">\n",
entry.imageSize[0], entry.imageSize[1], entry.imageAtlasOffset[0], entry.imageAtlasOffset[1] );
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 );
file->WriteFloatString( "\t\t</Image>\n" );
break;
}
case SWF_DICT_MORPH:
case SWF_DICT_SHAPE:
{
idSWFShape* shape = dictionary[i].shape;
2013-03-26 17:07:01 +00:00
file->WriteFloatString( "\t\t<Shape characterID=\"%i\">\n", i );
2013-03-25 17:52:29 +00:00
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 );
file->WriteFloatString( "\t\t\t<StartBounds x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" />\n", x, y, width, height );
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 );
file->WriteFloatString( "\t\t\t<EndBounds x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" />\n", x, y, width, height );
2013-03-25 20:17:11 +00:00
// export fill draws
2013-03-25 17:52:29 +00:00
for( int d = 0; d < shape->fillDraws.Num(); d++ )
{
idSWFShapeDrawFill& fillDraw = shape->fillDraws[d];
2013-03-27 12:15:09 +00:00
if( fillDraw.style.type != 4 )
{
continue;
}
file->WriteFloatString( "\t\t\t<DrawFill>\n" );
2013-03-25 17:52:29 +00:00
file->WriteFloatString( "\t\t\t\t<FillStyle type=" );
// 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
file->WriteFloatString( " subType=" );
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 )
{
file->WriteFloatString( " focalPoint=\"%f\"", fillDraw.style.focalPoint );
}
if( fillDraw.style.type == 4 )
{
file->WriteFloatString( " bitmapID=\"%i\"", fillDraw.style.bitmapID );
}
2013-03-27 12:15:09 +00:00
file->WriteFloatString( ">\n" );
2013-03-25 17:52:29 +00:00
if( fillDraw.style.type == 0 )
{
idVec4 color = fillDraw.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 );
color = fillDraw.style.endColor.ToVec4();
file->WriteFloatString( "\t\t\t\t\t<EndColor r=\"%f\" g=\"%f\" b=\"%f\" a=\"%f\"/>\n",
color.x, color.y, color.z, color.w );
}
if( fillDraw.style.type > 0 )
{
swfMatrix_t m = fillDraw.style.startMatrix;
file->WriteFloatString( "\t\t\t\t\t<StartMatrix>%f %f %f %f %f %f</StartMatrix>\n",
m.xx, m.yy, m.xy, m.yx, m.tx, m.ty );
m = fillDraw.style.endMatrix;
file->WriteFloatString( "\t\t\t\t\t<EndMatrix>%f %f %f %f %f %f</EndMatrix>\n",
m.xx, m.yy, m.xy, m.yx, m.tx, m.ty );
}
for( int g = 0; g < fillDraw.style.gradient.numGradients; g++ )
{
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 );
color = gr.endColor.ToVec4();
file->WriteFloatString( "\t\t\t\t\t\t<EndColor r=\"%f\" g=\"%f\" b=\"%f\" a=\"%f\"/>\n",
color.x, color.y, color.z, color.w );
}
file->WriteFloatString( "\t\t\t\t</FillStyle>\n" );
for( int v = 0; v < fillDraw.startVerts.Num(); v++ )
{
const idVec2& vert = fillDraw.startVerts[v];
file->WriteFloatString( "\t\t\t\t<StartVertex x=\"%f\" y=\"%f\"/>\n", vert.x, vert.y );
}
for( int v = 0; v < fillDraw.endVerts.Num(); v++ )
{
const idVec2& vert = fillDraw.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\">", fillDraw.indices.Num() );
for( int v = 0; v < fillDraw.indices.Num(); v++ )
{
const uint16& vert = fillDraw.indices[v];
file->WriteFloatString( "%i ", vert );
}
file->WriteFloatString( "</Indices>\n" );
file->WriteFloatString( "\t\t\t</DrawFill>\n" );
}
2013-03-25 20:17:11 +00:00
// export line draws
2013-03-27 12:15:09 +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 );
color = lineDraw.style.endColor.ToVec4();
file->WriteFloatString( "\t\t\t\t\t<EndColor r=\"%f\" g=\"%f\" b=\"%f\" a=\"%f\"/>\n",
color.x, color.y, color.z, color.w );
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
file->WriteFloatString( "\t\t</Shape>\n" );
break;
}
2013-03-25 20:17:11 +00:00
case SWF_DICT_SPRITE:
{
2013-03-26 17:07:01 +00:00
dictionary[i].sprite->WriteXML( file, "\t\t", 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
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
}
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
//file->WriteFloatString( "\t</DictionaryEntry>\n" );
2013-03-25 17:52:29 +00:00
}
2013-03-25 23:06:38 +00:00
file->WriteFloatString( "\t</Dictionary>\n" );
2013-03-25 17:52:29 +00:00
2013-05-24 10:10:52 +00:00
mainsprite->WriteXML( file, "\t" );
2013-03-25 17:52:29 +00:00
file->WriteFloatString( "</XSWF>\n" );
}
// RB end
>>>>>>> c4098bc... XML Flash part 1