Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: svg res work error in <img> tag #601

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions webf/lib/src/svg/svg_render_object_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class SVGRenderBoxBuilder {
.toDartString(length: element.original_tag.length)
.toUpperCase();
final renderBox = getSVGRenderBox(tagName);

if (renderBox == null) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it more suitable to return a null value when the renderBox is null, as the expected value of visitSVGTree is RenderBoxModel ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be necessary. You can take a look at this complete code.

}
final attributes = element.attributes;
for (int i = 0; i < attributes.length; i++) {
final attr = attributes.data[i] as Pointer<NativeGumboAttribute>;
Expand All @@ -99,7 +101,7 @@ class SVGRenderBoxBuilder {
return rootRenderObject as RenderBoxModel;
}

RenderBoxModel getSVGRenderBox(String tagName) {
RenderBoxModel? getSVGRenderBox(String tagName) {
final Constructor = svgElementsRegistry[tagName];
if (Constructor != null) {
final element = Constructor(null);
Expand All @@ -110,6 +112,14 @@ class SVGRenderBoxBuilder {
}
element.tagName = tagName;
element.namespaceURI = SVG_ELEMENT_URI;
/// These tags are only for setting properties and do not need to participate in time rendering.
/// Such tags do not require renderBoxModel.
if (tagName == TAG_DEFS ||
tagName == TAG_LINEAR_GRADIENT ||
tagName == TAG_STOP ||
tagName == TAG_CLIP_PATH) {
return null;
}
element.createRenderer();
return element.renderBoxModel!;
}
Expand Down
Loading