#include <font_manager.h>
Nevrax France
Definition at line 62 of file font_manager.h.
Public Member Functions | |
CFontManager () | |
void | computeString (const ucstring &s, CFontGenerator *fontGen, const NLMISC::CRGBA &color, uint32 fontSize, IDriver *driver, CComputedString &output, bool keep800x600Ratio=true) |
void | computeString (const std::string &s, CFontGenerator *fontGen, const NLMISC::CRGBA &color, uint32 fontSize, IDriver *driver, CComputedString &output, bool keep800x600Ratio=true) |
void | computeStringInfo (const ucstring &s, CFontGenerator *fontGen, const NLMISC::CRGBA &color, uint32 fontSize, IDriver *driver, CComputedString &output, bool keep800x600Ratio=true) |
void | dumpCache (const char *filename) |
std::string | getCacheInformation () const |
CMaterial * | getFontMaterial () |
uint32 | getMaxMemory () const |
void | setMaxMemory (uint32 mem) |
Private Attributes | |
CMaterial * | _MatFont |
uint32 | _MaxMemory |
uint32 | _MemSize |
uint32 | _NbChar |
CTextureFont * | _TexFont |
|
Default constructor Definition at line 76 of file font_manager.h. References _MatFont, _MaxMemory, _MemSize, _NbChar, and _TexFont.
00077 { 00078 _MemSize = 0; 00079 _MaxMemory = 1000000; 00080 _NbChar = 0; 00081 _MatFont = NULL; 00082 _TexFont = NULL; 00083 } |
|
Same as computeString but works with a unicode string (ucstring) Definition at line 88 of file font_manager.cpp. References NL3D::CTextureFont::SLetterInfo::AdvX, NL3D::CTextureFont::SLetterKey::Char, NL3D::CTextureFont::SLetterInfo::CharHeight, NL3D::CTextureFont::SLetterInfo::CharWidth, NL3D::CComputedString::Color, NL3D::CTextureFont::SLetterKey::FontGenerator, getFontMaterial(), NLMISC::CBitmap::getHeight(), NL3D::CTextureFont::getLetterInfo(), NL3D::CMaterial::getTexture(), NLMISC::CBitmap::getWidth(), NL3D::IDriver::getWindowSize(), height, NL3D::CTextureFont::SLetterInfo::Left, NL3D::CComputedString::Material, min, s, NL3D::CVertexBuffer::setNumVertices(), NL3D::CVertexBuffer::setTexCoord(), NL3D::CVertexBuffer::setVertexCoord(), sint32, NL3D::CTextureFont::SLetterKey::Size, NL3D::CComputedString::StringHeight, NL3D::CComputedString::StringLine, NL3D::CComputedString::StringWidth, NL3D::CTextureFont::SLetterInfo::Top, NL3D::CTextureFont::SLetterInfo::U, uint, uint32, NL3D::CTextureFont::SLetterInfo::V, NL3D::CComputedString::Vertices, width, NL3D::CComputedString::XMax, NL3D::CComputedString::XMin, NL3D::CComputedString::ZMax, and NL3D::CComputedString::ZMin.
00095 { 00096 output.Color = color; 00097 00098 // resize fontSize if window not of 800x600. 00099 if (keep800x600Ratio) 00100 { 00101 uint32 width, height; 00102 driver->getWindowSize (width, height); 00103 if ((height == 0) || (width == 0)) 00104 return; 00105 00106 // keep the 800*600 ratio 00107 fontSize = (uint32)floor(fontSize*height/600.f); 00108 fontSize = max(fontSize, (uint32)2); 00109 } 00110 00111 // Setting vertices format 00112 output.Vertices.setNumVertices (4 * s.size()); 00113 00114 // 1 character <-> 1 quad 00115 sint32 penx = 0, dx; 00116 sint32 penz = 0, dz; 00117 float x1, z1, x2, z2; 00118 float u1, v1, u2, v2; 00119 CMaterial *pMatFont = getFontMaterial(); 00120 CTextureFont *pTexFont = (CTextureFont*)(pMatFont->getTexture (0)); 00121 float TexRatioW = 1.0f / pTexFont->getWidth(); 00122 float TexRatioH = 1.0f / pTexFont->getHeight(); 00123 /*float hlfPixTexW = 0.5f * TexRatioW; 00124 float hlfPixTexH = 0.5f * TexRatioH; 00125 float hlfPixScrW = 0.5f; 00126 float hlfPixScrH = 0.5f;*/ 00127 // Yoyo: Do not need Half Pixel/Texel displacement!! 00128 float hlfPixTexW = 0; 00129 float hlfPixTexH = 0; 00130 float hlfPixScrW = 0; 00131 float hlfPixScrH = 0; 00132 00133 00134 CTextureFont::SLetterKey k; 00135 00136 // string bound. 00137 output.XMin= FLT_MAX; 00138 output.XMax= -FLT_MAX; 00139 output.ZMin= FLT_MAX; 00140 output.ZMax= -FLT_MAX; 00141 00142 // string info. 00143 sint32 nMaxZ = -1000000, nMinZ = 1000000; 00144 output.StringHeight = 0; 00145 00146 // For all chats 00147 uint j = 0; 00148 for (uint i = 0; i < s.size(); i++) 00149 { 00150 // Creating font 00151 k.Char = s[i]; 00152 k.FontGenerator = fontGen; 00153 k.Size = fontSize; 00154 CTextureFont::SLetterInfo *pLI = pTexFont->getLetterInfo (k); 00155 if(pLI != NULL) 00156 { 00157 if ((pLI->CharWidth > 0) && (pLI->CharHeight > 0)) 00158 { 00159 // Creating vertices 00160 dx = pLI->Left; 00161 dz = -((sint32)pLI->CharHeight-(sint32)(pLI->Top)); 00162 u1 = pLI->U - hlfPixTexW; 00163 v1 = pLI->V - hlfPixTexH; 00164 u2 = pLI->U + ((float)pLI->CharWidth) * TexRatioW + hlfPixTexW; 00165 v2 = pLI->V + ((float)pLI->CharHeight) * TexRatioH + hlfPixTexH; 00166 00167 x1 = (penx + dx) - hlfPixScrW; 00168 z1 = (penz + dz) - hlfPixScrH; 00169 x2 = (penx + dx + (sint32)pLI->CharWidth) + hlfPixScrW; 00170 z2 = (penz + dz + (sint32)pLI->CharHeight) + hlfPixScrH; 00171 00172 output.Vertices.setVertexCoord (j, x1, 0, z1); 00173 output.Vertices.setTexCoord (j, 0, u1, v2); 00174 ++j; 00175 00176 output.Vertices.setVertexCoord (j, x2, 0, z1); 00177 output.Vertices.setTexCoord (j, 0, u2, v2); 00178 ++j; 00179 00180 output.Vertices.setVertexCoord (j, x2, 0, z2); 00181 output.Vertices.setTexCoord (j, 0, u2, v1); 00182 ++j; 00183 00184 output.Vertices.setVertexCoord (j, x1, 0, z2); 00185 output.Vertices.setTexCoord (j, 0, u1, v1); 00186 ++j; 00187 00188 // String Bound 00189 output.XMin= min(output.XMin, x1); 00190 output.XMin= min(output.XMin, x2); 00191 output.XMax= max(output.XMax, x1); 00192 output.XMax= max(output.XMax, x2); 00193 output.ZMin= min(output.ZMin, z1); 00194 output.ZMin= min(output.ZMin, z2); 00195 output.ZMax= max(output.ZMax, z1); 00196 output.ZMax= max(output.ZMax, z2); 00197 00198 // String info 00199 sint32 nZ1 = (sint32)pLI->Top-(sint32)pLI->CharHeight; 00200 sint32 nZ2 = pLI->Top; 00201 00202 if (nZ1 < nMinZ) nMinZ = nZ1; 00203 if (nZ2 > nMaxZ) nMaxZ = nZ2; 00204 } 00205 penx += pLI->AdvX; 00206 } 00207 00208 // Building Material 00209 output.Material = pMatFont; 00210 } 00211 output.Vertices.setNumVertices (j); 00212 00213 // compile string info 00214 output.StringWidth = (float)penx; 00215 if(nMaxZ>nMinZ) 00216 { 00217 output.StringHeight = (float)(nMaxZ - nMinZ); 00218 output.StringLine = -(float)nMinZ; 00219 } 00220 else 00221 { 00222 output.StringHeight = 0; 00223 output.StringLine = 0; 00224 } 00225 } |
|
Compute primitive blocks and materials of each character of the string.
Definition at line 72 of file font_manager.cpp. Referenced by NL3D::CTextContext::computeString(), NL3D::CTextContext::printAt(), NL3D::CTextContext::printfAt(), and NL3D::CTextContext::textPush().
00079 { 00080 // static to avoid reallocation 00081 static ucstring ucs; 00082 ucs= s; 00083 computeString(ucs, fontGen, color, fontSize, driver, output, keep800x600Ratio); 00084 } |
|
Same as computeString but do not make vertex buffers and primitives Definition at line 229 of file font_manager.cpp. References NL3D::CTextureFont::SLetterInfo::AdvX, NL3D::CTextureFont::SLetterKey::Char, NL3D::CTextureFont::SLetterInfo::CharHeight, NL3D::CTextureFont::SLetterInfo::CharWidth, NL3D::CComputedString::Color, NL3D::CTextureFont::SLetterKey::FontGenerator, getFontMaterial(), NL3D::CTextureFont::getLetterInfo(), NL3D::CMaterial::getTexture(), NL3D::IDriver::getWindowSize(), height, s, sint32, NL3D::CTextureFont::SLetterKey::Size, NL3D::CComputedString::StringHeight, NL3D::CComputedString::StringLine, NL3D::CComputedString::StringWidth, NL3D::CTextureFont::SLetterInfo::Top, uint, uint32, and width. Referenced by NL3D::CTextContext::computeStringInfo().
00236 { 00237 output.Color = color; 00238 00239 // resize fontSize if window not of 800x600. 00240 if (keep800x600Ratio) 00241 { 00242 uint32 width, height; 00243 driver->getWindowSize (width, height); 00244 if ((height == 0) || (width == 0)) 00245 return; 00246 // keep the 800*600 ratio 00247 fontSize = (uint32)floor(fontSize*height/600.f); 00248 fontSize = max(fontSize, (uint32)2); 00249 } 00250 00251 sint32 penx = 0; 00252 sint32 nMaxZ = -1000000, nMinZ = 1000000; 00253 CMaterial *pMatFont = getFontMaterial(); 00254 CTextureFont *pTexFont = (CTextureFont*)(pMatFont->getTexture (0)); 00255 00256 CTextureFont::SLetterKey k; 00257 CTextureFont::SLetterInfo *pLI; 00258 00259 for (uint i = 0; i < s.size(); i++) 00260 { 00261 // Creating font 00262 k.Char = s[i]; 00263 k.FontGenerator = fontGen; 00264 k.Size = fontSize; 00265 pLI = pTexFont->getLetterInfo (k); 00266 if(pLI != NULL) 00267 { 00268 if ((pLI->CharWidth > 0) && (pLI->CharHeight > 0)) 00269 { 00270 // String info 00271 sint32 nZ1 = (sint32)pLI->Top-(sint32)pLI->CharHeight; 00272 sint32 nZ2 = pLI->Top; 00273 00274 if (nZ1 < nMinZ) nMinZ = nZ1; 00275 if (nZ2 > nMaxZ) nMaxZ = nZ2; 00276 } 00277 penx += pLI->AdvX; 00278 } 00279 } 00280 00281 // compile string info 00282 output.StringWidth = (float)penx; 00283 if(nMaxZ>nMinZ) 00284 { 00285 output.StringHeight = (float)(nMaxZ - nMinZ); 00286 output.StringLine = -(float)nMinZ; 00287 } 00288 else 00289 { 00290 output.StringHeight = 0; 00291 output.StringLine = 0; 00292 } 00293 00294 } |
|
Definition at line 154 of file font_manager.h. References _TexFont, and NL3D::CTextureFont::dumpTextureFont(). Referenced by NL3D::CTextContext::dumpCache().
00155 { 00156 _TexFont->dumpTextureFont (filename); 00157 } |
|
return a string given information about the cache Definition at line 298 of file font_manager.cpp. References _MaxMemory, _MemSize, _NbChar, and NLMISC::toString(). Referenced by NL3D::CDriverUser::getFontManagerCacheInformation().
00299 { 00300 // stringstream ss; 00301 // ss << "MaxMemory: " << (uint) _MaxMemory << " MemSize: " << (uint) _MemSize << " NbChar: " << (uint) _NbChar; 00302 // return ss.str(); 00303 string str; 00304 str = "MaxMemory: " + NLMISC::toString(_MaxMemory) + " MemSize: " + NLMISC::toString(_MemSize) + " NbChar: " + NLMISC::toString(_NbChar); 00305 return str; 00306 } |
|
manages fonts in memory using CSmartPtr
Definition at line 49 of file font_manager.cpp. References _MatFont, _TexFont, NL3D::CMaterial::initUnlit(), NL3D::CMaterial::setBlend(), NL3D::CMaterial::setDstBlend(), NL3D::CMaterial::setSrcBlend(), NL3D::CMaterial::setTexture(), NL3D::CMaterial::texEnvArg0RGB(), and NL3D::CMaterial::texEnvOpRGB(). Referenced by computeString(), computeStringInfo(), NL3D::CTextContextUser::flushRenderBuffer(), and NL3D::CTextContextUser::flushRenderBufferUnProjected().
00050 { 00051 if (_TexFont == NULL) 00052 { 00053 _TexFont = new CTextureFont; 00054 } 00055 00056 if (_MatFont == NULL) 00057 { 00058 _MatFont= new CMaterial; 00059 _MatFont->initUnlit(); 00060 _MatFont->setSrcBlend(CMaterial::srcalpha); 00061 _MatFont->setDstBlend(CMaterial::invsrcalpha); 00062 _MatFont->setBlend(true); 00063 _MatFont->setTexture(0, _TexFont); 00064 _MatFont->texEnvOpRGB(0, CMaterial::Replace); 00065 _MatFont->texEnvArg0RGB(0, CMaterial::Diffuse, CMaterial::SrcColor); 00066 } 00067 return _MatFont; 00068 } |
|
gives maximum memory allowed
Definition at line 97 of file font_manager.h. References _MaxMemory, and uint32.
00097 { return _MaxMemory; } |
|
define maximum memory allowed
Definition at line 90 of file font_manager.h. References _MaxMemory, and uint32. Referenced by NL3D::CDriverUser::setFontManagerMaxMemory().
00090 { _MaxMemory = mem; } |
|
Definition at line 68 of file font_manager.h. Referenced by CFontManager(), and getFontMaterial(). |
|
Definition at line 65 of file font_manager.h. Referenced by CFontManager(), getCacheInformation(), getMaxMemory(), and setMaxMemory(). |
|
Definition at line 64 of file font_manager.h. Referenced by CFontManager(), and getCacheInformation(). |
|
Definition at line 66 of file font_manager.h. Referenced by CFontManager(), and getCacheInformation(). |
|
Definition at line 69 of file font_manager.h. Referenced by CFontManager(), dumpCache(), and getFontMaterial(). |