Skip to content

Commit

Permalink
settings_plugin: add text-scaling-factor commandline option (#367)
Browse files Browse the repository at this point in the history
This change adds text-scaling-factor to command-line option.

Related issue #2

Signed-off-by: Hidenori Matsubayashi <[email protected]>
  • Loading branch information
HidenoriMatsubayashi authored Aug 10, 2023
1 parent fe14f60 commit c5a7852
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class FlutterEmbedderOptions {
options_.AddInt("rotation", "r",
"Window rotation(degree) [0(default)|90|180|270]", 0,
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -83,6 +85,8 @@ class FlutterEmbedderOptions {
}
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
scale_factor_ = options_.GetValue<double>("force-scale-factor");
Expand Down Expand Up @@ -154,6 +158,9 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation WindowRotation() const {
return window_view_rotation_;
}
double TextScaleFactor() const {
return text_scale_factor_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -181,6 +188,7 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation::kRotation_0;
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-drm-eglstream-backend/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int main(int argc, char** argv) {
view_properties.use_mouse_cursor = options.IsUseMouseCursor();
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
8 changes: 8 additions & 0 deletions examples/flutter-drm-gbm-backend/flutter_embedder_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class FlutterEmbedderOptions {
options_.AddInt("rotation", "r",
"Window rotation(degree) [0(default)|90|180|270]", 0,
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -83,6 +85,8 @@ class FlutterEmbedderOptions {
}
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
scale_factor_ = options_.GetValue<double>("force-scale-factor");
Expand Down Expand Up @@ -154,6 +158,9 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation WindowRotation() const {
return window_view_rotation_;
}
double TextScaleFactor() const {
return text_scale_factor_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -181,6 +188,7 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation::kRotation_0;
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-drm-gbm-backend/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int main(int argc, char** argv) {
view_properties.use_mouse_cursor = options.IsUseMouseCursor();
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class FlutterEmbedderOptions {
options_.AddInt("rotation", "r",
"Window rotation(degree) [0(default)|90|180|270]", 0,
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -83,6 +85,8 @@ class FlutterEmbedderOptions {
}
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
scale_factor_ = options_.GetValue<double>("force-scale-factor");
Expand Down Expand Up @@ -154,6 +158,9 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation WindowRotation() const {
return window_view_rotation_;
}
double TextScaleFactor() const {
return text_scale_factor_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -181,6 +188,7 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation::kRotation_0;
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-external-texture-plugin/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int main(int argc, char** argv) {
view_properties.use_mouse_cursor = options.IsUseMouseCursor();
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class FlutterEmbedderOptions {
options_.AddInt("rotation", "r",
"Window rotation(degree) [0(default)|90|180|270]", 0,
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -83,6 +85,8 @@ class FlutterEmbedderOptions {
}
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
scale_factor_ = options_.GetValue<double>("force-scale-factor");
Expand Down Expand Up @@ -154,6 +158,9 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation WindowRotation() const {
return window_view_rotation_;
}
double TextScaleFactor() const {
return text_scale_factor_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -181,6 +188,7 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation::kRotation_0;
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-video-player-plugin/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int main(int argc, char** argv) {
view_properties.use_mouse_cursor = options.IsUseMouseCursor();
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
8 changes: 8 additions & 0 deletions examples/flutter-wayland-client/flutter_embedder_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class FlutterEmbedderOptions {
options_.AddInt("rotation", "r",
"Window rotation(degree) [0(default)|90|180|270]", 0,
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -83,6 +85,8 @@ class FlutterEmbedderOptions {
}
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
scale_factor_ = options_.GetValue<double>("force-scale-factor");
Expand Down Expand Up @@ -154,6 +158,9 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation WindowRotation() const {
return window_view_rotation_;
}
double TextScaleFactor() const {
return text_scale_factor_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -181,6 +188,7 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation::kRotation_0;
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-wayland-client/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int main(int argc, char** argv) {
view_properties.use_mouse_cursor = options.IsUseMouseCursor();
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
8 changes: 8 additions & 0 deletions examples/flutter-x11-client/flutter_embedder_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class FlutterEmbedderOptions {
options_.AddInt("rotation", "r",
"Window rotation(degree) [0(default)|90|180|270]", 0,
false);
options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0,
false);
options_.AddDouble("force-scale-factor", "s",
"Force a scale factor instead using default value", 1.0,
false);
Expand Down Expand Up @@ -83,6 +85,8 @@ class FlutterEmbedderOptions {
}
}

text_scale_factor_ = options_.GetValue<double>("text-scaling-factor");

if (options_.Exist("force-scale-factor")) {
is_force_scale_factor_ = true;
scale_factor_ = options_.GetValue<double>("force-scale-factor");
Expand Down Expand Up @@ -154,6 +158,9 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation WindowRotation() const {
return window_view_rotation_;
}
double TextScaleFactor() const {
return text_scale_factor_;
}
bool IsForceScaleFactor() const {
return is_force_scale_factor_;
}
Expand Down Expand Up @@ -181,6 +188,7 @@ class FlutterEmbedderOptions {
flutter::FlutterViewController::ViewRotation::kRotation_0;
bool is_force_scale_factor_;
double scale_factor_;
double text_scale_factor_;
bool enable_vsync_;
};

Expand Down
1 change: 1 addition & 0 deletions examples/flutter-x11-client/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int main(int argc, char** argv) {
view_properties.use_mouse_cursor = options.IsUseMouseCursor();
view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard();
view_properties.use_window_decoration = options.IsUseWindowDecoraation();
view_properties.text_scale_factor = options.TextScaleFactor();
view_properties.force_scale_factor = options.IsForceScaleFactor();
view_properties.scale_factor = options.ScaleFactor();
view_properties.enable_vsync = options.EnableVsync();
Expand Down
1 change: 1 addition & 0 deletions src/client_wrapper/flutter_view_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ FlutterViewController::FlutterViewController(
view_properties.use_onscreen_keyboard;
c_view_properties.use_window_decoration =
view_properties.use_window_decoration;
c_view_properties.text_scale_factor = view_properties.text_scale_factor;
c_view_properties.force_scale_factor = view_properties.force_scale_factor;
c_view_properties.scale_factor = view_properties.scale_factor;
c_view_properties.enable_vsync = view_properties.enable_vsync;
Expand Down
3 changes: 3 additions & 0 deletions src/client_wrapper/include/flutter/flutter_view_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class FlutterViewController {
// This option is only active for Wayland backend.
bool use_window_decoration;

// Text scaling factor.
double text_scale_factor;

// Force scale factor specified by command line argument
bool force_scale_factor;
double scale_factor;
Expand Down
3 changes: 3 additions & 0 deletions src/flutter/shell/platform/linux_embedded/flutter_elinux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(
if (!state->view->GetEngine()->RunWithEntrypoint(nullptr)) {
return nullptr;
}

const float text_scaling_factor = view_properties->text_scale_factor;
state->view->GetEngine()->SetSystemSettings(text_scaling_factor);
}

// Must happen after engine is running.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,6 @@ bool FlutterELinuxEngine::RunWithEntrypoint(const char* entrypoint) {
return false;
}

// TODO: add theme initial value support.
view_->UpdateHighContrastEnabled(false);

SendSystemLocales();

return true;
}

Expand Down Expand Up @@ -384,6 +379,15 @@ void FlutterELinuxEngine::ReloadSystemFonts() {
embedder_api_.ReloadSystemFonts(engine_);
}

void FlutterELinuxEngine::SetSystemSettings(float text_scaling_factor) {
view_->UpdateTextScaleFactor(text_scaling_factor);

// TODO: add theme initial value support.
view_->UpdateHighContrastEnabled(false);

SendSystemLocales();
}

void FlutterELinuxEngine::SendSystemLocales() {
auto languages = flutter::GetPreferredLanguageInfo();
auto flutter_locales = flutter::ConvertToFlutterLocale(languages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class FlutterELinuxEngine {
// Gets the status whether Impeller is enabled.
bool IsImpellerEnabled() const { return enable_impeller_; }

// Sets system settings.
void SetSystemSettings(float text_scaling_factor);

private:
// Allows swapping out embedder_api_ calls in tests.
friend class EngineEmbedderApiModifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,8 @@ void FlutterELinuxView::UpdateHighContrastEnabled(bool enabled) {
settings_handler_->UpdateHighContrastMode(enabled);
}

void FlutterELinuxView::UpdateTextScaleFactor(float factor) {
settings_handler_->UpdateTextScaleFactor(factor);
}

} // namespace flutter
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate {
// |WindowBindingHandlerDelegate|
void UpdateHighContrastEnabled(bool enabled) override;

// |WindowBindingHandlerDelegate|
void UpdateTextScaleFactor(float factor) override;

private:
// Struct holding the mouse state. The engine doesn't keep track of which
// mouse buttons have been pressed, so it's the embedding's responsibility.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ bool SettingsPlugin::GetAlwaysUse24HourFormat() {
}

float SettingsPlugin::GetTextScaleFactor() {
// The current OS does not have text scale factor.
return 1.0;
return text_scaling_factor_;
}

void SettingsPlugin::UpdateTextScaleFactor(float factor) {
text_scaling_factor_ = factor;
SendSettings();
}

SettingsPlugin::PlatformBrightness SettingsPlugin::GetPreferredBrightness() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class SettingsPlugin {
// Update the high contrast status of the system.
void UpdateHighContrastMode(bool is_high_contrast);

// Update the text scale factor of the system.
void UpdateTextScaleFactor(float factor);

private:
// Returns `true` if the user uses 24 hour time.
bool GetAlwaysUse24HourFormat();
Expand All @@ -44,11 +47,10 @@ class SettingsPlugin {
// Returns the user-preferred brightness.
PlatformBrightness GetPreferredBrightness();

bool is_high_contrast_ = false;

private:
std::unique_ptr<BasicMessageChannel<rapidjson::Document>> channel_;
WindowBindingHandler* delegate_;
bool is_high_contrast_ = false;
float text_scaling_factor_ = 1.0;
};

} // namespace flutter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ typedef struct {
// This option is only active for Wayland backend.
bool use_window_decoration;

// Text scaling factor.
double text_scale_factor;

// Force scale factor specified by command line argument
bool force_scale_factor;
double scale_factor;
Expand Down
Loading

0 comments on commit c5a7852

Please sign in to comment.