• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
16 #include "core/components_ng/property/calc_length.h"
17 
18 #include "base/utils/string_expression.h"
19 #include "core/pipeline/pipeline_base.h"
20 
21 namespace OHOS::Ace::NG {
22 
CreateScaleProperty(PipelineBase * context)23 ScaleProperty ScaleProperty::CreateScaleProperty(PipelineBase* context)
24 {
25     ScaleProperty scaleProperty;
26     auto pipeline = context ? AceType::Claim(context) : PipelineBase::GetCurrentContextSafely();
27     CHECK_NULL_RETURN(pipeline, scaleProperty);
28     scaleProperty.fpScale = pipeline->GetFontScale();
29     scaleProperty.vpScale = static_cast<float>(pipeline->GetDipScale());
30     scaleProperty.lpxScale = static_cast<float>(pipeline->GetLogicScale());
31     return scaleProperty;
32 }
33 
NormalizeToPx(double vpScale,double fpScale,double lpxScale,double parentLength,double & result,const std::vector<std::string> & rpnexp) const34 bool CalcLength::NormalizeToPx(double vpScale, double fpScale, double lpxScale, double parentLength, double& result,
35     const std::vector<std::string>& rpnexp) const
36 {
37     // don't use this function for calc.
38     if (!calcValue_.empty()) {
39         result = StringExpression::CalculateExp(
40             calcValue_,
41             [vpScale, fpScale, lpxScale, parentLength](const Dimension& dim) -> double {
42                 double result = -1.0;
43                 dim.NormalizeToPx(vpScale, fpScale, lpxScale, parentLength, result);
44                 return result;
45             },
46             rpnexp);
47         return result >= 0;
48     }
49     return dimension_.NormalizeToPx(vpScale, fpScale, lpxScale, parentLength, result);
50 }
51 
52 } // namespace OHOS::Ace::NG
53