public void Reset(
            Font font,
            int visibleWidth)
        {
            ClearCaches();

            if (hdcOffscreenStrip != null)
            {
                hdcOffscreenStrip.Dispose();
                hdcOffscreenStrip = null;
            }
            if (offscreenStrip != null)
            {
                offscreenStrip.Dispose();
                offscreenStrip = null;
            }
            this.visibleWidth = visibleWidth;
            // allocation of offscreenStrip is deferred until HDC is available to make compatible with

            this.font = font;
        }
        public void Dispose()
        {
            ClearCaches();

            if (hdcOffscreenStrip != null)
            {
                hdcOffscreenStrip.Dispose();
                hdcOffscreenStrip = null;
            }
            if (offscreenStrip != null)
            {
                offscreenStrip.Dispose();
                offscreenStrip = null;
            }

            GC.SuppressFinalize(this);
        }
Esempio n. 3
0
        public GDIOffscreenBitmap(Graphics graphicsCompatibleWith, int width, int height)
        {
            if ((width <= 0) || (height <= 0))
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }

            // Create GDI objects for offscreen. Must be created through GDI because Uniscribe/DirectWrite do not
            // like objects created by GDI+ and will draw with very poor quality on them.
            using (GraphicsHDC hDC = new GraphicsHDC(graphicsCompatibleWith))
            {
                this.hDC = GDIDC.CreateCompatibleDC(hDC);
                hBitmap = new GDIBitmap(width, height, PixelFormat.Format32bppArgb);
                GDI.SelectObject(this.hDC, hBitmap);
            }
            graphics = Graphics.FromHdc(hDC);
        }
        public ITextInfo AnalyzeText(
            Graphics graphics,
            Font font,
            int fontHeight,
            string line)
        {
            int index;
            if ((index = line.IndexOfAny(new char[] { '\r', '\n' })) >= 0)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }

            if (offscreenStrip == null)
            {
                using (GraphicsHDC hdc = new GraphicsHDC(graphics))
                {
                    offscreenStrip = new GDIBitmap(visibleWidth, fontHeight, hdc);
                }
                Debug.Assert(hdcOffscreenStrip == null);
                hdcOffscreenStrip = GDIDC.Create(offscreenStrip);
            }

            using (Pin<string> pinLine = new Pin<string>(line))
            {
                return TextItems.AnalyzeText(
                    this,
                    hdcOffscreenStrip,
                    pinLine.AddrOfPinnedObject(),
                    new FontRunInfo[] { new FontRunInfo(line.Length, font, fontHeight) });
            }
        }
Esempio n. 5
0
 public static GDIDC Create(GDIBitmap bitmap)
 {
     IntPtr hdc = GDI.CreateCompatibleDC(IntPtr.Zero);
     if (hdc == IntPtr.Zero)
     {
         Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
     }
     GDIDC gdidc = new GDIDC(hdc);
     GDI.SelectObject(hdc, bitmap);
     return gdidc;
 }