diff --git a/gfx/thebes/gfxDWriteCommon.cpp b/gfx/thebes/gfxDWriteCommon.cpp index 1852a9c66c42..76d52538f641 100644 --- a/gfx/thebes/gfxDWriteCommon.cpp +++ b/gfx/thebes/gfxDWriteCommon.cpp @@ -26,7 +26,8 @@ public: * * @param aData Font data */ - gfxDWriteFontFileStream(FallibleTArray *aData, + gfxDWriteFontFileStream(const uint8_t* aData, + uint32_t aLength, uint64_t aFontFileKey); ~gfxDWriteFontFileStream(); @@ -82,11 +83,16 @@ private: uint64_t mFontFileKey; }; -gfxDWriteFontFileStream::gfxDWriteFontFileStream(FallibleTArray *aData, +gfxDWriteFontFileStream::gfxDWriteFontFileStream(const uint8_t* aData, + uint32_t aLength, uint64_t aFontFileKey) : mFontFileKey(aFontFileKey) { - mData.SwapElements(*aData); + // If this fails, mData will remain empty. That's OK: GetFileSize() + // will then return 0, etc., and the font just won't load. + if (!mData.AppendElements(aData, aLength, mozilla::fallible_t())) { + NS_WARNING("Failed to store data in gfxDWriteFontFileStream"); + } } gfxDWriteFontFileStream::~gfxDWriteFontFileStream() @@ -151,7 +157,8 @@ gfxDWriteFontFileLoader::CreateStreamFromKey(const void *fontFileReferenceKey, /* static */ HRESULT -gfxDWriteFontFileLoader::CreateCustomFontFile(FallibleTArray& aFontData, +gfxDWriteFontFileLoader::CreateCustomFontFile(const uint8_t* aFontData, + uint32_t aLength, IDWriteFontFile** aFontFile, IDWriteFontFileStream** aFontFileStream) { @@ -165,7 +172,8 @@ gfxDWriteFontFileLoader::CreateCustomFontFile(FallibleTArray& aFontData } uint64_t fontFileKey = sNextFontFileKey++; - RefPtr ffsRef = new gfxDWriteFontFileStream(&aFontData, fontFileKey); + RefPtr ffsRef = + new gfxDWriteFontFileStream(aFontData, aLength, fontFileKey); sFontFileStreams[fontFileKey] = ffsRef; RefPtr fontFile; diff --git a/gfx/thebes/gfxDWriteCommon.h b/gfx/thebes/gfxDWriteCommon.h index 65c2df7bcbe4..5bf6a60e0aae 100644 --- a/gfx/thebes/gfxDWriteCommon.h +++ b/gfx/thebes/gfxDWriteCommon.h @@ -135,14 +135,17 @@ public: /** * Creates a IDWriteFontFile and IDWriteFontFileStream from aFontData. - * aFontData will be empty on return as it swaps out the data. + * The data from aFontData will be copied internally, so the caller + * is free to dispose of it once this method returns. * * @param aFontData the font data for the custom font file + * @param aLength length of the font data * @param aFontFile out param for the created font file * @param aFontFileStream out param for the corresponding stream * @return HRESULT of internal calls */ - static HRESULT CreateCustomFontFile(FallibleTArray& aFontData, + static HRESULT CreateCustomFontFile(const uint8_t* aFontData, + uint32_t aLength, IDWriteFontFile** aFontFile, IDWriteFontFileStream** aFontFileStream); diff --git a/gfx/thebes/gfxDWriteFontList.cpp b/gfx/thebes/gfxDWriteFontList.cpp index d3a5f69895f6..e9acbd20bf5a 100644 --- a/gfx/thebes/gfxDWriteFontList.cpp +++ b/gfx/thebes/gfxDWriteFontList.cpp @@ -934,41 +934,30 @@ gfxDWriteFontList::MakePlatformFont(const nsAString& aFontName, const uint8_t* aFontData, uint32_t aLength) { - nsresult rv; - nsAutoString uniqueName; - rv = gfxFontUtils::MakeUniqueUserFontName(uniqueName); - if (NS_FAILED(rv)) { - free((void*)aFontData); - return nullptr; - } - - FallibleTArray newFontData; - - rv = gfxFontUtils::RenameFont(uniqueName, aFontData, aLength, &newFontData); - free((void*)aFontData); - - if (NS_FAILED(rv)) { - return nullptr; - } - RefPtr fontFileStream; RefPtr fontFile; HRESULT hr = - gfxDWriteFontFileLoader::CreateCustomFontFile(newFontData, + gfxDWriteFontFileLoader::CreateCustomFontFile(aFontData, aLength, getter_AddRefs(fontFile), getter_AddRefs(fontFileStream)); - + free((void*)aFontData); if (FAILED(hr)) { NS_WARNING("Failed to create custom font file reference."); return nullptr; } + nsAutoString uniqueName; + nsresult rv = gfxFontUtils::MakeUniqueUserFontName(uniqueName); + if (NS_FAILED(rv)) { + return nullptr; + } + BOOL isSupported; DWRITE_FONT_FILE_TYPE fileType; UINT32 numFaces; gfxDWriteFontEntry *entry = - new gfxDWriteFontEntry(uniqueName, + new gfxDWriteFontEntry(uniqueName, fontFile, fontFileStream, aWeight,