SimpleFontData* SimpleFontData::scaledFontData(const FontDescription& fontDescription, float scaleFactor) const { FontDescription fontDesc(fontDescription); fontDesc.setComputedSize(lroundf(scaleFactor * fontDesc.computedSize())); fontDesc.setSpecifiedSize(lroundf(scaleFactor * fontDesc.specifiedSize())); fontDesc.setKeywordSize(lroundf(scaleFactor * fontDesc.keywordSize())); FontPlatformData* result = fontCache()->getCachedFontPlatformData(fontDesc, m_platformData.family()); return result ? new SimpleFontData(*result) : 0; }
PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const FontDescription& fontDescription, float scaleFactor) const { FontDescription fontDesc(fontDescription); fontDesc.setComputedSize(lroundf(scaleFactor * fontDesc.computedSize())); fontDesc.setSpecifiedSize(lroundf(scaleFactor * fontDesc.specifiedSize())); fontDesc.setKeywordSize(lroundf(scaleFactor * fontDesc.keywordSize())); FontPlatformData* result = fontCache()->getCachedFontPlatformData(fontDesc, m_platformData.family()); if (!result) return 0; return SimpleFontData::create(*result); }
StringRenderable FontManager::CreateStringRenderable( const char* msg, const char* fontFamily, int fontSize, long x, long y, const Vector3 &color, ID3DXSprite* sprite) { FontDescription fontDesc(fontFamily, fontSize); map<FontDescription,ID3DXFont*>::iterator font; if ((font = cache.find(fontDesc)) == cache.end()) { //Cache Miss ID3DXFont* newFont = NULL; HRESULT hr = D3DXCreateFont( GraphicsLayer::GetInstance().GetDevice(), fontSize, 0, FW_NORMAL, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, fontFamily, &newFont ); assert(D3DERR_INVALIDCALL != hr); assert(D3DXERR_INVALIDDATA != hr); if(E_OUTOFMEMORY == hr){ cout << "Ran out of memory for custom font" << endl; HRESULT hr = D3DXCreateFont( GraphicsLayer::GetInstance().GetDevice(), fontSize, 0, FW_NORMAL, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Verdana", &newFont ); } font = cache.insert(make_pair(fontDesc,newFont)).first; } //Buffer sring for rendering StringRenderable s(sprite); s.m_pFont = font->second; s.m_strTextBuffer = msg; s.m_color = D3DXCOLOR(color.x, color.y, color.z, 1.0f); s.m_uiScreenX = x; s.m_uiScreenY = y; return s; }