Repository: flutter
Issue: [web] Fractional line width on scaled canvas fails with html renderer
Labels: engine,a: fidelity,platform-web,e: web_html,has reproducible steps,P2,found in release: 2.2,team-web,triaged-web

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Steps to Reproduce

<!-- You must include full steps to reproduce so that we can reproduce the problem. -->

1. Run `flutter create bug`.
2. Update the files as follows: replace main.dart with the following code
```
import 'dart:math';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  int _counter = 0;
  final myPainter = MyCustomPainter();

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Expanded(child: CustomPaint(painter: myPainter, child:Center())),
            Text('You have pushed the button this many times:'),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

class MyCustomPainter extends ChangeNotifier implements CustomPainter {

  final sprites = [
    MySprite(1, Offset(1,2)),
    MySprite(2, Offset(-1,2)),
    MySprite(3, Offset(1,-2)),
    MySprite(4, Offset(-1,-2)),
  ];

  @override
  void paint(Canvas canvas, Size size) {
    canvas.save();
    canvas.drawRect(Rect.fromLTWH(0,0,size.width,size.height),
        Paint()..color = Color(0xfffff0e0));
    final range = min(size.width,size.height);
    canvas.translate(size.width/2, size.height/2);
    var sc = range / 13.0;
    canvas.scale(sc,sc);
    for (final s in sprites) {
      s.draw(canvas);
    }
    canvas.restore();
  }

  @override
  bool? hitTest(Offset position) => null;

  @override
  SemanticsBuilderCallback? get semanticsBuilder => null;

  @override
  bool shouldRebuildSemantics(covariant CustomPainter oldDelegate) => shouldRepaint(oldDelegate);

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;

}

class MySprite {

  Offset position;
  int number;

  MySprite(this.number, this.position);

  void draw(Canvas canvas) {
    canvas.save();
    canvas.translate(position.dx,position.dy);
    var p = Paint()..color = Color(0xffffc0c0);
    var rect = Rect.fromLTWH(-0.5, -0.5, 1.0, 1.0);
    canvas.drawRect(rect, p);
    p.strokeWidth = 0.1;
    p.color = Colors.red;
    p.style = PaintingStyle.stroke;
    canvas.drawRect(rect, p);
    canvas.restore();
  }

}
```


3. Run the program with Chrome using the html renderer
`flutter run -d chrome --web-renderer html`
 <!-- describe how to reproduce the problem -->
