예제 #1
0
	//----------------------------------------------------------------//
	void Load ( u32 transform = 0 ) {
	
		if ( this->mType != TYPE_UNKNOWN ) {
			return;
		}
		
		this->mTransform |= transform;
		
		if ( !this->mImage.IsOK ()) {
	
			if ( this->mFileData ) {
				this->mImage.Load ( this->mFileData, ( u32 )this->mFileDataSize, this->mTransform );
				free ( this->mFileData );
				this->mFileData = 0;
			}
			else if ( mFilename.size ()) {
				this->mImage.Load ( this->mFilename, this->mTransform );
			}
		}
		
		if ( this->mImage.IsOK ()) {
			this->mType = TYPE_MOAI_IMAGE;
		}
		#ifdef MOAI_TEST_PVR
			else {
				// get file data, check if PVR
				USFileStream stream;
				stream.OpenRead ( this->mFilename );
	
				if ( this->mFileData ) {
					free ( this->mFileData );
					this->mFileData = 0;
				}
				
				this->mFileDataSize = stream.GetLength ();
				this->mFileData = malloc ( this->mFileDataSize );
				stream.ReadBytes ( this->mFileData, this->mFileDataSize );
	
				stream.Close ();
				
				if ( MOAIPvrHeader::GetHeader( this->mFileData, this->mFileDataSize )) {				
					this->mType = TYPE_PVR;
				}
			}
		#endif
		
		if ( this->mType == TYPE_UNKNOWN ) {
			this->mType = TYPE_FAIL;
			this->Release ();
		}
	}
