Make CFX_Font retain its own files.
Rather than relying on CFGAS_FontMgr::m_pIFXFont2FileRead to keep them
in existence.
Change-Id: I9356a84fecca362a842d447b03cebb6a0f6e6d58
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/73332
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index 72725f8..17d6900 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -315,7 +315,7 @@
}
#ifdef PDF_ENABLE_XFA
-bool CFX_Font::LoadFile(const RetainPtr<IFX_SeekableReadStream>& pFile,
+bool CFX_Font::LoadFile(RetainPtr<IFX_SeekableReadStream> pFile,
int nFaceIndex) {
m_bEmbedded = false;
@@ -325,6 +325,7 @@
if (!m_Face)
return false;
+ m_pOwnedFile = std::move(pFile);
m_pOwnedStream = std::move(stream);
FT_Set_Pixel_Sizes(m_Face->GetRec(), 0, 64);
return true;
diff --git a/core/fxge/cfx_font.h b/core/fxge/cfx_font.h
index ba5c57e..6b2cb29 100644
--- a/core/fxge/cfx_font.h
+++ b/core/fxge/cfx_font.h
@@ -60,7 +60,7 @@
int GetSubstFontItalicAngle() const;
#if defined(PDF_ENABLE_XFA)
- bool LoadFile(const RetainPtr<IFX_SeekableReadStream>& pFile, int nFaceIndex);
+ bool LoadFile(RetainPtr<IFX_SeekableReadStream> pFile, int nFaceIndex);
#if !defined(OS_WIN)
void SetFace(RetainPtr<CFX_Face> face);
@@ -138,6 +138,8 @@
ByteString GetFamilyNameOrUntitled() const;
#if defined(PDF_ENABLE_XFA)
+ // |m_pOwnedFile| must outlive |m_pOwnedStream|.
+ RetainPtr<IFX_SeekableReadStream> m_pOwnedFile;
std::unique_ptr<FXFT_StreamRec> m_pOwnedStream; // Must outlive |m_Face|.
#endif
mutable RetainPtr<CFX_Face> m_Face;
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 9153e8a..485c1dd 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -689,16 +689,10 @@
return nullptr;
auto pInternalFont = std::make_unique<CFX_Font>();
- if (!pInternalFont->LoadFile(pFontStream, iFaceIndex))
+ if (!pInternalFont->LoadFile(std::move(pFontStream), iFaceIndex))
return nullptr;
- RetainPtr<CFGAS_GEFont> pFont =
- CFGAS_GEFont::LoadFont(std::move(pInternalFont), this);
- if (!pFont)
- return nullptr;
-
- m_IFXFont2FileRead[pFont] = pFontStream;
- return pFont;
+ return CFGAS_GEFont::LoadFont(std::move(pInternalFont), this);
}
void CFGAS_FontMgr::MatchFonts(
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index 94def1c..0d5daff 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -153,8 +153,6 @@
std::vector<std::unique_ptr<CFX_FontDescriptor>> m_InstalledFonts;
std::map<uint32_t, std::unique_ptr<std::vector<CFX_FontDescriptorInfo>>>
m_Hash2CandidateList;
- std::map<RetainPtr<CFGAS_GEFont>, RetainPtr<IFX_SeekableReadStream>>
- m_IFXFont2FileRead;
#endif // defined(OS_WIN)
};