Рисую текст на canvas в помощью библиотеки jCanvas. При исполнении метода printCanvas.drawText выдает ошибку Cannot read property 'text' of undefined.
var products=canvas.getLayerGroup('products');
if(products!==undefined)
{
for(var i=0; i<products.length; i++) {
var width = products[i].width
var height = products[i].height;
var x = products[i].x;
var y = products[i].y;
printCanvas.drawRect({
layer: true,
groups: ['textrect'],
strokeStyle: '#444',
fillStyle: '#ddd',
strokeWidth: 8,
x: x, y: y,
width: width,
height: height,
cornerRadius: 10,
translateX: canvasWidth
});
var title = "Название: "+products[i].data['title'];
var vendor_code="Вендор: "+products[i].data['vendor_code'];
var count="Штук: "+products[i].data['count'];
// var stringLength = canvas.measureText(title).width;
var stringHeight = 38;//printCanvas.measureText(title).height*3;
/* console.log(products[i].data['title']);
console.log(products[i].x);
console.log(products[i].y);
console.log(products[i].width);
console.log(products[i].height);*/
printCanvas.drawText({
layer: true,
groups: ['info'],
// fillStyle: '#9cf',
strokeStyle: "#fgf",
fillStyle: '222',
//strokeWidth: 2,
x: x-width/2, y: y - height / 2 + stringHeight,
fontSize: 38,
fontFamily: 'Verdana, sans-serif',
text: "dsfdsf",//title,
maxWidth:width,
align: "info",
fromCenter:false,
translateX: canvasWidth
});
printCanvas.drawText({
layer: true,
groups: ['info'],
// fillStyle: '#9cf',
fillStyle: '222',
//strokeWidth: 2,
x: x-width/2, y: y - height / 2 + stringHeight*2 + stringHeight + 5,
fontSize: 38,
fontFamily: 'Verdana, sans-serif',
text: "dfds",//vendor_code,
maxWidth:width,
align: "left",
fromCenter:false,
translateX: canvasWidth
});
printCanvas.drawText({
layer: true,
groups: ['info'],
// fillStyle: '#9cf',
fillStyle: '222',
//strokeWidth: 2,
x: x-width/2, y: y - height / 2 + stringHeight * 4+stringHeight + 5,
fontSize: 38,
fontFamily: 'Verdana, sans-serif',
text: "dfdsf",//count,
maxWidth:width,
align: "left",
fromCenter:false,
translateX: canvasWidth
});
}
}
else{
console.log("Oblom");
}