/// <summary>
        /// Special draw logic to draw transparent text using GDI.<br/>
        /// 1. Create in-memory DC<br/>
        /// 2. Copy background to in-memory DC<br/>
        /// 3. Draw the text to in-memory DC<br/>
        /// 4. Copy the in-memory DC to the proper location with alpha blend<br/>
        /// </summary>
        static void DrawTransparentText(IntPtr hdc, string str, Font font, Point point, Size size, Color color)
        {
            IntPtr dib;
            var    memoryHdc = Win32Utils.CreateMemoryHdc(hdc, size.Width, size.Height, out dib);

            try
            {
                // copy target background to memory HDC so when copied back it will have the proper background
                Win32Utils.BitBlt(memoryHdc, 0, 0, size.Width, size.Height, hdc, point.X, point.Y, Win32Utils.BitBltCopy);

                // Create and select font
                Win32Utils.SelectObject(memoryHdc, FontStore.GetCachedHFont(font.InnerFont as System.Drawing.Font));
                Win32Utils.SetTextColor(memoryHdc, (color.B & 0xFF) << 16 | (color.G & 0xFF) << 8 | color.R);

                // Draw text to memory HDC
                NativeTextWin32.TextOut(memoryHdc, 0, 0, str, str.Length);

                // copy from memory HDC to normal HDC with alpha blend so achieve the transparent text
                Win32Utils.AlphaBlend(hdc, point.X, point.Y, size.Width, size.Height, memoryHdc, 0, 0, size.Width, size.Height, new BlendFunction(color.A));
            }
            finally
            {
                Win32Utils.ReleaseMemoryHdc(memoryHdc, dib);
            }
        }
Exemplo n.º 2
0
        public override void DrawText(char[] buffer, Rectangle logicalTextBox, int textAlignment)
        {
            ReleaseHdc();
            IntPtr gxdc     = gx.GetHdc();
            var    clipRect = System.Drawing.Rectangle.Intersect(logicalTextBox.ToRect(), currentClipRect);

            clipRect.Offset(canvasOriginX, canvasOriginY);
            MyWin32.SetRectRgn(hRgn,
                               clipRect.Left,
                               clipRect.Top,
                               clipRect.Right,
                               clipRect.Bottom);
            MyWin32.SelectClipRgn(gxdc, hRgn);

            NativeTextWin32.TextOut(gxdc, CanvasOrgX + logicalTextBox.X, CanvasOrgY + logicalTextBox.Y, buffer, buffer.Length);

            MyWin32.SelectClipRgn(gxdc, IntPtr.Zero);
            gx.ReleaseHdc();

            //ReleaseHdc();
            //IntPtr gxdc = gx.GetHdc();
            //MyWin32.SetViewportOrgEx(gxdc, CanvasOrgX, CanvasOrgY, IntPtr.Zero);
            //System.Drawing.Rectangle clipRect =
            //    System.Drawing.Rectangle.Intersect(logicalTextBox.ToRect(), currentClipRect);
            //clipRect.Offset(CanvasOrgX, CanvasOrgY);
            //MyWin32.SetRectRgn(hRgn, clipRect.X, clipRect.Y, clipRect.Right, clipRect.Bottom);
            //MyWin32.SelectClipRgn(gxdc, hRgn);
            //NativeTextWin32.TextOut(gxdc, logicalTextBox.X, logicalTextBox.Y, buffer, buffer.Length);
            //MyWin32.SelectClipRgn(gxdc, IntPtr.Zero);
            //MyWin32.SetViewportOrgEx(gxdc, -CanvasOrgX, -CanvasOrgY, IntPtr.Zero);
            //gx.ReleaseHdc();
        }
