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() const21TextStyle TypographyStyle::ConvertToTextStyle() const 22 { 23 TextStyle style; 24 style.fontSize = fontSize; 25 style.fontFamilies = fontFamilies; 26 style.heightScale = heightScale; 27 style.heightOnly = heightOnly; 28 style.fontWeight = fontWeight; 29 style.fontStyle = fontStyle; 30 31 return style; 32 } 33 GetEquivalentAlign() const34TextAlign TypographyStyle::GetEquivalentAlign() const 35 { 36 TextAlign textAlign = align; 37 bool isLTR = direction == TextDirection::LTR; 38 TextAlign trim = textAlign & TextAlign::TRIM; 39 textAlign &= ~TextAlign::TRIM; 40 if (textAlign == TextAlign::START) { 41 textAlign = isLTR ? TextAlign::LEFT : TextAlign::RIGHT; 42 } else if (textAlign == TextAlign::END) { 43 textAlign = isLTR ? TextAlign::RIGHT : TextAlign::LEFT; 44 } else if (textAlign == TextAlign::JUSTIFY) { 45 textAlign = isLTR ? TextAlign::JUSTIFY : TextAlign::RIGHT; 46 } 47 return textAlign | trim; 48 } 49 } // namespace TextEngine 50 } // namespace Rosen 51 } // namespace OHOS 52