コード例 #1
0
ファイル: GdiTextureFont.cs プロジェクト: asmboom/PixelFarm
        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);
        }
コード例 #2
0
ファイル: GdiTextureFont.cs プロジェクト: asmboom/PixelFarm
        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);
        }