mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-14 00:14:33 +00:00
Bug 985257 - Add implementation for Path2D constructor that takes an SVG path string. r=roc
This commit is contained in:
parent
20769aaaa3
commit
543f9e966c
@ -94,6 +94,7 @@
|
|||||||
#include "nsGlobalWindow.h"
|
#include "nsGlobalWindow.h"
|
||||||
#include "GLContext.h"
|
#include "GLContext.h"
|
||||||
#include "GLContextProvider.h"
|
#include "GLContextProvider.h"
|
||||||
|
#include "SVGContentUtils.h"
|
||||||
|
|
||||||
#undef free // apparently defined by some windows header, clashing with a free()
|
#undef free // apparently defined by some windows header, clashing with a free()
|
||||||
// method in SkTypes.h
|
// method in SkTypes.h
|
||||||
@ -4362,6 +4363,18 @@ CanvasPath::Constructor(const GlobalObject& aGlobal, CanvasPath& aCanvasPath, Er
|
|||||||
return path.forget();
|
return path.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
already_AddRefed<CanvasPath>
|
||||||
|
CanvasPath::Constructor(const GlobalObject& aGlobal, const nsAString& aPathString, ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
RefPtr<gfx::Path> tempPath = SVGContentUtils::GetPath(aPathString);
|
||||||
|
if (!tempPath) {
|
||||||
|
return Constructor(aGlobal, aRv);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsRefPtr<CanvasPath> path = new CanvasPath(aGlobal.GetAsSupports(), tempPath->CopyToBuilder());
|
||||||
|
return path.forget();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CanvasPath::ClosePath()
|
CanvasPath::ClosePath()
|
||||||
{
|
{
|
||||||
|
@ -61,6 +61,9 @@ public:
|
|||||||
static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal,
|
static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal,
|
||||||
CanvasPath& aCanvasPath,
|
CanvasPath& aCanvasPath,
|
||||||
ErrorResult& rv);
|
ErrorResult& rv);
|
||||||
|
static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal,
|
||||||
|
const nsAString& aPathString,
|
||||||
|
ErrorResult& rv);
|
||||||
|
|
||||||
void ClosePath();
|
void ClosePath();
|
||||||
void MoveTo(double x, double y);
|
void MoveTo(double x, double y);
|
||||||
|
@ -97,6 +97,7 @@ FINAL_LIBRARY = 'gklayout'
|
|||||||
LOCAL_INCLUDES += [
|
LOCAL_INCLUDES += [
|
||||||
'/content/base/src',
|
'/content/base/src',
|
||||||
'/content/html/content/src',
|
'/content/html/content/src',
|
||||||
|
'/content/svg/content/src',
|
||||||
'/content/xul/content/src',
|
'/content/xul/content/src',
|
||||||
'/dom/base',
|
'/dom/base',
|
||||||
'/image/src',
|
'/image/src',
|
||||||
|
@ -315,6 +315,23 @@ function test_isPointInStroke_canvas() {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<p>Canvas test: test_pathconstructor_canvas</p>
|
||||||
|
<canvas id="c7" class="output" width="200" height="100">+
|
||||||
|
</canvas>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
function test_pathconstructor_canvas() {
|
||||||
|
var c = document.getElementById("c7");
|
||||||
|
var ctx = c.getContext("2d");
|
||||||
|
|
||||||
|
var p = new Path2D("M100,0L200,0L200,100L100,100z");
|
||||||
|
ctx.fillStyle = 'blue';
|
||||||
|
ctx.fill(p);
|
||||||
|
isPixel(ctx, 105, 5, [0, 0, 255, 255], 0);
|
||||||
|
isPixel(ctx, 5, 5, [0, 0, 0, 0], 0);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function runTests() {
|
function runTests() {
|
||||||
@ -354,6 +371,12 @@ function runTests() {
|
|||||||
throw e;
|
throw e;
|
||||||
ok(false, "unexpected exception thrown in: test_isPointInStroke_canvas");
|
ok(false, "unexpected exception thrown in: test_isPointInStroke_canvas");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
test_pathconstructor_canvas();
|
||||||
|
} catch(e) {
|
||||||
|
throw e;
|
||||||
|
ok(false, "unexpected exception thrown in: test_pathconstructor_canvas");
|
||||||
|
}
|
||||||
SpecialPowers.setBoolPref("canvas.path.enabled", false);
|
SpecialPowers.setBoolPref("canvas.path.enabled", false);
|
||||||
SimpleTest.finish();
|
SimpleTest.finish();
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,10 @@
|
|||||||
#include "SVGAnimatedPreserveAspectRatio.h"
|
#include "SVGAnimatedPreserveAspectRatio.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "mozilla/gfx/2D.h"
|
#include "mozilla/gfx/2D.h"
|
||||||
|
#include "mozilla/gfx/Types.h"
|
||||||
#include "gfx2DGlue.h"
|
#include "gfx2DGlue.h"
|
||||||
|
#include "nsSVGPathDataParser.h"
|
||||||
|
#include "SVGPathData.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
@ -584,3 +587,15 @@ SVGContentUtils::CoordToFloat(nsPresContext *aPresContext,
|
|||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr<gfx::Path>
|
||||||
|
SVGContentUtils::GetPath(const nsAString& aPathString)
|
||||||
|
{
|
||||||
|
SVGPathData pathData;
|
||||||
|
nsSVGPathDataParser parser(aPathString, &pathData);
|
||||||
|
if (!parser.Parse()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pathData.BuildPath(mozilla::gfx::FillRule::FILL_WINDING, NS_STYLE_STROKE_LINECAP_BUTT, 1);
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "mozilla/RangedPtr.h"
|
#include "mozilla/RangedPtr.h"
|
||||||
#include "nsError.h"
|
#include "nsError.h"
|
||||||
#include "nsStringFwd.h"
|
#include "nsStringFwd.h"
|
||||||
|
#include "gfx2DGlue.h"
|
||||||
|
|
||||||
class nsIContent;
|
class nsIContent;
|
||||||
class nsIDocument;
|
class nsIDocument;
|
||||||
@ -243,6 +244,13 @@ public:
|
|||||||
static float CoordToFloat(nsPresContext *aPresContext,
|
static float CoordToFloat(nsPresContext *aPresContext,
|
||||||
nsSVGElement *aContent,
|
nsSVGElement *aContent,
|
||||||
const nsStyleCoord &aCoord);
|
const nsStyleCoord &aCoord);
|
||||||
|
/**
|
||||||
|
* Parse the SVG path string
|
||||||
|
* Returns a path
|
||||||
|
* string formatted as an SVG path
|
||||||
|
*/
|
||||||
|
static mozilla::RefPtr<mozilla::gfx::Path>
|
||||||
|
GetPath(const nsAString& aPathString);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -316,7 +316,8 @@ interface TextMetrics {
|
|||||||
|
|
||||||
[Pref="canvas.path.enabled",
|
[Pref="canvas.path.enabled",
|
||||||
Constructor,
|
Constructor,
|
||||||
Constructor(Path2D other)]
|
Constructor(Path2D other),
|
||||||
|
Constructor(DOMString pathString)]
|
||||||
interface Path2D
|
interface Path2D
|
||||||
{};
|
{};
|
||||||
Path2D implements CanvasPathMethods;
|
Path2D implements CanvasPathMethods;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user