Skip to content

Commit

Permalink
Fix the iterator call in the Path::decompose method to correctly hand…
Browse files Browse the repository at this point in the history
…le conic convert to quad Bezier curves;
  • Loading branch information
YGaurora committed Nov 26, 2024
1 parent 2bf38d0 commit 829bb4d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
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
3 changes: 2 additions & 1 deletion test/baseline/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"text_shape": "74f94c4",
"tile_mode_normal": "8cb853c",
"tile_mode_rgbaaa": "8cb853c",
"tile_mode_subset": "8cb853c"
"tile_mode_subset": "8cb853c",
"Path_decompose": "2bf38d0"
},
"DrawersTest": {
"ConicGradient": "5a1fb11",
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

0 comments on commit 829bb4d

Please sign in to comment.