Bug 1343813 - make NativeFontResourceGDI send the LOGFONT as scaled font instance data. r=bobowen
authorLee Salzman <lsalzman@mozilla.com>
Wed, 29 Mar 2017 18:22:06 -0400
changeset 350451 09daa6aeb0a2607c095197f35421915e20869ea8
parent 350450 887df2649e914efaf9215f27080bed3367ff5301
child 350452 83d25c5fdde7aa894cc4cb27e0eac220e5ffc8ec
push id31574
push usercbook@mozilla.com
push dateThu, 30 Mar 2017 11:48:04 +0000
treeherdermozilla-central@03d602fd723a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbobowen
bugs1343813
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1343813 - make NativeFontResourceGDI send the LOGFONT as scaled font instance data. r=bobowen MozReview-Commit-ID: F4UCQSXScHz
gfx/2d/NativeFontResourceGDI.cpp
gfx/2d/NativeFontResourceGDI.h
gfx/2d/RecordedEvent.h
gfx/2d/ScaledFontFontconfig.cpp
gfx/2d/ScaledFontWin.cpp
gfx/2d/ScaledFontWin.h
--- a/gfx/2d/NativeFontResourceGDI.cpp
+++ b/gfx/2d/NativeFontResourceGDI.cpp
@@ -4,110 +4,60 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "NativeFontResourceGDI.h"
 
 #include "Logging.h"
 #include "mozilla/RefPtr.h"
 #include "ScaledFontWin.h"
