Ejemplo n.º 1
0
        protected override object EvaluateIDENTIFIERCOLONValueListSEMICOLON(CssNode node)
        {
            string IDENTIFIER = (string)Evaluate(node.Nodes[0]);

            object[] ValueList = (object[])Evaluate(node.Nodes[2]);

            if (ValueList.Length == 1)
            {
                if (IDENTIFIER.Equals("TextAlign"))
                {
                    this._styleRule.Declarations.Add(new StyleDeclaration(IDENTIFIER, System.Enum.Parse(typeof(System.Drawing.ContentAlignment), (string)ValueList[0])));
                }
                else
                {
                    this._styleRule.Declarations.Add(new StyleDeclaration(IDENTIFIER, ValueList[0]));
                }
            }
            else if (IDENTIFIER.Equals("Font"))
            {
                Css.Font font;
                if (ValueList.Length == 2)
                {
                    font = new Css.Font((string)ValueList[0], System.Convert.ToSingle(ValueList[1]));
                }
                else if (ValueList.Length == 3)
                {
                    if (ValueList[2].Equals("bold"))
                    {
                        font = new Css.Font((string)ValueList[0], System.Convert.ToSingle(ValueList[1]), true);
                    }
                    else
                    {
                        throw new System.Exception("Invalid font.");
                    }
                }
                else
                {
                    throw new System.Exception("Invalid font.");
                }
                this._styleRule.Declarations.Add(new StyleDeclaration(IDENTIFIER, font));
            }
            else if (IDENTIFIER.Equals("Colors"))
            {
                string[] colors = new string[ValueList.Length];
                for (int i = 0; i < ValueList.Length; i++)
                {
                    colors[i] = (string)ValueList[i];
                }
                this._styleRule.Declarations.Add(new StyleDeclaration(IDENTIFIER, colors));
            }
            else
            {
                throw new System.Exception("Invalid declaration.");
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void Write(StyleSheet styleSheet)
        {
            bool first = true;

            foreach (StyleRule styleRule in styleSheet.Rules)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    this._writer.WriteLine();
                }
                this._writer.Write(styleRule.Name);
                if (styleRule is KeyValueStyleRule)
                {
                    KeyValueStyleRule keyValueStyleRule = (KeyValueStyleRule)styleRule;
                    this._writer.Write("[");
                    this._writer.Write(keyValueStyleRule.Key);
                    this._writer.Write("=");
                    this._writer.Write("\"" + keyValueStyleRule.Value + "\"");
                    this._writer.Write("]");
                }
                this._writer.WriteLine();
                this._writer.WriteLine("{");
                foreach (StyleDeclaration styleDeclaration in styleRule.Declarations)
                {
                    this._writer.Write("\t" + styleDeclaration.Name + ": ");
                    if (styleDeclaration.Value is string)
                    {
                        string s = (string)styleDeclaration.Value;
                        if (s.IndexOf(" ") != -1)
                        {
                            this._writer.Write("\"" + s + "\"");
                        }
                        else
                        {
                            this._writer.Write(s);
                        }
                    }
                    else if (styleDeclaration.Value is bool)
                    {
                        this._writer.Write(styleDeclaration.Value.ToString().ToLower());
                    }
                    else if (styleDeclaration.Value is Css.Font)
                    {
                        Css.Font font = (Css.Font)styleDeclaration.Value;
                        this._writer.Write("\"" + font.Name + "\"");
                        this._writer.Write(" ");
                        this._writer.Write(font.Size);
                        if (font.Bold)
                        {
                            this._writer.Write(" ");
                            this._writer.Write("bold");
                        }
                    }
                    else
                    {
                        this._writer.Write(styleDeclaration.Value);
                    }

                    //bool first2 = true;
                    //foreach (object value in styleDeclaration.Values)
                    //{
                    //    if (first2)
                    //    {
                    //        first2 = false;
                    //    }
                    //    else
                    //    {
                    //        this._writer.Write(" ");
                    //    }
                    //    if (value is string)
                    //    {
                    //        string s = (string)value;
                    //        if (s.IndexOf(" ") != -1)
                    //        {
                    //            this._writer.Write("\"" + value + "\"");
                    //        }
                    //        else
                    //        {
                    //            this._writer.Write(value);
                    //        }
                    //    }
                    //    else if (value is bool)
                    //    {
                    //        this._writer.Write(value.ToString().ToLower());
                    //    }
                    //    else
                    //    {
                    //        this._writer.Write(value);
                    //    }
                    //}
                    this._writer.WriteLine(";");
                }
                this._writer.WriteLine("}");
            }
            this._writer.Flush();
        }