Fix: StrokeEndType::kClosed渲染不正确

dev-wuyize
wuyize 2023-03-20 23:22:44 +08:00
parent e39eb15f03
commit a84c8cb752
6 changed files with 76 additions and 18 deletions

View File

@ -24,7 +24,7 @@
}, },
{ {
"data": { "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", "name": "4_L0-fill.svg",
"type": "svg-file" "type": "svg-file"

View File

@ -225,9 +225,6 @@
<ClCompile Include="src\NavigationBarWidget.cpp"> <ClCompile Include="src\NavigationBarWidget.cpp">
<Filter>Source Files\Editor</Filter> <Filter>Source Files\Editor</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Editor\EditorWidgetComponent\ColorPicker.cpp">
<Filter>Source Files\Editor</Filter>
</ClCompile>
<ClCompile Include="src\Editor\EditorWidget.cpp"> <ClCompile Include="src\Editor\EditorWidget.cpp">
<Filter>Source Files\Editor</Filter> <Filter>Source Files\Editor</Filter>
</ClCompile> </ClCompile>
@ -264,6 +261,9 @@
<ClCompile Include="src\Editor\DataManager\ProjectDataManager.cpp"> <ClCompile Include="src\Editor\DataManager\ProjectDataManager.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Editor\EditorWidgetComponent\ColorPicker.cpp">
<Filter>Source Files\Editor</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtMoc Include="src\Renderer\RendererGLWidget.h"> <QtMoc Include="src\Renderer\RendererGLWidget.h">

View File

@ -1132,13 +1132,7 @@ void main()
vec2 pTemp = path[pathIndex + 1]; vec2 pTemp = path[pathIndex + 1];
if (isinf(pTemp.x)) if (isinf(pTemp.x))
{ {
if(endType == 4) onVeryEnd = true;
{
//onVeryEnd = false;
tangentBeginNext = tangentFirstBegin;
}
else
onVeryEnd = true;
} }
else else
{ {
@ -1151,7 +1145,16 @@ void main()
} }
} }
else 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); float d = cubic_bezier_dis(localUV, p[0], p[1], p[2], p[3], true);
if (d <= strokeWidth) if (d <= strokeWidth)
@ -1199,7 +1202,7 @@ void main()
} }
} }
tangentEndLast = tangentEnd; tangentEndLast = tangentEnd;
if(pathIndex == 0) if(pathIndex == 4)
tangentFirstBegin = tangentBegin; tangentFirstBegin = tangentBegin;
} }
p3Last = p[3]; p3Last = p[3];

View File

@ -4,6 +4,7 @@
#include "ElementRendererTest.h" #include "ElementRendererTest.h"
#include "Renderer/Painting/ElementStyle.h" #include "Renderer/Painting/ElementStyle.h"
#include "Renderer/Painting/MaterialStyleFill.h" #include "Renderer/Painting/MaterialStyleFill.h"
#include "Editor/util/SvgFileLoader.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Renderer; using namespace Renderer;
@ -203,6 +204,30 @@ namespace UnitTest
w.show(); w.show();
a.exec(); 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<Renderer::BaseStyle> toBaseStyles() const override
{
std::map<float, Material> 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<TransformStyle>(),
std::make_shared<MaterialStyleStroke>(20, StrokeType::kLeftSide, StrokeEndType::kClosed,
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
}
} style;
TestGLWidget w(style, closedPath);
w.show();
a.exec();
}
}; };
TEST_CLASS(ElementRendererStokeMaterialTest) TEST_CLASS(ElementRendererStokeMaterialTest)

View File

@ -1,5 +1,4 @@
<svg id="万字笔画" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1068 1045"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 141 171">
<title>4_L0</title> <title>4_L0的副本</title>
<polyline points="873 0 360 390 427 483 490 439 600 592 690 524 750 608 189 1045" fill="none"/> <polygon points="0.5 0.5 140.5 0.5 140.5 10.5 115.5 10.5 115.5 35.5 105.5 35.5 105.5 10.5 75.5 10.5 75.5 160.5 105.5 160.5 105.5 135.5 115.5 135.5 115.5 160.5 140.5 160.5 140.5 170.5 0.5 170.5 0.5 160.5 25.5 160.5 25.5 135.5 35.5 135.5 35.5 160.5 65.5 160.5 65.5 10.5 35.5 10.5 35.5 35.5 25.5 35.5 25.5 10.5 0.5 10.5 0.5 0.5" fill="none" stroke="#000" stroke-miterlimit="10"/>
<polyline points="1068 830 651 303 566 373 629 455 487 566 538 632 461 696 0 99" fill="none"/>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 307 B

After

Width:  |  Height:  |  Size: 480 B

View File

@ -21,6 +21,13 @@
}, },
"name": "ababa2", "name": "ababa2",
"type": "svg-file" "type": "svg-file"
},
{
"data": {
"include": "D:/BigC2022/temp/ArchitectureColoredPainting/svg/3.svg"
},
"name": "3.svg",
"type": "svg-file"
} }
], ],
"height": 1080, "height": 1080,
@ -76,6 +83,30 @@
"y": 1.5 "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, "is-folder": true,