EscValue EscFromStdValue(const Value& v) { EscValue r; Time t; if(!IsNull(v)) switch(v.GetType()) { case BOOL_V: case INT_V: case INT64_V: case DOUBLE_V: r = (double)v; break; case STRING_V: case WSTRING_V: r = (WString)v; break; case TIME_V: t = v; r.MapSet("hour", t.hour); r.MapSet("minute", t.minute); r.MapSet("second", t.second); case DATE_V: t = v; r.MapSet("year", t.year); r.MapSet("month", t.month); r.MapSet("day", t.day); break; case VALUEARRAY_V: ValueArray va = v; r.SetEmptyArray(); for(int i = 0; i < va.GetCount(); i++) r.ArrayAdd(EscFromStdValue(va[i])); } return r; }
Font FontEsc(EscValue v) { if(!v.IsMap()) return Null; const VectorMap<EscValue, EscValue>& m = v.GetMap(); int q = m.Find("Height"); if(q < 0) return Null; const EscLambda& l = m[q].GetLambda(); if(!dynamic_cast<SIC_Font *>(l.handle)) return Null; Font f = ((SIC_Font *)l.handle)->font; if(f.GetHeight() == 0) f.Height(StdFont().GetHeight()); return f; }
void EscValue::MapSet(EscValue key, EscValue value) { LTIMING("MapSet"); if(IsVoid()) SetEmptyMap(); VectorMap<EscValue, EscValue>& m = CloneMap(); int q = m.Find(key); if(q >= 0) { if(value.IsVoid()) { m.Unlink(q); map->count--; } else m[q] = value; } else if(!value.IsVoid()) { map->count++; m.Add(key, value); } }
EscDraw::EscDraw(EscValue& v, Draw& w) : w(w) { v.Escape("DrawRect(...)", this, THISBACK(DrawRect)); v.Escape("DrawLine(...)", this, THISBACK(DrawLine)); v.Escape("DrawText(...)", this, THISBACK(DrawText)); v.Escape("DrawSmartText(...)", this, THISBACK(DrawSmartText)); v.Escape("DrawQtf(...)", this, THISBACK(DrawQtf)); v.Escape("GetTextSize(...)", this, THISBACK(GetTextSize)); v.Escape("DrawImage(...)", this, THISBACK(DrawImage)); v.Escape("DrawImageColor(...)", this, THISBACK(DrawImageColor)); }
Value StdValueFromEsc(const EscValue& v) { if(v.IsNumber()) return v.GetNumber(); if(v.IsArray()) return (WString)v; if(IsTime(v)) return Time(v.GetFieldInt("year"), v.GetFieldInt("month"), v.GetFieldInt("day"), v.GetFieldInt("hour"), v.GetFieldInt("minute"), v.GetFieldInt("second")); if(IsDate(v)) return Date(v.GetFieldInt("year"), v.GetFieldInt("month"), v.GetFieldInt("day")); return Value(); }
Point PointEsc(EscValue v) { return Point(v.GetFieldInt("x"), v.GetFieldInt("y")); }
Size SizeEsc(EscValue v) { return Size(v.GetFieldInt("cx"), v.GetFieldInt("cy")); }
Rect RectEsc(EscValue v) { return Rect(v.GetFieldInt("left"), v.GetFieldInt("top"), v.GetFieldInt("right"), v.GetFieldInt("bottom")); }
Color ColorEsc(EscValue v) { return v.IsVoid() ? Color(Null) : Color(v.GetFieldInt("r"), v.GetFieldInt("g"), v.GetFieldInt("b")); }
SIC_Font(EscValue& v) { v.Escape("Height(h)", this, THISBACK(Height)); v.Escape("Bold(...)", this, THISBACK(Bold)); v.Escape("Italic(...)", this, THISBACK(Italic)); v.Escape("Underline(...)", this, THISBACK(Underline)); }