From 18d12280d2670506d95e14770db7aa3e3d23aac0 Mon Sep 17 00:00:00 2001 From: "tor%cs.brown.edu" Date: Mon, 11 Sep 2006 15:26:19 +0000 Subject: [PATCH] Bug 350059 Allow cairo.h usage in nsSVGUtils.h. r+sr=roc --- content/base/src/nsNameSpaceManager.cpp | 5 ++--- .../svg/content/src/nsSVGElementFactory.cpp | 2 +- content/svg/content/src/nsSVGFeatures.cpp | 2 +- content/svg/content/src/nsSVGMatrix.cpp | 14 ------------ content/svg/content/src/nsSVGMatrix.h | 9 -------- content/svg/content/src/nsSVGPathElement.cpp | 3 +-- layout/base/nsCSSFrameConstructor.cpp | 11 +++++----- layout/build/nsContentDLF.cpp | 6 ++--- layout/build/nsLayoutStatics.cpp | 5 +++-- layout/svg/base/src/nsSVGGlyphFrame.cpp | 3 +-- layout/svg/base/src/nsSVGGradientFrame.cpp | 2 +- layout/svg/base/src/nsSVGImageFrame.cpp | 2 +- .../svg/base/src/nsSVGPathGeometryFrame.cpp | 2 +- layout/svg/base/src/nsSVGPatternFrame.cpp | 2 +- layout/svg/base/src/nsSVGUtils.cpp | 16 +++++++++++++- layout/svg/base/src/nsSVGUtils.h | 22 +++++++++++++------ .../renderer/src/cairo/nsSVGCairoCanvas.cpp | 4 ++-- 17 files changed, 53 insertions(+), 57 deletions(-) diff --git a/content/base/src/nsNameSpaceManager.cpp b/content/base/src/nsNameSpaceManager.cpp index bb47cb4f813..551dfad8c40 100644 --- a/content/base/src/nsNameSpaceManager.cpp +++ b/content/base/src/nsNameSpaceManager.cpp @@ -57,7 +57,7 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID); #endif #ifdef MOZ_SVG -#include "nsSVGUtils.h" +PRBool NS_SVGEnabled(); #endif #define kXMLNSNameSpaceURI "http://www.w3.org/2000/xmlns/" @@ -253,8 +253,7 @@ NS_NewElement(nsIContent** aResult, PRInt32 aElementType, } #endif #ifdef MOZ_SVG - if (aElementType == kNameSpaceID_SVG && - nsSVGUtils::SVGEnabled()) { + if (aElementType == kNameSpaceID_SVG && NS_SVGEnabled()) { return NS_NewSVGElement(aResult, aNodeInfo); } #endif diff --git a/content/svg/content/src/nsSVGElementFactory.cpp b/content/svg/content/src/nsSVGElementFactory.cpp index 3d208679a78..23087d6255c 100644 --- a/content/svg/content/src/nsSVGElementFactory.cpp +++ b/content/svg/content/src/nsSVGElementFactory.cpp @@ -132,7 +132,7 @@ NS_NewSVGMaskElement(nsIContent **aResult, nsINodeInfo *aNodeInfo); nsresult NS_NewSVGElement(nsIContent** aResult, nsINodeInfo *aNodeInfo) { - NS_PRECONDITION(nsSVGUtils::SVGEnabled(), + NS_PRECONDITION(NS_SVGEnabled(), "creating an SVG element while SVG disabled"); static const char kSVGStyleSheetURI[] = "resource://gre/res/svg.css"; diff --git a/content/svg/content/src/nsSVGFeatures.cpp b/content/svg/content/src/nsSVGFeatures.cpp index 0bfb2c4460b..bdab83b6777 100644 --- a/content/svg/content/src/nsSVGFeatures.cpp +++ b/content/svg/content/src/nsSVGFeatures.cpp @@ -44,7 +44,7 @@ // Test to see if a feature is implemented PRBool NS_SVG_TestFeature(const nsAString& fstr) { - if (!nsSVGUtils::SVGEnabled()) { + if (!NS_SVGEnabled()) { return PR_FALSE; } nsAutoString lstr(fstr); diff --git a/content/svg/content/src/nsSVGMatrix.cpp b/content/svg/content/src/nsSVGMatrix.cpp index 5ef51e5f92b..125cdfe8566 100644 --- a/content/svg/content/src/nsSVGMatrix.cpp +++ b/content/svg/content/src/nsSVGMatrix.cpp @@ -320,17 +320,3 @@ 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 4f1a58106c1..9fd972449c1 100644 --- a/content/svg/content/src/nsSVGMatrix.h +++ b/content/svg/content/src/nsSVGMatrix.h @@ -48,13 +48,4 @@ 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/content/svg/content/src/nsSVGPathElement.cpp b/content/svg/content/src/nsSVGPathElement.cpp index d4a56f0acb3..152289bbe46 100644 --- a/content/svg/content/src/nsSVGPathElement.cpp +++ b/content/svg/content/src/nsSVGPathElement.cpp @@ -47,7 +47,6 @@ #include "nsISVGValueUtils.h" #include "nsSVGUtils.h" #include "nsSVGPoint.h" -#include "nsSVGMatrix.h" nsSVGElement::NumberInfo nsSVGPathElement::sNumberInfo = { &nsGkAtoms::pathLength, 0 }; @@ -456,7 +455,7 @@ nsSVGPathElement::GetFlattenedPath(nsIDOMSVGMatrix *aMatrix) } if (aMatrix) { - cairo_matrix_t matrix = NS_ConvertSVGMatrixToCairo(aMatrix); + cairo_matrix_t matrix = nsSVGUtils::ConvertSVGMatrixToCairo(aMatrix); cairo_set_matrix(ctx, &matrix); } diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 3e3a61b5e22..8ee7cd9b51d 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -173,8 +173,9 @@ NS_NewHTMLCanvasFrame (nsIPresShell* aPresShell, nsStyleContext* aContext); #include "nsSVGAtoms.h" #include "nsISVGTextContentMetrics.h" #include "nsStyleUtil.h" -#include "nsSVGUtils.h" +PRBool +NS_SVGEnabled(); nsIFrame* NS_NewSVGOuterSVGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext); nsIFrame* @@ -3522,8 +3523,7 @@ IsSpecialContent(nsIContent* aContent, PR_FALSE; #ifdef MOZ_SVG - if (aNameSpaceID == kNameSpaceID_SVG && - nsSVGUtils::SVGEnabled()) { + if (aNameSpaceID == kNameSpaceID_SVG && NS_SVGEnabled()) { // All SVG content is special... return PR_TRUE; } @@ -4616,8 +4616,7 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsFrameConstructorState& aState, else #endif #ifdef MOZ_SVG - if (aDocElement->GetNameSpaceID() == kNameSpaceID_SVG && - nsSVGUtils::SVGEnabled()) { + if (aDocElement->GetNameSpaceID() == kNameSpaceID_SVG && NS_SVGEnabled()) { contentFrame = NS_NewSVGOuterSVGFrame(mPresShell, aDocElement, styleContext); } else @@ -8138,7 +8137,7 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsFrameConstructorState& aState, if (NS_SUCCEEDED(rv) && (!frameItems->childList || lastChild == frameItems->lastChild) && aNameSpaceID == kNameSpaceID_SVG && - nsSVGUtils::SVGEnabled()) { + NS_SVGEnabled()) { PRBool haltProcessing; rv = ConstructSVGFrame(aState, aContent, adjParentFrame, aTag, aNameSpaceID, styleContext, diff --git a/layout/build/nsContentDLF.cpp b/layout/build/nsContentDLF.cpp index 3186ca13d7b..b0d709fe04b 100644 --- a/layout/build/nsContentDLF.cpp +++ b/layout/build/nsContentDLF.cpp @@ -113,7 +113,7 @@ static const char* const gSVGTypes[] = { 0 }; -#include "nsSVGUtils.h" +PRBool NS_SVGEnabled(); #endif static const char* const gRDFTypes[] = { @@ -193,7 +193,7 @@ nsContentDLF::CreateInstance(const char* aCommand, } #ifdef MOZ_SVG - if (nsSVGUtils::SVGEnabled()) { + if (NS_SVGEnabled()) { for (typeIndex = 0; gSVGTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gSVGTypes[typeIndex])) { knownType = PR_TRUE; @@ -241,7 +241,7 @@ nsContentDLF::CreateInstance(const char* aCommand, } #ifdef MOZ_SVG - if (nsSVGUtils::SVGEnabled()) { + if (NS_SVGEnabled()) { // Try SVG typeIndex = 0; while(gSVGTypes[typeIndex]) { diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp index 05eaea582bf..7af54ce63ba 100644 --- a/layout/build/nsLayoutStatics.cpp +++ b/layout/build/nsLayoutStatics.cpp @@ -90,7 +90,8 @@ #ifdef MOZ_SVG #include "nsSVGAtoms.h" -#include "nsSVGUtils.h" + +PRBool NS_SVGEnabled(); #endif #ifndef MOZ_NO_INSPECTOR_APIS @@ -159,7 +160,7 @@ nsLayoutStatics::Initialize() #endif #ifdef MOZ_SVG - if (nsSVGUtils::SVGEnabled()) + if (NS_SVGEnabled()) nsContentDLF::RegisterSVG(); #endif diff --git a/layout/svg/base/src/nsSVGGlyphFrame.cpp b/layout/svg/base/src/nsSVGGlyphFrame.cpp index e060b1f3f66..68c6ad70df0 100644 --- a/layout/svg/base/src/nsSVGGlyphFrame.cpp +++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp @@ -52,7 +52,6 @@ #include "nsSVGPoint.h" #include "nsSVGRect.h" #include "nsDOMError.h" -#include "nsSVGMatrix.h" #include "nsISVGCairoCanvas.h" #include "cairo.h" @@ -1486,7 +1485,7 @@ nsSVGGlyphFrame::GetGlobalTransform(cairo_t *ctx, GetCanvasTM(getter_AddRefs(ctm)); NS_ASSERTION(ctm, "graphic source didn't specify a ctm"); - cairo_matrix_t matrix = NS_ConvertSVGMatrixToCairo(ctm); + cairo_matrix_t matrix = nsSVGUtils::ConvertSVGMatrixToCairo(ctm); if (aCanvas) { aCanvas->AdjustMatrixForInitialTransform(&matrix); } diff --git a/layout/svg/base/src/nsSVGGradientFrame.cpp b/layout/svg/base/src/nsSVGGradientFrame.cpp index 59b0a3cfb1d..02efe7b223b 100644 --- a/layout/svg/base/src/nsSVGGradientFrame.cpp +++ b/layout/svg/base/src/nsSVGGradientFrame.cpp @@ -337,7 +337,7 @@ nsSVGGradientFrame::SetupPaintServer(nsISVGRendererCanvas *aCanvas, if (!svgMatrix) return NS_ERROR_FAILURE; - cairo_matrix_t patternMatrix = NS_ConvertSVGMatrixToCairo(svgMatrix); + cairo_matrix_t patternMatrix = nsSVGUtils::ConvertSVGMatrixToCairo(svgMatrix); if (cairo_matrix_invert(&patternMatrix)) return NS_ERROR_FAILURE; diff --git a/layout/svg/base/src/nsSVGImageFrame.cpp b/layout/svg/base/src/nsSVGImageFrame.cpp index 8f96cd2e13a..dceb59eba64 100644 --- a/layout/svg/base/src/nsSVGImageFrame.cpp +++ b/layout/svg/base/src/nsSVGImageFrame.cpp @@ -276,7 +276,7 @@ nsSVGImageFrame::PaintSVG(nsISVGRendererCanvas* canvas, nsRect *aDirtyRect) } nsCOMPtr cairoCanvas = do_QueryInterface(canvas); - cairo_matrix_t matrix = NS_ConvertSVGMatrixToCairo(fini); + cairo_matrix_t matrix = nsSVGUtils::ConvertSVGMatrixToCairo(fini); cairoCanvas->AdjustMatrixForInitialTransform(&matrix); cairo_t *ctx = cairoCanvas->GetContext(); diff --git a/layout/svg/base/src/nsSVGPathGeometryFrame.cpp b/layout/svg/base/src/nsSVGPathGeometryFrame.cpp index 0d616a18fe9..e139370adbd 100644 --- a/layout/svg/base/src/nsSVGPathGeometryFrame.cpp +++ b/layout/svg/base/src/nsSVGPathGeometryFrame.cpp @@ -645,7 +645,7 @@ nsSVGPathGeometryFrame::GeneratePath(cairo_t *ctx, nsISVGCairoCanvas* aCanvas) GetCanvasTM(getter_AddRefs(ctm)); NS_ASSERTION(ctm, "graphic source didn't specify a ctm"); - cairo_matrix_t matrix = NS_ConvertSVGMatrixToCairo(ctm); + cairo_matrix_t matrix = nsSVGUtils::ConvertSVGMatrixToCairo(ctm); if (aCanvas) { aCanvas->AdjustMatrixForInitialTransform(&matrix); } diff --git a/layout/svg/base/src/nsSVGPatternFrame.cpp b/layout/svg/base/src/nsSVGPatternFrame.cpp index c016e924247..37e9f2f3ce8 100644 --- a/layout/svg/base/src/nsSVGPatternFrame.cpp +++ b/layout/svg/base/src/nsSVGPatternFrame.cpp @@ -838,7 +838,7 @@ nsSVGPatternFrame::SetupPaintServer(nsISVGRendererCanvas *aCanvas, return NS_ERROR_FAILURE; // Translate the pattern frame - cairo_matrix_t pmatrix = NS_ConvertSVGMatrixToCairo(pMatrix); + cairo_matrix_t pmatrix = nsSVGUtils::ConvertSVGMatrixToCairo(pMatrix); cairoCanvas->AdjustMatrixForInitialTransform(&pmatrix); if (cairo_matrix_invert(&pmatrix)) return NS_ERROR_FAILURE; diff --git a/layout/svg/base/src/nsSVGUtils.cpp b/layout/svg/base/src/nsSVGUtils.cpp index ffb633fdca4..755a44d1d76 100644 --- a/layout/svg/base/src/nsSVGUtils.cpp +++ b/layout/svg/base/src/nsSVGUtils.cpp @@ -110,7 +110,7 @@ SVGPrefChanged(const char *aPref, void *aClosure) } PRBool -nsSVGUtils::SVGEnabled() +NS_SVGEnabled() { static PRBool sInitialized = PR_FALSE; @@ -952,3 +952,17 @@ nsSVGUtils::GetCairoComputationalSurface() return mCairoComputationalSurface; } + +cairo_matrix_t +nsSVGUtils::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/layout/svg/base/src/nsSVGUtils.h b/layout/svg/base/src/nsSVGUtils.h index 2d146704a6b..30e3f39def3 100644 --- a/layout/svg/base/src/nsSVGUtils.h +++ b/layout/svg/base/src/nsSVGUtils.h @@ -45,6 +45,7 @@ #include "nsCOMPtr.h" #include "nsISVGValue.h" #include "nsRect.h" +#include "cairo.h" class nsIDocument; class nsPresContext; @@ -69,8 +70,6 @@ class nsSVGElement; class nsSVGCoordCtxProvider; class nsAttrValue; -typedef struct _cairo_surface cairo_surface_t; - #ifndef M_PI #define M_PI 3.14159265358979323846 #endif @@ -96,14 +95,17 @@ typedef struct _cairo_surface cairo_surface_t; /* are we the child of a non-display container? */ #define NS_STATE_SVG_NONDISPLAY_CHILD 0x20000000 +/* + * Checks the svg enable preference and if a renderer could + * successfully be created. Declared as a function instead of a + * nsSVGUtil method so that files that can't pull in nsSVGUtils.h (due + * to cairo.h usage) can still query this information. + */ +PRBool NS_SVGEnabled(); + class nsSVGUtils { public: - /* Checks the svg enable preference and if a renderer could - * successfully be created. - */ - static PRBool SVGEnabled(); - /* * Report a localized error message to the error console. */ @@ -252,6 +254,12 @@ public: static cairo_surface_t * GetCairoComputationalSurface(); + /* + * Convert a nsIDOMSVGMatrix to a cairo_matrix_t. + */ + static cairo_matrix_t + ConvertSVGMatrixToCairo(nsIDOMSVGMatrix *aMatrix); + private: /* Cairo computational (nil) surface */ static cairo_surface_t *mCairoComputationalSurface; diff --git a/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp b/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp index ba4077bc15c..36b1714ca71 100644 --- a/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp +++ b/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp @@ -50,7 +50,7 @@ #include "nsRect.h" #include "nsISVGCairoSurface.h" #include -#include "nsSVGMatrix.h" +#include "nsSVGUtils.h" #ifdef MOZ_X11 extern "C" { @@ -454,7 +454,7 @@ NS_INTERFACE_MAP_END void nsSVGCairoCanvas::SetupCairoMatrix(nsIDOMSVGMatrix *aCTM) { - cairo_matrix_t matrix = NS_ConvertSVGMatrixToCairo(aCTM); + cairo_matrix_t matrix = nsSVGUtils::ConvertSVGMatrixToCairo(aCTM); AdjustMatrixForInitialTransform(&matrix); cairo_set_matrix(mCR, &matrix); }