Added units per EM square
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
diff --git a/include/FTFace.h b/include/FTFace.h
index d2b58b6..74bd703 100755
--- a/include/FTFace.h
+++ b/include/FTFace.h
@@ -79,6 +79,8 @@ class FTGL_EXPORT FTFace
*/
const FTSize& Size( const unsigned int size, const unsigned int res);
+ unsigned int UnitsPerEM() const;
+
/**
* Sets the character map for the face.
*
diff --git a/include/FTSize.h b/include/FTSize.h
index 12a839f..31f6bb6 100755
--- a/include/FTSize.h
+++ b/include/FTSize.h
@@ -94,6 +94,10 @@ class FTGL_EXPORT FTSize
*/
float Underline() const;
+ unsigned int XPixelsPerEm() const;
+
+ unsigned int YPixelsPerEm() const;
+
/**
* Queries for errors.
*
diff --git a/src/FTFace.cpp b/src/FTFace.cpp
index 4ae397f..e291eae 100755
--- a/src/FTFace.cpp
+++ b/src/FTFace.cpp
@@ -104,6 +104,12 @@ bool FTFace::CharMap( FT_Encoding encoding)
}
+unsigned int FTFace::UnitsPerEM() const
+{
+ return (*ftFace)->units_per_EM;
+}
+
+
unsigned int FTFace::CharIndex( unsigned int index) const
{
return charMap->CharIndex( index);
diff --git a/src/FTSize.cpp b/src/FTSize.cpp
index 035e662..7bc9a6a 100755
--- a/src/FTSize.cpp
+++ b/src/FTSize.cpp
@@ -61,10 +61,7 @@ float FTSize::Height() const
if( FT_IS_SCALABLE((*ftFace)))
{
- float height = ( (*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin)
- * ( (float)ftSize->metrics.y_ppem / (float)(*ftFace)->units_per_EM);
-
- return height;
+ return ( (*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin) * ( (float)ftSize->metrics.y_ppem / (float)(*ftFace)->units_per_EM);
}
else
{
@@ -82,10 +79,7 @@ float FTSize::Width() const
if( FT_IS_SCALABLE((*ftFace)))
{
- float width = ( (*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin)
- * ( (float)ftSize->metrics.x_ppem / (float)(*ftFace)->units_per_EM);
-
- return width;
+ return ( (*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin) * ( static_cast<float>(ftSize->metrics.x_ppem) / static_cast<float>((*ftFace)->units_per_EM));
}
else
{
@@ -98,3 +92,14 @@ float FTSize::Underline() const
{
return 0.0f;
}
+
+unsigned int FTSize::XPixelsPerEm() const
+{
+ return ftSize->metrics.x_ppem;
+}
+
+unsigned int FTSize::YPixelsPerEm() const
+{
+ return ftSize->metrics.y_ppem;
+}
+
diff --git a/test/FTFace-Test.cpp b/test/FTFace-Test.cpp
index 56d047a..69159d5 100755
--- a/test/FTFace-Test.cpp
+++ b/test/FTFace-Test.cpp
@@ -16,6 +16,7 @@ class FTFaceTest : public CppUnit::TestCase
CPPUNIT_TEST( testAttachMemoryData);
CPPUNIT_TEST( testGlyphCount);
CPPUNIT_TEST( testSetFontSize);
+ CPPUNIT_TEST( testUnitPerEMSquare);
CPPUNIT_TEST( testSetCharMap);
CPPUNIT_TEST( testCharacterIndex);
CPPUNIT_TEST( testKerning);
@@ -84,6 +85,10 @@ class FTFaceTest : public CppUnit::TestCase
CPPUNIT_ASSERT( testFace->Error() == 0);
}
+ void testUnitPerEMSquare()
+ {
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 1000, testFace->UnitsPerEM(), 0.01);
+ }
void testSetCharMap()
{
diff --git a/test/FTSize-Test.cpp b/test/FTSize-Test.cpp
index 60d6b42..4678b57 100755
--- a/test/FTSize-Test.cpp
+++ b/test/FTSize-Test.cpp
@@ -16,6 +16,7 @@ class FTSizeTest : public CppUnit::TestCase
CPPUNIT_TEST_SUITE( FTSizeTest);
CPPUNIT_TEST( testConstructor);
CPPUNIT_TEST( testSetCharSize);
+ CPPUNIT_TEST( testPixelsPerEMSquare);
CPPUNIT_TEST_SUITE_END();
public:
@@ -60,6 +61,19 @@ class FTSizeTest : public CppUnit::TestCase
tearDownFreetype();
}
+ void testPixelsPerEMSquare()
+ {
+ setUpFreetype();
+
+ FTSize size;
+
+ CPPUNIT_ASSERT( size.CharSize( &face, FONT_POINT_SIZE, RESOLUTION, RESOLUTION));
+ CPPUNIT_ASSERT( size.Error() == 0);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 72, size.XPixelsPerEm(), 0.01);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 72, size.YPixelsPerEm(), 0.01);
+ }
+
void setUp()
{}