我正在尝试更改文本框的字体大小而不是缩放比例,因为缩放时。我有一个文本框,其中有多个字体大小应用于字符/单词。我想根据比例改变每个单独的字符/单词fontsize
if (object.styles) {
var styles = object.styles;
for (var row in styles) {
for (var char in styles[row]) {
if ('fontSize' in styles[row][char]) {
activeObject.selectionStart = styles[row][char];
activeObject.selectionEnd = activeObject.selectionStart + 1;
var seletedText = activeObject.getSelectedText();
if(styles[row][char]['fontSize']){
var selectedFontSize = styles[row][char]['fontSize'] * activeObject.scaleX;
selectedFontSize = selectedFontSize.toFixed(0);
}else{
var selectedFontSize = activeObject.fontSize * activeObject.scaleX;
selectedFontSize = selectedFontSize.toFixed(0);
}
styles[row][char]['fontSize'] = selectedFontSize;
// $scope.setStyle(activeObject, 'fontSize',selectedFontSize);
$scope.selectedFontSize = activeObject.fontSize * activeObject.scaleX;
activeObject.selectedFontSize = $scope.selectedFontSize;
// activeObject.text.slice(activeObject.selectionStart, activeObject.selectionEnd);
// delete styles[row][char]['fontSize'];
}
}
}
}
答案 0 :(得分:0)
> canvas.on('text:changed', function (opt) {
> var t1 = opt.target;
> PreventMovingoutsidecanvas(opt);
> PreventWidth(opt);
> if (t1.width > t1.fixedWidth) {
> t1.fontSize *= (t1.fixedWidth+20) / (t1.width);
> t1.width = t1.fixedWidth;
> }
>
> });
您可以在Fabric itext中键入文本时使用它来更改字体大小。