engine
engine copied to clipboard
Support user defined font request URL
issue
https://github.com/flutter/flutter/issues/94404
Description
Because of GWF, Chinese users cannot access Google services normally, Flutter needs to provide proxy configuration to access google font.
Use examples
flutter build web --web-renderer=canvaskit --release --dart-define=FONT_API_SERVER="https://fonts.loli.net/" --dart-define=ROBOTO_FONT_URL="https://gstatic.loli.net/s/roboto/v20/KFOmCnqEu92Fr1Me5WZLCzYlKw.ttf"
- environment variable FONT_API_SERVER: Font api server, default value is
https://fonts.googleapis.com/ - environment variable ROBOTO_FONT_URL: Roboto font url, default value is
https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Me5WZLCzYlKw.ttf
Result
- Font api:

- Get roboto font:

Pre-launch Checklist
- [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description above.
- [x] I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with
///). - [x] I signed the [CLA].
- [x] All existing and new tests are passing.
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.
If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?
Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.
This will need testing.
This will need testing.
@Hixie PR depends on environment variables, and I can't find a way to inject environment variables into the test. I found a test example in Flutter Tools, but it doesn't seem to be used in the engine.
Can you provide advice or help? I will be very grateful.
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.
As a drive by comment, this will only work in profile and release mode. in debug mode, the engine is precompiled so this will be left as a default. This may still be worth implementing, though I wonder if @yjbanov had a different idea on the sort of approach.
Technically this could be provided to a test, though I'm not sure if the web engine supports the same testing patterns that the framework does. (Also a Yegor question)
Can you provide advice or help? I will be very grateful.
I am not sure exactly how to help but if you reach out on Discord we may be able to figure something out (see the contributing docs below).
This URL customization looks good as a temporary solution. Long-term we'd like to remove our dependency on fonts.google.com (if you need Google Fonts, there's a package for it already). Our plan is to bundle fallback fonts with the app. So this code will likely be removed in the future. Otherwise, if the change LGT @Hixie it's good to go.
Otherwise, if the change LGT @Hixie it's good to go.
Well it would still need a test. I'm not sure how exactly to test it though since I'm not very familiar with this part of the code. The point Jonah raised about it not working in debug mode is also an issue (and will make testing it even harder).
@chvin Thanks again for your contribution! Are you interested in trying to find a way to test this and address the comments above?
@chvin I'm going to close this one since it still requires work; please don't hesitate to create a new PR if you do have the time to come back to it. Thanks again for your contribution, I'm sorry we couldn't land it!