summaryrefslogtreecommitdiff
path: root/xfa/fwl
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2017-01-05 12:57:00 -0800
committerCommit bot <commit-bot@chromium.org>2017-01-05 12:57:00 -0800
commite647799f6a2f7f747c9f55d9f0ce08dcdfbd53f4 (patch)
tree282c502bd9f807f385d0cbcc1692bb475c8a4df1 /xfa/fwl
parent6bb3b894488fd6f38c096b708980a9f08286ac5c (diff)
downloadpdfium-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/fwl')
-rw-r--r--xfa/fwl/cfwl_barcode.cpp3
-rw-r--r--xfa/fwl/cfwl_edit.cpp2
-rw-r--r--xfa/fwl/ifwl_themeprovider.h3
-rw-r--r--xfa/fwl/theme/cfwl_widgettp.cpp14
-rw-r--r--xfa/fwl/theme/cfwl_widgettp.h16
5 files changed, 21 insertions, 17 deletions
diff --git a/xfa/fwl/cfwl_barcode.cpp b/xfa/fwl/cfwl_barcode.cpp
index 8b05927223..0412b86958 100644
--- a/xfa/fwl/cfwl_barcode.cpp
+++ b/xfa/fwl/cfwl_barcode.cpp
@@ -169,8 +169,7 @@ void CFWL_Barcode::GenerateBarcodeImageCache() {
if (pTheme) {
CFWL_ThemePart part;
part.m_pWidget = this;
-
- if (CFGAS_GEFont* pFont = pTheme->GetFont(&part)) {
+ if (CFX_RetainPtr<CFGAS_GEFont> pFont = pTheme->GetFont(&part)) {
if (CFX_Font* pCXFont = pFont->GetDevFont())
m_pBarcodeEngine->SetFont(pCXFont);
}
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index 79b0b2d366..acd5672227 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -688,7 +688,7 @@ void CFWL_Edit::UpdateEditParams() {
params.dwFontColor = theme->GetTextColor(&part);
params.fLineSpace = theme->GetLineHeight(&part);
- CFGAS_GEFont* pFont = theme->GetFont(&part);
+ CFX_RetainPtr<CFGAS_GEFont> pFont = theme->GetFont(&part);
if (!pFont)
return;
diff --git a/xfa/fwl/ifwl_themeprovider.h b/xfa/fwl/ifwl_themeprovider.h
index c0460fe901..21a12a55f2 100644
--- a/xfa/fwl/ifwl_themeprovider.h
+++ b/xfa/fwl/ifwl_themeprovider.h
@@ -26,7 +26,8 @@ class IFWL_ThemeProvider {
virtual float GetCYBorderSize() const = 0;
virtual CFX_RectF GetUIMargin(CFWL_ThemePart* pThemePart) const = 0;
virtual float GetFontSize(CFWL_ThemePart* pThemePart) const = 0;
- virtual CFGAS_GEFont* GetFont(CFWL_ThemePart* pThemePart) const = 0;
+ virtual CFX_RetainPtr<CFGAS_GEFont> GetFont(
+ CFWL_ThemePart* pThemePart) const = 0;
virtual float GetLineHeight(CFWL_ThemePart* pThemePart) const = 0;
virtual float GetScrollBarWidth() const = 0;
virtual FX_COLORREF GetTextColor(CFWL_ThemePart* pThemePart) const = 0;
diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp
index 395571c2c4..a0d6b4c54d 100644
--- a/xfa/fwl/theme/cfwl_widgettp.cpp
+++ b/xfa/fwl/theme/cfwl_widgettp.cpp
@@ -298,8 +298,8 @@ bool CFWL_FontData::LoadFont(const CFX_WideStringC& wsFontFamily,
m_pFontMgr = CFGAS_FontMgr::Create(m_pFontSource.get());
#endif
}
- m_pFont.reset(CFGAS_GEFont::LoadFont(wsFontFamily.c_str(), dwFontStyles,
- dwCodePage, m_pFontMgr.get()));
+ m_pFont = CFGAS_GEFont::LoadFont(wsFontFamily.c_str(), dwFontStyles,
+ dwCodePage, m_pFontMgr.get());
return !!m_pFont;
}
@@ -319,16 +319,18 @@ CFWL_FontManager::CFWL_FontManager() {}
CFWL_FontManager::~CFWL_FontManager() {}
-CFGAS_GEFont* CFWL_FontManager::FindFont(const CFX_WideStringC& wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t wCodePage) {
+CFX_RetainPtr<CFGAS_GEFont> CFWL_FontManager::FindFont(
+ const CFX_WideStringC& wsFontFamily,
+ uint32_t dwFontStyles,
+ uint16_t wCodePage) {
for (const auto& pData : m_FontsArray) {
if (pData->Equal(wsFontFamily, dwFontStyles, wCodePage))
return pData->GetFont();
}
- std::unique_ptr<CFWL_FontData> pFontData(new CFWL_FontData);
+ auto pFontData = pdfium::MakeUnique<CFWL_FontData>();
if (!pFontData->LoadFont(wsFontFamily, dwFontStyles, wCodePage))
return nullptr;
+
m_FontsArray.push_back(std::move(pFontData));
return m_FontsArray.back()->GetFont();
}
diff --git a/xfa/fwl/theme/cfwl_widgettp.h b/xfa/fwl/theme/cfwl_widgettp.h
index 33a5febbec..794c67be8b 100644
--- a/xfa/fwl/theme/cfwl_widgettp.h
+++ b/xfa/fwl/theme/cfwl_widgettp.h
@@ -10,8 +10,10 @@
#include <memory>
#include <vector>
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
+#include "xfa/fgas/font/cfgas_gefont.h"
#include "xfa/fwl/fwl_error.h"
#include "xfa/fwl/theme/cfwl_utils.h"
#include "xfa/fxgraphics/cfx_graphics.h"
@@ -38,7 +40,7 @@ class CFWL_WidgetTP {
virtual void DrawBackground(CFWL_ThemeBackground* pParams);
virtual void DrawText(CFWL_ThemeText* pParams);
- CFGAS_GEFont* GetFont() const { return m_pFDEFont; }
+ const CFX_RetainPtr<CFGAS_GEFont>& GetFont() const { return m_pFDEFont; }
protected:
struct CColorData {
@@ -94,7 +96,7 @@ class CFWL_WidgetTP {
uint32_t m_dwRefCount;
std::unique_ptr<CFDE_TextOut> m_pTextOut;
- CFGAS_GEFont* m_pFDEFont;
+ CFX_RetainPtr<CFGAS_GEFont> m_pFDEFont;
std::unique_ptr<CColorData> m_pColorData;
};
@@ -111,7 +113,7 @@ class CFWL_FontData {
bool LoadFont(const CFX_WideStringC& wsFontFamily,
uint32_t dwFontStyles,
uint16_t wCodePage);
- CFGAS_GEFont* GetFont() const { return m_pFont.get(); }
+ CFX_RetainPtr<CFGAS_GEFont> GetFont() const { return m_pFont; }
protected:
CFX_WideString m_wsFamily;
@@ -121,7 +123,7 @@ class CFWL_FontData {
std::unique_ptr<CFX_FontSourceEnum_File> m_pFontSource;
#endif
std::unique_ptr<CFGAS_FontMgr> m_pFontMgr;
- std::unique_ptr<CFGAS_GEFont> m_pFont;
+ CFX_RetainPtr<CFGAS_GEFont> m_pFont;
};
class CFWL_FontManager {
@@ -129,9 +131,9 @@ class CFWL_FontManager {
static CFWL_FontManager* GetInstance();
static void DestroyInstance();
- CFGAS_GEFont* FindFont(const CFX_WideStringC& wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t dwCodePage);
+ CFX_RetainPtr<CFGAS_GEFont> FindFont(const CFX_WideStringC& wsFontFamily,
+ uint32_t dwFontStyles,
+ uint16_t dwCodePage);
protected:
CFWL_FontManager();