1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- GooFlow.prototype.exportDiagram = function (fileName) {
-
- var width = this.$workArea.width();
- var height = this.$workArea.height();
- $('body').append('<div id="demo_export" style="position:absolute;top:0;left:0;z-index:-1;width:0px;height:0px;overflow:hidden">' +
- '<div style="color:#15428B;position:absolute;left:0;right:0;width:' + width + 'px;height:' + height + 'px;overflow:hidden;float:none;" class="GooFlow GooFlow_work"></div>' +
- '</div>');
-
- var inner = $('#demo').find('.GooFlow_work_inner');
- var divCanvas = $('#demo_export').children('div:eq(0)');
-
- inner.children('div').each(function (i) {
- var item = $(this);
- if (item.hasClass('GooFlow_item')) {
- item.clone().removeAttr('id').css('position', 'absolute').appendTo(divCanvas);
- } else if (item.hasClass('GooFlow_work_group')) {
- item.clone().removeAttr('id').css('position', 'absolute')
- .attr('xmlns', 'http://www.w3.org/1999/xhtml').appendTo(divCanvas);
- }
- });
- html2canvas(divCanvas[0], {
- allowTaint: false,
- taintTest: false,
- onrendered: function (canvas) {
-
-
- var context = canvas.getContext('2d');
- context.save();
- var strSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="1160" height="507">' +
- '<defs><style type="text/css">text{font-size:14px;line-height:1.42857143;' +
- 'font-family:"Microsoft Yahei", "Helvetica Neue", Helvetica, Hiragino Sans GB, WenQuanYi Micro Hei, Arial, sans-serif;' +
- '}</style></defs>' + window.$('<svg>').append(window.$('#draw_demo').clone()).html() + '</svg>';
- var image = null;
- if (!!window.ActiveXObject || 'ActiveXObject' in window) {
- image = document.createElement('canvas');
- canvg(image, strSvg);
- } else {
- var image = new Image();
- image.src = 'data:image/svg+xml,' + encodeURIComponent(strSvg);
- }
- var tempFunc = function () {
- context.drawImage(image, 0, 0);
-
- $('#demo_export').empty().remove();
- try {
- var blob = canvas.msToBlob();
-
- navigator.msSaveBlob(blob, 'prettyImage.png');
- } catch (e) {
-
- var a = document.createElementNS('http://www.w3.org/1999/xhtml', 'a')
- a.href = canvas.toDataURL('image/png');
- a.download = fileName + '.png';
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- }
- }
- if (image.complete || (!!window.ActiveXObject || 'ActiveXObject' in window)) {
-
- tempFunc();
- return;
- }
- image.onload = function () {
-
- tempFunc();
- };
- },
- width: width,
- height: height
- });
- }
|