Bug 1256678 - Account for truncated font names in ScaledFontWin::GetFontFileData() - r=jfkthame
authorEdwin Flores <edwin@mozilla.com>
Fri, 22 Apr 2016 13:23:25 +0100
changeset 332412 0a64b841be88b591fc8c86b99e4fbc01cd5fc22d
parent 332411 7600273fa9a96bfb1a6c30a95bd0951f696081c6
child 332413 ed251ff578cd53fe8a862a487aa7b7bd422c9dfb
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1256678
milestone48.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 1256678 - Account for truncated font names in ScaledFontWin::GetFontFileData() - r=jfkthame
gfx/2d/SFNTData.cpp
gfx/2d/SFNTData.h
gfx/2d/ScaledFontWin.cpp
--- a/gfx/2d/SFNTData.cpp
+++ b/gfx/2d/SFNTData.cpp
@@ -199,21 +199,30 @@ SFNTData::GetU16FullNames(Vector<mozilla
     }
   }
 
   return fontFound;
 }
 
 bool
 SFNTData::GetIndexForU16Name(const mozilla::u16string& aU16FullName,
-                             uint32_t* aIndex)
+                             uint32_t* aIndex, size_t aTruncatedLen)
 {
   for (size_t i = 0; i < mFonts.length(); ++i) {
     mozilla::u16string name;
-    if (mFonts[i]->GetU16FullName(name) && name == aU16FullName) {
+    if (!mFonts[i]->GetU16FullName(name)) {
+      continue;
+    }
+
+    if (aTruncatedLen) {
+      MOZ_ASSERT(aU16FullName.length() <= aTruncatedLen);
+      name = name.substr(0, aTruncatedLen);
+    }
+
+    if (name == aU16FullName) {
       *aIndex = i;
       return true;
     }
   }
 
   return false;
 }
 
--- a/gfx/2d/SFNTData.h
+++ b/gfx/2d/SFNTData.h
@@ -65,19 +65,21 @@ public:
    */
   bool GetU16FullNames(Vector<mozilla::u16string>& aU16FullNames);
 
   /**
    * Returns the index for the first UTF16 name matching aU16FullName.
    *
    * @param aU16FullName full name to find.
    * @param aIndex out param for the index if found.
+   * @param aTruncatedLen length to truncate the compared font name to.
    * @return true if the full name is successfully read.
    */
-  bool GetIndexForU16Name(const mozilla::u16string& aU16FullName, uint32_t* aIndex);
+  bool GetIndexForU16Name(const mozilla::u16string& aU16FullName, uint32_t* aIndex,
+                          size_t aTruncatedLen = 0);
 
 private:
 
   SFNTData() {}
 
   bool AddFont(const uint8_t *aFontData, uint32_t aDataLength,
                uint32_t aOffset);
 
--- a/gfx/2d/ScaledFontWin.cpp
+++ b/gfx/2d/ScaledFontWin.cpp
@@ -60,17 +60,17 @@ ScaledFontWin::GetFontFileData(FontFileD
     if (!sfntData) {
       gfxWarning() << "Failed to create SFNTData for GetFontFileData.";
       return false;
     }
 
     // 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)) {
+          reinterpret_cast<char16_t*>(mLogFont.lfFaceName), &index, LF_FACESIZE - 1)) {
       gfxWarning() << "Failed to get index for face name.";
       return false;
     }
   }
 
   aDataCallback(fontData.get(), tableSize, index, mSize, aBaton);
   return true;
 }