// Copyright 2019 Google LLC. #include "modules/skparagraph/include/FontArguments.h" static bool operator==(const SkFontArguments::VariationPosition::Coordinate& a, const SkFontArguments::VariationPosition::Coordinate& b) { return a.axis == b.axis && a.value == b.value; } static bool operator==(const SkFontArguments::Palette::Override& a, const SkFontArguments::Palette::Override& b) { return a.index == b.index && a.color == b.color; } namespace std { size_t hash::operator()(const skia::textlayout::FontArguments& args) const { size_t hash = 0; hash ^= std::hash()(args.fCollectionIndex); for (const auto& coord : args.fCoordinates) { hash ^= std::hash()(coord.axis); hash ^= std::hash()(coord.value); } hash ^= std::hash()(args.fPaletteIndex); for (const auto& override : args.fPaletteOverrides) { hash ^= std::hash()(override.index); hash ^= std::hash()(override.color); } return hash; } } // namespace std namespace skia { namespace textlayout { FontArguments::FontArguments(const SkFontArguments& args) : fCollectionIndex(args.getCollectionIndex()), fCoordinates(args.getVariationDesignPosition().coordinates, args.getVariationDesignPosition().coordinates + args.getVariationDesignPosition().coordinateCount), fPaletteIndex(args.getPalette().index), fPaletteOverrides(args.getPalette().overrides, args.getPalette().overrides + args.getPalette().overrideCount) {} bool operator==(const FontArguments& a, const FontArguments& b) { return a.fCollectionIndex == b.fCollectionIndex && a.fCoordinates == b.fCoordinates && a.fPaletteIndex == b.fPaletteIndex && a.fPaletteOverrides == b.fPaletteOverrides; } bool operator!=(const skia::textlayout::FontArguments& a, const skia::textlayout::FontArguments& b) { return !(a == b); } sk_sp FontArguments::CloneTypeface(const sk_sp& typeface) const { SkFontArguments::VariationPosition position{ fCoordinates.data(), static_cast(fCoordinates.size()) }; SkFontArguments::Palette palette{ fPaletteIndex, fPaletteOverrides.data(), static_cast(fPaletteOverrides.size()) }; SkFontArguments args; args.setCollectionIndex(fCollectionIndex); args.setVariationDesignPosition(position); args.setPalette(palette); return typeface->makeClone(args); } } // namespace textlayout } // namespace skia