2 scalable Inman Flash Replacement (sIFR) version 3.
5 Copyright: 2006 Mark Wubben.
6 Author: Mark Wubben, <http://novemberborn.net/>
10 * sIFR 1: Mike Davidson, Shaun Inman and Tomas Jogin
11 * sIFR 2: Mike Davidson, Shaun Inman, Tomas Jogin and Mark Wubben
14 This software is licensed and provided under the CC-GNU LGPL.
15 See <http://creativecommons.org/licenses/LGPL/2.1/>
18 import TextField.StyleSheet;
20 class SifrStyleSheet extends TextField.StyleSheet {
22 public var latestLeading = 0;
24 public function parseCSS(cssText:String) {
25 var native = new TextField.StyleSheet();
26 var parsed = native.parseCSS(cssText);
28 if(!parsed) return false;
30 var selectors = native.getStyleNames();
31 for(var i = selectors.length - 1; i >= 0; i--) {
32 var selector = selectors[i];
33 var nativeStyle = native.getStyle(selector);
34 var style = this.getStyle(selector) || nativeStyle;
35 if(style != nativeStyle) {
36 for(var property in nativeStyle) style[property] = nativeStyle[property];
38 this.setStyle(selector, style);
44 // Apply leading to the textFormat. Much thanks to <http://www.blog.lessrain.com/?p=98>.
45 private function applyLeading(format, leading) {
46 this.latestLeading = leading;
49 format.leading = leading;
53 // Workaround for negative leading, which is ignored otherwise.
54 var newFormat = new TextFormat(null, null, null, null, null, null, null, null, null, null, null, null, leading);
55 for(var property in format) if(property != 'leading') newFormat[property] = format[property];
60 public function transform(style) {
61 var format = super.transform(style);
62 if(style.leading) format = applyLeading(format, style.leading);
63 if(style.letterSpacing) format.letterSpacing = style.letterSpacing;
64 // Support font sizes relative to the size of .sIFR-root.
65 if(this.fontSize && style.fontSize && style.fontSize.indexOf('%')) {
66 format.size = this.fontSize * parseInt(style.fontSize) / 100;
68 format.kerning = _root.kerning == 'true' || !(_root.kerning == 'false') || sIFR.defaultKerning;