diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-09-21 09:46:03 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-21 18:34:29 +0000 |
commit | db0312e6acd7cc15fef0f64e05bd463cb74c70e4 (patch) | |
tree | 6ffb772e0f29f65c414adaeececc0c8e3047805d /xfa | |
parent | 46fc3fa47dc5c863519c5c3d834319b80bf5ff4a (diff) | |
download | pdfium-db0312e6acd7cc15fef0f64e05bd463cb74c70e4.tar.xz |
Move CXFA_PDFFontMgr to CFGAS_PDFFontMgr
XFA bits passed into the PDFFontMgr are just used to get the
CPDF_Document and the CFGAS_FontMgr. This CL changes the code to pass
those two things into the constructor. Then, the fxfa/cxfa_pdffontmgr.*
code has been moved to fgas/cfgas_pdffontmgr.* to show it doesn't depend
on any of the XFA classes.
Change-Id: I21d791869e2a32ffedfd7c87bb3bbd035232d991
Reviewed-on: https://pdfium-review.googlesource.com/14550
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.h | 2 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_gefont.cpp | 1 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_gefont.h | 6 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_pdffontmgr.cpp (renamed from xfa/fxfa/cxfa_pdffontmgr.cpp) | 99 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_pdffontmgr.h (renamed from xfa/fxfa/cxfa_pdffontmgr.h) | 19 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdatetimeedit.cpp | 1 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffnumericedit.cpp | 1 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffpasswordedit.cpp | 1 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fftextedit.cpp | 1 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fontmgr.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fontmgr.h | 4 |
11 files changed, 73 insertions, 67 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index 8e970361b4..946486be2a 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h @@ -21,7 +21,7 @@ #include "core/fxge/cfx_fontmapper.h" #include "core/fxge/fx_freetype.h" #include "core/fxge/ifx_systemfontinfo.h" -#include "xfa/fxfa/cxfa_pdffontmgr.h" +#include "xfa/fgas/font/cfgas_pdffontmgr.h" #define FX_FONTSTYLE_Normal 0x00 #define FX_FONTSTYLE_FixedPitch 0x01 diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp index c710ed96b0..404b23cf7b 100644 --- a/xfa/fgas/font/cfgas_gefont.cpp +++ b/xfa/fgas/font/cfgas_gefont.cpp @@ -15,7 +15,6 @@ #include "core/fxge/cfx_unicodeencodingex.h" #include "third_party/base/ptr_util.h" #include "xfa/fgas/font/fgas_fontutils.h" -#include "xfa/fxfa/cxfa_fontmgr.h" // static CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::LoadFont(const wchar_t* pszFontFamily, diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h index 13ac48f9cb..c83fc4319d 100644 --- a/xfa/fgas/font/cfgas_gefont.h +++ b/xfa/fgas/font/cfgas_gefont.h @@ -15,7 +15,7 @@ #include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_memory.h" #include "xfa/fgas/font/cfgas_fontmgr.h" -#include "xfa/fxfa/cxfa_pdffontmgr.h" +#include "xfa/fgas/font/cfgas_pdffontmgr.h" #define FXFONT_SUBST_ITALIC 0x02 @@ -50,7 +50,7 @@ class CFGAS_GEFont : public CFX_Retainable { bool GetBBox(CFX_Rect* bbox); CFX_RetainPtr<CFGAS_GEFont> GetSubstFont(int32_t iGlyphIndex); CFX_Font* GetDevFont() const { return m_pFont; } - void SetFontProvider(CXFA_PDFFontMgr* pProvider) { + void SetFontProvider(CFGAS_PDFFontMgr* pProvider) { m_pProvider.Reset(pProvider); } #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ @@ -99,7 +99,7 @@ class CFGAS_GEFont : public CFX_Retainable { bool m_bExternalFont; CFX_RetainPtr<CFGAS_GEFont> m_pSrcFont; // Only set by ctor, so no cycles. CFGAS_FontMgr::ObservedPtr m_pFontMgr; - CXFA_PDFFontMgr::ObservedPtr m_pProvider; + CFGAS_PDFFontMgr::ObservedPtr m_pProvider; CFX_RetainPtr<CFX_SeekableStreamProxy> m_pStream; CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead; std::unique_ptr<CFX_UnicodeEncoding> m_pFontEncoding; diff --git a/xfa/fxfa/cxfa_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp index 9a90e54dec..2b8e30e5ee 100644 --- a/xfa/fxfa/cxfa_pdffontmgr.cpp +++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp @@ -4,13 +4,14 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/cxfa_pdffontmgr.h" +#include "xfa/fgas/font/cfgas_pdffontmgr.h" #include <algorithm> #include "core/fpdfapi/font/cpdf_font.h" +#include "core/fpdfapi/parser/cpdf_document.h" +#include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fgas/font/cfgas_gefont.h" -#include "xfa/fxfa/cxfa_ffapp.h" namespace { @@ -23,22 +24,22 @@ const char* const g_XFAPDFFontName[][5] = { } // namespace -CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) : m_pDoc(pDoc) {} +CFGAS_PDFFontMgr::CFGAS_PDFFontMgr(CPDF_Document* pDoc, CFGAS_FontMgr* pFontMgr) + : m_pDoc(pDoc), m_pFontMgr(pFontMgr) { + ASSERT(pDoc); + ASSERT(pFontMgr); +} -CXFA_PDFFontMgr::~CXFA_PDFFontMgr() {} +CFGAS_PDFFontMgr::~CFGAS_PDFFontMgr() {} -CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::FindFont( +CFX_RetainPtr<CFGAS_GEFont> CFGAS_PDFFontMgr::FindFont( const ByteString& strPsName, bool bBold, bool bItalic, CPDF_Font** pDstPDFFont, bool bStrictMatch) { - CPDF_Document* pDoc = m_pDoc->GetPDFDoc(); - if (!pDoc) - return nullptr; - CPDF_Dictionary* pFontSetDict = - pDoc->GetRoot()->GetDictFor("AcroForm")->GetDictFor("DR"); + m_pDoc->GetRoot()->GetDictFor("AcroForm")->GetDictFor("DR"); if (!pFontSetDict) return nullptr; @@ -48,7 +49,6 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::FindFont( ByteString name = strPsName; name.Remove(' '); - CFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr(); for (const auto& it : *pFontSetDict) { const ByteString& key = it.first; CPDF_Object* pObj = it.second.get(); @@ -57,23 +57,23 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::FindFont( continue; } CPDF_Dictionary* pFontDict = ToDictionary(pObj->GetDirect()); - if (!pFontDict || pFontDict->GetStringFor("Type") != "Font") { + if (!pFontDict || pFontDict->GetStringFor("Type") != "Font") return nullptr; - } - CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict); - if (!pPDFFont) { + + CPDF_Font* pPDFFont = m_pDoc->LoadFont(pFontDict); + if (!pPDFFont) return nullptr; - } + if (!pPDFFont->IsEmbedded()) { *pDstPDFFont = pPDFFont; return nullptr; } - return CFGAS_GEFont::LoadFont(pPDFFont->GetFont(), pFDEFontMgr); + return CFGAS_GEFont::LoadFont(pPDFFont->GetFont(), m_pFontMgr.Get()); } return nullptr; } -CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::GetFont( +CFX_RetainPtr<CFGAS_GEFont> CFGAS_PDFFontMgr::GetFont( const WideStringView& wsFontFamily, uint32_t dwFontStyles, CPDF_Font** pPDFFont, @@ -84,6 +84,7 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::GetFont( auto it = m_FontMap.find(strKey); if (it != m_FontMap.end()) return it->second; + ByteString bsPsName = ByteString::FromUnicode(WideString(wsFontFamily)); bool bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; bool bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; @@ -92,12 +93,13 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::GetFont( FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch); if (pFont) m_FontMap[strKey] = pFont; + return pFont; } -ByteString CXFA_PDFFontMgr::PsNameToFontName(const ByteString& strPsName, - bool bBold, - bool bItalic) { +ByteString CFGAS_PDFFontMgr::PsNameToFontName(const ByteString& strPsName, + bool bBold, + bool bItalic) { for (size_t i = 0; i < FX_ArraySize(g_XFAPDFFontName); ++i) { if (strPsName == g_XFAPDFFontName[i][0]) { size_t index = 1; @@ -111,11 +113,11 @@ ByteString CXFA_PDFFontMgr::PsNameToFontName(const ByteString& strPsName, return strPsName; } -bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const ByteStringView& bsPsName, - bool bBold, - bool bItalic, - const ByteString& bsDRFontName, - bool bStrictMatch) { +bool CFGAS_PDFFontMgr::PsNameMatchDRFontName(const ByteStringView& bsPsName, + bool bBold, + bool bItalic, + const ByteString& bsDRFontName, + bool bStrictMatch) { ByteString bsDRName = bsDRFontName; bsDRName.Remove('-'); FX_STRSIZE iPsLen = bsPsName.GetLength(); @@ -137,15 +139,15 @@ bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const ByteStringView& bsPsName, bsDRName.GetLength() - iBoldIndex.value() - 4); } bool bItalicFont = true; - if (bsDRName.Contains("Italic")) { + if (bsDRName.Contains("Italic")) iDifferLength -= 6; - } else if (bsDRName.Contains("It")) { + else if (bsDRName.Contains("It")) iDifferLength -= 2; - } else if (bsDRName.Contains("Oblique")) { + else if (bsDRName.Contains("Oblique")) iDifferLength -= 7; - } else { + else bItalicFont = false; - } + if (bItalic != bItalicFont) return false; @@ -160,21 +162,20 @@ bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const ByteStringView& bsPsName, bool bMatch = false; switch (bsPsName[iPsLen - 1]) { - case 'L': { - if (bsDRName.Right(5) == "Light") { + case 'L': + if (bsDRName.Right(5) == "Light") bMatch = true; - } - } break; - case 'R': { - if (bsDRName.Right(7) == "Regular" || bsDRName.Right(3) == "Reg") { + + break; + case 'R': + if (bsDRName.Right(7) == "Regular" || bsDRName.Right(3) == "Reg") bMatch = true; - } - } break; - case 'M': { - if (bsDRName.Right(5) == "Medium") { + + break; + case 'M': + if (bsDRName.Right(5) == "Medium") bMatch = true; - } - } break; + break; default: break; } @@ -184,10 +185,10 @@ bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const ByteStringView& bsPsName, return true; } -bool CXFA_PDFFontMgr::GetCharWidth(const CFX_RetainPtr<CFGAS_GEFont>& pFont, - wchar_t wUnicode, - bool bCharCode, - int32_t* pWidth) { +bool CFGAS_PDFFontMgr::GetCharWidth(const CFX_RetainPtr<CFGAS_GEFont>& pFont, + wchar_t wUnicode, + bool bCharCode, + int32_t* pWidth) { if (wUnicode != 0x20 || bCharCode) return false; @@ -200,7 +201,7 @@ bool CXFA_PDFFontMgr::GetCharWidth(const CFX_RetainPtr<CFGAS_GEFont>& pFont, return true; } -void CXFA_PDFFontMgr::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont, - CPDF_Font* pPDFFont) { +void CFGAS_PDFFontMgr::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont, + CPDF_Font* pPDFFont) { m_FDE2PDFFont[pFont] = pPDFFont; } diff --git a/xfa/fxfa/cxfa_pdffontmgr.h b/xfa/fgas/font/cfgas_pdffontmgr.h index 4c8941f8f0..8a09a95bd1 100644 --- a/xfa/fxfa/cxfa_pdffontmgr.h +++ b/xfa/fgas/font/cfgas_pdffontmgr.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_CXFA_PDFFONTMGR_H_ -#define XFA_FXFA_CXFA_PDFFONTMGR_H_ +#ifndef XFA_FGAS_FONT_CFGAS_PDFFONTMGR_H_ +#define XFA_FGAS_FONT_CFGAS_PDFFONTMGR_H_ #include <map> @@ -14,16 +14,16 @@ #include "core/fxcrt/cfx_observable.h" #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_string.h" -#include "xfa/fxfa/cxfa_ffdoc.h" +class CFGAS_FontMgr; class CFGAS_GEFont; +class CPDF_Document; class CPDF_Font; -class CXFA_FFDoc; -class CXFA_PDFFontMgr : public CFX_Observable<CXFA_PDFFontMgr> { +class CFGAS_PDFFontMgr : public CFX_Observable<CFGAS_PDFFontMgr> { public: - explicit CXFA_PDFFontMgr(CXFA_FFDoc* pDoc); - ~CXFA_PDFFontMgr(); + explicit CFGAS_PDFFontMgr(CPDF_Document* pDoc, CFGAS_FontMgr* pFontMgr); + ~CFGAS_PDFFontMgr(); CFX_RetainPtr<CFGAS_GEFont> GetFont(const WideStringView& wsFontFamily, uint32_t dwFontStyles, @@ -50,9 +50,10 @@ class CXFA_PDFFontMgr : public CFX_Observable<CXFA_PDFFontMgr> { const ByteString& bsDRFontName, bool bStrictMatch); - CFX_UnownedPtr<CXFA_FFDoc> const m_pDoc; + CFX_UnownedPtr<CPDF_Document> const m_pDoc; + CFX_UnownedPtr<CFGAS_FontMgr> const m_pFontMgr; std::map<CFX_RetainPtr<CFGAS_GEFont>, CPDF_Font*> m_FDE2PDFFont; std::map<ByteString, CFX_RetainPtr<CFGAS_GEFont>> m_FontMap; }; -#endif // XFA_FXFA_CXFA_PDFFONTMGR_H_ +#endif // XFA_FGAS_FONT_CFGAS_PDFFONTMGR_H_ diff --git a/xfa/fxfa/cxfa_ffdatetimeedit.cpp b/xfa/fxfa/cxfa_ffdatetimeedit.cpp index 643d384efd..5ed1690e30 100644 --- a/xfa/fxfa/cxfa_ffdatetimeedit.cpp +++ b/xfa/fxfa/cxfa_ffdatetimeedit.cpp @@ -13,6 +13,7 @@ #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fwl/cfwl_widget.h" #include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/parser/cxfa_localevalue.h" CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc) diff --git a/xfa/fxfa/cxfa_ffnumericedit.cpp b/xfa/fxfa/cxfa_ffnumericedit.cpp index 9b87c406d7..d6e1defca4 100644 --- a/xfa/fxfa/cxfa_ffnumericedit.cpp +++ b/xfa/fxfa/cxfa_ffnumericedit.cpp @@ -11,6 +11,7 @@ #include "xfa/fwl/cfwl_edit.h" #include "xfa/fwl/cfwl_eventvalidate.h" #include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/parser/cxfa_localevalue.h" CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc) diff --git a/xfa/fxfa/cxfa_ffpasswordedit.cpp b/xfa/fxfa/cxfa_ffpasswordedit.cpp index e050a69e86..7e2f6cd29a 100644 --- a/xfa/fxfa/cxfa_ffpasswordedit.cpp +++ b/xfa/fxfa/cxfa_ffpasswordedit.cpp @@ -10,6 +10,7 @@ #include "xfa/fwl/cfwl_edit.h" #include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fxfa/cxfa_ffdoc.h" CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc) : CXFA_FFTextEdit(pDataAcc) {} diff --git a/xfa/fxfa/cxfa_fftextedit.cpp b/xfa/fxfa/cxfa_fftextedit.cpp index 8f68368757..dbfb52e085 100644 --- a/xfa/fxfa/cxfa_fftextedit.cpp +++ b/xfa/fxfa/cxfa_fftextedit.cpp @@ -18,6 +18,7 @@ #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/parser/cxfa_node.h" namespace { diff --git a/xfa/fxfa/cxfa_fontmgr.cpp b/xfa/fxfa/cxfa_fontmgr.cpp index b47ce6b21d..7d2ad70f48 100644 --- a/xfa/fxfa/cxfa_fontmgr.cpp +++ b/xfa/fxfa/cxfa_fontmgr.cpp @@ -1748,7 +1748,7 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_FontMgr::GetFont( WideString wsEnglishName = XFA_LocalFontNameToEnglishName(wsFontFamily); auto it = m_PDFFontMgrMap.find(hDoc); - CXFA_PDFFontMgr* pMgr = + CFGAS_PDFFontMgr* pMgr = it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr; CPDF_Font* pPDFFont = nullptr; CFX_RetainPtr<CFGAS_GEFont> pFont; @@ -1784,7 +1784,8 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_FontMgr::GetFont( void CXFA_FontMgr::LoadDocFonts(CXFA_FFDoc* hDoc) { if (!m_PDFFontMgrMap[hDoc]) - m_PDFFontMgrMap[hDoc] = pdfium::MakeUnique<CXFA_PDFFontMgr>(hDoc); + m_PDFFontMgrMap[hDoc] = pdfium::MakeUnique<CFGAS_PDFFontMgr>( + hDoc->GetPDFDoc(), hDoc->GetApp()->GetFDEFontMgr()); } void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) { diff --git a/xfa/fxfa/cxfa_fontmgr.h b/xfa/fxfa/cxfa_fontmgr.h index e5db565147..2e335622c6 100644 --- a/xfa/fxfa/cxfa_fontmgr.h +++ b/xfa/fxfa/cxfa_fontmgr.h @@ -15,8 +15,8 @@ #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_system.h" #include "xfa/fgas/font/cfgas_fontmgr.h" +#include "xfa/fgas/font/cfgas_pdffontmgr.h" #include "xfa/fxfa/cxfa_deffontmgr.h" -#include "xfa/fxfa/cxfa_pdffontmgr.h" #include "xfa/fxfa/fxfa.h" class CPDF_Font; @@ -47,7 +47,7 @@ class CXFA_FontMgr { private: std::unique_ptr<CXFA_DefFontMgr> m_pDefFontMgr; - std::map<CXFA_FFDoc*, std::unique_ptr<CXFA_PDFFontMgr>> m_PDFFontMgrMap; + std::map<CXFA_FFDoc*, std::unique_ptr<CFGAS_PDFFontMgr>> m_PDFFontMgrMap; std::map<ByteString, CFX_RetainPtr<CFGAS_GEFont>> m_FontMap; }; |