1 #include  "FTSize.h"
2 #ifdef FTGL_DEBUG
3   #include "mmgr.h"
4 #endif
5 
6 #ifdef FTGL_USE_NAMESPACE
7 namespace ftgl
8 {
9 #endif
10 
FTSize()11 FTSize::FTSize()
12 :  ftFace(0),
13   size(0),
14   err(0)
15 {}
16 
17 
~FTSize()18 FTSize::~FTSize()
19 {}
20 
21 
CharSize(FT_Face * face,unsigned int point_size,unsigned int x_resolution,unsigned int y_resolution)22 bool FTSize::CharSize( FT_Face* face, unsigned int point_size, unsigned int x_resolution, unsigned int y_resolution )
23 {
24   ftFace = face;
25   size = point_size;
26   err = FT_Set_Char_Size( *ftFace, 0L, point_size * 64, x_resolution, y_resolution);
27 
28   ftSize = (*ftFace)->size;
29 
30   return !err;
31 }
32 
33 
Ascender() const34 int FTSize::Ascender() const
35 {
36   return ftSize->metrics.ascender >> 6;
37 }
38 
39 
Descender() const40 int FTSize::Descender() const
41 {
42   return ftSize->metrics.descender >> 6;
43 }
44 
45 
Height() const46 int FTSize::Height() const
47 {
48   if( FT_IS_SCALABLE((*ftFace)))
49   {
50     float height;
51     if( FT_IS_SFNT((*ftFace))) // Don't think this is correct
52     {
53       height = (float)((*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin); // bbox.yMax-bbox.yMin
54     }
55     else
56     {
57       height = (float)(((*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin) >> 16); // bbox.yMax-bbox.yMin
58     }
59 
60     height =  height * ( (float)ftSize->metrics.y_ppem / (float)(*ftFace)->units_per_EM);
61     return static_cast<int>(height);
62   }
63   else
64   {
65     return ftSize->metrics.height >> 6;
66   }
67 }
68 
69 
Width() const70 int FTSize::Width() const
71 {
72   if( FT_IS_SCALABLE((*ftFace)))
73   {
74     float width;
75     if( FT_IS_SFNT((*ftFace))) // Don't think this is correct
76     {
77       width = (float)((*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin); // bbox.xMax-bbox.xMin
78     }
79     else
80     {
81       width = (float)(((*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin) >> 16); // bbox.xMax-bbox.xMin
82     }
83 
84     width = width * ( (float)ftSize->metrics.x_ppem / (float)(*ftFace)->units_per_EM);
85     return static_cast<int>(width);
86   }
87   else
88   {
89     return ftSize->metrics.max_advance >> 6;
90   }
91 }
92 
93 
Underline() const94 int FTSize::Underline() const
95 {
96   return 0;
97 }
98 
99 #ifdef FTGL_USE_NAMESPACE
100 } // namespace ftgl
101 #endif
102