Пример #1
0
 private IValue HandleValue(Term term)
 {
     return term.Function != null ? HandleFunctionValue(term.Function) : new StringValue(term.Value);
 }
Пример #2
0
        void term(out Term trm)
        {
            trm = new Term();
            string val = "";
            Expression exp = null;
            string ident = null;

            if (la.kind == 7 || la.kind == 8) {
                QuotedString(out val);
                trm.Value = val; trm.Type = TermType.String;
            } else if (la.kind == 9) {
                URI(out val);
                trm.Value = val; trm.Type = TermType.Url;
            } else if (la.kind == 46) {
                Get();
                identity(out ident);
                trm.Value = "U\\" + ident; trm.Type = TermType.Unicode;
            } else if (la.kind == 33) {
                HexValue(out val);
                trm.Value = val; trm.Type = TermType.Hex;
            } else if (StartOf(15)) {
                bool minus = false;
                if (la.kind == 24) {
                    Get();
                    minus = true;
                }
                if (StartOf(16)) {
                    identity(out ident);
                    trm.Value = ident; trm.Type = TermType.String;
                    if (minus) { trm.Value = "-" + trm.Value; }
                    if (StartOf(17)) {
                        while (la.kind == 34 || la.kind == 36 || la.kind == 43) {
                            if (la.kind == 43) {
                                Get();
                                trm.Value += t.val;
                                if (la.kind == 43) {
                                    Get();
                                    trm.Value += t.val;
                                }
                                if (la.kind == 24) {
                                    Get();
                                    trm.Value += t.val;
                                }
                                identity(out ident);
                                trm.Value += ident;
                            } else if (la.kind == 34) {
                                Get();
                                trm.Value += t.val;
                                if (la.kind == 24) {
                                    Get();
                                    trm.Value += t.val;
                                }
                                identity(out ident);
                                trm.Value += ident;
                            } else {
                                Get();
                                trm.Value += t.val;
                                if (la.kind == 24) {
                                    Get();
                                    trm.Value += t.val;
                                }
                                if (StartOf(16)) {
                                    identity(out ident);
                                    trm.Value += ident;
                                } else if (StartOf(18)) {
                                    while (la.kind == 3) {
                                        Get();
                                        trm.Value += t.val;
                                    }
                                } else SynErr(56);
                            }
                        }
                    }
                    if (la.kind == 10) {
                        Get();
                        while (la.kind == 4) {
                            Get();
                        }
                        expr(out exp);
                        Function func = new Function();
                        func.Name = trm.Value;
                        func.Expression = exp;
                        trm.Value = null;
                        trm.Function = func;
                        trm.Type = TermType.Function;

                        while (la.kind == 4) {
                            Get();
                        }
                        Expect(11);
                    }
                } else if (StartOf(15)) {
                    if (la.kind == 29) {
                        Get();
                        trm.Sign = '+';
                    }
                    if (minus) { trm.Sign = '-'; }
                    while (la.kind == 3) {
                        Get();
                        val += t.val;
                    }
                    if (la.kind == 34) {
                        Get();
                        val += t.val;
                        while (la.kind == 3) {
                            Get();
                            val += t.val;
                        }
                    }
                    if (StartOf(19)) {
                        if (la.val.ToLower().Equals("n")) {
                            Expect(22);
                            val += t.val;
                            if (la.kind == 24 || la.kind == 29) {
                                if (la.kind == 29) {
                                    Get();
                                    val += t.val;
                                } else {
                                    Get();
                                    val += t.val;
                                }
                                Expect(3);
                                val += t.val;
                                while (la.kind == 3) {
                                    Get();
                                    val += t.val;
                                }
                            }
                        } else if (la.kind == 47) {
                            Get();
                            trm.Unit = Unit.Percent;
                        } else {
                            if (IsUnit()) {
                                identity(out ident);
                                try {
                                    trm.Unit = (Unit)Enum.Parse(typeof(Unit), ident, true);
                                } catch {
                                    errors.SemErr(t.line, t.col, string.Format("Unrecognized unit '{0}'", ident));
                                }

                            }
                        }
                    }
                    trm.Value = val; trm.Type = TermType.Number;
                } else SynErr(57);
            } else SynErr(58);
        }
