bug 3512 - support font-stretch in the GDI font backend. r=jdaggett
authorJonathan Kew <jfkthame@gmail.com>
Mon, 05 Sep 2011 08:34:40 +0100
changeset 76547 0d8e92d3138e897984ce726a6d16b6aadf9e0922
parent 76546 36d230088375c24180a1b9b62504dac7b8f5a1d6
child 76548 910e5f55a57e892338367f1f61ea73cc7d32c535
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersjdaggett
bugs3512
milestone9.0a1
bug 3512 - support font-stretch in the GDI font backend. r=jdaggett
gfx/thebes/gfxGDIFontList.cpp
gfx/thebes/gfxGDIFontList.h
--- a/gfx/thebes/gfxGDIFontList.cpp
+++ b/gfx/thebes/gfxGDIFontList.cpp
@@ -208,27 +208,30 @@ FontTypeToOutPrecision(PRUint8 fontType)
 }
 
 /***************************************************************
  *
  * GDIFontEntry
  *
  */
 
-GDIFontEntry::GDIFontEntry(const nsAString& aFaceName, gfxWindowsFontType aFontType,
-                                   PRBool aItalic, PRUint16 aWeight, gfxUserFontData *aUserFontData) : 
-    gfxFontEntry(aFaceName), 
-    mWindowsFamily(0), mWindowsPitch(0),
-    mFontType(aFontType),
-    mForceGDI(PR_FALSE), mUnknownCMAP(PR_FALSE),
-    mCharset(), mUnicodeRanges()
+GDIFontEntry::GDIFontEntry(const nsAString& aFaceName,
+                           gfxWindowsFontType aFontType,
+                           PRBool aItalic, PRUint16 aWeight, PRInt16 aStretch,
+                           gfxUserFontData *aUserFontData)
+    : gfxFontEntry(aFaceName),
+      mWindowsFamily(0), mWindowsPitch(0),
+      mFontType(aFontType),
+      mForceGDI(PR_FALSE), mUnknownCMAP(PR_FALSE),
+      mCharset(), mUnicodeRanges()
 {
     mUserFontData = aUserFontData;
     mItalic = aItalic;
     mWeight = aWeight;
+    mStretch = aStretch;
     if (IsType1())
         mForceGDI = PR_TRUE;
     mIsUserFont = aUserFontData != nsnull;
 
     InitLogFont(aFaceName, aFontType);
 }
 
 nsresult
@@ -313,18 +316,18 @@ GDIFontEntry::GetFontTable(PRUint32 aTab
             return NS_ERROR_OUT_OF_MEMORY;
         }
     }
     return NS_ERROR_FAILURE;
 }
 
 void
 GDIFontEntry::FillLogFont(LOGFONTW *aLogFont, PRBool aItalic,
-                              PRUint16 aWeight, gfxFloat aSize,
-                              PRBool aUseCleartype)
+                          PRUint16 aWeight, gfxFloat aSize,
+                          PRBool aUseCleartype)
 {
     memcpy(aLogFont, &mLogFont, sizeof(LOGFONTW));
 
     aLogFont->lfHeight = (LONG)-ROUND(aSize);
 
     if (aLogFont->lfHeight == 0)
         aLogFont->lfHeight = -1;
 
@@ -409,17 +412,17 @@ GDIFontEntry::TestCharacterMap(PRUint32 
         return mCharacterMap.test(aCh);
     }
 
     return PR_FALSE;
 }
 
 void
 GDIFontEntry::InitLogFont(const nsAString& aName,
-                              gfxWindowsFontType aFontType)
+                          gfxWindowsFontType aFontType)
 {
 #define CLIP_TURNOFF_FONTASSOCIATION 0x40
     
     mLogFont.lfHeight = -1;
 
     // Fill in logFont structure
     mLogFont.lfWidth          = 0;
     mLogFont.lfEscapement     = 0;
@@ -439,24 +442,25 @@ GDIFontEntry::InitLogFont(const nsAStrin
     mLogFont.lfWeight         = mWeight;
 
     int len = NS_MIN<int>(aName.Length(), LF_FACESIZE - 1);
     memcpy(&mLogFont.lfFaceName, nsPromiseFlatString(aName).get(), len * 2);
     mLogFont.lfFaceName[len] = '\0';
 }
 
 GDIFontEntry* 
-GDIFontEntry::CreateFontEntry(const nsAString& aName, gfxWindowsFontType aFontType, 
-                                  PRBool aItalic, PRUint16 aWeight, 
-                                  gfxUserFontData* aUserFontData)
+GDIFontEntry::CreateFontEntry(const nsAString& aName,
+                              gfxWindowsFontType aFontType, PRBool aItalic,
+                              PRUint16 aWeight, PRInt16 aStretch,
+                              gfxUserFontData* aUserFontData)
 {
     // jtdfix - need to set charset, unicode ranges, pitch/family
 
-    GDIFontEntry *fe = new GDIFontEntry(aName, aFontType, aItalic, aWeight,
-                                        aUserFontData);
+    GDIFontEntry *fe = new GDIFontEntry(aName, aFontType, aItalic,
+                                        aWeight, aStretch, aUserFontData);
 
     return fe;
 }
 
 /***************************************************************
  *
  * GDIFontFamily
  *
@@ -495,18 +499,20 @@ GDIFontFamily::FamilyAddStylesProc(const
         if (fe->mWeight == logFont.lfWeight &&
             fe->mItalic == (logFont.lfItalic == 0xFF)) {
             // update the charset bit here since this could be different
             fe->mCharset.set(metrics.tmCharSet);
             return 1; 
         }
     }
 
-    fe = GDIFontEntry::CreateFontEntry(nsDependentString(lpelfe->elfFullName), feType, (logFont.lfItalic == 0xFF),
-                                       (PRUint16) (logFont.lfWeight), nsnull);
+    fe = GDIFontEntry::CreateFontEntry(nsDependentString(lpelfe->elfFullName),
+                                       feType, (logFont.lfItalic == 0xFF),
+                                       (PRUint16) (logFont.lfWeight), 0,
+                                       nsnull);
     if (!fe)
         return 1;
 
     ff->AddFontEntry(fe);
 
     // mark the charset bit
     fe->mCharset.set(metrics.tmCharSet);
 
@@ -742,17 +748,17 @@ gfxGDIFontList::LookupLocalFont(const gf
     
     // use the face name from the lookup font entry, which will be the localized
     // face name which GDI mapping tables use (e.g. with the system locale set to
     // Dutch, a fullname of 'Arial Bold' will find a font entry with the face name
     // 'Arial Vet' which can be used as a key in GDI font lookups).
     gfxFontEntry *fe = GDIFontEntry::CreateFontEntry(lookup->Name(), 
         gfxWindowsFontType(isCFF ? GFX_FONT_TYPE_PS_OPENTYPE : GFX_FONT_TYPE_TRUETYPE) /*type*/, 
         PRUint32(aProxyEntry->mItalic ? FONT_STYLE_ITALIC : FONT_STYLE_NORMAL), 
-        w, nsnull);
+        w, aProxyEntry->mStretch, nsnull);
         
     if (!fe)
         return nsnull;
 
     fe->mIsUserFont = PR_TRUE;
     fe->mIsLocalUserFont = PR_TRUE;
     return fe;
 }
