Skip to content

Commit 1a741c4

Browse files
committed
code cleanup
1 parent ba89204 commit 1a741c4

File tree

6 files changed

+67
-148
lines changed

6 files changed

+67
-148
lines changed

dist/node-i2d.js

Lines changed: 34 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,17 +2352,12 @@ function exec(value) {
23522352
return this;
23532353
}
23542354

2355-
function on(eventType, hndlr) {
2356-
for (var i = 0, len = this.stack.length; i < len; i += 1) {
2357-
this.stack[i].on(eventType, hndlr);
2358-
}
2355+
// function on(eventType, hndlr) {
2356+
// for (let i = 0, len = this.stack.length; i < len; i += 1) {
2357+
// this.stack[i].on(eventType, hndlr);
2358+
// }
23592359

2360-
return this;
2361-
} // function in (coOr) {
2362-
// for (let i = 0, len = this.stack.length; i < len; i += 1) {
2363-
// this.stack[i].in(coOr)
2364-
// }
2365-
// return this
2360+
// return this;
23662361
// }
23672362

23682363
function remove() {
@@ -2373,13 +2368,30 @@ function remove() {
23732368
return this;
23742369
}
23752370

2376-
function interrupt() {
2377-
for (var i = 0, len = this.stack.length; i < len; i += 1) {
2378-
this.stack[i].interrupt();
2379-
}
2371+
// function interrupt() {
2372+
// for (let i = 0, len = this.stack.length; i < len; i += 1) {
2373+
// this.stack[i].interrupt();
2374+
// }
23802375

2381-
return this;
2382-
}
2376+
// return this;
2377+
// }
2378+
2379+
// function resolveObject(config, node, i) {
2380+
// const obj = {};
2381+
// let key;
2382+
2383+
// for (key in config) {
2384+
// if (key !== "end") {
2385+
// if (typeof config[key] === "function") {
2386+
// obj[key] = config[key].call(node, node.dataObj, i);
2387+
// } else {
2388+
// obj[key] = config[key];
2389+
// }
2390+
// }
2391+
// }
2392+
2393+
// return obj;
2394+
// }
23832395

23842396
var textArray = function textArray(value) {
23852397
var node;
@@ -2476,14 +2488,9 @@ CollectionPrototype.prototype = {
24762488
rotate: rotate,
24772489
scale: scale,
24782490
exec: exec,
2479-
// animateTo: animateArrayTo,
2480-
// animateExe: animateArrayExe,
2481-
// animatePathTo: animatePathArrayTo,
24822491
remove: remove,
2483-
interrupt: interrupt,
24842492
text: textArray,
24852493
join: join,
2486-
on: on,
24872494
};
24882495

24892496
CollectionPrototype.prototype.createNode = function () {};
@@ -2739,8 +2746,6 @@ function PixelObject(data, width, height) {
27392746
this.imageData = data;
27402747
this.width = width;
27412748
this.height = height;
2742-
// this.x = x;
2743-
// this.y = y;
27442749
}
27452750

27462751
PixelObject.prototype.get = function (pos) {
@@ -2896,7 +2901,6 @@ function CanvasDom() {
28962901

28972902
CanvasDom.prototype = {
28982903
render: cRender,
2899-
// on: addListener,
29002904
setAttr: domSetAttribute,
29012905
setStyle: domSetStyle,
29022906
applyStyles: applyStyles,
@@ -2906,15 +2910,12 @@ function imageInstance(self) {
29062910
var imageIns = new Image();
29072911
imageIns.crossOrigin = "anonymous";
29082912
imageIns.dataMode = Image.MODE_MIME | Image.MODE_IMAGE;
2909-
// console.log(self.ctx.type_);
29102913
imageIns.onload = function onload() {
29112914
self.attr.height = self.attr.height ? self.attr.height : imageIns.naturalHeight;
29122915
self.attr.width = self.attr.width ? self.attr.width : imageIns.naturalWidth;
29132916
self.imageObj = imageIns;
29142917

29152918
if (self.nodeExe.attr.onload && typeof self.nodeExe.attr.onload === "function") {
2916-
// console.log(self);
2917-
// console.log(self.nodeExe);
29182919
self.nodeExe.attr.onload.call(self.nodeExe, self.image);
29192920
}
29202921

@@ -3058,7 +3059,9 @@ RenderText.prototype.fitWidth = function () {
30583059
if (this.ctx.measureText(strLit + textList[i]).width < width) {
30593060
strLit = strLit + textList[i];
30603061
} else {
3061-
textSubStrs.push(strLit);
3062+
if (strLit && strLit.length > 0) {
3063+
textSubStrs.push(strLit);
3064+
}
30623065
strLit = textList[i];
30633066
}
30643067
}
@@ -3415,14 +3418,6 @@ RenderPath.prototype.updateBBox = function RPupdateBBox() {
34153418
var scaleX = ref$1.scaleX;
34163419
var scaleY = ref$1.scaleY;
34173420

3418-
// if (transform && transform.translate) {
3419-
// [translateX, translateY] = transform.translate;
3420-
// }
3421-
3422-
// if (transform && transform.scale) {
3423-
// [scaleX = 1, scaleY = scaleX] = transform.scale;
3424-
// }
3425-
34263421
self.BBox = self.path
34273422
? self.path.BBox
34283423
: {
@@ -3623,10 +3618,6 @@ RenderEllipse.prototype.constructor = RenderEllipse;
36233618

36243619
RenderEllipse.prototype.updateBBox = function REupdateBBox() {
36253620
var self = this;
3626-
// let translateX = 0;
3627-
// let translateY = 0;
3628-
// let scaleX = 1;
3629-
// let scaleY = 1;
36303621
var ref = self.attr;
36313622
var transform = ref.transform;
36323623
var cx = ref.cx; if ( cx === void 0 ) cx = 0;
@@ -3639,14 +3630,6 @@ RenderEllipse.prototype.updateBBox = function REupdateBBox() {
36393630
var scaleX = ref$1.scaleX;
36403631
var scaleY = ref$1.scaleY;
36413632

3642-
// if (transform && transform.translate) {
3643-
// [translateX, translateY] = transform.translate;
3644-
// }
3645-
3646-
// if (transform && transform.scale) {
3647-
// [scaleX = 1, scaleY = scaleX] = transform.scale;
3648-
// }
3649-
36503633
self.BBox = {
36513634
x: translateX + (cx - rx) * scaleX,
36523635
y: translateY + (cy - ry) * scaleY,
@@ -4002,13 +3985,6 @@ var CanvasNodeExe = function CanvasNodeExe(context, config, id, vDomIndex) {
40023985

40033986
this.dom.nodeExe = this;
40043987
this.BBoxUpdate = true;
4005-
// if (config.style) {
4006-
// this.setStyle(config.style);
4007-
// }
4008-
4009-
// if (config.attr) {
4010-
// this.setAttr(config.attr);
4011-
// }
40123988
};
40133989

40143990
CanvasNodeExe.prototype = new NodePrototype();
@@ -4202,7 +4178,7 @@ CanvasNodeExe.prototype.execute = function Cexecute(disableRestore) {
42024178
if (this.style.display === "none") {
42034179
return;
42044180
}
4205-
console.log(disableRestore);
4181+
// console.log(disableRestore);
42064182
if (!disableRestore) {
42074183
this.ctx.save();
42084184
}
@@ -4493,8 +4469,6 @@ function RenderTexture(nodeExe, config) {
44934469
if (key !== "height" && key !== "width")
44944470
{ self.setAttr(key, self.attr[key]); }
44954471
}
4496-
4497-
// self.stack = [self];
44984472
}
44994473
RenderTexture.prototype = new NodePrototype();
45004474
RenderTexture.prototype.constructor = RenderTexture;
@@ -4619,9 +4593,8 @@ function createPage (ctx) {
46194593
);
46204594
root.ENV = "NODE";
46214595
var execute = root.execute.bind(root);
4622-
var ratio = 1;
46234596
var onClear = function (ctx, width, height) {
4624-
ctx.clearRect(0, 0, width * ratio, height * ratio);
4597+
ctx.clearRect(0, 0, width, height);
46254598
};
46264599

46274600
root.setClear = function (exe) {
@@ -4658,8 +4631,6 @@ function createPage (ctx) {
46584631
};
46594632

46604633
root.setSize = function (width_, height_) {
4661-
// width = width_;
4662-
// height = height_;
46634634
this.domEl = createCanvas(width_, height_, "pdf");
46644635
ctx = this.domEl.getContext("2d", config);
46654636
ctx.type_ = "pdf";
@@ -4671,7 +4642,7 @@ function createPage (ctx) {
46714642

46724643
root.execute = function executeExe() {
46734644
onClear(ctx, this.width, this.height);
4674-
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
4645+
ctx.setTransform(1, 0, 0, 1, 0, 0);
46754646
this.updateBBox();
46764647
execute();
46774648
if (onChangeExe && this.stateModified) {

examples/Example5.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
sheight: 140,
166166
},
167167
onload: function (argument) {
168-
console.log("onload called");
168+
// console.log("onload called");
169169
}
170170
},
171171
});
@@ -181,9 +181,6 @@
181181
},
182182
});
183183

184-
185-
186-
187184
var clipInstance = canvasInstance.createClip();
188185
clipInstance.clip.createEl({
189186
el: "polygon",

examples/examplej.png

-409 Bytes
Loading

src/modules/canvas.js

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ function PixelObject(data, width, height) {
232232
this.imageData = data;
233233
this.width = width;
234234
this.height = height;
235-
// this.x = x;
236-
// this.y = y;
237235
}
238236

239237
PixelObject.prototype.get = function (pos) {
@@ -378,7 +376,6 @@ function CanvasDom() {
378376

379377
CanvasDom.prototype = {
380378
render: cRender,
381-
// on: addListener,
382379
setAttr: domSetAttribute,
383380
setStyle: domSetStyle,
384381
applyStyles,
@@ -388,15 +385,12 @@ function imageInstance(self) {
388385
const imageIns = new Image();
389386
imageIns.crossOrigin = "anonymous";
390387
imageIns.dataMode = Image.MODE_MIME | Image.MODE_IMAGE
391-
// console.log(self.ctx.type_);
392388
imageIns.onload = function onload() {
393389
self.attr.height = self.attr.height ? self.attr.height : imageIns.naturalHeight;
394390
self.attr.width = self.attr.width ? self.attr.width : imageIns.naturalWidth;
395391
self.imageObj = imageIns;
396392

397393
if (self.nodeExe.attr.onload && typeof self.nodeExe.attr.onload === "function") {
398-
// console.log(self);
399-
// console.log(self.nodeExe);
400394
self.nodeExe.attr.onload.call(self.nodeExe, self.image);
401395
}
402396

@@ -523,7 +517,9 @@ RenderText.prototype.fitWidth = function () {
523517
if (this.ctx.measureText(strLit + textList[i]).width < width) {
524518
strLit = strLit + textList[i];
525519
} else {
526-
textSubStrs.push(strLit);
520+
if (strLit && strLit.length > 0) {
521+
textSubStrs.push(strLit);
522+
}
527523
strLit = textList[i];
528524
}
529525
}
@@ -832,14 +828,6 @@ RenderPath.prototype.updateBBox = function RPupdateBBox() {
832828
const { transform } = self.attr;
833829
const { translateX, translateY, scaleX, scaleY } = parseTransform(transform);
834830

835-
// if (transform && transform.translate) {
836-
// [translateX, translateY] = transform.translate;
837-
// }
838-
839-
// if (transform && transform.scale) {
840-
// [scaleX = 1, scaleY = scaleX] = transform.scale;
841-
// }
842-
843831
self.BBox = self.path
844832
? self.path.BBox
845833
: {
@@ -1040,21 +1028,9 @@ RenderEllipse.prototype.constructor = RenderEllipse;
10401028

10411029
RenderEllipse.prototype.updateBBox = function REupdateBBox() {
10421030
const self = this;
1043-
// let translateX = 0;
1044-
// let translateY = 0;
1045-
// let scaleX = 1;
1046-
// let scaleY = 1;
10471031
const { transform, cx = 0, cy = 0, rx = 0, ry = 0 } = self.attr;
10481032
const { translateX, translateY, scaleX, scaleY } = parseTransform(transform);
10491033

1050-
// if (transform && transform.translate) {
1051-
// [translateX, translateY] = transform.translate;
1052-
// }
1053-
1054-
// if (transform && transform.scale) {
1055-
// [scaleX = 1, scaleY = scaleX] = transform.scale;
1056-
// }
1057-
10581034
self.BBox = {
10591035
x: translateX + (cx - rx) * scaleX,
10601036
y: translateY + (cy - ry) * scaleY,
@@ -1367,13 +1343,6 @@ const CanvasNodeExe = function CanvasNodeExe(context, config, id, vDomIndex) {
13671343

13681344
this.dom.nodeExe = this;
13691345
this.BBoxUpdate = true;
1370-
// if (config.style) {
1371-
// this.setStyle(config.style);
1372-
// }
1373-
1374-
// if (config.attr) {
1375-
// this.setAttr(config.attr);
1376-
// }
13771346
};
13781347

13791348
CanvasNodeExe.prototype = new NodePrototype();
@@ -1566,7 +1535,7 @@ CanvasNodeExe.prototype.execute = function Cexecute(disableRestore) {
15661535
if (this.style.display === "none") {
15671536
return;
15681537
}
1569-
console.log(disableRestore);
1538+
// console.log(disableRestore);
15701539
if (!disableRestore) {
15711540
this.ctx.save();
15721541
}
@@ -1847,8 +1816,6 @@ function RenderTexture(nodeExe, config = {}) {
18471816
if (key !== "height" && key !== "width")
18481817
self.setAttr(key, self.attr[key]);
18491818
}
1850-
1851-
// self.stack = [self];
18521819
}
18531820
RenderTexture.prototype = new NodePrototype();
18541821
RenderTexture.prototype.constructor = RenderTexture;
@@ -1971,9 +1938,8 @@ function createPage (ctx) {
19711938
);
19721939
root.ENV = "NODE";
19731940
const execute = root.execute.bind(root);
1974-
const ratio = 1;
19751941
let onClear = function (ctx, width, height) {
1976-
ctx.clearRect(0, 0, width * ratio, height * ratio);
1942+
ctx.clearRect(0, 0, width, height);
19771943
};
19781944

19791945
root.setClear = function (exe) {
@@ -2010,8 +1976,6 @@ function createPage (ctx) {
20101976
};
20111977

20121978
root.setSize = function (width_, height_) {
2013-
// width = width_;
2014-
// height = height_;
20151979
this.domEl = createCanvas(width_, height_, "pdf");
20161980
ctx = this.domEl.getContext("2d", config);
20171981
ctx.type_ = "pdf";
@@ -2023,7 +1987,7 @@ function createPage (ctx) {
20231987

20241988
root.execute = function executeExe() {
20251989
onClear(ctx, this.width, this.height);
2026-
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
1990+
ctx.setTransform(1, 0, 0, 1, 0, 0);
20271991
this.updateBBox();
20281992
execute();
20291993
if (onChangeExe && this.stateModified) {
@@ -2089,7 +2053,6 @@ function createPage (ctx) {
20892053
function pdfLayer(config, height = 0, width = 0) {
20902054
const layer = createCanvas(width, height, "pdf");
20912055
let ctx = layer.getContext("2d", config);
2092-
const ratio = 1;
20932056
ctx.type_ = "pdf";
20942057
ctx.quality = "best";
20952058
ctx.patternQuality = "best";
@@ -2161,7 +2124,6 @@ function canvasLayer(config, height = 0, width = 0) {
21612124
let onChangeExe;
21622125
const layer = createCanvas(width, height);
21632126
let ctx = layer.getContext("2d", config);
2164-
const ratio = 1;
21652127
let root = createPage(ctx);
21662128
root.domEl = layer;
21672129
root.height = height;

0 commit comments

Comments
 (0)