From 3911a252e279309c785016dcb78012f5e398be2f Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Thu, 27 May 2021 13:05:42 +0200 Subject: [PATCH] svg_loader: the viewBox clipping composite layer added independently of the shapes bounds For now the bounding box of all the shapes was established and if it was larger than the viewBox of the SVG, the clipping layer was added. The bounds api returns the rectangle that encloses the shapes before any transformations. So comparing it with the viewBox doesn't make sense. The comparison is removed and the clipping layer is always added. --- src/loaders/svg/tvgSvgSceneBuilder.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/loaders/svg/tvgSvgSceneBuilder.cpp b/src/loaders/svg/tvgSvgSceneBuilder.cpp index 464f267d..87b8a22b 100644 --- a/src/loaders/svg/tvgSvgSceneBuilder.cpp +++ b/src/loaders/svg/tvgSvgSceneBuilder.cpp @@ -402,25 +402,18 @@ unique_ptr svgSceneBuild(SvgNode* node, float vx, float vy, float vw, flo { if (!node || (node->type != SvgNodeType::Doc)) return nullptr; - unique_ptr root; auto docNode = _sceneBuildHelper(node, vx, vy, vw, vh); - float x, y, w, h; - if (docNode->bounds(&x, &y, &w, &h) != Result::Success) return nullptr; + auto viewBoxClip = Shape::gen(); + viewBoxClip->appendRect(vx, vy ,vw, vh, 0, 0); + viewBoxClip->fill(0, 0, 0, 255); - if (x < vx || y < vy || w > vh || h > vh) { - auto viewBoxClip = Shape::gen(); - viewBoxClip->appendRect(vx, vy ,vw, vh, 0, 0); - viewBoxClip->fill(0, 0, 0, 255); + auto compositeLayer = Scene::gen(); + compositeLayer->composite(move(viewBoxClip), CompositeMethod::ClipPath); + compositeLayer->push(move(docNode)); - auto compositeLayer = Scene::gen(); - compositeLayer->composite(move(viewBoxClip), CompositeMethod::ClipPath); - compositeLayer->push(move(docNode)); + auto root = Scene::gen(); + root->push(move(compositeLayer)); - root = Scene::gen(); - root->push(move(compositeLayer)); - } else { - root = move(docNode); - } return root; }