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
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 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
52 static const ArkUIUtilsModifier modifier = {
53 .getDensity = GetDensity,
54 .getFontScale = GetFontScale,
55 .getDesignWidthScale = GetDesignWidthScale,
56 };
57 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
58 return &modifier;
59 }
60
GetCJUIUtilsModifier()61 const CJUIUtilsModifier* GetCJUIUtilsModifier()
62 {
63 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
64 static const CJUIUtilsModifier modifier = {
65 .getDensity = GetDensity,
66 .getFontScale = GetFontScale,
67 .getDesignWidthScale = GetDesignWidthScale,
68 };
69 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
70 return &modifier;
71 }
72 }
73 } // namespace OHOS::Ace::NG