moai/src/moaicore/MOAIFont.cpp
//----------------------------------------------------------------//
// iterate through the pending glyphs in each set and attempt to
// update them to match target - i.e. metrics or metrics and bitmap
iterate through the pending glyphs in each set and attempt to
update them to match target - i.e. metrics or metrics and bitmap
iterate through the pending glyphs in each set and attempt to update them to match target - i . e . metrics or metrics and bitmap
void MOAIFont::BuildKerning ( MOAIGlyph* glyphs, MOAIGlyph* pendingGlyphs ) {
	if ( !this->mReader->HasKerning ()) return;
	MOAIKernVec kernTable [ MOAIGlyph::MAX_KERN_TABLE_SIZE ]; 
	for ( MOAIGlyph* glyphIt = glyphs; glyphIt; glyphIt = glyphIt->mNext ) {
		MOAIGlyph& glyph = *glyphIt;
		u32 kernTableSize = 0;
		u32 oldTableSize = glyph.mKernTable.Size ();
		for ( MOAIGlyph* glyphIt2 = pendingGlyphs; glyphIt2; glyphIt2 = glyphIt2->mNext ) {
			MOAIGlyph& glyph2 = *glyphIt2;
			bool unknown = true;
			for ( u32 i = 0; i < oldTableSize; ++i ) {
				if ( glyph.mKernTable [ i ].mName == glyph2.mCode ) {
					unknown = false;
					break;
				}
			} 
			if ( unknown ) {
				MOAIKernVec kernVec;
				if ( this->mReader->GetKernVec ( glyph, glyph2, kernVec )) {
					assert ( kernTableSize < MOAIGlyph::MAX_KERN_TABLE_SIZE );
					kernTable [ kernTableSize++ ] = kernVec;
				}
			}
		}
		if ( kernTableSize ) {
			glyph.mKernTable.Resize ( oldTableSize + kernTableSize );
			memcpy ( &glyph.mKernTable [ oldTableSize ], kernTable, sizeof ( MOAIKernVec ) * kernTableSize );
		}
	}
	for ( MOAIGlyph* glyphIt = pendingGlyphs; glyphIt; glyphIt = glyphIt->mNext ) {
		MOAIGlyph& glyph = *glyphIt;
		u32 kernTableSize = 0;
		for ( MOAIGlyph* glyphIt2 = glyphs; glyphIt2; glyphIt2 = glyphIt2->mNext ) {
			MOAIGlyph& glyph2 = *glyphIt2;
			MOAIKernVec kernVec;
			if ( this->mReader->GetKernVec ( glyph, glyph2, kernVec )) {
				assert ( kernTableSize < MOAIGlyph::MAX_KERN_TABLE_SIZE );
				kernTable [ kernTableSize++ ] = kernVec;
			}
		}
		for ( MOAIGlyph* glyphIt2 = pendingGlyphs; glyphIt2; glyphIt2 = glyphIt2->mNext ) {
			MOAIGlyph& glyph2 = *glyphIt2;
			MOAIKernVec kernVec;
			if ( this->mReader->GetKernVec ( glyph, glyph2, kernVec )) {
				assert ( kernTableSize < MOAIGlyph::MAX_KERN_TABLE_SIZE );
				kernTable [ kernTableSize++ ] = kernVec;
			}
		}
		if ( kernTableSize ) {
			glyph.mKernTable.Init ( kernTableSize );
			memcpy ( glyph.mKernTable, kernTable, sizeof ( MOAIKernVec ) * kernTableSize );
		}
	}
}
void MOAIFont :: BuildKerning ( MOAIGlyph * glyphs , MOAIGlyph * pendingGlyphs ) { if ( ! this -> mReader -> HasKerning ( ) ) return ; MOAIKernVec kernTable [ MOAIGlyph :: MAX_KERN_TABLE_SIZE ] ; for ( MOAIGlyph * glyphIt = glyphs ; glyphIt ; glyphIt = glyphIt -> mNext ) { MOAIGlyph & glyph = * glyphIt ; u32 kernTableSize = 0 ; u32 oldTableSize = glyph . mKernTable . Size ( ) ; for ( MOAIGlyph * glyphIt2 = pendingGlyphs ; glyphIt2 ; glyphIt2 = glyphIt2 -> mNext ) { MOAIGlyph & glyph2 = * glyphIt2 ; bool unknown = true ; for ( u32 i = 0 ; i < oldTableSize ; ++ i ) { if ( glyph . mKernTable [ i ] . mName == glyph2 . mCode ) { unknown = false ; break ; } } if ( unknown ) { MOAIKernVec kernVec ; if ( this -> mReader -> GetKernVec ( glyph , glyph2 , kernVec ) ) { assert ( kernTableSize < MOAIGlyph :: MAX_KERN_TABLE_SIZE ) ; kernTable [ kernTableSize ++ ] = kernVec ; } } } if ( kernTableSize ) { glyph . mKernTable . Resize ( oldTableSize + kernTableSize ) ; memcpy ( & glyph . mKernTable [ oldTableSize ] , kernTable , sizeof ( MOAIKernVec ) * kernTableSize ) ; } } for ( MOAIGlyph * glyphIt = pendingGlyphs ; glyphIt ; glyphIt = glyphIt -> mNext ) { MOAIGlyph & glyph = * glyphIt ; u32 kernTableSize = 0 ; for ( MOAIGlyph * glyphIt2 = glyphs ; glyphIt2 ; glyphIt2 = glyphIt2 -> mNext ) { MOAIGlyph & glyph2 = * glyphIt2 ; MOAIKernVec kernVec ; if ( this -> mReader -> GetKernVec ( glyph , glyph2 , kernVec ) ) { assert ( kernTableSize < MOAIGlyph :: MAX_KERN_TABLE_SIZE ) ; kernTable [ kernTableSize ++ ] = kernVec ; } } for ( MOAIGlyph * glyphIt2 = pendingGlyphs ; glyphIt2 ; glyphIt2 = glyphIt2 -> mNext ) { MOAIGlyph & glyph2 = * glyphIt2 ; MOAIKernVec kernVec ; if ( this -> mReader -> GetKernVec ( glyph , glyph2 , kernVec ) ) { assert ( kernTableSize < MOAIGlyph :: MAX_KERN_TABLE_SIZE ) ; kernTable [ kernTableSize ++ ] = kernVec ; } } if ( kernTableSize ) { glyph . mKernTable . Init ( kernTableSize ) ; memcpy ( glyph . mKernTable , kernTable , sizeof ( MOAIKernVec ) * kernTableSize ) ; } } }
iterate through the pending glyphs in each set and attempt to
update them to match target - i.e.
iterate through the pending glyphs in each set and attempt to update them to match target - i . e .
// TODO: handle overflow cases // iterate over the orignal glyphs and add kerning info for new glyphs // iterate over just the new glyphs; check each one against olf glyphs for kerning info // skip if glyph is already in old glyph's kerning table // may happen if glyphs are purged and then re-added // resize the old kerning table and copy in the new kern vecs (if any) // iterate over the new glyphs and add kerning info for all glyphs // iterate over the original glyphs // iterate over the new glyphs // init the kern table