Compare commits

...

2 Commits

Author SHA1 Message Date
karlis 5fbf46faf2 merge 2023-03-21 14:13:41 +08:00
karlis 16671ae71f 添加Element渲染缓存 2023-03-21 14:11:47 +08:00
4 changed files with 248 additions and 325 deletions

535
4_L0.json
View File

@ -1,33 +1,40 @@
{ {
"background-color": "#b7a386", "background-color": "#ae9f86",
"elements": [ "elements": [
{ {
"data": { "data": {
"include": "../svg/2.svg" "include": "/svg/2.svg"
}, },
"name": "ababa", "name": "ababa",
"type": "svg-file" "type": "svg-file"
}, },
{ {
"data": { "data": {
"reference-layer": "0.0" "include": "/svg/0.svg"
},
"name": "ababa-group",
"type": "group"
},
{
"data": {
"include": "../svg/0.svg"
}, },
"name": "ababa2", "name": "ababa2",
"type": "svg-file" "type": "svg-file"
}, },
{ {
"data": { "data": {
"include": "D:/BigC2022/temp/ArchitectureColoredPainting/svg/4_L0.svg" "include": "/svg/4_L0.svg"
}, },
"name": "4_L0-fill.svg", "name": "4_L0.svg",
"type": "svg-file" "type": "svg-file"
},
{
"data": {
"reference-layer": "0.0"
},
"name": "图源工",
"type": "group"
},
{
"data": {
"reference-layer": "0.0"
},
"name": "图源万",
"type": "group"
} }
], ],
"height": 1080, "height": 1080,
@ -37,307 +44,109 @@
{ {
"children": [ "children": [
{ {
"element": 3, "children": [
"is-folder": false,
"name": "4_L0",
"styles": [
{ {
"material": "AH8A/2pkiv8=", "element": 2,
"type": "fill" "is-folder": false,
}, "name": "4_L0",
{ "styles": [
"enableEachSideIndependent": true, {
"left": "AADAQAEAJJwAf///9dKG/w==", "material": "AH8A/1JOff8=",
"right": "AADgQAAACpw=", "type": "fill"
"type": "stroke" },
{
"enableEachSideIndependent": true,
"left": "AAAAQAEAJJwAf///9c19/w==",
"right": "AADgQAAACpw=",
"type": "stroke"
}
],
"transform": {
"offset": {
"x": 0,
"y": 0
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
} }
], ],
"is-folder": true,
"name": "工",
"referenced-by": 3,
"transform": { "transform": {
"offset": { "offset": {
"x": -230, "x": 0,
"y": -533 "y": 0
}, },
"rotation": 0, "rotation": 0,
"scale": { "scale": {
"x": 0.32341007644113307, "x": 1,
"y": 0.32341007644113307 "y": 1
}
}
},
{
"element": 3,
"is-folder": false,
"name": "1",
"styles": [
],
"transform": {
"offset": {
"x": 103,
"y": -1
},
"rotation": 90,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 3,
"is-folder": false,
"name": "2",
"styles": [
],
"transform": {
"offset": {
"x": 104,
"y": 100
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 3,
"is-folder": false,
"name": "3",
"styles": [
],
"transform": {
"offset": {
"x": 3,
"y": 102
},
"rotation": 90,
"scale": {
"x": 1,
"y": 1
} }
} }
} }
], ],
"is-folder": true, "is-folder": true,
"name": "GroupFolderExample", "name": "子图层-1",
"referenced-by": 1, "referenced-by": 4,
"transform": {
"offset": {
"x": 50,
"y": 50
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "aaaa2",
"styles": [
],
"transform": {
"offset": {
"x": 127,
"y": -109
},
"rotation": 90,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "aaaa3",
"styles": [
],
"transform": {
"offset": {
"x": 232,
"y": 17
},
"rotation": 180,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "aaaa4",
"styles": [
],
"transform": {
"offset": {
"x": 103,
"y": 130
},
"rotation": 270,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "bbbb1",
"styles": [
],
"transform": {
"offset": {
"x": 197,
"y": 265
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "bbbb2",
"styles": [
],
"transform": {
"offset": {
"x": 323,
"y": 156
},
"rotation": 90,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "bbbb3",
"styles": [
],
"transform": {
"offset": {
"x": 432,
"y": 285
},
"rotation": 180,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "bbbb4",
"styles": [
],
"transform": {
"offset": {
"x": 302,
"y": 399
},
"rotation": 270,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "cccc1",
"styles": [
],
"transform": {
"offset": {
"x": 467,
"y": 71
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "cccc2",
"styles": [
],
"transform": {
"offset": {
"x": 361,
"y": -70
},
"rotation": 90,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "cccc3",
"styles": [
],
"transform": {
"offset": {
"x": 273,
"y": -211
},
"rotation": 180,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "cccc4",
"styles": [
],
"transform": {
"offset": {
"x": 574,
"y": 198
},
"rotation": 270,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "dddd1",
"styles": [
],
"transform": {
"offset": {
"x": 33,
"y": -231
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "dddd2",
"styles": [
],
"transform": {
"offset": {
"x": 55,
"y": 352
},
"rotation": 90,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "dddd3",
"styles": [
],
"transform": {
"offset": {
"x": -40,
"y": 220
},
"rotation": 180,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 1,
"is-folder": false,
"name": "dddd4",
"styles": [
],
"transform": { "transform": {
"offset": { "offset": {
"x": 0, "x": 0,
@ -351,14 +160,14 @@
} }
}, },
{ {
"element": 1, "element": 4,
"is-folder": false, "is-folder": false,
"name": "eeee1", "name": "子图层-2",
"styles": [ "styles": [
], ],
"transform": { "transform": {
"offset": { "offset": {
"x": 0, "x": 204,
"y": 0 "y": 0
}, },
"rotation": 0, "rotation": 0,
@ -369,17 +178,17 @@
} }
}, },
{ {
"element": 1, "element": 4,
"is-folder": false, "is-folder": false,
"name": "eeee2", "name": "子图层-3",
"styles": [ "styles": [
], ],
"transform": { "transform": {
"offset": { "offset": {
"x": -149, "x": 3,
"y": 85 "y": 205
}, },
"rotation": 90, "rotation": 0,
"scale": { "scale": {
"x": 1, "x": 1,
"y": 1 "y": 1
@ -387,17 +196,107 @@
} }
}, },
{ {
"element": 1, "element": 4,
"is-folder": false, "is-folder": false,
"name": "eeee3", "name": "子图层-4",
"styles": [ "styles": [
], ],
"transform": { "transform": {
"offset": { "offset": {
"x": 166, "x": 207,
"y": 482 "y": 203
}, },
"rotation": 180, "rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 4,
"is-folder": false,
"name": "子图层-5",
"styles": [
],
"transform": {
"offset": {
"x": 407,
"y": -2
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 4,
"is-folder": false,
"name": "子图层-6",
"styles": [
],
"transform": {
"offset": {
"x": 411,
"y": 201
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 4,
"is-folder": false,
"name": "子图层-7",
"styles": [
],
"transform": {
"offset": {
"x": 6,
"y": 408
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 4,
"is-folder": false,
"name": "子图层-8",
"styles": [
],
"transform": {
"offset": {
"x": 210,
"y": 408
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 4,
"is-folder": false,
"name": "子图层-9",
"styles": [
],
"transform": {
"offset": {
"x": 414,
"y": 405
},
"rotation": 0,
"scale": { "scale": {
"x": 1, "x": 1,
"y": 1 "y": 1
@ -410,13 +309,13 @@
"referenced-by": null, "referenced-by": null,
"transform": { "transform": {
"offset": { "offset": {
"x": 8, "x": -9,
"y": 20 "y": -34
}, },
"rotation": 0, "rotation": 60,
"scale": { "scale": {
"x": 1.7159367435419115, "x": 1,
"y": 1.7159367435419115 "y": 1
} }
} }
}, },

View File

@ -114,10 +114,22 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const LayerSt
else else
maxScale = std::max(fabs(transform.m12() / sin(angle)), fabs(transform.m21() / sin(angle))); maxScale = std::max(fabs(transform.m12() / sin(angle)), fabs(transform.m21() / sin(angle)));
double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio(); double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio();
auto [img, mov] = Renderer::ElementRenderer::instance()->drawElement(painterPath, styles, pixelRatio); if (painterPath == painterPathPrev && styles.getHash() == stylesHashValue)
transform.translate(mov.x(), mov.y()); {
painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio)); transform.translate(movPrev.x(), movPrev.y());
painter->drawImage(0, 0, img); painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio));
painter->drawImage(0, 0, imagePrev);
}
else
{
auto [img, mov] = Renderer::ElementRenderer::instance()->drawElement(painterPath, styles, pixelRatio);
transform.translate(mov.x(), mov.y());
painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio));
painter->drawImage(0, 0, img);
stylesHashValue = styles.getHash();
painterPathPrev = painterPath;
}
} }
painter->restore(); painter->restore();
} }

View File

@ -23,6 +23,10 @@ public:
size_t referencedCount = 0; size_t referencedCount = 0;
Renderer::ElementRenderer *renderer; Renderer::ElementRenderer *renderer;
QString name = ""; QString name = "";
size_t stylesHashValue;
QPainterPath painterPathPrev;
QPointF movPrev;
QImage imagePrev;
int index; int index;
// TODO: ¸ÄΪBitmapPath // TODO: ¸ÄΪBitmapPath
virtual QJsonObject toJson() const = 0; virtual QJsonObject toJson() const = 0;
@ -31,6 +35,7 @@ public:
virtual void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) = 0; virtual void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) = 0;
virtual bool isClosed() const = 0; virtual bool isClosed() const = 0;
virtual QPixmap getPreview(QSize size) = 0; virtual QPixmap getPreview(QSize size) = 0;
}; };
class SimpleElement : public GraphicElement class SimpleElement : public GraphicElement

View File

@ -1,4 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 141 171"> <?xml version="1.0" encoding="utf-8"?>
<title>4_L0的副本</title> <!-- Generator: Adobe Illustrator 25.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<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"/> <svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 141 171" style="enable-background:new 0 0 141 171;" xml:space="preserve">
<style type="text/css">
.st0{fill:none;stroke:#000000;stroke-miterlimit:10;}
</style>
<polygon class="st0" points="0.5,0.5 140.5,0.5 140.5,10.5 115.5,10.5 115.5,31.5 105.5,31.5 105.5,10.5 75.5,10.5 75.5,165.8
105.5,165.8 105.5,144.7 115.5,144.7 115.5,165.8 140.5,165.8 140.5,175.8 0.5,175.8 0.5,165.8 25.5,165.8 25.5,144.7 35.5,144.7
35.5,165.8 65.5,165.8 65.5,10.5 35.5,10.5 35.5,31.5 25.5,31.5 25.5,10.5 0.5,10.5 "/>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 480 B

After

Width:  |  Height:  |  Size: 781 B