/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/SkScalar.h" |
13 | | #include "include/core/SkTypes.h" |
14 | | |
15 | | /** Represents a set of actual arguments for a font. */ |
16 | | struct SkFontArguments { |
17 | | struct VariationPosition { |
18 | | struct Coordinate { |
19 | | SkFourByteTag axis; |
20 | | float value; |
21 | | }; |
22 | | const Coordinate* coordinates; |
23 | | int coordinateCount; |
24 | | }; |
25 | | |
26 | | /** Specify a palette to use and overrides for palette entries. |
27 | | * |
28 | | * `overrides` is a list of pairs of palette entry index and color. |
29 | | * The overriden palette entries will use the associated color. |
30 | | * Override pairs with palette entry indices out of range will not be applied. |
31 | | * Later override entries override earlier ones. |
32 | | */ |
33 | | struct Palette { |
34 | | struct Override { |
35 | | uint16_t index; |
36 | | SkColor color; |
37 | | }; |
38 | | int index; |
39 | | const Override* overrides; |
40 | | int overrideCount; |
41 | | }; |
42 | | |
43 | | SkFontArguments() |
44 | | : fCollectionIndex(0) |
45 | | , fVariationDesignPosition{nullptr, 0} |
46 | 528k | , fPalette{0, nullptr, 0} {} |
47 | | |
48 | | /** Specify the index of the desired font. |
49 | | * |
50 | | * Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may actually be indexed |
51 | | * collections of fonts. |
52 | | */ |
53 | 528k | SkFontArguments& setCollectionIndex(int collectionIndex) { |
54 | 528k | fCollectionIndex = collectionIndex; |
55 | 528k | return *this; |
56 | 528k | } |
57 | | |
58 | | /** Specify a position in the variation design space. |
59 | | * |
60 | | * Any axis not specified will use the default value. |
61 | | * Any specified axis not actually present in the font will be ignored. |
62 | | * |
63 | | * @param position not copied. The value must remain valid for life of SkFontArguments. |
64 | | */ |
65 | 523k | SkFontArguments& setVariationDesignPosition(VariationPosition position) { |
66 | 523k | fVariationDesignPosition.coordinates = position.coordinates; |
67 | 523k | fVariationDesignPosition.coordinateCount = position.coordinateCount; |
68 | 523k | return *this; |
69 | 523k | } |
70 | | |
71 | 541k | int getCollectionIndex() const { |
72 | 541k | return fCollectionIndex; |
73 | 541k | } |
74 | | |
75 | 50.0k | VariationPosition getVariationDesignPosition() const { |
76 | 50.0k | return fVariationDesignPosition; |
77 | 50.0k | } |
78 | | |
79 | 523k | SkFontArguments& setPalette(Palette palette) { |
80 | 523k | fPalette.index = palette.index; |
81 | 523k | fPalette.overrides = palette.overrides; |
82 | 523k | fPalette.overrideCount = palette.overrideCount; |
83 | 523k | return *this; |
84 | 523k | } |
85 | | |
86 | 150k | Palette getPalette() const { return fPalette; } |
87 | | |
88 | | private: |
89 | | int fCollectionIndex; |
90 | | VariationPosition fVariationDesignPosition; |
91 | | Palette fPalette; |
92 | | }; |
93 | | |
94 | | #endif |