TextField autoSize+italics cuts of last character

泪湿孤枕 提交于 2019-12-11 13:42:45

问题


In actionscript 3, my TextField has :

  • CSS styling
  • embedded fonts
  • textAlign : CENTER
  • autoSize : CENTER

... when italics are used the very right character gets slightly cut off (specially caps). It basically seems that it fails detecting the right size.

I've had this problem before but just wondered is there a nice workaround (instead of checking textWidth or offsetting text etc.)?


回答1:


Initialize your textField as you always do, using multiline, autosize, htmlText...

Then do this little trick :

// saving wanted width and height plus 1px to get some space for last char
var savedWidth = myTextField.width + 1;
var savedHeight = myTextField.height + 1;

// removing autoSize, wich is the origin of the problem i think                 
myTextField.autoSize = "none";      

// now manually autoSizing the textField with saved values          
myTextField.width = savedWidth;
myTextField.height = savedHeight;



回答2:


Not that it is much comfort to you, but Flash sometimes has trouble with this seemingly simple task. CSS styling of html TextField was a nice addition but it has caused headaches for text-rendering. In fact I very rarely use CSS for styling text for that reason. I can only imagine that combining bold, italic and normal type faces within the HTML causes Flash to get some of the width calculations wrong which causes autoSize to set the mask a tiny bit short. I hope very much that the new text rendering engine in Flash Player 10 will finally fix these issues (it certainly looks better in theory).

So my solution is never to use HTML with the exception being when I require <a> links in my text ... and there are even some tricky text shifting issues there. In those cases I avoid mixing different font weights and font styles within the same text field. All other cases I use TextFormat directly on TextField.

I suppose if you can't get out of your current architecture (for some reason) you could try adding &nbsp; to the end of your html encoded strings. Or you could manually set the width of the field and not rely on autoSize (as you have mentioned). But if you keep on the CSS/HTML route you may find another new and painful limitation just when you don't want it.




回答3:


I've had issues with TextField masks behaving differently in the Flash preview, and in the actual browser plugin. Usually, and this is strange to me, it would appear more correctly in the browser. Have you tried running the swf in a browser to see if the problem is actually an annoyance rather than a permanent problem?

I had said this:
My in-ideal approach to solving this is to attach a change event to the TextField which always adds a space after the last character of the field. And then to remember to trim this space off when using the value.

But that didn't take into account that this probably doesn't have a change event and that it's an HTML rendered text field. To add a trailing space in the HTML text field throw in an &nbsp; again, that's not really fixing the problem.



来源:https://stackoverflow.com/questions/1516391/textfield-autosizeitalics-cuts-of-last-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!