字体中的大衬线会导致 Flash 无法正确测量尺寸
我有一个文本区域,我在其中测量文本宽度和文本高度,以确保用户输入的文本不能多于文本区域所能容纳的文本。我还使用 textHeightNow 和 textWidthNow 扩展了 textArea,用于测量 textField 的尺寸,因为它们更新时不需要验证。现在,这对于我正在使用的 90% 的嵌入字体来说效果很好,但是任何具有巨型衬线的字体都无法正确测量,例如查看此文本区域中的“f”:
替代文本 http://img.skitch.com/20091101-xhm5jguma1qgukg6fxrymrwr3u.jpg
您可以看到它们在两侧被切断,因为 textWidth和 textWidthNow 都返回不正确的大小,没有考虑到大量衬线。文本区域的字体大小、坐标和尺寸都是整数,所以这不是问题,还有其他建议吗?我查看 textArea 是否有 ClipContent 参数,但它没有(那就太好了)。
谢谢
I have a textarea where I measure the textWidth and textHeight to make sure the user cannot enter more text than can fit in the text area. I also extended the textArea with a textHeightNow and textWidthNow that measure the textField's dimensions since they update w/out requiring validation. Now this works great for 90% of the embedded fonts I'm using but any fonts that have giant serifs are not measured properly, for instance look at the 'f's in this text area:
alt text http://img.skitch.com/20091101-xhm5jguma1qgukg6fxrymrwr3u.jpg
You can see they get cut off on both sides because textWidth and textWidthNow both return an incorrect size not taking into account the massive serifs. The font size, coords and dimensions of the text area are all integers so thats not the problem, any other suggestions? I looked to see if textArea has a clipContent argument but it doesn't (that would have been nice).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前遇到过这个问题,据我所知,有两个选择,但没有一个很好:
Flash Player 10...它很难使用,但是
我认为它会测量这样的字体
(和连字)正确。
并使用 getColorBoundsRect 来
确定其实际尺寸。
我最终使用了后者,因为将整个应用程序更改为新引擎会困难得多。您将需要调整边距并使用更大的文本字段(在某个容器内)才能正确绘制它,但它应该可以工作。
I've run into this problem before and as far as I can tell you have two options, none of them very nice:
Flash Player 10... its very hard to use but
I think it will measure such fonts
(and ligatures) properly.
and use getColorBoundsRect to
determine its real dimensions.
I ended up using the latter as changing the whole app to the new engine would have been much much harder. You will need to tweak margins and use a larger textfield (inside some container) to be able to draw it properly, but it should work.