MCPcopy Create free account
hub / github.com/ddnet/ddnet / CalculateTextWidth

Method CalculateTextWidth

src/engine/client/text.cpp:2278–2312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2276 }
2277
2278 int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontHeight) const override
2279 {
2280 if(m_pGlyphMap->DefaultFace() == nullptr)
2281 return 0;
2282
2283 const char *pCurrent = pText;
2284 const char *pEnd = pCurrent + TextLength;
2285
2286 int WidthOfText = 0;
2287 FT_Set_Pixel_Sizes(m_pGlyphMap->DefaultFace(), FontWidth, FontHeight);
2288 while(pCurrent < pEnd)
2289 {
2290 const char *pTmp = pCurrent;
2291 const int NextCharacter = str_utf8_decode(&pTmp);
2292 if(NextCharacter)
2293 {
2294#if FREETYPE_MAJOR >= 2 && FREETYPE_MINOR >= 7 && (FREETYPE_MINOR > 7 || FREETYPE_PATCH >= 1)
2295 const FT_Int32 FTFlags = FT_LOAD_BITMAP_METRICS_ONLY | FT_LOAD_NO_BITMAP;
2296#else
2297 const FT_Int32 FTFlags = FT_LOAD_RENDER | FT_LOAD_NO_BITMAP;
2298#endif
2299 if(FT_Load_Char(m_pGlyphMap->DefaultFace(), NextCharacter, FTFlags))
2300 {
2301 log_debug("textrender", "Error loading glyph. Chr=%d", NextCharacter);
2302 pCurrent = pTmp;
2303 continue;
2304 }
2305
2306 WidthOfText += (m_pGlyphMap->DefaultFace()->glyph->metrics.width >> 6) + 1;
2307 }
2308 pCurrent = pTmp;
2309 }
2310
2311 return WidthOfText;
2312 }
2313
2314 void OnPreWindowResize() override
2315 {

Callers 1

UpdateEntityLayerTextMethod · 0.80

Calls 2

str_utf8_decodeFunction · 0.85
DefaultFaceMethod · 0.80

Tested by

no test coverage detected