1
我想添加一些輸入字段/文本區域到畫布。Frabricjs - 限制文本輸入區域
我想以某種方式設置該文本可以顯示的區域 - >(x,y) - 位置,寬度,區域的高度。內容不應流到定義區域之外。
是否可以自動更改字體大小以使內容適合定義的區域? 例如像這裏:http://www.my-wallsticker.de/index.php?cl=designer&html5=1&text=fabricjs
這裏是我的代碼的一部分,我添加一個區域的文本字段。
var title_input = new fabric.IText('Custom Text', {
fontFamily: 'arial black',
fontStyle: 'normal',
fontSize: $j('#configurator-fontsize').val(),
fill: 'red',
hasControls: false,
lockMovementX: true,
lockMovementY: true,
centerTransform: true,
left: 0,
top: 0
});
var placeholder_title_input = new fabric.Rect({
angle: 0,
backgroundColor: 'transparent',
fill: 'transparent',
borderColor: '#000',
originX: 'center',
originY: 'center',
selectable: true,
width: 300,
height: 90
});
var title_group = new fabric.Group([placeholder_title_input, title_input], {
borderColor: '#f00',
selectable: true,
lockMovementX: true,
lockMovementY: true,
hasControls: false,
left: zero_position_left + 40,
top: zero_position_top - 60
});
canvas.add(title_group);
整個代碼可以在my jsfiddle找到。
我還注意到,我的文本對齊不工作,我希望它工作。如果我更改「title_input」的對齊方式,則不會有任何更改。我希望它能對齊給定區域內的內容。
非常感謝您的幫助。