Commit 28cc198bd7d8362b0a2c89a04f8880ee5d995709

sammy 2008-05-07T14:58:09

* Reimplement all FTFont::BBox() variants using the same FTFontImpl::BBox() common method.

diff --git a/src/FTFont/FTFont.cpp b/src/FTFont/FTFont.cpp
index 5b278c2..cbc8373 100644
--- a/src/FTFont/FTFont.cpp
+++ b/src/FTFont/FTFont.cpp
@@ -206,7 +206,9 @@ void FTFont::BBox(const char* string, const int start, const int end,
                   float& llx, float& lly, float& llz,
                   float& urx, float& ury, float& urz)
 {
-    return impl->BBox(string, start, end, llx, lly, llz, urx, ury, urz);
+    FTBBox tmp = impl->BBox(string, start, end);
+    llx = tmp.Lower().X(); lly = tmp.Lower().Y(); llz = tmp.Lower().Z();
+    urx = tmp.Upper().X(); ury = tmp.Upper().Y(); urz = tmp.Upper().Z();
 }
 
 
@@ -214,21 +216,27 @@ void FTFont::BBox(const wchar_t* string, const int start, const int end,
                   float& llx, float& lly, float& llz,
                   float& urx, float& ury, float& urz)
 {
-    return impl->BBox(string, start, end, llx, lly, llz, urx, ury, urz);
+    FTBBox tmp = impl->BBox(string, start, end);
+    llx = tmp.Lower().X(); lly = tmp.Lower().Y(); llz = tmp.Lower().Z();
+    urx = tmp.Upper().X(); ury = tmp.Upper().Y(); urz = tmp.Upper().Z();
 }
 
 
 void FTFont::BBox(const char* string, float& llx, float& lly, float& llz,
                   float& urx, float& ury, float& urz)
 {
-    return impl->BBox(string, 0, -1, llx, lly, llz, urx, ury, urz);
+    FTBBox tmp = impl->BBox(string, 0, -1);
+    llx = tmp.Lower().X(); lly = tmp.Lower().Y(); llz = tmp.Lower().Z();
+    urx = tmp.Upper().X(); ury = tmp.Upper().Y(); urz = tmp.Upper().Z();
 }
 
 
 void FTFont::BBox(const wchar_t* string, float& llx, float& lly, float& llz,
                   float& urx, float& ury, float& urz)
 {
-    return impl->BBox(string, 0, -1, llx, lly, llz, urx, ury, urz);
+    FTBBox tmp = impl->BBox(string, 0, -1);
+    llx = tmp.Lower().X(); lly = tmp.Lower().Y(); llz = tmp.Lower().Z();
+    urx = tmp.Upper().X(); ury = tmp.Upper().Y(); urz = tmp.Upper().Z();
 }
 
 
@@ -449,9 +457,7 @@ float FTFontImpl::LineHeight() const
 
 
 template <typename T>
-inline void FTFontImpl::BBoxI(const T* string, const int start, const int end,
-                              float& llx, float& lly, float& llz,
-                              float& urx, float& ury, float& urz)
+inline FTBBox FTFontImpl::BBoxI(const T* string, const int start, const int end)
 {
     FTBBox totalBBox;
 
@@ -481,50 +487,22 @@ inline void FTFontImpl::BBoxI(const T* string, const int start, const int end,
         }
     }
 
-    // TODO: The Z values do not follow the proper ordering.  I'm not sure why.
-    llx = totalBBox.Lower().Xf() < totalBBox.Upper().Xf() ? totalBBox.Lower().Xf() : totalBBox.Upper().Xf();
-    lly = totalBBox.Lower().Yf() < totalBBox.Upper().Yf() ? totalBBox.Lower().Yf() : totalBBox.Upper().Yf();
-    llz = totalBBox.Lower().Zf() < totalBBox.Upper().Zf() ? totalBBox.Lower().Zf() : totalBBox.Upper().Zf();
-    urx = totalBBox.Lower().Xf() > totalBBox.Upper().Xf() ? totalBBox.Lower().Xf() : totalBBox.Upper().Xf();
-    ury = totalBBox.Lower().Yf() > totalBBox.Upper().Yf() ? totalBBox.Lower().Yf() : totalBBox.Upper().Yf();
-    urz = totalBBox.Lower().Zf() > totalBBox.Upper().Zf() ? totalBBox.Lower().Zf() : totalBBox.Upper().Zf();
+    // TODO: The Z values used to not follow the proper ordering.  Investigate
+    // and confirm/infirm that the bug is still there.
+    return totalBBox;
 }
 
 
 FTBBox FTFontImpl::BBox(const char *string, const int start, const int end)
 {
-    float llx, lly, llz, urx, ury, urz;
-    BBoxI((const unsigned char *)string, start, end,
-          llx, lly, llz, urx, ury, urz);
-    FTBBox tmp(llx, lly, llz, urx, ury, urz);
-    return tmp;
-}
-
-
-FTBBox FTFontImpl::BBox(const wchar_t *string, const int start, const int end)
-{
-    float llx, lly, llz, urx, ury, urz;
-    BBoxI(string, start, end, llx, lly, llz, urx, ury, urz);
-    FTBBox tmp(llx, lly, llz, urx, ury, urz);
-    return tmp;
-}
-
-
-void FTFontImpl::BBox(const char* string, const int start, const int end,
-                      float& llx, float& lly, float& llz,
-                      float& urx, float& ury, float& urz)
-{
     /* The chars need to be unsigned because they are cast to int later */
-    return BBoxI((const unsigned char *)string, start, end,
-                 llx, lly, llz, urx, ury, urz);
+    return BBoxI((const unsigned char *)string, start, end);
 }
 
 
-void FTFontImpl::BBox(const wchar_t* string, const int start, const int end,
-                      float& llx, float& lly, float& llz,
-                      float& urx, float& ury, float& urz)
+FTBBox FTFontImpl::BBox(const wchar_t *string, const int start, const int end)
 {
-    return BBoxI(string, start, end, llx, lly, llz, urx, ury, urz);
+    return BBoxI(string, start, end);
 }
 
 
diff --git a/src/FTFont/FTFontImpl.h b/src/FTFont/FTFontImpl.h
index fcb5ea7..f163b7b 100644
--- a/src/FTFont/FTFontImpl.h
+++ b/src/FTFont/FTFontImpl.h
@@ -90,14 +90,6 @@ class FTFontImpl
 
         FTBBox BBox(const wchar_t *s, const int start, const int end);
 
-        void BBox(const char *string, const int start, const int end,
-                  float& llx, float& lly, float& llz,
-                  float& urx, float& ury, float& urz);
-
-        void BBox(const wchar_t *string, const int start, const int end,
-                  float& llx, float& lly, float& llz,
-                  float& urx, float& ury, float& urz);
-
         float Advance(const wchar_t* string);
 
         float Advance(const char* string);
@@ -166,9 +158,7 @@ class FTFontImpl
 
         /* Internal generic BBox() implementation */
         template <typename T>
-        inline void BBoxI(const T *string, const int start, const int end,
-                          float& llx, float& lly, float& llz,
-                          float& urx, float& ury, float& urz);
+        inline FTBBox BBoxI(const T *string, const int start, const int end);
 
         /* Internal generic BBox() implementation */
         template <typename T>