From 829bb4dcf7a146d44d21dec7765417bfe3485aae Mon Sep 17 00:00:00 2001 From: YGauroa Date: Tue, 26 Nov 2024 19:37:46 +0800 Subject: [PATCH 1/2] Fix the iterator call in the Path::decompose method to correctly handle conic convert to quad Bezier curves; --- src/core/Path.cpp | 4 +-- test/baseline/version.json | 3 ++- test/src/CanvasTest.cpp | 50 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/core/Path.cpp b/src/core/Path.cpp index 8999a6a0..b2805c01 100644 --- a/src/core/Path.cpp +++ b/src/core/Path.cpp @@ -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(quads), info); - iterator(PathVerb::Quad, reinterpret_cast(quads) + 2, info); + iterator(PathVerb::Quad, reinterpret_cast(quads) + 1, info); + iterator(PathVerb::Quad, reinterpret_cast(quads) + 3, info); break; case SkPath::kCubic_Verb: iterator(PathVerb::Cubic, reinterpret_cast(points), info); diff --git a/test/baseline/version.json b/test/baseline/version.json index 197824cc..8f966ad6 100644 --- a/test/baseline/version.json +++ b/test/baseline/version.json @@ -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", diff --git a/test/src/CanvasTest.cpp b/test/src/CanvasTest.cpp index f85e96be..8cfc6d0f 100644 --- a/test/src/CanvasTest.cpp +++ b/test/src/CanvasTest.cpp @@ -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" @@ -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 From b15dc1647a95f078453407835e300cdf81d3d4b4 Mon Sep 17 00:00:00 2001 From: YGauroa Date: Tue, 26 Nov 2024 19:55:34 +0800 Subject: [PATCH 2/2] replace version md5 --- test/baseline/version.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/baseline/version.json b/test/baseline/version.json index 8f966ad6..b5b72c9d 100644 --- a/test/baseline/version.json +++ b/test/baseline/version.json @@ -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", @@ -49,8 +50,7 @@ "text_shape": "74f94c4", "tile_mode_normal": "8cb853c", "tile_mode_rgbaaa": "8cb853c", - "tile_mode_subset": "8cb853c", - "Path_decompose": "2bf38d0" + "tile_mode_subset": "8cb853c" }, "DrawersTest": { "ConicGradient": "5a1fb11",