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 int index; 36 SkColor color; 37 }; 38 int index; 39 const Override* overrides; 40 int overrideCount; 41 }; 42 SkFontArgumentsSkFontArguments43 SkFontArguments() 44 : fCollectionIndex(0) 45 , fVariationDesignPosition{nullptr, 0} 46 , 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 */ setCollectionIndexSkFontArguments53 SkFontArguments& setCollectionIndex(int collectionIndex) { 54 fCollectionIndex = collectionIndex; 55 return *this; 56 } 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 */ setVariationDesignPositionSkFontArguments65 SkFontArguments& setVariationDesignPosition(VariationPosition position) { 66 fVariationDesignPosition.coordinates = position.coordinates; 67 fVariationDesignPosition.coordinateCount = position.coordinateCount; 68 return *this; 69 } 70 getCollectionIndexSkFontArguments71 int getCollectionIndex() const { 72 return fCollectionIndex; 73 } 74 getVariationDesignPositionSkFontArguments75 VariationPosition getVariationDesignPosition() const { 76 return fVariationDesignPosition; 77 } 78 setPaletteSkFontArguments79 SkFontArguments& setPalette(Palette palette) { 80 fPalette.index = palette.index; 81 fPalette.overrides = palette.overrides; 82 fPalette.overrideCount = palette.overrideCount; 83 return *this; 84 } 85 getPaletteSkFontArguments86 Palette getPalette() const { return fPalette; } 87 88 private: 89 int fCollectionIndex; 90 VariationPosition fVariationDesignPosition; 91 Palette fPalette; 92 }; 93 94 #endif 95