**Expected results:** <!-- what did you want to see? -->
With the canvaskit renderer
![image_2021-06-08_132600](https://user-images.githubusercontent.com/1609203/121252607-1123ba80-c85d-11eb-8745-d3b033e89ef1.png)

**Actual results:** <!-- what did you see? -->
With the html renderer
![image_2021-06-08_132623](https://user-images.githubusercontent.com/1609203/121252653-1e40a980-c85d-11eb-871e-8cef7b7169d7.png)

<details>
  <summary>Logs</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue.
-->

```
P:\FlutterProjects\htmlbug>flutter run --verbose -d chrome --web-renderer html
[ +158 ms] executing: [P:\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[ +125 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +1 ms] 02c026b03cd31dd3f867e5faeb7e104cce174c5f
[   +3 ms] executing: [P:\flutter/] git tag --points-at 02c026b03cd31dd3f867e5faeb7e104cce174c5f
[  +97 ms] Exit code 0 from: git tag --points-at 02c026b03cd31dd3f867e5faeb7e104cce174c5f
[   +1 ms] 2.2.1
[   +8 ms] executing: [P:\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +68 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[   +1 ms] origin/stable
[        ] executing: [P:\flutter/] git ls-remote --get-url origin
[  +67 ms] Exit code 0 from: git ls-remote --get-url origin
[   +1 ms] https://github.com/flutter/flutter.git
[ +191 ms] executing: [P:\flutter/] git rev-parse --abbrev-ref HEAD
[  +85 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[   +1 ms] stable
[ +132 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +7 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +3 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +78 ms] executing: p:\programs\AndroidSDK\platform-tools\adb.exe devices -l
[  +72 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +107 ms] executing: p:\programs\AndroidSDK\platform-tools\adb.exe devices -l
[  +17 ms] Skipping pub get: version match.
[ +176 ms] Generating P:\FlutterProjects\htmlbug\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java
[  +91 ms] List of devices attached
           emulator-5554          device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:1
[ +136 ms] Launching lib\main.dart on Chrome in debug mode...
[  +16 ms] List of devices attached
           emulator-5554          device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:1
[ +207 ms] Updating assets
[ +124 ms] Waiting for connection from debug service on Chrome...
[ +132 ms] <- reset
[  +10 ms] P:\flutter\bin\cache\dart-sdk\bin\dart.exe --disable-dart-dev
P:\flutter\bin\cache\artifacts\engine\windows-x64\frontend_server.dart.snapshot --sdk-root P:\flutter\bin\cache\flutter_web_sdk/
--incremental --target=dartdevc --debugger-module-names --experimental-emit-debug-metadata -DFLUTTER_WEB_AUTO_DETECT=false
-DFLUTTER_WEB_USE_SKIA=false --output-dill C:\Users\brad\AppData\Local\Temp\flutter_tools.36ee024e\flutter_tool.55d2efa5\app.dill
--libraries-spec file:///P:/flutter/bin/cache/flutter_web_sdk/libraries.json --packages
P:\FlutterProjects\htmlbug\.dart_tool\package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts
--track-widget-creation --filesystem-root C:\Users\brad\AppData\Local\Temp\flutter_tools.36ee024e\flutter_tools.ef52edf9
--filesystem-scheme org-dartlang-app --initialize-from-dill build\e1ffba66f615b3b54e08e2104bac7ab8.cache.dill.track.dill --platform
file:///P:/flutter/bin/cache/flutter_web_sdk/kernel/flutter_ddc_sdk_sound.dill --sound-null-safety
[  +15 ms] <- compile org-dartlang-app:/web_entrypoint.dart
[+29678 ms] Waiting for connection from debug service on Chrome... (completed in 29.8s)
[   +6 ms] Synced 28.2MB.
[   +2 ms] <- accept
[        ] Caching compiled dill
[+1375 ms] [CHROME]:
[   +1 ms] [CHROME]:DevTools listening on ws://127.0.0.1:55864/devtools/browser/3b2cdb0e-70ce-4fa4-ab79-888e5028a53b
[ +496 ms] DwdsInjector: Received request for entrypoint at http://localhost:55764/main_module.bootstrap.js
[  +30 ms] MetadataProvider: Loading debug metadata...
[  +51 ms] MetadataProvider: Loaded debug metadata (sound null safety)
[  +16 ms] DwdsInjector: Injected debugging metadata for entrypoint at http://localhost:55764/main_module.bootstrap.js
[+2727 ms] ChromeProxyService: Initializing expression compiler for main_module.bootstrap.js with sound null safety: true
[ +100 ms] DevHandler: Debug service listening on ws://127.0.0.1:50874/nWzDLZnsqeM=/ws

[  +40 ms] This app is linked to the debug service: ws://127.0.0.1:50874/nWzDLZnsqeM=/ws
[  +15 ms] Debug service listening on ws://127.0.0.1:50874/nWzDLZnsqeM=/ws
[   +1 ms]  Running with sound null safety
[   +7 ms]   To hot restart changes while running, press "r" or "R".
[   +2 ms] For a more detailed help message, press "h". To quit, press "q".
```

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[√] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19042.985], locale en-US)
    • Flutter version 2.2.1 at P:\flutter
    • Framework revision 02c026b03c (12 days ago), 2021-05-27 12:24:44 -0700
    • Engine revision 0fdb562ac8
    • Dart version 2.13.1

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at p:\programs\AndroidSDK
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = p:\programs\AndroidSDK
    • ANDROID_SDK_ROOT = p:\programs\AndroidSDK
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] IntelliJ IDEA Community Edition (version 2021.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3
    • Flutter plugin version 57.0.5
    • Dart plugin version 211.7233

[√] Connected device (3 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 8.0.0 (API 26) (emulator)
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 91.0.4472.77
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 90.0.818.56

• No issues found!
```

</details>