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

查看:140
本文介绍了如何读取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属性),该属性将返回 IFlowComposer ,但您必须将其强制转换为 StandardFlowComposer 以便访问各个行.
  • 现在您可以访问lines属性,该属性是
  • 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天全站免登陆