-#include "SFNTData.h"
 
 namespace mozilla {
 namespace gfx {
 
 /* static */
 already_AddRefed<NativeFontResourceGDI>
 NativeFontResourceGDI::Create(uint8_t *aFontData, uint32_t aDataLength,
                               bool aNeedsCairo)
 {
-  UniquePtr<SFNTData> sfntData = SFNTData::Create(aFontData, aDataLength);
-  if (!sfntData) {
-    gfxWarning() << "Failed to create SFNTData for ScaledFontWin.";
-    return nullptr;
-  }
-
-  Vector<mozilla::u16string> fontNames;
-  if (!sfntData->GetU16FullNames(fontNames)) {
-    gfxWarning() << "Failed to get font names from font.";
-    return nullptr;
-  }
-
-  // lfFaceName has a maximum length including null.
-  for (size_t i = 0; i < fontNames.length(); ++i) {
-    if (fontNames[i].size() > LF_FACESIZE - 1) {
-      fontNames[i].resize(LF_FACESIZE - 1);
-    }
-    // Add null to end for easy copying later.
-    fontNames[i].append(1, '\0');
-  }
-
   DWORD numberOfFontsAdded;
   HANDLE fontResourceHandle = ::AddFontMemResourceEx(aFontData, aDataLength,
                                                      0, &numberOfFontsAdded);
   if (!fontResourceHandle) {
     gfxWarning() << "Failed to add memory font resource.";
     return nullptr;
   }
 
-  if (numberOfFontsAdded != fontNames.length()) {
-    gfxWarning() <<
-      "Number of fonts added doesn't match number of names extracted.";
-  }
-
   RefPtr<NativeFontResourceGDI> fontResouce =
-    new NativeFontResourceGDI(fontResourceHandle, Move(fontNames), aNeedsCairo);
+    new NativeFontResourceGDI(fontResourceHandle, aNeedsCairo);
 
   return fontResouce.forget();
 }
 
 NativeFontResourceGDI::~NativeFontResourceGDI()
 {
   ::RemoveFontMemResourceEx(mFontResourceHandle);
 }
 
 already_AddRefed<ScaledFont>
 NativeFontResourceGDI::CreateScaledFont(uint32_t aIndex, Float aGlyphSize,
                                         const uint8_t* aInstanceData, uint32_t aInstanceDataLength)
 {
-  if (aIndex >= mFontNames.length()) {
-    gfxWarning() << "Font index is too high for font resource.";
-    return nullptr;
-  }
-
-  if (mFontNames[aIndex].empty()) {
-    gfxWarning() << "Font name for index is empty.";
+  if (aInstanceDataLength < sizeof(LOGFONT)) {
+    gfxWarning() << "GDI scaled font instance data is truncated.";
     return nullptr;
   }
 
-  LOGFONT logFont;
-  logFont.lfHeight = 0;
-  logFont.lfWidth = 0;
-  logFont.lfEscapement = 0;
-  logFont.lfOrientation = 0;
-  logFont.lfWeight = FW_DONTCARE;
-  logFont.lfItalic = FALSE;
-  logFont.lfUnderline = FALSE;
-  logFont.lfStrikeOut = FALSE;
-  logFont.lfCharSet = DEFAULT_CHARSET;
-  logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
-  logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
-  logFont.lfQuality = DEFAULT_QUALITY;
-  logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
-
-  // Copy name to mLogFont (null already included in font name). We cast here
-  // because for VS2015 char16_t != wchar_t, even though they are both 16 bit.
-  mFontNames[aIndex].copy(reinterpret_cast<char16_t*>(logFont.lfFaceName),
-                          mFontNames[aIndex].length());
+  const LOGFONT* logFont = reinterpret_cast<const LOGFONT*>(aInstanceData);
 
   // Constructor for ScaledFontWin dereferences and copies the LOGFONT, so we
   // are safe to pass this reference.
-  RefPtr<ScaledFontBase> scaledFont = new ScaledFontWin(&logFont, aGlyphSize);
+  RefPtr<ScaledFontBase> scaledFont = new ScaledFontWin(logFont, aGlyphSize);
   if (mNeedsCairo && !scaledFont->PopulateCairoScaledFont()) {
-    gfxWarning() << "Unable to create cairo scaled font DWrite font.";
+    gfxWarning() << "Unable to create cairo scaled font GDI font.";
     return nullptr;
   }
 
   return scaledFont.forget();
 }
 
 } // gfx
 } // mozilla
--- a/gfx/2d/NativeFontResourceGDI.h
+++ b/gfx/2d/NativeFontResourceGDI.h
@@ -7,17 +7,16 @@
 #ifndef mozilla_gfx_NativeFontResourceGDI_h
 #define mozilla_gfx_NativeFontResourceGDI_h
 
 #include <windows.h>
 
 #include "2D.h"
 #include "mozilla/AlreadyAddRefed.h"
 #include "mozilla/Vector.h"
-#include "u16string.h"
 
 namespace mozilla {
 namespace gfx {
 
 class NativeFontResourceGDI final : public NativeFontResource
 {
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResourceGDI)
@@ -36,23 +35,21 @@ public:
   ~NativeFontResourceGDI();
 
   already_AddRefed<ScaledFont>
     CreateScaledFont(uint32_t aIndex, Float aGlyphSize,
                      const uint8_t* aInstanceData, uint32_t aInstanceDataLength) final;
 
 private:
   NativeFontResourceGDI(HANDLE aFontResourceHandle,
-                        Vector<mozilla::u16string>&& aFontNames,
                         bool aNeedsCairo)
-    : mFontResourceHandle(aFontResourceHandle), mFontNames(Move(aFontNames))
+    : mFontResourceHandle(aFontResourceHandle)
     , mNeedsCairo(aNeedsCairo)
   {}
 
   HANDLE mFontResourceHandle;
-  Vector<mozilla::u16string> mFontNames;
   bool mNeedsCairo;
 };
 
 } // gfx
 } // mozilla
 
 #endif // mozilla_gfx_NativeFontResourceGDI_h
--- a/gfx/2d/RecordedEvent.h
+++ b/gfx/2d/RecordedEvent.h
@@ -19,17 +19,17 @@ struct PathOp;
 class PathRecording;
 
 const uint32_t kMagicInt = 0xc001feed;
 
 // A change in major revision means a change in event binary format, causing
 // loss of backwards compatibility. Old streams will not work in a player
 // using a newer major revision. And new streams will not work in a player
 // using an older major revision.
