/** @name getFont @text Gets the font. @in MOAIProfilerReportBox self @out MOAIFont font */ int MOAIProfilerReportBox::_getFont ( lua_State* L ) { MOAI_LUA_SETUP ( MOAIProfilerReportBox, "U" ) MOAIFont* font = self->GetFont (); if ( font ) { font->PushLuaUserdata ( state ); return 1; } return 0; }
/** @name getScale @text Returns the default size of this font for use with the MOAITextbox:setTextSize function. @in MOAIFont self @out number size The default point size of the font. */ int MOAIFont::_getScale ( lua_State* L ) { USLuaState state ( L ); if ( !state.CheckParams ( 1, "U" )) return 0; MOAIFont* self = state.GetLuaObject < MOAIFont >( 1 ); if ( !self ) return 0; lua_pushnumber ( state, self->GetScale ()); return 1; }
/** @name getFont @text Gets the font of the style. @in MOAITextStyle self @out MOAIFont font */ int MOAITextStyle::_getFont ( lua_State* L ) { MOAI_LUA_SETUP ( MOAITextStyle, "U" ) MOAIFont* font = self->GetFont (); if ( font ) { font->PushLuaUserdata ( state ); return 1; } return 0; }
//----------------------------------------------------------------// u32 MOAITextDesigner::NextChar () { bool newSpan = false; if ( !this->mStyleSpan ) { this->mStyleSpan = &this->mTextBox->mStyleMap.Elem ( 0 ); this->mSpanIdx = 0; newSpan = true; } if ( this->mIdx >= this->mStyleSpan->mTop ) { this->mStyleSpan = 0; u32 totalStyles = this->mTextBox->mStyleMap.GetTop (); for ( this->mSpanIdx++; this->mSpanIdx < totalStyles; this->mSpanIdx++ ) { MOAITextStyleSpan& styleSpan = this->mTextBox->mStyleMap.Elem ( this->mSpanIdx ); if ( this->mIdx < styleSpan.mTop ) { this->mStyleSpan = &styleSpan; newSpan = true; break; } } } if ( this->mStyleSpan ) { if ( newSpan ) { if ( this->mIdx < this->mStyleSpan->mBase ) { this->mIdx = this->mStyleSpan->mBase; } this->mStyle = this->mStyleSpan->mStyle; assert ( this->mStyle ); MOAIFont* font = this->mStyle->mFont; assert ( font ); this->mDeck = font->GetGlyphSet ( this->mStyle->mSize ); this->mDeckScale = this->mDeck && ( this->mStyle->mSize > 0.0f ) ? this->mStyle->mSize / this->mDeck->GetSize () : 1.0f; } this->mPrevIdx = this->mIdx; u32 c = u8_nextchar ( this->mStr, &this->mIdx ); return c; } return 0; }
//----------------------------------------------------------------// void MOAIStaticGlyphCache::SetImage ( MOAIFont& font, MOAIImage& image ) { this->ClearTextures (); u32 width = image.GetWidth (); u32 height = image.GetHeight (); if ( !( width && height )) return; u32 totalTextures = ( height / width ) + 1; this->mTextures.Init ( totalTextures ); u32 y = 0; for ( u32 i = 0; i < totalTextures; ++i ) { MOAITexture* texture = new MOAITexture (); this->mTextures [ i ] = texture; u32 textureHeight = height - y; textureHeight = textureHeight > width ? width : textureHeight; texture->Init ( image, 0, y, width, textureHeight, font.GetFilename ()); texture->SetFilter ( GL_LINEAR, GL_LINEAR ); y += textureHeight; } }
/** @name load @text Attempts to load glyphs from the specified image file or MOAIDataBuffer containing image data. @in MOAIFont self @opt string filename A string indicating the path to an image file. @opt MOAIDataBuffer data A MOAIDataBuffer containing image data. You must provide either a string or a MOAIDataBuffer, but not both. @in string charCodes A string which defines the characters found in the font. For example if A and B are the first letters in the image, the first characters in the string would be "AB" and so forth. @out nil */ int MOAIFont::_load ( lua_State* L ) { USLuaState state ( L ); if ( !state.CheckParams ( 1, "U" )) return 0; MOAIFont* self = state.GetLuaObject < MOAIFont >( 1 ); if ( !self ) return 0; STLString charCodes = state.GetValue ( 3, "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,?!" ); MOAIDataBuffer *data = state.GetLuaObject < MOAIDataBuffer >( 2 ); if ( data ) { self->LoadFont ( *data, charCodes ); } else { STLString imageFile = state.GetValue ( 2, "" ); self->LoadFont ( imageFile, charCodes ); } return 0; }
//----------------------------------------------------------------// void MOAIGlyphCachePage::AffirmCanvas ( MOAIFont& font ) { if ( !this->mImageTexture ) { this->mImageTexture = new MOAIImageTexture (); this->mImageTexture->Init ( MAX_TEXTURE_SIZE, this->mRows.mSize, this->mColorFormat, USPixel::TRUECOLOR ); this->mImageTexture->SetDebugName ( font.GetFilename ()); this->mImageTexture->SetFilter ( GL_LINEAR, GL_LINEAR ); this->mImageTexture->ClearBitmap (); } else if ( this->mImageTexture->MOAIImage::GetHeight () < this->mRows.mSize ) { USIntRect rect; rect.Init ( 0, 0, MAX_TEXTURE_SIZE, this->mRows.mSize ); this->mImageTexture->ResizeCanvas ( *this->mImageTexture, rect ); this->mImageTexture->Invalidate (); } }