Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 07c780b

Browse files
authored
[web] Assign default natural width/height for svgs that report 0,0 on firefox and ie11 (#22184)
1 parent 11ed711 commit 07c780b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/web_ui/lib/src/engine/html_image_codec.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ class HtmlCodec implements ui.Codec {
3939
js_util.setProperty(imgElement, 'decoding', 'async');
4040
imgElement.decode().then((dynamic _) {
4141
chunkCallback?.call(100, 100);
42+
int naturalWidth = imgElement.naturalWidth;
43+
int naturalHeight = imgElement.naturalHeight;
44+
// Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=700533.
45+
if (naturalWidth == 0 && naturalHeight == 0 && (
46+
browserEngine == BrowserEngine.firefox ||
47+
browserEngine == BrowserEngine.ie11)) {
48+
const int kDefaultImageSizeFallback = 300;
49+
naturalWidth = kDefaultImageSizeFallback;
50+
naturalHeight = kDefaultImageSizeFallback;
51+
}
4252
final HtmlImage image = HtmlImage(
4353
imgElement,
44-
imgElement.naturalWidth,
45-
imgElement.naturalHeight,
54+
naturalWidth,
55+
naturalHeight,
4656
);
4757
completer.complete(SingleFrameInfo(image));
4858
}).catchError((dynamic e) {

lib/web_ui/test/engine/image/html_image_codec_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ void testMain() async {
8080
await codec.getNextFrame();
8181
expect(buffer.toString(), '0/100,100/100,');
8282
});
83+
84+
/// Regression test for Firefox/ie11
85+
/// https://github.com/flutter/flutter/issues/66412
86+
test('Returns nonzero natural width/height', () async {
87+
final HtmlCodec codec = HtmlCodec(
88+
'data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9I'
89+
'jAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48dG'
90+
'l0bGU+QWJzdHJhY3QgaWNvbjwvdGl0bGU+PHBhdGggZD0iTTEyIDBjOS42MDEgMCAx'
91+
'MiAyLjM5OSAxMiAxMiAwIDkuNjAxLTIuMzk5IDEyLTEyIDEyLTkuNjAxIDAtMTItMi'
92+
'4zOTktMTItMTJDMCAyLjM5OSAyLjM5OSAwIDEyIDB6bS0xLjk2OSAxOC41NjRjMi41'
93+
'MjQuMDAzIDQuNjA0LTIuMDcgNC42MDktNC41OTUgMC0yLjUyMS0yLjA3NC00LjU5NS'
94+
'00LjU5NS00LjU5NVM1LjQ1IDExLjQ0OSA1LjQ1IDEzLjk2OWMwIDIuNTE2IDIuMDY1'
95+
'IDQuNTg4IDQuNTgxIDQuNTk1em04LjM0NC0uMTg5VjUuNjI1SDUuNjI1djIuMjQ3aD'
96+
'EwLjQ5OHYxMC41MDNoMi4yNTJ6bS04LjM0NC02Ljc0OGEyLjM0MyAyLjM0MyAwIDEx'
97+
'LS4wMDIgNC42ODYgMi4zNDMgMi4zNDMgMCAwMS4wMDItNC42ODZ6Ii8+PC9zdmc+');
98+
final ui.FrameInfo frameInfo = await codec.getNextFrame();
99+
expect(frameInfo.image.width, isNot(0));
100+
});
83101
});
84102

85103
group('ImageCodecUrl', () {

0 commit comments

Comments
 (0)