| 1 |
// Copyright 2019 Google LLC. |
| 2 |
|
| 3 |
#include "modules/skparagraph/include/FontArguments.h" |
| 4 |
|
| 5 |
static bool operator==(const SkFontArguments::VariationPosition::Coordinate& a, |
| 6 |
const SkFontArguments::VariationPosition::Coordinate& b) { |
| 7 |
return a.axis == b.axis && a.value == b.value; |
| 8 |
} |
| 9 |
|
| 10 |
static bool operator==(const SkFontArguments::Palette::Override& a, |
| 11 |
const SkFontArguments::Palette::Override& b) { |
| 12 |
return a.index == b.index && a.color == b.color; |
| 13 |
} |
| 14 |
|
| 15 |
namespace std { |
| 16 |
|
| 17 |
size_t hash<skia::textlayout::FontArguments>::operator()(const skia::textlayout::FontArguments& args) const { |
| 18 |
size_t hash = 0; |
| 19 |
hash ^= std::hash<int>()(args.fCollectionIndex); |
| 20 |
for (const auto& coord : args.fCoordinates) { |
| 21 |
hash ^= std::hash<SkFourByteTag>()(coord.axis); |
| 22 |
hash ^= std::hash<float>()(coord.value); |
| 23 |
} |
| 24 |
hash ^= std::hash<int>()(args.fPaletteIndex); |
| 25 |
for (const auto& override : args.fPaletteOverrides) { |
| 26 |
hash ^= std::hash<int>()(override.index); |
| 27 |
hash ^= std::hash<SkColor>()(override.color); |
| 28 |
} |
| 29 |
return hash; |
| 30 |
} |
| 31 |
|
| 32 |
} // namespace std |
| 33 |
|
| 34 |
namespace skia { |
| 35 |
namespace textlayout { |
| 36 |
|
| 37 |
FontArguments::FontArguments(const SkFontArguments& args) |
| 38 |
: fCollectionIndex(args.getCollectionIndex()), |
| 39 |
fCoordinates(args.getVariationDesignPosition().coordinates, |
| 40 |
args.getVariationDesignPosition().coordinates + |
| 41 |
args.getVariationDesignPosition().coordinateCount), |
| 42 |
fPaletteIndex(args.getPalette().index), |
| 43 |
fPaletteOverrides(args.getPalette().overrides, |
| 44 |
args.getPalette().overrides + |
| 45 |
args.getPalette().overrideCount) {} |
| 46 |
|
| 47 |
bool operator==(const FontArguments& a, const FontArguments& b) { |
| 48 |
return a.fCollectionIndex == b.fCollectionIndex && |
| 49 |
a.fCoordinates == b.fCoordinates && |
| 50 |
a.fPaletteIndex == b.fPaletteIndex && |
| 51 |
a.fPaletteOverrides == b.fPaletteOverrides; |
| 52 |
} |
| 53 |
|
| 54 |
bool operator!=(const skia::textlayout::FontArguments& a, const skia::textlayout::FontArguments& b) { |
| 55 |
return !(a == b); |
| 56 |
} |
| 57 |
|
| 58 |
sk_sp<SkTypeface> FontArguments::CloneTypeface(const sk_sp<SkTypeface>& typeface) const { |
| 59 |
SkFontArguments::VariationPosition position{ |
| 60 |
fCoordinates.data(), |
| 61 |
static_cast<int>(fCoordinates.size()) |
| 62 |
}; |
| 63 |
|
| 64 |
SkFontArguments::Palette palette{ |
| 65 |
fPaletteIndex, |
| 66 |
fPaletteOverrides.data(), |
| 67 |
static_cast<int>(fPaletteOverrides.size()) |
| 68 |
}; |
| 69 |
|
| 70 |
SkFontArguments args; |
| 71 |
args.setCollectionIndex(fCollectionIndex); |
| 72 |
args.setVariationDesignPosition(position); |
| 73 |
args.setPalette(palette); |
| 74 |
|
| 75 |
return typeface->makeClone(args); |
| 76 |
} |
| 77 |
|
| 78 |
} // namespace textlayout |
| 79 |
} // namespace skia |