Exemplo n.º 3
0
        void PrepareCharacterMapWhiteOnBlack(char[] buffer)
        {
            //-----------------------------------------------------------------------
            IntPtr gxdc = gx.GetHdc();
            int    len  = buffer.Length;
            //draw each character
            int curX = 0;
            int curY = 0;

            //1. clear with white color,
            MyWin32.PatBlt(gxdc, 0, 0, width, height, MyWin32.BLACKNESS);
            //2. transparent background
            MyWin32.SetBkMode(gxdc, MyWin32._SetBkMode_TRANSPARENT);
            //3. white brush
            //set user font to dc
            MyWin32.SelectObject(gxdc, this.hFont);
            int rgb = ((255 & 0xFF) << 16 | (255 & 0xFF) << 8 | 255);

            MyWin32.SetTextColor(gxdc, rgb);

            //TODO:correct white text on black bg for subpixel rendering
            //when draw with subpixel rendering
            //on white bg -> red come first from left ,end with blue
            //on black bg -> blue come first from left, end with red

            int fontHeight    = fontInfo.FontHeight;
            int maxLineHeight = fontHeight;

            for (int i = 0; i < len; ++i)
            {
                //-----------------------------------------------------------------------
                //measure string
                //and make simple character map
                //-----------------------------------------------------------------------
                //measure each character ***
                //not adjust kerning***

                char    c             = buffer[i];
                FontABC abcWidth      = fontInfo.GetCharABCWidth(c);
                int     glyphBoxWidth = Math.Abs(abcWidth.a) + (int)abcWidth.b + abcWidth.c;
                if (abcWidth.Sum + curX > this.width)
                {
                    //start newline
                    curX          = 0;
                    curY         += maxLineHeight;
                    maxLineHeight = fontHeight;
                }

                NativeTextWin32.TextOut(gxdc, curX, curY, new char[] { c }, 1);
                charMap.Add(c, new PixelFarm.Drawing.RectangleF(curX, curY, glyphBoxWidth, fontHeight));
                curX += glyphBoxWidth; //move next
            }
            gx.ReleaseHdc(gxdc);
            //myTextBoardBmp = new Bitmap(width, height, new LazyGdiBitmapBufferProvider(this.textBoardBmp));
            //myTextBoardBmp.InnerImage = GLBitmapTextureHelper.CreateBitmapTexture(this.textBoardBmp);
        }
Exemplo n.º 4
0
        //public override float GetCharWidth(RequestFont f, char c)
        //{
        //    WinGdiFont winFont = WinGdiFontSystem.GetWinGdiFont(f);
        //    return winFont.GetGlyph(c).horiz_adv_x >> 6;
        //}
        public override void DrawText(char[] buffer, int x, int y)
        {
            var clipRect = currentClipRect;

            clipRect.Offset(canvasOriginX, canvasOriginY);
            //1.
            win32MemDc.SetClipRect(clipRect.Left, clipRect.Top, clipRect.Width, clipRect.Height);
            //2.
            NativeTextWin32.TextOut(win32MemDc.DC, CanvasOrgX + x, CanvasOrgY + y, buffer, buffer.Length);
            //3
            win32MemDc.ClearClipRect();
        }
Exemplo n.º 5
0
        void PrepareCharacterMapBlackOnWhite(char[] buffer)
        {
            //-----------------------------------------------------------------------
            IntPtr gxdc = gx.GetHdc();
            int    len  = buffer.Length;
            //draw each character
            int curX = 0;
            int curY = 0;

            //1. clear with white color,
            MyWin32.PatBlt(gxdc, 0, 0, width, height, MyWin32.WHITENESS);
            //2. transparent background
            MyWin32.SetBkMode(gxdc, MyWin32._SetBkMode_TRANSPARENT);

            //set user font to dc
            MyWin32.SelectObject(gxdc, this.hFont);
            int fontHeight    = fontInfo.FontHeight;
            int maxLineHeight = fontHeight;

            for (int i = 0; i < len; ++i)
            {
                //-----------------------------------------------------------------------
                //measure string
                //and make simple character map
                //-----------------------------------------------------------------------
                //measure each character ***
                //not adjust kerning***

                char    c             = buffer[i];
                FontABC abcWidth      = fontInfo.GetCharABCWidth(c);
                int     glyphBoxWidth = Math.Abs(abcWidth.a) + (int)abcWidth.b + abcWidth.c;
                if (abcWidth.Sum + curX > this.width)
                {
                    //start newline
                    curX          = 0;
                    curY         += maxLineHeight;
                    maxLineHeight = fontHeight;
                }

                NativeTextWin32.TextOut(gxdc, curX, curY, new char[] { c }, 1);
                charMap.Add(c, new PixelFarm.Drawing.RectangleF(curX, curY, glyphBoxWidth, fontHeight));
                curX += glyphBoxWidth; //move next
            }
            gx.ReleaseHdc(gxdc);
            //myTextBoardBmp = new Bitmap(width, height, new LazyGdiBitmapBufferProvider(this.textBoardBmp));
            //myTextBoardBmp.InnerImage = GLBitmapTextureHelper.CreateBitmapTexture(this.textBoardBmp);
        }
Exemplo n.º 6
0
        //==============================================



        public override void DrawText(char[] buffer, int x, int y)
        {
            ReleaseHdc();
            IntPtr gxdc     = gx.GetHdc();
            var    clipRect = currentClipRect;

            clipRect.Offset(canvasOriginX, canvasOriginY);
            MyWin32.SetRectRgn(hRgn,
                               clipRect.Left,
                               clipRect.Top,
                               clipRect.Right,
                               clipRect.Bottom);
            MyWin32.SelectClipRgn(gxdc, hRgn);
            NativeTextWin32.TextOut(gxdc, CanvasOrgX + x, CanvasOrgY + y, buffer, buffer.Length);
            MyWin32.SelectClipRgn(gxdc, IntPtr.Zero);
            gx.ReleaseHdc();
        }