IFormatResolver And Using CSS With TLF
TLF supports a new property on TextFlow called formatResolver of type IFormatResolver. Clients can supply an implementation that can be used to do CSS or "based-on" styling (ala traditional word processors).
The following link is a sample implementation with a primitive styling editor.
Download file
This is the SimpleEditor application from the labs release plus some new UI. The application loads a CSS style sheet at startup that supplied a few styles. The editor lets you modify the "id" or "styleName" property of a particular element or selection range.
The example style sheet has a few simple styles. These are available for use in the editor.
- element selectors for span and TextFlow
- class selectors named italic and center
- an id selector named bold
Modify the style sheet and rebuild it to make additional styles available.
Class CSSFormatResolver is an implementation of IFormatResolver for simple CSS styling. IFormatResolver requires 5 methods.
function invalidateAllTargets(textFlow:TextFlow):void;
/** cached information on this element is now invalid (e.g. parent changed, id changed, styleName changed) */
function invalidateTarget(target:Object):void;
/** Given a FlowElement or IContainerController return any TLFFormat style settings */
function resolveTextLayoutFormat(target:Object):ITextLayoutFormat;
/** Given a FlowElement or IContainerController and the name of a style property return a style value or undefined*/
function resolveUserFormat(target:Object,userFormat:String):*;
/** Called when the owning TextFlow is copied. Return a styleresolver for the copy. */
function getResolverForNewFlow(oldFlow:TextFlow,newFlow:TextFlow):IFormatResolver;
TLF calls the resolveTextLayoutFormat function when it is doing its cascade of attributes. Only styles set by the particular elements styling are set into the returned TextLayoutFormat. Other styles should be undefined. These styles take precedence over any inherited styles from the parent. Any styles directly set on the element take precendence over the styles returned by the formatResolver.
Whenever an elements id or styleName is changed the invalidateTarget API is called from within TLF.
The resolveUserFormat API is called when the client calls getStyle on a FlowElement using a non-TLF styleName. This lets user styles cascade through the TLF elements.
Comments
Hi,
I am getting the following error:
1045: Interface IFormatResolver was not found. SimpleEditorWithCSS/src CSSFormatResolver.as.
I have (i)textLayout_conversion.swc, (ii) textLayout_core.swc and (iii) textLayout_edit.swc copied in to frameworks/libs folder.
Am I missing any swc file ?
Faisal
Posted by: Faisal | February 27, 2009 09:39 AM
Sounds like the wrong versions of the swc files. Make sure you have the latest versions from the gumbo respository. The link is in the FAQ on the forum:
http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid=72&catid=669
Posted by: Richard Dermer | February 27, 2009 03:55 PM
That worked, thanks.
Posted by: Faisal | March 2, 2009 08:59 AM
I'm trying too. I downloaded the latest version from the forum as you suggest and still get errors like "Type was not found ... CharacterFormat"
Posted by: Jack F | March 4, 2009 04:34 PM
That class has been deleted from TLF as of build 370 and isn't used in the sample project.
I suggest you check carefully for out of date versions of the textLayout swcs possibly somewhere in your Flex SDK folder.
Posted by: Richard Dermer | March 4, 2009 05:16 PM