修改了PixelPath

dev-LayerStyle
karlis 2023-03-15 16:16:59 +08:00
parent 073f68e360
commit 3b87644e21
10 changed files with 69 additions and 9 deletions

View File

@ -41,7 +41,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
layerManager = new LayerManager(source, elementManager); layerManager = new LayerManager(source, elementManager);
elementInfoDisplayWidget->setElementManager(elementManager); elementInfoDisplayWidget->setElementManager(elementManager);
treeWidget->elementManager = elementManager; treeWidget->elementManager = elementManager;
qDebug() << layerManager->toJson(); //qDebug() << layerManager->toJson();
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble())); previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble()));

View File

@ -1,11 +1,14 @@
#include "GraphicElement.h" #include "GraphicElement.h"
#include "util/SvgFileLoader.h" #include "util/SvgFileLoader.h"
#include <QGuiApplication>
#include <QScreen>
using namespace std; using namespace std;
PixelPath SimpleElement::getPaintObject() const PixelPath SimpleElement::getPaintObject() const
{ {
PixelPath result; PixelPath result;
result.addPath(painterPath); result.addPath(painterPath);
qDebug() << result.getPainterPath();
return result; return result;
} }
@ -48,7 +51,7 @@ PixelPath SimpleElement::getPaintObject(std::vector<std::shared_ptr<LayerStyle>>
std::shared_ptr<Renderer::ElementStyle> style; std::shared_ptr<Renderer::ElementStyle> style;
if ((*styles).empty()) if ((*styles).empty())
{ {
style = std::make_shared<Renderer::ElementStyleStrokeDemo>(2); return this->getPaintObject();
} }
else else
{ {
@ -63,6 +66,7 @@ PixelPath SimpleElement::getPaintObject(std::vector<std::shared_ptr<LayerStyle>>
auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0); auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0);
//qDebug() << img << " ------"; //qDebug() << img << " ------";
result.addImage(img, mov); result.addImage(img, mov);
result.addPath(painterPath);
//result.addPath(painterPath); //result.addPath(painterPath);
// QImage img(80,80,QImage::Format_ARGB32); // QImage img(80,80,QImage::Format_ARGB32);
// QPainter pt(&img); // QPainter pt(&img);
@ -124,8 +128,15 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const vector<
std::dynamic_pointer_cast<StrokeElementLayerStyle>(style)->materialStyles[0]->materialStroke std::dynamic_pointer_cast<StrokeElementLayerStyle>(style)->materialStyles[0]->materialStroke
)->materialMap[1.0].color;*/ )->materialMap[1.0].color;*/
} }
auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0); QVector2D scale(transform.m11(), transform.m22());
scale /= transform.m33();
double maxScale = std::max(scale.x(), scale.y());
double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio();
auto [img, mov] = renderer->drawElement(painterPath, *style, pixelRatio);
painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio));
//img = img.scaled(img.width() / pixelRatio, img.height() / pixelRatio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter->drawImage(mov, img); painter->drawImage(mov, img);
} }
painter->restore(); painter->restore();

View File

