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

Method getTextureDataForText

core/platform/winrt/Device-winrt.cpp:509–547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

507}
508
509Data Device::getTextureDataForText(std::string_view text,
510 const FontDefinition& textDefinition,
511 TextAlign align,
512 int& width,
513 int& height,
514 bool& hasPremultipliedAlpha)
515{
516 Data ret;
517 do
518 {
519 auto& textRenderer = sharedTextRenderer();
520
521 if (!textRenderer.setFont(textDefinition))
522 {
523 AXLOGW("Can't found font({}), use system default", textDefinition._fontName);
524 }
525
526 // draw text
527 // does changing to SIZE here affects the font size by rounding from float?
528 SIZE size = {(LONG)textDefinition._dimensions.width, (LONG)textDefinition._dimensions.height};
529 AX_BREAK_IF(!textRenderer.drawText(text, size, align, textDefinition));
530
531 int dataLen = size.cx * size.cy * 4;
532 unsigned char* dataBuf = (unsigned char*)malloc(sizeof(unsigned char) * dataLen);
533 AX_BREAK_IF(!dataBuf);
534
535 width = static_cast<int>(size.cx);
536 height = static_cast<int>(size.cy);
537
538 const int bpp = 32;
539 size_t rowPitch = (width * bpp + 7) / 8;
540 textRenderer.copyPixels(dataBuf, dataLen, rowPitch);
541
542 ret.fastSet(dataBuf, dataLen);
543 hasPremultipliedAlpha = false;
544 } while (0);
545
546 return ret;
547}
548
549void Device::setKeepScreenOn(bool /*value*/) {}
550

Callers

nothing calls this directly

Calls 4

copyPixelsMethod · 0.80
fastSetMethod · 0.80
setFontMethod · 0.45
drawTextMethod · 0.45

Tested by

no test coverage detected