Skip to main content
September 14, 2010
Question

TextLayoutFormat.fontFamily is null for a selection containing multiple fonts

  • September 14, 2010
  • 1 reply
  • 666 views

First we use RichEditableText.getFormatOfRange() to retreive a TextLayoutFormat object. Then we attempt to determine the fonts used in that selection with TextLayoutFormat.fontFamily. This works fine if only one font is set on the selection. However, if you type in one font, then change the font and type some more, and select the text containing both fonts, TextLayoutFormat.fontFamily will return null. I would hope that it could return a comma-separated list or array of fonts used in the selection. Is this a known bug/limitation, and if so, is there a workaround or any plan to address this in the future? This kind of thing is a common use case for our rich text input, and I need to figure out which fonts are selected.

I am still using the TLF framework that came with Flex 4.0.

Adam

This topic has been closed for replies.

1 reply

Adobe Employee
September 14, 2010

That's by design.  The property is undefined when its multi valued.  Comma separated list wouldn't work anyhow as that's actually a legal value for fontFamily - but I understand the point in general.  You probably want an array for each multi-valued property.

getFormatOfRange is calling the underlying Selectionmanager function getCommonCharacterFormat.

This code looks something like this:

    public function getCommonCharacterFormat():TextLayoutFormat
    {      

        var firstLeaf:FlowLeafElement = textFlow.findLeaf(absoluteStart);

        var lastLeaf:FlowLeafElement = textFlow.findLeaf(absoluteEnd);
        var leaf:FlowLeafElement = firstLeaf;
        var attr:TextLayoutFormat = new TextLayoutFormat(leaf.computedFormat);
       
        for (;;)
        {
            if (leaf == lastLeaf)
                break;
            leaf = leaf.getNextLeaf();
            attr.removeClashing(leaf.computedFormat);
        }

        return Property.extractInCategory(TextLayoutFormat, TextLayoutFormat.description, attr, Category.CHARACTER) as TextLayoutFormat;
    }

For your specialized behavior I'd suggest writing a new version of this function that takes a textFlow, an absoluteStart and an absoluteEnd as parameters and makes the calculation.  Instead of returning a TextLayoutFormat a Dictionary would be more appropriate.

Hope that helps,

Richard

September 16, 2010

Thanks for the info. This sounds like it will be a little more involved than I feel comfortable attempting right now (we're in crunch time and this particular problem can be defferred a little longer). So I'll give this a try later and post back here if I have trouble.

PS - I'm going to leave this question "unanswered" until I can confirm this approach will work.

Adam