Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Add system font change listener for windows #12276

Merged
merged 3 commits into from
Sep 23, 2019

Conversation

chunhtai
Copy link
Contributor

@chunhtai chunhtai commented Sep 13, 2019

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

@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@chunhtai
Copy link
Contributor Author

@googlebot I fixed it

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

@chunhtai chunhtai Sep 16, 2019

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

@chunhtai chunhtai requested a review from GaryQian September 16, 2019 19:37
@@ -147,6 +151,22 @@ void Win32FlutterWindow::OnClose() {
messageloop_running_ = false;
}

void Win32FlutterWindow::OnFontChange() {
Copy link
Contributor Author

@chunhtai chunhtai Sep 16, 2019

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:

  1. Use FlutterEngineReloadSystemFonts in embedder.h to reload system font and clear caches
  2. 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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

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

std::vector<std::string> families(1, "Robotofake");
auto font =
fontCollection->GetMinikinFontCollectionForFamilies(families, "en");
ASSERT_EQ(font->getId(), (unsigned int)0);
Copy link
Contributor

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() {
Copy link
Contributor

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();
Copy link
Contributor

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(
Copy link
Contributor

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"
Copy link
Contributor

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";
Copy link
Contributor

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.

Copy link
Contributor

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";
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

// After system fonts are reloaded, we send a system channel message
// to notify flutter framework.
rapidjson::Document document;
document.Parse("{}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document.SetObject();

rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
document.Accept(writer);
std::string message(buffer.GetString(), buffer.GetSize());
Copy link
Contributor

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());
}

Copy link
Contributor

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) {}
Copy link
Contributor

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";
Copy link
Contributor

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.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot removed the cla: no label Sep 19, 2019
@chunhtai chunhtai force-pushed the issues/38556 branch 2 times, most recently from a401745 to d42ec1c Compare September 23, 2019 16:43
@chunhtai
Copy link
Contributor Author

@stuartmorgan this is ready for re-review

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@chunhtai chunhtai merged commit aadd5a3 into flutter:master Sep 23, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 24, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Sep 24, 2019
[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
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
[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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants