freetype - render freetype glyph on windows


       
 hdc = BeginPaint(hWnd, &ps);

        assert(Draw());

        FT_GlyphSlot &pBm = m_face->glyph;

        //output by console
        {
            printf("\n");
            for (int j = 0; j < pBm->bitmap.rows; j++) {
                printf("\n");
                for (int i = 0; i < pBm->bitmap.width; i++) 
                    printf("%2x", pBm->bitmap.buffer[j * pBm->bitmap.width + i]);
            }
        }

        //output by gdi+
        {
            Bitmap *pBitmap = NULL;
            LPBYTE pBuffer = NULL;      
            int stride = (pBm->bitmap.pitch + 3) / 4 * 4;
            if (stride != pBm->bitmap.pitch)
            {
                pBuffer = new BYTE[stride * pBm->bitmap.rows];
                memset(pBuffer, 0, stride * pBm->bitmap.rows);
                for (int i = 0; i < pBm->bitmap.rows; i++)
                    for (int j = 0; j < pBm->bitmap.width; j++)
                        pBuffer[i * stride + j] = pBm->bitmap.buffer[i * pBm->bitmap.width + j];
            } else
            {
                pBuffer = pBm->bitmap.buffer;
            }
            pBitmap = new Bitmap(pBm->bitmap.width, pBm->bitmap.rows, stride, PixelFormat8bppIndexed, pBuffer);
            ColorPalette *pPalette = (ColorPalette*)malloc(sizeof(ColorPalette) + 255 * sizeof(ARGB));
            pPalette->Count = 256;
            pPalette->Flags = PaletteFlagsGrayScale;
            ARGB* pColor = &pPalette->Entries[0];
            for (int i = 0; i < 256; i++)
                pColor[i] = Color::MakeARGB(i, 0x00, 0x00, 0x00);
            assert(pBitmap->GetLastStatus() == Ok);
            pBitmap->SetPalette(pPalette);
            assert(pBitmap->GetLastStatus() == Ok);
            Graphics graphics(hdc);
            graphics.DrawImage(pBitmap, 300, 300);

            free(pPalette);
            delete pBitmap;

            //draw with gdi
            {
                BITMAPINFO* pBmi = (BITMAPINFO*)malloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 255);
                memset(pBmi, 0, sizeof(BITMAPINFO));
                BITMAPINFOHEADER &bmh = pBmi->bmiHeader;
                bmh.biSize = sizeof(BITMAPINFOHEADER);
                bmh.biBitCount = 8;
                bmh.biCompression = BI_RGB;
                bmh.biPlanes = 1;
                RGBQUAD* palette = &pBmi->bmiColors[0];
                for (int i = 0; i < 256; ++i) 
                {
                    RGBQUAD rgb = {0};
                    rgb.rgbRed =  ~i;
                    rgb.rgbGreen =  ~i;
                    rgb.rgbBlue =  ~i;
                    palette[i] = rgb;
                }
                bmh.biWidth = stride;
                bmh.biHeight =  - pBm->bitmap.rows;
                StretchDIBits(hdc, 200, 200, stride, pBm->bitmap.rows, 0, 0, stride, pBm->bitmap.rows, pBuffer, 
                    pBmi, DIB_RGB_COLORS, SRCCOPY);

                if (pBmi)
                    free(pBmi);

                if (pBuffer != pBm->bitmap.buffer)
                    delete [] pBuffer;

                /*bmh.biWidth = pBm->bitmap.width;
                bmh.biHeight =  - pBm->bitmap.rows;
                StretchDIBits(hdc, 200, 200, pBm->bitmap.width, pBm->bitmap.rows, 0, 0, pBm->bitmap.width, pBm->bitmap.rows, pBm->bitmap.buffer, 
                    pBmi, DIB_PAL_COLORS, SRCCOPY);*/
            }

        }
        EndPaint(hWnd, &ps);

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值