Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

FTE's textLine.textWidth value does not change if text ends with SPACE character

Enthusiast ,
Oct 17, 2013 Oct 17, 2013

Hi all FTE users,

Here is a simplest code sample to create a single FTE textLine filled with a SAMPLE_TEXT const content

package {

    import flash.display.Sprite;

    import flash.text.engine.TextBlock;

    import flash.text.engine.TextElement;

    import flash.text.engine.TextLine;

    import flash.text.engine.ElementFormat;   

    public class FTETextLineExample extends Sprite {

        private const SAMPLE_TEXT:String = "Sample";

        public function FTETextLineExample():void {

            var format:ElementFormat = new ElementFormat(null, 12, 0xCC0000);

            var textElement:TextElement = new TextElement(SAMPLE_TEXT, format);                       

            var textBlock:TextBlock = new TextBlock();           

            textBlock.content = textElement;           

            createLine(textBlock);

        }

        private function createLine(textBlock:TextBlock):void {

            var yPos:Number = 20;

            var textLine:TextLine = textBlock.createTextLine (null, 1000);            

            textLine.x = 15;

            yPos += textLine.textHeight + 2;

            textLine.y = yPos;

            addChild(textLine);                                   

           trace ("textLine.textWidth=", textLine.textWidth);

        }

    }

}

In my testing, trace ("textLine.textWidth=", textLine.textWidth) outputs 35 for the textLine.textWidth value, which is fine.

But whenever I add a few spaces at the end of the SAMPLE_TEXT string, e.g

private const SAMPLE_TEXT:String = "Sample                    ";

and run the test code, textLine.textWidth will continue to output the same 35 value.

Why is that?

The string is getting larger by the char count, but textLine.textWidth is not changing.

TOPICS
ActionScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Oct 22, 2013 Oct 22, 2013

As far as I can tell the FTE strips all leading and trailing (white)space characters.

This has caused me a lot of headaches for my project which requires exact placement of CFF glyphs.

I even tried the XML methods such as XML.ignoreWhitespace(false) hoping it FTE would use this, but no luck.

If anyone has any idea how to make FTE keep leading and trailing whitespace that would be pretty awesome.

Translate
Community Beginner ,
Oct 22, 2013 Oct 22, 2013

As far as I can tell the FTE strips all leading and trailing (white)space characters.

This has caused me a lot of headaches for my project which requires exact placement of CFF glyphs.

I even tried the XML methods such as XML.ignoreWhitespace(false) hoping it FTE would use this, but no luck.

If anyone has any idea how to make FTE keep leading and trailing whitespace that would be pretty awesome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 20, 2013 Nov 20, 2013

Correction, yes it is just trailing whitespace that doesn't affect width.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 12, 2015 Mar 12, 2015
LATEST

I know I'm 2 years late, but I ran into this problem today and I thought that someone somewhere would be interested in my workaround.

Basically I wrap my string in zero-width whitespace characters before calculating the width. Apparently the FTE is picky about what kinds of whitespace it will strip, and zero-width characters will "protect" the regular spaces.

It looks something like this:

const ZERO_WIDTH_NON_JOINER:String = String.fromCharCode(0x200c);

var textElement:TextElement = new TextElement(ZERO_WIDTH_NON_JOINER + SAMPLE_TEXT + ZERO_WIDTH_NON_JOINER, format);

Hope this helps!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines