From 51ab69b54c35a590f0c5e7e3bac1e399207806a5 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 23 Dec 2020 20:32:12 +0100 Subject: [PATCH] Fixed an issue where some SVG graphics would have their right side cut off slightly. --- es-core/src/components/ImageComponent.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index ac18c4f3f..41faa63c7 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -72,8 +72,8 @@ void ImageComponent::resize() // 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 // 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 - // better solution, please make a pull request! + // It's important to use the floorf() function rather than round() for this, as we never + // want to round up since that can lead to the cutoff just described. if (mTargetIsMax) { mSize = textureSize; @@ -83,11 +83,11 @@ void ImageComponent::resize() // This will be mTargetSize.x(). We can't exceed it, nor be lower than it. mSize[0] *= resizeScale.x(); // 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 { // 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 // 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(), @@ -115,7 +115,7 @@ void ImageComponent::resize() } // 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. - 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()); } @@ -128,18 +128,18 @@ void ImageComponent::resize() // For SVG rasterization, we always calculate width from rounded height (see // comment above). 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(); } 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] = Math::round(mSize.x()); - mSize[1] = Math::round(mSize.y()); + mSize[0] = Math::floorf(mSize.x()); + mSize[1] = Math::floorf(mSize.y()); // mSize.y() should already be rounded. mTexture->rasterizeAt(static_cast(mSize.x()), static_cast(mSize.y()));