我试图将IText元素添加到画布的中心,但是当我调用canvas.centerObject(object)
方法时,文本变得模糊。
您在此fiddle中有个例子。
var canvas = new fabric.Canvas('canvas',{
width:400,
height:400
});
canvas.setBackgroundColor('#f4f2f2', canvas.renderAll.bind(canvas));
$('#add-text-btn').click(function() {
var text = new fabric.IText('Tap and Type', {
fill: '#333',
fontSize: 14,
});
canvas.add(text);
})
$('#add-ugly-text-btn').click(function() {
var text = new fabric.IText('Tap and Type', {
fill: '#333',
fontSize: 14,
});
canvas.add(text);
//canvas.centerObject(text);
text.center();
text.setCoords();
canvas.renderAll();
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.2.3/fabric.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="add-text-btn">Add text</button>
<button id="add-ugly-text-btn">Add centered text</button><br>
<canvas id="canvas"></canvas>