Пример #3
0
 private int GetRGBValue(Term t)
 {
     try {
         if (t.Unit.HasValue && t.Unit.Value == BoneSoft.CSS.Unit.Percent) {
             return (int)(255f * float.Parse(t.Value) / 100f);
         }
         return int.Parse(t.Value);
     } catch {}
     return 0;
 }
Пример #4
0
 private int GetHueValue(Term t)
 {
     // 0 - 360
     try {
         return (int)(float.Parse(t.Value) * 255f / 360f);
     } catch {}
     return 0;
 }
Пример #5
0
        private void MakeUriTagRelative(Term term, string fullCssPath)
        {
            // if the term is an absolute URI then we'll just move on
            var uri = new Uri(term.Value, UriKind.RelativeOrAbsolute);

            if (term.Value.StartsWith("/") || uri.IsAbsoluteUri)
                return;

            // make the url absolute
            var absolute = new Uri(Path.Combine(Path.GetDirectoryName(fullCssPath), uri.ToString()));

            var resourceUri = new Uri(HttpContext.Server.MapPath("~/resources/css/"));

            // and make it relative again so we can use it :-)
            term.Value = resourceUri.MakeRelativeUri(absolute).ToString();
        }
Пример #6
0
 public static void RenderTerm(StringBuilder sb, Term term)
 {
     if (term.Type == TermType.Function)
     {
         RenderFunction(sb, term.Function);
     }
     else if (term.Type == TermType.Url)
     {
         sb.AppendFormat("url('{0}')", term.Value);
     }
     else if (term.Type == TermType.Unicode)
     {
         sb.AppendFormat("U\\{0}", term.Value.ToUpper());
     }
     else if (term.Type == TermType.Hex)
     {
         sb.Append(term.Value.ToUpper());
     }
     else
     {
         if (term.Sign.HasValue) {
             sb.Append(term.Sign.Value);
         }
         sb.Append(term.Value);
         if (term.Unit.HasValue)
         {
             if (term.Unit.Value == BoneSoft.CSS.Unit.Percent)
             {
                 sb.Append("%");
             }
             else
             {
                 sb.Append(UnitOutput.ToString(term.Unit.Value));
             }
         }
     }
 }
Пример #7
0
        static string Render(Term t)
        {
            StringBuilder txt = new StringBuilder();
            // leave off seperator

            if (t.Type == TermType.Function) {
                txt.AppendFormat("<span class=\"value_function function\">{0}</span>", Render(t.Function));
            } else if (t.Type == TermType.Url) {
                txt.AppendFormat("<span class=\"value_url\">url('{0}')</span>", t.Value);
            } else if (t.Type == TermType.Unicode) {
                txt.AppendFormat("<span class=\"value_unicode\">U\\{0}</span>", t.Value.ToUpper());
            } else if (t.Type == TermType.Hex) {
                txt.AppendFormat("<span class=\"value_hex{1}\">{0}</span>", t.Value.ToUpper(), t.IsColor ? " value_color" : "");
            } else {
                if (t.Type == TermType.Number) {
                    txt.Append("<span class=\"value_number\">");
                } else {
                    txt.AppendFormat("<span class=\"value_string{0}\">", t.IsColor ? " value_color" : "");
                }
                if (t.Sign.HasValue) { txt.AppendFormat("<span class=\"values_sign\">{0}</span>", t.Sign.Value); }
                txt.Append(t.Value);
                if (t.Unit.HasValue) {
                    txt.Append("<span class=\"values_unit\">");
                    if (t.Unit.Value == BoneSoft.CSS.Unit.Percent) {
                        txt.Append("%");
                    } else {
                        txt.Append(UnitOutput.ToString(t.Unit.Value));
                    }
                    txt.Append("</span>");
                }
                txt.Append("</span>");
            }

            return txt.ToString();
        }