简体   繁体   English

Fabric JS文本限制

[英]Fabric js text restrictions

How can i achieve this in fabric.js? 我如何在fabric.js中实现这一目标?

Text Restrictions: 1)- If user types too much text in the text box available, it should not allow them to and a message should display telling them to choose a different message or find a different font. 文本限制:1)-如果用户在可用的文本框中键入过多的文本,则不应允许他们输入,并且应显示一条消息,告诉他们选择其他消息或找到其他字体。 Found the answer for this.. 找到了答案。

pls help me for remaning 2 请帮我还还2

2)- If the user types a message where there is a lot of space left in the text box in the sides, the text box should resize to be within 1mm of the text. 2)-如果用户键入一条消息,该消息的两侧文本框中还有很多空间,则文本框的大小应调整为文本的1mm以内。 I suppose this is in case the text box has the dotted border. 我想这是在文本框带有虚线边框的情况下。 Note also that the background pattern will not go under the text box, which is another reason the text box needs to be shortened if the text doesn't fill the width (so that more of the background can show). 还要注意,背景图案不会出现在文本框下方,这是另一个原因,如果文本不能填满宽度,则需要缩短文本框(这样才能显示更多背景)。

3)- The client always wants the full height of the text box to be maxed out, so that the tops of letters always touch the top and the bottoms of letters always touch the bottom, no matter if it's a mix of lower and upper case and no matter if the letters have tails. 3)-客户始终希望最大化文本框的整个高度,以使字母的顶部始终接触顶部,字母的底部始终接触底部,无论大小写混合而且不管字母是否有尾巴。
Here are a few examples to explain what needs to happen (please read till the end of the list to understand properly): 以下是一些说明需要发生的情况的示例(请仔细阅读列表末尾以正确理解):
The word “HELLO” - all letters will touch top and bottom “ HELLO”一词-所有字母都将触及顶部和底部
The word “Hello” – the “H” and “ll” will touch top and bottom “你好”一词–“ H”和“ ll”将触及顶部和底部
The word “aaaa” - even though lower case will touch top and bottom “ aaaa”一词-即使小写字母也会触及顶部和底部
The word “aaah” – the “h” will touch top and bottom and the “aaa” will only touch bottom 单词“ aaah” –“ h”将触及顶部和底部,而“ aaa”将触及底部
The word “big” – because the “g” goes down, the “g” will touch the bottom but “大”一词–因为“ g”下降,“ g”将触底,但
the “bi” will not. “ bi”不会。 The word will actually be very small because the “b” will touch the top but not the bottom, the “g” will touch the bottom but not the top, and the “i” will not touch either. 该单词实际上很小,因为“ b”将触摸顶部但不触摸底部,“ g”将触摸底部但不触摸顶部,而“ i”也将不触摸任何一个。

For problem 2, you need to catch the event, 对于问题2,您需要赶上事件,

and then inside the function you should get the width of text box and width of actual text and adjust the textbox width accordingly, something like 然后在函数中,您应该获取文本框的宽度和实际文本的宽度,并相应地调整文本框的宽度,例如

canvas.on('text:editing:exited',   onTextExited)
onTextExited = function(event)
{
var onemm = 10; //Need to calculate what one mm is in pixels
var canvasObj=event.target;
if(canvasObj.width > canvasObj._getTextWidth())
{
//Adjust the width of object 
canvasObj.width = canvasObj._getTextWidth() + onemm;
canvasObj.setCoords();
}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM