public void Reset(int hPageNum, int vPageNum, int newWidth, int newHeight)
        {
            this.pageNumFlags = (hPageNum << 8) | vPageNum;
            this.ReleaseUnManagedResource();
            this.ClearPreviousStoredValues();

            var orgHdc = MyWin32.CreateCompatibleDC(IntPtr.Zero);

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            hbmp = bmp.GetHbitmap();
            MyWin32.SelectObject(orgHdc, hbmp);
            MyWin32.PatBlt(orgHdc, 0, 0, newWidth, newHeight, MyWin32.WHITENESS);
            MyWin32.SetBkMode(orgHdc, MyWin32._SetBkMode_TRANSPARENT);


            hFont = defaultHFont;

            MyWin32.SelectObject(orgHdc, hFont);
            currentClipRect = new System.Drawing.Rectangle(0, 0, newWidth, newHeight);
            MyWin32.SelectObject(orgHdc, hRgn);
            gx = System.Drawing.Graphics.FromHdc(orgHdc);
            this.originalHdc = orgHdc;

            gx.Clear(System.Drawing.Color.White);
            MyWin32.SetRectRgn(hRgn, 0, 0, newWidth, newHeight);


            left   = hPageNum * newWidth;
            top    = vPageNum * newHeight;
            right  = left + newWidth;
            bottom = top + newHeight;
#if DEBUG
            debug_resetCount++;
#endif
        }
Пример #2
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);
        }
Пример #3
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);
        }
        void CreateGraphicsFromNativeHdc(int width, int height)
        {
            //3. create original dc from memory dc and prepare background
            var orgHdc = MyWin32.CreateCompatibleDC(IntPtr.Zero);

            bgBmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            hbmp  = bgBmp.GetHbitmap();
            MyWin32.SelectObject(orgHdc, hbmp);
            MyWin32.PatBlt(orgHdc, 0, 0, width, height, MyWin32.WHITENESS);
            MyWin32.SetBkMode(orgHdc, MyWin32._SetBkMode_TRANSPARENT);
            //4. font
            hFont = MyWin32.SelectObject(orgHdc, hFont);
            //5. region
            hRgn = MyWin32.CreateRectRgn(0, 0, width, height);
            MyWin32.SelectObject(orgHdc, hRgn);
            //6. create graphics from hdc***

            gx = System.Drawing.Graphics.FromHdc(orgHdc);
            this.originalHdc = orgHdc;
        }