MCPcopy Create free account
hub / github.com/axmolengine/axmol / drawText

Method drawText

core/platform/win32/Device-win32.cpp:231–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229 }
230
231 int drawText(std::string_view text,
232 SIZE& tSize,
233 Device::TextAlign eAlign,
234 const char* fontName,
235 int textSize,
236 bool enableWrap,
237 int overflow)
238 {
239 int nRet = 0;
240 wchar_t* pwszBuffer = nullptr;
241 wchar_t* fixedText = nullptr;
242 do
243 {
244 AX_BREAK_IF(text.empty());
245
246 DWORD dwFmt = DT_WORDBREAK;
247 if (!enableWrap)
248 {
249 dwFmt |= DT_SINGLELINE;
250 }
251 DWORD dwHoriFlag = (int)eAlign & 0x0f;
252 DWORD dwVertFlag = ((int)eAlign & 0xf0) >> 4;
253
254 switch (dwHoriFlag)
255 {
256 case 1: // left
257 dwFmt |= DT_LEFT;
258 break;
259 case 2: // right
260 dwFmt |= DT_RIGHT;
261 break;
262 case 3: // center
263 dwFmt |= DT_CENTER;
264 break;
265 }
266
267 int nLen = static_cast<int>(text.length());
268 // utf-8 to utf-16
269 int nBufLen = nLen + 1;
270 pwszBuffer = new wchar_t[nBufLen];
271 AX_BREAK_IF(!pwszBuffer);
272
273 memset(pwszBuffer, 0, sizeof(wchar_t) * nBufLen);
274 nLen = MultiByteToWideChar(CP_UTF8, 0, text.data(), nLen, pwszBuffer, nBufLen);
275
276 if (strchr(text.data(), '&'))
277 {
278 fixedText = new wchar_t[nLen * 2 + 1];
279 int fixedIndex = 0;
280 for (int index = 0; index < nLen; ++index)
281 {
282 if (pwszBuffer[index] == '&')
283 {
284 fixedText[fixedIndex] = '&';
285 fixedText[fixedIndex + 1] = '&';
286 fixedIndex += 2;
287 }
288 else

Callers 1

getTextureDataForTextMethod · 0.45

Calls 3

emptyMethod · 0.45
lengthMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected