如何读取 spark TextArea 隐式换行符? [英] How can I read a spark TextArea implicit line breaks?

查看:35
本文介绍了如何读取 spark TextArea 隐式换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TextArea,用户可以在其中输入文本并更改 TextArea 的宽度和高度.调整大小时,文本在预期的地方中断.我需要找到调整大小后 TextArea 皮肤添加隐式换行符的位置.

I have a TextArea where the user can enter text and also change the width and height of the TextArea. When resizing, the text is breaking where expected. I need to find where the TextArea skin added the implicit line breaks after resizing.

环境

  • FlexBuilder 4.6
  • Flex SDK 4.6.0
  • Flash Player 11.1

示例

This is just plain text that
breaks after the word "that".

当 TextArea lineBreak 属性为 toFit 且文本没有 CR 或 LF 字符时,如何找到换行符的位置有什么想法吗?在上面的例子中,它是位置 28.

Any ideas on how to find the position of the line break when the TextArea lineBreak property is toFit and the text has no CR or LF characters? In the example above, it would be position 28.

推荐答案

您可以将文本拆分为行组件并非常轻松地返回它们各自的文本长度,但是您必须使用一些文本布局框架"魔法.

You can split up the text into line components and return their individual text lengths pretty easily, but you'll have to use some 'text layout framework' magic.

  • 首先访问您的 TextArea 的 textFlow 属性(不是 text 属性),它将返回一个 TextFlow 实例.这是 TextArea 中文本的模型.
  • 这个对象有一个 flowComposer,它负责处理文本的布局并携带大量信息.
  • 它的类型是 IFlowComposer,但您必须将其转换为 StandardFlowComposer 以访问各个行.
  • 现在您可以访问 lines 属性,它是 TextFlowLine
  • 每一行都有一个 textLength 属性.
  • First access your TextArea's textFlow property (not the text property), which will return a TextFlow instance. This is a model for the text inside your TextArea.
  • This object has a flowComposer which takes care of the layout of the text and carries a lot of information with it.
  • Its type is IFlowComposer, but you'll have to cast it to a StandardFlowComposer in order to access the individual lines.
  • Now you have access to the lines property, which is a collection of TextFlowLine
  • Each of these lines has a textLength property.

所以下面

var composer:StandardFlowComposer = 
    myTextArea.textFlow.flowComposer as StandardFlowComposer;
for each (var line:TextFlowLine in composer.lines) 
    trace(line.textLength)

会产生(以你的例子)

29
30

这篇关于如何读取 spark TextArea 隐式换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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