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

« back to all changes in this revision

Viewing changes to extern/bFTGL/src/FTFace.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 "FTFace.h"
 
2
#include "FTLibrary.h"
 
3
 
 
4
#include FT_TRUETYPE_TABLES_H
 
5
 
 
6
FTFace::FTFace( const char* filename)
 
7
:   numGlyphs(0),
 
8
    fontEncodingList(0),
 
9
    err(0)
 
10
{
 
11
    const FT_Long DEFAULT_FACE_INDEX = 0;
 
12
    ftFace = new FT_Face;
 
13
 
 
14
    err = FT_New_Face( *FTLibrary::Instance().GetLibrary(), filename, DEFAULT_FACE_INDEX, ftFace);
 
15
 
 
16
    if( err)
 
17
    {
 
18
        delete ftFace;
 
19
        ftFace = 0;
 
20
    }
 
21
    else
 
22
    {
 
23
        numGlyphs = (*ftFace)->num_glyphs;
 
24
    }
 
25
}
 
26
 
 
27
 
 
28
FTFace::FTFace( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
 
29
:   numGlyphs(0),
 
30
    err(0)
 
31
{
 
32
    const FT_Long DEFAULT_FACE_INDEX = 0;
 
33
    ftFace = new FT_Face;
 
34
 
 
35
    err = FT_New_Memory_Face( *FTLibrary::Instance().GetLibrary(), (FT_Byte *)pBufferBytes, bufferSizeInBytes, DEFAULT_FACE_INDEX, ftFace);
 
36
 
 
37
    if( err)
 
38
    {
 
39
        delete ftFace;
 
40
        ftFace = 0;
 
41
    }
 
42
    else
 
43
    {
 
44
        numGlyphs = (*ftFace)->num_glyphs;
 
45
    }
 
46
}
 
47
 
 
48
 
 
49
FTFace::~FTFace()
 
50
{
 
51
    Close();
 
52
}
 
53
 
 
54
 
 
55
bool FTFace::Attach( const char* filename)
 
56
{
 
57
    err = FT_Attach_File( *ftFace, filename);
 
58
    return !err;
 
59
}
 
60
 
 
61
 
 
62
bool FTFace::Attach( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
 
63
{
 
64
    FT_Open_Args open;
 
65
 
 
66
    open.flags = FT_OPEN_MEMORY;
 
67
    open.memory_base = (FT_Byte *)pBufferBytes;
 
68
    open.memory_size = bufferSizeInBytes;
 
69
 
 
70
    err = FT_Attach_Stream( *ftFace, &open);
 
71
    return !err;
 
72
}
 
73
 
 
74
 
 
75
void FTFace::Close()
 
76
{
 
77
    if( ftFace)
 
78
    {
 
79
        FT_Done_Face( *ftFace);
 
80
        delete ftFace;
 
81
        ftFace = 0;
 
82
    }
 
83
}
 
84
 
 
85
 
 
86
const FTSize& FTFace::Size( const unsigned int size, const unsigned int res)
 
87
{
 
88
    charSize.CharSize( ftFace, size, res, res);
 
89
    err = charSize.Error();
 
90
 
 
91
    return charSize;
 
92
}
 
93
 
 
94
 
 
95
unsigned int FTFace::CharMapCount()
 
96
{
 
97
    return (*ftFace)->num_charmaps;
 
98
}
 
99
 
 
100
 
 
101
FT_Encoding* FTFace::CharMapList()
 
102
{
 
103
    if( 0 == fontEncodingList)
 
104
    {
 
105
        fontEncodingList = new FT_Encoding[CharMapCount()];
 
106
        for( size_t encodingIndex = 0; encodingIndex < CharMapCount(); ++encodingIndex)
 
107
        {
 
108
            fontEncodingList[encodingIndex] = (*ftFace)->charmaps[encodingIndex]->encoding;
 
109
        }
 
110
    }
 
111
    
 
112
    return fontEncodingList;
 
113
}
 
114
 
 
115
 
 
116
unsigned int FTFace::UnitsPerEM() const
 
117
{
 
118
    return (*ftFace)->units_per_EM;
 
119
}
 
120
 
 
121
 
 
122
FTPoint FTFace::KernAdvance( unsigned int index1, unsigned int index2)
 
123
{
 
124
    float x, y;
 
125
    x = y = 0.0f;
 
126
 
 
127
    if( FT_HAS_KERNING((*ftFace)) && index1 && index2)
 
128
    {
 
129
        FT_Vector kernAdvance;
 
130
        kernAdvance.x = kernAdvance.y = 0;
 
131
 
 
132
        err = FT_Get_Kerning( *ftFace, index1, index2, ft_kerning_unfitted, &kernAdvance);
 
133
        if( !err)
 
134
        {   
 
135
            x = static_cast<float>( kernAdvance.x) / 64.0f;
 
136
            y = static_cast<float>( kernAdvance.y) / 64.0f;
 
137
        }
 
138
    }
 
139
    
 
140
    return FTPoint( x, y, 0.0);
 
141
}
 
142
 
 
143
 
 
144
FT_GlyphSlot FTFace::Glyph( unsigned int index, FT_Int load_flags)
 
145
{
 
146
    err = FT_Load_Glyph( *ftFace, index, load_flags);
 
147
    if( err)
 
148
    {
 
149
        return NULL;
 
150
    }
 
151
 
 
152
    return (*ftFace)->glyph;
 
153
}
 
154