This commit is contained in:
halx99 2024-12-06 00:37:54 +08:00
parent e5073273b8
commit 775b752f85
3 changed files with 10 additions and 4 deletions

View File

@ -429,8 +429,8 @@ Data Device::getTextureDataForText(std::string_view text,
{
break;
}
height = (short)info.height;
width = (short)info.width;
height = static_cast<int>(info.height);
width = static_cast<int>(info.width);
ret.fastSet(info.data, width * height * 4);
hasPremultipliedAlpha = true;
} while (0);

View File

@ -450,8 +450,8 @@ Data Device::getTextureDataForText(std::string_view text,
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
AX_BREAK_IF(!GetDIBits(dc.getDC(), dc.getBitmap(), 0, 0, nullptr, (LPBITMAPINFO)&bi, DIB_RGB_COLORS));
width = (short)size.cx;
height = (short)size.cy;
width = static_cast<int>(size.cx);
height = static_cast<int>(size.cy);
// copy pixel data
bi.bmiHeader.biHeight = (bi.bmiHeader.biHeight > 0) ? -bi.bmiHeader.biHeight : bi.bmiHeader.biHeight;

View File

@ -549,7 +549,13 @@ bool Texture2D::initWithString(std::string_view text, const FontDefinition& text
bool hasPremultipliedAlpha;
Data outData = Device::getTextureDataForText(text, textDef, align, imageWidth, imageHeight, hasPremultipliedAlpha);
if (outData.isNull())
return false;
const auto maxTextureSize = backend::DriverBase::getInstance()->getMaxTextureSize();
if (imageWidth > maxTextureSize || imageHeight > maxTextureSize)
{
AXLOGW("Texture2D::initWithString fail, the texture size:{}x{} too large, max texture size:{}", imageWidth,
imageHeight, maxTextureSize);
return false;
}