mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 23:21:05 +00:00
commit
defca68454
@ -1205,10 +1205,25 @@ UIContentErrorCode UIContentImpl::CommonInitializeForm(
|
||||
reinterpret_cast<NativeReference*>(ref), context);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateFontScale(context->GetConfiguration());
|
||||
return UIContentErrorCode::NO_ERRORS;
|
||||
}
|
||||
|
||||
void UIContentImpl::UpdateFontScale(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& 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<OHOS::AppExecFwk::Configuration>& config)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
@ -1788,6 +1803,7 @@ UIContentErrorCode UIContentImpl::CommonInitialize(
|
||||
.append(moduleName)
|
||||
.append(",abilityName:")
|
||||
.append(abilityName));
|
||||
UpdateFontScale(context->GetConfiguration());
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
|
@ -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<OHOS::AppExecFwk::Configuration>& config);
|
||||
|
||||
// UI content event process
|
||||
bool ProcessBackPressed() override;
|
||||
|
@ -168,8 +168,8 @@ double Dimension::ConvertToPxWithSize(double size) const
|
||||
|
||||
double Dimension::ConvertToPxDistribute(std::optional<float> minOptional, std::optional<float> 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<float>(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;
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
@ -1467,6 +1487,8 @@ private:
|
||||
WindowSizeChangeReason type_ = WindowSizeChangeReason::UNDEFINED;
|
||||
std::shared_ptr<Rosen::RSTransaction> rsTransaction_;
|
||||
uint32_t frameCount_ = 0;
|
||||
bool followSystem_ = true;
|
||||
float maxAppFontScale_ = static_cast<float>(INT32_MAX);
|
||||
float dragNodeGrayscale_ = 0.0f;
|
||||
|
||||
// To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker thread.
|
||||
|
Loading…
Reference in New Issue
Block a user