1 /*
2 * Copyright (c) 2021 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_v2/inspector/utils.h"
17
18 namespace OHOS::Ace::V2 {
19
GetTextStyleInJson(const TextStyle & textStyle)20 std::string GetTextStyleInJson(const TextStyle& textStyle)
21 {
22 auto jsonValue = JsonUtil::Create(true);
23 jsonValue->Put("size", textStyle.GetFontSize().ToString().c_str());
24 auto weight = textStyle.GetFontWeight();
25 if (weight == FontWeight::W100) {
26 jsonValue->Put("weight", "100");
27 } else if (weight == FontWeight::W200) {
28 jsonValue->Put("weight", "200");
29 } else if (weight == FontWeight::W300) {
30 jsonValue->Put("weight", "300");
31 } else if (weight == FontWeight::W400) {
32 jsonValue->Put("weight", "400");
33 } else if (weight == FontWeight::W500) {
34 jsonValue->Put("weight", "500");
35 } else if (weight == FontWeight::W600) {
36 jsonValue->Put("weight", "600");
37 } else if (weight == FontWeight::W700) {
38 jsonValue->Put("weight", "700");
39 } else if (weight == FontWeight::W800) {
40 jsonValue->Put("weight", "800");
41 } else if (weight == FontWeight::W900) {
42 jsonValue->Put("weight", "900");
43 } else {
44 jsonValue->Put("weight", ConvertWrapFontWeightToStirng(weight).c_str());
45 }
46 std::string jsonFamily = ConvertFontFamily(textStyle.GetFontFamilies());
47 jsonValue->Put("family", jsonFamily.c_str());
48 auto fontStyle = textStyle.GetFontStyle();
49 jsonValue->Put("style", ConvertWrapFontStyleToStirng(fontStyle).c_str());
50 return jsonValue->ToString();
51 }
52
53 } // namespace OHOS::Ace::V2
54