From 377e990c199c4c38404d122697d263350da0dfc9 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 9 Jun 2011 19:15:13 -0700 Subject: [PATCH] Bug 655926: Implement canvas.mozFillRule. sr=vlad --- .../canvas/src/nsCanvasRenderingContext2D.cpp | 32 +++++++++++++++++++ .../canvas/nsIDOMCanvasRenderingContext2D.idl | 5 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index 44d6597cc011..fa0127ddd40a 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -1182,6 +1182,7 @@ nsCanvasRenderingContext2D::InitializeWithSurface(nsIDocShell *docShell, gfxASur mThebes->SetMiterLimit(10.0); mThebes->SetLineCap(gfxContext::LINE_CAP_BUTT); mThebes->SetLineJoin(gfxContext::LINE_JOIN_MITER); + mThebes->SetFillRule(gfxContext::FILL_RULE_WINDING); mThebes->NewPath(); @@ -1600,6 +1601,37 @@ nsCanvasRenderingContext2D::GetFillStyle_multi(nsAString& aStr, nsISupports **aI return GetStyleAsStringOrInterface(aStr, aInterface, aType, STYLE_FILL); } +NS_IMETHODIMP +nsCanvasRenderingContext2D::SetMozFillRule(const nsAString& aString) +{ + gfxContext::FillRule rule; + + if (aString.EqualsLiteral("evenodd")) + rule = gfxContext::FILL_RULE_EVEN_ODD; + else if (aString.EqualsLiteral("nonzero")) + rule = gfxContext::FILL_RULE_WINDING; + else + // XXX ERRMSG we need to report an error to developers here! (bug 329026) + return NS_OK; + + mThebes->SetFillRule(rule); + return NS_OK; +} + +NS_IMETHODIMP +nsCanvasRenderingContext2D::GetMozFillRule(nsAString& aString) +{ + switch (mThebes->CurrentFillRule()) { + case gfxContext::FILL_RULE_WINDING: + aString.AssignLiteral("nonzero"); break; + case gfxContext::FILL_RULE_EVEN_ODD: + aString.AssignLiteral("evenodd"); break; + default: + return NS_ERROR_FAILURE; + } + return NS_OK; +} + // // gradients and patterns // diff --git a/dom/interfaces/canvas/nsIDOMCanvasRenderingContext2D.idl b/dom/interfaces/canvas/nsIDOMCanvasRenderingContext2D.idl index 8b671674b2a0..2cc18ccd6686 100644 --- a/dom/interfaces/canvas/nsIDOMCanvasRenderingContext2D.idl +++ b/dom/interfaces/canvas/nsIDOMCanvasRenderingContext2D.idl @@ -62,7 +62,7 @@ interface nsIDOMTextMetrics : nsISupports readonly attribute float width; }; -[scriptable, uuid(408be1b9-4d75-4873-b50b-9b651626e41d)] +[scriptable, uuid(bf5e52a3-6ec1-4a6e-8364-9f9222ec8edb)] interface nsIDOMCanvasRenderingContext2D : nsISupports { // back-reference to the canvas element for which @@ -106,6 +106,9 @@ enum CanvasMultiGetterType { [noscript] void setFillStyle_multi(in DOMString str, in nsISupports iface); [noscript] void getFillStyle_multi(out DOMString str, out nsISupports iface, out long type); + //attribute DOMString fillRule; + attribute DOMString mozFillRule; /* "evenodd", "nonzero" (default) */ + nsIDOMCanvasGradient createLinearGradient (in float x0, in float y0, in float x1, in float y1); nsIDOMCanvasGradient createRadialGradient(in float x0, in float y0, in float r0, in float x1, in float y1, in float r1); nsIDOMCanvasPattern createPattern(in nsIDOMHTMLElement image, in DOMString repetition);