зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1264809 - (Part 2) Preserve scale ratio if SVG dosen't have viewport size and viewBox. r=dholbert
This commit is contained in:
Родитель
96f6cecc6b
Коммит
f90480e301
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "ClippedImage.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <new> // Workaround for bug in VS10; see bug 981264.
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
@ -28,6 +29,7 @@ using namespace gfx;
|
|||
using layers::LayerManager;
|
||||
using layers::ImageContainer;
|
||||
using std::make_pair;
|
||||
using std::max;
|
||||
using std::modf;
|
||||
using std::pair;
|
||||
|
||||
|
@ -501,10 +503,12 @@ ClippedImage::OptimalImageSizeForDest(const gfxSize& aDest,
|
|||
|
||||
int32_t imgWidth, imgHeight;
|
||||
bool needScale = false;
|
||||
bool forceUniformScaling = false;
|
||||
if (mSVGViewportSize && !mSVGViewportSize->IsEmpty()) {
|
||||
imgWidth = mSVGViewportSize->width;
|
||||
imgHeight = mSVGViewportSize->height;
|
||||
needScale = true;
|
||||
forceUniformScaling = (aFlags & imgIContainer::FLAG_FORCE_UNIFORM_SCALING);
|
||||
} else if (NS_SUCCEEDED(InnerImage()->GetWidth(&imgWidth)) &&
|
||||
NS_SUCCEEDED(InnerImage()->GetHeight(&imgHeight))) {
|
||||
needScale = true;
|
||||
|
@ -519,6 +523,10 @@ ClippedImage::OptimalImageSizeForDest(const gfxSize& aDest,
|
|||
nsIntSize scale(ceil(aDest.width / mClip.width),
|
||||
ceil(aDest.height / mClip.height));
|
||||
|
||||
if (forceUniformScaling) {
|
||||
scale.width = scale.height = max(scale.height, scale.width);
|
||||
}
|
||||
|
||||
// Determine the size we'd prefer to render the inner image at, and ask the
|
||||
// inner image what size we should actually use.
|
||||
gfxSize desiredSize(imgWidth * scale.width, imgHeight * scale.height);
|
||||
|
|
|
@ -207,6 +207,7 @@ interface imgIContainer : nsISupports
|
|||
const unsigned long FLAG_WANT_DATA_SURFACE = 0x80;
|
||||
const unsigned long FLAG_BYPASS_SURFACE_CACHE = 0x100;
|
||||
const unsigned long FLAG_FORCE_PRESERVEASPECTRATIO_NONE = 0x200;
|
||||
const unsigned long FLAG_FORCE_UNIFORM_SCALING = 0x400;
|
||||
|
||||
/**
|
||||
* A constant specifying the default set of decode flags (i.e., the default
|
||||
|
|
|
@ -5521,6 +5521,12 @@ nsImageRenderer::DrawBorderImageComponent(nsPresContext* aPresContext,
|
|||
// preserveAspectRatio attribute, and always do non-uniform stretch.
|
||||
uint32_t drawFlags = ConvertImageRendererToDrawFlags(mFlags) |
|
||||
imgIContainer::FLAG_FORCE_PRESERVEASPECTRATIO_NONE;
|
||||
// For those SVG image sources which don't have fixed aspect ratio (i.e.
|
||||
// without viewport size and viewBox), we should scale the source uniformly
|
||||
// after the viewport size is decided by "Default Sizing Algorithm".
|
||||
if (!ComputeIntrinsicSize().HasRatio()) {
|
||||
drawFlags = drawFlags | imgIContainer::FLAG_FORCE_UNIFORM_SCALING;
|
||||
}
|
||||
// Retrieve or create the subimage we'll draw.
|
||||
nsIntRect srcRect(aSrc.x, aSrc.y, aSrc.width, aSrc.height);
|
||||
if (mType == eStyleImageType_Image) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче