Commit 9a6997a2b05083735f3d5deb47d78cc98f745386

henry 2003-01-10T01:47:05

Added units per EM square

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() 
         {}