• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "texgine/typography_style.h"
17 
18 namespace OHOS {
19 namespace Rosen {
20 namespace TextEngine {
ConvertToTextStyle() const21 TextStyle TypographyStyle::ConvertToTextStyle() const
22 {
23     TextStyle style;
24     style.fontSize = fontSize;
25     style.fontFamilies = fontFamilies;
26     style.heightScale = heightScale;
27     style.halfLeading = halfLeading;
28     style.heightOnly = heightOnly;
29     style.fontWeight = fontWeight;
30     style.fontStyle = fontStyle;
31 
32     return style;
33 }
34 
GetEquivalentAlign() const35 TextAlign TypographyStyle::GetEquivalentAlign() const
36 {
37     TextAlign textAlign = align;
38     bool isLTR = direction == TextDirection::LTR;
39     TextAlign trim = textAlign & TextAlign::TRIM;
40     textAlign &= ~TextAlign::TRIM;
41     if (textAlign == TextAlign::START) {
42         textAlign = isLTR ? TextAlign::LEFT : TextAlign::RIGHT;
43     } else if (textAlign == TextAlign::END) {
44         textAlign = isLTR ? TextAlign::RIGHT : TextAlign::LEFT;
45     } else if (textAlign == TextAlign::JUSTIFY) {
46         textAlign = isLTR ? TextAlign::JUSTIFY : TextAlign::RIGHT;
47     }
48     return textAlign | trim;
49 }
50 } // namespace TextEngine
51 } // namespace Rosen
52 } // namespace OHOS
53