00001 #include "FTSize.h"
00002
00003
00004 FTSize::FTSize()
00005 : ftFace(0),
00006 ftSize(0),
00007 size(0),
00008 xResolution(0),
00009 yResolution(0),
00010 err(0)
00011 {}
00012
00013
00014 FTSize::~FTSize()
00015 {}
00016
00017
00018 bool FTSize::CharSize( FT_Face* face, unsigned int pointSize, unsigned int xRes, unsigned int yRes )
00019 {
00020 if( size != pointSize || xResolution != xRes || yResolution != yRes)
00021 {
00022 err = FT_Set_Char_Size( *face, 0L, pointSize * 64, xResolution, yResolution);
00023
00024 if( !err)
00025 {
00026 ftFace = face;
00027 size = pointSize;
00028 xResolution = xRes;
00029 yResolution = yRes;
00030 ftSize = (*ftFace)->size;
00031 }
00032 else
00033 {
00034 ftFace = 0;
00035 size = 0;
00036 xResolution = 0;
00037 yResolution = 0;
00038 ftSize = 0;
00039 }
00040 }
00041
00042 return !err;
00043 }
00044
00045
00046 unsigned int FTSize::CharSize() const
00047 {
00048 return size;
00049 }
00050
00051
00052 float FTSize::Ascender() const
00053 {
00054 return ftSize == 0 ? 0.0f : static_cast<float>( ftSize->metrics.ascender) / 64.0f;
00055 }
00056
00057
00058 float FTSize::Descender() const
00059 {
00060 return ftSize == 0 ? 0.0f : static_cast<float>( ftSize->metrics.descender) / 64.0f;
00061 }
00062
00063
00064 float FTSize::Height() const
00065 {
00066 if( 0 == ftSize)
00067 {
00068 return 0.0f;
00069 }
00070
00071 if( FT_IS_SCALABLE((*ftFace)))
00072 {
00073 return ( (*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin) * ( (float)ftSize->metrics.y_ppem / (float)(*ftFace)->units_per_EM);
00074 }
00075 else
00076 {
00077 return static_cast<float>( ftSize->metrics.height) / 64.0f;
00078 }
00079 }
00080
00081
00082 float FTSize::Width() const
00083 {
00084 if( 0 == ftSize)
00085 {
00086 return 0.0f;
00087 }
00088
00089 if( FT_IS_SCALABLE((*ftFace)))
00090 {
00091 return ( (*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin) * ( static_cast<float>(ftSize->metrics.x_ppem) / static_cast<float>((*ftFace)->units_per_EM));
00092 }
00093 else
00094 {
00095 return static_cast<float>( ftSize->metrics.max_advance) / 64.0f;
00096 }
00097 }
00098
00099
00100 float FTSize::Underline() const
00101 {
00102 return 0.0f;
00103 }
00104