Bug 337145 - one copy of nsIDOMSVGMatrix -> cairo_matrix_t code.

r=jwatt, sr=roc
This commit is contained in:
tor%cs.brown.edu 2006-05-11 20:59:11 +00:00
parent b5a7adce1f
commit a859a39c05
7 changed files with 34 additions and 92 deletions

View File

@ -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;
}

View File

@ -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__

View File

@ -50,6 +50,7 @@
#include "nsRect.h"
#include "nsISVGCairoSurface.h"
#include <cairo.h>
#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);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -60,6 +60,7 @@
#include "nsIComponentManager.h"
#include "nsISVGPathFlatten.h"
#include "nsSVGPathGeometryFrame.h"
#include "nsSVGMatrix.h"
#ifdef DEBUG
#include <stdio.h>
#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);
}

View File

@ -54,24 +54,12 @@
#include "nsSVGCairoPattern.h"
#include "nsSVGPatternFrame.h"
#include "nsSVGGeometryFrame.h"
#include "nsSVGMatrix.h"
#ifdef DEBUG
#include <stdio.h>
#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))