diff options
Diffstat (limited to 'xfa/fxfa')
-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 | ||||
-rw-r--r-- | xfa/fxfa/fxfa_widget.h | 3 | ||||
-rw-r--r-- | xfa/fxfa/xfa_fontmgr.h | 57 |
8 files changed, 88 insertions, 90 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; diff --git a/xfa/fxfa/fxfa_widget.h b/xfa/fxfa/fxfa_widget.h index 9a0e66b24e..74c63c9d52 100644 --- a/xfa/fxfa/fxfa_widget.h +++ b/xfa/fxfa/fxfa_widget.h @@ -9,6 +9,7 @@ #include <memory> +#include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxge/fx_dib.h" #include "xfa/fxfa/parser/cxfa_box.h" @@ -75,7 +76,7 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { void UpdateUIDisplay(CXFA_FFWidget* pExcept = nullptr); CXFA_Node* GetDatasets(); - CFGAS_GEFont* GetFDEFont(); + CFX_RetainPtr<CFGAS_GEFont> GetFDEFont(); FX_FLOAT GetFontSize(); FX_ARGB GetTextColor(); FX_FLOAT GetLineHeight(); diff --git a/xfa/fxfa/xfa_fontmgr.h b/xfa/fxfa/xfa_fontmgr.h index a6a5822e0d..f00b069ef0 100644 --- a/xfa/fxfa/xfa_fontmgr.h +++ b/xfa/fxfa/xfa_fontmgr.h @@ -9,7 +9,9 @@ #include <map> #include <memory> +#include <vector> +#include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_ext.h" #include "core/fxcrt/fx_system.h" #include "xfa/fgas/font/cfgas_fontmgr.h" @@ -30,17 +32,18 @@ class CXFA_DefFontMgr { CXFA_DefFontMgr(); ~CXFA_DefFontMgr(); - CFGAS_GEFont* GetFont(CXFA_FFDoc* hDoc, - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage = 0xFFFF); - CFGAS_GEFont* GetDefaultFont(CXFA_FFDoc* hDoc, - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage = 0xFFFF); + CFX_RetainPtr<CFGAS_GEFont> GetFont(CXFA_FFDoc* hDoc, + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage = 0xFFFF); + CFX_RetainPtr<CFGAS_GEFont> GetDefaultFont( + CXFA_FFDoc* hDoc, + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage = 0xFFFF); protected: - CFX_ArrayTemplate<CFGAS_GEFont*> m_CacheFonts; + std::vector<CFX_RetainPtr<CFGAS_GEFont>> m_CacheFonts; }; class CXFA_PDFFontMgr { @@ -48,22 +51,22 @@ class CXFA_PDFFontMgr { explicit CXFA_PDFFontMgr(CXFA_FFDoc* pDoc); ~CXFA_PDFFontMgr(); - CFGAS_GEFont* GetFont(const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - CPDF_Font** pPDFFont, - bool bStrictMatch); - bool GetCharWidth(const CFGAS_GEFont* pFont, + CFX_RetainPtr<CFGAS_GEFont> GetFont(const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + CPDF_Font** pPDFFont, + bool bStrictMatch); + bool GetCharWidth(const CFX_RetainPtr<CFGAS_GEFont>& pFont, FX_WCHAR wUnicode, bool bCharCode, int32_t* pWidth); - void SetFont(const CFGAS_GEFont* pFont, CPDF_Font* pPDFFont); + void SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont, CPDF_Font* pPDFFont); protected: - CFGAS_GEFont* FindFont(const CFX_ByteString& strFamilyName, - bool bBold, - bool bItalic, - CPDF_Font** pPDFFont, - bool bStrictMatch); + CFX_RetainPtr<CFGAS_GEFont> FindFont(const CFX_ByteString& strFamilyName, + bool bBold, + bool bItalic, + CPDF_Font** pPDFFont, + bool bStrictMatch); CFX_ByteString PsNameToFontName(const CFX_ByteString& strPsName, bool bBold, bool bItalic); @@ -74,8 +77,8 @@ class CXFA_PDFFontMgr { bool bStrictMatch); CXFA_FFDoc* const m_pDoc; - std::map<const CFGAS_GEFont*, CPDF_Font*> m_FDE2PDFFont; - std::map<CFX_ByteString, CFGAS_GEFont*> m_FontMap; + std::map<CFX_RetainPtr<CFGAS_GEFont>, CPDF_Font*> m_FDE2PDFFont; + std::map<CFX_ByteString, CFX_RetainPtr<CFGAS_GEFont>> m_FontMap; }; class CXFA_FontMgr { @@ -83,10 +86,10 @@ class CXFA_FontMgr { CXFA_FontMgr(); ~CXFA_FontMgr(); - CFGAS_GEFont* GetFont(CXFA_FFDoc* hDoc, - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage = 0xFFFF); + CFX_RetainPtr<CFGAS_GEFont> GetFont(CXFA_FFDoc* hDoc, + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage = 0xFFFF); void LoadDocFonts(CXFA_FFDoc* hDoc); void ReleaseDocFonts(CXFA_FFDoc* hDoc); void SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr); @@ -94,7 +97,7 @@ class CXFA_FontMgr { protected: std::unique_ptr<CXFA_DefFontMgr> m_pDefFontMgr; std::map<CXFA_FFDoc*, std::unique_ptr<CXFA_PDFFontMgr>> m_PDFFontMgrMap; - std::map<CFX_ByteString, CFGAS_GEFont*> m_FontMap; + std::map<CFX_ByteString, CFX_RetainPtr<CFGAS_GEFont>> m_FontMap; }; #endif // XFA_FXFA_XFA_FONTMGR_H_ |