[web] Fix scaledImageSize handling of a target width with no target height (flutter/engine#54122)

This commit is contained in:
Jason Simmons
2024-07-29 09:27:37 -07:00
committed by GitHub
parent eae06f9678
commit 8165d2a54a
2 changed files with 9 additions and 1 deletions

View File

@@ -274,7 +274,7 @@ BitmapSize? scaledImageSize(
}
targetWidth = (width * targetHeight / height).round();
} else if (targetHeight == null) {
if (targetWidth == targetWidth) {
if (targetWidth == width) {
// Not scaled.
return null;
}

View File

@@ -8,6 +8,8 @@ import 'dart:typed_data';
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine/canvaskit/image.dart';
import 'package:ui/src/engine/image_decoder.dart';
import 'package:ui/src/engine/util.dart';
import 'package:ui/ui.dart' as ui;
import 'common.dart';
@@ -98,6 +100,12 @@ void testMain() {
List<int>.generate(100000, (int i) => i & 0xFF),
);
});
test('scaledImageSize scales to a target width with no target height', () {
final BitmapSize? size = scaledImageSize(200, 100, 600, null);
expect(size?.width, 600);
expect(size?.height, 300);
});
}
Future<ui.Image> _createImage() => _createPicture().toImage(10, 10);