2011-06-24 21:41:16 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
#include "PathD2D.h"
|
|
|
|
#include "HelpersD2D.h"
|
|
|
|
#include <math.h>
|
2016-02-13 16:33:28 +03:00
|
|
|
#include "DrawTargetD2D1.h"
|
2011-06-24 21:41:16 +04:00
|
|
|
#include "Logging.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
// This class exists as a wrapper for ID2D1SimplifiedGeometry sink, it allows
|
|
|
|
// a geometry to be duplicated into a geometry sink, while removing the final
|
|
|
|
// figure end and thus allowing a figure that was implicitly closed to be
|
|
|
|
// continued.
|
|
|
|
class OpeningGeometrySink : public ID2D1SimplifiedGeometrySink
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OpeningGeometrySink(ID2D1SimplifiedGeometrySink *aSink)
|
|
|
|
: mSink(aSink)
|
|
|
|
, mNeedsFigureEnded(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE QueryInterface(const IID &aIID, void **aPtr)
|
|
|
|
{
|
|
|
|
if (!aPtr) {
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIID == IID_IUnknown) {
|
|
|
|
*aPtr = static_cast<IUnknown*>(this);
|
|
|
|
return S_OK;
|
|
|
|
} else if (aIID == IID_ID2D1SimplifiedGeometrySink) {
|
|
|
|
*aPtr = static_cast<ID2D1SimplifiedGeometrySink*>(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE AddRef()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE Release()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We ignore SetFillMode, the copier will decide.
|
|
|
|
STDMETHOD_(void, SetFillMode)(D2D1_FILL_MODE aMode)
|
|
|
|
{ EnsureFigureEnded(); return; }
|
|
|
|
STDMETHOD_(void, BeginFigure)(D2D1_POINT_2F aPoint, D2D1_FIGURE_BEGIN aBegin)
|
|
|
|
{ EnsureFigureEnded(); return mSink->BeginFigure(aPoint, aBegin); }
|
|
|
|
STDMETHOD_(void, AddLines)(const D2D1_POINT_2F *aLines, UINT aCount)
|
|
|
|
{ EnsureFigureEnded(); return mSink->AddLines(aLines, aCount); }
|
|
|
|
STDMETHOD_(void, AddBeziers)(const D2D1_BEZIER_SEGMENT *aSegments, UINT aCount)
|
|
|
|
{ EnsureFigureEnded(); return mSink->AddBeziers(aSegments, aCount); }
|
|
|
|
STDMETHOD(Close)()
|
|
|
|
{ /* Should never be called! */ return S_OK; }
|
|
|
|
STDMETHOD_(void, SetSegmentFlags)(D2D1_PATH_SEGMENT aFlags)
|
|
|
|
{ return mSink->SetSegmentFlags(aFlags); }
|
|
|
|
|
|
|
|
// This function is special - it's the reason this class exists.
|
|
|
|
// It needs to intercept the very last endfigure. So that a user can
|
|
|
|
// continue writing to this sink as if they never stopped.
|
|
|
|
STDMETHOD_(void, EndFigure)(D2D1_FIGURE_END aEnd)
|
|
|
|
{
|
|
|
|
if (aEnd == D2D1_FIGURE_END_CLOSED) {
|
|
|
|
return mSink->EndFigure(aEnd);
|
|
|
|
} else {
|
|
|
|
mNeedsFigureEnded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
void EnsureFigureEnded()
|
|
|
|
{
|
|
|
|
if (mNeedsFigureEnded) {
|
|
|
|
mSink->EndFigure(D2D1_FIGURE_END_OPEN);
|
|
|
|
mNeedsFigureEnded = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ID2D1SimplifiedGeometrySink *mSink;
|
|
|
|
bool mNeedsFigureEnded;
|
|
|
|
};
|
|
|
|
|
2013-11-07 13:10:53 +04:00
|
|
|
class StreamingGeometrySink : public ID2D1SimplifiedGeometrySink
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StreamingGeometrySink(PathSink *aSink)
|
|
|
|
: mSink(aSink)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE QueryInterface(const IID &aIID, void **aPtr)
|
|
|
|
{
|
|
|
|
if (!aPtr) {
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIID == IID_IUnknown) {
|
|
|
|
*aPtr = static_cast<IUnknown*>(this);
|
|
|
|
return S_OK;
|
|
|
|
} else if (aIID == IID_ID2D1SimplifiedGeometrySink) {
|
|
|
|
*aPtr = static_cast<ID2D1SimplifiedGeometrySink*>(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE AddRef()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE Release()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We ignore SetFillMode, this depends on the destination sink.
|
|
|
|
STDMETHOD_(void, SetFillMode)(D2D1_FILL_MODE aMode)
|
|
|
|
{ return; }
|
|
|
|
STDMETHOD_(void, BeginFigure)(D2D1_POINT_2F aPoint, D2D1_FIGURE_BEGIN aBegin)
|
|
|
|
{ mSink->MoveTo(ToPoint(aPoint)); }
|
|
|
|
STDMETHOD_(void, AddLines)(const D2D1_POINT_2F *aLines, UINT aCount)
|
|
|
|
{ for (UINT i = 0; i < aCount; i++) { mSink->LineTo(ToPoint(aLines[i])); } }
|
|
|
|
STDMETHOD_(void, AddBeziers)(const D2D1_BEZIER_SEGMENT *aSegments, UINT aCount)
|
|
|
|
{
|
|
|
|
for (UINT i = 0; i < aCount; i++) {
|
|
|
|
mSink->BezierTo(ToPoint(aSegments[i].point1), ToPoint(aSegments[i].point2), ToPoint(aSegments[i].point3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
STDMETHOD(Close)()
|
|
|
|
{ /* Should never be called! */ return S_OK; }
|
|
|
|
STDMETHOD_(void, SetSegmentFlags)(D2D1_PATH_SEGMENT aFlags)
|
|
|
|
{ /* Should never be called! */ }
|
|
|
|
|
|
|
|
STDMETHOD_(void, EndFigure)(D2D1_FIGURE_END aEnd)
|
|
|
|
{
|
|
|
|
if (aEnd == D2D1_FIGURE_END_CLOSED) {
|
|
|
|
return mSink->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
|
|
|
|
PathSink *mSink;
|
|
|
|
};
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
PathBuilderD2D::~PathBuilderD2D()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathBuilderD2D::MoveTo(const Point &aPoint)
|
|
|
|
{
|
|
|
|
if (mFigureActive) {
|
|
|
|
mSink->EndFigure(D2D1_FIGURE_END_OPEN);
|
|
|
|
mFigureActive = false;
|
|
|
|
}
|
|
|
|
EnsureActive(aPoint);
|
|
|
|
mCurrentPoint = aPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathBuilderD2D::LineTo(const Point &aPoint)
|
|
|
|
{
|
|
|
|
EnsureActive(aPoint);
|
|
|
|
mSink->AddLine(D2DPoint(aPoint));
|
|
|
|
|
|
|
|
mCurrentPoint = aPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathBuilderD2D::BezierTo(const Point &aCP1,
|
|
|
|
const Point &aCP2,
|
|
|
|
const Point &aCP3)
|
|
|
|
{
|
|
|
|
EnsureActive(aCP1);
|
|
|
|
mSink->AddBezier(D2D1::BezierSegment(D2DPoint(aCP1),
|
|
|
|
D2DPoint(aCP2),
|
|
|
|
D2DPoint(aCP3)));
|
|
|
|
|
|
|
|
mCurrentPoint = aCP3;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathBuilderD2D::QuadraticBezierTo(const Point &aCP1,
|
|
|
|
const Point &aCP2)
|
|
|
|
{
|
|
|
|
EnsureActive(aCP1);
|
|
|
|
mSink->AddQuadraticBezier(D2D1::QuadraticBezierSegment(D2DPoint(aCP1),
|
|
|
|
D2DPoint(aCP2)));
|
|
|
|
|
|
|
|
mCurrentPoint = aCP2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathBuilderD2D::Close()
|
|
|
|
{
|
|
|
|
if (mFigureActive) {
|
|
|
|
mSink->EndFigure(D2D1_FIGURE_END_CLOSED);
|
|
|
|
|
|
|
|
mFigureActive = false;
|
|
|
|
|
|
|
|
EnsureActive(mBeginPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathBuilderD2D::Arc(const Point &aOrigin, Float aRadius, Float aStartAngle,
|
|
|
|
Float aEndAngle, bool aAntiClockwise)
|
|
|
|
{
|
|
|
|
if (aAntiClockwise && aStartAngle < aEndAngle) {
|
|
|
|
// D2D does things a little differently, and draws the arc by specifying an
|
|
|
|
// beginning and an end point. This means the circle will be the wrong way
|
|
|
|
// around if the start angle is smaller than the end angle. It might seem
|
|
|
|
// tempting to invert aAntiClockwise but that would change the sweeping
|
2015-07-06 23:46:00 +03:00
|
|
|
// direction of the arc so instead we exchange start/begin.
|
2011-06-24 21:41:16 +04:00
|
|
|
Float oldStart = aStartAngle;
|
|
|
|
aStartAngle = aEndAngle;
|
|
|
|
aEndAngle = oldStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX - Workaround for now, D2D does not appear to do the desired thing when
|
|
|
|
// the angle sweeps a complete circle.
|
2015-11-19 22:57:32 +03:00
|
|
|
bool fullCircle = false;
|
2011-06-24 21:41:16 +04:00
|
|
|
if (aEndAngle - aStartAngle >= 2 * M_PI) {
|
2015-11-19 22:57:32 +03:00
|
|
|
fullCircle = true;
|
|
|
|
aEndAngle = Float(aStartAngle + M_PI * 1.9999);
|
2011-06-24 21:41:16 +04:00
|
|
|
} else if (aStartAngle - aEndAngle >= 2 * M_PI) {
|
2015-11-19 22:57:32 +03:00
|
|
|
fullCircle = true;
|
|
|
|
aStartAngle = Float(aEndAngle + M_PI * 1.9999);
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Point startPoint;
|
|
|
|
startPoint.x = aOrigin.x + aRadius * cos(aStartAngle);
|
|
|
|
startPoint.y = aOrigin.y + aRadius * sin(aStartAngle);
|
|
|
|
|
|
|
|
if (!mFigureActive) {
|
|
|
|
EnsureActive(startPoint);
|
|
|
|
} else {
|
|
|
|
mSink->AddLine(D2DPoint(startPoint));
|
|
|
|
}
|
|
|
|
|
|
|
|
Point endPoint;
|
2015-09-29 03:12:07 +03:00
|
|
|
endPoint.x = aOrigin.x + aRadius * cosf(aEndAngle);
|
|
|
|
endPoint.y = aOrigin.y + aRadius * sinf(aEndAngle);
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
D2D1_ARC_SIZE arcSize = D2D1_ARC_SIZE_SMALL;
|
2015-07-06 23:46:00 +03:00
|
|
|
D2D1_SWEEP_DIRECTION direction =
|
|
|
|
aAntiClockwise ? D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE :
|
|
|
|
D2D1_SWEEP_DIRECTION_CLOCKWISE;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-11-19 22:57:32 +03:00
|
|
|
// if startPoint and endPoint of our circle are too close there are D2D issues
|
|
|
|
// with drawing the circle as a single arc
|
|
|
|
const Float kEpsilon = 1e-5f;
|
|
|
|
if (!fullCircle ||
|
|
|
|
(std::abs(startPoint.x - endPoint.x) +
|
|
|
|
std::abs(startPoint.y - endPoint.y) > kEpsilon)) {
|
2015-07-06 23:46:00 +03:00
|
|
|
|
|
|
|
if (aAntiClockwise) {
|
|
|
|
if (aStartAngle - aEndAngle > M_PI) {
|
|
|
|
arcSize = D2D1_ARC_SIZE_LARGE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aEndAngle - aStartAngle > M_PI) {
|
|
|
|
arcSize = D2D1_ARC_SIZE_LARGE;
|
|
|
|
}
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
2015-07-06 23:46:00 +03:00
|
|
|
mSink->AddArc(D2D1::ArcSegment(D2DPoint(endPoint),
|
|
|
|
D2D1::SizeF(aRadius, aRadius),
|
|
|
|
0.0f,
|
|
|
|
direction,
|
|
|
|
arcSize));
|
|
|
|
}
|
|
|
|
else {
|
2015-11-19 22:57:32 +03:00
|
|
|
// our first workaround attempt didn't work, so instead draw the circle as
|
|
|
|
// two half-circles
|
|
|
|
Float midAngle = aEndAngle > aStartAngle ?
|
|
|
|
Float(aStartAngle + M_PI) : Float(aEndAngle + M_PI);
|
2015-07-06 23:46:00 +03:00
|
|
|
Point midPoint;
|
2015-09-29 03:12:07 +03:00
|
|
|
midPoint.x = aOrigin.x + aRadius * cosf(midAngle);
|
|
|
|
midPoint.y = aOrigin.y + aRadius * sinf(midAngle);
|
2015-07-06 23:46:00 +03:00
|
|
|
|
|
|
|
mSink->AddArc(D2D1::ArcSegment(D2DPoint(midPoint),
|
|
|
|
D2D1::SizeF(aRadius, aRadius),
|
|
|
|
0.0f,
|
|
|
|
direction,
|
|
|
|
arcSize));
|
|
|
|
|
2015-11-19 22:57:32 +03:00
|
|
|
// if the adjusted endPoint computed above is used here and endPoint !=
|
|
|
|
// startPoint then this half of the circle won't render...
|
|
|
|
mSink->AddArc(D2D1::ArcSegment(D2DPoint(startPoint),
|
2015-07-06 23:46:00 +03:00
|
|
|
D2D1::SizeF(aRadius, aRadius),
|
|
|
|
0.0f,
|
|
|
|
direction,
|
|
|
|
arcSize));
|
|
|
|
}
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
mCurrentPoint = endPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
Point
|
|
|
|
PathBuilderD2D::CurrentPoint() const
|
|
|
|
{
|
|
|
|
return mCurrentPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathBuilderD2D::EnsureActive(const Point &aPoint)
|
|
|
|
{
|
|
|
|
if (!mFigureActive) {
|
|
|
|
mSink->BeginFigure(D2DPoint(aPoint), D2D1_FIGURE_BEGIN_FILLED);
|
|
|
|
mBeginPoint = aPoint;
|
|
|
|
mFigureActive = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<Path>
|
2011-06-24 21:41:16 +04:00
|
|
|
PathBuilderD2D::Finish()
|
|
|
|
{
|
|
|
|
if (mFigureActive) {
|
|
|
|
mSink->EndFigure(D2D1_FIGURE_END_OPEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = mSink->Close();
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 19:35:39 +04:00
|
|
|
gfxDebug() << "Failed to close PathSink. Code: " << hexa(hr);
|
2012-08-14 22:06:12 +04:00
|
|
|
return nullptr;
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
2015-04-30 22:20:30 +03:00
|
|
|
return MakeAndAddRef<PathD2D>(mGeometry, mFigureActive, mCurrentPoint, mFillRule, mBackendType);
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<PathBuilder>
|
2011-06-24 21:41:16 +04:00
|
|
|
PathD2D::CopyToBuilder(FillRule aFillRule) const
|
|
|
|
{
|
|
|
|
return TransformedCopyToBuilder(Matrix(), aFillRule);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<PathBuilder>
|
2011-06-24 21:41:16 +04:00
|
|
|
PathD2D::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1PathGeometry> path;
|
2016-02-13 16:33:28 +03:00
|
|
|
HRESULT hr = DrawTargetD2D1::factory()->CreatePathGeometry(getter_AddRefs(path));
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 19:35:39 +04:00
|
|
|
gfxWarning() << "Failed to create PathGeometry. Code: " << hexa(hr);
|
2012-08-14 22:06:12 +04:00
|
|
|
return nullptr;
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1GeometrySink> sink;
|
2015-10-18 07:40:10 +03:00
|
|
|
hr = path->Open(getter_AddRefs(sink));
|
2011-06-24 21:41:16 +04:00
|
|
|
if (FAILED(hr)) {
|
2014-09-23 19:35:39 +04:00
|
|
|
gfxWarning() << "Failed to open Geometry for writing. Code: " << hexa(hr);
|
2012-08-14 22:06:12 +04:00
|
|
|
return nullptr;
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
2014-01-10 23:06:17 +04:00
|
|
|
if (aFillRule == FillRule::FILL_WINDING) {
|
2011-06-24 21:41:16 +04:00
|
|
|
sink->SetFillMode(D2D1_FILL_MODE_WINDING);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mEndedActive) {
|
|
|
|
OpeningGeometrySink wrapSink(sink);
|
|
|
|
mGeometry->Simplify(D2D1_GEOMETRY_SIMPLIFICATION_OPTION_CUBICS_AND_LINES,
|
|
|
|
D2DMatrix(aTransform),
|
|
|
|
&wrapSink);
|
|
|
|
} else {
|
|
|
|
mGeometry->Simplify(D2D1_GEOMETRY_SIMPLIFICATION_OPTION_CUBICS_AND_LINES,
|
|
|
|
D2DMatrix(aTransform),
|
|
|
|
sink);
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PathBuilderD2D> pathBuilder = new PathBuilderD2D(sink, path, aFillRule, mBackendType);
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
pathBuilder->mCurrentPoint = aTransform * mEndPoint;
|
|
|
|
|
|
|
|
if (mEndedActive) {
|
|
|
|
pathBuilder->mFigureActive = true;
|
|
|
|
}
|
|
|
|
|
2014-06-13 20:09:23 +04:00
|
|
|
return pathBuilder.forget();
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
2013-11-07 13:10:53 +04:00
|
|
|
void
|
|
|
|
PathD2D::StreamToSink(PathSink *aSink) const
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
StreamingGeometrySink sink(aSink);
|
|
|
|
|
|
|
|
hr = mGeometry->Simplify(D2D1_GEOMETRY_SIMPLIFICATION_OPTION_CUBICS_AND_LINES,
|
|
|
|
D2D1::IdentityMatrix(), &sink);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 19:35:39 +04:00
|
|
|
gfxWarning() << "Failed to stream D2D path to sink. Code: " << hexa(hr);
|
2013-11-07 13:10:53 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
bool
|
|
|
|
PathD2D::ContainsPoint(const Point &aPoint, const Matrix &aTransform) const
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
|
|
|
|
HRESULT hr = mGeometry->FillContainsPoint(D2DPoint(aPoint), D2DMatrix(aTransform), 0.001f, &result);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2012-10-29 19:54:53 +04:00
|
|
|
// Log
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !!result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PathD2D::StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
|
|
|
|
const Point &aPoint,
|
|
|
|
const Matrix &aTransform) const
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
2012-10-29 19:54:53 +04:00
|
|
|
HRESULT hr = mGeometry->StrokeContainsPoint(D2DPoint(aPoint),
|
|
|
|
aStrokeOptions.mLineWidth,
|
|
|
|
strokeStyle,
|
|
|
|
D2DMatrix(aTransform),
|
|
|
|
&result);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2011-06-24 21:41:16 +04:00
|
|
|
// Log
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !!result;
|
|
|
|
}
|
|
|
|
|
2011-07-13 04:34:40 +04:00
|
|
|
Rect
|
|
|
|
PathD2D::GetBounds(const Matrix &aTransform) const
|
|
|
|
{
|
2013-11-04 05:47:18 +04:00
|
|
|
D2D1_RECT_F d2dBounds;
|
2011-07-13 04:34:40 +04:00
|
|
|
|
2013-11-04 05:47:18 +04:00
|
|
|
HRESULT hr = mGeometry->GetBounds(D2DMatrix(aTransform), &d2dBounds);
|
2011-07-13 04:34:40 +04:00
|
|
|
|
2013-11-04 05:47:18 +04:00
|
|
|
Rect bounds = ToRect(d2dBounds);
|
|
|
|
if (FAILED(hr) || !bounds.IsFinite()) {
|
2014-09-23 19:35:39 +04:00
|
|
|
gfxWarning() << "Failed to get stroked bounds for path. Code: " << hexa(hr);
|
2013-11-04 05:47:18 +04:00
|
|
|
return Rect();
|
2011-07-13 04:34:40 +04:00
|
|
|
}
|
|
|
|
|
2013-11-04 05:47:18 +04:00
|
|
|
return bounds;
|
2011-07-13 04:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Rect
|
|
|
|
PathD2D::GetStrokedBounds(const StrokeOptions &aStrokeOptions,
|
|
|
|
const Matrix &aTransform) const
|
|
|
|
{
|
2013-11-04 05:47:18 +04:00
|
|
|
D2D1_RECT_F d2dBounds;
|
2011-07-13 04:34:40 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
2011-07-13 04:34:40 +04:00
|
|
|
HRESULT hr =
|
|
|
|
mGeometry->GetWidenedBounds(aStrokeOptions.mLineWidth, strokeStyle,
|
2013-11-04 05:47:18 +04:00
|
|
|
D2DMatrix(aTransform), &d2dBounds);
|
2011-07-13 04:34:40 +04:00
|
|
|
|
2013-11-04 05:47:18 +04:00
|
|
|
Rect bounds = ToRect(d2dBounds);
|
|
|
|
if (FAILED(hr) || !bounds.IsFinite()) {
|
2014-09-23 19:35:39 +04:00
|
|
|
gfxWarning() << "Failed to get stroked bounds for path. Code: " << hexa(hr);
|
2013-11-04 05:47:18 +04:00
|
|
|
return Rect();
|
2011-07-13 04:34:40 +04:00
|
|
|
}
|
|
|
|
|
2013-11-04 05:47:18 +04:00
|
|
|
return bounds;
|
2011-07-13 04:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|