From a859a39c0539c13aacadbe711b532b97c2cb8a55 Mon Sep 17 00:00:00 2001 From: "tor%cs.brown.edu" Date: Thu, 11 May 2006 20:59:11 +0000 Subject: [PATCH] Bug 337145 - one copy of nsIDOMSVGMatrix -> cairo_matrix_t code. r=jwatt, sr=roc --- content/svg/content/src/nsSVGMatrix.cpp | 14 +++++++++++ content/svg/content/src/nsSVGMatrix.h | 10 ++++++++ .../renderer/src/cairo/nsSVGCairoCanvas.cpp | 23 ++----------------- .../src/cairo/nsSVGCairoGlyphGeometry.cpp | 23 ++----------------- .../renderer/src/cairo/nsSVGCairoGradient.cpp | 17 ++------------ .../src/cairo/nsSVGCairoPathGeometry.cpp | 23 ++----------------- .../renderer/src/cairo/nsSVGCairoPattern.cpp | 16 ++----------- 7 files changed, 34 insertions(+), 92 deletions(-) diff --git a/content/svg/content/src/nsSVGMatrix.cpp b/content/svg/content/src/nsSVGMatrix.cpp index 125cdfe8566d..5ef51e5f92b4 100644 --- a/content/svg/content/src/nsSVGMatrix.cpp +++ b/content/svg/content/src/nsSVGMatrix.cpp @@ -320,3 +320,17 @@ nsSVGMatrix::GetValueString(nsAString& aValue) NS_NOTYETIMPLEMENTED("nsSVGMatrix::GetValueString"); return NS_ERROR_NOT_IMPLEMENTED; } + +cairo_matrix_t +NS_ConvertSVGMatrixToCairo(nsIDOMSVGMatrix *aMatrix) +{ + float A, B, C, D, E, F; + aMatrix->GetA(&A); + aMatrix->GetB(&B); + aMatrix->GetC(&C); + aMatrix->GetD(&D); + aMatrix->GetE(&E); + aMatrix->GetF(&F); + cairo_matrix_t m = { A, B, C, D, E, F }; + return m; +} diff --git a/content/svg/content/src/nsSVGMatrix.h b/content/svg/content/src/nsSVGMatrix.h index 0681b36c64d0..4f1a58106c1c 100644 --- a/content/svg/content/src/nsSVGMatrix.h +++ b/content/svg/content/src/nsSVGMatrix.h @@ -40,6 +40,7 @@ #define __NS_SVGMATRIX_H__ #include "nsIDOMSVGMatrix.h" +#include "cairo.h" nsresult NS_NewSVGMatrix(nsIDOMSVGMatrix** result, @@ -47,4 +48,13 @@ NS_NewSVGMatrix(nsIDOMSVGMatrix** result, float c = 0.0f, float d = 1.0f, float e = 0.0f, float f = 0.0f); +/* + * Helper to convert a nsIDOMSVGMatrix to a cairo_matrix_t. Defined + * here instead of in nsSVGUtils.h because that file is needed in + * several places where it would be inappropriate to include cairo.h. + */ + +cairo_matrix_t +NS_ConvertSVGMatrixToCairo(nsIDOMSVGMatrix *aMatrix); + #endif //__NS_SVGMATRIX_H__ diff --git a/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp b/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp index 63320e31117d..ba4077bc15c0 100644 --- a/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp +++ b/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp @@ -50,6 +50,7 @@ #include "nsRect.h" #include "nsISVGCairoSurface.h" #include +#include "nsSVGMatrix.h" #ifdef MOZ_X11 extern "C" { @@ -453,27 +454,7 @@ NS_INTERFACE_MAP_END void nsSVGCairoCanvas::SetupCairoMatrix(nsIDOMSVGMatrix *aCTM) { - float m[6]; - float val; - aCTM->GetA(&val); - m[0] = val; - - aCTM->GetB(&val); - m[1] = val; - - aCTM->GetC(&val); - m[2] = val; - - aCTM->GetD(&val); - m[3] = val; - - aCTM->GetE(&val); - m[4] = val; - - aCTM->GetF(&val); - m[5] = val; - - cairo_matrix_t matrix = {m[0], m[1], m[2], m[3], m[4], m[5]}; + cairo_matrix_t matrix = NS_ConvertSVGMatrixToCairo(aCTM); AdjustMatrixForInitialTransform(&matrix); cairo_set_matrix(mCR, &matrix); } diff --git a/layout/svg/renderer/src/cairo/nsSVGCairoGlyphGeometry.cpp b/layout/svg/renderer/src/cairo/nsSVGCairoGlyphGeometry.cpp index 5d3e8e400eee..a434cce6f35e 100644 --- a/layout/svg/renderer/src/cairo/nsSVGCairoGlyphGeometry.cpp +++ b/layout/svg/renderer/src/cairo/nsSVGCairoGlyphGeometry.cpp @@ -63,6 +63,7 @@ #include "nsSVGTypeCIDs.h" #include "nsIComponentManager.h" #include "nsSVGGlyphFrame.h" +#include "nsSVGMatrix.h" extern cairo_surface_t *gSVGCairoDummySurface; @@ -575,27 +576,7 @@ nsSVGCairoGlyphGeometry::GetGlobalTransform(nsSVGGlyphFrame *aSource, aSource->GetCanvasTM(getter_AddRefs(ctm)); NS_ASSERTION(ctm, "graphic source didn't specify a ctm"); - float m[6]; - float val; - ctm->GetA(&val); - m[0] = val; - - ctm->GetB(&val); - m[1] = val; - - ctm->GetC(&val); - m[2] = val; - - ctm->GetD(&val); - m[3] = val; - - ctm->GetE(&val); - m[4] = val; - - ctm->GetF(&val); - m[5] = val; - - cairo_matrix_t matrix = {m[0], m[1], m[2], m[3], m[4], m[5]}; + cairo_matrix_t matrix = NS_ConvertSVGMatrixToCairo(ctm); if (aCanvas) { aCanvas->AdjustMatrixForInitialTransform(&matrix); } diff --git a/layout/svg/renderer/src/cairo/nsSVGCairoGradient.cpp b/layout/svg/renderer/src/cairo/nsSVGCairoGradient.cpp index 8adabde1bfe6..3981572725cb 100644 --- a/layout/svg/renderer/src/cairo/nsSVGCairoGradient.cpp +++ b/layout/svg/renderer/src/cairo/nsSVGCairoGradient.cpp @@ -48,20 +48,7 @@ #include "nsSVGCairoGradient.h" #include "nsSVGGeometryFrame.h" #include "nsSVGGradientFrame.h" - -static cairo_matrix_t SVGToMatrix(nsIDOMSVGMatrix *ctm) -{ - float A, B, C, D, E, F; - ctm->GetA(&A); - ctm->GetB(&B); - ctm->GetC(&C); - ctm->GetD(&D); - ctm->GetE(&E); - ctm->GetF(&F); - cairo_matrix_t matrix = { A, B, C, D, E, F }; - return matrix; -} - +#include "nsSVGMatrix.h" static void CairoSetStops(cairo_pattern_t *aPattern, @@ -150,7 +137,7 @@ CairoGradient(cairo_t *ctx, nsSVGGradientFrame *aGrad, if (!svgMatrix) return nsnull; - cairo_matrix_t patternMatrix = SVGToMatrix(svgMatrix); + cairo_matrix_t patternMatrix = NS_ConvertSVGMatrixToCairo(svgMatrix); if (cairo_matrix_invert(&patternMatrix)) { return nsnull; } diff --git a/layout/svg/renderer/src/cairo/nsSVGCairoPathGeometry.cpp b/layout/svg/renderer/src/cairo/nsSVGCairoPathGeometry.cpp index a28b11f040cf..47af8b215d63 100644 --- a/layout/svg/renderer/src/cairo/nsSVGCairoPathGeometry.cpp +++ b/layout/svg/renderer/src/cairo/nsSVGCairoPathGeometry.cpp @@ -60,6 +60,7 @@ #include "nsIComponentManager.h" #include "nsISVGPathFlatten.h" #include "nsSVGPathGeometryFrame.h" +#include "nsSVGMatrix.h" #ifdef DEBUG #include #endif @@ -130,27 +131,7 @@ nsSVGCairoPathGeometry::GeneratePath(nsSVGPathGeometryFrame *aSource, aSource->GetCanvasTM(getter_AddRefs(ctm)); NS_ASSERTION(ctm, "graphic source didn't specify a ctm"); - float m[6]; - float val; - ctm->GetA(&val); - m[0] = val; - - ctm->GetB(&val); - m[1] = val; - - ctm->GetC(&val); - m[2] = val; - - ctm->GetD(&val); - m[3] = val; - - ctm->GetE(&val); - m[4] = val; - - ctm->GetF(&val); - m[5] = val; - - cairo_matrix_t matrix = { m[0], m[1], m[2], m[3], m[4], m[5] }; + cairo_matrix_t matrix = NS_ConvertSVGMatrixToCairo(ctm); if (aCanvas) { aCanvas->AdjustMatrixForInitialTransform(&matrix); } diff --git a/layout/svg/renderer/src/cairo/nsSVGCairoPattern.cpp b/layout/svg/renderer/src/cairo/nsSVGCairoPattern.cpp index 3dc5fac5fb1f..20b594005556 100644 --- a/layout/svg/renderer/src/cairo/nsSVGCairoPattern.cpp +++ b/layout/svg/renderer/src/cairo/nsSVGCairoPattern.cpp @@ -54,24 +54,12 @@ #include "nsSVGCairoPattern.h" #include "nsSVGPatternFrame.h" #include "nsSVGGeometryFrame.h" +#include "nsSVGMatrix.h" #ifdef DEBUG #include #endif -static cairo_matrix_t SVGToMatrix(nsIDOMSVGMatrix *ctm) -{ - float A, B, C, D, E, F; - ctm->GetA(&A); - ctm->GetB(&B); - ctm->GetC(&C); - ctm->GetD(&D); - ctm->GetE(&E); - ctm->GetF(&F); - cairo_matrix_t matrix = { A, B, C, D, E, F }; - return matrix; -} - #ifdef DEBUG_scooter void printMatrix(char *msg, cairo_matrix_t *matrix); void dumpPattern(nsISVGCairoSurface *surf); @@ -114,7 +102,7 @@ CairoPattern(nsISVGRendererCanvas *canvas, nsSVGPatternFrame *aPat, #endif // Translate the pattern frame - cairo_matrix_t pmatrix = SVGToMatrix(pMatrix); + cairo_matrix_t pmatrix = NS_ConvertSVGMatrixToCairo(pMatrix); cairoCanvas->AdjustMatrixForInitialTransform(&pmatrix); if (cairo_matrix_invert(&pmatrix))