1 /*
2  * FTGL - OpenGL font library
3  *
4  * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 #include "config.h"
27 
28 #include "FTSize.h"
29 
30 
FTSize()31 FTSize::FTSize()
32 :   ftFace(0),
33     ftSize(0),
34     size(0),
35     xResolution(0),
36     yResolution(0),
37     err(0)
38 {}
39 
40 
~FTSize()41 FTSize::~FTSize()
42 {}
43 
44 
CharSize(FT_Face * face,unsigned int pointSize,unsigned int xRes,unsigned int yRes)45 bool FTSize::CharSize(FT_Face* face, unsigned int pointSize, unsigned int xRes, unsigned int yRes)
46 {
47     if(size != pointSize || xResolution != xRes || yResolution != yRes)
48     {
49         err = FT_Set_Char_Size(*face, 0L, pointSize * 64, xResolution, yResolution);
50 
51         if(!err)
52         {
53             ftFace = face;
54             size = pointSize;
55             xResolution = xRes;
56             yResolution = yRes;
57             ftSize = (*ftFace)->size;
58         }
59     }
60 
61     return !err;
62 }
63 
64 
CharSize() const65 unsigned int FTSize::CharSize() const
66 {
67     return size;
68 }
69 
70 
Ascender() const71 float FTSize::Ascender() const
72 {
73     return ftSize == 0 ? 0.0f : static_cast<float>(ftSize->metrics.ascender) / 64.0f;
74 }
75 
76 
Descender() const77 float FTSize::Descender() const
78 {
79     return ftSize == 0 ? 0.0f : static_cast<float>(ftSize->metrics.descender) / 64.0f;
80 }
81 
82 
Height() const83 float FTSize::Height() const
84 {
85     if(0 == ftSize)
86     {
87         return 0.0f;
88     }
89 
90     if(FT_IS_SCALABLE((*ftFace)))
91     {
92         return ((*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin) * ((float)ftSize->metrics.y_ppem / (float)(*ftFace)->units_per_EM);
93     }
94     else
95     {
96         return static_cast<float>(ftSize->metrics.height) / 64.0f;
97     }
98 }
99 
100 
Width() const101 float FTSize::Width() const
102 {
103     if(0 == ftSize)
104     {
105         return 0.0f;
106     }
107 
108     if(FT_IS_SCALABLE((*ftFace)))
109     {
110         return ((*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin) * (static_cast<float>(ftSize->metrics.x_ppem) / static_cast<float>((*ftFace)->units_per_EM));
111     }
112     else
113     {
114         return static_cast<float>(ftSize->metrics.max_advance) / 64.0f;
115     }
116 }
117 
118 
Underline() const119 float FTSize::Underline() const
120 {
121     return 0.0f;
122 }
123 
124