Skip to content

Commit

Permalink
Base SVG size on height
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaz82 committed Jan 20, 2022
1 parent 7828391 commit ba701e1
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions es-core/src/resources/TextureData.cpp
Expand Up @@ -46,33 +46,22 @@ bool TextureData::initSVGFromMemory(const unsigned char* fileData, size_t length

NSVGimage* svgImage = nsvgParse(copy, "px", DPI);
free(copy);
if (!svgImage)
if (!svgImage || (svgImage->width == 0) || (svgImage->height == 0))
{
LOG(LogError) << "Error parsing SVG image.";
return false;
}

// We want to rasterise this texture at a specific resolution. If the source size
// variables are set then use them otherwise set them from the parsed file
if ((mSourceWidth == 0.0f) && (mSourceHeight == 0.0f))
{
mSourceWidth = svgImage->width;
if (mSourceHeight == 0.0f)
mSourceHeight = svgImage->height;
}

mSourceWidth = (mSourceHeight * svgImage->width) / svgImage->height;

mWidth = (size_t)Math::round(mSourceWidth);
mHeight = (size_t)Math::round(mSourceHeight);

if (mWidth == 0)
{
// auto scale width to keep aspect
mWidth = (size_t)Math::round(((float)mHeight / svgImage->height) * svgImage->width);
}
else if (mHeight == 0)
{
// auto scale height to keep aspect
mHeight = (size_t)Math::round(((float)mWidth / svgImage->width) * svgImage->height);
}

unsigned char* dataRGBA = new unsigned char[mWidth * mHeight * 4];

NSVGrasterizer* rast = nsvgCreateRasterizer();
Expand Down

0 comments on commit ba701e1

Please sign in to comment.