• 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 #ifndef ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_FONT_H
17 #define ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_FONT_H
18 
19 #include <memory>
20 
21 #ifndef USE_ROSEN_DRAWING
22 #include <include/core/SkFont.h>
23 #else
24 #include "drawing.h"
25 #endif
26 
27 #include "texgine_font_metrics.h"
28 #include "texgine_typeface.h"
29 
30 namespace OHOS {
31 namespace Rosen {
32 namespace TextEngine {
33 class TexgineFont {
34 public:
35     enum FontEdging : uint8_t {
36         ALIAS,
37         ANTIALIAS,
38         SUBPIXEL_ANTIALIAS,
39     };
40 
41     enum TexgineFontHinting : uint8_t {
42         NONE,
43         SLIGHT,
44         NORMAL,
45         FULL,
46     };
47 
48 #ifndef USE_ROSEN_DRAWING
49     std::shared_ptr<SkFont> GetFont() const;
50 #else
51     std::shared_ptr<RSFont> GetFont() const;
52 #endif
53 
54     /*
55      * @brief Set typeface to SkFont
56      */
57     void SetTypeface(const std::shared_ptr<TexgineTypeface> tf);
58 
59     /*
60      * @brief Set font size
61      */
62     void SetSize(float textSize);
63 
64     /*
65      * @brief Get metrics of the font
66      */
67     float GetMetrics(std::shared_ptr<TexgineFontMetrics> metrics) const;
68 
69     /*
70      * @brief Get metrics of the font
71      */
72     void SetSubpixel(const bool isSubpixel);
73 
74     /*
75      * @brief Set subpixel positioning
76      */
77     void SetEdging(const FontEdging edging);
78 
79     /*
80      * @brief Set font optimization mode
81      */
82     void SetHinting(const TexgineFontHinting hinting);
83 
84     /*
85      * @brief Set font default non-bold italics mode
86      */
87     void SetSkewX();
88 
89     void SetBold();
90 private:
91 #ifndef USE_ROSEN_DRAWING
92     std::shared_ptr<SkFont> font_ = std::make_shared<SkFont>();
93 #else
94     std::shared_ptr<RSFont> font_ = std::make_shared<RSFont>();
95 #endif
96 };
97 } // namespace TextEngine
98 } // namespace Rosen
99 } // namespace OHOS
100 
101 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_FONT_H
102