Implement strokeDasharray correctly.

Support units and percentages with whitespace separated and/or (possibly white-space surrounded) comma separated length lists.
This commit is contained in:
Mikael Sand
2017-08-04 00:26:00 +03:00
parent b38ae08e9c
commit 786b5f2375
6 changed files with 51 additions and 65 deletions

View File

@@ -2,12 +2,12 @@ import _ from 'lodash';
//noinspection JSUnresolvedVariable
import React, {Children} from 'react';
import TSpan from '../../elements/TSpan';
import extractLengthList from './extractLengthList';
const fontRegExp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?[ptexm%])*(?:\s*\/.*?)?\s+)?\s*"?([^"]*)/i;
const fontFamilyPrefix = /^[\s"']*/;
const fontFamilySuffix = /[\s"']*$/;
const spaceReg = /\s+/;
const commaReg = /,/g;
const commaReg = /\s*,\s*/g;
const cachedFontObjectsFromString = {};
@@ -85,18 +85,6 @@ export function extractFont(props) {
return _.defaults(ownedFont, font);
}
function parseSVGLengthList(delta) {
if (typeof delta === 'string') {
return delta.trim().replace(commaReg, ' ').split(spaceReg);
} else if (typeof delta === 'number') {
return [delta.toString()];
} else if (delta && typeof delta.map === 'function') {
return delta.map(d => `${d}`);
} else {
return [];
}
}
export default function(props, container) {
const {
x,
@@ -110,11 +98,11 @@ export default function(props, container) {
children
} = props;
const positionX = parseSVGLengthList(x);
const positionY = parseSVGLengthList(y);
const deltaX = parseSVGLengthList(dx);
const deltaY = parseSVGLengthList(dy);
rotate = parseSVGLengthList(rotate);
const positionX = extractLengthList(x);
const positionY = extractLengthList(y);
const deltaX = extractLengthList(dx);
const deltaY = extractLengthList(dy);
rotate = extractLengthList(rotate);
let content = null;
if (typeof children === 'string' || typeof children === 'number') {