mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
39 lines
831 B
JavaScript
39 lines
831 B
JavaScript
/* @flow */
|
|
'use strict';
|
|
|
|
export type Font = {
|
|
fontFamily: string,
|
|
fontSize: string,
|
|
fontStyle: string,
|
|
fontVariant: string,
|
|
fontWeight: number
|
|
};
|
|
|
|
const parseFontWeight = (weight: string): number => {
|
|
switch (weight) {
|
|
case 'normal':
|
|
return 400;
|
|
case 'bold':
|
|
return 700;
|
|
}
|
|
|
|
const value = parseInt(weight, 10);
|
|
return isNaN(value) ? 400 : value;
|
|
};
|
|
|
|
export const parseFont = (style: CSSStyleDeclaration): Font => {
|
|
const fontFamily = style.fontFamily;
|
|
const fontSize = style.fontSize;
|
|
const fontStyle = style.fontStyle;
|
|
const fontVariant = style.fontVariant;
|
|
const fontWeight = parseFontWeight(style.fontWeight);
|
|
|
|
return {
|
|
fontFamily,
|
|
fontSize,
|
|
fontStyle,
|
|
fontVariant,
|
|
fontWeight
|
|
};
|
|
};
|