Bug 1156742 Part 22: Change ScaledFontDWrite to support creation from TrueType Collection data. r=bas
authorBob Owen <bobowencode@gmail.com>
Tue, 05 Jan 2016 10:08:58 +0000
changeset 318992 f67ed3a6ee9a94c5a294528e006b4b07eb559abe
parent 318991 6e490856b991d39f70c08231462a043b555c1d00
child 318993 f2ce8e30096013f0957ce0ad42b1640be877f22e
push id8951
push userbenj@benj.me
push dateTue, 05 Jan 2016 13:08:54 +0000
reviewersbas
bugs1156742
milestone46.0a1
Bug 1156742 Part 22: Change ScaledFontDWrite to support creation from TrueType Collection data. r=bas
gfx/2d/ScaledFontDWrite.cpp
--- a/gfx/2d/ScaledFontDWrite.cpp
+++ b/gfx/2d/ScaledFontDWrite.cpp
@@ -303,18 +303,33 @@ ScaledFontDWrite::ScaledFontDWrite(uint8
   RefPtr<IDWriteFontFileStream> ffsRef = sFontFileStreams[fontFileKey];
 
   RefPtr<IDWriteFontFile> fontFile;
   if (FAILED(factory->CreateCustomFontFileReference(&fontFileKey, sizeof(fontFileKey), DWriteFontFileLoader::Instance(), getter_AddRefs(fontFile)))) {
     gfxWarning() << "Failed to load font file from data!";
     return;
   }
 
+  BOOL isSupported;
+  DWRITE_FONT_FILE_TYPE fileType;
+  DWRITE_FONT_FACE_TYPE faceType;
+  UINT32 numberOfFaces;
+  fontFile->Analyze(&isSupported, &fileType, &faceType, &numberOfFaces);
+  if (!isSupported) {
+    gfxWarning() << "Font file is not supported.";
+    return;
+  }
+
+  if (aIndex >= numberOfFaces) {
+    gfxWarning() << "Font face index is greater than number of fonts in file.";
+    return;
+  }
+
   IDWriteFontFile *ff = fontFile;
-  if (FAILED(factory->CreateFontFace(DWRITE_FONT_FACE_TYPE_TRUETYPE, 1, &ff, aIndex, DWRITE_FONT_SIMULATIONS_NONE, getter_AddRefs(mFontFace)))) {
+  if (FAILED(factory->CreateFontFace(faceType, 1, &ff, aIndex, DWRITE_FONT_SIMULATIONS_NONE, getter_AddRefs(mFontFace)))) {
     gfxWarning() << "Failed to create font face from font file data!";
     return;
   }
 
   // Now that we've successfully created the font take ownership of the
   // reference, so that we know that the font file stream will be around if
   // someone calls GetFontFileData.
   mFontFileStream = ffsRef.forget();