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_font.h"
17 
18 #include <include/core/SkFontTypes.h>
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace TextEngine {
23 #define DEFAULT_ITALIC 1.0f
GetFont() const24 std::shared_ptr<RSFont> TexgineFont::GetFont() const
25 {
26     return font_;
27 }
28 
SetTypeface(const std::shared_ptr<TexgineTypeface> tf)29 void TexgineFont::SetTypeface(const std::shared_ptr<TexgineTypeface> tf)
30 {
31     if (tf) {
32         font_->SetTypeface(tf->GetTypeface());
33     } else {
34         font_->SetTypeface(nullptr);
35     }
36 }
37 
SetSize(float textSize)38 void TexgineFont::SetSize(float textSize)
39 {
40     font_->SetSize(textSize);
41 }
42 
GetMetrics(std::shared_ptr<TexgineFontMetrics> metrics) const43 float TexgineFont::GetMetrics(std::shared_ptr<TexgineFontMetrics> metrics) const
44 {
45     if (metrics == nullptr) {
46         return 0;
47     }
48 
49     return font_->GetMetrics(metrics->GetFontMetrics().get());
50 }
SetSubpixel(const bool isSubpixel)51 void TexgineFont::SetSubpixel(const bool isSubpixel)
52 {
53     font_->SetSubpixel(isSubpixel);
54 }
55 
SetEdging(const FontEdging edging)56 void TexgineFont::SetEdging(const FontEdging edging)
57 {
58     font_->SetEdging(static_cast<Drawing::FontEdging>(edging));
59 }
60 
SetHinting(const TexgineFontHinting hinting)61 void TexgineFont::SetHinting(const TexgineFontHinting hinting)
62 {
63     font_->SetHinting(static_cast<Drawing::FontHinting>(hinting));
64 }
65 
SetSkewX()66 void TexgineFont::SetSkewX()
67 {
68     font_->SetSkewX(-DEFAULT_ITALIC / 4); // standard italic offset is 1/4
69 }
70 
SetBold()71 void TexgineFont::SetBold()
72 {
73     font_->SetEmbolden(true);
74 }
75 } // namespace TextEngine
76 } // namespace Rosen
77 } // namespace OHOS
78