1 /*
2 * Copyright (c) 2024 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 FONT_ARGUMENTS_H
17 #define FONT_ARGUMENTS_H
18
19 #include <cstdint>
20
21 namespace OHOS {
22 namespace Rosen {
23 namespace Drawing {
24 // Represents a set of actual arguments for a font.
25 struct FontArguments {
26 struct VariationPosition {
27 struct Coordinate {
28 uint32_t axis;
29 float value;
30 };
31 const Coordinate* coordinates;
32 int coordinateCount;
33 };
34
35 /*
36 * Specify a palette to use and overrides for palette entries.
37 * `overrides` is a list of pairs of palette entry index and color.
38 * The overriden palette entries will use the associated color.
39 * Override pairs with palette entry indices out of range will not be applied.
40 * Later override entries override earlier ones.
41 */
42 struct Palette {
43 struct Override {
44 int index;
45 uint32_t color;
46 };
47 int index;
48 const Override* overrides;
49 int overrideCount;
50 };
51
FontArgumentsFontArguments52 FontArguments(): fontCollectionIndex_(0), variationDesignPosition_{nullptr, 0}, palette_{0, nullptr, 0}
53 {
54 }
55
56 /*
57 * Specify the index of the desired font.
58 * Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may actually be indexed
59 * collections of fonts.
60 */
SetCollectionIndexFontArguments61 FontArguments& SetCollectionIndex(int fontCollectionIndex)
62 {
63 fontCollectionIndex_ = fontCollectionIndex;
64 return *this;
65 }
66
67 /*
68 * Specify a position in the variation design space.
69 * Any axis not specified will use the default value.
70 * Any specified axis not actually present in the font will be ignored.
71 */
SetVariationDesignPositionFontArguments72 FontArguments& SetVariationDesignPosition(VariationPosition position)
73 {
74 variationDesignPosition_.coordinates = position.coordinates;
75 variationDesignPosition_.coordinateCount = position.coordinateCount;
76 return *this;
77 }
78
GetCollectionIndexFontArguments79 int GetCollectionIndex() const
80 {
81 return fontCollectionIndex_;
82 }
83
GetVariationDesignPositionFontArguments84 VariationPosition GetVariationDesignPosition() const
85 {
86 return variationDesignPosition_;
87 }
88
SetPaletteFontArguments89 FontArguments& SetPalette(Palette palette)
90 {
91 palette_.index = palette.index;
92 palette_.overrides = palette.overrides;
93 palette_.overrideCount = palette.overrideCount;
94 return *this;
95 }
96
GetPaletteFontArguments97 Palette GetPalette() const
98 {
99 return palette_;
100 }
101
102 private:
103 int fontCollectionIndex_;
104 VariationPosition variationDesignPosition_;
105 Palette palette_;
106 };
107 } // namespace Drawing
108 } // namespace Rosen
109 } // namespace OHOS
110 #endif // FONT_ARGUMENTS_H
111