b=569770 part 5: gfxFT2FontBase::GetHintedGlyphWidth implementation r=jfkthame
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 09 Dec 2010 20:28:51 +1300
changeset 58946 04bffc3f2754c0be041dc98344e6f06939a7eb08
parent 58945 25e50bb14a82ada5c312f13594d69cd8e8de565a
child 58947 a95df38d5991ea66a3250526578aaa8ba845f2e1
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjfkthame
bugs569770
milestone2.0b8pre
b=569770 part 5: gfxFT2FontBase::GetHintedGlyphWidth implementation r=jfkthame
gfx/thebes/gfxFT2FontBase.cpp
gfx/thebes/gfxFT2FontBase.h
gfx/thebes/gfxFont.h
--- a/gfx/thebes/gfxFT2FontBase.cpp
+++ b/gfx/thebes/gfxFT2FontBase.cpp
@@ -197,16 +197,25 @@ gfxFT2FontBase::GetFontTable(PRUint32 aT
     PRBool haveTable = gfxFT2LockedFace(this).GetFontTable(aTag, buffer);
 
     // Cache even when there is no table to save having to open the FT_Face
     // again.
     return mFontEntry->ShareFontTableAndGetBlob(aTag,
                                                 haveTable ? &buffer : nsnull);
 }
 
+PRInt32
+gfxFT2FontBase::GetHintedGlyphWidth(gfxContext *aCtx, PRUint16 aGID)
+{
+    cairo_text_extents_t extents;
+    GetGlyphExtents(aGID, &extents);
+    // convert to 16.16 fixed point
+    return NS_lround(0x10000 * extents.x_advance);
+}
+
 PRBool
 gfxFT2FontBase::SetupCairoFont(gfxContext *aContext)
 {
     cairo_t *cr = aContext->GetCairo();
 
     // The scaled font ctm is not relevant right here because
     // cairo_set_scaled_font does not record the scaled font itself, but
     // merely the font_face, font_matrix, font_options.  The scaled_font used
--- a/gfx/thebes/gfxFT2FontBase.h
+++ b/gfx/thebes/gfxFT2FontBase.h
@@ -56,16 +56,18 @@ public:
 
     PRUint32 GetGlyph(PRUint32 aCharCode);
     void GetGlyphExtents(PRUint32 aGlyph,
                          cairo_text_extents_t* aExtents);
     virtual const gfxFont::Metrics& GetMetrics();
     virtual nsString GetUniqueName();
     virtual PRUint32 GetSpaceGlyph();
     virtual hb_blob_t *GetFontTable(PRUint32 aTag);
+    virtual PRBool ProvidesHintedWidths() const { return PR_TRUE; }
+    virtual PRInt32 GetHintedGlyphWidth(gfxContext *aCtx, PRUint16 aGID);
 
     cairo_scaled_font_t *CairoScaledFont() { return mScaledFont; };
     virtual PRBool SetupCairoFont(gfxContext *aContext);
 
 protected:
     cairo_scaled_font_t *mScaledFont;
     PRUint32 mSpaceGlyph;
     PRBool mHasMetrics;
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -1002,16 +1002,18 @@ public:
 
     // subclasses may provide hinted glyph widths (in font units);
     // if they do not override this, harfbuzz will use unhinted widths
     // derived from the font tables
     virtual PRBool ProvidesHintedWidths() const {
         return PR_FALSE;
     }
 
+    // The return value is interpreted as a horizontal advance in 16.16 fixed
+    // point format.
     virtual PRInt32 GetHintedGlyphWidth(gfxContext *aCtx, PRUint16 aGID) {
         return -1;
     }
 
     // Font metrics
     struct Metrics {
         gfxFloat xHeight;
         gfxFloat superscriptOffset;