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/SkScalar.h" |
12 | #include "include/core/SkTypes.h" |
13 | |
14 | /** Represents a set of actual arguments for a font. */ |
15 | struct SkFontArguments { |
16 | struct VariationPosition { |
17 | struct Coordinate { |
18 | SkFourByteTag axis; |
19 | float value; |
20 | }; |
21 | const Coordinate* coordinates; |
22 | int coordinateCount; |
23 | }; |
24 | // deprecated, use VariationPosition::Coordinate instead |
25 | struct Axis { |
26 | SkFourByteTag fTag; |
27 | float fStyleValue; |
28 | }; |
29 | |
30 | SkFontArguments() : fCollectionIndex(0), fVariationDesignPosition{nullptr, 0} {} |
31 | |
32 | /** Specify the index of the desired font. |
33 | * |
34 | * Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may actually be indexed |
35 | * collections of fonts. |
36 | */ |
37 | SkFontArguments& setCollectionIndex(int collectionIndex) { |
38 | fCollectionIndex = collectionIndex; |
39 | return *this; |
40 | } |
41 | |
42 | // deprecated, use setVariationDesignPosition instead. |
43 | SkFontArguments& setAxes(const Axis* axes, int axisCount) { |
44 | fVariationDesignPosition.coordinates = |
45 | reinterpret_cast<const VariationPosition::Coordinate*>(axes); |
46 | fVariationDesignPosition.coordinateCount = axisCount; |
47 | return *this; |
48 | } |
49 | |
50 | /** Specify a position in the variation design space. |
51 | * |
52 | * Any axis not specified will use the default value. |
53 | * Any specified axis not actually present in the font will be ignored. |
54 | * |
55 | * @param position not copied. The value must remain valid for life of SkFontArguments. |
56 | */ |
57 | SkFontArguments& setVariationDesignPosition(VariationPosition position) { |
58 | fVariationDesignPosition.coordinates = position.coordinates; |
59 | fVariationDesignPosition.coordinateCount = position.coordinateCount; |
60 | return *this; |
61 | } |
62 | |
63 | int getCollectionIndex() const { |
64 | return fCollectionIndex; |
65 | } |
66 | // deprecated, use getVariationDesignPosition instead. |
67 | const Axis* getAxes(int* axisCount) const { |
68 | *axisCount = fVariationDesignPosition.coordinateCount; |
69 | return reinterpret_cast<const Axis*>(fVariationDesignPosition.coordinates); |
70 | } |
71 | VariationPosition getVariationDesignPosition() const { |
72 | return fVariationDesignPosition; |
73 | } |
74 | private: |
75 | int fCollectionIndex; |
76 | VariationPosition fVariationDesignPosition; |
77 | }; |
78 | |
79 | #endif |
80 | |