public Operator(string name, Form form, Length lSpace, Length rSpace, bool stretchy, bool fence, bool accent, bool largeOp, bool moveableLimits, bool separator, Length minSize, Length maxSize, bool symmetric) { Name = name; Form = form; LSpace = lSpace; RSpace = rSpace; Fence = fence; Separator = separator; Stretchy = stretchy; MaxSize = maxSize; MinSize = minSize; Accent = accent; LargeOp = largeOp; MoveableLimits = moveableLimits; Symmetric = symmetric; }
/// <summary> /// parse a list of length types, each one separated by one or more space /// </summary> internal static Length[] ParseLengths(string s, Length[] def) { Length[] result = def; if(s.Length > 0) { string[] lengths = s.Split(' '); int count = 0; int li = 0; // although technically wrong, the string may be separated by more than // one space between strings, so deal with it. for(int i = 0; i < lengths.Length; i++) { if(lengths[i].Length > 0) count++; } if(count > 0) { result = new Length[count]; for(int i = 0; i < result.Length; i++) { while(lengths[li].Length == 0) li++; result[i] = ParseLength(lengths[li++], def[i < def.Length ? i : def.Length - 1]); } } } return result; }
internal static string UnparseLengths(Length[] lengths) { return ""; }
internal static Length ParseLength(String s, Length def) { Length result = def; try { if(s.Length > 0) { if(s.EndsWith("%")) { result.Value = Int32.Parse(s.TrimEnd('%')); result.Type = LengthType.Percentage; } else if(Char.IsDigit(s[0]) && Char.IsDigit(s[s.Length - 1])) { result.Value = Int32.Parse(s); result.Type = LengthType.Percentage; } else if(s.EndsWith("em")) { result.Value = Single.Parse(s.TrimEnd(em)); result.Type = LengthType.Em; } else if(s.EndsWith("px")) { result.Value = Single.Parse(s.TrimEnd(px)); result.Type = LengthType.Px; } else if(s.EndsWith("in")) { result.Value = Single.Parse(s.TrimEnd(inch)); result.Type = LengthType.In; } else if(s.EndsWith("cm")) { result.Value = Single.Parse(s.TrimEnd(cm)); result.Type = LengthType.Cm; } else if(s.EndsWith("mm")) { result.Value = Single.Parse(s.TrimEnd(mm)); result.Type = LengthType.Mm; } else if(s.EndsWith("pt")) { result.Value = Single.Parse(s.TrimEnd(pt)); result.Type = LengthType.Pt; } else if(s.EndsWith("pc")) { result.Value = Single.Parse(s.TrimEnd(pc)); result.Type = LengthType.Pc; } else if(s.EndsWith("ex")) { result.Value = Single.Parse(s.TrimEnd(ex)); result.Type = LengthType.Ex; } else { result.Value = 0; switch(s) { case "undefined": result.Type = LengthType.Undefined; break; case "pure": result.Type = LengthType.Pure; break; case "infinity": result.Type = LengthType.Infinity; break; case "veryverythin": result.Type = LengthType.VeryVeryThin; break; case "verythin": result.Type = LengthType.VeryThin; break; case "thin": result.Type = LengthType.Thin; break; case "medium": result.Type = LengthType.Medium; break; case "thick": result.Type = LengthType.Thick; break; case "verythick": result.Type = LengthType.VeryThick; break; case "veryverythick": result.Type = LengthType.VeryVeryThick; break; case "negativeveryverythin": result.Type = LengthType.NegativeVeryVeryThin; break; case "negativeverythin": result.Type = LengthType.NegativeVeryThin; break; case "negativethin": result.Type = LengthType.NegativeThin; break; case "negativemedium": result.Type = LengthType.NegativeMedium; break; case "negativethick": result.Type = LengthType.NegativeThick; break; case "negativeverythick": result.Type = LengthType.NegativeVeryThick; break; case "negativeveryverythick": result.Type = LengthType.NegativeVeryVeryThick; break; case "small": result.Type = LengthType.Small; break; case "normal": result.Type = LengthType.Normal; break; case "big": result.Type = LengthType.Big; break; case "auto": result.Type = LengthType.Auto; break; case "fit": result.Type = LengthType.Fit; break; default: result = def; break; } } } } catch(Exception e) { Debug.WriteLine("Warning, invalid length format: \"" + s + "\", " + e.StackTrace); result = def; } return result; }