Bug 1149222 part 2 - Make nsSVGImageFrame::PaintSVG use LayoutDeviceSize & LayoutDevicePixel::ToAppUnits, when setting up its dest-rect. r=mats

This commit is contained in:
Daniel Holbert 2015-04-03 19:48:12 +00:00
parent 400128b6ce
commit 9f9755084d
2 changed files with 16 additions and 4 deletions

View File

@ -282,6 +282,11 @@ struct LayoutDevicePixel {
aSize.height * aAppUnitsPerDevPixel); aSize.height * aAppUnitsPerDevPixel);
} }
static nsSize ToAppUnits(const LayoutDeviceSize& aSize, nscoord aAppUnitsPerDevPixel) {
return nsSize(NSFloatPixelsToAppUnits(aSize.width, aAppUnitsPerDevPixel),
NSFloatPixelsToAppUnits(aSize.height, aAppUnitsPerDevPixel));
}
static nsRect ToAppUnits(const LayoutDeviceRect& aRect, nscoord aAppUnitsPerDevPixel) { static nsRect ToAppUnits(const LayoutDeviceRect& aRect, nscoord aAppUnitsPerDevPixel) {
return nsRect(NSFloatPixelsToAppUnits(aRect.x, aAppUnitsPerDevPixel), return nsRect(NSFloatPixelsToAppUnits(aRect.x, aAppUnitsPerDevPixel),
NSFloatPixelsToAppUnits(aRect.y, aAppUnitsPerDevPixel), NSFloatPixelsToAppUnits(aRect.y, aAppUnitsPerDevPixel),

View File

@ -365,13 +365,20 @@ nsSVGImageFrame::PaintSVG(gfxContext& aContext,
if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) { if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
// Package up the attributes of this image element which can override the // Package up the attributes of this image element which can override the
// attributes of mImageContainer's internal SVG document. // attributes of mImageContainer's internal SVG document. The 'width' &
// 'height' values we're passing in here are in CSS units (though they
// come from width/height *attributes* in SVG). They influence the region
// of the SVG image's internal document that is visible, in combination
// with preserveAspectRatio and viewBox.
SVGImageContext context(CSSIntSize(width, height), SVGImageContext context(CSSIntSize(width, height),
Some(imgElem->mPreserveAspectRatio.GetAnimValue())); Some(imgElem->mPreserveAspectRatio.GetAnimValue()));
nsRect destRect(0, 0, // For the actual draw operation to draw crisply (and at the right size),
appUnitsPerDevPx * width, // our destination rect needs to be |width|x|height|, *in dev pixels*.
appUnitsPerDevPx * height); LayoutDeviceSize devPxSize(width, height);
nsRect destRect(nsPoint(),
LayoutDevicePixel::ToAppUnits(devPxSize,
appUnitsPerDevPx));
// Note: Can't use DrawSingleUnscaledImage for the TYPE_VECTOR case. // Note: Can't use DrawSingleUnscaledImage for the TYPE_VECTOR case.
// That method needs our image to have a fixed native width & height, // That method needs our image to have a fixed native width & height,