Added some stuff from gfxPangoFonts implementation
authorromashin
Sat, 19 Apr 2008 18:39:55 +0300
changeset 16824 dfa6c7ddbab2008617506b687ddedc00f4598019
parent 16823 b0e976cc3b93e4ace0787a7d26ee668849572934
child 16825 9f77bf854180533001c27c800644b147a4cd2c14
push id1298
push userpavlov@mozilla.com
push dateSun, 17 Aug 2008 05:03:09 +0000
treeherderautoland@4a506fa751d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone2.0a1pre
Added some stuff from gfxPangoFonts implementation
gfx/thebes/src/gfxQtFonts.cpp
--- a/gfx/thebes/src/gfxQtFonts.cpp
+++ b/gfx/thebes/src/gfxQtFonts.cpp
@@ -38,16 +38,17 @@
 #include "gfxTypes.h"
 #include "gfxQtFonts.h"
 #include "qdebug.h"
 #include "qrect.h"
 #include <locale.h>
 #include <QFont>
 #include <QFontMetrics>
 #include "cairo-ft.h"
+#include <freetype/tttables.h>
 
 /**
  * gfxQtFontGroup
  */
 
 static int
 FFRECountHyphens (const nsAString &aFFREName)
 {
@@ -396,16 +397,24 @@ gfxQtFont::gfxQtFont(const nsAString &aN
 }
 
 gfxQtFont::~gfxQtFont()
 {
     delete mQFont;
     cairo_scaled_font_destroy(mCairoFont);
 }
 
+// rounding and truncation functions for a Freetype floating point number 
+// (FT26Dot6) stored in a 32bit integer with high 26 bits for the integer
+// part and low 6 bits for the fractional part. 
+#define MOZ_FT_ROUND(x) (((x) + 32) & ~63) // 63 = 2^6 - 1
+#define MOZ_FT_TRUNC(x) ((x) >> 6)
+#define CONVERT_DESIGN_UNITS_TO_PIXELS(v, s) \
+        MOZ_FT_TRUNC(MOZ_FT_ROUND(FT_MulFix((v) , (s))))
+
 const gfxFont::Metrics&
 gfxQtFont::GetMetrics()
 {
      if (mHasMetrics)
         return mMetrics;
 
     QFontMetrics fontMetrics( *mQFont );
 
@@ -435,19 +444,45 @@ gfxQtFont::GetMetrics()
 
     mMetrics.emAscent = lineHeight > 0.0 ?
         mMetrics.maxAscent * mMetrics.emHeight / lineHeight : 0.0;
     mMetrics.emDescent = mMetrics.emHeight - mMetrics.emAscent;
 
     mMetrics.spaceWidth = fontMetrics.width( QChar(' ') );
     mMetrics.xHeight = fontMetrics.xHeight();
 
+#if 0
+    FT_Face face = mQFont->freetypeFace();
+    if (face) {
+        mMetrics.maxAdvance = face->size->metrics.max_advance / 64.0; // 26.6
+        float val;
+        TT_OS2 *os2 = (TT_OS2 *) FT_Get_Sfnt_Table(face, ft_sfnt_os2);
+        if (os2 && os2->ySuperscriptYOffset) {
+            val = CONVERT_DESIGN_UNITS_TO_PIXELS(os2->ySuperscriptYOffset,
+                                                 face->size->metrics.y_scale);
+            mMetrics.superscriptOffset = PR_MAX(1, val);
+        } else {
+            mMetrics.superscriptOffset = mMetrics.xHeight;
+        }
 
-    mMetrics.superscriptOffset = mMetrics.xHeight;
-    mMetrics.subscriptOffset = mMetrics.xHeight;
+        if (os2 && os2->ySubscriptYOffset) {
+            val = CONVERT_DESIGN_UNITS_TO_PIXELS(os2->ySubscriptYOffset,
+                                                 face->size->metrics.y_scale);
+            // some fonts have the incorrect sign..
+            val = (val < 0) ? -val : val;
+            mMetrics.subscriptOffset = PR_MAX(1, val);
+        } else {
+            mMetrics.subscriptOffset = mMetrics.xHeight;
+        }
+    } else
+#endif
+    {
+        mMetrics.superscriptOffset = mMetrics.xHeight;
+        mMetrics.subscriptOffset = mMetrics.xHeight;
+    }
 
     SanitizeMetrics(&mMetrics, PR_FALSE);
 
 #if 0
 
     fprintf (stderr, "Font: %s\n", NS_ConvertUTF16toUTF8(mName).get());
     fprintf (stderr, "    emHeight: %f emAscent: %f emDescent: %f\n", mMetrics.emHeight, mMetrics.emAscent, mMetrics.emDescent);
     fprintf (stderr, "    maxAscent: %f maxDescent: %f\n", mMetrics.maxAscent, mMetrics.maxDescent);