]> git.mxchange.org Git - friendica.git/blob - library/simplepie/demo/for_the_demo/source_files/sIFR-r245/SifrStyleSheet.as
bug #96 move libraries to library - better alignment of like rotator
[friendica.git] / library / simplepie / demo / for_the_demo / source_files / sIFR-r245 / SifrStyleSheet.as
1 /*=:project
2     scalable Inman Flash Replacement (sIFR) version 3.
3
4   =:file
5     Copyright: 2006 Mark Wubben.
6     Author: Mark Wubben, <http://novemberborn.net/>
7
8   =:history
9     * IFR: Shaun Inman
10     * sIFR 1: Mike Davidson, Shaun Inman and Tomas Jogin
11     * sIFR 2: Mike Davidson, Shaun Inman, Tomas Jogin and Mark Wubben
12
13   =:license
14     This software is licensed and provided under the CC-GNU LGPL.
15     See <http://creativecommons.org/licenses/LGPL/2.1/>    
16 */
17
18 import TextField.StyleSheet;
19
20 class SifrStyleSheet extends TextField.StyleSheet {
21   public var fontSize;
22   public var latestLeading = 0;
23   
24   public function parseCSS(cssText:String) {
25     var native = new TextField.StyleSheet();
26     var parsed = native.parseCSS(cssText);
27     
28     if(!parsed) return false;
29     
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];
37       }
38       this.setStyle(selector, style);
39     }
40     
41     return true;
42   }
43   
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;
47     
48     if(leading >= 0) {
49         format.leading = leading;
50         return format;
51     }
52
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];
56
57     return newFormat;
58   }
59   
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;
67     }
68     format.kerning = _root.kerning == 'true' || !(_root.kerning == 'false') || sIFR.defaultKerning;
69     return format;
70   }
71 }