Copy link to clipboard
Copied
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.
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Correction, yes it is just trailing whitespace that doesn't affect width.
Copy link to clipboard
Copied
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!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now