Fixed an issue where some SVG graphics would have their right side cut off slightly.

This commit is contained in:
Leon Styhre 2020-12-23 20:32:12 +01:00
parent 327676d7d7
commit 51ab69b54c

View file

@ -72,8 +72,8 @@ void ImageComponent::resize()
// ratios), it can cause cutoff when the aspect ratio breaks. // ratios), it can cause cutoff when the aspect ratio breaks.
// So we always make sure the resultant height is an integer to make sure cutoff doesn't // So we always make sure the resultant height is an integer to make sure cutoff doesn't
// happen, and scale width from that (you'll see this scattered throughout the function). // happen, and scale width from that (you'll see this scattered throughout the function).
// This is probably not the best way, so if you're familiar with this problem and have a // It's important to use the floorf() function rather than round() for this, as we never
// better solution, please make a pull request! // want to round up since that can lead to the cutoff just described.
if (mTargetIsMax) { if (mTargetIsMax) {
mSize = textureSize; mSize = textureSize;
@ -83,11 +83,11 @@ void ImageComponent::resize()
// This will be mTargetSize.x(). We can't exceed it, nor be lower than it. // This will be mTargetSize.x(). We can't exceed it, nor be lower than it.
mSize[0] *= resizeScale.x(); mSize[0] *= resizeScale.x();
// We need to make sure we're not creating an image larger than max size. // We need to make sure we're not creating an image larger than max size.
mSize[1] = Math::min(Math::round(mSize[1] *= resizeScale.x()), mTargetSize.y()); mSize[1] = Math::min(Math::floorf(mSize[1] *= resizeScale.x()), mTargetSize.y());
} }
else { else {
// This will be mTargetSize.y(). We can't exceed it. // This will be mTargetSize.y(). We can't exceed it.
mSize[1] = Math::round(mSize[1] * resizeScale.y()); mSize[1] = Math::floorf(mSize[1] * resizeScale.y());
// For SVG rasterization, always calculate width from rounded height (see comment // For SVG rasterization, always calculate width from rounded height (see comment
// above). We need to make sure we're not creating an image larger than max size. // above). We need to make sure we're not creating an image larger than max size.
mSize[0] = Math::min((mSize[1] / textureSize.y()) * textureSize.x(), mSize[0] = Math::min((mSize[1] / textureSize.y()) * textureSize.x(),
@ -115,7 +115,7 @@ void ImageComponent::resize()
} }
// For SVG rasterization, always calculate width from rounded height (see comment // For SVG rasterization, always calculate width from rounded height (see comment
// above). We need to make sure we're not creating an image smaller than min size. // above). We need to make sure we're not creating an image smaller than min size.
mSize[1] = Math::max(Math::round(mSize[1]), mTargetSize.y()); mSize[1] = Math::max(Math::floorf(mSize[1]), mTargetSize.y());
mSize[0] = Math::max((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x()); mSize[0] = Math::max((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x());
} }
@ -128,18 +128,18 @@ void ImageComponent::resize()
// For SVG rasterization, we always calculate width from rounded height (see // For SVG rasterization, we always calculate width from rounded height (see
// comment above). // comment above).
if (!mTargetSize.x() && mTargetSize.y()) { if (!mTargetSize.x() && mTargetSize.y()) {
mSize[1] = Math::round(mTargetSize.y()); mSize[1] = Math::floorf(mTargetSize.y());
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x();
} }
else if (mTargetSize.x() && !mTargetSize.y()) { else if (mTargetSize.x() && !mTargetSize.y()) {
mSize[1] = Math::round((mTargetSize.x() / textureSize.x()) * textureSize.y()); mSize[1] = Math::floorf((mTargetSize.x() / textureSize.x()) * textureSize.y());
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x();
} }
} }
} }
mSize[0] = Math::round(mSize.x()); mSize[0] = Math::floorf(mSize.x());
mSize[1] = Math::round(mSize.y()); mSize[1] = Math::floorf(mSize.y());
// mSize.y() should already be rounded. // mSize.y() should already be rounded.
mTexture->rasterizeAt(static_cast<size_t>(mSize.x()), static_cast<size_t>(mSize.y())); mTexture->rasterizeAt(static_cast<size_t>(mSize.x()), static_cast<size_t>(mSize.y()));