• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "ani_common.h"
17 #include "ani_line_metrics_converter.h"
18 #include "ani_run_metrics_converter.h"
19 #include "ani_text_utils.h"
20 
21 namespace OHOS::Text::ANI {
22 using namespace OHOS::Rosen;
ParseLineMetricsToAni(ani_env * env,const LineMetrics & lineMetrics)23 ani_object AniLineMetricsConverter::ParseLineMetricsToAni(ani_env* env, const LineMetrics& lineMetrics)
24 {
25     ani_object aniObj = AniTextUtils::CreateAniObject(env, ANI_CLASS_LINEMETRICS, ":V");
26     env->Object_SetPropertyByName_Double(aniObj, "startIndex", ani_int(lineMetrics.startIndex));
27     env->Object_SetPropertyByName_Double(aniObj, "endIndex", ani_int(lineMetrics.endIndex));
28     env->Object_SetPropertyByName_Double(aniObj, "ascent", ani_double(lineMetrics.ascender));
29     env->Object_SetPropertyByName_Double(aniObj, "descent", ani_double(lineMetrics.descender));
30     env->Object_SetPropertyByName_Double(aniObj, "height", ani_double(lineMetrics.height));
31     env->Object_SetPropertyByName_Double(aniObj, "width", ani_double(lineMetrics.width));
32     env->Object_SetPropertyByName_Double(aniObj, "left", ani_double(lineMetrics.x));
33     env->Object_SetPropertyByName_Double(aniObj, "baseline", ani_double(lineMetrics.baseline));
34     env->Object_SetPropertyByName_Double(aniObj, "lineNumber", ani_int(lineMetrics.lineNumber));
35     env->Object_SetPropertyByName_Double(aniObj, "topHeight", ani_double(lineMetrics.y));
36     env->Object_SetPropertyByName_Ref(
37         aniObj, "runMetrics", AniRunMetricsConverter::ParseRunMetricsToAni(env, lineMetrics.runMetrics));
38     return aniObj;
39 }
40 } // namespace OHOS::Text::ANI