有没有办法在 ActionScript 中获取字形的实际边界框? [英] Is there a way to get the actual bounding box of a glyph in ActionScript?
问题描述
我正在学习 ActionScript/Flash.我喜欢玩文本,并且使用出色的 Java2D API 做了很多类似的事情.
我想知道的一件事是您究竟在哪里绘制该字形?"TextField 类提供了方法 getBounds
和 getCharBoundaries
,但这些方法分别返回远远超出整个文本对象或单个字符的实际边界的矩形.>
var b:Sprite = new Sprite();b.graphics.lineStyle(1,0xFF0000);var r:Rectangle = text.getCharBoundaries(4);r.offset(text.x, text.y);b.graphics.drawRect(r.x,r.y,r.width,r.height);addChild(b);b = 新精灵();b.graphics.lineStyle(1,0x00FF00);r = text.getBounds(this);b.graphics.drawRect(r.x,r.y,r.width,r.height);addChild(b);
有没有办法获得有关 ActionScript 中文本字形实际视觉边界的更精确信息?
在 Flash 9 中不太可能——Richard 的回答是一个聪明的解决方法,尽管可能完全不适合生产代码(正如他所提到的):)>
如果您可以访问 Flash 10,请查看新的 文本引擎类,尤其是 TextLine.
I'm learning ActionScript/Flash. I love to play with text, and have done a lot of that kind of thing with the superb Java2D API.
One of the things I like to know is "where, exactly, are you drawing that glyph?" The TextField class provides the methods getBounds
and getCharBoundaries
, but these methods return rectangles that extend far beyond the actual bounds of the whole text object or the individual character, respectively.
var b:Sprite = new Sprite();
b.graphics.lineStyle(1,0xFF0000);
var r:Rectangle = text.getCharBoundaries(4);
r.offset(text.x, text.y);
b.graphics.drawRect(r.x,r.y,r.width,r.height);
addChild(b);
b = new Sprite();
b.graphics.lineStyle(1,0x00FF00);
r = text.getBounds(this);
b.graphics.drawRect(r.x,r.y,r.width,r.height);
addChild(b);
Is there any way to get more precise information about the actual visual bounds of text glyphs in ActionScript?
Not reasonably possible in Flash 9 -- Richard's answer is a clever work-around, though probably completely unsuitable for production code (as he mentions) :)
If you have access to Flash 10, check out the new text engine classes, particularly TextLine.
这篇关于有没有办法在 ActionScript 中获取字形的实际边界框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!