(fontValue: string)
| 167 | const weights = new Set<string>([FontWeight.THIN, FontWeight.EXTRA_LIGHT, FontWeight.LIGHT, FontWeight.NORMAL, '400', FontWeight.MEDIUM, FontWeight.SEMI_BOLD, FontWeight.BOLD, '700', FontWeight.EXTRA_BOLD, FontWeight.BLACK]); |
| 168 | |
| 169 | export function parseFont(fontValue: string): ParsedFont { |
| 170 | const result: ParsedFont = { |
| 171 | fontStyle: 'normal', |
| 172 | fontVariant: 'normal', |
| 173 | fontWeight: 'normal', |
| 174 | }; |
| 175 | |
| 176 | const parts = fontValue.split(/\s+/); |
| 177 | let part: string; |
| 178 | while ((part = parts.shift())) { |
| 179 | if (part === 'normal') { |
| 180 | // nothing to do here |
| 181 | } else if (part === 'small-caps') { |
| 182 | // The only supported font variant in shorthand font |
| 183 | result.fontVariant = part; |
| 184 | } else if (styles.has(part)) { |
| 185 | result.fontStyle = <any>part; |
| 186 | } else if (weights.has(part)) { |
| 187 | result.fontWeight = <any>part; |
| 188 | } else if (!result.fontSize) { |
| 189 | const sizes = part.split('/'); |
| 190 | result.fontSize = sizes[0]; |
| 191 | result.lineHeight = sizes.length > 1 ? sizes[1] : undefined; |
| 192 | } else { |
| 193 | result.fontFamily = part; |
| 194 | if (parts.length) { |
| 195 | result.fontFamily += ' ' + parts.join(' '); |
| 196 | } |
| 197 | break; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | return result; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Kind of hack. |
no test coverage detected