| 1 | use crate::PropertyKind; |
| 2 | |
| 3 | macro_rules! define_constant { |
| 4 | ( |
| 5 | $( |
| 6 | $variant:ident = $(($ty:ident, $value:expr),)+ |
| 7 | )+ |
| 8 | ) => { |
| 9 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
| 10 | #[cfg_attr(feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
| 11 | pub enum Constant { |
| 12 | $( |
| 13 | $variant, |
| 14 | )+ |
| 15 | } |
| 16 | |
| 17 | impl Constant { |
| 18 | pub fn get_value(self, kind: PropertyKind) -> Option<u32> { |
| 19 | match (self, kind) { |
| 20 | $( |
| 21 | $( |
| 22 | (Constant::$variant, PropertyKind::$ty) => Some($value), |
| 23 | )+ |
| 24 | )+ |
| 25 | _ => None, |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | }; |
| 30 | } |
| 31 | |
| 32 | define_constant! { |
| 33 | Thin = (Weight, 0), |
| 34 | Extralight = (Weight, 40), |
| 35 | Ultralight = (Weight, 40), |
| 36 | Light = (Weight, 50), |
| 37 | Demilight = (Weight, 55), |
| 38 | Semilight = (Weight, 55), |
| 39 | Book = (Weight, 75), |
| 40 | Regular = (Weight, 80), |
| 41 | Normal = (Weight, 80), (Width, 100), |
| 42 | Medium = (Weight, 100), |
| 43 | Demibold = (Weight, 180), |
| 44 | Semibold = (Weight, 180), |
| 45 | Bold = (Weight, 200), |
| 46 | Extrabold = (Weight, 205), |
| 47 | Black = (Weight, 210), |
| 48 | Heavy = (Weight, 210), |
| 49 | Roman = (Slant, 0), |
| 50 | Italic = (Slant, 100), |
| 51 | Oblique = (Slant, 110), |
| 52 | Ultracondensed = (Width, 50), |
| 53 | Extracondensed = (Width, 63), |
| 54 | Condensed = (Width, 75), |
| 55 | Semicondensed = (Width, 87), |
| 56 | // Merged into above Normal |
| 57 | // Normal = (Width, 100), |
| 58 | Semiexpanded = (Width, 113), |
| 59 | Expanded = (Width, 125), |
| 60 | Extraexpanded = (Width, 150), |
| 61 | Ultraexpanded = (Width, 200), |
| 62 | Proportional = (Spacing, 0), |
| 63 | Dual = (Spacing, 90), |
| 64 | Mono = (Spacing, 100), |
| 65 | Charcell = (Spacing, 110), |
| 66 | Unknown = (Rgba, 0), |
| 67 | Rgb = (Rgba, 1), |
| 68 | Bgr = (Rgba, 2), |
| 69 | Vrgb = (Rgba, 3), |
| 70 | Vbgr = (Rgba, 4), |
| 71 | None = (Rgba, 5), |
| 72 | Lcdnone = (Lcdfilter, 0), |
| 73 | Lcddefault = (Lcdfilter, 1), |
| 74 | Lcdlight = (Lcdfilter, 2), |
| 75 | Lcdlegacy = (Lcdfilter, 3), |
| 76 | Hintnone = (HintStyle, 0), |
| 77 | Hintslight = (HintStyle, 1), |
| 78 | Hintmedium = (HintStyle, 2), |
| 79 | Hintfull = (HintStyle, 3), |
| 80 | } |
| 81 | |
| 82 | parse_enum! { |
| 83 | Constant, |
| 84 | (Thin, "thin" ), |
| 85 | (Extralight, "extralight" ), |
| 86 | (Ultralight, "ultralight" ), |
| 87 | (Light, "light" ), |
| 88 | (Demilight, "demilight" ), |
| 89 | (Semilight, "semilight" ), |
| 90 | (Book, "book" ), |
| 91 | (Regular, "regular" ), |
| 92 | (Normal, "normal" ), |
| 93 | (Medium, "medium" ), |
| 94 | (Demibold, "demibold" ), |
| 95 | (Semibold, "semibold" ), |
| 96 | (Bold, "bold" ), |
| 97 | (Extrabold, "extrabold" ), |
| 98 | (Black, "black" ), |
| 99 | (Heavy, "heavy" ), |
| 100 | (Roman, "roman" ), |
| 101 | (Italic, "italic" ), |
| 102 | (Oblique, "oblique" ), |
| 103 | (Ultracondensed, "ultracondensed" ), |
| 104 | (Extracondensed, "extracondensed" ), |
| 105 | (Condensed, "condensed" ), |
| 106 | (Semicondensed, "semicondensed" ), |
| 107 | (Semiexpanded, "semiexpanded" ), |
| 108 | (Expanded, "expanded" ), |
| 109 | (Extraexpanded, "extraexpanded" ), |
| 110 | (Ultraexpanded, "ultraexpanded" ), |
| 111 | (Proportional, "proportional" ), |
| 112 | (Dual, "dual" ), |
| 113 | (Mono, "mono" ), |
| 114 | (Charcell, "charcell" ), |
| 115 | (Unknown, "unknown" ), |
| 116 | (Rgb, "rgb" ), |
| 117 | (Bgr, "bgr" ), |
| 118 | (Vrgb, "vrgb" ), |
| 119 | (Vbgr, "vbgr" ), |
| 120 | (None, "none" ), |
| 121 | (Lcdnone, "lcdnone" ), |
| 122 | (Lcddefault, "lcddefault" ), |
| 123 | (Lcdlight, "lcdlight" ), |
| 124 | (Lcdlegacy, "lcdlegacy" ), |
| 125 | (Hintnone, "hintnone" ), |
| 126 | (Hintslight, "hintslight" ), |
| 127 | (Hintmedium, "hintmedium" ), |
| 128 | (Hintfull, "hintfull" ), |
| 129 | } |
| 130 | |
| 131 | #[test ] |
| 132 | fn convert_test() { |
| 133 | assert_eq!(Constant::Roman.get_value(PropertyKind::Slant).unwrap(), 0,); |
| 134 | } |
| 135 | |