/src/skia/include/core/SkFontArguments.h
Line | Count | Source |
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 | | |
45 | | SkFontArguments() |
46 | | : fCollectionIndex(0) |
47 | | , fVariationDesignPosition{nullptr, 0} |
48 | 418k | , 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 | | */ |
55 | 418k | SkFontArguments& setCollectionIndex(int collectionIndex) { |
56 | 418k | fCollectionIndex = collectionIndex; |
57 | 418k | return *this; |
58 | 418k | } |
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 | | */ |
67 | 415k | SkFontArguments& setVariationDesignPosition(VariationPosition position) { |
68 | 415k | fVariationDesignPosition.coordinates = position.coordinates; |
69 | 415k | fVariationDesignPosition.coordinateCount = position.coordinateCount; |
70 | 415k | return *this; |
71 | 415k | } |
72 | | |
73 | 429k | int getCollectionIndex() const { |
74 | 429k | return fCollectionIndex; |
75 | 429k | } |
76 | | |
77 | 41.8k | VariationPosition getVariationDesignPosition() const { |
78 | 41.8k | return fVariationDesignPosition; |
79 | 41.8k | } |
80 | | |
81 | 415k | SkFontArguments& setPalette(Palette palette) { |
82 | 415k | fPalette.index = palette.index; |
83 | 415k | fPalette.overrides = palette.overrides; |
84 | 415k | fPalette.overrideCount = palette.overrideCount; |
85 | 415k | return *this; |
86 | 415k | } |
87 | | |
88 | 125k | Palette getPalette() const { return fPalette; } |
89 | | |
90 | | private: |
91 | | int fCollectionIndex; |
92 | | VariationPosition fVariationDesignPosition; |
93 | | Palette fPalette; |
94 | | }; |
95 | | |
96 | | #endif |