Bug 1433098 - Don't rename downloaded fonts (replacing the original 'name' table) when using DirectWrite backend. r=jrmuizel

This commit is contained in:
Jonathan Kew 2018-01-26 17:26:19 +00:00
Родитель b9bc1f73c5
Коммит 5b401bc09e
3 изменённых файлов: 27 добавлений и 27 удалений

Просмотреть файл

@ -26,7 +26,8 @@ public:
*
* @param aData Font data
*/
gfxDWriteFontFileStream(FallibleTArray<uint8_t> *aData,
gfxDWriteFontFileStream(const uint8_t* aData,
uint32_t aLength,
uint64_t aFontFileKey);
~gfxDWriteFontFileStream();
@ -82,11 +83,16 @@ private:
uint64_t mFontFileKey;
};
gfxDWriteFontFileStream::gfxDWriteFontFileStream(FallibleTArray<uint8_t> *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<uint8_t>& aFontData,
gfxDWriteFontFileLoader::CreateCustomFontFile(const uint8_t* aFontData,
uint32_t aLength,
IDWriteFontFile** aFontFile,
IDWriteFontFileStream** aFontFileStream)
{
@ -165,7 +172,8 @@ gfxDWriteFontFileLoader::CreateCustomFontFile(FallibleTArray<uint8_t>& aFontData
}
uint64_t fontFileKey = sNextFontFileKey++;
RefPtr<IDWriteFontFileStream> ffsRef = new gfxDWriteFontFileStream(&aFontData, fontFileKey);
RefPtr<IDWriteFontFileStream> ffsRef =
new gfxDWriteFontFileStream(aFontData, aLength, fontFileKey);
sFontFileStreams[fontFileKey] = ffsRef;
RefPtr<IDWriteFontFile> fontFile;

Просмотреть файл

@ -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<uint8_t>& aFontData,
static HRESULT CreateCustomFontFile(const uint8_t* aFontData,
uint32_t aLength,
IDWriteFontFile** aFontFile,
IDWriteFontFileStream** aFontFileStream);

Просмотреть файл

@ -934,35 +934,24 @@ 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<uint8_t> newFontData;
rv = gfxFontUtils::RenameFont(uniqueName, aFontData, aLength, &newFontData);
free((void*)aFontData);
if (NS_FAILED(rv)) {
return nullptr;
}
RefPtr<IDWriteFontFileStream> fontFileStream;
RefPtr<IDWriteFontFile> 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;