mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 20:14:37 +00:00
loader SvgSceneBuilder: Add root node to clipping viewBox.
If the boundary of scene created through the scenebuilder is larger than the viewbox, scene(SVG's root) should be clipped to the size of the viewbox. So, if scene need a clip, add a parent root and add clippath composition to that root.
This commit is contained in:
parent
8ff1405050
commit
631c1e5651
1 changed files with 27 additions and 1 deletions
|
@ -386,6 +386,32 @@ unique_ptr<Scene> _sceneBuildHelper(const SvgNode* node, float vx, float vy, flo
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unique_ptr<Scene> _buildRoot(const SvgNode* node, float vx, float vy, float vw, float vh)
|
||||||
|
{
|
||||||
|
unique_ptr<Scene> root;
|
||||||
|
auto docNode = move(_sceneBuildHelper(node, vx, vy, vw, vh));
|
||||||
|
float x, y, w, h;
|
||||||
|
|
||||||
|
if (docNode->bounds(&x, &y, &w, &h) != Result::Success) return nullptr;
|
||||||
|
|
||||||
|
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), tvg::CompositeMethod::ClipPath);
|
||||||
|
compositeLayer->push(move(docNode));
|
||||||
|
|
||||||
|
root = Scene::gen();
|
||||||
|
root->push(move(compositeLayer));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
root = move(docNode);
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
SvgSceneBuilder::SvgSceneBuilder()
|
SvgSceneBuilder::SvgSceneBuilder()
|
||||||
{
|
{
|
||||||
|
@ -401,5 +427,5 @@ unique_ptr<Scene> SvgSceneBuilder::build(SvgNode* node)
|
||||||
{
|
{
|
||||||
if (!node || (node->type != SvgNodeType::Doc)) return nullptr;
|
if (!node || (node->type != SvgNodeType::Doc)) return nullptr;
|
||||||
|
|
||||||
return _sceneBuildHelper(node, node->node.doc.vx, node->node.doc.vy, node->node.doc.vw, node->node.doc.vh);
|
return _buildRoot(node, node->node.doc.vx, node->node.doc.vy, node->node.doc.vw, node->node.doc.vh);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue