diff --git a/gfx/2d/DrawTargetRecording.cpp b/gfx/2d/DrawTargetRecording.cpp index 84f3764271c9..8ee65bb0ac4b 100644 --- a/gfx/2d/DrawTargetRecording.cpp +++ b/gfx/2d/DrawTargetRecording.cpp @@ -389,6 +389,10 @@ DrawTargetRecording::FillGlyphs(ScaledFont *aFont, { EnsurePatternDependenciesStored(aPattern); + if (aFont->GetType() != FontType::DWRITE && aFont->GetType() != FontType::GDI) { + gfxDevCrash(LogReason::GetFontFileDataFailed) << "Unexpected ScaledFont type " << (int)aFont->GetType(); + } + if (!aFont->GetUserData(reinterpret_cast(mRecorder.get()))) { // TODO support font in b2g recordings #ifndef MOZ_WIDGET_GONK diff --git a/gfx/2d/Logging.h b/gfx/2d/Logging.h index 206cf2f0c442..cd2f346ad09a 100644 --- a/gfx/2d/Logging.h +++ b/gfx/2d/Logging.h @@ -133,6 +133,7 @@ enum class LogReason : int { IncompatibleBasicTexturedEffect, InvalidFont, PAllocTextureBackendMismatch, + GetFontFileDataFailed, // End MustBeLessThanThis = 101, }; diff --git a/gfx/2d/SFNTData.cpp b/gfx/2d/SFNTData.cpp index 1978577eb056..2e0fa6e0feef 100644 --- a/gfx/2d/SFNTData.cpp +++ b/gfx/2d/SFNTData.cpp @@ -116,7 +116,7 @@ SFNTData::Create(const uint8_t *aFontData, uint32_t aDataLength) // Check to see if this is a font collection. if (aDataLength < sizeof(TTCHeader)) { - gfxWarning() << "Font data too short."; + gfxDevCrash(LogReason::GetFontFileDataFailed) << "Font data too short: length = " << aDataLength; return nullptr; } @@ -124,7 +124,7 @@ SFNTData::Create(const uint8_t *aFontData, uint32_t aDataLength) if (ttcHeader->ttcTag == TRUETYPE_TAG('t', 't', 'c', 'f')) { uint32_t numFonts = ttcHeader->numFonts; if (aDataLength < sizeof(TTCHeader) + (numFonts * sizeof(BigEndianUint32))) { - gfxWarning() << "Font data too short to contain full TTC Header."; + gfxDevCrash(LogReason::GetFontFileDataFailed) << "Font data too short to contain full TTC Header: numFonts = " << numFonts << "; length = " << aDataLength; return nullptr; } @@ -134,6 +134,7 @@ SFNTData::Create(const uint8_t *aFontData, uint32_t aDataLength) const BigEndianUint32* endOfOffsets = offset + numFonts; while (offset != endOfOffsets) { if (!sfntData->AddFont(aFontData, aDataLength, *offset)) { + gfxDevCrash(LogReason::GetFontFileDataFailed) << "Failed to add font data from TTC"; return nullptr; } ++offset; @@ -144,6 +145,7 @@ SFNTData::Create(const uint8_t *aFontData, uint32_t aDataLength) UniquePtr sfntData(new SFNTData); if (!sfntData->AddFont(aFontData, aDataLength, 0)) { + gfxDevCrash(LogReason::GetFontFileDataFailed) << "Failed to add single font data"; return nullptr; } @@ -223,7 +225,7 @@ SFNTData::AddFont(const uint8_t *aFontData, uint32_t aDataLength, { uint32_t remainingLength = aDataLength - aOffset; if (remainingLength < sizeof(OffsetTable)) { - gfxWarning() << "Font data too short to contain OffsetTable " << aOffset; + gfxCriticalError() << "Font data too short to contain OffsetTable: offset = " << aOffset << "; length = " << aDataLength; return false; } @@ -231,7 +233,7 @@ SFNTData::AddFont(const uint8_t *aFontData, uint32_t aDataLength, reinterpret_cast(aFontData + aOffset); if (remainingLength < sizeof(OffsetTable) + (offsetTable->numTables * sizeof(TableDirEntry))) { - gfxWarning() << "Font data too short to contain tables."; + gfxCriticalError() << "Font data too short to contain tables. numTables = " << offsetTable->numTables << "; offset = " << aOffset << "; length = " << aDataLength; return false; } diff --git a/gfx/2d/ScaledFontWin.cpp b/gfx/2d/ScaledFontWin.cpp index 1993b7efcced..40390cd240f7 100644 --- a/gfx/2d/ScaledFontWin.cpp +++ b/gfx/2d/ScaledFontWin.cpp @@ -40,6 +40,7 @@ ScaledFontWin::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton) table = 0; tableSize = ::GetFontData(dc.GetDC(), table, 0, nullptr, 0); if (tableSize == GDI_ERROR) { + gfxDevCrash(LogReason::GetFontFileDataFailed) << "Failed to get font data from GDI"; return false; } } @@ -49,6 +50,7 @@ ScaledFontWin::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton) uint32_t sizeGot = ::GetFontData(dc.GetDC(), table, 0, fontData.get(), tableSize); if (sizeGot != tableSize) { + gfxDevCrash(LogReason::GetFontFileDataFailed) << "GDI did not return enough data for font: wanted " << tableSize << ", got " << sizeGot; return false; } @@ -58,7 +60,7 @@ ScaledFontWin::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton) UniquePtr sfntData = SFNTData::Create(fontData.get(), tableSize); if (!sfntData) { - gfxWarning() << "Failed to create SFNTData for GetFontFileData."; + gfxDevCrash(LogReason::GetFontFileDataFailed) << "Failed to create SFNTData for GetFontFileData."; return false; } @@ -66,7 +68,7 @@ ScaledFontWin::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton) // both 16 bit. if (!sfntData->GetIndexForU16Name( reinterpret_cast(mLogFont.lfFaceName), &index)) { - gfxWarning() << "Failed to get index for face name."; + gfxDevCrash(LogReason::GetFontFileDataFailed) << "Failed to get index for face name."; return false; } }