diff options
author | tsepez <tsepez@chromium.org> | 2017-01-05 12:57:00 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2017-01-05 12:57:00 -0800 |
commit | e647799f6a2f7f747c9f55d9f0ce08dcdfbd53f4 (patch) | |
tree | 282c502bd9f807f385d0cbcc1692bb475c8a4df1 /xfa/fxfa/app | |
parent | 6bb3b894488fd6f38c096b708980a9f08286ac5c (diff) | |
download | pdfium-e647799f6a2f7f747c9f55d9f0ce08dcdfbd53f4.tar.xz |
Properly ref-count CFGAS_GEFont with CFX_RetainPtr.
We worry about cyclical references, but no leaks found.
Review-Url: https://codereview.chromium.org/2609423003
Diffstat (limited to 'xfa/fxfa/app')
-rw-r--r-- | xfa/fxfa/app/xfa_ffwidgetacc.cpp | 11 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_fontmgr.cpp | 83 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_fwltheme.cpp | 7 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_fwltheme.h | 5 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_textlayout.cpp | 6 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_textlayout.h | 6 |
6 files changed, 56 insertions, 62 deletions
diff --git a/xfa/fxfa/app/xfa_ffwidgetacc.cpp b/xfa/fxfa/app/xfa_ffwidgetacc.cpp index 13145e6448..e62ebca302 100644 --- a/xfa/fxfa/app/xfa_ffwidgetacc.cpp +++ b/xfa/fxfa/app/xfa_ffwidgetacc.cpp @@ -1498,19 +1498,18 @@ CXFA_WidgetLayoutData* CXFA_WidgetAcc::GetWidgetLayoutData() { return m_pLayoutData.get(); } -CFGAS_GEFont* CXFA_WidgetAcc::GetFDEFont() { +CFX_RetainPtr<CFGAS_GEFont> CXFA_WidgetAcc::GetFDEFont() { CFX_WideStringC wsFontName = FX_WSTRC(L"Courier"); uint32_t dwFontStyle = 0; if (CXFA_Font font = GetFont()) { - if (font.IsBold()) { + if (font.IsBold()) dwFontStyle |= FX_FONTSTYLE_Bold; - } - if (font.IsItalic()) { + if (font.IsItalic()) dwFontStyle |= FX_FONTSTYLE_Italic; - } font.GetTypeface(wsFontName); } - CXFA_FFDoc* pDoc = GetDoc(); + + auto pDoc = GetDoc(); return pDoc->GetApp()->GetXFAFontMgr()->GetFont(pDoc, wsFontName, dwFontStyle); } diff --git a/xfa/fxfa/app/xfa_fontmgr.cpp b/xfa/fxfa/app/xfa_fontmgr.cpp index 636017d4e3..5db389663a 100644 --- a/xfa/fxfa/app/xfa_fontmgr.cpp +++ b/xfa/fxfa/app/xfa_fontmgr.cpp @@ -1740,18 +1740,16 @@ const XFA_FONTINFO* XFA_GetFontINFOByFontName( CXFA_DefFontMgr::CXFA_DefFontMgr() {} -CXFA_DefFontMgr::~CXFA_DefFontMgr() { - for (int32_t i = 0; i < m_CacheFonts.GetSize(); i++) - m_CacheFonts[i]->Release(); -} +CXFA_DefFontMgr::~CXFA_DefFontMgr() {} -CFGAS_GEFont* CXFA_DefFontMgr::GetFont(CXFA_FFDoc* hDoc, - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage) { +CFX_RetainPtr<CFGAS_GEFont> CXFA_DefFontMgr::GetFont( + CXFA_FFDoc* hDoc, + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage) { CFX_WideString wsFontName(wsFontFamily); CFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); - CFGAS_GEFont* pFont = + CFX_RetainPtr<CFGAS_GEFont> pFont = pFDEFontMgr->LoadFont(wsFontName.c_str(), dwFontStyles, wCodePage); if (!pFont) { const XFA_FONTINFO* pCurFont = @@ -1785,56 +1783,50 @@ CFGAS_GEFont* CXFA_DefFontMgr::GetFont(CXFA_FFDoc* hDoc, } } if (pFont) - m_CacheFonts.Add(pFont); + m_CacheFonts.push_back(pFont); return pFont; } -CFGAS_GEFont* CXFA_DefFontMgr::GetDefaultFont( +CFX_RetainPtr<CFGAS_GEFont> CXFA_DefFontMgr::GetDefaultFont( CXFA_FFDoc* hDoc, const CFX_WideStringC& wsFontFamily, uint32_t dwFontStyles, uint16_t wCodePage) { CFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); - CFGAS_GEFont* pFont = + CFX_RetainPtr<CFGAS_GEFont> pFont = pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); if (!pFont) { pFont = pFDEFontMgr->LoadFont(static_cast<const FX_WCHAR*>(nullptr), dwFontStyles, wCodePage); } - - ASSERT(pFont); if (pFont) - m_CacheFonts.Add(pFont); + m_CacheFonts.push_back(pFont); return pFont; } CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) : m_pDoc(pDoc) {} -CXFA_PDFFontMgr::~CXFA_PDFFontMgr() { - for (const auto& pair : m_FontMap) { - if (pair.second) - pair.second->Release(); - } -} +CXFA_PDFFontMgr::~CXFA_PDFFontMgr() {} -CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(const CFX_ByteString& strPsName, - bool bBold, - bool bItalic, - CPDF_Font** pDstPDFFont, - bool bStrictMatch) { +CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::FindFont( + const CFX_ByteString& strPsName, + bool bBold, + bool bItalic, + CPDF_Font** pDstPDFFont, + bool bStrictMatch) { CPDF_Document* pDoc = m_pDoc->GetPDFDoc(); - if (!pDoc) { + if (!pDoc) return nullptr; - } + CPDF_Dictionary* pFontSetDict = pDoc->GetRoot()->GetDictFor("AcroForm")->GetDictFor("DR"); - if (!pFontSetDict) { + if (!pFontSetDict) return nullptr; - } + pFontSetDict = pFontSetDict->GetDictFor("Font"); - if (!pFontSetDict) { + if (!pFontSetDict) return nullptr; - } + CFX_ByteString name = strPsName; name.Remove(' '); CFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr(); @@ -1862,10 +1854,11 @@ CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(const CFX_ByteString& strPsName, return nullptr; } -CFGAS_GEFont* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - CPDF_Font** pPDFFont, - bool bStrictMatch) { +CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::GetFont( + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + CPDF_Font** pPDFFont, + bool bStrictMatch) { uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false); CFX_ByteString strKey; strKey.Format("%u%u", dwHashCode, dwFontStyles); @@ -1877,7 +1870,7 @@ CFGAS_GEFont* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, bool bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; bool bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); - CFGAS_GEFont* pFont = + CFX_RetainPtr<CFGAS_GEFont> pFont = FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch); if (pFont) m_FontMap[strKey] = pFont; @@ -1975,7 +1968,7 @@ bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName, return true; } -bool CXFA_PDFFontMgr::GetCharWidth(const CFGAS_GEFont* pFont, +bool CXFA_PDFFontMgr::GetCharWidth(const CFX_RetainPtr<CFGAS_GEFont>& pFont, FX_WCHAR wUnicode, bool bCharCode, int32_t* pWidth) { @@ -1991,7 +1984,8 @@ bool CXFA_PDFFontMgr::GetCharWidth(const CFGAS_GEFont* pFont, return true; } -void CXFA_PDFFontMgr::SetFont(const CFGAS_GEFont* pFont, CPDF_Font* pPDFFont) { +void CXFA_PDFFontMgr::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont, + CPDF_Font* pPDFFont) { m_FDE2PDFFont[pFont] = pPDFFont; } @@ -1999,10 +1993,11 @@ CXFA_FontMgr::CXFA_FontMgr() {} CXFA_FontMgr::~CXFA_FontMgr() {} -CFGAS_GEFont* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage) { +CFX_RetainPtr<CFGAS_GEFont> CXFA_FontMgr::GetFont( + CXFA_FFDoc* hDoc, + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage) { uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false); CFX_ByteString bsKey; bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); @@ -2015,7 +2010,7 @@ CFGAS_GEFont* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, CXFA_PDFFontMgr* pMgr = it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr; CPDF_Font* pPDFFont = nullptr; - CFGAS_GEFont* pFont = nullptr; + CFX_RetainPtr<CFGAS_GEFont> pFont; if (pMgr) { pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont, true); diff --git a/xfa/fxfa/app/xfa_fwltheme.cpp b/xfa/fxfa/app/xfa_fwltheme.cpp index d12678e51b..1de302e995 100644 --- a/xfa/fxfa/app/xfa_fwltheme.cpp +++ b/xfa/fxfa/app/xfa_fwltheme.cpp @@ -75,10 +75,6 @@ CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp) CXFA_FWLTheme::~CXFA_FWLTheme() { m_pTextOut.reset(); - if (m_pCalendarFont) { - m_pCalendarFont->Release(); - m_pCalendarFont = nullptr; - } FWLTHEME_Release(); } @@ -193,7 +189,8 @@ float CXFA_FWLTheme::GetFontSize(CFWL_ThemePart* pThemePart) const { return FWLTHEME_CAPACITY_FontSize; } -CFGAS_GEFont* CXFA_FWLTheme::GetFont(CFWL_ThemePart* pThemePart) const { +CFX_RetainPtr<CFGAS_GEFont> CXFA_FWLTheme::GetFont( + CFWL_ThemePart* pThemePart) const { if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) return pWidget->GetDataAcc()->GetFDEFont(); return GetTheme(pThemePart->m_pWidget)->GetFont(); diff --git a/xfa/fxfa/app/xfa_fwltheme.h b/xfa/fxfa/app/xfa_fwltheme.h index f8b804893a..a8efad0ccf 100644 --- a/xfa/fxfa/app/xfa_fwltheme.h +++ b/xfa/fxfa/app/xfa_fwltheme.h @@ -37,7 +37,8 @@ class CXFA_FWLTheme final : public IFWL_ThemeProvider { float GetCYBorderSize() const override; CFX_RectF GetUIMargin(CFWL_ThemePart* pThemePart) const override; float GetFontSize(CFWL_ThemePart* pThemePart) const override; - CFGAS_GEFont* GetFont(CFWL_ThemePart* pThemePart) const override; + CFX_RetainPtr<CFGAS_GEFont> GetFont( + CFWL_ThemePart* pThemePart) const override; float GetLineHeight(CFWL_ThemePart* pThemePart) const override; float GetScrollBarWidth() const override; FX_COLORREF GetTextColor(CFWL_ThemePart* pThemePart) const override; @@ -58,7 +59,7 @@ class CXFA_FWLTheme final : public IFWL_ThemeProvider { std::unique_ptr<CFWL_CaretTP> m_pCaretTP; std::unique_ptr<CFWL_BarcodeTP> m_pBarcodeTP; std::unique_ptr<CFDE_TextOut> m_pTextOut; - CFGAS_GEFont* m_pCalendarFont; + CFX_RetainPtr<CFGAS_GEFont> m_pCalendarFont; CFX_WideString m_wsResource; CXFA_FFApp* const m_pApp; CFX_RectF m_Rect; diff --git a/xfa/fxfa/app/xfa_textlayout.cpp b/xfa/fxfa/app/xfa_textlayout.cpp index ea4ae4b2da..826fefcfbc 100644 --- a/xfa/fxfa/app/xfa_textlayout.cpp +++ b/xfa/fxfa/app/xfa_textlayout.cpp @@ -376,8 +376,10 @@ bool CXFA_TextParser::IsSpaceRun(IFDE_CSSComputedStyle* pStyle) const { } return false; } -CFGAS_GEFont* CXFA_TextParser::GetFont(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const { + +CFX_RetainPtr<CFGAS_GEFont> CXFA_TextParser::GetFont( + CXFA_TextProvider* pTextProvider, + IFDE_CSSComputedStyle* pStyle) const { CFX_WideStringC wsFamily = FX_WSTRC(L"Courier"); uint32_t dwStyle = 0; CXFA_Font font = pTextProvider->GetFontNode(); diff --git a/xfa/fxfa/app/xfa_textlayout.h b/xfa/fxfa/app/xfa_textlayout.h index f923c743ed..fa0ca668ca 100644 --- a/xfa/fxfa/app/xfa_textlayout.h +++ b/xfa/fxfa/app/xfa_textlayout.h @@ -92,8 +92,8 @@ class CXFA_TextParser { bool IsSpaceRun(IFDE_CSSComputedStyle* pStyle) const; bool GetTabstops(IFDE_CSSComputedStyle* pStyle, CXFA_TextTabstopsContext* pTabstopContext); - CFGAS_GEFont* GetFont(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const; + CFX_RetainPtr<CFGAS_GEFont> GetFont(CXFA_TextProvider* pTextProvider, + IFDE_CSSComputedStyle* pStyle) const; FX_FLOAT GetFontSize(CXFA_TextProvider* pTextProvider, IFDE_CSSComputedStyle* pStyle) const; int32_t GetHorScale(CXFA_TextProvider* pTextProvider, @@ -210,7 +210,7 @@ class XFA_TextPiece : public CFX_Target { int32_t iUnderline; int32_t iPeriod; int32_t iLineThrough; - CFGAS_GEFont* pFont; + CFX_RetainPtr<CFGAS_GEFont> pFont; FX_ARGB dwColor; FX_FLOAT fFontSize; CFX_RectF rtPiece; |