private void URemove(string path) { CacheEntry entry = (CacheEntry)items [path]; if (entry != null) { items.Remove(path); items_mru.Remove(entry); entry.Dispose(); } }
private void URemove(SafeUri uri) { CacheEntry entry = null; if (items.ContainsKey(uri)) { entry = items[uri]; items.Remove(uri); items_mru.Remove(entry); entry.Dispose(); } }
bool ShrinkIfNeeded() { int num = 0; while ((items_mru.Count - num) > 10 && total_size > max_size) { CacheEntry entry = items_mru [num++]; items.Remove(entry.Uri); entry.Dispose(); } if (num > 0) { //System.Console.WriteLine ("removing {0} out of {3} ({1} > {2})", // num, total_size, max_size, items_mru.Count); items_mru.RemoveRange(0, num); return(true); } return(false); }
public Bitmap Get( Graphics graphics, string text, Font font, RotateFlipType rotation, Color textColor, Color outlineColor, StringFormat stringFormat, SizeF size ) { CacheEntry ce = null; if (size.Width < 1) { size.Width = 1; } if (size.Height < 1) { size.Height = 1; } bool needNewBitmap = true; if (TryGetValue(text, out ce)) { if ((ce.Font == font) && (ce.TextColor == textColor) && (ce.OutlineColor == outlineColor) && (ce.Size == size)) { needNewBitmap = false; } } if (needNewBitmap) { var fullSize = graphics.MeasureString(text, font, new PointF(0, 0), stringFormat); var bitmap = new Bitmap( (int)Math.Ceiling(Math.Min(size.Width, fullSize.Width)), (int)Math.Ceiling(Math.Min(size.Height, fullSize.Height)), System.Drawing.Imaging.PixelFormat.Format32bppPArgb ); using (var g = Graphics.FromImage(bitmap)) { g.Clear(Color.FromArgb(0, outlineColor)); g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.GammaCorrected; using (var brush = new SolidBrush(textColor)) using (var innerPen = new Pen(Color.FromArgb(160, textColor), 0.5f)) using (var pen = new Pen(outlineColor, 3f)) using (var path = new GraphicsPath()) { float emSize = g.DpiY * font.Size / 72f; path.AddString( text, font.FontFamily, (int)font.Style, emSize, new RectangleF(0f, 0f, size.Width, size.Height), stringFormat ); innerPen.LineJoin = pen.LineJoin = LineJoin.Round; g.DrawPath(pen, path); // Compensate for inadequate gamma correction in GDI+ if (textColor.GetBrightness() < outlineColor.GetBrightness()) { g.DrawPath(innerPen, path); } g.FillPath(brush, path); } } if (ce != null) { Remove(ce.Text); ce.Dispose(); } bitmap.RotateFlip(rotation); ce = new CacheEntry { Bitmap = bitmap, Font = font, OutlineColor = outlineColor, TextColor = textColor, Text = text, Size = size }; Add(ce); } var result = ce.Bitmap; return(result); }