mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
svg_loader: Support id attribute for tvg::Accessor
Supports access with tvg::Accessor using the value set in the id attribute of SVG Please refer to examples/Accessor.cpp
This commit is contained in:
parent
a481f621fe
commit
6cfc22d123
3 changed files with 16 additions and 3 deletions
|
@ -60,6 +60,13 @@ struct UserExample : tvgexam::Example
|
|||
|
||||
if (!tvgexam::verify(accessor->set(picture.get(), f, nullptr))) return false;
|
||||
|
||||
// Try to retrieve the shape that corresponds to the SVG node with the unique ID "star".
|
||||
if (auto paint = picture->paint(tvg::Accessor::id("star"))) {
|
||||
auto shape = static_cast<tvg::Shape*>(const_cast<tvg::Paint*>(paint));
|
||||
shape->strokeFill(255, 255, 0);
|
||||
shape->strokeWidth(5);
|
||||
}
|
||||
|
||||
canvas->push(std::move(picture));
|
||||
|
||||
return true;
|
||||
|
@ -74,4 +81,4 @@ struct UserExample : tvgexam::Example
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
return tvgexam::main(new UserExample, argc, argv);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
width="80px" height="80px" viewBox="-14 -14 80 80" enable-background="new -14 -14 80 80" xml:space="preserve">
|
||||
<path fill="#FFB400" d="M39.633,49c-0.492,0-0.987-0.145-1.417-0.432l-12.212-8.141l-12.215,8.141
|
||||
<path id="star" fill="#FFB400" d="M39.633,49c-0.492,0-0.987-0.145-1.417-0.432l-12.212-8.141l-12.215,8.141
|
||||
c-0.892,0.598-2.059,0.57-2.926-0.061c-0.866-0.629-1.245-1.734-0.949-2.766l4.104-14.365L3.846,22.429
|
||||
c-0.788-0.71-1.055-1.828-0.676-2.814c0.378-0.987,1.326-1.641,2.385-1.641h13.007l5.036-13.331c0.377-0.989,1.326-1.64,2.384-1.643
|
||||
h0.003c1.056,0,2.003,0.651,2.384,1.637l5.063,13.337h13.011c1.061,0,2.007,0.652,2.387,1.641c0.38,0.988,0.109,2.104-0.677,2.814
|
||||
|
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
|
@ -847,15 +847,20 @@ static unique_ptr<Scene> _sceneBuildHelper(SvgLoaderData& loaderData, const SvgN
|
|||
scene->push(_useBuildHelper(loaderData, *child, vBox, svgPath, depth + 1, isMaskWhite));
|
||||
else if (!((*child)->type == SvgNodeType::Symbol && node->type != SvgNodeType::Use))
|
||||
scene->push(_sceneBuildHelper(loaderData, *child, vBox, svgPath, false, depth + 1, isMaskWhite));
|
||||
if ((*child)->id) scene->id = djb2Encode((*child)->id);
|
||||
} else if ((*child)->type == SvgNodeType::Image) {
|
||||
auto image = _imageBuildHelper(loaderData, *child, vBox, svgPath);
|
||||
if (image) {
|
||||
if ((*child)->id) image->id = djb2Encode((*child)->id);
|
||||
scene->push(std::move(image));
|
||||
if (isMaskWhite) *isMaskWhite = false;
|
||||
}
|
||||
} else if ((*child)->type == SvgNodeType::Text) {
|
||||
auto text = _textBuildHelper(loaderData, *child, vBox, svgPath);
|
||||
if (text) scene->push(std::move(text));
|
||||
if (text) {
|
||||
if ((*child)->id) text->id = djb2Encode((*child)->id);
|
||||
scene->push(std::move(text));
|
||||
}
|
||||
} else if ((*child)->type != SvgNodeType::Mask) {
|
||||
auto shape = _shapeBuildHelper(loaderData, *child, vBox, svgPath);
|
||||
if (shape) {
|
||||
|
@ -867,6 +872,7 @@ static unique_ptr<Scene> _sceneBuildHelper(SvgLoaderData& loaderData, const SvgN
|
|||
*isMaskWhite = false;
|
||||
}
|
||||
}
|
||||
if ((*child)->id) shape->id = djb2Encode((*child)->id);
|
||||
scene->push(std::move(shape));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue