MCPcopy Create free account
hub / github.com/TheRealMJP/DeferredTexturing / MeasureText

Method MeasureText

SampleFramework12/v1.00/Graphics/SpriteFont.cpp:240–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240Float2 SpriteFont::MeasureText(const wchar* text) const
241{
242 Float2 textSize = Float2(0.0f, 0.0f);
243 Float2 curPos = Float2(0.0f, 0.0f);;
244
245 size_t length = wcslen(text);
246
247 for (uint64 i = 0; i < length; ++i)
248 {
249 wchar character = text[i];
250 if(character == ' ')
251 curPos.x += SpaceWidth();
252 else if(character == '\n')
253 {
254 curPos.y += CharHeight();
255 curPos.x = 0;
256 }
257 else
258 {
259 SpriteFont::CharDesc desc = GetCharDescriptor(character);
260 curPos.x += desc.Width + 1;
261 }
262
263 textSize.x = std::max(curPos.x, textSize.x);
264 textSize.y = std::max(curPos.y, textSize.y);
265 }
266
267 return size;
268}
269
270}

Callers

nothing calls this directly

Calls 1

Float2Class · 0.85

Tested by

no test coverage detected