Bug 1003505 - Fix printing of SVG images so that they're no longer pixelated. r=seth

This commit is contained in:
Jonathan Watt 2014-06-26 08:40:12 +01:00
Родитель 251f0161da
Коммит 77c21d8bd6
3 изменённых файлов: 29 добавлений и 12 удалений

Просмотреть файл

@ -154,6 +154,13 @@ interface imgIContainer : nsISupports
* caller knows they want a SourceSurface of type DATA.
*/
const long FLAG_WANT_DATA_SURFACE = 0x20;
/**
* Forces drawing to happen rather than taking cached rendering from the
* surface cache. This is used when we are printing, for example, where we
* want the vector commands from VectorImages to end up in the PDF output
* rather than a cached rendering at screen resolution.
*/
const long FLAG_BYPASS_SURFACE_CACHE = 0x40;
/**
* Constants for specifying various "special" frames.

Просмотреть файл

@ -859,11 +859,16 @@ VectorImage::Draw(gfxContext* aContext,
SVGDrawingParameters params(aContext, aFilter, aUserSpaceToImageSpace, aFill,
aSubimage, aViewportSize, aSVGContext, animTime, aFlags);
// Check the cache.
nsRefPtr<gfxDrawable> drawable =
SurfaceCache::Lookup(ImageKey(this),
SurfaceKey(params.imageRect.Size(), params.scale,
aSVGContext, animTime, aFlags));
// Check the cache. (The FLAG_BYPASS_SURFACE_CACHE check here is just an
// optimization since the flags are part of the cache key and we never put
// surfaces in the cache if the flags contain FLAG_BYPASS_SURFACE_CACHE.)
nsRefPtr<gfxDrawable> drawable;
if (!(aFlags & FLAG_BYPASS_SURFACE_CACHE)) {
drawable =
SurfaceCache::Lookup(ImageKey(this),
SurfaceKey(params.imageRect.Size(), params.scale,
aSVGContext, animTime, aFlags));
}
// Draw.
if (drawable) {
@ -890,13 +895,13 @@ VectorImage::CreateDrawableAndShow(const SVGDrawingParameters& aParams)
nsRefPtr<gfxDrawable> svgDrawable =
new gfxCallbackDrawable(cb, ThebesIntSize(aParams.imageRect.Size()));
// Refuse to cache animated images.
// XXX(seth): We may remove this restriction in bug 922893.
if (mHaveAnimations)
return Show(svgDrawable, aParams);
// If the image is too big to fit in the cache, don't go any further.
if (!SurfaceCache::CanHold(aParams.imageRect.Size()))
bool bypassCache = bool(aParams.flags & FLAG_BYPASS_SURFACE_CACHE) ||
// Refuse to cache animated images:
// XXX(seth): We may remove this restriction in bug 922893.
mHaveAnimations ||
// The image is too big to fit in the cache:
!SurfaceCache::CanHold(aParams.imageRect.Size());
if (bypassCache)
return Show(svgDrawable, aParams);
// Try to create an offscreen surface.

Просмотреть файл

@ -5009,6 +5009,11 @@ DrawImageInternal(nsRenderingContext* aRenderingContext,
const SVGImageContext* aSVGContext,
uint32_t aImageFlags)
{
if (aPresContext->Type() == nsPresContext::eContext_Print) {
// We want vector images to be passed on as vector commands, not a raster
// image.
aImageFlags |= imgIContainer::FLAG_BYPASS_SURFACE_CACHE;
}
if (aDest.Contains(aFill)) {
aImageFlags |= imgIContainer::FLAG_CLAMP;
}