freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Freetype] Windows code displaying garbage - any help?


From: Jason C. Weaver
Subject: [Freetype] Windows code displaying garbage - any help?
Date: Sun, 1 Jun 2003 14:49:46 -0700 (PDT)

If anyone could assist I would greatly appreciate it.  I've read over the docs, 
the examples, and
the digest of this newgroup and have hobbled together the best of what I could 
figure out.  I'm
just trying to get a hard-coded 'X' painted into a a Windows bitmap at 
(300,300).  I certainly get
something on the screen but it's much bigger than I'd expect and it doesn't 
look anything like an
'X' but rather garbage.

I've removed the error checking to make this easier to read.  I've have 
verified that all
functions are not returning errors.  Also, I know the CDC and bitblt 
functionality works.  I can
replace character.CreateBitmap call with a simple LoadBitmap which will display 
at (300,300) as
expected.

Thanks for any assistance.  This looks like exactly what I need for my project 
but I'm stuck
getting it working on Windows!
Chris


    FT_Face face;      /* handle to face object */
    FT_Libary       m_ftFontLibrary

    int error = FT_New_Face( m_ftFontLibrary, "Fonts/arial.ttf", 0, &face );

    error = FT_Set_Char_Size(
              face,    /* handle to face object           */
              0,       /* char_width in 1/64th of points  */
              12 /* ptsize */ * 64,   /* char_height in 1/64th of points */
              1280,     /* horizontal device resolution    */
              1024 );   /* vertical device resolution      */


    CDC* pDC = ( ( CFrameWnd* )AfxGetMainWnd() )->GetActiveView()->GetDC();
    CDC dc;
    dc.CreateCompatibleDC( pDC );

    CDC dctext;
    dctext.CreateCompatibleDC( pDC );

    CBitmap bmp;
    bmp.Attach( m_hOverlay );   /* HBITMAP m_hOverlay */
    CBitmap* pSaveBmp = dc.SelectObject( &bmp );


    FT_Face face = ( FT_Face )font;
    FT_GlyphSlot  slot = face->glyph;  // a small shortcut
    int           pen_x, pen_y, n, error;
    pen_x = 300;    // temp hard-coded known value
    pen_y = 300;    // temp hard-coded known value

    // hard-coded X to just try and get something on the screen
    error = FT_Load_Char( face, 'X', FT_LOAD_RENDER );
    if (error) return; // do something here

    // now, draw to our target surface
    BITMAPINFO i;
    ZeroMemory( &i.bmiHeader, sizeof(BITMAPINFOHEADER));
    i.bmiHeader.biPlanes  = 1;
    i.bmiHeader.biBitCount  = 8;
    i.bmiHeader.biSizeImage = 0;
    i.bmiHeader.biSize   = sizeof(BITMAPINFOHEADER);
    i.bmiHeader.biClrUsed  = 0;
    i.bmiHeader.biClrImportant = 0;
    i.bmiHeader.biCompression  = BI_RGB;
    i.bmiHeader.biWidth = slot->bitmap.width;
    i.bmiHeader.biHeight = -slot->bitmap.rows;

    int FreeTypeX = slot->bitmap.width;
    int FreeTypeY = slot->bitmap.rows;

    for( int h = 0; h < 2; h++ )
    {
        i.bmiColors[h].rgbBlue   = h;
        i.bmiColors[h].rgbGreen  = h;
        i.bmiColors[h].rgbRed    = h;
    }

    void *pvBits;
    HBITMAP hbmp = CreateDIBSection( dc, &i, DIB_RGB_COLORS, &pvBits, NULL,0 );
    if( !hbmp )
        return;

#define NEAREST_LONGINT_BOUNDARY(a) (((a) + 3)& 0xfffffffc);
    // Calculate # of pad bytes 'cuz BMPs pad scanlines to long boundaries
    int BmpX = NEAREST_LONGINT_BOUNDARY( FreeTypeX );

    unsigned char* CurrSrcPixel = face->glyph->bitmap.buffer;
    unsigned char* CurrDstPixel = ( unsigned char* )pvBits;
    int CurrY, CurrX;

    for ( CurrY = 0; CurrY < FreeTypeY; CurrY++)
    {
        for (CurrX = 0; CurrX < FreeTypeX;  CurrX++)
        {
            // Copy the each scanline a pixel at a time
            CurrDstPixel[ CurrX ] = CurrSrcPixel[ CurrX ];
        }

        // Advance the pointer to the start of the the next scanline
        CurrSrcPixel += FreeTypeX;
        CurrDstPixel += BmpX;
    }

    CBitmap character;
    BOOL bWorked = character.CreateBitmap( BmpX, FreeTypeY, 1, 1, pvBits );

    CBitmap* oldbmp = dctext.SelectObject( &character );
    dc.BitBlt( 300, 300, face->glyph->bitmap.width, face->glyph->bitmap.rows, 
&dctext, 0, 0,
SRCCOPY );
    dctext.SelectObject( oldbmp );



__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com



reply via email to

[Prev in Thread] Current Thread [Next in Thread]