Fix: style宽度转换问题

dev-wuyize
wuyize 2023-03-21 13:54:01 +08:00
parent 2581624388
commit d3cf84f479
3 changed files with 130 additions and 100 deletions

View File

@ -91,22 +91,26 @@ FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTr
painterPath = trans.map(painterPath); painterPath = trans.map(painterPath);
shared_ptr<vector<vector<Renderer::Point> >> contour = std::make_shared<vector<vector<Renderer::Point> >>(PainterPathUtil::transformToLines(painterPath)); shared_ptr<vector<vector<Renderer::Point> >> contour = std::make_shared<vector<vector<Renderer::Point> >>(PainterPathUtil::transformToLines(painterPath));
QSize screenSize = QSize(1024, 1024); QSize screenSize = QSize(1080, 1080);
ElementTransform elementTransform; ElementTransform elementTransform;
transform = trans.inverted() * transform * QTransform::fromScale(2. / screenSize.width(), 2. / screenSize.height()) * QTransform::fromTranslate(-1, -1) * QTransform::fromScale(1, -1); transform = trans.inverted() * transform * QTransform::fromScale(2. / screenSize.width(), 2. / screenSize.height()) * QTransform::fromTranslate(-1, -1) * QTransform::fromScale(1, -1);
auto baseStyles = leafLayer->styles.toBaseStyles(); auto baseStyles = leafLayer->styles.toBaseStyles();
Renderer::BaseElement element;
element.contour = contour;
for (auto& baseStyle : baseStyles) { for (auto& baseStyle : baseStyles) {
double lineWidth = 0; double lineWidth = 0;
std::shared_ptr<MaterialStyle> material;
if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) { if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) {
auto material = std::static_pointer_cast<MaterialStyleStroke>(baseStyle.material); std::shared_ptr copy = baseStyle.material->clone();
material->halfWidth /= maxLen; std::static_pointer_cast<MaterialStyleStroke>(copy)->halfWidth /= maxLen;
lineWidth = material->halfWidth; lineWidth = std::static_pointer_cast<MaterialStyleStroke>(copy)->halfWidth;
qDebug() << material->halfWidth; material = copy;
} }
else
material = baseStyle.material;
QPainterPathStroker stroker; QPainterPathStroker stroker;
stroker.setWidth(lineWidth * 2); stroker.setWidth(lineWidth * 2);
stroker.setCapStyle(Qt::RoundCap); stroker.setCapStyle(Qt::RoundCap);
@ -114,17 +118,14 @@ FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTr
QPainterPath strokePath = stroker.createStroke(painterPath); QPainterPath strokePath = stroker.createStroke(painterPath);
auto rect = transform.map(strokePath).boundingRect(); auto rect = transform.map(strokePath).boundingRect();
elementTransform.bound = glm::vec4(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); elementTransform.bound = glm::vec4(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height());
qDebug() << elementTransform.bound.x << elementTransform.bound.y << elementTransform.bound.z << elementTransform.bound.z; //qDebug() << elementTransform.bound.x << elementTransform.bound.y << elementTransform.bound.z << elementTransform.bound.z;
transform = transform.inverted(); transform = transform.inverted();
elementTransform.transform = glm::mat3x2( elementTransform.transform = glm::mat3x2(
transform.m11(), transform.m12(), transform.m21(), transform.m11(), transform.m12(), transform.m21(),
transform.m22(), transform.m31(), transform.m32() transform.m22(), transform.m31(), transform.m32()
); );
//qDebug() << transform;
elementTransform.zIndex = 0; elementTransform.zIndex = 0;
painting.addElement(BaseElement{ contour, material }, elementTransform);
element.style = baseStyle.material;
painting.addElement(element, elementTransform);
} }
return nullptr; return nullptr;

View File

@ -21,6 +21,13 @@
}, },
"name": "ababa2", "name": "ababa2",
"type": "svg-file" "type": "svg-file"
},
{
"data": {
"include": "/svg/4_L0.svg"
},
"name": "4_L0.svg",
"type": "svg-file"
} }
], ],
"height": 1080, "height": 1080,
@ -35,9 +42,9 @@
"name": "Leaf2", "name": "Leaf2",
"styles": [ "styles": [
{ {
"enableEachSideIndependent": false, "enableEachSideIndependent": true,
"left": "AABAQAEAIZwAf///AFqe/w==", "left": "AABAQAEAIZwAf///AFqe/w==",
"right": "AABAQAEACJwAf////1UA/w==", "right": "AABAQAAACJw=",
"type": "stroke" "type": "stroke"
} }
], ],
@ -59,8 +66,8 @@
"referenced-by": 1, "referenced-by": 1,
"transform": { "transform": {
"offset": { "offset": {
"x": 50, "x": 503,
"y": 50 "y": 36
}, },
"rotation": 0, "rotation": 0,
"scale": { "scale": {
@ -77,8 +84,8 @@
], ],
"transform": { "transform": {
"offset": { "offset": {
"x": -2, "x": 1,
"y": 515 "y": 986
}, },
"rotation": 0, "rotation": 0,
"scale": { "scale": {
@ -95,8 +102,8 @@
], ],
"transform": { "transform": {
"offset": { "offset": {
"x": -503, "x": -959,
"y": -1 "y": -5
}, },
"rotation": 0, "rotation": 0,
"scale": { "scale": {
@ -113,8 +120,30 @@
], ],
"transform": { "transform": {
"offset": { "offset": {
"x": -503, "x": -958,
"y": 511 "y": 980
},
"rotation": 0,
"scale": {
"x": 1,
"y": 1
}
}
},
{
"element": 3,
"is-folder": false,
"name": "子图层-5",
"styles": [
{
"material": "AH8A/wBanv8=",
"type": "fill"
}
],
"transform": {
"offset": {
"x": 473,
"y": 419
}, },
"rotation": 0, "rotation": 0,
"scale": { "scale": {