Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
3d93cad0
Commit
3d93cad0
authored
Jan 17, 2016
by
hy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove all transform attribute when export SVG.
parent
11f466db
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
179 additions
and
2 deletions
+179
-2
svg.js
src/protocol/svg.js
+179
-2
No files found.
src/protocol/svg.js
View file @
3d93cad0
define
(
function
(
require
,
exports
,
module
)
{
var
data
=
require
(
'../core/data'
);
/**
* 导出svg时删除全部svg元素中的transform
* @auth Naixor
* @method removeTransform
* @param {[type]} svgDom [description]
* @return {[type]} [description]
*/
function
removeTransform
(
svgDom
)
{
function
getTransformToElement
(
target
,
source
)
{
var
matrix
;
try
{
matrix
=
source
.
getScreenCTM
().
inverse
();
}
catch
(
e
)
{
throw
new
Error
(
'Can not inverse source element
\'
ctm.'
);
}
return
matrix
.
multiply
(
target
.
getScreenCTM
());
}
function
dealWithPath
(
d
,
dealWithPattern
)
{
if
(
!
(
dealWithPattern
instanceof
Function
))
{
dealWithPattern
=
function
()
{};
}
var
strArr
=
[],
pattern
=
[],
cache
=
[];
for
(
var
i
=
0
,
l
=
d
.
length
;
i
<
l
;
i
++
)
{
switch
(
d
[
i
])
{
case
'M'
:
case
'L'
:
case
'T'
:
case
'S'
:
case
'A'
:
case
'C'
:
{
if
(
cache
.
length
)
{
pattern
.
push
(
cache
.
join
(
''
));
cache
=
[];
}
if
(
pattern
.
length
)
{
dealWithPattern
(
pattern
);
strArr
.
push
(
pattern
.
join
(
''
));
pattern
=
[];
}
pattern
.
push
(
d
[
i
]);
break
;
}
case
'Z'
:
case
'z'
:
{
pattern
.
push
(
cache
.
join
(
''
),
d
[
i
]);
dealWithPattern
(
pattern
);
strArr
.
push
(
pattern
.
join
(
''
));
cache
=
[];
pattern
=
[];
break
;
}
case
'.'
:
{
cache
.
push
(
'.'
);
break
;
}
case
'-'
:
{
if
(
cache
.
length
)
{
pattern
.
push
(
cache
.
join
(
''
),
','
);
}
cache
=
[];
cache
.
push
(
'-'
);
break
;
}
case
' '
:
case
','
:
{
pattern
.
push
(
cache
.
join
(
''
),
','
);
cache
=
[];
break
;
}
default
:
{
if
(
/
\d
/
.
test
(
d
[
i
]))
{
cache
.
push
(
d
[
i
]);
}
else
{
if
(
cache
.
length
)
{
pattern
.
push
(
cache
.
join
(
''
),
d
[
i
]);
cache
=
[];
}
}
if
(
i
+
1
===
l
)
{
if
(
cache
.
length
)
{
pattern
.
push
(
cache
.
join
(
''
));
}
dealWithPattern
(
pattern
);
strArr
.
push
(
pattern
.
join
(
''
));
cache
=
null
;
pattern
=
null
;
}
}
}
}
return
strArr
.
join
(
''
);
}
function
replaceWithNode
(
parent
,
svgNode
,
parentX
,
parentY
)
{
if
(
!
svgNode
)
{
return
;
}
parentX
=
parentX
||
0
;
parentY
=
parentY
||
0
;
if
(
svgNode
.
getAttribute
(
'transform'
))
{
var
ctm
=
getTransformToElement
(
svgNode
,
parent
);
parentX
-=
ctm
.
e
;
parentY
-=
ctm
.
f
;
svgNode
.
removeAttribute
(
'transform'
);
}
switch
(
svgNode
.
tagName
.
toLowerCase
())
{
case
'g'
:
{
break
;
}
case
'path'
:
{
var
d
=
svgNode
.
getAttribute
(
'd'
);
if
(
d
)
{
d
=
dealWithPath
(
d
,
function
(
pattern
)
{
switch
(
pattern
[
0
])
{
case
'M'
:
case
'L'
:
case
'T'
:
{
pattern
[
1
]
=
+
pattern
[
1
]
-
parentX
;
pattern
[
3
]
=
+
pattern
[
3
]
-
parentY
;
break
;
}
case
'S'
:
{
pattern
[
1
]
=
+
pattern
[
1
]
-
parentX
;
pattern
[
3
]
=
+
pattern
[
3
]
-
parentY
;
pattern
[
5
]
=
+
pattern
[
5
]
-
parentX
;
pattern
[
7
]
=
+
pattern
[
7
]
-
parentY
;
break
;
}
case
'A'
:
{
pattern
[
11
]
=
+
pattern
[
11
]
-
parentX
;
pattern
[
13
]
=
+
pattern
[
13
]
-
parentY
;
break
;
}
case
'C'
:
{
pattern
[
1
]
=
+
pattern
[
1
]
-
parentX
;
pattern
[
3
]
=
+
pattern
[
3
]
-
parentY
;
pattern
[
5
]
=
+
pattern
[
5
]
-
parentX
;
pattern
[
7
]
=
+
pattern
[
7
]
-
parentY
;
pattern
[
9
]
=
+
pattern
[
9
]
-
parentX
;
pattern
[
11
]
=
+
pattern
[
11
]
-
parentY
;
}
}
});
svgNode
.
setAttribute
(
'd'
,
d
);
svgNode
.
removeAttribute
(
'transform'
);
}
return
;
}
case
'image'
:
case
'text'
:
{
if
(
parentX
&&
parentY
)
{
var
x
=
+
svgNode
.
getAttribute
(
'x'
)
||
0
,
y
=
+
svgNode
.
getAttribute
(
'y'
)
||
0
;
svgNode
.
setAttribute
(
'x'
,
x
-
parentX
);
svgNode
.
setAttribute
(
'y'
,
y
-
parentY
);
}
svgNode
.
removeAttribute
(
'transform'
);
return
;
}
}
if
(
svgNode
.
children
)
{
for
(
var
i
=
0
,
l
=
svgNode
.
children
.
length
;
i
<
l
;
i
++
){
replaceWithNode
(
svgNode
,
svgNode
.
children
[
i
],
parentX
,
parentY
)
};
}
}
svgDom
.
style
.
display
=
'none'
;
replaceWithNode
(
null
,
svgDom
,
0
,
0
);
svgDom
.
style
.
display
=
'inline'
;
}
data
.
registerProtocol
(
'svg'
,
module
.
exports
=
{
fileDescription
:
'SVG 矢量图'
,
fileExtension
:
'.svg'
,
...
...
@@ -33,7 +209,7 @@ define(function(require, exports, module) {
svgDom
.
setAttribute
(
'width'
,
width
+
padding
*
2
|
0
);
svgDom
.
setAttribute
(
'height'
,
height
+
padding
*
2
|
0
);
svgDom
.
setAttribute
(
'style'
,
'font-family: Arial,
"Microsoft Yahei", "Heiti SC"
; '
+
'font-family: Arial,
Microsoft Yahei, Heiti SC
; '
+
'background: '
+
minder
.
getStyle
(
'background'
));
svgDom
.
setAttribute
(
'viewBox'
,
[
renderBox
.
x
-
padding
|
0
,
...
...
@@ -43,6 +219,7 @@ define(function(require, exports, module) {
].
join
(
' '
));
svgContainer
=
document
.
createElement
(
'div'
);
removeTransform
(
svgDom
);
svgContainer
.
appendChild
(
svgDom
);
// need a xml with width and height
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment