Flash 11, Embedded Fonts - Not Calculated Until Rendered?
Hello,
I upgraded to Flash 11 from 10.3 and my truncation logic using TLF no longer works correctly with embedded fonts because, it seems, TextFlow is not processing or applying the embedded font until it is rendered in it's container on screen. To clarify, here is the function I am using to calculate the point at which I need to truncate:
public static function findLastVisibleIndex(textFlow:TextFlow, width:int, height:int):int {
var textFlowComposer:IFlowComposer = textFlow.flowComposer;
if (textFlowComposer.numControllers == 0) {
textFlowComposer.addController(new ContainerController(new Sprite(), width, height));
}
var lastContainerController:ContainerController = textFlowComposer.getControllerAt(textFlowComposer.numControllers - 1);
lastContainerController.setCompositionSize(width, height);
textFlowComposer.updateAllControllers();
var lastVisibleTextFlowLine:TextFlowLine = lastContainerController.tlf_internal::getLastVisibleLine();
var endPosition:int = lastVisibleTextFlowLine.absoluteStart + lastVisibleTextFlowLine.textLength - 1;
return endPosition;
}
If I use any device font like Times, Courier, Arial, etc. it measures perfectly to the last character than can fit in a container of a specified size. In Flash 10.3 this works the same/correctly with embedded fonts (I tested it again to be sure). When I upgraded to Flash 11, however, it seems the embedded fonts aren't taking in time. The reason I think that is because when I look at:
trace(textFlowComposer.getLineAt(i).getTextLine(true).textBlock.dump().toString());
If I use an embedded font, I always get Times Roman (while the size is correct at 18):
<glyph isEmbedded='n' fontName='Times New Roman' isBold='n' isItalic='n' gid='42' pointSize='18.00000000000' x='0.00000000000' y='0.00000000000' rotation='0' color='#FF000000'/>
But if I use a device font, the font name is populated correctly.
To add some more information, I am running the above function BEFORE containers (i.e. RichEditableText) are rendered on screen. This is key for my requirements. If, however, I run the above function AFTER containers are renderered - that is, passing in a TextFlow from a rendered RichEditableText on some button click - then everything works again.
So my question is, how can I mimic what is happeneing to TextFlow after everything is rendered but without having to renderer it? And why is the behaviour different between Flash 10.3 and 11?
Thanks!
