Backed out changeset 0529f89855bd (bug 1673397) for causing awsy failures.

This commit is contained in:
Mihai Alexandru Michis 2020-11-14 07:01:24 +02:00
Родитель 78cca3abfe
Коммит ba567fa55c
1 изменённых файлов: 15 добавлений и 68 удалений

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

@ -965,25 +965,6 @@ gfxFontEntry* gfxDWriteFontList::MakePlatformFont(
return entry.release();
}
static void GetPostScriptNameFromNameTable(IDWriteFontFace* aFace,
nsCString& aName) {
const auto kNAME =
NativeEndian::swapToBigEndian(TRUETYPE_TAG('n', 'a', 'm', 'e'));
const char* data;
UINT32 size;
void* context;
BOOL exists;
if (SUCCEEDED(aFace->TryGetFontTable(kNAME, (const void**)&data, &size,
&context, &exists)) &&
exists) {
if (NS_FAILED(gfxFontUtils::ReadCanonicalName(
data, size, gfxFontUtils::NAME_ID_POSTSCRIPT, aName))) {
aName.Truncate(0);
}
aFace->ReleaseFontTable(context);
}
}
gfxFontEntry* gfxDWriteFontList::CreateFontEntry(
fontlist::Face* aFace, const fontlist::Family* aFamily) {
IDWriteFontCollection* collection =
@ -1028,52 +1009,14 @@ gfxFontEntry* gfxDWriteFontList::CreateFontEntry(
return nullptr;
}
}
// Retrieve the required face by index within the family.
RefPtr<IDWriteFont> font;
if (FAILED(family->GetFont(aFace->mIndex, getter_AddRefs(font))) || !font) {
return nullptr;
}
// Retrieve the psName from the font, so we can check we've found the
// expected face.
nsAutoCString psName;
if (FAILED(GetDirectWriteFaceName(font, PSNAME_ID, psName))) {
RefPtr<IDWriteFontFace> dwFontFace;
if (SUCCEEDED(font->CreateFontFace(getter_AddRefs(dwFontFace)))) {
GetPostScriptNameFromNameTable(dwFontFace, psName);
}
}
// If it doesn't match, DirectWrite must have shuffled the order of faces
// returned for the family; search by name as a fallback.
nsCString faceName = aFace->mDescriptor.AsString(SharedFontList());
if (psName != faceName) {
gfxWarning() << "Face name mismatch for index " << aFace->mIndex
<< " in family " << familyName.get() << ": expected "
<< faceName.get() << ", found " << psName.get();
for (uint32_t i = 0; i < family->GetFontCount(); ++i) {
if (i == aFace->mIndex) {
continue; // this was the face we already tried
}
if (FAILED(family->GetFont(i, getter_AddRefs(font))) || !font) {
return nullptr; // this font family is broken!
}
if (FAILED(GetDirectWriteFaceName(font, PSNAME_ID, psName))) {
RefPtr<IDWriteFontFace> dwFontFace;
if (SUCCEEDED(font->CreateFontFace(getter_AddRefs(dwFontFace)))) {
GetPostScriptNameFromNameTable(dwFontFace, psName);
}
}
if (psName == faceName) {
break;
}
}
}
if (psName != faceName) {
nsAutoCString faceName;
if (FAILED(GetDirectWriteFontName(font, faceName))) {
return nullptr;
}
auto fe = new gfxDWriteFontEntry(faceName, font, !aFamily->IsBundled());
fe->InitializeFrom(aFace, aFamily);
fe->mForceGDIClassic = aFamily->IsForceClassic();
@ -1235,9 +1178,8 @@ void gfxDWriteFontList::GetFacesInitDataForFamily(
}
WeightRange weight(FontWeight(dwFont->GetWeight()));
StretchRange stretch(FontStretchFromDWriteStretch(dwFont->GetStretch()));
// Try to read PSName as a unique face identifier; if this fails we'll get
// it directly from the 'name' table, and if that also fails we consider
// the face unusable.
// Try to read PSName as a unique face identifier; we leave the name blank
// if this fails, though the face may still be used.
MOZ_SEH_TRY {
nsAutoCString name;
RefPtr<gfxCharacterMap> charmap;
@ -1245,13 +1187,23 @@ void gfxDWriteFontList::GetFacesInitDataForFamily(
aLoadCmaps) {
RefPtr<IDWriteFontFace> dwFontFace;
if (SUCCEEDED(dwFont->CreateFontFace(getter_AddRefs(dwFontFace)))) {
GetPostScriptNameFromNameTable(dwFontFace, name);
const auto kNAME =
NativeEndian::swapToBigEndian(TRUETYPE_TAG('n', 'a', 'm', 'e'));
const auto kCMAP =
NativeEndian::swapToBigEndian(TRUETYPE_TAG('c', 'm', 'a', 'p'));
const char* data;
UINT32 size;
void* context;
BOOL exists;
if (name.IsEmpty()) {
if (SUCCEEDED(dwFontFace->TryGetFontTable(
kNAME, (const void**)&data, &size, &context, &exists)) &&
exists) {
gfxFontUtils::ReadCanonicalName(
data, size, gfxFontUtils::NAME_ID_POSTSCRIPT, name);
dwFontFace->ReleaseFontTable(context);
}
}
if (aLoadCmaps) {
if (SUCCEEDED(dwFontFace->TryGetFontTable(
kCMAP, (const void**)&data, &size, &context, &exists)) &&
@ -1265,11 +1217,6 @@ void gfxDWriteFontList::GetFacesInitDataForFamily(
}
}
}
if (name.IsEmpty()) {
gfxWarning() << "Failed to get name for face " << i << " in family "
<< aFamily->Key().AsString(SharedFontList()).get();
continue;
}
SlantStyleRange slant(dwstyle == DWRITE_FONT_STYLE_NORMAL
? FontSlantStyle::Normal()
: dwstyle == DWRITE_FONT_STYLE_ITALIC