-
Notifications
You must be signed in to change notification settings - Fork 6k
Add system font change listener for windows #12276
Conversation
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
1 similar comment
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
19ca3e6
to
65f9874
Compare
@googlebot I fixed it |
65f9874
to
a347504
Compare
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
1 similar comment
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
@@ -228,6 +228,16 @@ TEST(EmbedderTestNoFixture, CanGetCurrentTimeInNanoseconds) { | |||
ASSERT_LT((point2 - point1), fml::TimeDelta::FromMilliseconds(1)); | |||
} | |||
|
|||
TEST_F(EmbedderTest, CanReloadSystemFonts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test make sure the hook from embedding -> embedding_engine -> shell works. It does not test for functionality.
@@ -519,6 +519,30 @@ TEST_F(ShellTest, ReportTimingsIsCalledImmediatelyAfterTheFirstFrame) { | |||
ASSERT_EQ(timestamps.size(), FrameTiming::kCount); | |||
} | |||
|
|||
TEST_F(ShellTest, ReloadSystemFonts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests the actual functionality
@@ -147,6 +151,22 @@ void Win32FlutterWindow::OnClose() { | |||
messageloop_running_ = false; | |||
} | |||
|
|||
void Win32FlutterWindow::OnFontChange() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kpozin Here is the current design for system font api.
When system font changes:
- Use FlutterEngineReloadSystemFonts in embedder.h to reload system font and clear caches
- send system channel message {"type": "fontsChange"} to "flutter/system" flutter framework to rebuild the widget.
Noted that you will probably need to implement fuchsia version of loading default fonts.
see: third_party/txt/src/txt/platform_windows.cc
FlutterEngineReloadSystemFonts relys on this function to retrieve the latest system fonts. If there is any caching happen under this layer, the FlutterEngineReloadSystemFonts will still load the old value.
Let me know if this looks ok to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this seems fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming, I will let you know if anything change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kpozin a little update
you will only need to call this embedder api
engine/shell/platform/embedder/embedder.h
Line 1211 in aadd5a3
FlutterEngineResult FlutterEngineReloadSystemFonts( |
I make it so it will send the system message as part of the api.
However, you will still need to implement fuchsia version of loading default fonts.
https://github.com/flutter/engine/blob/master/third_party/txt/src/txt/platform_fuchsia.cc
shell/common/shell_unittests.cc
Outdated
std::vector<std::string> families(1, "Robotofake"); | ||
auto font = | ||
fontCollection->GetMinikinFontCollectionForFamilies(families, "en"); | ||
ASSERT_EQ(font->getId(), (unsigned int)0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C-style casts are forbidden; use C++ casts (static_cast here)
@@ -58,5 +58,8 @@ FlutterDesktopPluginRegistrarRef FlutterViewController::GetRegistrarForPlugin( | |||
} | |||
return FlutterDesktopGetPluginRegistrar(controller_, plugin_name.c_str()); | |||
} | |||
void FlutterViewController::OnFontChange() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line above this.
@@ -61,6 +61,8 @@ class FlutterViewController { | |||
// loop. | |||
void ProcessMessages(); | |||
|
|||
void OnFontChange(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a declaration comment.
It should also get a TODO to move out of the view controller class once there is an engine class. You can reference #38600
@@ -69,6 +69,10 @@ FlutterDesktopGetHWND(FlutterDesktopViewControllerRef controller); | |||
// loop. | |||
FLUTTER_EXPORT void FlutterDesktopProcessMessages(); | |||
|
|||
// Invokes OnFontChange callback in flutter windows view. | |||
FLUTTER_EXPORT void FlutterOnFontChange( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything in this API surface should use FlutterDesktop
as a prefix.
#include <chrono> | ||
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/json_message_codec.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line above this.
#include <chrono> | ||
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/json_message_codec.h" | ||
|
||
static constexpr char kSystemChannelName[] = "flutter/system"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
win32_flutter_window doesn't seem like the right place for the flutter/system channel to live. Please set up a new handler for now, following the model of platform_handler.{h,cc}. Later we may decide to fold it into another class, but that will be easier if it's not embedded into this one to start with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all cruft now.
namespace txt { | ||
|
||
std::string GetDefaultFontFamily() { | ||
return "Arial"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems unrelated. Is this improving font fallback handling? If so, it would be great to split this out into its own change as part of #39915
Also, I'm surprised to see a file being added to third_party. What is the source for txt
, and why isn't this an upstream change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is essential for reloading system fonts. The original GetDefaultFontFamily in third_party/txt/src/txt/platform.cc uses SkFontMgr::RefDefault() which will cache the result and there is no way to clear it. When a new system font is installed, it will not load the latest system fonts but return previous cached. We have to implement the windows version of it.
There is no upstream for txt. The txt's source lives in here. One thing that worries me is that this might be migrated to skia library at some point @jason-simmons Do you think it is ok to change it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - go ahead and modify this in libtxt. if we later migrate to Skia's text shaper then we will need to port this feature over to the integration with Skia.
615844a
to
55b7fb5
Compare
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
1 similar comment
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
shell/common/shell.cc
Outdated
// After system fonts are reloaded, we send a system channel message | ||
// to notify flutter framework. | ||
rapidjson::Document document; | ||
document.Parse("{}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document.SetObject();
shell/common/shell.cc
Outdated
rapidjson::StringBuffer buffer; | ||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); | ||
document.Accept(writer); | ||
std::string message(buffer.GetString(), buffer.GetSize()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC you only need GetString()
, since we should be building rapidjson with std::string support. Am I misremembering?
@@ -58,5 +58,4 @@ FlutterDesktopPluginRegistrarRef FlutterViewController::GetRegistrarForPlugin( | |||
} | |||
return FlutterDesktopGetPluginRegistrar(controller_, plugin_name.c_str()); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert please, since you're no longer touching this file otherwise.
@@ -70,6 +70,8 @@ void FlutterDesktopProcessMessages() { | |||
} | |||
} | |||
|
|||
void FlutterOnFontChange(FlutterDesktopViewControllerRef controller) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these changes.
#include <chrono> | ||
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/json_message_codec.h" | ||
|
||
static constexpr char kSystemChannelName[] = "flutter/system"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all cruft now.
55b7fb5
to
7c47a64
Compare
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
1 similar comment
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
a401745
to
d42ec1c
Compare
@stuartmorgan this is ready for re-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
cd579e2
to
514ed64
Compare
[email protected]:flutter/engine.git/compare/e7fd442410f4...953ac71 git log e7fd442..953ac71 --no-merges --oneline 2019-09-24 [email protected] Roll src/third_party/dart acac9ab11b..d53d355c6c (12 commits) 2019-09-24 [email protected] Roll src/third_party/skia b4b1005d485f..c096654fa7c6 (1 commits) (flutter/engine#12415) 2019-09-24 [email protected] Roll src/third_party/skia b3542d95da65..b4b1005d485f (6 commits) (flutter/engine#12414) 2019-09-24 [email protected] Write MINIMAL_SDK to exception message (flutter/engine#11345) 2019-09-23 [email protected] Track "mouse leave" event (flutter/engine#12363) 2019-09-23 [email protected] Roll src/third_party/dart 77ff89b223..acac9ab11b (6 commits) 2019-09-23 [email protected] Don't send pointer events when the framework isn't ready yet (flutter/engine#12403) 2019-09-23 [email protected] Update test to verify that secondary isolate gets shutdown before root isolate exits. (flutter/engine#12342) 2019-09-23 [email protected] Roll src/third_party/skia 57ef68077574..b3542d95da65 (12 commits) (flutter/engine#12409) 2019-09-23 [email protected] Update --dart-vm-flags whitelist to include --write-service-info and --sample-buffer-duration (flutter/engine#12395) 2019-09-23 [email protected] Add system font change listener for windows (flutter/engine#12276) 2019-09-23 [email protected] Roll fuchsia/sdk/core/mac-amd64 from xPX7p... to kgFwg... (flutter/engine#12405) 2019-09-23 [email protected] Check for index bounds in RTL handling for trailing whitespace runs. (flutter/engine#12336) 2019-09-23 [email protected] Roll fuchsia/sdk/core/linux-amd64 from F-g18... to NY2A5... (flutter/engine#12407) 2019-09-23 [email protected] Roll src/third_party/dart f546362691..77ff89b223 (6 commits) 2019-09-23 [email protected] Updating text field location in IOS as a pre-work for spellcheck (flutter/engine#12192) 2019-09-23 [email protected] Roll buildroot and remove toolchain prefix. (flutter/engine#12324) 2019-09-23 [email protected] Roll src/third_party/dart 94dd49cdb6..f546362691 (1 commits) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
[email protected]:flutter/engine.git/compare/e7fd442410f4...953ac71 git log e7fd442..953ac71 --no-merges --oneline 2019-09-24 [email protected] Roll src/third_party/dart acac9ab11b..d53d355c6c (12 commits) 2019-09-24 [email protected] Roll src/third_party/skia b4b1005d485f..c096654fa7c6 (1 commits) (flutter/engine#12415) 2019-09-24 [email protected] Roll src/third_party/skia b3542d95da65..b4b1005d485f (6 commits) (flutter/engine#12414) 2019-09-24 [email protected] Write MINIMAL_SDK to exception message (flutter/engine#11345) 2019-09-23 [email protected] Track "mouse leave" event (flutter/engine#12363) 2019-09-23 [email protected] Roll src/third_party/dart 77ff89b223..acac9ab11b (6 commits) 2019-09-23 [email protected] Don't send pointer events when the framework isn't ready yet (flutter/engine#12403) 2019-09-23 [email protected] Update test to verify that secondary isolate gets shutdown before root isolate exits. (flutter/engine#12342) 2019-09-23 [email protected] Roll src/third_party/skia 57ef68077574..b3542d95da65 (12 commits) (flutter/engine#12409) 2019-09-23 [email protected] Update --dart-vm-flags whitelist to include --write-service-info and --sample-buffer-duration (flutter/engine#12395) 2019-09-23 [email protected] Add system font change listener for windows (flutter/engine#12276) 2019-09-23 [email protected] Roll fuchsia/sdk/core/mac-amd64 from xPX7p... to kgFwg... (flutter/engine#12405) 2019-09-23 [email protected] Check for index bounds in RTL handling for trailing whitespace runs. (flutter/engine#12336) 2019-09-23 [email protected] Roll fuchsia/sdk/core/linux-amd64 from F-g18... to NY2A5... (flutter/engine#12407) 2019-09-23 [email protected] Roll src/third_party/dart f546362691..77ff89b223 (6 commits) 2019-09-23 [email protected] Updating text field location in IOS as a pre-work for spellcheck (flutter/engine#12192) 2019-09-23 [email protected] Roll buildroot and remove toolchain prefix. (flutter/engine#12324) 2019-09-23 [email protected] Roll src/third_party/dart 94dd49cdb6..f546362691 (1 commits) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
This pr add listener in windows embedding and use the new embedding api to notify system font changes
This requires framework flutter/flutter#38930
This also requires example app change google/flutter-desktop-embedding#563
flutter/flutter#38556