mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1786281 - Use AutoHBBlob for temporary blobs in various places, to replace manual destruction. r=gfx-reviewers,lsalzman
Depends on D155208 Differential Revision: https://phabricator.services.mozilla.com/D155209
This commit is contained in:
parent
166dab3f9d
commit
5839530325
@ -855,13 +855,10 @@ bool gfxDWriteFontEntry::IsCJKFont() {
|
||||
mIsCJK = false;
|
||||
|
||||
const uint32_t kOS2Tag = TRUETYPE_TAG('O', 'S', '/', '2');
|
||||
hb_blob_t* blob = GetFontTable(kOS2Tag);
|
||||
gfxFontUtils::AutoHBBlob blob(GetFontTable(kOS2Tag));
|
||||
if (!blob) {
|
||||
return mIsCJK;
|
||||
}
|
||||
// |blob| is an owning reference, but is not RAII-managed, so it must be
|
||||
// explicitly freed using |hb_blob_destroy| before we return. (Beware of
|
||||
// adding any early-return codepaths!)
|
||||
|
||||
uint32_t len;
|
||||
const OS2Table* os2 =
|
||||
@ -879,7 +876,6 @@ bool gfxDWriteFontEntry::IsCJKFont() {
|
||||
mIsCJK = true;
|
||||
}
|
||||
}
|
||||
hb_blob_destroy(blob);
|
||||
|
||||
return mIsCJK;
|
||||
}
|
||||
|
@ -277,19 +277,20 @@ static void SetPropertiesFromFace(gfxFontEntry* aFontEntry,
|
||||
};
|
||||
|
||||
// Get the macStyle field from the 'head' table
|
||||
hb_blob_t* blob = hb_face_reference_table(aFace, HB_TAG('h', 'e', 'a', 'd'));
|
||||
gfxFontUtils::AutoHBBlob headBlob(
|
||||
hb_face_reference_table(aFace, HB_TAG('h', 'e', 'a', 'd')));
|
||||
unsigned int len;
|
||||
const char* data = hb_blob_get_data(blob, &len);
|
||||
const char* data = hb_blob_get_data(headBlob, &len);
|
||||
uint16_t style = 0;
|
||||
if (len >= sizeof(HeadTable)) {
|
||||
const HeadTable* head = reinterpret_cast<const HeadTable*>(data);
|
||||
style = head->macStyle;
|
||||
}
|
||||
hb_blob_destroy(blob);
|
||||
|
||||
// Get the OS/2 table for weight & width fields
|
||||
blob = hb_face_reference_table(aFace, HB_TAG('O', 'S', '/', '2'));
|
||||
data = hb_blob_get_data(blob, &len);
|
||||
gfxFontUtils::AutoHBBlob os2blob(
|
||||
hb_face_reference_table(aFace, HB_TAG('O', 'S', '/', '2')));
|
||||
data = hb_blob_get_data(os2blob, &len);
|
||||
uint16_t os2weight = 400;
|
||||
float stretch = 100.0;
|
||||
if (len >= offsetof(OS2Table, fsType)) {
|
||||
@ -300,7 +301,6 @@ static void SetPropertiesFromFace(gfxFontEntry* aFontEntry,
|
||||
stretch = kOS2WidthToStretch[os2width];
|
||||
}
|
||||
}
|
||||
hb_blob_destroy(blob);
|
||||
|
||||
aFontEntry->mStyleRange = SlantStyleRange(
|
||||
(style & 2) ? FontSlantStyle::ITALIC : FontSlantStyle::NORMAL);
|
||||
@ -362,12 +362,12 @@ nsresult FT2FontEntry::ReadCMAP(FontInfoData* aFontInfoData) {
|
||||
|
||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
||||
uint32_t uvsOffset = 0;
|
||||
if (hb_blob_t* cmapBlob = GetFontTable(TTAG_cmap)) {
|
||||
gfxFontUtils::AutoHBBlob cmapBlob(GetFontTable(TTAG_cmap));
|
||||
if (cmapBlob) {
|
||||
unsigned int length;
|
||||
const char* data = hb_blob_get_data(cmapBlob, &length);
|
||||
rv = gfxFontUtils::ReadCMAP((const uint8_t*)data, length, *charmap,
|
||||
uvsOffset);
|
||||
hb_blob_destroy(cmapBlob);
|
||||
}
|
||||
mUVSOffset.exchange(uvsOffset);
|
||||
|
||||
@ -439,11 +439,11 @@ hb_face_t* FT2FontEntry::CreateHBFace() const {
|
||||
if (mFilename[0] == '/') {
|
||||
// An absolute path means a normal file in the filesystem, so we can use
|
||||
// hb_blob_create_from_file to read it.
|
||||
hb_blob_t* fileBlob = hb_blob_create_from_file(mFilename.get());
|
||||
gfxFontUtils::AutoHBBlob fileBlob(
|
||||
hb_blob_create_from_file(mFilename.get()));
|
||||
if (hb_blob_get_length(fileBlob) > 0) {
|
||||
result = hb_face_create(fileBlob, mFTFontIndex);
|
||||
}
|
||||
hb_blob_destroy(fileBlob);
|
||||
} else {
|
||||
// A relative path means an omnijar resource, which we may need to
|
||||
// decompress to a temporary buffer.
|
||||
@ -462,11 +462,10 @@ hb_face_t* FT2FontEntry::CreateHBFace() const {
|
||||
cursor.Copy(&length);
|
||||
MOZ_ASSERT(length == item->RealSize(), "error reading font");
|
||||
if (length == item->RealSize()) {
|
||||
hb_blob_t* blob =
|
||||
gfxFontUtils::AutoHBBlob blob(
|
||||
hb_blob_create((const char*)buffer, length,
|
||||
HB_MEMORY_MODE_READONLY, buffer, free);
|
||||
HB_MEMORY_MODE_READONLY, buffer, free));
|
||||
result = hb_face_create(blob, mFTFontIndex);
|
||||
hb_blob_destroy(blob);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1180,14 +1179,13 @@ void gfxFT2FontList::AppendFacesFromFontFile(const nsCString& aFileName,
|
||||
}
|
||||
}
|
||||
|
||||
hb_blob_t* fileBlob = hb_blob_create_from_file(aFileName.get());
|
||||
gfxFontUtils::AutoHBBlob fileBlob(hb_blob_create_from_file(aFileName.get()));
|
||||
if (hb_blob_get_length(fileBlob) > 0) {
|
||||
LOG(("reading font info via harfbuzz for %s", aFileName.get()));
|
||||
AppendFacesFromBlob(aFileName, aStdFile, fileBlob,
|
||||
0 == statRetval ? aCache : nullptr, s.st_mtime,
|
||||
s.st_size);
|
||||
}
|
||||
hb_blob_destroy(fileBlob);
|
||||
}
|
||||
|
||||
void gfxFT2FontList::FindFontsInOmnijar(FontNameCache* aCache) {
|
||||
@ -1374,10 +1372,9 @@ void gfxFT2FontList::AppendFacesFromOmnijarEntry(nsZipArchive* aArchive,
|
||||
return;
|
||||
}
|
||||
|
||||
hb_blob_t* blob =
|
||||
hb_blob_create(buffer, bufSize, HB_MEMORY_MODE_READONLY, buffer, free);
|
||||
gfxFontUtils::AutoHBBlob blob(
|
||||
hb_blob_create(buffer, bufSize, HB_MEMORY_MODE_READONLY, buffer, free));
|
||||
AppendFacesFromBlob(aEntryName, kStandard, blob, aCache, 0, bufSize);
|
||||
hb_blob_destroy(blob);
|
||||
}
|
||||
|
||||
// Called on each family after all fonts are added to the list;
|
||||
|
@ -131,8 +131,8 @@ void gfxFT2Utils::GetVariationInstances(
|
||||
if (!aMMVar) {
|
||||
return;
|
||||
}
|
||||
hb_blob_t* nameTable =
|
||||
aFontEntry->GetFontTable(TRUETYPE_TAG('n', 'a', 'm', 'e'));
|
||||
gfxFontUtils::AutoHBBlob nameTable(
|
||||
aFontEntry->GetFontTable(TRUETYPE_TAG('n', 'a', 'm', 'e')));
|
||||
if (!nameTable) {
|
||||
return;
|
||||
}
|
||||
@ -154,5 +154,4 @@ void gfxFT2Utils::GetVariationInstances(
|
||||
}
|
||||
aInstances.AppendElement(inst);
|
||||
}
|
||||
hb_blob_destroy(nameTable);
|
||||
}
|
||||
|
@ -656,7 +656,7 @@ tainted_opaque_gr<const void*> gfxFontEntry::GrGetTable(
|
||||
rlbox::from_opaque(aName).unverified_safe_because(
|
||||
"This is only being used to index into a hashmap, which is robust "
|
||||
"for any value. No checks needed.");
|
||||
hb_blob_t* blob = fontEntry->GetFontTable(fontTableKey);
|
||||
gfxFontUtils::AutoHBBlob blob(fontEntry->GetFontTable(fontTableKey));
|
||||
|
||||
if (blob) {
|
||||
unsigned int blobLength;
|
||||
@ -670,7 +670,6 @@ tainted_opaque_gr<const void*> gfxFontEntry::GrGetTable(
|
||||
*t_aLen = blobLength;
|
||||
ret = rlbox::sandbox_const_cast<const void*>(t_tableData);
|
||||
}
|
||||
hb_blob_destroy(blob);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1171,11 +1171,10 @@ nsresult gfxFontUtils::GetFullNameFromSFNT(const uint8_t* aFontData,
|
||||
NS_ENSURE_TRUE(aLength > len && aLength - len >= dirEntry->offset,
|
||||
NS_ERROR_UNEXPECTED);
|
||||
|
||||
hb_blob_t* nameBlob =
|
||||
hb_blob_create((const char*)aFontData + dirEntry->offset, len,
|
||||
HB_MEMORY_MODE_READONLY, nullptr, nullptr);
|
||||
AutoHBBlob nameBlob(hb_blob_create((const char*)aFontData + dirEntry->offset,
|
||||
len, HB_MEMORY_MODE_READONLY, nullptr,
|
||||
nullptr));
|
||||
nsresult rv = GetFullNameFromTable(nameBlob, aFullName);
|
||||
hb_blob_destroy(nameBlob);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user