(options: Partial<FontSpec>, fallback?: Partial<FontSpec>)
| 113 | */ |
| 114 | |
| 115 | export function toFont(options: Partial<FontSpec>, fallback?: Partial<FontSpec>) { |
| 116 | options = options || {}; |
| 117 | fallback = fallback || defaults.font as FontSpec; |
| 118 | |
| 119 | let size = valueOrDefault(options.size, fallback.size); |
| 120 | |
| 121 | if (typeof size === 'string') { |
| 122 | size = parseInt(size, 10); |
| 123 | } |
| 124 | let style = valueOrDefault(options.style, fallback.style); |
| 125 | if (style && !('' + style).match(FONT_STYLE)) { |
| 126 | console.warn('Invalid font style specified: "' + style + '"'); |
| 127 | style = undefined; |
| 128 | } |
| 129 | |
| 130 | const font = { |
| 131 | family: valueOrDefault(options.family, fallback.family), |
| 132 | lineHeight: toLineHeight(valueOrDefault(options.lineHeight, fallback.lineHeight), size), |
| 133 | size, |
| 134 | style, |
| 135 | weight: valueOrDefault(options.weight, fallback.weight), |
| 136 | string: '' |
| 137 | }; |
| 138 | |
| 139 | font.string = toFontString(font); |
| 140 | return font; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Evaluates the given `inputs` sequentially and returns the first defined value. |
no test coverage detected