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