public static VisualLineImageCache GetInstance()
 {
     if (_instance == null)
     {
         _instance = new VisualLineImageCache();
     }
     return(_instance);
 }
        public void Render(DrawingContext drawingContext, RenderContext renderContext)
        {
            // DrawingImage会自动Trimming,怎么解决这个问题?
#if false
            DrawingImage cachedImg    = VisualLineImageCache.GetInstance().GetCache(Document, Line);
            DrawingGroup drawingGroup = null;
            if (cachedImg == null)
            {
                renderContext.PrepareRendering();

                drawingGroup = new DrawingGroup();
                foreach (VisualLineElement elem in Elements)
                {
                    var drawings = elem.GenerateDrawings(drawingContext, renderContext);
                    if (drawings != null)
                    {
                        foreach (var drawing in drawings)
                        {
                            drawingGroup.Children.Add(drawing);
                        }
                    }
                }
                cachedImg = new DrawingImage(drawingGroup);
                VisualLineImageCache.GetInstance().AddCache(Document, Line, cachedImg);

                renderContext.FinishRendering();
            }
            cachedImg.Freeze();
            Point startPos = renderContext.Offset;
            startPos.Y += (Owner.GlyphOption.LineHeight - cachedImg.Height);
            drawingContext.DrawImage(cachedImg, new Rect(startPos, new Size(cachedImg.Width, cachedImg.Height)));
            drawingContext.DrawDrawing(drawingGroup);
#else
            renderContext.PrepareRendering();

            foreach (VisualLineElement elem in Elements)
            {
                var drawings = elem.GenerateDrawings(drawingContext, renderContext);
                if (drawings != null)
                {
                    foreach (var drawing in drawings)
                    {
                        drawingContext.DrawDrawing(drawing);
                    }
                }
            }

            renderContext.FinishRendering();
#endif
        }
 public void Dispose()
 {
     VisualLineImageCache.GetInstance().RemoveCache(Document, Line);
 }