private int GetHueValue(Term t) { // 0 - 360 try { return (int)(float.Parse(t.Value) * 255f / 360f); } catch { } return 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 == 45) { Get(); identity(out ident); trm.Value = "U\\" + ident; trm.Type = TermType.Unicode; } else if (la.kind == 32) { HexValue(out val); trm.Value = val; trm.Type = TermType.Hex; } else if (StartOf(3)) { identity(out ident); trm.Value = ident; trm.Type = TermType.String; if (StartOf(14)) { while (la.kind == 33 || la.kind == 35 || la.kind == 42) { if (la.kind == 42) { Get(); trm.Value += t.val; if (la.kind == 42) { Get(); trm.Value += t.val; } identity(out ident); trm.Value += ident; } else if (la.kind == 33) { Get(); trm.Value += t.val; identity(out ident); trm.Value += ident; } else { Get(); trm.Value += t.val; if (StartOf(3)) { identity(out ident); trm.Value += ident; } else if (StartOf(15)) { while (la.kind == 3) { Get(); trm.Value += t.val; } } else SynErr(56); } } } if (la.kind == 10) { 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; Expect(11); } } else if (StartOf(16)) { if (la.kind == 28 || la.kind == 46) { if (la.kind == 46) { Get(); trm.Sign = '-'; } else { Get(); trm.Sign = '+'; } } while (la.kind == 3) { Get(); val += t.val; } if (la.kind == 33) { Get(); val += t.val; while (la.kind == 3) { Get(); val += t.val; } } if (StartOf(17)) { if (la.val.ToLower().Equals("n")) { Expect(22); val += t.val; if (la.kind == 28 || la.kind == 46) { if (la.kind == 28) { 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); }
private int GetRGBValue(Term t) { try { if (t.Unit.HasValue && t.Unit.Value == JinxBot.Controls.CSS.Unit.Percent) { return (int)(255f * float.Parse(t.Value) / 100f); } return int.Parse(t.Value); } catch { } return 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 == JinxBot.Controls.CSS.Unit.Percent) { txt.Append("%"); } else { txt.Append(UnitOutput.ToString(t.Unit.Value)); } txt.Append("</span>"); } txt.Append("</span>"); } return txt.ToString(); }