|
26 | 26 | #include "flutter/shell/common/skia_event_tracer_impl.h"
|
27 | 27 | #include "flutter/shell/common/switches.h"
|
28 | 28 | #include "flutter/shell/common/vsync_waiter.h"
|
| 29 | +#include "rapidjson/stringbuffer.h" |
| 30 | +#include "rapidjson/writer.h" |
29 | 31 | #include "third_party/dart/runtime/include/dart_tools_api.h"
|
30 | 32 | #include "third_party/skia/include/core/SkGraphics.h"
|
31 | 33 | #include "third_party/tonic/common/log.h"
|
32 | 34 |
|
33 | 35 | namespace flutter {
|
34 | 36 |
|
35 | 37 | constexpr char kSkiaChannel[] = "flutter/skia";
|
| 38 | +constexpr char kSystemChannel[] = "flutter/system"; |
| 39 | +constexpr char kTypeKey[] = "type"; |
| 40 | +constexpr char kFontChange[] = "fontsChange"; |
36 | 41 |
|
37 | 42 | std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
|
38 | 43 | DartVMRef vm,
|
@@ -1351,4 +1356,36 @@ fml::Status Shell::WaitForFirstFrame(fml::TimeDelta timeout) {
|
1351 | 1356 | }
|
1352 | 1357 | }
|
1353 | 1358 |
|
| 1359 | +bool Shell::ReloadSystemFonts() { |
| 1360 | + FML_DCHECK(is_setup_); |
| 1361 | + FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread()); |
| 1362 | + |
| 1363 | + if (!engine_) { |
| 1364 | + return false; |
| 1365 | + } |
| 1366 | + engine_->GetFontCollection().GetFontCollection()->SetupDefaultFontManager(); |
| 1367 | + engine_->GetFontCollection().GetFontCollection()->ClearFontFamilyCache(); |
| 1368 | + // After system fonts are reloaded, we send a system channel message |
| 1369 | + // to notify flutter framework. |
| 1370 | + rapidjson::Document document; |
| 1371 | + document.SetObject(); |
| 1372 | + auto& allocator = document.GetAllocator(); |
| 1373 | + rapidjson::Value message_value; |
| 1374 | + message_value.SetString(kFontChange, allocator); |
| 1375 | + document.AddMember(kTypeKey, message_value, allocator); |
| 1376 | + |
| 1377 | + rapidjson::StringBuffer buffer; |
| 1378 | + rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); |
| 1379 | + document.Accept(writer); |
| 1380 | + std::string message = buffer.GetString(); |
| 1381 | + fml::RefPtr<PlatformMessage> fontsChangeMessage = |
| 1382 | + fml::MakeRefCounted<flutter::PlatformMessage>( |
| 1383 | + kSystemChannel, |
| 1384 | + std::vector<uint8_t>(message.begin(), message.end()), |
| 1385 | + nullptr); |
| 1386 | + |
| 1387 | + OnPlatformViewDispatchPlatformMessage(fontsChangeMessage); |
| 1388 | + return true; |
| 1389 | +} |
| 1390 | + |
1354 | 1391 | } // namespace flutter
|
0 commit comments