2012-08-10 15:14:56 +00:00
( function ( ) {
function makeElement ( ) {
var element = fabric . document . createElement ( 'path' ) ;
var attributes = {
'cx' : 101 ,
'x' : 102 ,
'cy' : 103 ,
'y' : 104 ,
'r' : 105 ,
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
'opacity' : 0.45 ,
2012-08-10 15:14:56 +00:00
'fill-rule' : 'foo' ,
'stroke-width' : 4
} ;
for ( var prop in attributes ) {
element . setAttribute ( prop , attributes [ prop ] ) ;
}
return element ;
}
2015-04-23 09:47:23 +00:00
// var EXPECTED_PATH_JSON = "{\"type\":\"path\",\"left\":0,\"top\":0,\"width\":93,\"height\":137,\"fill\":\"#99CCFF\",\"stroke\":null,\"strokeWidth\":1,\"scaleX\":1,\"scaleY\":1,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"selectable\":true,\"hasControls\":true,\"hasBorders\":true,\"hasRotatingPoint\":false,\"path\":[[\"M\",62.022,30.848],[\"c\",4.251,0.038,9.565,-2.206,13.424,-3.924],[\"c\",3.131,-1.396,4.47,-1.299,7.833,0.263],[\"c\",2.18,1.012,3.883,-1.551,5.824,-2.048],[\"c\",0.243,-0.062,0.537,0.464,0.374,0.652],[\"c\",-0.553,0.639,-2.932,1.753,-2.679,2.821],[\"c\",0.184,0.779,4.081,0.817,5.226,1.347],[\"c\",1.008,0.653,-3.22,0.665,-3.17,1.028],[\"c\",1.038,0.191,2.175,0.279,3.03,0.703],[\"c\",0.482,0.238,-0.707,0.815,-1.245,0.731],[\"c\",0.194,0.103,0.711,0.257,0.583,0.436],[\"c\",-0.144,0.891,-3.265,0.128,-4.132,-0.003],[\"c\",-0.688,-0.104,-3.754,-0.843,-3.892,0.039],[\"c\",-0.092,0.586,0.47,1.079,0.133,2.617],[\"c\",-0.314,1.438,-1.942,1.633,-1.831,1.024],[\"c\",0.273,-1.496,1.201,-1.914,-0.4,-3.564],[\"c\",-0.979,-1.01,-1.908,-2.344,-2.138,-3.425],[\"c\",-7.581,1.092,-9.456,6.321,-17.365,7.858],[\"c\",-2.787,0.541,-5.233,-1.016,-7.887,-2.27],[\"c\",0.168,0.259,0.457,0.272,0.169,1.184],[\"c\",-0.29,0.918,-0.479,2.081,-0.225,3.104],[\"c\",0.539,2.169,1.73,4.464,2.5,6.755],[\"c\",1.481,4.415,0.996,11.273,0.42,15.21],[\"c\",-0.105,0.715,0.497,1.432,0.129,2.608],[\"c\",-0.128,0.413,0.384,1.027,0.347,1.458],[\"c\",-0.195,2.236,1.106,2.01,3.446,4.502],[\"c\",-0.21,0.252,-0.926,0.504,-1.136,0.756],[\"c\",4.353,5.205,8.404,10.612,11.622,16.651],[\"c\",0.805,1.512,1.511,3.199,1.511,4.913],[\"c\",0,1.955,-1.154,2.843,-2.057,4.577],[\"c\",-0.741,1.423,-2.081,2.305,-3.121,3.526],[\"c\",-5.631,6.614,-9.57,11.287,-15.186,17.936],[\"c\",-0.976,3.091,1.141,4.783,1.093,6.394],[\"c\",-0.011,0.372,-0.267,0.74,-0.555,1.119],[\"c\",-0.452,0.595,-2.752,-1.225,-4.01,-2.617],[\"c\",-1.657,8.48,5.22,10.332,8.284,12.274],[\"c\",0.37,0.234,0.076,1.004,-0.05,1.424],[\"c\",-4.442,0.217,-7.603,0.246,-11.857,-1.172],[\"c\",-0.783,-0.963,-2.958,-5.188,-4.535,-3.406],[\"c\",-0.735,0.831,-1.092,1.932,-1.637,2.897],[\"c\",-0.462,0,-0.76,-0.247,-1.222,-0.247],[\"c\",-0.042,-1.553,0.19,-2.878,-0.044,-4.413],[\"c\",-0.633,-4.152,-1.551,-4.467,2.037,-7.866],[\"c\",1.782,-1.689,2.374,-2.065,4.045,-3.916],[\"c\",-0.552,-1.562,0.385,-2.303,-1.192,-3],[\"c\",-0.936,-0.041,-3.255,1.205,-3.535,2.152],[\"c\",-0.378,-0.042,-1.001,-0.701,-1.379,-0.742],[\"c\",0.896,-1.794,1.155,-1.791,0.926,-2.913],[\"c\",-0.796,-3.892,1.304,-4.478,3.593,-5.779],[\"c\",3.523,-3.523,6.666,-10.464,10.145,-14.605],[\"c\",1.05,-1.25,2.885,-2.043,4.019,-3.219],[\"c\",-1.26,-1.175,-2.805,-2.106,-3.779,-3.526],[\"c\",-2.437,-3.554,-6.445,-7.633,-9.421,-8.945],[\"c\",-0.756,0.168,-1.513,0.336,-2.269,0.504],[\"c\",-3.89,-2.843,-8.766,-8.817,-6.814,-16.892],[\"c\",1.413,-5.846,8.545,-7.913,2.791,-13.009],[\"c\",-1.299,-1.15,-7.22,-6.915,-8.904,-6.021],[\"c\",-1.257,0.667,-3.774,2.431,-3.966,4.015],[\"c\",-0.299,2.472,-4.275,17.925,-7.829,14.167],[\"C\",9.169,53.682,7.55,47.517,6.059,43.276],[\"c\",-0.873,-2.481,-4.009,-2.109,-5.077,-5],[\"c\",-0.368,-0.997,-1.229,-2.067,-0.914,-3.082],[\"c\",0.169,-0.545,0.63,-0.336,1.175,-0.504],[\"c\",0.535,-2.002,0.199,-1.216,1.704,-1.318],[\"c\",0,-1.215,0.604,-0.978,1.498,-0.978],[\"c\",0.987,-1.624,1.841,-0.106,4.696,1.74],[\"c\",1.461,0.945,1.292,2.708,0.987,4.319],[\"c\",-0.281,1.483,-0.582,2.403,-0.018,3.626],[\"c\",1.14,2.472,4.709,6.794,6.412,9.063],[\"c\",2.12,-2.974,1.531,-6.198,1.788,-10.647],[\"c\",0.1,-1.729,0.84,-3.361,1.26,-5.041],[\"c\",-1.504,-0.111,-2.596,-0.532,-3.277,-1.261],[\"c\",0.336,-0.588,0.672,-1.177,1.008,-1.765],[\"c\",-1.64,-1.64,-1.834,-2.188,-2.325,-4.48],[\"c\",3.162,0,2.708,-1.862,4.342,-4.09],[\"c\",-0.84,-0.504,-1.681,-1.008,-2.521,-1.512],[\"c\",3.833,-2.869,3.828,-2.76,2.539,-8.066],[\"c\",-0.877,-3.608,-0.278,-6.225,2.058,-9.733],[\"C\",25.57,-1.726,27.022,0.327,31.783,0.3],[\"c\",3.464,-0.021,6.667,0.022,8.97,5.944],[\"c\",-0.462,-0.248,-1.416,-0.428,-1.878,-0.126],[\"c\",0.126,0.588,0.825,2.
2012-08-10 15:14:56 +00:00
QUnit . module ( 'fabric.Parser' ) ;
test ( 'parseAttributes' , function ( ) {
ok ( fabric . parseAttributes ) ;
var element = makeElement ( ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
var attributeNames = 'cx cy x y r opacity fill-rule stroke-width transform fill fill-rule' . split ( ' ' ) ;
2012-08-10 15:14:56 +00:00
var parsedAttributes = fabric . parseAttributes ( element , attributeNames ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( parsedAttributes , {
2012-08-10 15:14:56 +00:00
left : 102 ,
top : 104 ,
radius : 105 ,
opacity : 0.45 ,
fillRule : 'foo' ,
strokeWidth : 4
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
} ) ;
2012-08-10 15:14:56 +00:00
} ) ;
test ( 'parseAttributesNoneValues' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
element . setAttribute ( 'fill' , 'none' ) ;
element . setAttribute ( 'stroke' , 'none' ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( fabric . parseAttributes ( element , 'fill stroke' . split ( ' ' ) ) , { fill : '' , stroke : '' } ) ;
2012-08-10 15:14:56 +00:00
} ) ;
test ( 'parseAttributesFillRule' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
element . setAttribute ( 'fill-rule' , 'evenodd' ) ;
2014-09-21 18:55:00 +00:00
deepEqual ( fabric . parseAttributes ( element , [ 'fill-rule' ] ) , { fillRule : 'evenodd' } ) ;
2012-08-10 15:14:56 +00:00
} ) ;
test ( 'parseAttributesFillRuleWithoutTransformation' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
element . setAttribute ( 'fill-rule' , 'inherit' ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( fabric . parseAttributes ( element , [ 'fill-rule' ] ) , { fillRule : 'inherit' } ) ;
2012-08-10 15:14:56 +00:00
} ) ;
test ( 'parseAttributesTransform' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
element . setAttribute ( 'transform' , 'translate(5, 10)' ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( fabric . parseAttributes ( element , [ 'transform' ] ) , { transformMatrix : [ 1 , 0 , 0 , 1 , 5 , 10 ] } ) ;
2012-08-10 15:14:56 +00:00
} ) ;
test ( 'parseAttributesWithParent' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
var parent = fabric . document . createElement ( 'g' ) ;
var grandParent = fabric . document . createElement ( 'g' ) ;
parent . appendChild ( element ) ;
grandParent . appendChild ( parent ) ;
element . setAttribute ( 'x' , '100' ) ;
parent . setAttribute ( 'y' , '200' ) ;
grandParent . setAttribute ( 'fill' , 'red' ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( fabric . parseAttributes ( element , 'x y fill' . split ( ' ' ) ) ,
{ fill : 'red' , left : 100 , top : 200 } ) ;
2012-08-10 15:14:56 +00:00
} ) ;
2015-06-26 10:33:10 +00:00
test ( 'parseAttributesWithGrandParentSvg' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ,
parent = fabric . document . createElement ( 'g' ) ,
grandParent = fabric . document . createElement ( 'svg' ) ;
parent . appendChild ( element ) ;
grandParent . appendChild ( parent ) ;
element . setAttribute ( 'x' , '100' ) ;
parent . setAttribute ( 'y' , '200' ) ;
grandParent . setAttribute ( 'width' , '600' ) ;
grandParent . setAttribute ( 'height' , '600' ) ;
2015-07-15 15:05:34 +00:00
deepEqual ( fabric . parseAttributes ( element , 'x y width height' . split ( ' ' ) ) ,
2015-06-26 10:33:10 +00:00
{ left : 100 , top : 200 , width : 600 , height : 600 } ) ;
} ) ;
2012-08-10 15:14:56 +00:00
asyncTest ( 'parseElements' , function ( ) {
ok ( fabric . parseElements ) ;
function getOptions ( options ) {
return fabric . util . object . extend ( fabric . util . object . clone ( {
left : 10 , top : 20 , width : 30 , height : 40
} ) , options || { } ) ;
}
var elements = [
fabric . util . makeElement ( 'rect' , getOptions ( ) ) ,
fabric . util . makeElement ( 'circle' , getOptions ( { r : 14 } ) ) ,
fabric . util . makeElement ( 'path' , getOptions ( { d : 'M 100 100 L 300 100 L 200 300 z' } ) ) ,
fabric . util . makeElement ( 'inexistent' , getOptions ( ) )
] ;
var parsedElements , error ;
try {
fabric . parseElements ( elements , function ( instances ) {
parsedElements = instances ;
} ) ;
}
catch ( err ) {
error = err ;
}
ok ( error === undefined , 'No error is raised' ) ;
setTimeout ( function ( ) {
if ( parsedElements ) {
ok ( parsedElements [ 0 ] instanceof fabric . Rect ) ;
ok ( parsedElements [ 1 ] instanceof fabric . Circle ) ;
ok ( parsedElements [ 2 ] instanceof fabric . Path ) ;
}
start ( ) ;
} , 1000 ) ;
} ) ;
test ( 'parseStyleAttribute' , function ( ) {
ok ( fabric . parseStyleAttribute ) ;
var element = fabric . document . createElement ( 'path' ) ;
element . setAttribute ( 'style' , 'left:10px;top:22.3em;width:103.45pt;height:20%;' ) ;
2014-10-21 20:50:34 +00:00
var styleObj = fabric . parseStyleAttribute ( element ) ;
// TODO: looks like this still fails with % values
2012-08-10 15:14:56 +00:00
var expectedObject = {
2012-12-23 14:28:08 +00:00
'left' : 10 ,
2014-10-21 20:50:34 +00:00
'top' : 356.8 ,
2014-07-18 11:11:18 +00:00
'width' : 137.93333333333334 ,
2012-12-23 14:28:08 +00:00
'height' : 20
2012-08-10 15:14:56 +00:00
} ;
2014-10-21 20:50:34 +00:00
deepEqual ( styleObj , expectedObject ) ;
2012-08-10 15:14:56 +00:00
} ) ;
test ( 'parseStyleAttribute with one pair' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
element . setAttribute ( 'style' , 'left:10px' ) ;
var expectedObject = {
2012-12-23 14:28:08 +00:00
'left' : 10
2012-08-10 15:14:56 +00:00
} ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( fabric . parseStyleAttribute ( element ) , expectedObject ) ;
2012-08-10 15:14:56 +00:00
} ) ;
2015-06-02 21:05:54 +00:00
test ( 'parseStyleAttribute with trailing spaces' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
element . setAttribute ( 'style' , 'left:10px; top:5px; ' ) ;
var expectedObject = {
'left' : 10 ,
'top' : 5
} ;
deepEqual ( fabric . parseStyleAttribute ( element ) , expectedObject ) ;
} ) ;
2013-05-01 06:58:52 +00:00
test ( 'parseStyleAttribute with value normalization' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
2014-09-26 12:03:11 +00:00
element . setAttribute ( 'style' , 'fill:none; stroke-dasharray: 2 0.4;' ) ;
2013-05-01 06:58:52 +00:00
var expectedObject = {
2014-09-26 12:03:11 +00:00
'fill' : '' ,
'strokeDashArray' : [ 2 , 0.4 ]
2013-05-01 06:58:52 +00:00
} ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( fabric . parseStyleAttribute ( element ) , expectedObject ) ;
2013-05-01 06:58:52 +00:00
} ) ;
2013-05-12 17:01:23 +00:00
test ( 'parseStyleAttribute with short font declaration' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
element . setAttribute ( 'style' , 'font: italic 12px Arial,Helvetica,sans-serif' ) ;
2014-10-21 20:50:34 +00:00
var styleObj = fabric . parseStyleAttribute ( element ) ;
if ( styleObj . font ) {
fabric . parseFontDeclaration ( styleObj . font , styleObj ) ;
}
2013-05-12 17:01:23 +00:00
var expectedObject = {
2014-10-21 20:50:34 +00:00
'font' : 'italic 12px Arial,Helvetica,sans-serif' ,
2013-05-12 17:01:23 +00:00
'fontSize' : 12 ,
'fontStyle' : 'italic' ,
'fontFamily' : 'Arial,Helvetica,sans-serif'
} ;
2015-04-23 09:47:23 +00:00
2014-10-21 20:50:34 +00:00
deepEqual ( styleObj , expectedObject ) ;
//testing different unit
element . setAttribute ( 'style' , 'font: italic 1.5em Arial,Helvetica,sans-serif' ) ;
2015-04-23 09:47:23 +00:00
styleObj = fabric . parseStyleAttribute ( element ) ;
2014-10-21 20:50:34 +00:00
if ( styleObj . font ) {
fabric . parseFontDeclaration ( styleObj . font , styleObj ) ;
}
2015-04-23 09:47:23 +00:00
expectedObject = {
2014-10-21 20:50:34 +00:00
'font' : 'italic 1.5em Arial,Helvetica,sans-serif' ,
'fontSize' : 24 ,
'fontStyle' : 'italic' ,
'fontFamily' : 'Arial,Helvetica,sans-serif'
} ;
2015-04-23 09:47:23 +00:00
2014-10-21 20:50:34 +00:00
deepEqual ( styleObj , expectedObject ) ;
2013-05-12 17:01:23 +00:00
} ) ;
2012-08-10 15:14:56 +00:00
test ( 'parseAttributes (style to have higher priority than attribute)' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
element . setAttribute ( 'style' , 'fill:red' ) ;
element . setAttribute ( 'fill' , 'green' ) ;
var expectedObject = {
'fill' : 'red'
} ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( fabric . parseAttributes ( element , fabric . Path . ATTRIBUTE _NAMES ) , expectedObject ) ;
} ) ;
test ( 'parseAttributes stroke-opacity and fill-opacity' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
element . setAttribute ( 'style' , 'fill:rgb(100,200,50);fill-opacity:0.2;' ) ;
element . setAttribute ( 'stroke' , 'green' ) ;
element . setAttribute ( 'stroke-opacity' , '0.5' ) ;
element . setAttribute ( 'fill' , 'green' ) ;
var expectedObject = {
'fill' : 'rgba(100,200,50,0.2)' ,
2014-07-21 04:48:49 +00:00
'stroke' : 'rgba(0,128,0,0.5)' ,
'fillOpacity' : 0.2 ,
'strokeOpacity' : 0.5
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
} ;
deepEqual ( fabric . parseAttributes ( element , fabric . Path . ATTRIBUTE _NAMES ) , expectedObject ) ;
2012-08-10 15:14:56 +00:00
} ) ;
test ( 'parsePointsAttribute' , function ( ) {
ok ( fabric . parsePointsAttribute ) ;
var element = fabric . document . createElement ( 'polygon' ) ;
2014-07-14 14:57:14 +00:00
element . setAttribute ( 'points' , '10, 12 20 ,22, -0.52,0.001 2.3e2,2.3e-2, 10,-1 ' ) ;
2012-08-10 15:14:56 +00:00
var actualPoints = fabric . parsePointsAttribute ( element . getAttribute ( 'points' ) ) ;
equal ( actualPoints [ 0 ] . x , 10 ) ;
equal ( actualPoints [ 0 ] . y , 12 ) ;
equal ( actualPoints [ 1 ] . x , 20 ) ;
equal ( actualPoints [ 1 ] . y , 22 ) ;
equal ( actualPoints [ 2 ] . x , - 0.52 ) ;
equal ( actualPoints [ 2 ] . y , 0.001 ) ;
equal ( actualPoints [ 3 ] . x , 2.3 e2 ) ;
equal ( actualPoints [ 3 ] . y , 2.3 e - 2 ) ;
equal ( actualPoints [ 4 ] . x , 10 ) ;
equal ( actualPoints [ 4 ] . y , - 1 ) ;
} ) ;
test ( 'parseTransformAttribute' , function ( ) {
2015-04-23 09:47:23 +00:00
var parsedValue ;
2012-08-10 15:14:56 +00:00
ok ( fabric . parseTransformAttribute ) ;
var element = fabric . document . createElement ( 'path' ) ;
//'translate(-10,-20) scale(2) rotate(45) translate(5,10)'
element . setAttribute ( 'transform' , 'translate(5,10)' ) ;
2015-04-23 09:47:23 +00:00
parsedValue = fabric . parseTransformAttribute ( element . getAttribute ( 'transform' ) ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( parsedValue , [ 1 , 0 , 0 , 1 , 5 , 10 ] ) ;
2012-08-10 15:14:56 +00:00
element . setAttribute ( 'transform' , 'translate(-10,-20)' ) ;
2015-04-23 09:47:23 +00:00
parsedValue = fabric . parseTransformAttribute ( element . getAttribute ( 'transform' ) ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( parsedValue , [ 1 , 0 , 0 , 1 , - 10 , - 20 ] ) ;
2012-08-10 15:14:56 +00:00
2014-05-08 18:53:00 +00:00
var ANGLE _DEG = 90 ;
var ANGLE = ANGLE _DEG * Math . PI / 180 ;
element . setAttribute ( 'transform' , 'rotate(' + ANGLE _DEG + ')' ) ;
2015-04-23 09:47:23 +00:00
parsedValue = fabric . parseTransformAttribute ( element . getAttribute ( 'transform' ) ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( parsedValue , [ Math . cos ( ANGLE ) , Math . sin ( ANGLE ) , - Math . sin ( ANGLE ) , Math . cos ( ANGLE ) , 0 , 0 ] ) ;
2012-08-10 15:14:56 +00:00
element . setAttribute ( 'transform' , 'scale(3.5)' ) ;
2015-04-23 09:47:23 +00:00
parsedValue = fabric . parseTransformAttribute ( element . getAttribute ( 'transform' ) ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( parsedValue , [ 3.5 , 0 , 0 , 3.5 , 0 , 0 ] ) ;
2012-08-10 15:14:56 +00:00
element . setAttribute ( 'transform' , 'scale(2 13)' ) ;
2015-04-23 09:47:23 +00:00
parsedValue = fabric . parseTransformAttribute ( element . getAttribute ( 'transform' ) ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( parsedValue , [ 2 , 0 , 0 , 13 , 0 , 0 ] ) ;
2012-08-10 15:14:56 +00:00
element . setAttribute ( 'transform' , 'skewX(2)' ) ;
2015-04-23 09:47:23 +00:00
parsedValue = fabric . parseTransformAttribute ( element . getAttribute ( 'transform' ) ) ;
2014-10-07 08:58:44 +00:00
deepEqual ( parsedValue , [ 1 , 0 , 0.03492076949174773 , 1 , 0 , 0 ] ) ;
2012-08-10 15:14:56 +00:00
element . setAttribute ( 'transform' , 'skewY(234.111)' ) ;
2015-04-23 09:47:23 +00:00
parsedValue = fabric . parseTransformAttribute ( element . getAttribute ( 'transform' ) ) ;
2014-10-07 08:58:44 +00:00
deepEqual ( parsedValue , [ 1 , 1.3820043381762832 , 0 , 1 , 0 , 0 ] ) ;
2012-08-10 15:14:56 +00:00
element . setAttribute ( 'transform' , 'matrix(1,2,3,4,5,6)' ) ;
2015-04-23 09:47:23 +00:00
parsedValue = fabric . parseTransformAttribute ( element . getAttribute ( 'transform' ) ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( parsedValue , [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
2012-08-10 15:14:56 +00:00
2013-05-01 06:58:52 +00:00
element . setAttribute ( 'transform' , 'translate(21,31) translate(11,22)' ) ;
2015-04-23 09:47:23 +00:00
parsedValue = fabric . parseTransformAttribute ( element . getAttribute ( 'transform' ) ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
deepEqual ( parsedValue , [ 1 , 0 , 0 , 1 , 32 , 53 ] ) ;
2012-08-10 15:14:56 +00:00
2013-05-01 06:58:52 +00:00
element . setAttribute ( 'transform' , 'scale(2 13) translate(5,15) skewX(11.22)' ) ;
2015-04-23 09:47:23 +00:00
parsedValue = fabric . parseTransformAttribute ( element . getAttribute ( 'transform' ) ) ;
2014-10-07 08:58:44 +00:00
deepEqual ( parsedValue , [ 2 , 0 , 0.3967362169237356 , 13 , 10 , 195 ] ) ;
2012-08-10 15:14:56 +00:00
} ) ;
2013-06-13 21:10:27 +00:00
test ( 'parseNestedTransformAttribute' , function ( ) {
var element = fabric . document . createElement ( 'path' ) ;
var parent = fabric . document . createElement ( 'g' ) ;
parent . appendChild ( element ) ;
parent . setAttribute ( 'transform' , 'translate(50)' ) ;
element . setAttribute ( 'transform' , 'translate(10 10)' ) ;
var parsedAttributes = fabric . parseAttributes ( element , [ 'transform' ] ) ;
deepEqual ( parsedAttributes . transformMatrix , [ 1 , 0 , 0 , 1 , 60 , 10 ] ) ;
} ) ;
2015-08-10 22:39:50 +00:00
asyncTest ( 'parseSVGFromString id polyfill' , function ( ) {
var string = '<?xml version="1.0" standalone="no"?><svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
'<defs><rect id="myrect" width="300" height="100" style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)"/></defs>' +
'<use xlink:href="#myrect" x="50" y="50" ></use>' +
'</svg>' ,
rect ;
ok ( fabric . loadSVGFromString ) ;
fabric . loadSVGFromString ( string , function ( objects ) {
rect = objects [ 0 ] ;
} ) ;
setTimeout ( function ( ) {
ok ( rect instanceof fabric . Rect ) ;
start ( ) ;
} , 1000 ) ;
} ) ;
2012-08-10 15:14:56 +00:00
// asyncTest('parseSVGDocument', function() {
// ok(fabric.parseSVGDocument);
// var data;
// fabric.util.request('../fixtures/path.svg', {
// method: 'get',
// onComplete: function(resp) {
// var doc = resp.responseXML;
// if (!doc || !doc.documentElement) {
// //IE can't parse XML with a DOCTYPE...
// doc = new ActiveXObject('Microsoft.XMLDOM');
// doc.async = 'false';
// //IE chokes on DOCTYPE
// doc.loadXML(resp.responseText.replace(/<!DOCTYPE[\s\S]*?(\[[\s\S]*\])*?>/i,''));
// }
// fabric.parseSVGDocument(doc.documentElement, function() {
// data = arguments[0];
// });
// }
// });
// setTimeout(function() {
// equal(typeof data, 'object');
// if (data) {
// equal(data.length, 1);
// var path = data[0];
// ok(path instanceof fabric.Path);
// equal(JSON.stringify(path), EXPECTED_PATH_JSON);
// }
// start();
// }, 1500);
// });
// https://github.com/kangax/fabric.js/issues/25
// asyncTest('parsing one element should not "leak" its "fill" value onto parsing of following element', function() {
// var objects;
// fabric.util.request('../fixtures/svg_with_rect.svg', {
// method: 'get',
// onComplete: function(resp) {
// var doc = resp.responseXML;
// if (!doc || !doc.documentElement) return;
// fabric.parseSVGDocument(doc.documentElement, function() {
// objects = arguments[0];
// });
// }
// });
// setTimeout(function() {
// if (objects) {
// equal(objects[1].fill, 'green');
// }
// start();
// }, 1500);
// });
test ( 'opacity attribute' , function ( ) {
var tagNames = [ 'rect' , 'path' , 'circle' , 'ellipse' , 'polygon' ] ;
for ( var i = tagNames . length ; i -- ; ) {
var el = fabric . document . createElement ( tagNames [ i ] ) ;
var opacityValue = Math . random ( ) . toFixed ( 2 ) ;
el . setAttribute ( 'opacity' , opacityValue ) ;
var obj = fabric . Rect . fromElement ( el ) ;
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
equal ( obj . opacity , parseFloat ( opacityValue ) ,
2012-08-10 15:14:56 +00:00
'opacity should be parsed correctly from "opacity" attribute of ' + tagNames [ i ] + ' element' ) ;
}
} ) ;
2015-04-23 09:47:23 +00:00
2015-12-22 00:34:45 +00:00
test ( 'fill-opacity attribute with fill attribute' , function ( ) {
2015-12-24 16:22:00 +00:00
var el = fabric . document . createElement ( 'rect' ) ;
2015-12-22 00:34:45 +00:00
var opacityValue = Math . random ( ) . toFixed ( 2 ) ;
el . setAttribute ( 'fill-opacity' , opacityValue ) ;
el . setAttribute ( 'fill' , '#FF0000' ) ;
var obj = fabric . Rect . fromElement ( el ) ;
2015-12-26 13:11:10 +00:00
equal ( obj . fill , 'rgba(255,0,0,' + parseFloat ( opacityValue ) + ')' ,
2015-12-24 16:22:00 +00:00
'opacity should be parsed correctly from "opacity" attribute of rect element' ) ;
2015-12-22 00:34:45 +00:00
} ) ;
test ( 'fill-opacity attribute without fill attribute' , function ( ) {
2015-12-24 16:22:00 +00:00
var el = fabric . document . createElement ( 'rect' ) ;
2015-12-22 00:34:45 +00:00
var opacityValue = Math . random ( ) . toFixed ( 2 ) ;
el . setAttribute ( 'fill-opacity' , opacityValue ) ;
var obj = fabric . Rect . fromElement ( el ) ;
2015-12-26 13:11:10 +00:00
equal ( obj . fill , 'rgba(0,0,0,' + parseFloat ( opacityValue ) + ')' ,
2015-12-24 16:22:00 +00:00
'opacity should be parsed correctly from "opacity" attribute of rect element' ) ;
2015-12-22 00:34:45 +00:00
} ) ;
2016-04-12 23:44:15 +00:00
test ( 'fill-opacity attribute with fill none' , function ( ) {
2015-12-24 16:22:00 +00:00
var el = fabric . document . createElement ( 'rect' ) ;
2015-12-22 00:34:45 +00:00
var opacityValue = Math . random ( ) . toFixed ( 2 ) ;
el . setAttribute ( 'fill-opacity' , opacityValue ) ;
2016-04-12 23:44:15 +00:00
el . setAttribute ( 'fill' , 'none' ) ;
2015-12-22 00:34:45 +00:00
var obj = fabric . Rect . fromElement ( el ) ;
2016-04-12 23:44:15 +00:00
equal ( obj . fill , '' , 'fill should stay empty' ) ;
2015-12-22 00:34:45 +00:00
} ) ;
2016-04-12 23:44:15 +00:00
test ( 'stroke-opacity attribute with stroke attribute' , function ( ) {
2015-12-24 16:22:00 +00:00
var el = fabric . document . createElement ( 'rect' ) ;
2015-12-22 00:34:45 +00:00
var opacityValue = Math . random ( ) . toFixed ( 2 ) ;
2016-04-12 23:44:15 +00:00
el . setAttribute ( 'stroke-opacity' , opacityValue ) ;
el . setAttribute ( 'stroke' , '#FF0000' ) ;
2015-12-22 00:34:45 +00:00
var obj = fabric . Rect . fromElement ( el ) ;
2016-04-12 23:44:15 +00:00
equal ( obj . stroke , 'rgba(255,0,0,' + parseFloat ( opacityValue ) + ')' ,
2015-12-24 16:22:00 +00:00
'opacity should be parsed correctly from "opacity" attribute of rect element' ) ;
2015-12-22 00:34:45 +00:00
} ) ;
2016-04-12 23:44:15 +00:00
test ( 'stroke-opacity attribute without stroke attribute' , function ( ) {
var el = fabric . document . createElement ( 'rect' ) ;
var opacityValue = Math . random ( ) . toFixed ( 2 ) ;
el . setAttribute ( 'stroke-opacity' , opacityValue ) ;
var obj = fabric . Rect . fromElement ( el ) ;
equal ( obj . stroke , null , 'Default stroke is null' ) ;
} ) ;
test ( 'stroke-opacity attribute with stroke none' , function ( ) {
var el = fabric . document . createElement ( 'rect' ) ;
var opacityValue = Math . random ( ) . toFixed ( 2 ) ;
el . setAttribute ( 'stroke-opacity' , opacityValue ) ;
el . setAttribute ( 'stroke' , 'none' ) ;
var obj = fabric . Rect . fromElement ( el ) ;
equal ( obj . stroke , '' , 'stroke should stay empty' ) ;
} ) ;
2014-07-26 17:19:59 +00:00
test ( 'getCssRule' , function ( ) {
ok ( fabric . getCSSRules ) ;
var doc = fabric . document ,
2015-04-23 09:47:23 +00:00
svgUid = 'uniqueId' ,
2014-07-26 17:19:59 +00:00
styleElement = doc . createElement ( 'style' ) ;
2015-04-23 09:47:23 +00:00
styleElement . textContent = ' g polygon . cls , rect { fill : # FF0000 ; stroke : # 000000 ; stroke - width : 0.25 px ; } \
polygon . cls { fill : none ; stroke : # 0000 FF ; } ' ;
doc . body . appendChild ( styleElement ) ;
2014-07-26 17:19:59 +00:00
var expectedObject = {
'g polygon.cls' : {
'fill' : '#FF0000' ,
'stroke' : '#000000' ,
'strokeWidth' : 0.25
} ,
'rect' : {
'fill' : '#FF0000' ,
'stroke' : '#000000' ,
'strokeWidth' : 0.25
} ,
'polygon.cls' : {
'fill' : '' ,
'stroke' : '#0000FF'
}
2014-09-26 14:12:06 +00:00
} ;
2014-07-26 17:19:59 +00:00
2014-09-20 23:16:59 +00:00
fabric . cssRules [ svgUid ] = fabric . getCSSRules ( doc ) ;
deepEqual ( fabric . cssRules [ svgUid ] , expectedObject ) ;
2015-04-23 09:47:23 +00:00
2014-07-26 17:19:59 +00:00
var elPolygon = fabric . document . createElement ( 'polygon' ) ,
expectedStyle = {
'fill' : '' ,
'stroke' : '#0000FF'
} ;
elPolygon . setAttribute ( 'points' , '10,12 20,22' ) ;
elPolygon . setAttribute ( 'class' , 'cls' ) ;
2014-09-20 23:16:59 +00:00
elPolygon . setAttribute ( 'svgUid' , svgUid ) ;
2014-07-26 17:19:59 +00:00
var style = fabric . parseAttributes ( elPolygon , [ ] ) ;
deepEqual ( style , expectedStyle ) ;
2015-04-23 09:47:23 +00:00
2014-09-26 14:12:06 +00:00
styleElement . textContent = '\t\n' ;
2015-04-23 09:47:23 +00:00
expectedStyle = { } ;
2014-09-26 14:12:06 +00:00
svgUid = 'uniqueId2' ;
fabric . cssRules [ svgUid ] = fabric . getCSSRules ( doc ) ;
deepEqual ( fabric . cssRules [ svgUid ] , expectedStyle ) ;
2014-07-26 17:19:59 +00:00
} ) ;
2012-08-10 15:14:56 +00:00
2013-05-01 06:58:52 +00:00
} ) ( ) ;