Skip to content

Commit 37d4943

Browse files
committed
canvas-5-polyfill import bug fix
1 parent 02c584f commit 37d4943

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

dist/node-i2d.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* node-i2djs v1.0.1
2+
* node-i2djs v1.1.0
33
* (c) 2022 Narayana swamy ([email protected])
44
* @license BSD-3-Clause
55
*/
@@ -4525,8 +4525,7 @@ CollectionPrototype.prototype.wrapper = function wrapper(nodes) {
45254525
var ref = require('canvas');
45264526
var createCanvas = ref.createCanvas;
45274527
var Image = ref.Image;
4528-
var ref$1 = require("canvas-5-polyfill");
4529-
var Path2D = ref$1.Path2D;
4528+
require("canvas-5-polyfill");
45304529
var t2DGeometry = geometry;
45314530
var queueInstance = queue;
45324531
var Id = 0;
@@ -5098,15 +5097,15 @@ RenderText.prototype.fitWidth = function () {
50985097
var strLit = "";
50995098
var i = 0;
51005099
while(i < textLits.length) {
5101-
if (this.ctx.measureText(strLit + " " + textLits[i]).width < width) {
5100+
if (i !== 0) {
5101+
strLit += " ";
5102+
}
5103+
if (this.ctx.measureText(strLit + textLits[i]).width < width) {
51025104
strLit = strLit + textLits[i];
51035105
} else {
51045106
textSubStrs.push(strLit);
51055107
strLit = textLits[i];
51065108
}
5107-
if (i !== 0) {
5108-
strLit += " ";
5109-
}
51105109
i++;
51115110
}
51125111
textSubStrs.push(strLit);
@@ -5564,7 +5563,6 @@ function polygonExe(points) {
55645563
if (points && points.length === 0) {
55655564
return;
55665565
}
5567-
55685566
var polygon = new Path2D();
55695567
polygon.moveTo(points[0].x, points[0].y);
55705568
for (var i = 1; i < points.length; i++) {

examples/Example2.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@
103103
}
104104
});
105105

106+
page1.createEl({
107+
el: "polygon",
108+
attr: {
109+
transform: {
110+
translate: [200, 410]
111+
},
112+
points: [{x: 100, y: 100}, {x: 100, y: 0}, {x: 0, y: 100}]
113+
},
114+
style: {
115+
fillStyle: "#0075F3"
116+
}
117+
});
118+
106119
PDFInstance.execute();
107120

108121
fs.writeFileSync((process.cwd() + "/examples/example2.pdf"), PDFInstance.exportPdf(), err => {

src/modules/canvas.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import colorMap from "./colorMap.js";
66
import Events from "./events.js";
77
import behaviour from "./behaviour.js";
88
const { createCanvas, Image } = require('canvas');
9-
const { Path2D } = require("canvas-5-polyfill");
9+
require("canvas-5-polyfill");
1010

1111
import {
1212
NodePrototype,
@@ -544,15 +544,15 @@ RenderText.prototype.fitWidth = function () {
544544
let strLit = "";
545545
let i = 0;
546546
while(i < textLits.length) {
547-
if (this.ctx.measureText(strLit + " " + textLits[i]).width < width) {
547+
if (i !== 0) {
548+
strLit += " "
549+
}
550+
if (this.ctx.measureText(strLit + textLits[i]).width < width) {
548551
strLit = strLit + textLits[i];
549552
} else {
550553
textSubStrs.push(strLit);
551554
strLit = textLits[i];
552555
}
553-
if (i !== 0) {
554-
strLit += " "
555-
}
556556
i++;
557557
}
558558
textSubStrs.push(strLit);
@@ -962,7 +962,6 @@ function polygonExe(points) {
962962
if (points && points.length === 0) {
963963
return;
964964
}
965-
966965
const polygon = new Path2D();
967966
polygon.moveTo(points[0].x, points[0].y);
968967
for (let i = 1; i < points.length; i++) {

0 commit comments

Comments
 (0)