-const uint16_t kMajorRevision = 7;
+const uint16_t kMajorRevision = 8;
 // A change in minor revision means additions of new events. New streams will
 // not play in older players.
 const uint16_t kMinorRevision = 0;
 
 struct ReferencePtr
 {
   ReferencePtr()
     : mLongPtr(0)
--- a/gfx/2d/ScaledFontFontconfig.cpp
+++ b/gfx/2d/ScaledFontFontconfig.cpp
@@ -273,16 +273,17 @@ ScaledFontFontconfig::GetFontDescriptor(
   uint8_t* data = new uint8_t[dataLength];
   FontDescriptor* desc = reinterpret_cast<FontDescriptor*>(data);
   desc->mPathLength = pathLength;
   desc->mIndex = index;
   desc->mInstanceData = InstanceData(GetCairoScaledFont(), mPattern);
   memcpy(data + sizeof(FontDescriptor), pathname, pathLength);
 
   aCb(data, dataLength, mSize, aBaton);
+  delete[] data;
   return true;
 }
 
 already_AddRefed<ScaledFont>
 ScaledFontFontconfig::CreateFromInstanceData(const InstanceData& aInstanceData,
                                              FT_Face aFace, const char* aPathname, uint32_t aIndex,
                                              Float aSize)
 
--- a/gfx/2d/ScaledFontWin.cpp
+++ b/gfx/2d/ScaledFontWin.cpp
@@ -3,32 +3,31 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ScaledFontWin.h"
 
 #include "AutoHelpersWin.h"
 #include "Logging.h"
 #include "nsString.h"
-#include "SFNTData.h"
 
 #ifdef USE_SKIA
 #include "skia/include/ports/SkTypeface_win.h"
 #endif
 
 #ifdef USE_CAIRO_SCALED_FONT
 #include "cairo-win32.h"
 #endif
 
 #include "HelpersWinFonts.h"
 
 namespace mozilla {
 namespace gfx {
 
-ScaledFontWin::ScaledFontWin(LOGFONT* aFont, Float aSize)
+ScaledFontWin::ScaledFontWin(const LOGFONT* aFont, Float aSize)
   : ScaledFontBase(aSize)
   , mLogFont(*aFont)
 {
 }
 
 bool
 ScaledFontWin::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton)
 {
@@ -50,39 +49,24 @@ ScaledFontWin::GetFontFileData(FontFileD
   UniquePtr<uint8_t[]> fontData(new uint8_t[tableSize]);
 
   uint32_t sizeGot =
     ::GetFontData(dc.GetDC(), table, 0, fontData.get(), tableSize);
   if (sizeGot != tableSize) {
     return false;
   }
 
-  // If it's a font collection then attempt to get the index.
-  uint32_t index = 0;
-  if (table != 0) {
-    UniquePtr<SFNTData> sfntData = SFNTData::Create(fontData.get(),
-                                                    tableSize);
-    if (!sfntData) {
-      gfxWarning() << "Failed to create SFNTData for GetFontFileData.";
-      return false;
-    }
+  aDataCallback(fontData.get(), tableSize, 0, mSize, 0, nullptr, aBaton);
+  return true;
+}
 
-    // We cast here because for VS2015 char16_t != wchar_t, even though they are
-    // both 16 bit.
-    if (!sfntData->GetIndexForU16Name(
-          reinterpret_cast<char16_t*>(mLogFont.lfFaceName), &index, LF_FACESIZE - 1)) {
-      gfxWarning() << "Failed to get index for face name.";
-      gfxDevCrash(LogReason::GetFontFileDataFailed) <<
-        "Failed to get index for face name |" <<
-        NS_ConvertUTF16toUTF8(mLogFont.lfFaceName).get() << "|.";
-      return false;
-    }
-  }
-
-  aDataCallback(fontData.get(), tableSize, index, mSize, 0, nullptr, aBaton);
+bool
+ScaledFontWin::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
+{
+  aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), aBaton);
   return true;
 }
 
 bool
 ScaledFontWin::GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton)
 {
   aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), mSize, aBaton);
   return true;
--- a/gfx/2d/ScaledFontWin.h
+++ b/gfx/2d/ScaledFontWin.h
@@ -11,22 +11,24 @@
 
 namespace mozilla {
 namespace gfx {
 
 class ScaledFontWin : public ScaledFontBase
 {
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontWin)
-  ScaledFontWin(LOGFONT* aFont, Float aSize);
+  ScaledFontWin(const LOGFONT* aFont, Float aSize);
 
   virtual FontType GetType() const { return FontType::GDI; }
 
   bool GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton) override;
 
+  bool GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton) override;
+
   virtual bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
 
   static already_AddRefed<ScaledFont>
     CreateFromFontDescriptor(const uint8_t* aData, uint32_t aDataLength, Float aSize);
 
   virtual AntialiasMode GetDefaultAAMode() override;
 
 #ifdef USE_SKIA