1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "core/interfaces/native/node/util_modifier.h"
16 #include "base/utils/system_properties.h"
17 #include "core/common/container.h"
18
19 namespace OHOS::Ace::NG {
20
GetDensity(int deviceId)21 ArkUI_Float32 GetDensity(int deviceId)
22 {
23 return SystemProperties::GetResolution();
24 }
25
GetFontScale(int deviceId)26 ArkUI_Float32 GetFontScale(int deviceId)
27 {
28 auto scale = 0.0;
29 auto density = SystemProperties::GetResolution();
30 auto container = Container::Current();
31 if (container && container->GetPipelineContext()) {
32 scale = container->GetPipelineContext()->GetFontScale() * density;
33 }
34 return scale;
35 }
36
GetDesignWidthScale(int deviceId)37 ArkUI_Float32 GetDesignWidthScale(int deviceId)
38 {
39 auto scale = 0.0;
40 auto container = Container::Current();
41 CHECK_NULL_RETURN(container, scale);
42 auto frontend = container->GetFrontend();
43 CHECK_NULL_RETURN(frontend, scale);
44 auto windowConfig = frontend->GetWindowConfig();
45 return windowConfig.GetDesignWidthScale(SystemProperties::GetDeviceWidth());
46 }
47
48 namespace NodeModifier {
GetUtilsModifier()49 const ArkUIUtilsModifier* GetUtilsModifier()
50 {
51 static const ArkUIUtilsModifier modifier = {
52 GetDensity,
53 GetFontScale,
54 GetDesignWidthScale,
55 };
56 return &modifier;
57 }
58
GetCJUIUtilsModifier()59 const CJUIUtilsModifier* GetCJUIUtilsModifier()
60 {
61 static const CJUIUtilsModifier modifier = {
62 GetDensity,
63 GetFontScale,
64 GetDesignWidthScale,
65 };
66 return &modifier;
67 }
68 }
69 } // namespace OHOS::Ace::NG