Пример #1
0
        static WinGdiFont SetFont(RequestFont font)
        {
            WinGdiFont winFont = WinGdiFontSystem.GetWinGdiFont(font);

            MyWin32.SelectObject(win32MemDc.DC, winFont.CachedHFont());
            return(winFont);
        }
Пример #2
0
        internal static void MeasureCharWidths(IntPtr hFont,
                                               out int[] charWidths,
                                               out NativeTextWin32.FontABC[] abcSizes)
        {
            //only in ascii range
            //current version
            charWidths = new int[MAX_CODEPOINT_NO + 1]; //
            MyWin32.SelectObject(win32MemDc.DC, hFont);
            unsafe
            {
                //see: https://msdn.microsoft.com/en-us/library/ms404377(v=vs.110).aspx
                //A code page contains 256 code points and is zero-based.
                //In most code pages, code points 0 through 127 represent the ASCII character set,
                //and code points 128 through 255 differ significantly between code pages
                abcSizes = new NativeTextWin32.FontABC[MAX_CODEPOINT_NO + 1];
                fixed(NativeTextWin32.FontABC *abc = abcSizes)
                {
                    NativeTextWin32.GetCharABCWidths(win32MemDc.DC, (uint)0, (uint)MAX_CODEPOINT_NO, abc);
                }

                for (int i = 0; i < (MAX_CODEPOINT_NO + 1); ++i)
                {
                    charWidths[i] = abcSizes[i].Sum;
                }
            }
        }
Пример #3
0
 public static void dbugDrawTextOrigin(IntPtr hdc, int x, int y)
 {
     MyWin32.Rectangle(hdc, x, y, x + 20, y + 20);
     MyWin32.MoveToEx(hdc, x, y, 0);
     MyWin32.LineTo(hdc, x + 20, y + 20);
     MyWin32.MoveToEx(hdc, x, y + 20, 0);
     MyWin32.LineTo(hdc, x + 20, y);
 }
Пример #4
0
        public NativeWin32MemoryDc(int w, int h, bool invertImage = false)
        {
            this._width  = w;
            this._height = h;

            memHdc = MyWin32.CreateMemoryHdc(
                IntPtr.Zero,
                w,
                invertImage ? -h : h, //***
                out dib,
                out ppvBits);
        }
Пример #5
0
 public void SetClipRect(int x, int y, int w, int h)
 {
     if (hRgn == IntPtr.Zero)
     {
         //create
         hRgn = MyWin32.CreateRectRgn(0, 0, w, h);
     }
     MyWin32.SetRectRgn(hRgn,
                        x,
                        y,
                        x + w,
                        y + h);
     MyWin32.SelectObject(memHdc, hRgn);
 }
Пример #6
0
        public NativeWin32MemoryDC(int w, int h, bool invertImage = false)
        {
            _width  = w;
            _height = h;

            _invertedImage = invertImage;

            _memHdc = MyWin32.CreateMemoryHdc(
                IntPtr.Zero,
                w,
                invertImage ? -h : h, //***
                out _dib,
                out _ppvBits);
        }
Пример #7
0
        static IntPtr InitFont(string fontName, float emHeight, FontStyle style)
        {
            //see: MSDN, LOGFONT structure
            //https://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
            MyWin32.LOGFONT logFont = new MyWin32.LOGFONT();
            MyWin32.SetFontName(ref logFont, fontName);
            logFont.lfHeight  = -(int)ConvEmSizeInPointsToPixels(emHeight); //minus **
            logFont.lfCharSet = 1;                                          //default
            logFont.lfQuality = 0;                                          //default

            MyWin32.LOGFONT_FontWeight weight =
                ((style & FontStyle.Bold) == FontStyle.Bold) ?
                MyWin32.LOGFONT_FontWeight.FW_BOLD :
                MyWin32.LOGFONT_FontWeight.FW_REGULAR;
            logFont.lfWeight = (int)weight;
            //
            logFont.lfItalic = (byte)(((style & FontStyle.Italic) == FontStyle.Italic) ? 1 : 0);
            return(MyWin32.CreateFontIndirect(ref logFont));
        }
Пример #8
0
        public void Dispose()
        {
            if (isDisposed)
            {
                return;
            }

            if (hRgn != IntPtr.Zero)
            {
                MyWin32.DeleteObject(hRgn);
                hRgn = IntPtr.Zero;
            }


            MyWin32.ReleaseMemoryHdc(memHdc, dib);
            dib        = IntPtr.Zero;
            memHdc     = IntPtr.Zero;
            isDisposed = true;
        }
Пример #9
0
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }

            if (_hRgn != IntPtr.Zero)
            {
                MyWin32.DeleteObject(_hRgn);
                _hRgn = IntPtr.Zero;
            }


            MyWin32.ReleaseMemoryHdc(_memHdc, _dib);
            _dib        = IntPtr.Zero;
            _memHdc     = IntPtr.Zero;
            _isDisposed = true;
        }
