添加Element渲染缓存

dev-wuyize
karlis 2023-03-21 14:11:47 +08:00
parent 826a8d3e2e
commit 16671ae71f
4 changed files with 248 additions and 326 deletions

535
4_L0.json
View File

@ -1,33 +1,40 @@
{
"background-color": "#b7a386",
"background-color": "#ae9f86",
"elements": [
{
"data": {
"include": "../svg/2.svg"
"include": "/svg/2.svg"
},
"name": "ababa",
"type": "svg-file"
},
{
"data": {
"reference-layer": "0.0"
},
"name": "ababa-group",
"type": "group"
},
{
"data": {
"include": "../svg/0.svg"
"include": "/svg/0.svg"
},
"name": "ababa2",
"type": "svg-file"
},
{
"data": {
"include": "D:/BigC2022/temp/ArchitectureColoredPainting/svg/4_L0-fill.svg"
"include": "/svg/4_L0.svg"
},
"name": "4_L0-fill.svg",
"name": "4_L0.svg",
"type": "svg-file"
},
{
"data": {
"reference-layer": "0.0"
},
"name": "图源工",
"type": "group"
},
{
"data": {
"reference-layer": "0.0"
},
"name": "图源万",
"type": "group"
}
],
"height": 1080,
@ -37,307 +44,109 @@
{
"children": [
{
"element": 3,
"is-folder": false,
"name": "4_L0",
"styles": [
"children": [
{
"material": "AH8A/2pkiv8=",
"type": "fill"
},
{
"enableEachSideIndependent": true,
"left": "AADAQAEAJJwAf///9dKG/w==",
"right": "AADgQAAACpw=",
"type": "stroke"
"element": 2,
"is-folder": false,
"name": "4_L0",
"styles": [
{
"material": "AH8A/1JOff8=",
"type": "fill"
},
{
"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": {
"offset": {
"x": -230,
"y": -533
"x": 0,
"y": 0
},
"rotation": 0,
"scale": {
"x": 0.32341007644113307,
"y": 0.32341007644113307
"x": 1,
"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,
"name": "GroupFolderExample",
"referenced-by": 1,
"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": [
],
"name": "子图层-1",
"referenced-by": 4,
"transform": {
"offset": {
"x": 0,
@ -351,14 +160,14 @@
}
},
{
"element": 1,
"element": 4,
"is-folder": false,
"name": "eeee1",
"name": "子图层-2",
"styles": [
],
"transform": {
"offset": {
"x": 0,
"x": 204,
"y": 0
},
"rotation": 0,
@ -369,17 +178,17 @@
}
},
{
"element": 1,
"element": 4,
"is-folder": false,
"name": "eeee2",
"name": "子图层-3",
"styles": [
],
"transform": {
"offset": {
"x": -149,
"y": 85
"x": 3,
"y": 205
},
"rotation": 90,
"rotation": 0,
"scale": {
"x": 1,
"y": 1
@ -387,17 +196,107 @@
}
},
{
"element": 1,
"element": 4,
"is-folder": false,
"name": "eeee3",
"name": "子图层-4",
"styles": [
],
"transform": {
"offset": {
"x": 166,
"y": 482
"x": 207,
"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": {
"x": 1,
"y": 1
@ -410,13 +309,13 @@
"referenced-by": null,
"transform": {
"offset": {
"x": 8,
"y": 20
"x": -9,
"y": -34
},
"rotation": 0,
"rotation": 60,
"scale": {
"x": 1.7159367435419115,
"y": 1.7159367435419115
"x": 1,
"y": 1
}
}
},

View File

@ -114,10 +114,22 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const LayerSt
else
maxScale = std::max(fabs(transform.m12() / sin(angle)), fabs(transform.m21() / sin(angle)));
double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio();
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);
if (painterPath == painterPathPrev && styles.getHash() == stylesHashValue)
{
transform.translate(movPrev.x(), movPrev.y());
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();
}

View File

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

View File

@ -1,5 +1,11 @@
<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"/>
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 25.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<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>

Before

Width:  |  Height:  |  Size: 307 B

After

Width:  |  Height:  |  Size: 781 B