@@ -961,17 +967,17 @@ gfxGDIFontList::MakePlatformFont(const g
 
     // make a new font entry using the unique name
     WinUserFontData *winUserFontData = new WinUserFontData(fontRef, isEmbedded);
     PRUint16 w = (aProxyEntry->mWeight == 0 ? 400 : aProxyEntry->mWeight);
 
     GDIFontEntry *fe = GDIFontEntry::CreateFontEntry(uniqueName, 
         gfxWindowsFontType(isCFF ? GFX_FONT_TYPE_PS_OPENTYPE : GFX_FONT_TYPE_TRUETYPE) /*type*/, 
         PRUint32(aProxyEntry->mItalic ? FONT_STYLE_ITALIC : FONT_STYLE_NORMAL), 
-        w, winUserFontData);
+        w, aProxyEntry->mStretch, winUserFontData);
 
     if (!fe)
         return fe;
 
     fe->mIsUserFont = PR_TRUE;
 
     // Uniscribe doesn't place CFF fonts loaded privately 
     // via AddFontMemResourceEx on XP/Vista
--- a/gfx/thebes/gfxGDIFontList.h
+++ b/gfx/thebes/gfxGDIFontList.h
@@ -270,40 +270,42 @@ public:
 
     virtual PRBool SkipDuringSystemFallback() { 
         return !HasCmapTable(); // explicitly skip non-SFNT fonts
     }
 
     virtual PRBool TestCharacterMap(PRUint32 aCh);
 
     // create a font entry for a font with a given name
-    static GDIFontEntry* CreateFontEntry(const nsAString& aName, 
-                                      gfxWindowsFontType aFontType, 
-                                      PRBool aItalic, PRUint16 aWeight, 
-                                      gfxUserFontData* aUserFontData);
+    static GDIFontEntry* CreateFontEntry(const nsAString& aName,
+                                         gfxWindowsFontType aFontType,
+                                         PRBool aItalic,
+                                         PRUint16 aWeight, PRInt16 aStretch,
+                                         gfxUserFontData* aUserFontData);
 
     // create a font entry for a font referenced by its fullname
     static GDIFontEntry* LoadLocalFont(const gfxProxyFontEntry &aProxyEntry,
-                                    const nsAString& aFullname);
+                                       const nsAString& aFullname);
 
     PRUint8 mWindowsFamily;
     PRUint8 mWindowsPitch;
 
     gfxWindowsFontType mFontType;
     PRPackedBool mForceGDI    : 1;
     PRPackedBool mUnknownCMAP : 1;
 
     gfxSparseBitSet mCharset;
     gfxSparseBitSet mUnicodeRanges;
 
 protected:
     friend class gfxWindowsFont;
 
     GDIFontEntry(const nsAString& aFaceName, gfxWindowsFontType aFontType,
-                     PRBool aItalic, PRUint16 aWeight, gfxUserFontData *aUserFontData);
+                 PRBool aItalic, PRUint16 aWeight, PRInt16 aStretch,
+                 gfxUserFontData *aUserFontData);
 
     void InitLogFont(const nsAString& aName, gfxWindowsFontType aFontType);
 
     virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle, PRBool aNeedsBold);
 
     virtual nsresult GetFontTable(PRUint32 aTableTag,
                                   FallibleTArray<PRUint8>& aBuffer);