基于父项的文本字段的字符边界 [英] Character boundaries of text field based on parent

查看:209
本文介绍了基于父项的文本字段的字符边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个容器内的文本字段。我想知道是否有可能找到每个字符的边界,而不是基于容器而不是文本字段。



这是一个示例屏幕截图:





正常状态会是这样的:
这样我就可以根据文本字段找到每个字符的边界,但是我需要基于容器:

  var rect:Rectangle = new Rectangle(); 
for(var i:int = 0; i< textField.length; i ++){
rect = textField.getCharBoundaries(i);

$ / code>

有没有人有这方面的经验? $ b

解决方案

我相信你必须利用Point转换。 c $ c> var rect:Rectangle = new Rectangle();
for(var i:int = 0; i< textField.length; i ++){
rect = textField.getCharBoundaries(i);

var globalTopLeft:Point = textField.localToGlobal(rect.topLeft);
var globalBottomRight:Point = textField.localToGlobal(rect.bottomRight);

var containerTopLeft:Point = container.globalToLocal(globalTopLeft);
var containerBottomRight:Point = container.globalToLocal(globalBottomRight);

RECT =新的Rectangle(containerTopLeft.x,containerTopLeft.y,containerBottomRight.x-containerTopLeft.x,containerBottomRight.y-containerTopLeft.y)
}


I have a text field inside a container. I'm wondering is it possible to find the boundaries of each character based on the container and not the text field.

Here is a sample screen shot:

And normal state would be like this: With this I can find the bounds of each character based on text field, But I need it based on the container:

var rect:Rectangle = new Rectangle();
for (var i:int = 0; i < textField.length; i++){
    rect = textField.getCharBoundaries(i);
}

Is there anybody whom has an experience on this?

解决方案

I believe you have to make use of Point conversions.

var rect:Rectangle = new Rectangle();
for (var i:int = 0; i < textField.length; i++){
    rect = textField.getCharBoundaries(i);

    var globalTopLeft:Point = textField.localToGlobal(rect.topLeft);
    var globalBottomRight:Point = textField.localToGlobal(rect.bottomRight);

    var containerTopLeft:Point = container.globalToLocal(globalTopLeft);
    var containerBottomRight:Point = container.globalToLocal(globalBottomRight);

    rect = new Rectangle(containerTopLeft.x,containerTopLeft.y,containerBottomRight.x-containerTopLeft.x,containerBottomRight.y-containerTopLeft.y)
}

这篇关于基于父项的文本字段的字符边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