Restructure fontSize handling.

This commit is contained in:
Mikael Sand
2017-07-22 21:59:13 +03:00
parent 6b022ac861
commit ed9c0bd647
4 changed files with 160 additions and 155 deletions
+6 -7
View File
@@ -2,7 +2,7 @@ import _ from 'lodash';
import React, {Children} from 'react';
import TSpan from '../../elements/TSpan';
const fontRegExp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?)[ptexm%]*(?:\s*\/.*?)?\s+)?\s*"?([^"]*)/i;
const fontRegExp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?[ptexm%])*(?:\s*\/.*?)?\s+)?\s*"?([^"]*)/i;
const fontFamilyPrefix = /^[\s"']*/;
const fontFamilySuffix = /[\s"']*$/;
const spaceReg = /\s+/;
@@ -42,12 +42,12 @@ function parseFontString(font) {
return null;
}
let fontFamily = extractSingleFontFamily(match[3]);
let fontSize = +match[2] || 12;
let fontSize = match[2] || "12";
let isBold = /bold/.exec(match[1]);
let isItalic = /italic/.exec(match[1]);
cachedFontObjectsFromString[font] = {
fontFamily: fontFamily,
fontSize: fontSize,
fontSize,
fontFamily,
fontWeight: isBold ? 'bold' : 'normal',
fontStyle: isItalic ? 'italic' : 'normal'
};
@@ -56,15 +56,14 @@ function parseFontString(font) {
export function extractFont(props) {
let font = props.font;
let fontSize = +props.fontSize;
let ownedFont = {
fontFamily: extractSingleFontFamily(props.fontFamily),
fontSize: isNaN(fontSize) ? null : fontSize,
letterSpacing: props.letterSpacing,
fontWeight: props.fontWeight,
fontStyle: props.fontStyle,
fontSize: props.fontSize,
kerning: props.kerning,
letterSpacing: props.letterSpacing,
};
if (typeof props.font === 'string') {