using System; using System.Collections.Generic; using System.Linq; using CPF.Drawing; using CPF.ReoGrid.Drawing; namespace CPF.ReoGrid.Common { internal sealed class ResourcePoolManager : IDisposable { internal ResourcePoolManager() { } public SolidColorBrush GetBrush(Color color) { bool flag = color.A == 0; SolidColorBrush result; if (flag) { result = null; } else { Dictionary obj = this.cachedBrushes; lock (obj) { SolidColorBrush solidColorBrush; bool flag3 = this.cachedBrushes.TryGetValue(color, out solidColorBrush); if (flag3) { result = solidColorBrush; } else { solidColorBrush = new SolidColorBrush(color); this.cachedBrushes.Add(color, solidColorBrush); bool flag4 = this.cachedBrushes.Count % 10 == 0; if (flag4) { Logger.Log("resource pool", "solid brush count: " + this.cachedBrushes.Count.ToString()); } result = solidColorBrush; } } } return result; } public CPFPen GetPen(Color color) { return this.GetPen(color, 1f, DashStyles.Solid); } public CPFPen GetPen(Color color, float weight, DashStyles style) { bool flag = color.A == 0; CPFPen result; if (flag) { result = null; } else { Dictionary> obj = this.cachedPens; CPFPen cpfpen; lock (obj) { List list; bool flag3 = !this.cachedPens.TryGetValue(color, out list); if (flag3) { list = (this.cachedPens[color] = new List()); list.Add(cpfpen = new CPFPen(color, weight)); cpfpen.DashStyle = style; } else { List obj2 = list; lock (obj2) { cpfpen = list.FirstOrDefault((CPFPen p) => p.Stroke.Width == weight && p.DashStyle == style); } bool flag5 = cpfpen == null; if (flag5) { list.Add(cpfpen = new CPFPen(color, weight)); cpfpen.DashStyle = style; } } } result = cpfpen; } return result; } public static Font CreateFont(string familyName, double emSizeD, FontStyles wfs) { float num = (float)emSizeD; return new Font(familyName, num * 96f / 72f, wfs); } public Font GetFont(string familyName, double emSizeD, FontStyles wfs) { bool flag = string.IsNullOrEmpty(familyName); if (flag) { familyName = "宋体"; } return ResourcePoolManager.CreateFont(familyName, emSizeD, wfs); } internal void ReleaseAllResources() { int num = this.cachedPens.Count + this.cachedBrushes.Count; foreach (List list in this.cachedPens.Values) { list.Clear(); } this.cachedPens.Clear(); this.cachedBrushes.Clear(); } public void Dispose() { this.ReleaseAllResources(); } private Dictionary cachedBrushes = new Dictionary(); private Dictionary> cachedPens = new Dictionary>(); internal class NoAvailableFontStyleException : Exception { } } }