Skip to content

Commit

Permalink
updated readme to address font-subset bug and building with --no-tree…
Browse files Browse the repository at this point in the history
…-shake-icons to prevent it
  • Loading branch information
timmaffett committed Apr 28, 2023
1 parent 84d2478 commit 7ebcea6
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@ This can be build for any platform.

```
#build for github>>> flutter build web --release --web-renderer canvaskit --base-href "/material_symbols_icons/"
#build for github>>>
```console
flutter build web --release --web-renderer canvaskit --base-href "/material_symbols_icons/"
# building for web
flutter build web --release --web-renderer canvaskit
# serve http to localhost:8080
dhttpd --path=build\web
```

------

With new tree shaking for web on master channel this still results large savings EVEN WHEN USING EVERY ICON in each of the
Material Symbols Icons fonts. (This is most likely because of letters and numbers/regular symbols present in these fonts being removed):
Building without icon tree shaking - due to a bug in flutter's `font-subset` this is breaking the variable fonts used for Material Symbols Icons.
See https://github.com/flutter/flutter/issues/125704 .
I have submitted a PR fixing this in the flutter engine : https://github.com/flutter/engine/pull/41592 .

In the mean time it is necessary to build the web release with the `--no-tree-shake-icons` in order for all variations to work correctly.

```console
flutter build web --release --web-renderer canvaskit --no-tree-shake-icons --base-href "/material_symbols_icons/"
```
Font asset "CupertinoIcons.ttf" was tree-shaken, reducing it from 283452 to 1236 bytes (99.6% reduction). Tree-shaking
can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 10808 bytes (99.3% reduction).
Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf" was tree-shaken, reducing it from 6944756 to 4781576 bytes
(31.1% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialSymbolsRounded[FILL,GRAD,opsz,wght].ttf" was tree-shaken, reducing it from 9361824 to 6397020 bytes
(31.7% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialSymbolsSharp[FILL,GRAD,opsz,wght].ttf" was tree-shaken, reducing it from 5848492 to 4079548 bytes
(30.2% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Compiling lib\main.dart for the Web... 51.2s
```

It turns out that the icon tree-shaking is breaking the material symbols variable fonts by dropping the GSUB table.
This causes rendering errors for some variations (such as Fill->1 Weight->100) I filed an issue addressing this, https://github.com/flutter/flutter/issues/125704 , as well as a PR fixing font-subset so that it preserves these tables for variable fonts - https://github.com/flutter/engine/pull/41592.

This dropping of the GSUB table was the reason for the 30% saving in font size, even in the case of using every material symbol icon. Unfortunately we cannot keep having this saving AND have the variable fonts work correctly. After the `font-subset ` fix from https://github.com/flutter/engine/pull/41592 the size savings when using every icon in the fonts is ~2% instead of ~30%.

0 comments on commit 7ebcea6

Please sign in to comment.