From 40f176d1b11a7bada810bc39419011d826ba0b33 Mon Sep 17 00:00:00 2001 From: guanzengkun Date: Fri, 19 Jul 2024 13:46:38 +0800 Subject: [PATCH] =?UTF-8?q?https://gitee.com/openharmony/arkui=5Face=5Feng?= =?UTF-8?q?ine/issues/IAE550=20Description:=E5=AD=97=E4=BD=93=E4=B8=8D?= =?UTF-8?q?=E8=B7=9F=E9=9A=8F=E9=9C=80=E6=B1=82=20Sig:=20SIG=5FApplication?= =?UTF-8?q?Framework=20Feature=20or=20Bugfix:Bugfix=20Binary=20Source:No?= =?UTF-8?q?=20TDD:(=E8=AF=84=E4=BC=B0=E4=B8=8D=E6=B6=89=E5=8F=8A)=20XTS:Pa?= =?UTF-8?q?ss=20=E9=A2=84=E6=B5=8B=E8=AF=95:=E8=AF=84=E4=BC=B0=E4=B8=8D?= =?UTF-8?q?=E6=B6=89=E5=8F=8A=20Signed-off-by:guanzengkun=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapter/ohos/entrance/ui_content_impl.cpp | 18 ++++++++++++++- adapter/ohos/entrance/ui_content_impl.h | 1 + frameworks/base/geometry/dimension.cpp | 9 +++++--- .../declarative_frontend/jsview/js_text.cpp | 8 ++++--- frameworks/core/pipeline/pipeline_base.h | 23 +++++++++++++++++++ 5 files changed, 52 insertions(+), 7 deletions(-) diff --git a/adapter/ohos/entrance/ui_content_impl.cpp b/adapter/ohos/entrance/ui_content_impl.cpp index 54d0ef2b28f..6a74555ede5 100644 --- a/adapter/ohos/entrance/ui_content_impl.cpp +++ b/adapter/ohos/entrance/ui_content_impl.cpp @@ -1205,10 +1205,25 @@ UIContentErrorCode UIContentImpl::CommonInitializeForm( reinterpret_cast(ref), context); } } - + UpdateFontScale(context->GetConfiguration()); return UIContentErrorCode::NO_ERRORS; } +void UIContentImpl::UpdateFontScale(const std::shared_ptr& config) +{ + CHECK_NULL_VOID(config); + auto maxAppFontScale = config->GetItem(OHOS::AAFwk::GlobalConfigurationKey::APP_FONT_MAX_SCALE); + auto followSystem = config->GetItem(OHOS::AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); + auto context = NG::PipelineContext::GetContextByContainerId(instanceId_); + CHECK_NULL_VOID(context); + if (!followSystem.empty()) { + context->SetFollowSystem(followSystem == "followSystem"); + } + if (!maxAppFontScale.empty()) { + context->SetMaxAppFontScale(std::stof(maxAppFontScale)); + } +} + void UIContentImpl::SetConfiguration(const std::shared_ptr& config) { if (config == nullptr) { @@ -1788,6 +1803,7 @@ UIContentErrorCode UIContentImpl::CommonInitialize( .append(moduleName) .append(",abilityName:") .append(abilityName)); + UpdateFontScale(context->GetConfiguration()); return errorCode; } diff --git a/adapter/ohos/entrance/ui_content_impl.h b/adapter/ohos/entrance/ui_content_impl.h index 9b7137d3c44..e89121ff9b2 100644 --- a/adapter/ohos/entrance/ui_content_impl.h +++ b/adapter/ohos/entrance/ui_content_impl.h @@ -78,6 +78,7 @@ public: std::string GetContentInfo(ContentInfoType type) const override; void DestroyUIDirector() override; void SetUIContentType(UIContentType uIContentType) override; + void UpdateFontScale(const std::shared_ptr& config); // UI content event process bool ProcessBackPressed() override; diff --git a/frameworks/base/geometry/dimension.cpp b/frameworks/base/geometry/dimension.cpp index 221a44db584..fe5aa218479 100644 --- a/frameworks/base/geometry/dimension.cpp +++ b/frameworks/base/geometry/dimension.cpp @@ -168,8 +168,8 @@ double Dimension::ConvertToPxWithSize(double size) const double Dimension::ConvertToPxDistribute(std::optional minOptional, std::optional maxOptional) const { - auto minFontScale = minOptional.value_or(0.85f); - auto maxFontScale = maxOptional.value_or(3.2f); + auto minFontScale = minOptional.value_or(0.0f); + auto maxFontScale = maxOptional.value_or(static_cast(INT32_MAX)); if (!maxOptional.has_value()) { return ConvertToPxByAppFontScale(minFontScale); } @@ -194,7 +194,10 @@ double Dimension::ConvertToPxByAppFontScale(float minFontScale) const } auto pipeline = PipelineBase::GetCurrentContextSafely(); CHECK_NULL_RETURN(pipeline, value_); - float maxFontScale = 3.2f; + if (!pipeline->IsFollowSystem()) { + return value_ * pipeline->GetDipScale(); + } + float maxFontScale = pipeline->GetMaxAppFontScale(); float fontScale = std::clamp(pipeline->GetFontScale(), minFontScale, maxFontScale); return value_ * pipeline->GetDipScale() * fontScale; } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_text.cpp b/frameworks/bridge/declarative_frontend/jsview/js_text.cpp index 61c519d841d..ad47fe2ef4e 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_text.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_text.cpp @@ -190,10 +190,13 @@ void JSText::SetMinFontScale(const JSCallbackInfo& info) { double minFontScale; if (info.Length() < 1 || !ParseJsDouble(info[0], minFontScale)) { - TextModel::GetInstance()->SetMinFontScale(1.0f); return; } - if (LessOrEqual(minFontScale, 0.0f) || GreatOrEqual(minFontScale, 1.0f)) { + if (LessOrEqual(minFontScale, 0.0f)) { + TextModel::GetInstance()->SetMinFontScale(0.0f); + return; + } + if (GreatOrEqual(minFontScale, 1.0f)) { TextModel::GetInstance()->SetMinFontScale(1.0f); return; } @@ -204,7 +207,6 @@ void JSText::SetMaxFontScale(const JSCallbackInfo& info) { double maxFontScale; if (info.Length() < 1 || !ParseJsDouble(info[0], maxFontScale)) { - TextModel::GetInstance()->SetMaxFontScale(1.0f); return; } if (LessOrEqual(maxFontScale, 1.0f)) { diff --git a/frameworks/core/pipeline/pipeline_base.h b/frameworks/core/pipeline/pipeline_base.h index 7f46e3f7238..4f21572af71 100644 --- a/frameworks/core/pipeline/pipeline_base.h +++ b/frameworks/core/pipeline/pipeline_base.h @@ -369,6 +369,26 @@ public: void UpdateFontWeightScale(); + void SetFollowSystem(bool followSystem) + { + followSystem_ = followSystem; + } + + void SetMaxAppFontScale(float maxAppFontScale) + { + maxAppFontScale_ = maxAppFontScale; + } + + float GetMaxAppFontScale() + { + return maxAppFontScale_; + } + + bool IsFollowSystem() + { + return followSystem_; + } + double NormalizeToPx(const Dimension& dimension) const; double ConvertPxToVp(const Dimension& dimension) const; @@ -1461,6 +1481,9 @@ private: std::shared_ptr rsTransaction_; uint32_t frameCount_ = 0; + bool followSystem_ = true; + float maxAppFontScale_ = static_cast(INT32_MAX); + // To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker thread. std::mutex densityChangeMutex_; int32_t densityChangeCallbackId_ = 0;