Merge remote-tracking branch 'systemed/filebank' into filebank
[potlatch2.git] / net / systemeD / halcyon / styleparser / RuleSet.as
index 99183d5c61a46f2ac1956a853df5816739da0342..d0842145ce594d55702a28b1c891750a8de6e025 100644 (file)
@@ -9,13 +9,15 @@ package net.systemeD.halcyon.styleparser {
     import net.systemeD.halcyon.FileBank;
 
     import net.systemeD.halcyon.connection.*;
-       
-       /** A complete stylesheet, as loaded from a MapCSS file. It contains all selectors, declarations, 
-               and embedded images.                                                                                                                                                            </p><p>
-               
-               The RuleSet class has two principal methods: getStyles, which calculates the styles that apply
-               to an entity (returned as a StyleList); and parse, which parses a MapCSS stylesheet into
-               a complete RuleSet. */
+
+    /**
+    * A complete stylesheet, as loaded from a MapCSS file. It contains all selectors, declarations,
+    * and embedded images.
+    *
+    * <p>The RuleSet class has two principal methods: getStyles, which calculates the styles that apply
+    * to an entity (returned as a StyleList); and parse, which parses a MapCSS stylesheet into
+    * a complete RuleSet.</p>
+    */
 
        public class RuleSet {
 
@@ -59,12 +61,15 @@ package net.systemeD.halcyon.styleparser {
                private static const CONDITION_LE:RegExp        =/^ \s* ([:\w]+) \s* <= \s* (.+) \s* $/sx;
                private static const CONDITION_REGEX:RegExp     =/^ \s* ([:\w]+) \s* =~\/ \s* (.+) \/ \s* $/sx;
 
-               private static const ASSIGNMENT_EVAL:RegExp     =/^ \s* (\S+) \s* \:      \s* eval \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
-               private static const ASSIGNMENT:RegExp          =/^ \s* (\S+) \s* \:      \s*          (.+?) \s*                   $/sx;
-               private static const SET_TAG_EVAL:RegExp        =/^ \s* set \s+(\S+)\s* = \s* eval \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
-               private static const SET_TAG:RegExp                     =/^ \s* set \s+(\S+)\s* = \s*          (.+?) \s*                   $/isx;
-               private static const SET_TAG_TRUE:RegExp        =/^ \s* set \s+(\S+)\s* $/isx;
-               private static const EXIT:RegExp                        =/^ \s* exit \s* $/isx;
+               private static const ASSIGNMENT_EVAL:RegExp             =/^ \s* (\S+) \s* \:      \s* eval \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
+               private static const ASSIGNMENT_TAGVALUE:RegExp =/^ \s* (\S+) \s* \:      \s* tag  \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
+               private static const ASSIGNMENT:RegExp                  =/^ \s* (\S+) \s* \:      \s*          (.+?) \s*                   $/sx;
+               private static const SET_TAG_EVAL:RegExp                =/^ \s* set \s+(\S+)\s* = \s* eval \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
+               private static const SET_TAG_TAGVALUE:RegExp    =/^ \s* set \s+(\S+)\s* = \s* tag  \s* \( \s* ' (.+?) ' \s* \) \s* $/isx;
+               private static const SET_TAG:RegExp                             =/^ \s* set \s+(\S+)\s* = \s*          (.+?) \s*                   $/isx;
+               private static const SET_TAG_TRUE:RegExp                =/^ \s* set \s+(\S+)\s* $/isx;
+               private static const DELETE_TAG:RegExp                  =/^ \s* delete \s+(\S+)\s* $/isx;
+               private static const EXIT:RegExp                                =/^ \s* exit \s* $/isx;
 
                private static const oZOOM:uint=2;
                private static const oGROUP:uint=3;
@@ -250,6 +255,14 @@ package net.systemeD.halcyon.styleparser {
                        return sl;
                }
 
+               /** Run instruction styles only, for CSSTransform. */
+               public function runInstructions(obj:Entity, tags:Object):Object {
+                       for each (var sc:StyleChooser in choosers) {
+                               tags=sc.runInstructions(obj,tags);
+                       }
+                       return tags;
+               }
+
                // ---------------------------------------------------------------------------------------------------------
                // Loading stylesheet
 
@@ -430,11 +443,14 @@ package net.systemeD.halcyon.styleparser {
                        var xs:InstructionStyle=new InstructionStyle(); 
 
                        for each (a in s.split(';')) {
-                               if ((o=ASSIGNMENT_EVAL.exec(a)))   { t[o[1].replace(DASH,'_')]=saveEval(o[2]); }
-                               else if ((o=ASSIGNMENT.exec(a)))   { t[o[1].replace(DASH,'_')]=o[2]; }
-                               else if ((o=SET_TAG_EVAL.exec(a))) { xs.addSetTag(o[1],saveEval(o[2])); }
-                               else if ((o=SET_TAG.exec(a)))      { xs.addSetTag(o[1],o[2]); }
-                               else if ((o=SET_TAG_TRUE.exec(a))) { xs.addSetTag(o[1],true); }
+                               if      ((o=ASSIGNMENT_EVAL.exec(a)))           { t[o[1].replace(DASH,'_')]=saveEval(o[2]); }
+                               else if ((o=ASSIGNMENT_TAGVALUE.exec(a)))       { t[o[1].replace(DASH,'_')]=new TagValue(o[2]); }
+                               else if ((o=ASSIGNMENT.exec(a)))                        { t[o[1].replace(DASH,'_')]=o[2]; }
+                               else if ((o=SET_TAG_EVAL.exec(a)))                      { xs.addSetTag(o[1],saveEval(o[2])); }
+                               else if ((o=SET_TAG_TAGVALUE.exec(a)))          { xs.addSetTag(o[1],new TagValue(o[2])); }
+                               else if ((o=SET_TAG.exec(a)))                           { xs.addSetTag(o[1],o[2]); }
+                               else if ((o=SET_TAG_TRUE.exec(a)))                      { xs.addSetTag(o[1],true); }
+                               else if ((o=DELETE_TAG.exec(a)))                        { xs.addSetTag(o[1],''); }
                                else if ((o=EXIT.exec(a))) { xs.setPropertyFromString('breaker',true); }
                        }
 
@@ -517,7 +533,7 @@ package net.systemeD.halcyon.styleparser {
 
         public static function parseCSSColor(colorStr:String):uint {
             colorStr = colorStr.toLowerCase();
-            if (CSSCOLORS[colorStr]) {
+            if (CSSCOLORS[colorStr] != undefined) {
                 return CSSCOLORS[colorStr];
             } else {
                 var match:Object = HEX.exec(colorStr);