@@ -1838,8 +1838,9 @@ CompositeArray.remove = {
18381838 var self = this ;
18391839
18401840 for ( var i = 0 , len = data . length ; i < len ; i ++ ) {
1841- if ( this . data . indexOf ( data [ i ] ) !== - 1 ) {
1842- this . data . splice ( this . data . indexOf ( data [ i ] ) , 1 ) ;
1841+ var index_ = this . data . indexOf ( data [ i ] ) ;
1842+ if ( index_ !== - 1 ) {
1843+ this . data . splice ( index_ , 1 ) ;
18431844 }
18441845 }
18451846
@@ -2521,19 +2522,6 @@ CanvasCollection.prototype.createNode = function (ctx, config, vDomIndex) {
25212522 return new CanvasNodeExe ( ctx , config , domId ( ) , vDomIndex ) ;
25222523} ;
25232524
2524- function getPixlRatio ( ctx ) {
2525- var dpr = window . devicePixelRatio || 1 ;
2526- var bsr =
2527- ctx . webkitBackingStorePixelRatio ||
2528- ctx . mozBackingStorePixelRatio ||
2529- ctx . msBackingStorePixelRatio ||
2530- ctx . oBackingStorePixelRatio ||
2531- ctx . backingStorePixelRatio ||
2532- 1 ;
2533- var ratio = dpr / bsr ;
2534- return ratio < 1.0 ? 1.0 : ratio ;
2535- }
2536-
25372525function domSetAttribute ( attr , value ) {
25382526 if ( value == null && this . attr [ attr ] != null ) {
25392527 delete this . attr [ attr ] ;
@@ -2837,8 +2825,8 @@ function CanvasClipping(self, config) {
28372825 ) ;
28382826}
28392827
2840- CanvasClipping . prototype . exe = function ( ) {
2841- this . clip . execute ( ) ;
2828+ CanvasClipping . prototype . exe = function ( ctx , bbox , disableRestore ) {
2829+ this . clip . execute ( disableRestore ) ;
28422830 this . clip . dom . ctx . clip ( ) ;
28432831 return true ;
28442832} ;
@@ -3016,8 +3004,6 @@ RenderImage.prototype.execute = function RIexecute() {
30163004 var y = ref . y ; if ( y === void 0 ) y = 0 ;
30173005
30183006 if ( this . imageObj ) {
3019- // console.log(this.imageObj);
3020- // this.ctx.drawImage(this.rImageObj ? this.rImageObj.canvas : this.imageObj, x, y, width, height);
30213007 this . ctx . drawImage ( this . imageObj , x , y , width , height ) ;
30223008 }
30233009} ;
@@ -4037,6 +4023,7 @@ CanvasNodeExe.prototype.stylesExe = function CstylesExe() {
40374023 var key ;
40384024 var style = this . style ;
40394025
4026+ this . ctx [ "clip-Path" ] = null ;
40404027 for ( key in style ) {
40414028 if ( typeof style [ key ] === "string" || typeof style [ key ] === "number" ) {
40424029 value = style [ key ] ;
@@ -4047,7 +4034,7 @@ CanvasNodeExe.prototype.stylesExe = function CstylesExe() {
40474034 style [ key ] instanceof CanvasClipping ||
40484035 style [ key ] instanceof CanvasMask
40494036 ) {
4050- value = style [ key ] . exe ( this . ctx , this . dom . BBox ) ;
4037+ value = style [ key ] . exe ( this . ctx , this . dom . BBox , true ) ;
40514038 } else {
40524039 value = style [ key ] ;
40534040 }
@@ -4211,19 +4198,24 @@ CanvasNodeExe.prototype.skewY = function CskewY(y) {
42114198 return this ;
42124199} ;
42134200
4214- CanvasNodeExe . prototype . execute = function Cexecute ( ) {
4201+ CanvasNodeExe . prototype . execute = function Cexecute ( disableRestore ) {
42154202 if ( this . style . display === "none" ) {
42164203 return ;
42174204 }
4218- this . ctx . save ( ) ;
4205+ console . log ( disableRestore ) ;
4206+ if ( ! disableRestore ) {
4207+ this . ctx . save ( ) ;
4208+ }
42194209 this . stylesExe ( ) ;
42204210 this . attributesExe ( ) ;
42214211 if ( this . dom instanceof RenderGroup ) {
42224212 for ( var i = 0 , len = this . children . length ; i < len ; i += 1 ) {
4223- this . children [ i ] . execute ( ) ;
4213+ this . children [ i ] . execute ( disableRestore ) ;
42244214 }
42254215 }
4226- this . ctx . restore ( ) ;
4216+ if ( ! disableRestore ) {
4217+ this . ctx . restore ( ) ;
4218+ }
42274219} ;
42284220
42294221CanvasNodeExe . prototype . prependChild = function child ( childrens ) {
@@ -4363,9 +4355,7 @@ CanvasNodeExe.prototype.putPixels = function (pixels) {
43634355} ;
43644356
43654357function GetCanvasImgInstance ( width , height ) {
4366- var canvas = document . createElement ( "canvas" ) ;
4367- canvas . setAttribute ( "height" , height ) ;
4368- canvas . setAttribute ( "width" , width ) ;
4358+ var canvas = createCanvas ( width , height ) ;
43694359 this . canvas = canvas ;
43704360 this . context = this . canvas . getContext ( "2d" ) ;
43714361}
@@ -4386,39 +4376,57 @@ function textureImageInstance(self, url) {
43864376 if ( ! self ) {
43874377 return imageIns ;
43884378 }
4389-
4390- imageIns . onload = function onload ( ) {
4391- if ( ! self ) {
4392- return ;
4393- }
4394- if ( self . attr ) {
4395- self . attr . height = self . attr . height ? self . attr . height : imageIns . naturalHeight ;
4396- self . attr . width = self . attr . width ? self . attr . width : imageIns . naturalWidth ;
4397- }
4398- if ( self instanceof RenderTexture ) {
4399- self . setSize ( self . attr . width , self . attr . height ) ;
4400- }
4401- self . imageObj = imageIns ;
44024379
4403- if ( self . attr && self . attr . onload && typeof self . attr . onload === "function" ) {
4404- self . attr . onload . call ( self , self . image ) ;
4405- }
4406- if ( self . asyncOnLoad && typeof self . asyncOnLoad === "function" ) {
4407- self . asyncOnLoad ( self . image ) ;
4408- }
4380+ self . imageObj = imageIns ;
44094381
4410- postProcess ( self ) ;
4411- } ;
4382+ if ( self . attr ) {
4383+ self . attr . height = self . attr . height ? self . attr . height : imageIns . naturalHeight ;
4384+ self . attr . width = self . attr . width ? self . attr . width : imageIns . naturalWidth ;
4385+ }
4386+ if ( self instanceof RenderTexture ) {
4387+ self . setSize ( self . attr . width , self . attr . height ) ;
4388+ }
4389+ self . imageObj = imageIns ;
44124390
4413- imageIns . onerror = function onerror ( error ) {
4414- console . error ( error ) ;
4415- if ( self . nodeExe . attr . onerror && typeof self . nodeExe . attr . onerror === "function" ) {
4416- self . nodeExe . attr . onerror . call ( self . nodeExe , error ) ;
4417- }
4418- if ( self . asyncOnLoad && typeof self . asyncOnLoad === "function" ) {
4419- self . asyncOnLoad ( self . image ) ;
4420- }
4421- } ;
4391+ if ( self . attr && self . attr . onload && typeof self . attr . onload === "function" ) {
4392+ self . attr . onload . call ( self , self . image ) ;
4393+ }
4394+ if ( self . asyncOnLoad && typeof self . asyncOnLoad === "function" ) {
4395+ self . asyncOnLoad ( self . image ) ;
4396+ }
4397+
4398+ // imageIns.onload = function onload() {
4399+ // if (!self) {
4400+ // return;
4401+ // }
4402+ // if (self.attr) {
4403+ // self.attr.height = self.attr.height ? self.attr.height : imageIns.naturalHeight;
4404+ // self.attr.width = self.attr.width ? self.attr.width : imageIns.naturalWidth;
4405+ // }
4406+ // if (self instanceof RenderTexture) {
4407+ // self.setSize(self.attr.width, self.attr.height);
4408+ // }
4409+ // self.imageObj = imageIns;
4410+
4411+ // if (self.attr && self.attr.onload && typeof self.attr.onload === "function") {
4412+ // self.attr.onload.call(self, self.image);
4413+ // }
4414+ // if (self.asyncOnLoad && typeof self.asyncOnLoad === "function") {
4415+ // self.asyncOnLoad(self.image);
4416+ // }
4417+
4418+ // postProcess(self);
4419+ // };
4420+
4421+ // imageIns.onerror = function onerror(error) {
4422+ // console.error(error);
4423+ // if (self.nodeExe.attr.onerror && typeof self.nodeExe.attr.onerror === "function") {
4424+ // self.nodeExe.attr.onerror.call(self.nodeExe, error);
4425+ // }
4426+ // if (self.asyncOnLoad && typeof self.asyncOnLoad === "function") {
4427+ // self.asyncOnLoad(self.image);
4428+ // }
4429+ // };
44224430 return imageIns ;
44234431}
44244432
@@ -4493,8 +4501,7 @@ RenderTexture.prototype.constructor = RenderTexture;
44934501
44944502RenderTexture . prototype . setSize = function ( w , h ) {
44954503 var scale = this . attr . scale || 1 ;
4496- this . rImageObj . setAttr ( "width" , w * scale ) ;
4497- this . rImageObj . setAttr ( "height" , h * scale ) ;
4504+ this . rImageObj = createCanvas ( w * scale , h * scale ) ;
44984505 postProcess ( this ) ;
44994506} ;
45004507
@@ -4533,6 +4540,7 @@ RenderTexture.prototype.setAttr = function RSsetAttr(attr, value) {
45334540 if ( self . image . src !== value ) {
45344541 self . image . src = value ;
45354542 }
4543+ postProcess ( self ) ;
45364544 } else if ( value instanceof CanvasNodeExe || value instanceof RenderTexture ) {
45374545 self . imageObj = value . domEl ;
45384546 self . attr . height = self . attr . height ? self . attr . height : value . attr . height ;
@@ -4611,7 +4619,7 @@ function createPage (ctx) {
46114619 ) ;
46124620 root . ENV = "NODE" ;
46134621 var execute = root . execute . bind ( root ) ;
4614- var ratio = getPixlRatio ( ctx ) ;
4622+ var ratio = 1 ;
46154623 var onClear = function ( ctx , width , height ) {
46164624 ctx . clearRect ( 0 , 0 , width * ratio , height * ratio ) ;
46174625 } ;
@@ -4702,17 +4710,6 @@ function createPage (ctx) {
47024710 return new RenderTexture ( this , config ) ;
47034711 } ;
47044712
4705- root . createAsyncTexture = function ( config ) {
4706- var this$1$1 = this ;
4707-
4708- return new Promise ( function ( resolve , reject ) {
4709- var textureInstance = new RenderTexture ( this$1$1 , config ) ;
4710- textureInstance . onLoad ( function ( ) {
4711- resolve ( textureInstance ) ;
4712- } ) ;
4713- } ) ;
4714- } ;
4715-
47164713 root . setContext = function ( prop , value ) {
47174714 /** Expecting value to be array if multiple aruments */
47184715 if ( this . ctx [ prop ] && typeof this . ctx [ prop ] === "function" ) {
@@ -4722,6 +4719,14 @@ function createPage (ctx) {
47224719 }
47234720 } ;
47244721
4722+ root . export = function ( metaData ) {
4723+ if ( metaData === void 0 ) metaData = {
4724+ } ;
4725+
4726+
4727+ return this . domEl . toBuffer ( metaData . mimeType || 'image/png' , metaData ) ;
4728+ } ;
4729+
47254730 root . createPattern = createCanvasPattern ;
47264731
47274732 root . createClip = createCanvasClip ;
@@ -4737,8 +4742,9 @@ function pdfLayer(config, height, width) {
47374742
47384743 var layer = createCanvas ( width , height , "pdf" ) ;
47394744 var ctx = layer . getContext ( "2d" , config ) ;
4740- getPixlRatio ( ctx ) ;
47414745 ctx . type_ = "pdf" ;
4746+ ctx . quality = "best" ;
4747+ ctx . patternQuality = "best" ;
47424748
47434749 function PDFCreator ( ) {
47444750 this . pages = [ ] ;
@@ -4774,6 +4780,12 @@ function pdfLayer(config, height, width) {
47744780 this . pages . push ( newpage ) ;
47754781 return newpage ;
47764782 } ;
4783+ PDFCreator . prototype . removePage = function ( page ) {
4784+ var pageIndex = this . pages . indexOf ( page ) ;
4785+ if ( pageIndex !== - 1 ) {
4786+ this . pages . splice ( pageIndex , 1 ) ;
4787+ }
4788+ } ;
47774789 PDFCreator . prototype . exportPdf = function ( metaData ) {
47784790 if ( metaData === void 0 ) metaData = {
47794791 title : 'I2DJs Pdf' ,
@@ -4804,13 +4816,13 @@ function canvasLayer$1(config, height, width) {
48044816 if ( width === void 0 ) width = 0 ;
48054817 var layer = createCanvas ( width , height ) ;
48064818 var ctx = layer . getContext ( "2d" , config ) ;
4807- getPixlRatio ( ctx ) ;
48084819 var root = createPage ( ctx ) ;
48094820 root . domEl = layer ;
48104821 root . height = height ;
48114822 root . width = width ;
48124823 root . type = "CANVAS" ;
48134824 root . ctx = ctx ;
4825+ ctx . quality = "best" ;
48144826
48154827 return root ;
48164828}
0 commit comments