• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FONTINFO_OHOS_H
6 #define FONTINFO_OHOS_H
7 
8 #include "securec.h"
9 
10 #include "SkFixed.h"
11 #include "SkFontDescriptor.h"
12 #include "SkFontHost_FreeType_common.h"
13 
14 /*!
15  * \brief To manage the font information
16  */
17 struct FontInfo {
18 public:
19     /*! Constructor
20      *
21      */
FontInfoFontInfo22     FontInfo() : familyName(""), fname(""), index(0),
23         style(SkFontStyle::Normal()), isFixedWidth(false), stream(nullptr)
24     {
25         memset_s(&axisSet, sizeof(AxisSet), 0, sizeof(AxisSet));
26     }
27     /*! Copy Constructor
28      * \param font an object of FontInfo
29      */
FontInfoFontInfo30     explicit FontInfo(const FontInfo& font)
31         : familyName(font.familyName), fname(font.fname), index(font.index),
32           style(font.style), isFixedWidth(font.isFixedWidth), stream(nullptr)
33     {
34         axisSet.axis = font.axisSet.axis;
35         axisSet.range = font.axisSet.range;
36         if (font.stream) {
37             stream = font.stream->duplicate();
38         }
39     }
40 
41     /*! Move Constructor
42      * \param font an object of FontInfo
43      */
FontInfoFontInfo44     explicit FontInfo(FontInfo&& font)
45         : familyName(std::move(font.familyName)), fname(std::move(font.fname)), index(font.index),
46           style(font.style), isFixedWidth(font.isFixedWidth), stream(nullptr)
47     {
48         axisSet.axis = std::move(font.axisSet.axis);
49         axisSet.range = std::move(font.axisSet.range);
50         if (font.stream) {
51             stream = std::move(font.stream);
52         }
53     }
54 
55     /*! Constructor
56      * \param fname the fullname of font file
57      * \param index the index of the typeface in the font file
58      */
FontInfoFontInfo59     FontInfo(const char* fname, int index)
60         : familyName(""), fname(""), index(index),
61           style(SkFontStyle::Normal()), isFixedWidth(false), stream(nullptr)
62     {
63         if (fname) {
64             this->fname.set(fname);
65         }
66         memset_s(&axisSet, sizeof(axisSet), 0, sizeof(axisSet));
67     }
68 
69     /*! Destructor
70      *
71      */
72     virtual ~FontInfo() = default;
73 
74     /*! Copy assignment operator
75      * \param font an object of FontInfo
76      */
77     FontInfo& operator = (const FontInfo& font)
78     {
79         if (this == &font) {
80             return *this;
81         }
82         familyName = font.familyName;
83         fname = font.fname;
84         index = font.index;
85         style = font.style;
86         isFixedWidth = font.isFixedWidth;
87         axisSet.axis = font.axisSet.axis;
88         axisSet.range = font.axisSet.range;
89         if (font.stream) {
90             stream = font.stream->duplicate();
91         }
92         return *this;
93     }
94 
95     /*! The move assignment operator
96      * \param font an object of FontInfo
97      */
98     FontInfo& operator = (FontInfo&& font)
99     {
100         if (this == &font) {
101             return *this;
102         }
103         familyName = std::move(font.familyName);
104         fname = std::move(font.fname);
105         index = font.index;
106         style = font.style;
107         isFixedWidth = font.isFixedWidth;
108         axisSet.axis = std::move(font.axisSet.axis);
109         axisSet.range = std::move(font.axisSet.range);
110         if (font.stream) {
111             stream = std::move(font.stream);
112         }
113         return *this;
114     }
115 
116     /*! To set axis values
117      * \param count the count of axis
118      * \param axis an array of SkFixed value
119      * \param range an array of AxisDefinition
120      */
setAxisSetFontInfo121     void setAxisSet(int count, const SkFixed* axis,
122         const SkTypeface_FreeType::Scanner::AxisDefinition* range)
123     {
124         axisSet.axis.clear();
125         axisSet.range.clear();
126         for (int i = 0; i < count; i++) {
127             axisSet.axis.emplace_back(axis[i]);
128             axisSet.range.emplace_back(range[i]);
129         }
130     }
131 
132     SkString familyName;  // the real family name of the font
133     SkString fname; // the full name of font file
134     int index; // the index of the font in a ttc font
135     SkFontStyle style; // the font style
136     bool isFixedWidth; // the flag to indicate if the font has fixed width or not
137     /*!
138      * \brief To manage the axis values for variable font
139      */
140     struct AxisSet {
141         std::vector<SkFixed> axis;  // the axis values
142         std::vector<SkTypeface_FreeType::Scanner::AxisDefinition> range; // the axis ranges
143     } axisSet; // the axis values for a variable font
144     std::unique_ptr<SkStreamAsset> stream; // the data stream of font file
145 };
146 
147 #endif /* FONTINFO_OHOS_H */
148