Пример #10
0
        /// <summary>
        /// Create a compatible memory HDC from the given HDC.<br/>
        /// The memory HDC can be rendered into without effecting the original HDC.<br/>
        /// The returned memory HDC and <paramref name="dib"/> must be released using <see cref="ReleaseMemoryHdc"/>.
        /// </summary>
        /// <param name="hdc">the HDC to create memory HDC from</param>
        /// <param name="width">the width of the memory HDC to create</param>
        /// <param name="height">the height of the memory HDC to create</param>
        /// <param name="dib">returns used bitmap memory section that must be released when done with memory HDC</param>
        /// <returns>memory HDC</returns>
        public static IntPtr CreateMemoryHdc(IntPtr hdc, int width, int height, out IntPtr dib, out IntPtr ppvBits)
        {
            // Create a memory DC so we can work off-screen
            IntPtr memoryHdc = MyWin32.CreateCompatibleDC(hdc);

            MyWin32.SetBkMode(memoryHdc, 1);
            // Create a device-independent bitmap and select it into our DC
            var info = new Win32.BitMapInfo();

            info.biSize        = Marshal.SizeOf(info);
            info.biWidth       = width;
            info.biHeight      = -height;
            info.biPlanes      = 1;
            info.biBitCount    = 32;
            info.biCompression = 0; // BI_RGB
            dib = MyWin32.CreateDIBSection(hdc, ref info, 0, out ppvBits, IntPtr.Zero, 0);
            MyWin32.SelectObject(memoryHdc, dib);
            return(memoryHdc);
        }
Пример #11
0
        public static Win32Font CreateWin32Font(string fontName, float emHeight, bool bold, bool italic, float pixels_per_inch = 96)
        {
            //see: MSDN, LOGFONT structure
            //https://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
            MyWin32.LOGFONT logFont = new MyWin32.LOGFONT();
            MyWin32.SetFontName(ref logFont, fontName);
            logFont.lfHeight  = -(int)MyWin32.ConvEmSizeInPointsToPixels(emHeight, pixels_per_inch); //minus **
            logFont.lfCharSet = 1;                                                                   //default
            logFont.lfQuality = 0;                                                                   //default

            //
            MyWin32.LOGFONT_FontWeight weight =
                bold ?
                MyWin32.LOGFONT_FontWeight.FW_BOLD :
                MyWin32.LOGFONT_FontWeight.FW_REGULAR;
            logFont.lfWeight = (int)weight;
            //
            logFont.lfItalic = (byte)(italic ? 1 : 0);
            return(new Win32Font(MyWin32.CreateFontIndirect(ref logFont)));
        }
Пример #12
0
 public static extern bool FrameRect(IntPtr hDC, ref MyWin32.Win32Rect rect, IntPtr hBrush);
Пример #13
0
 public static unsafe extern bool GetViewportOrgEx(IntPtr hdc, MyWin32.POINT* p);
Пример #14
0
 /// <summary>
 /// set( solid) text color
 /// </summary>
 /// <param name="r">0-255</param>
 /// <param name="g">0-255</param>
 /// <param name="b">0-255</param>
 public void SetTextColor(byte r, byte g, byte b)
 {
     //convert to win32 (BGR) color
     MyWin32.SetTextColor(_memHdc, (b << 16) | (g << 8) | r);
 }
Пример #15
0
 /// <summary>
 /// Release the given memory HDC and dib section created from <see cref="CreateMemoryHdc"/>.
 /// </summary>
 /// <param name="memoryHdc">Memory HDC to release</param>
 /// <param name="dib">bitmap section to release</param>
 public static void ReleaseMemoryHdc(IntPtr memoryHdc, IntPtr dib)
 {
     MyWin32.DeleteObject(dib);
     MyWin32.DeleteDC(memoryHdc);
 }
Пример #16
0
 /// <summary>
 /// set solid text color
 /// </summary>
 /// <param name="r">0-255</param>
 /// <param name="g">0-255</param>
 /// <param name="b">0-255</param>
 public void SetSolidTextColor(byte r, byte g, byte b)
 {
     //convert to win32 colorv
     MyWin32.SetTextColor(memHdc, (b & 0xFF) << 16 | (g & 0xFF) << 8 | r);
 }
Пример #17
0
 public IntPtr SetFont(IntPtr hFont)
 {
     return(MyWin32.SelectObject(memHdc, hFont));
 }
Пример #18
0
 public void SetBackTransparent(bool value)
 {
     //public const int _SetBkMode_TRANSPARENT = 1;
     //public const int _SetBkMode_OPAQUE = 2;
     MyWin32.SetBkMode(memHdc, value ? 1 : 2);
 }
Пример #19
0
 public void PatBlt(PatBltColor color, int x, int y, int w, int h)
 {
     MyWin32.PatBlt(memHdc, x, y, w, h, (int)color);
 }
Пример #20
0
 public void PatBlt(PatBltColor color)
 {
     MyWin32.PatBlt(memHdc, 0, 0, _width, _height, (int)color);
 }
Пример #21
0
 public void ClearClipRect()
 {
     MyWin32.SelectClipRgn(memHdc, IntPtr.Zero);
 }