Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the iterator call in the Path::decompose method #341

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ void Path::decompose(const PathIterator& iterator, void* info) const {
case SkPath::kConic_Verb:
// approximate with 2^1=2 quads.
SkPath::ConvertConicToQuads(points[0], points[1], points[2], iter.conicWeight(), quads, 1);
iterator(PathVerb::Quad, reinterpret_cast<Point*>(quads), info);
iterator(PathVerb::Quad, reinterpret_cast<Point*>(quads) + 2, info);
iterator(PathVerb::Quad, reinterpret_cast<Point*>(quads) + 1, info);
iterator(PathVerb::Quad, reinterpret_cast<Point*>(quads) + 3, info);
break;
case SkPath::kCubic_Verb:
iterator(PathVerb::Cubic, reinterpret_cast<Point*>(points), info);
Expand Down
1 change: 1 addition & 0 deletions test/baseline/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Path_addArc_reversed6": "4802e56",
"Path_addArc_reversed7": "4802e56",
"Path_addArc_reversed8": "4802e56",
"Path_decompose": "2bf38d0",
"Picture": "d069eb4",
"PictureImage": "8a2ac4d",
"PictureImage_Path": "2212c4e",
Expand Down
50 changes: 50 additions & 0 deletions test/src/CanvasTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@
#include "gpu/ops/RectDrawOp.h"
#include "tgfx/core/Buffer.h"
#include "tgfx/core/Canvas.h"
#include "tgfx/core/Color.h"
#include "tgfx/core/ImageCodec.h"
#include "tgfx/core/ImageReader.h"
#include "tgfx/core/Mask.h"
#include "tgfx/core/Paint.h"
#include "tgfx/core/Path.h"
#include "tgfx/core/PathEffect.h"
#include "tgfx/core/PathTypes.h"
#include "tgfx/core/Recorder.h"
#include "tgfx/core/Rect.h"
#include "tgfx/core/Stream.h"
#include "tgfx/core/Surface.h"
#include "tgfx/gpu/opengl/GLFunctions.h"
Expand Down Expand Up @@ -1261,4 +1266,49 @@ TGFX_TEST(CanvasTest, Path_addArc) {
}
device->unlock();
}

TGFX_TEST(CanvasTest, Path_decompose) {
auto device = DevicePool::Make();
ASSERT_TRUE(device != nullptr);
auto* context = device->lockContext();
ASSERT_TRUE(context != nullptr);
auto surface = Surface::Make(context, 600, 500);
auto* canvas = surface->getCanvas();

Paint paint;
paint.setColor(Color::Red());
paint.setStyle(PaintStyle::Stroke);
paint.setStrokeWidth(5);

Path path;
path.addOval(Rect::MakeXYWH(50, 50, 100, 100));
canvas->drawPath(path, paint);

Path fitPath;
auto pathIter = [&](PathVerb verb, const Point points[4], void*) -> void {
switch (verb) {
case PathVerb::Move:
fitPath.moveTo(points[0]);
break;
case PathVerb::Line:
fitPath.lineTo(points[0]);
break;
case PathVerb::Quad:
fitPath.quadTo(points[0], points[1]);
break;
case PathVerb::Cubic:
fitPath.cubicTo(points[0], points[1], points[2]);
break;
case PathVerb::Close:
fitPath.close();
break;
}
};
path.decompose(pathIter, nullptr);

canvas->translate(0.f, 200.f);
canvas->drawPath(fitPath, paint);
EXPECT_TRUE(Baseline::Compare(surface, "CanvasTest/Path_decompose"));
}

} // namespace tgfx
Loading