xref: /aosp_15_r20/external/skia/include/core/SkFontArguments.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkFontArguments_DEFINED
9 #define SkFontArguments_DEFINED
10 
11 #include "include/core/SkColor.h"
12 #include "include/core/SkFourByteTag.h"
13 #include "include/core/SkTypes.h"
14 
15 #include <cstdint>
16 
17 /** Represents a set of actual arguments for a font. */
18 struct SkFontArguments {
19     struct VariationPosition {
20         struct Coordinate {
21             SkFourByteTag axis;
22             float value;
23         };
24         const Coordinate* coordinates;
25         int coordinateCount;
26     };
27 
28     /** Specify a palette to use and overrides for palette entries.
29      *
30      *  `overrides` is a list of pairs of palette entry index and color.
31      *  The overriden palette entries will use the associated color.
32      *  Override pairs with palette entry indices out of range will not be applied.
33      *  Later override entries override earlier ones.
34      */
35     struct Palette {
36         struct Override {
37             uint16_t index;
38             SkColor color;
39         };
40         int index;
41         const Override* overrides;
42         int overrideCount;
43     };
44 
SkFontArgumentsSkFontArguments45     SkFontArguments()
46             : fCollectionIndex(0)
47             , fVariationDesignPosition{nullptr, 0}
48             , fPalette{0, nullptr, 0} {}
49 
50     /** Specify the index of the desired font.
51      *
52      *  Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may actually be indexed
53      *  collections of fonts.
54      */
setCollectionIndexSkFontArguments55     SkFontArguments& setCollectionIndex(int collectionIndex) {
56         fCollectionIndex = collectionIndex;
57         return *this;
58     }
59 
60     /** Specify a position in the variation design space.
61      *
62      *  Any axis not specified will use the default value.
63      *  Any specified axis not actually present in the font will be ignored.
64      *
65      *  @param position not copied. The value must remain valid for life of SkFontArguments.
66      */
setVariationDesignPositionSkFontArguments67     SkFontArguments& setVariationDesignPosition(VariationPosition position) {
68         fVariationDesignPosition.coordinates = position.coordinates;
69         fVariationDesignPosition.coordinateCount = position.coordinateCount;
70         return *this;
71     }
72 
getCollectionIndexSkFontArguments73     int getCollectionIndex() const {
74         return fCollectionIndex;
75     }
76 
getVariationDesignPositionSkFontArguments77     VariationPosition getVariationDesignPosition() const {
78         return fVariationDesignPosition;
79     }
80 
setPaletteSkFontArguments81     SkFontArguments& setPalette(Palette palette) {
82         fPalette.index = palette.index;
83         fPalette.overrides = palette.overrides;
84         fPalette.overrideCount = palette.overrideCount;
85         return *this;
86     }
87 
getPaletteSkFontArguments88     Palette getPalette() const { return fPalette; }
89 
90 private:
91     int fCollectionIndex;
92     VariationPosition fVariationDesignPosition;
93     Palette fPalette;
94 };
95 
96 #endif
97