svg_loader: proper image transformation

One of the image's attributes can be a transformation matrix.
Now it's applied.
This commit is contained in:
Mira Grudzinska 2022-02-07 02:39:48 +01:00 committed by Hermet Park
parent 2fce4d46a0
commit 6a589777b0
2 changed files with 6 additions and 2 deletions

View file

@ -1715,6 +1715,8 @@ static bool _attrParseImageNode(void* data, const char* key, const char* value)
_handleClipPathAttr(loader, node, value);
} else if (!strcmp(key, "mask")) {
_handleMaskAttr(loader, node, value);
} else if (!strcmp(key, "transform")) {
node->transform = _parseTransformationMatrix(value);
} else {
return _parseStyleAttr(loader, key, value);
}

View file

@ -546,12 +546,14 @@ static unique_ptr<Picture> _imageBuildHelper(SvgNode* node, const Box& vBox, con
}
float w, h;
Matrix m = {1, 0, 0, 0, 1, 0, 0, 0, 1};
if (picture->size(&w, &h) == Result::Success && w > 0 && h > 0) {
auto sx = node->node.image.w / w;
auto sy = node->node.image.h / h;
Matrix m = {sx, 0, node->node.image.x, 0, sy, node->node.image.y, 0, 0, 1};
picture->transform(m);
m = {sx, 0, node->node.image.x, 0, sy, node->node.image.y, 0, 0, 1};
}
if (node->transform) m = mathMultiply(node->transform, &m);
picture->transform(m);
_applyComposition(picture.get(), node, vBox, svgPath);
return picture;