#include <cstring>
#include <string>
#include "tvgSvgLoaderCommon.h"
+#include "tvgPaint.h"
#include "tvgSvgSceneBuilder.h"
#include "tvgSvgPath.h"
#include "tvgSvgUtil.h"
return valid;
}
+static Matrix _compositionTransform(Paint* paint, const SvgNode* node, const SvgNode* compNode, SvgNodeType type)
+{
+ Matrix m = {1, 0, 0, 0, 1, 0, 0, 0, 1};
+ //The initial mask transformation ignored according to the SVG standard.
+ if (node->transform && type != SvgNodeType::Mask) {
+ m = *node->transform;
+ }
+ if (compNode->transform) {
+ m = mathMultiply(&m, compNode->transform);
+ }
+ if (!compNode->node.clip.userSpace) {
+ float x, y, w, h;
+ paint->bounds(&x, &y, &w, &h, false);
+ Matrix mBBox = {w, 0, x, 0, h, y, 0, 0, 1};
+ m = mathMultiply(&m, &mBBox);
+ }
+ return m;
+}
+
static void _applyComposition(Paint* paint, const SvgNode* node, const Box& vBox, const string& svgPath)
{
if (_appendChildShape(*child, comp.get(), vBox, svgPath)) valid = true;
}
- if (valid) paint->composite(move(comp), CompositeMethod::ClipPath);
+ if (valid) {
+ Matrix finalTransform = _compositionTransform(paint, node, compNode, SvgNodeType::ClipPath);
+ comp->transform(finalTransform);
+ paint->composite(std::move(comp), CompositeMethod::ClipPath);
+ }
node->style->clipPath.applying = false;
}
node->style->mask.applying = true;
bool isMaskWhite = true;
- auto comp = _sceneBuildHelper(compNode, vBox, svgPath, true, 0, &isMaskWhite);
- if (comp) {
- if (node->transform) comp->transform(*node->transform);
+ if (auto comp = _sceneBuildHelper(compNode, vBox, svgPath, true, 0, &isMaskWhite)) {
+ Matrix finalTransform = _compositionTransform(paint, node, compNode, SvgNodeType::Mask);
+ comp->transform(finalTransform);
if (compNode->node.mask.type == SvgMaskType::Luminance && !isMaskWhite) {
paint->composite(move(comp), CompositeMethod::LumaMask);