@ -33,7 +33,7 @@ public:
class SimpleElement : public GraphicElement class SimpleElement : public GraphicElement
{ {
private: public:
QJsonObject jsonSource; QJsonObject jsonSource;
// TODO: 改为ComposedPainterPath // TODO: 改为ComposedPainterPath
QPainterPath painterPath; QPainterPath painterPath;

View File

@ -26,6 +26,7 @@ FolderLayerWrapper*LayerWrapper::getParent() const
PixelPath LayerWrapper::getCache(LayerWrapper* selectedLayer) PixelPath LayerWrapper::getCache(LayerWrapper* selectedLayer)
{ {
this->refresh(selectedLayer); this->refresh(selectedLayer);
qDebug() << cache.painterPath;
if (selectedLayer == this) if (selectedLayer == this)
{ {
this->cache.highLight(); this->cache.highLight();
@ -130,7 +131,9 @@ void LeafLayerWrapper::refresh(LayerWrapper* layer)
cache.clear(); cache.clear();
if (wrappedElement != nullptr) if (wrappedElement != nullptr)
{ {
qDebug() << cache.painterPath;
cache.addPath(wrappedElement->getPaintObject(&(this->styles))); cache.addPath(wrappedElement->getPaintObject(&(this->styles)));
qDebug() << cache.painterPath;
} }
LayerWrapper::refresh(); LayerWrapper::refresh();
} }

View File

@ -66,6 +66,7 @@ void PixelPath::clear()
{ {
pixmap.fill(Qt::transparent); pixmap.fill(Qt::transparent);
boundingRect = QRectF(0, 0, 0, 0); boundingRect = QRectF(0, 0, 0, 0);
painterPath.clear();
} }
PixelPath PixelPath::trans(QTransform& mat)const PixelPath PixelPath::trans(QTransform& mat)const
@ -76,6 +77,7 @@ PixelPath PixelPath::trans(QTransform& mat)const
painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.setTransform(mat); painter.setTransform(mat);
painter.drawPixmap(0, 0, pixmap); painter.drawPixmap(0, 0, pixmap);
result.addPath(this->painterPath);
result.boundingRect = mat.mapRect(boundingRect); result.boundingRect = mat.mapRect(boundingRect);
return result; return result;
} }

View File

@ -7,7 +7,7 @@
class PixelPath class PixelPath
{ {
private: public:
QRectF boundingRect; QRectF boundingRect;
QPixmap pixmap; QPixmap pixmap;
QPainterPath painterPath; QPainterPath painterPath;

View File

@ -27,8 +27,15 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) {
QTransform transform; QTransform transform;
glm::bvec2 flip(0, 0); glm::bvec2 flip(0, 0);
QJsonObject jsonObj = readJsonFile(jsonFilePath); QJsonObject jsonObj = readJsonFile(jsonFilePath);
qDebug() << jsonObj;
ElementManager *elementManager = new ElementManager(jsonObj, Renderer::ElementRenderer::instance()); ElementManager *elementManager = new ElementManager(jsonObj, Renderer::ElementRenderer::instance());
LayerManager* layerManager = new LayerManager(jsonObj, elementManager); LayerManager* layerManager = new LayerManager(jsonObj, elementManager);
//qDebug() << elementManager->toJson();
//qDebug() << layerManager->toJson();
qDebug() << ((SimpleElement*)((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->wrappedElement)->painterPath;
qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath;
traverseLayTree(layerManager->getRoot(), transform, flip, painting); traverseLayTree(layerManager->getRoot(), transform, flip, painting);
return painting; return painting;
} }
@ -43,6 +50,7 @@ void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform,
transform = nowLayer->property.transform * transform; transform = nowLayer->property.transform * transform;
if (leafLayer != nullptr) { if (leafLayer != nullptr) {
qDebug() << leafLayer<<"------" << painterPath;
Element element; Element element;
ElementTransform elementTrans; ElementTransform elementTrans;
element.ratio = bound.width() / bound.height(); element.ratio = bound.width() / bound.height();
@ -52,10 +60,10 @@ void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform,
trans.scale(1 / bound.width(), 1 / bound.height()); trans.scale(1 / bound.width(), 1 / bound.height());
trans.translate(-bound.center().x(), -bound.center().y()); trans.translate(-bound.center().x(), -bound.center().y());
element.contour.reset(new vector<vector<Renderer::Point> >(PainterPathUtil::transformToLines(trans.map(painterPath)))); element.contour = std::make_shared<vector<vector<Renderer::Point> >>(PainterPathUtil::transformToLines(trans.map(painterPath)));
QSize screenSize = pixelPath.getPixmap().size(); QSize screenSize = pixelPath.getPixmap().size();
//element.style.reset(new Renderer::ElementStyleStrokeDemo(0.06)); element.style = std::make_shared<Renderer::ElementStyleStrokeDemo>(0.06);
painterPath = transform.map(painterPath); painterPath = transform.map(painterPath);
bound = painterPath.boundingRect(); bound = painterPath.boundingRect();

View File

@ -229,7 +229,7 @@ GLuint Renderer::Model::loadPainting(std::string path)
if (iter != paintingLoaded.end()) if (iter != paintingLoaded.end())
return iter->second; return iter->second;
Painting painting = PaintingUtil::transfromToPainting("D:\\BigC\\Project\\ArchitectureColoredPainting\\data.json"); Painting painting = PaintingUtil::transfromToPainting("../data.json");
painting.generateBuffers(glFunc); painting.generateBuffers(glFunc);

5
svg/4_L0.svg Normal file
View File

@ -0,0 +1,5 @@
<svg id="万字笔画" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1068 1045">
<title>4_L0</title>
<polyline points="873 0 360 390 427 483 490 439 600 592 690 524 750 608 189 1045" fill="none"/>
<polyline points="1068 830 651 303 566 373 629 455 487 566 538 632 461 696 0 99" fill="none"/>
</svg>

After

Width:  |  Height:  |  Size: 307 B

31
svg/ex.json Normal file
View File

@ -0,0 +1,31 @@
{
"height": 1080,
"width": 1080,
"elements": [
{
"name": "ababa",
"type": "svg-file",
"data": {
"include": "./svg/0.svg"
}
}
],
"root-layer": {
"name": "root",
"transform": {
"offset": {
"x": 0,
"y": 0
},
"scale": {
"x": 1.0,
"y": 1.0
},
"rotation": 0.0
},
"effects": [],
"is-folder": true,
"referenced-by": null,
"children":[]
}
}