• 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_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
24 #ifndef USE_ROSEN_DRAWING
GetFont() const25 std::shared_ptr<SkFont> TexgineFont::GetFont() const
26 #else
27 std::shared_ptr<RSFont> TexgineFont::GetFont() const
28 #endif
29 {
30     return font_;
31 }
32 
SetTypeface(const std::shared_ptr<TexgineTypeface> tf)33 void TexgineFont::SetTypeface(const std::shared_ptr<TexgineTypeface> tf)
34 {
35     if (tf) {
36 #ifndef USE_ROSEN_DRAWING
37         font_->setTypeface(tf->GetTypeface());
38 #else
39         font_->SetTypeface(tf->GetTypeface());
40 #endif
41     } else {
42 #ifndef USE_ROSEN_DRAWING
43         font_->setTypeface(nullptr);
44 #else
45         font_->SetTypeface(nullptr);
46 #endif
47     }
48 }
49 
SetSize(float textSize)50 void TexgineFont::SetSize(float textSize)
51 {
52 #ifndef USE_ROSEN_DRAWING
53     font_->setSize(textSize);
54 #else
55     font_->SetSize(textSize);
56 #endif
57 }
58 
GetMetrics(std::shared_ptr<TexgineFontMetrics> metrics) const59 float TexgineFont::GetMetrics(std::shared_ptr<TexgineFontMetrics> metrics) const
60 {
61     if (metrics == nullptr) {
62         return 0;
63     }
64 
65 #ifndef USE_ROSEN_DRAWING
66     return font_->getMetrics(metrics->GetFontMetrics().get());
67 #else
68     return font_->GetMetrics(metrics->GetFontMetrics().get());
69 #endif
70 }
SetSubpixel(const bool isSubpixel)71 void TexgineFont::SetSubpixel(const bool isSubpixel)
72 {
73 #ifndef USE_ROSEN_DRAWING
74     font_->setSubpixel(isSubpixel);
75 #else
76     font_->SetSubpixel(isSubpixel);
77 #endif
78 }
79 
SetEdging(const FontEdging edging)80 void TexgineFont::SetEdging(const FontEdging edging)
81 {
82 #ifndef USE_ROSEN_DRAWING
83     font_->setEdging(static_cast<SkFont::Edging>(edging));
84 #else
85     font_->SetEdging(static_cast<Drawing::FontEdging>(edging));
86 #endif
87 }
88 
SetHinting(const TexgineFontHinting hinting)89 void TexgineFont::SetHinting(const TexgineFontHinting hinting)
90 {
91 #ifndef USE_ROSEN_DRAWING
92     font_->setHinting(static_cast<SkFontHinting>(hinting));
93 #else
94     font_->SetHinting(static_cast<Drawing::FontHinting>(hinting));
95 #endif
96 }
97 
SetSkewX()98 void TexgineFont::SetSkewX()
99 {
100 #ifndef USE_ROSEN_DRAWING
101     font_->setSkewX(-DEFAULT_ITALIC / 4); // standard italic offset is 1/4
102 #else
103     font_->SetSkewX(-DEFAULT_ITALIC / 4); // standard italic offset is 1/4
104 #endif
105 }
106 
SetBold()107 void TexgineFont::SetBold()
108 {
109 #ifndef USE_ROSEN_DRAWING
110     font_->setEmbolden(true); // false means bold is turned off by default
111 #else
112     font_->SetEmbolden(true);
113 #endif
114 }
115 } // namespace TextEngine
116 } // namespace Rosen
117 } // namespace OHOS
118