bug 718513 - [dwrite] implement synthetic bolding for fonts loaded via @font-face with src:local(). r=bas
authorJonathan Kew <jfkthame@gmail.com>
Wed, 18 Jan 2012 21:18:10 +0000
changeset 86046 92395111938e3a363af505e160d26305234d4357
parent 86045 0f8b66a9333317df9159b8bc255754ddb0a92dd5
child 86047 d05a2f422e7d86f94c097b97230425207f948aeb
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs718513
milestone12.0a1
bug 718513 - [dwrite] implement synthetic bolding for fonts loaded via @font-face with src:local(). r=bas
gfx/thebes/gfxDWriteFontList.cpp
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -426,16 +426,46 @@ gfxDWriteFontEntry::CreateFontInstance(c
 
 nsresult
 gfxDWriteFontEntry::CreateFontFace(IDWriteFontFace **aFontFace,
                                    DWRITE_FONT_SIMULATIONS aSimulations)
 {
     HRESULT hr;
     if (mFont) {
         hr = mFont->CreateFontFace(aFontFace);
+        if (SUCCEEDED(hr) && (aSimulations & DWRITE_FONT_SIMULATIONS_BOLD) &&
+            !((*aFontFace)->GetSimulations() & DWRITE_FONT_SIMULATIONS_BOLD)) {
+            // need to replace aFontFace with a version that has the Bold
+            // simulation - unfortunately, DWrite doesn't provide a simple API
+            // for this
+            nsRefPtr<IDWriteFontFace> origFace = (*aFontFace);
+            (*aFontFace)->Release();
+            *aFontFace = NULL;
+            UINT32 numberOfFiles = 0;
+            hr = origFace->GetFiles(&numberOfFiles, NULL);
+            if (FAILED(hr)) {
+                return NS_ERROR_FAILURE;
+            }
+            nsAutoTArray<IDWriteFontFile*,1> files;
+            files.AppendElements(numberOfFiles);
+            hr = origFace->GetFiles(&numberOfFiles, files.Elements());
+            if (FAILED(hr)) {
+                return NS_ERROR_FAILURE;
+            }
+            hr = gfxWindowsPlatform::GetPlatform()->GetDWriteFactory()->
+                CreateFontFace(origFace->GetType(),
+                               numberOfFiles,
+                               files.Elements(),
+                               origFace->GetIndex(),
+                               aSimulations,
+                               aFontFace);
+            for (UINT32 i = 0; i < numberOfFiles; ++i) {
+                files[i]->Release();
+            }
+        }
     } else if (mFontFile) {
         IDWriteFontFile *fontFile = mFontFile.get();
         hr = gfxWindowsPlatform::GetPlatform()->GetDWriteFactory()->
             CreateFontFace(mFaceType,
                            1,
                            &fontFile,
                            0,
                            aSimulations,