From a84c8cb7522fe4770521d8c2d12ed7876c578ce7 Mon Sep 17 00:00:00 2001 From: wuyize Date: Mon, 20 Mar 2023 23:22:44 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20StrokeEndType::kClosed=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4_L0.json | 2 +- ...rchitectureColoredPainting.vcxproj.filters | 6 ++-- .../res/Shaders/element.comp | 23 ++++++++------ UnitTest/ElementRendererTest.cpp | 25 +++++++++++++++ svg/4_L0.svg | 7 ++--- test.json | 31 +++++++++++++++++++ 6 files changed, 76 insertions(+), 18 deletions(-) diff --git a/4_L0.json b/4_L0.json index 2465bb6..46e76f0 100644 --- a/4_L0.json +++ b/4_L0.json @@ -24,7 +24,7 @@ }, { "data": { - "include": "D:/BigC2022/temp/ArchitectureColoredPainting/svg/4_L0-fill.svg" + "include": "D:/BigC2022/temp/ArchitectureColoredPainting/svg/4_L0.svg" }, "name": "4_L0-fill.svg", "type": "svg-file" diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index 22b36f7..ec634e5 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -225,9 +225,6 @@ Source Files\Editor - - Source Files\Editor - Source Files\Editor @@ -264,6 +261,9 @@ Source Files + + Source Files\Editor + diff --git a/ArchitectureColoredPainting/res/Shaders/element.comp b/ArchitectureColoredPainting/res/Shaders/element.comp index 511c470..e8c1ca6 100644 --- a/ArchitectureColoredPainting/res/Shaders/element.comp +++ b/ArchitectureColoredPainting/res/Shaders/element.comp @@ -1131,14 +1131,8 @@ void main() { vec2 pTemp = path[pathIndex + 1]; if (isinf(pTemp.x)) - { - if(endType == 4) - { - //onVeryEnd = false; - tangentBeginNext = tangentFirstBegin; - } - else - onVeryEnd = true; + { + onVeryEnd = true; } else { @@ -1151,7 +1145,16 @@ void main() } } else - onVeryEnd = true; + { + if(endType == 4) + { + //onVeryEnd = false; + tangentBeginNext = tangentFirstBegin; + } + else + onVeryEnd = true; + } + float d = cubic_bezier_dis(localUV, p[0], p[1], p[2], p[3], true); if (d <= strokeWidth) @@ -1199,7 +1202,7 @@ void main() } } tangentEndLast = tangentEnd; - if(pathIndex == 0) + if(pathIndex == 4) tangentFirstBegin = tangentBegin; } p3Last = p[3]; diff --git a/UnitTest/ElementRendererTest.cpp b/UnitTest/ElementRendererTest.cpp index 5760980..c1c12ab 100644 --- a/UnitTest/ElementRendererTest.cpp +++ b/UnitTest/ElementRendererTest.cpp @@ -4,6 +4,7 @@ #include "ElementRendererTest.h" #include "Renderer/Painting/ElementStyle.h" #include "Renderer/Painting/MaterialStyleFill.h" +#include "Editor/util/SvgFileLoader.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Renderer; @@ -203,6 +204,30 @@ namespace UnitTest w.show(); a.exec(); } + TEST_METHOD(TestBothSidesClosed) + { + QPainterPath closedPath; + SvgFileLoader().loadSvgFile("../../svg/4_L0.svg", closedPath); + closedPath = QTransform::fromScale(5, 5).map(closedPath); + QApplication a(argc, argv); + class StyleStrokeRadialGradient : public Renderer::ElementStyle + { + virtual std::vector toBaseStyles() const override + { + std::map materialMap = { + {0.20, Material{QColor(255,255,255)}}, + {0.60, Material{QColor(165,176,207)}}, + {1.00, Material{QColor(58,64,151)}} + }; + return { BaseStyle(std::make_shared(), + std::make_shared(20, StrokeType::kLeftSide, StrokeEndType::kClosed, + std::make_shared(materialMap, false))) }; + } + } style; + TestGLWidget w(style, closedPath); + w.show(); + a.exec(); + } }; TEST_CLASS(ElementRendererStokeMaterialTest) diff --git a/svg/4_L0.svg b/svg/4_L0.svg index 58facaf..c2a99b3 100644 --- a/svg/4_L0.svg +++ b/svg/4_L0.svg @@ -1,5 +1,4 @@ - - 4_L0 - - + + 4_L0的副本 + diff --git a/test.json b/test.json index c5158fb..d369f0c 100644 --- a/test.json +++ b/test.json @@ -21,6 +21,13 @@ }, "name": "ababa2", "type": "svg-file" + }, + { + "data": { + "include": "D:/BigC2022/temp/ArchitectureColoredPainting/svg/3.svg" + }, + "name": "3.svg", + "type": "svg-file" } ], "height": 1080, @@ -76,6 +83,30 @@ "y": 1.5 } } + }, + { + "element": -842150451, + "is-folder": false, + "name": "子图层-3", + "styles": [ + { + "enableEachSideIndependent": false, + "left": "AAAAQAEAIZwAf///AP8A/w==", + "right": "AADgQAAACJw=", + "type": "stroke" + } + ], + "transform": { + "offset": { + "x": 0, + "y": 0 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } } ], "is-folder": true,