~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to extern/bFTGL/src/FTPixmapGlyph.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include    "FTPixmapGlyph.h"
 
2
 
 
3
FTPixmapGlyph::FTPixmapGlyph( FT_GlyphSlot glyph)
 
4
:   FTGlyph( glyph),
 
5
    destWidth(0),
 
6
    destHeight(0),
 
7
    data(0)
 
8
{
 
9
    err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL);
 
10
    if( err || ft_glyph_format_bitmap != glyph->format)
 
11
    {
 
12
        return;
 
13
    }
 
14
 
 
15
    FT_Bitmap bitmap = glyph->bitmap;
 
16
 
 
17
    //check the pixel mode
 
18
    //ft_pixel_mode_grays
 
19
        
 
20
    int srcWidth = bitmap.width;
 
21
    int srcHeight = bitmap.rows;
 
22
    
 
23
   // FIXME What about dest alignment?
 
24
    destWidth = srcWidth;
 
25
    destHeight = srcHeight;
 
26
    
 
27
    if( destWidth && destHeight)
 
28
    {
 
29
        data = new unsigned char[destWidth * destHeight * 4];
 
30
    
 
31
        // Get the current glColor.
 
32
        float ftglColour[4];
 
33
//        glGetFloatv( GL_CURRENT_COLOR, ftglColour);
 
34
                ftglColour[0] = ftglColour[1] = ftglColour[2] = ftglColour[3] = 1.0;
 
35
 
 
36
        unsigned char redComponent =   static_cast<unsigned char>( ftglColour[0] * 255.0f);
 
37
        unsigned char greenComponent = static_cast<unsigned char>( ftglColour[1] * 255.0f);
 
38
        unsigned char blueComponent =  static_cast<unsigned char>( ftglColour[2] * 255.0f);
 
39
 
 
40
        unsigned char* src = bitmap.buffer;
 
41
 
 
42
        unsigned char* dest = data + ((destHeight - 1) * destWidth) * 4;
 
43
        size_t destStep = destWidth * 4 * 2;
 
44
 
 
45
        if( ftglColour[3] == 1.0f)
 
46
        {
 
47
            for( int y = 0; y < srcHeight; ++y)
 
48
            {
 
49
                for( int x = 0; x < srcWidth; ++x)
 
50
                {
 
51
                    *dest++ = redComponent;
 
52
                    *dest++ = greenComponent;
 
53
                    *dest++ = blueComponent;
 
54
                    *dest++ = *src++;
 
55
                }
 
56
                dest -= destStep;
 
57
            }
 
58
        }
 
59
        else
 
60
        {
 
61
            for( int y = 0; y < srcHeight; ++y)
 
62
            {
 
63
                for( int x = 0; x < srcWidth; ++x)
 
64
                {
 
65
                    *dest++ = redComponent;
 
66
                    *dest++ = greenComponent;
 
67
                    *dest++ = blueComponent;
 
68
                    *dest++ = static_cast<unsigned char>(ftglColour[3] * *src++);
 
69
                }
 
70
                dest -= destStep;
 
71
            }
 
72
        }
 
73
 
 
74
        destHeight = srcHeight;
 
75
    }
 
76
 
 
77
    pos.x = glyph->bitmap_left;
 
78
    pos.y = srcHeight - glyph->bitmap_top;
 
79
}
 
80
 
 
81
 
 
82
FTPixmapGlyph::~FTPixmapGlyph()
 
83
{
 
84
    delete [] data;
 
85
}
 
86
 
 
87
#include <math.h>
 
88
float FTPixmapGlyph::Render( const FTPoint& pen)
 
89
{
 
90
    if( data)
 
91
    {
 
92
                float dx, dy;
 
93
                
 
94
                dx= floor( (pen.x + pos.x ) );
 
95
                dy= ( (pen.y - pos.y ) );
 
96
                
 
97
        // Move the glyph origin
 
98
        glBitmap( 0, 0, 0.0f, 0.0f, dx, dy, (const GLubyte*)0);
 
99
 
 
100
        glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
 
101
 
 
102
        glDrawPixels( destWidth, destHeight, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)data);
 
103
        
 
104
        // Restore the glyph origin
 
105
        glBitmap( 0, 0, 0.0f, 0.0f, -dx, -dy, (const GLubyte*)0);
 
106
    }
 
107
 
 
108
    return advance;
 
109
}