sony / flutter-embedded-linux

Embedded Linux embedding for Flutter
BSD 3-Clause "New" or "Revised" License
1.16k stars 122 forks source link

"text_scaling_factor" should default to 1 if unset #392

Closed t123yh closed 9 months ago

t123yh commented 9 months ago

Related commit: https://github.com/sony/flutter-embedded-linux/commit/c5a7852198a9821d4c58a5c33bf0185b57a2c05a

I recently upgraded from 3.10.2 to 3.13.6, and all my text disappeared. I found the reason is that "text_scale_factor" is set to zero after digging hard through Skia font rendering code.

I use a custom main function in my app:

int main(int argc, char** argv) {
  // Creates the Flutter project.
  const auto bundle_path = std::string(".");
  const std::wstring fl_path(bundle_path.begin(), bundle_path.end());
  flutter::DartProject project(fl_path);
  auto command_line_arguments = std::vector<std::string>();
  command_line_arguments.push_back("embedded");
  project.set_dart_entrypoint_arguments(std::move(command_line_arguments));

  flutter::FlutterViewController::ViewProperties view_properties = {};
  view_properties.width = 800;
  view_properties.height = 480;
  view_properties.view_mode = flutter::FlutterViewController::ViewMode::kFullscreen;
  view_properties.view_rotation = flutter::FlutterViewController::ViewRotation::kRotation_0;
  view_properties.use_mouse_cursor = false;
  view_properties.use_onscreen_keyboard = false;
  view_properties.use_window_decoration = false;
  view_properties.force_scale_factor = true;
  view_properties.scale_factor = 1;
  // view_properties.text_scale_factor = 1; <===== This was missing

  // The Flutter instance hosted by this window.
  FlutterWindow window(view_properties, project);
  if (!window.OnCreate()) {
    return 0;
  }
  window.Run();
  window.OnDestroy();

  return 0;
}

Before upgrading to 3.13, there's no text_scale_factor. After upgrading to 3.13, text_scale_factor will default to zero if unspecified, and this will cause all text disappear.

I suggest add some check in the embedder, and if text_scale_factor is zero, then set it to 1 or print a warning, to avoid this kind of mistakes. Also we can set text_scale_factor to 1 in the constructor of flutter::FlutterViewController::ViewProperties.

HidenoriMatsubayashi commented 9 months ago

Agreed. I'll add that check. Thanks.