Esempio n. 1
0
        //private static Size GetTextExtent(
        //    IntPtr hdc, string text, int textLen, int maxWidth, out int fitLength, out int[] extents
        //) {
        //    Int32 bOk;
        //    SIZE size;
        //    extents = new int[text.Length];

        //    unsafe {
        //        fixed (int* pExtents = extents)
        //        fixed (int* pFitLength = &fitLength)
        //            bOk = Gdi32PI.GetTextExtentExPointW(hdc, text, textLen, maxWidth, pFitLength, pExtents, &size);
        //        //Debug.Assert(bOk != 0, "failed to calculate text width");
        //        return new Size(size.cx, size.cy);
        //    }
        //}

        private static Size GetTextExtent(
            IntPtr hdc, string text, int textLen, int maxWidth, out int fitLength, out int[] extents
            )
        {
            SIZE size;

            extents = new int[text.Length];
            var result = Gdi32PI.GetTextExtentExPointW(hdc, text, textLen, maxWidth, out fitLength, extents, out size);

            return(new Size(size.cx, size.cy));
        }
Esempio n. 2
0
        // ========================================
        // constructor
        // ========================================
        public Gdi32NullGraphics()
        {
            _hdc = Gdi32PI.CreateCompatibleDC(IntPtr.Zero);

            if (_hdc == IntPtr.Zero)
            {
                ExceptionUtil.ThrowOnWin32Error("CreateCompatibleDC returned NULL");
            }

            _graphics = Graphics.FromHdc(_hdc);
        }
Esempio n. 3
0
        public static void CopyGraphics(Graphics tgtGra, Rectangle tgtRect, Graphics srcGra, Point srcLoc)
        {
            var srcHdc = srcGra.GetHdc();
            var tgtHdc = tgtGra.GetHdc();

            try {
                Gdi32PI.BitBlt(
                    tgtHdc, tgtRect.X, tgtRect.Y, tgtRect.Width, tgtRect.Height, srcHdc, srcLoc.X, srcLoc.Y, TernaryRasterOperations.SRCCOPY
                    );
            } finally {
                srcGra.ReleaseHdc(srcHdc);
                tgtGra.ReleaseHdc(tgtHdc);
            }
        }
Esempio n. 4
0
 protected virtual void Dispose(bool disposing)
 {
     if (_hOldFont != IntPtr.Zero)
     {
         Gdi32PI.SelectObject(_hdc, _hOldFont);
     }
     if (_hfont != IntPtr.Zero)
     {
         Gdi32PI.DeleteObject(_hfont);
     }
     TextAlignMode = _oldAlignMode;
     _graphics.ReleaseHdc(_hdc);
     _graphics = null;
 }
Esempio n. 5
0
        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    _graphics.Dispose();
                    _graphics = null;
                }

                Gdi32PI.DeleteDC(_hdc);
                _disposed = true;
            }
        }
Esempio n. 6
0
        // ========================================
        // method
        // ========================================
        // todo: tab文字を自前で描画
        public void DrawText(string text, Rectangle rect)
        {
            var r = new RECT()
            {
                left   = rect.Left,
                top    = rect.Top,
                right  = rect.Right,
                bottom = rect.Bottom,
            };

            if (
                !Gdi32PI.ExtTextOutW(
                    _hdc,
                    rect.Left,
                    rect.Top,
                    ExtTextOutFormatOptions.ETO_NONE,
                    ref r,
                    text,
                    text.Length,
                    null
                    )
                )
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            //var flags =
            //    DRAWTEXTFORMATS.DT_LEFT | DRAWTEXTFORMATS.DT_TOP | DRAWTEXTFORMATS.DT_TABSTOP | //DRAWTEXTFORMATS.DT_NOCLIP |
            //    DRAWTEXTFORMATS.DT_NOPREFIX | DRAWTEXTFORMATS.DT_SINGLELINE;
            //var paras = new DRAWTEXTPARAMS();
            //paras.CalcCbSize();
            //paras.iTabLength = 4;
            //paras.iLeftMargin = paras.iRightMargin = 0;
            //User32PI.DrawTextExW(
            //    _hdc,
            //    text,
            //    text.Length,
            //    ref r,
            //    flags,
            //    ref paras
            //);
        }
Esempio n. 7
0
 // ========================================
 // constructor
 // ========================================
 public Gdi32TextRenderer(Graphics g)
 {
     _graphics     = g;
     _hdc          = _graphics.GetHdc();
     _oldAlignMode = Gdi32PI.GetTextAlign(_hdc);
 }