예제 #2
0
//----------------------------------------------------------------//
bool USData::Load ( cc8* filename ) {

	USFileStream in;
	if ( !in.OpenRead ( filename )) return false;

	this->mMutex.Lock ();

	u32 size = in.GetLength ();
	this->mBytes.Init ( size );
	in.ReadBytes ( this->mBytes , size );

	this->mMutex.Unlock ();

	return true;
}
예제 #3
0
//----------------------------------------------------------------//
int main ( int argc, char** argv ) {

	if ( argc < 3 ) return 0;
	
	cc8* infile = argv [ 1 ];
	cc8* outfile = argv [ 2 ];
	
	USFileStream file;
	file.OpenRead ( infile );
	
	size_t size = file.GetLength ();
	void* data = malloc ( size );
	file.ReadBytes ( data, size );
	
	_dumpAsCPPHeader ( outfile, data, size, 16 );
	
	free ( data );
	return 0;
}
예제 #4
0
//----------------------------------------------------------------//
void MOAIFont::InitWithBMFont ( cc8* filename ) {

	USFileStream stream;
	if ( !stream.OpenRead ( filename )) return;

	u32 len = stream.GetLength ();
	char* buf = ( char* )malloc ( len + 1 );
	stream.ReadBytes ( buf, len );
	buf [ len ] = '\0';
	stream.Close ();

	char* p = buf;
	char* endp = p + len;

	MOAIGlyphSet* glyphSet = 0;
	MOAIStaticGlyphCache* glyphCache = new MOAIStaticGlyphCache ();

	this->mCache.Set ( *this, glyphCache );
	this->mReader.Set ( *this, 0 );

	p = buf;
	while ( p < endp ) {
	
		// Parse each line.
		bool endl;
		char* key;
		char* val;

		p = parseKeyVal ( p, &key, &val, &endl );

		if ( strcmp ( key, "info" ) == 0 ) {
		
			float size = 0.0f;
			
			//info face="Cambria" size=64 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2
			do {
				p = parseKeyVal ( p, &key, &val, &endl );
				if ( strcasecmp ( key, "size" ) == 0 ) { size = ( float )atof ( val ); }
			} while ( !endl );
			
			if ( size > 0.0f ) {
				glyphSet = &this->AffirmGlyphSet ( size );
				assert ( glyphSet );
			}
		}
		else if ( strcmp ( key, "common" ) == 0 ) {
			
			float lineSpacing = 0.0f;
			float base = 0.0f;
			u32 pages = 0;
			
			//common lineHeight=75 base=61 scaleW=512 scaleH=512 pages=1 packed=0
			do {
				p = parseKeyVal ( p, &key, &val, &endl );
				if ( strcasecmp ( key, "lineHeight" ) == 0 ) { lineSpacing = ( float )atof ( val ); }
				else if ( strcasecmp ( key, "pages" ) == 0 ) { pages = ( u32 )atoi ( val ); }
				else if ( strcasecmp ( key, "base" ) == 0 ) { base = ( float )atof ( val ); }
			} while ( !endl );
			
			glyphSet->SetHeight( lineSpacing );
			glyphSet->SetAscent( base );
			glyphCache->ReserveTextures ( pages );
		}
		else if ( strcmp ( key, "page" ) == 0 ) {
			
			STLString texturename;
			u32 id = 0;
		
			//page id=0 file="Blah.png"
			do {
				p = parseKeyVal ( p, &key, &val, &endl );
				if( strcmp(key, "id") == 0 ) { id = ( u32 )atoi ( val ); }
				else if ( strcmp ( key, "file" ) == 0 ) { texturename = val; }
			} while ( !endl );
			
			MOAITexture* texture = new MOAITexture ();
			glyphCache->SetTexture ( id, texture );
			texture->Init ( texturename, MOAITexture::DEFAULT_TRANSFORM );
		}
		else if ( strcmp ( key, "chars" ) == 0 ) {
			//chars count=95
			do {
				p = parseKeyVal ( p, &key, &val, &endl );
			} while ( !endl );
		}
		else if ( strcmp ( key, "char" ) == 0 ) {
			
			//char id=47 x=2 y=2 width=32 height=63 xoffset=1 yoffset=15 xadvance=31 page=0 chnl=0 letter="/"
			u32 c = 0;
			u32 x = 0;
			u32 y = 0;
			float width = 0.0f;
			float height = 0.0f;
			float xoff = 0.0f;
			float yoff = 0.0f;
			float xadv = 0.0f;
			u32 page = 0;
			
			do {
				p = parseKeyVal ( p, &key, &val, &endl );
				if ( strcasecmp ( key, "id" ) == 0 ) { c = ( u32 )atoi ( val ); }
				else if ( strcasecmp ( key, "x" ) == 0 ) { x = ( u32 )atoi ( val ); }
				else if ( strcasecmp ( key, "y" ) == 0 ) { y = ( u32 )atoi ( val ); }
				else if ( strcasecmp ( key, "width" ) == 0 ) { width = ( float )atof ( val ); }
				else if ( strcasecmp ( key, "height" ) == 0 ) { height = ( float )atof ( val ); }
				else if ( strcasecmp ( key, "xoffset" ) == 0 ) { xoff = ( float )atof ( val ); }
				else if ( strcasecmp ( key, "yoffset" ) == 0 ) { yoff = ( float )atof ( val ); }
				else if ( strcasecmp ( key, "xadvance" ) == 0 ) { xadv = ( float )atof ( val ); }
				else if ( strcasecmp ( key, "page" ) == 0 ) { page = ( u32 )atoi ( val ); }

			} while( !endl );
			
			assert ( glyphSet );
			MOAIGlyph& glyph = glyphSet->EditGlyph ( c );
			
			glyph.mSrcX = x;
			glyph.mSrcY = y;
			glyph.mPageID = page;
			glyph.mWidth = width;
			glyph.mHeight = height;
			glyph.mAdvanceX = xadv;
			glyph.mBearingX = xoff;
			glyph.mBearingY = glyphSet->GetAscent() - yoff;
			
		}
		else if ( strcmp ( key, "kernings" ) == 0 ) {
			//kernings count=560
			do {
				p = parseKeyVal ( p, &key, &val, &endl );
			} while ( !endl );
		}
		else if ( strcmp ( key, "kerning" ) == 0 ) {
			
			//kerning first=47 second=65 amount=-1
			u32 first = 0;
			u32 second = 0;
			float amount = 0.0f;

			do {
				p = parseKeyVal ( p, &key, &val, &endl );
				if( strcasecmp ( key, "first" ) == 0 ) { first = ( u32 )atoi ( val ); }
				else if ( strcasecmp ( key, "second" ) == 0 ) { second = ( u32 )atoi ( val ); }
				else if ( strcasecmp ( key, "amount" ) == 0 ) { amount =( float )atof ( val ); }
			} while( !endl );
			
			if ( first && second && ( amount != 0.0f )) {
			
				assert ( glyphSet );
				MOAIGlyph& glyph = glyphSet->EditGlyph ( first );
				
				u32 i = glyph.mKernTable.Size();
				glyph.mKernTable.Grow ( i + 1 );
				glyph.mKernTable [ i ].mName = second;
				glyph.mKernTable [ i ].mX = amount;
				glyph.mKernTable [ i ].mY = 0;
			}
		}
	}
}
예제 #5
0
파일: USCgt.cpp 프로젝트: doches/moai-beta
//----------------------------------------------------------------//
void USCgt::Load ( cc8* filename ) {

	USFileStream stream;
	stream.OpenRead ( filename );

	this->mHeader = this->ReadUnicodeAsASCII ( stream );
	
	u32 length = stream.GetLength ();
	while ( stream.GetCursor () < length ) {
		
		char recordType = stream.Read < u8 >();
		assert ( recordType == 'M' );
		
		u16 totalEntries = stream.Read < u16 >();
		
		u8 contentType = this->ReadByteEntry ( stream );
		switch ( contentType ) {
			
			// Parameters
			case 'P': {
				
				this->mName = this->ReadStringEntry ( stream );
				this->mVersion = this->ReadStringEntry ( stream );
				this->mAuthor = this->ReadStringEntry ( stream );
				this->mAbout = this->ReadStringEntry ( stream );
				this->mCaseSensitive = this->ReadBoolEntry ( stream );
				this->mLALRStartSymbol = this->ReadIntEntry ( stream );
				
				break;
			}
			
			// Table Counts
			case 'T': {
				
				this->mSymbolTable.Init ( this->ReadIntEntry ( stream ));
				this->mCharSetTable.Init ( this->ReadIntEntry ( stream ));
				this->mRuleTable.Init ( this->ReadIntEntry ( stream ));
				this->mDFAStateTable.Init ( this->ReadIntEntry ( stream ));
				this->mLALRStateTable.Init ( this->ReadIntEntry ( stream ));
				
				break;
			}
			
			// Initial States
			case 'I': {
				
				this->mDFAInitialStateID = this->ReadIntEntry ( stream );
				this->mLALRInitialStateID = this->ReadIntEntry ( stream );
				
				break;
			}
			
			// Symbol Table Entry
			case 'S': {
				
				u16 index = this->ReadIntEntry ( stream );
				assert ( index < this->mSymbolTable.Size ());
				USCgtSymbol& symbol = this->mSymbolTable [ index ];
				
				symbol.mID = index;
				symbol.mName = this->ReadStringEntry ( stream );
				symbol.mKind = this->ReadIntEntry ( stream );
				
				break;
			}
			
			// Character Set Table Entry
			case 'C': {
			
				u16 index = this->ReadIntEntry ( stream );
				assert ( index < this->mCharSetTable.Size ());
				
				this->mCharSetTable [ index ].mCharacters = this->ReadStringEntry ( stream );
				
				break;
			}
			
			// Rule Table Entry
			case 'R': {
			
				u16 index = this->ReadIntEntry ( stream );
				assert ( index < this->mRuleTable.Size ());
				USCgtRule& rule = this->mRuleTable [ index ];
				
				rule.mRuleResult = this->ReadIntEntry ( stream );
				this->ReadEmptyEntry ( stream );
				
				// 4 is the # of entries read so far...
				u32 ruleSize = totalEntries - 4;
				rule.mRuleSymbols.Init ( ruleSize );
				for ( u32 i = 0; i < ruleSize; ++i ) {
					rule.mRuleSymbols [ i ] = this->ReadIntEntry ( stream );
				}
				break;
			}
			
			// DFA State Entry
			case 'D': {
			
				u16 index = this->ReadIntEntry ( stream );
				assert ( index < this->mDFAStateTable.Size ());
				USDfaState& dfaState = this->mDFAStateTable [ index ];
				
				dfaState.mID = index;
				dfaState.mAcceptState = this->ReadBoolEntry ( stream );
				dfaState.mAcceptSymbolID = this->ReadIntEntry ( stream );
				this->ReadEmptyEntry ( stream );
				
				// 5 is the # of entries read so far...
				u32 totalEdges = totalEntries - 5;
				assert (( totalEdges % 3 ) == 0 ); // Make sure it's a sensible number...
				totalEdges = ( u32 )( totalEdges / 3 ); // '3' is the size of each edge...
				
				dfaState.mEdges.Init ( totalEdges );
				
				for ( u32 i = 0; i < totalEdges; ++i ) {
					dfaState.mEdges [ i ].mCharSetID = this->ReadIntEntry ( stream );
					dfaState.mEdges [ i ].mTargetStateID = this->ReadIntEntry ( stream );
					this->ReadEmptyEntry ( stream );
				}
				break;
			}
			
			// LALR State Entry
			case 'L': {
			
				u16 index = this->ReadIntEntry ( stream );
				assert ( index < this->mLALRStateTable.Size ());
				USLalrState& lalrState = this->mLALRStateTable [ index ];
				
				lalrState.mID = index;
				this->ReadEmptyEntry ( stream );
				
				// 3 is the # of entries read so far...
				u32 totalActions = totalEntries - 3;
				assert (( totalActions % 4 ) == 0 ); // Make sure it's a sensible number...
				totalActions = ( u32 )( totalActions / 4 ); // '4' is the size of each edge...
				
				lalrState.mActions.Init ( totalActions );
				
				for ( u32 i = 0; i < totalActions; ++i ) {
					USLalrAction& action = lalrState.mActions [ i ];
					action.mInputSymbolID = this->ReadIntEntry ( stream );
					action.mActionType = this->ReadIntEntry ( stream );
					action.mTarget = this->ReadIntEntry ( stream );
					this->ReadEmptyEntry ( stream );
				}
				break;
			}
			
			// Unknown
			default: assert ( false );
		}
	}
}