Fix: element.comp填充样式渲染错误 |#13
parent
0e62672b58
commit
12b62bf039
|
@ -1071,16 +1071,16 @@ void main()
|
|||
if (num_its % 2 == 1)
|
||||
{
|
||||
hitElement = true;
|
||||
elementColor = vec4(1, 1, 0, 0);
|
||||
|
||||
vec4 head = unpackUnorm4x8(floatBitsToUint(style[styleIndex]));
|
||||
if (head.z == 0)
|
||||
{
|
||||
elementColor = vec4(unpackUnorm4x8(floatBitsToUint(style[++styleIndex])).rgb, 1);
|
||||
}
|
||||
elementColor = vec4(unpackUnorm4x8(floatBitsToUint(style[styleIndex+1])).rgb, 1);
|
||||
}
|
||||
|
||||
}
|
||||
styleIndex += 2;
|
||||
}
|
||||
else // Stroke
|
||||
{
|
||||
float minDistance = 1e38;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <QtWidgets/QApplication>
|
||||
#include "ElementRendererTest.h"
|
||||
#include "Renderer/Painting/ElementStyle.h"
|
||||
|
||||
#include "Renderer/Painting/MaterialStyleFill.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace Renderer;
|
||||
|
@ -12,13 +12,63 @@ namespace UnitTest
|
|||
{
|
||||
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg);
|
||||
|
||||
TEST_CLASS(ElementRendererFillTest)
|
||||
{
|
||||
private:
|
||||
char* argv[1];
|
||||
int argc;
|
||||
QPainterPath path;
|
||||
public:
|
||||
ElementRendererFillTest() :argv{ (char*)"" }, argc(1)
|
||||
{
|
||||
QQuickSvgParser::parsePathDataFast("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z",
|
||||
path);
|
||||
QTransform transform;
|
||||
//transform.scale(10, 10);
|
||||
path = transform.map(path);
|
||||
}
|
||||
|
||||
TEST_METHOD_INITIALIZE(initialize)
|
||||
{
|
||||
qInstallMessageHandler(messageHandler);
|
||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
}
|
||||
TEST_METHOD(TestFillPlain)
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
class Style : public Renderer::ElementStyle
|
||||
{
|
||||
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
|
||||
{
|
||||
|
||||
return { BaseStyle(std::make_shared<TransformStyle>(),
|
||||
std::make_shared<MaterialStyleFill>(
|
||||
std::make_shared<FillPlain>(Material(QColor(255,255,0))))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TEST_CLASS(ElementRendererStokeTypeTest)
|
||||
{
|
||||
private:
|
||||
char* argv[1];
|
||||
int argc;
|
||||
QPainterPath path;
|
||||
public:
|
||||
ElementRendererStokeTypeTest() :argv{ (char*)"" }, argc(1) {}
|
||||
ElementRendererStokeTypeTest() :argv{ (char*)"" }, argc(1)
|
||||
{
|
||||
QQuickSvgParser::parsePathDataFast("M292.82,107.78s0,0,0,0,0,3.59,0,7.62c0,3.85,0,5.78.06,6.43a19.94,19.94,0,0,0,2.87,7.58,15.85,15.85,0,0,0,6.61,6.23A14.75,14.75,0,0,0,310,137a11.69,11.69,0,0,0,7.59-2.92,11,11,0,0,0,3.2-6.84c.15-1.27.58-4.84-1.79-7.64a8.54,8.54,0,0,0-3.56-2.44c-1.32-.52-3.32-1.31-5.06-.33a5.41,5.41,0,0,0-2.14,3,3.48,3.48,0,0,0-.16,2.71c.78,1.86,3.36,2.14,3.47,2.15", path);
|
||||
QTransform transform;
|
||||
transform.scale(10, 10);
|
||||
path = transform.map(path);
|
||||
}
|
||||
|
||||
TEST_METHOD_INITIALIZE(initialize)
|
||||
{
|
||||
|
@ -44,7 +94,7 @@ namespace UnitTest
|
|||
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style);
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
|
@ -65,7 +115,7 @@ namespace UnitTest
|
|||
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style);
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
|
@ -86,7 +136,7 @@ namespace UnitTest
|
|||
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style);
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
|
@ -107,7 +157,7 @@ namespace UnitTest
|
|||
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style);
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
|
@ -128,7 +178,7 @@ namespace UnitTest
|
|||
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style);
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
|
@ -139,8 +189,15 @@ namespace UnitTest
|
|||
private:
|
||||
char* argv[1];
|
||||
int argc;
|
||||
QPainterPath path;
|
||||
public:
|
||||
ElementRendererStokeMaterialTest() :argv{ (char*)"" }, argc(1) {}
|
||||
ElementRendererStokeMaterialTest() :argv{ (char*)"" }, argc(1)
|
||||
{
|
||||
QQuickSvgParser::parsePathDataFast("M292.82,107.78s0,0,0,0,0,3.59,0,7.62c0,3.85,0,5.78.06,6.43a19.94,19.94,0,0,0,2.87,7.58,15.85,15.85,0,0,0,6.61,6.23A14.75,14.75,0,0,0,310,137a11.69,11.69,0,0,0,7.59-2.92,11,11,0,0,0,3.2-6.84c.15-1.27.58-4.84-1.79-7.64a8.54,8.54,0,0,0-3.56-2.44c-1.32-.52-3.32-1.31-5.06-.33a5.41,5.41,0,0,0-2.14,3,3.48,3.48,0,0,0-.16,2.71c.78,1.86,3.36,2.14,3.47,2.15", path);
|
||||
QTransform transform;
|
||||
transform.scale(10, 10);
|
||||
path = transform.map(path);
|
||||
}
|
||||
TEST_METHOD(TestStrokePlain)
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
@ -153,7 +210,7 @@ namespace UnitTest
|
|||
std::make_shared<StrokePlain>(QColor(255,255,255),1,1))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style);
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
|
@ -174,7 +231,7 @@ namespace UnitTest
|
|||
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style);
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
|
@ -195,7 +252,7 @@ namespace UnitTest
|
|||
std::make_shared<StrokeRadialGradient>(materialMap, true))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style);
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
|
|
|
@ -16,29 +16,25 @@ namespace UnitTest
|
|||
private:
|
||||
Renderer::ElementRenderer& renderer;
|
||||
Renderer::ElementStyle& style;
|
||||
QPainterPath& path;
|
||||
public:
|
||||
TestGLWidget(Renderer::ElementStyle& style, QWidget* parent = nullptr)
|
||||
: QOpenGLWidget(parent), renderer(*Renderer::ElementRenderer::instance()), style(style) {};
|
||||
TestGLWidget(Renderer::ElementStyle& style, QPainterPath& path, QWidget* parent = nullptr)
|
||||
: QOpenGLWidget(parent), renderer(*Renderer::ElementRenderer::instance()), style(style), path(path) {};
|
||||
void initializeGL() override
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
};
|
||||
void paintGL() override
|
||||
{
|
||||
glClearColor(219/255., 78/255., 32/255., 1.0);
|
||||
glClearColor(219 / 255., 78 / 255., 32 / 255., 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
QPainterPath path;
|
||||
QQuickSvgParser::parsePathDataFast("M292.82,107.78s0,0,0,0,0,3.59,0,7.62c0,3.85,0,5.78.06,6.43a19.94,19.94,0,0,0,2.87,7.58,15.85,15.85,0,0,0,6.61,6.23A14.75,14.75,0,0,0,310,137a11.69,11.69,0,0,0,7.59-2.92,11,11,0,0,0,3.2-6.84c.15-1.27.58-4.84-1.79-7.64a8.54,8.54,0,0,0-3.56-2.44c-1.32-.52-3.32-1.31-5.06-.33a5.41,5.41,0,0,0-2.14,3,3.48,3.48,0,0,0-.16,2.71c.78,1.86,3.36,2.14,3.47,2.15", path);
|
||||
path = PainterPathUtil::monotonization(path);
|
||||
QTransform transform;
|
||||
transform.scale(10, 10);
|
||||
path = transform.map(path);
|
||||
|
||||
float pixelRatio = devicePixelRatioF();
|
||||
auto [img, pos] = renderer.drawElement(path, style, pixelRatio);
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
painter.drawImage(QRectF(QPointF(0, 0), img.size()/pixelRatio), img);
|
||||
painter.drawImage(QRectF(QPointF(0, 0), img.size() / pixelRatio), img);
|
||||
};
|
||||
void resizeGL(int w, int h) override {};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue