paper.js/src/svg/SVGStyles.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
2014-01-03 19:47:16 -05:00
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
2013-04-23 10:19:08 -04:00
var SVGStyles = Base.each({
2014-08-16 13:24:54 -04:00
// Fill
fillColor: ['fill', 'color'],
fillRule: ['fill-rule', 'string'],
2014-08-16 13:24:54 -04:00
// Stroke
strokeColor: ['stroke', 'color'],
strokeWidth: ['stroke-width', 'number'],
strokeCap: ['stroke-linecap', 'string'],
strokeJoin: ['stroke-linejoin', 'string'],
strokeScaling: ['vector-effect', 'lookup', {
true: 'none',
false: 'non-scaling-stroke'
}, function(item, value) {
// no inheritance, only applies to graphical elements
return !value // false, meaning non-scaling-stroke
&& (item instanceof PathItem
|| item instanceof Shape
|| item instanceof TextItem);
}],
miterLimit: ['stroke-miterlimit', 'number'],
dashArray: ['stroke-dasharray', 'array'],
dashOffset: ['stroke-dashoffset', 'number'],
// Text
fontFamily: ['font-family', 'string'],
fontWeight: ['font-weight', 'string'],
fontSize: ['font-size', 'number'],
justification: ['text-anchor', 'lookup', {
left: 'start',
center: 'middle',
right: 'end'
}],
// Item
opacity: ['opacity', 'number'],
blendMode: ['mix-blend-mode', 'string']
2012-11-05 22:26:54 -05:00
}, function(entry, key) {
2014-08-16 13:24:54 -04:00
var part = Base.capitalize(key),
lookup = entry[2];
this[key] = {
type: entry[1],
property: key,
attribute: entry[0],
toSVG: lookup,
fromSVG: lookup && Base.each(lookup, function(value, name) {
this[value] = name;
}, {}),
exportFilter: entry[3],
get: 'get' + part,
set: 'set' + part
};
}, {});