From 2b80f5518c9cce61289410057d2e905cfb3e2a04 Mon Sep 17 00:00:00 2001 From: "longsonr@gmail.com" Date: Thu, 19 Apr 2007 01:29:27 -0700 Subject: [PATCH] Bug 377263, bug 377399 - patternContentUnits='objectBoundingBox' not translated correctly. r=tor,sr=roc --- layout/svg/base/src/nsSVGPatternFrame.cpp | 29 ++++++++++++++++------- layout/svg/base/src/nsSVGPatternFrame.h | 1 + 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/layout/svg/base/src/nsSVGPatternFrame.cpp b/layout/svg/base/src/nsSVGPatternFrame.cpp index 651854906575..e888b9409b4c 100644 --- a/layout/svg/base/src/nsSVGPatternFrame.cpp +++ b/layout/svg/base/src/nsSVGPatternFrame.cpp @@ -270,7 +270,7 @@ nsSVGPatternFrame::PaintPattern(cairo_surface_t** surface, // Get the transformation matrix that we will hand to the renderer's pattern // routine. - if (NS_FAILED(GetPatternMatrix(patternMatrix, bbox, callerCTM))) + if (NS_FAILED(GetPatternMatrix(patternMatrix, bbox, callerBBox, callerCTM))) return NS_ERROR_FAILURE; #ifdef DEBUG_scooter @@ -642,13 +642,11 @@ nsSVGPatternFrame::ConstructCTM(nsIDOMSVGMatrix **aCTM, if (type == nsIDOMSVGPatternElement::SVG_PUNITS_OBJECTBOUNDINGBOX) { // Use the bounding box - float minx,miny,width,height; - callerBBox->GetX(&minx); - callerBBox->GetY(&miny); + float width, height; callerBBox->GetWidth(&width); callerBBox->GetHeight(&height); NS_NewSVGMatrix(getter_AddRefs(tCTM), width, 0.0f, 0.0f, - height, minx, miny); + height, 0.0f, 0.0f); } else { NS_NewSVGMatrix(getter_AddRefs(tCTM)); } @@ -690,6 +688,7 @@ nsSVGPatternFrame::ConstructCTM(nsIDOMSVGMatrix **aCTM, nsresult nsSVGPatternFrame::GetPatternMatrix(nsIDOMSVGMatrix **aCTM, nsIDOMSVGRect *bbox, + nsIDOMSVGRect *callerBBox, nsIDOMSVGMatrix *callerCTM) { *aCTM = nsnull; @@ -700,9 +699,18 @@ nsSVGPatternFrame::GetPatternMatrix(nsIDOMSVGMatrix **aCTM, NS_ENSURE_SUCCESS(rv, rv); // We really want the pattern matrix to handle translations - float minx,miny; + float minx, miny; bbox->GetX(&minx); bbox->GetY(&miny); + + PRUint16 type = GetPatternContentUnits(); + if (type == nsIDOMSVGPatternElement::SVG_PUNITS_OBJECTBOUNDINGBOX) { + float x, y; + callerBBox->GetX(&x); + callerBBox->GetY(&y); + minx += x; + miny += y; + } nsCOMPtr tCTM; patternTransform->Translate(minx, miny, getter_AddRefs(tCTM)); @@ -761,15 +769,18 @@ nsSVGPatternFrame::GetCallerGeometry(nsIDOMSVGMatrix **aCTM, // OK, now fix up the bounding box to reflect user coordinates // We handle device unit scaling in pattern matrix { - float x,y,width,height,xscale,yscale; + float x, y, width, height; (*aBBox)->GetX(&x); (*aBBox)->GetY(&y); (*aBBox)->GetWidth(&width); (*aBBox)->GetHeight(&height); + float xpos, ypos, xscale, yscale; (*aCTM)->GetA(&xscale); (*aCTM)->GetD(&yscale); - x = x / xscale; - y = y / yscale; + (*aCTM)->GetE(&xpos); + (*aCTM)->GetF(&ypos); + x = (x - xpos) / xscale; + y = (y - ypos) / yscale; width = width / xscale; height = height / yscale; (*aBBox)->SetX(x); diff --git a/layout/svg/base/src/nsSVGPatternFrame.h b/layout/svg/base/src/nsSVGPatternFrame.h index 7a3f1e9ba82c..eb561be539d0 100644 --- a/layout/svg/base/src/nsSVGPatternFrame.h +++ b/layout/svg/base/src/nsSVGPatternFrame.h @@ -139,6 +139,7 @@ protected: nsSVGElement *content); nsresult GetPatternMatrix(nsIDOMSVGMatrix **aCTM, nsIDOMSVGRect *bbox, + nsIDOMSVGRect *callerBBox, nsIDOMSVGMatrix *callerCTM); nsresult ConstructCTM(nsIDOMSVGMatrix **ctm, nsIDOMSVGRect *callerBBox); nsresult GetCallerGeometry(nsIDOMSVGMatrix **aCTM,