From 0fc6b25e738c311fd66aa9da8c56de50af5644d5 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Tue, 1 Mar 2016 16:29:41 -0800 Subject: Remove implicit conversions and some cleanup R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1751753002 . --- core/include/fpdfdoc/fpdf_doc.h | 175 ++++++++--------------------- core/src/fpdfdoc/doc_bookmark.cpp | 17 +-- core/src/fpdfdoc/doc_form.cpp | 11 +- core/src/fpdfdoc/doc_formcontrol.cpp | 34 +++--- core/src/fpdfdoc/doc_formfield.cpp | 7 +- core/src/fpdfdoc/doc_utils.cpp | 4 +- fpdfsdk/src/formfiller/FFL_IFormFiller.cpp | 18 +-- fpdfsdk/src/fpdfdoc.cpp | 13 ++- fpdfsdk/src/fpdfformfill.cpp | 4 +- fpdfsdk/src/fsdk_actionhandler.cpp | 6 +- fpdfsdk/src/fsdk_baseannot.cpp | 11 +- fpdfsdk/src/fsdk_baseform.cpp | 33 +++--- fpdfsdk/src/pdfwindow/PWL_Icon.cpp | 2 +- 13 files changed, 125 insertions(+), 210 deletions(-) diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h index e1766e0c38..836b48c17b 100644 --- a/core/include/fpdfdoc/fpdf_doc.h +++ b/core/include/fpdfdoc/fpdf_doc.h @@ -42,63 +42,51 @@ class CXML_Element; class CPDF_NameTree { public: - explicit CPDF_NameTree(CPDF_Dictionary* pRoot) { m_pRoot = pRoot; } - + explicit CPDF_NameTree(CPDF_Dictionary* pRoot) : m_pRoot(pRoot) {} CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteStringC& category); CPDF_Object* LookupValue(int nIndex, CFX_ByteString& csName) const; - CPDF_Object* LookupValue(const CFX_ByteString& csName) const; - CPDF_Array* LookupNamedDest(CPDF_Document* pDoc, const CFX_ByteStringC& sName); - int GetIndex(const CFX_ByteString& csName) const; - int GetCount() const; - CPDF_Dictionary* GetRoot() const { return m_pRoot; } protected: CPDF_Dictionary* m_pRoot; }; + class CPDF_BookmarkTree { public: explicit CPDF_BookmarkTree(CPDF_Document* pDoc) : m_pDocument(pDoc) {} CPDF_Bookmark GetFirstChild(const CPDF_Bookmark& parent) const; - CPDF_Bookmark GetNextSibling(const CPDF_Bookmark& bookmark) const; - CPDF_Document* GetDocument() const { return m_pDocument; } protected: - CPDF_Document* m_pDocument; + CPDF_Document* const m_pDocument; }; + #define PDFBOOKMARK_ITALIC 1 #define PDFBOOKMARK_BOLD 2 class CPDF_Bookmark { public: - CPDF_Bookmark() : m_pDict(NULL) {} - + CPDF_Bookmark() : m_pDict(nullptr) {} explicit CPDF_Bookmark(CPDF_Dictionary* pDict) : m_pDict(pDict) {} CPDF_Dictionary* GetDict() const { return m_pDict; } - - operator bool() const { return m_pDict != NULL; } - FX_DWORD GetColorRef() const; - FX_DWORD GetFontStyle() const; - CFX_WideString GetTitle() const; - CPDF_Dest GetDest(CPDF_Document* pDocument) const; - CPDF_Action GetAction() const; + protected: CPDF_Dictionary* m_pDict; }; + #define PDFZOOM_XYZ 1 #define PDFZOOM_FITPAGE 2 #define PDFZOOM_FITHORZ 3 @@ -112,9 +100,7 @@ class CPDF_Dest { CPDF_Dest() : m_pObj(nullptr) {} explicit CPDF_Dest(CPDF_Object* pObj) : m_pObj(pObj) {} - operator bool() const { return m_pObj != NULL; } CPDF_Object* GetObject() const { return m_pObj; } - CFX_ByteString GetRemoteName(); int GetPageIndex(CPDF_Document* pDoc); FX_DWORD GetPageObjNum(); @@ -124,6 +110,7 @@ class CPDF_Dest { protected: CPDF_Object* m_pObj; }; + class CPDF_OCContext : public IPDF_OCContext { public: enum UsageType { View = 0, Design, Print, Export }; @@ -131,53 +118,40 @@ class CPDF_OCContext : public IPDF_OCContext { explicit CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType = View); ~CPDF_OCContext() override; - CPDF_Document* GetDocument() const { return m_pDocument; } + // IPDF_OCContext: + FX_BOOL CheckOCGVisible(const CPDF_Dictionary* pOCGDict) override; + CPDF_Document* GetDocument() const { return m_pDocument; } UsageType GetUsageType() const { return m_eUsageType; } - FX_BOOL CheckOCGVisible(const CPDF_Dictionary* pOCGDict) override; - void ResetOCContext(); protected: FX_BOOL LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig, const CPDF_Dictionary* pOCGDict, FX_BOOL& bValidConfig) const; - FX_BOOL LoadOCGState(const CPDF_Dictionary* pOCGDict) const; - FX_BOOL GetOCGVisible(const CPDF_Dictionary* pOCGDict); - FX_BOOL GetOCGVE(CPDF_Array* pExpression, FX_BOOL bFromConfig, int nLevel = 0); - FX_BOOL LoadOCMDState(const CPDF_Dictionary* pOCMDDict, FX_BOOL bFromConfig); CPDF_Document* m_pDocument; - UsageType m_eUsageType; - std::map m_OCGStates; }; class CPDF_ActionFields { public: - // TODO(thestig): Examine why this cannot be explicit. - CPDF_ActionFields(const CPDF_Action* pAction) { - m_pAction = (CPDF_Action*)pAction; - } - - // TODO(thestig): Replace this. - operator CPDF_Action*() const { return m_pAction; } + explicit CPDF_ActionFields(const CPDF_Action* pAction) : m_pAction(pAction) {} FX_DWORD GetFieldsCount() const; - std::vector GetAllFields() const; - CPDF_Object* GetField(FX_DWORD iIndex) const; - CPDF_Action* m_pAction; + protected: + const CPDF_Action* const m_pAction; }; #define PDFNAMED_NEXTPAGE 1 @@ -212,62 +186,34 @@ class CPDF_Action { CPDF_Action() : m_pDict(nullptr) {} explicit CPDF_Action(CPDF_Dictionary* pDict) : m_pDict(pDict) {} - operator bool() const { return m_pDict != NULL; } - CPDF_Dictionary* GetDict() const { return m_pDict; } - CFX_ByteString GetTypeName() const { return m_pDict->GetStringBy("S"); } - ActionType GetType() const; - CPDF_Dest GetDest(CPDF_Document* pDoc) const; - CFX_WideString GetFilePath() const; - FX_BOOL GetNewWindow() const { return m_pDict->GetBooleanBy("NewWindow"); } - CFX_ByteString GetURI(CPDF_Document* pDoc) const; - FX_BOOL GetMouseMap() const { return m_pDict->GetBooleanBy("IsMap"); } - - CPDF_ActionFields GetWidgets() const { return this; } - FX_BOOL GetHideStatus() const { return m_pDict->GetBooleanBy("H", TRUE); } - CFX_ByteString GetNamedAction() const { return m_pDict->GetStringBy("N"); } - FX_DWORD GetFlags() const { return m_pDict->GetIntegerBy("Flags"); } - CFX_WideString GetJavaScript() const; - CPDF_Dictionary* GetAnnot() const; - int32_t GetOperationType() const; - CPDF_Stream* GetSoundStream() const { return m_pDict->GetStreamBy("Sound"); } - FX_FLOAT GetVolume() const { return m_pDict->GetNumberBy("Volume"); } - FX_BOOL IsSynchronous() const { return m_pDict->GetBooleanBy("Synchronous"); } - FX_BOOL IsRepeat() const { return m_pDict->GetBooleanBy("Repeat"); } - FX_BOOL IsMixPlay() const { return m_pDict->GetBooleanBy("Mix"); } - FX_DWORD GetSubActionsCount() const; - CPDF_Action GetSubAction(FX_DWORD iIndex) const; protected: - CPDF_Dictionary* m_pDict; + CPDF_Dictionary* const m_pDict; }; + class CPDF_AAction { public: - // TODO(thestig): Examine why this cannot be explicit. - CPDF_AAction(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; } - - operator CPDF_Dictionary*() const { return m_pDict; } - enum AActionType { CursorEnter = 0, CursorExit, @@ -292,24 +238,25 @@ class CPDF_AAction { DocumentPrinted }; - FX_BOOL ActionExist(AActionType eType) const; + CPDF_AAction() : m_pDict(nullptr) {} + explicit CPDF_AAction(CPDF_Dictionary* pDict) : m_pDict(pDict) {} + FX_BOOL ActionExist(AActionType eType) const; CPDF_Action GetAction(AActionType eType) const; + CPDF_Dictionary* GetDict() const { return m_pDict; } - CPDF_Dictionary* m_pDict; + protected: + CPDF_Dictionary* const m_pDict; }; + class CPDF_DocJSActions { public: explicit CPDF_DocJSActions(CPDF_Document* pDoc); int CountJSActions() const; - CPDF_Action GetJSAction(int index, CFX_ByteString& csName) const; - CPDF_Action GetJSAction(const CFX_ByteString& csName) const; - int FindJSAction(const CFX_ByteString& csName) const; - CPDF_Document* GetDocument() const { return m_pDocument; } protected: @@ -319,7 +266,7 @@ class CPDF_DocJSActions { class CPDF_FileSpec { public: CPDF_FileSpec(); - explicit CPDF_FileSpec(CPDF_Object* pObj) { m_pObj = pObj; } + explicit CPDF_FileSpec(CPDF_Object* pObj) : m_pObj(pObj) {} // Convert a platform dependent file name into pdf format. static CFX_WideString EncodeFileName(const CFX_WideStringC& filepath); @@ -349,7 +296,6 @@ class CPDF_LinkList { private: const std::vector* GetPageLinks(CPDF_Page* pPage); - void LoadPageLinks(CPDF_Page* pPage, std::vector* pList); std::map> m_PageMap; @@ -388,31 +334,23 @@ class CPDF_Annot : public CFX_PrivateData { ~CPDF_Annot(); CFX_ByteString GetSubType() const; - FX_DWORD GetFlags() const; - void GetRect(CFX_FloatRect& rect) const; - const CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict; } CPDF_Dictionary* GetAnnotDict() { return m_pAnnotDict; } - FX_BOOL DrawAppearance(CPDF_Page* pPage, CFX_RenderDevice* pDevice, const CFX_Matrix* pUser2Device, AppearanceMode mode, const CPDF_RenderOptions* pOptions); - FX_BOOL DrawInContext(const CPDF_Page* pPage, CPDF_RenderContext* pContext, const CFX_Matrix* pUser2Device, AppearanceMode mode); - void ClearCachedAP(); - void DrawBorder(CFX_RenderDevice* pDevice, const CFX_Matrix* pUser2Device, const CPDF_RenderOptions* pOptions); - CPDF_Form* GetAPForm(const CPDF_Page* pPage, AppearanceMode mode); private: @@ -436,6 +374,7 @@ class CPDF_AnnotList { DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, bShowWidget ? 3 : 1, pOptions, nullptr); } + void DisplayAnnots(CPDF_Page* pPage, CFX_RenderDevice* pDevice, CPDF_RenderContext* pContext, @@ -469,52 +408,33 @@ class CPDF_AnnotList { #define COLORTYPE_CMYK 3 class CPDF_DefaultAppearance { public: - // TODO(thestig): Examine why this cannot be explicit. - CPDF_DefaultAppearance(const CFX_ByteString& csDA = "") { m_csDA = csDA; } + CPDF_DefaultAppearance() {} + explicit CPDF_DefaultAppearance(const CFX_ByteString& csDA) : m_csDA(csDA) {} CPDF_DefaultAppearance(const CPDF_DefaultAppearance& cDA) { - m_csDA = (CFX_ByteString)(CPDF_DefaultAppearance&)cDA; - } - - operator CFX_ByteString() const { return m_csDA; } - - const CPDF_DefaultAppearance& operator=(const CFX_ByteString& csDA) { - m_csDA = csDA; - return *this; - } - - const CPDF_DefaultAppearance& operator=(const CPDF_DefaultAppearance& cDA) { - m_csDA = (CFX_ByteString)(CPDF_DefaultAppearance&)cDA; - return *this; + m_csDA = cDA.GetStr(); } + CFX_ByteString GetStr() const { return m_csDA; } FX_BOOL HasFont(); - CFX_ByteString GetFontString(); - void GetFont(CFX_ByteString& csFontNameTag, FX_FLOAT& fFontSize); - FX_BOOL HasColor(FX_BOOL bStrokingOperation = FALSE); - CFX_ByteString GetColorString(FX_BOOL bStrokingOperation = FALSE); - void GetColor(int& iColorType, FX_FLOAT fc[4], FX_BOOL bStrokingOperation = FALSE); - void GetColor(FX_ARGB& color, int& iColorType, FX_BOOL bStrokingOperation = FALSE); - FX_BOOL HasTextMatrix(); - CFX_ByteString GetTextMatrixString(); - CFX_Matrix GetTextMatrix(); protected: CFX_ByteString m_csDA; }; + #define FIELDTYPE_UNKNOWN 0 #define FIELDTYPE_PUSHBUTTON 1 #define FIELDTYPE_CHECKBOX 2 @@ -540,9 +460,10 @@ class CPDF_InterForm : public CFX_PrivateData { static CPDF_Font* AddStandardFont(CPDF_Document* pDocument, CFX_ByteString csFontName); - static CFX_ByteString GetNativeFont(uint8_t iCharSet, void* pLogFont = NULL); + static CFX_ByteString GetNativeFont(uint8_t iCharSet, + void* pLogFont = nullptr); - static CFX_ByteString GetNativeFont(void* pLogFont = NULL); + static CFX_ByteString GetNativeFont(void* pLogFont = nullptr); static uint8_t GetNativeCharSet(); @@ -704,6 +625,7 @@ class CPDF_InterForm : public CFX_PrivateData { friend class CPDF_FormControl; friend class CPDF_FormField; }; + #define FORMFIELD_READONLY 0x01 #define FORMFIELD_REQUIRED 0x02 #define FORMFIELD_NOEXPORT 0x04 @@ -861,27 +783,24 @@ class CPDF_FormField { friend class CPDF_InterForm; friend class CPDF_FormControl; }; + CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, const FX_CHAR* name, int nLevel = 0); class CPDF_IconFit { public: - // TODO(thestig): Examine why this cannot be explicit. - CPDF_IconFit(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; } - - operator CPDF_Dictionary*() const { return m_pDict; } - enum ScaleMethod { Always = 0, Bigger, Smaller, Never }; - ScaleMethod GetScaleMethod(); + explicit CPDF_IconFit(const CPDF_Dictionary* pDict) : m_pDict(pDict) {} + ScaleMethod GetScaleMethod(); FX_BOOL IsProportionalScale(); - void GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom); - FX_BOOL GetFittingBounds(); + const CPDF_Dictionary* GetDict() const { return m_pDict; } - CPDF_Dictionary* m_pDict; + protected: + const CPDF_Dictionary* const m_pDict; }; #define TEXTPOS_CAPTION 0 @@ -906,7 +825,7 @@ class CPDF_FormControl { CFX_Matrix* pMatrix, CPDF_Page* pPage, CPDF_Annot::AppearanceMode mode, - const CPDF_RenderOptions* pOptions = NULL); + const CPDF_RenderOptions* pOptions = nullptr); CFX_ByteString GetCheckedAPState(); CFX_WideString GetExportValue(); @@ -1021,18 +940,17 @@ class CPDF_FormNotify { }; FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); + class CPDF_PageLabel { public: - explicit CPDF_PageLabel(CPDF_Document* pDocument) { m_pDocument = pDocument; } + explicit CPDF_PageLabel(CPDF_Document* pDocument) : m_pDocument(pDocument) {} CFX_WideString GetLabel(int nPage) const; - int32_t GetPageByLabel(const CFX_ByteStringC& bsLabel) const; - int32_t GetPageByLabel(const CFX_WideStringC& wsLabel) const; protected: - CPDF_Document* m_pDocument; + CPDF_Document* const m_pDocument; }; class CPDF_Metadata { @@ -1049,17 +967,12 @@ class CPDF_Metadata { class CPDF_ViewerPreferences { public: explicit CPDF_ViewerPreferences(CPDF_Document* pDoc); - ~CPDF_ViewerPreferences(); FX_BOOL IsDirectionR2L() const; - FX_BOOL PrintScaling() const; - int32_t NumCopies() const; - CPDF_Array* PrintPageRange() const; - CFX_ByteString Duplex() const; protected: diff --git a/core/src/fpdfdoc/doc_bookmark.cpp b/core/src/fpdfdoc/doc_bookmark.cpp index 53e90c0ae1..d7e2e2fcab 100644 --- a/core/src/fpdfdoc/doc_bookmark.cpp +++ b/core/src/fpdfdoc/doc_bookmark.cpp @@ -11,23 +11,24 @@ CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild( const CPDF_Bookmark& parent) const { - if (!parent.m_pDict) { + if (!parent.GetDict()) { CPDF_Dictionary* pRoot = m_pDocument->GetRoot()->GetDictBy("Outlines"); - if (!pRoot) { + if (!pRoot) return CPDF_Bookmark(); - } return CPDF_Bookmark(pRoot->GetDictBy("First")); } - return CPDF_Bookmark(parent.m_pDict->GetDictBy("First")); + return CPDF_Bookmark(parent.GetDict()->GetDictBy("First")); } + CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling( const CPDF_Bookmark& bookmark) const { - if (!bookmark.m_pDict) { + if (!bookmark.GetDict()) return CPDF_Bookmark(); - } - CPDF_Dictionary* pNext = bookmark.m_pDict->GetDictBy("Next"); - return pNext == bookmark.m_pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext); + + CPDF_Dictionary* pNext = bookmark.GetDict()->GetDictBy("Next"); + return pNext == bookmark.GetDict() ? CPDF_Bookmark() : CPDF_Bookmark(pNext); } + FX_DWORD CPDF_Bookmark::GetColorRef() const { if (!m_pDict) { return 0; diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp index 5e333ea025..684d9122ad 100644 --- a/core/src/fpdfdoc/doc_form.cpp +++ b/core/src/fpdfdoc/doc_form.cpp @@ -836,14 +836,13 @@ void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { m_bUpdated = TRUE; RemoveInterFormFont(m_pFormDict, csNameTag); } + CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { - CFX_ByteString csDA; - if (!m_pFormDict) { - return csDA; - } - csDA = m_pFormDict->GetStringBy("DA"); - return csDA; + if (!m_pFormDict) + return CPDF_DefaultAppearance(); + return CPDF_DefaultAppearance(m_pFormDict->GetStringBy("DA")); } + CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { return GetDefaultInterFormFont(m_pFormDict, m_pDocument); } diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp index 169e9d73b7..4cfd4527e2 100644 --- a/core/src/fpdfdoc/doc_formcontrol.cpp +++ b/core/src/fpdfdoc/doc_formcontrol.cpp @@ -246,27 +246,27 @@ CPDF_Action CPDF_FormControl::GetAction() { } return CPDF_Action(pObj->GetDict()); } + CPDF_AAction CPDF_FormControl::GetAdditionalAction() { - if (!m_pWidgetDict) { - return nullptr; - } - if (m_pWidgetDict->KeyExist("AA")) { - return m_pWidgetDict->GetDictBy("AA"); - } + if (!m_pWidgetDict) + return CPDF_AAction(); + + if (m_pWidgetDict->KeyExist("AA")) + return CPDF_AAction(m_pWidgetDict->GetDictBy("AA")); return m_pField->GetAdditionalAction(); } + CPDF_DefaultAppearance CPDF_FormControl::GetDefaultAppearance() { - if (!m_pWidgetDict) { - return CFX_ByteString(); - } - if (m_pWidgetDict->KeyExist("DA")) { - return m_pWidgetDict->GetStringBy("DA"); - } + if (!m_pWidgetDict) + return CPDF_DefaultAppearance(); + + if (m_pWidgetDict->KeyExist("DA")) + return CPDF_DefaultAppearance(m_pWidgetDict->GetStringBy("DA")); + CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "DA"); - if (!pObj) { - return m_pField->m_pForm->GetDefaultAppearance(); - } - return pObj->GetString(); + if (pObj) + return CPDF_DefaultAppearance(pObj->GetString()); + return m_pField->m_pForm->GetDefaultAppearance(); } CPDF_Font* CPDF_FormControl::GetDefaultControlFont() { @@ -421,7 +421,7 @@ CPDF_Stream* CPDF_ApSettings::GetIcon(const CFX_ByteStringC& csEntry) const { } CPDF_IconFit CPDF_ApSettings::GetIconFit() const { - return m_pDict ? m_pDict->GetDictBy("IF") : nullptr; + return CPDF_IconFit(m_pDict ? m_pDict->GetDictBy("IF") : nullptr); } int CPDF_ApSettings::GetTextPosition() const { diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp index 7f85aff4d3..a7cc484361 100644 --- a/core/src/fpdfdoc/doc_formfield.cpp +++ b/core/src/fpdfdoc/doc_formfield.cpp @@ -235,13 +235,12 @@ int CPDF_FormField::GetFieldType() { } return FIELDTYPE_UNKNOWN; } + CPDF_AAction CPDF_FormField::GetAdditionalAction() { CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "AA"); - if (!pObj) { - return NULL; - } - return pObj->GetDict(); + return CPDF_AAction(pObj ? pObj->GetDict() : nullptr); } + CFX_WideString CPDF_FormField::GetAlternateName() { CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TU"); if (!pObj) { diff --git a/core/src/fpdfdoc/doc_utils.cpp b/core/src/fpdfdoc/doc_utils.cpp index db5db4ee89..67a9324251 100644 --- a/core/src/fpdfdoc/doc_utils.cpp +++ b/core/src/fpdfdoc/doc_utils.cpp @@ -615,17 +615,19 @@ void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { } pFonts->RemoveAt(csNameTag); } + CPDF_Font* GetDefaultInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument) { if (!pFormDict) { return NULL; } - CPDF_DefaultAppearance cDA = pFormDict->GetStringBy("DA"); + CPDF_DefaultAppearance cDA(pFormDict->GetStringBy("DA")); CFX_ByteString csFontNameTag; FX_FLOAT fFontSize; cDA.GetFont(csFontNameTag, fFontSize); return GetInterFormFont(pFormDict, pDocument, csFontNameTag); } + CPDF_IconFit::ScaleMethod CPDF_IconFit::GetScaleMethod() { if (!m_pDict) { return Always; diff --git a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp index 21a4bb6ab2..2cad12b4e8 100644 --- a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp +++ b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp @@ -128,7 +128,7 @@ void CFFL_IFormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, if (!m_bNotifying) { CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (pWidget->GetAAction(CPDF_AAction::CursorEnter)) { + if (pWidget->GetAAction(CPDF_AAction::CursorEnter).GetDict()) { m_bNotifying = TRUE; int nValueAge = pWidget->GetValueAge(); @@ -164,7 +164,7 @@ void CFFL_IFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, if (!m_bNotifying) { CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (pWidget->GetAAction(CPDF_AAction::CursorExit)) { + if (pWidget->GetAAction(CPDF_AAction::CursorExit).GetDict()) { m_bNotifying = TRUE; pWidget->GetAppearanceAge(); int nValueAge = pWidget->GetValueAge(); @@ -202,7 +202,7 @@ FX_BOOL CFFL_IFormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, if (!m_bNotifying) { CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; if (Annot_HitTest(pPageView, pAnnot, point) && - pWidget->GetAAction(CPDF_AAction::ButtonDown)) { + pWidget->GetAAction(CPDF_AAction::ButtonDown).GetDict()) { m_bNotifying = TRUE; pWidget->GetAppearanceAge(); int nValueAge = pWidget->GetValueAge(); @@ -284,7 +284,7 @@ void CFFL_IFormFiller::OnButtonUp(CPDFSDK_Widget* pWidget, ASSERT(pWidget); if (!m_bNotifying) { - if (pWidget->GetAAction(CPDF_AAction::ButtonUp)) { + if (pWidget->GetAAction(CPDF_AAction::ButtonUp).GetDict()) { m_bNotifying = TRUE; int nAge = pWidget->GetAppearanceAge(); int nValueAge = pWidget->GetValueAge(); @@ -415,7 +415,7 @@ FX_BOOL CFFL_IFormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { if (!m_bNotifying) { CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (pWidget->GetAAction(CPDF_AAction::GetFocus)) { + if (pWidget->GetAAction(CPDF_AAction::GetFocus).GetDict()) { m_bNotifying = TRUE; pWidget->GetAppearanceAge(); @@ -461,7 +461,7 @@ FX_BOOL CFFL_IFormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { if (!m_bNotifying) { CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (pWidget->GetAAction(CPDF_AAction::LoseFocus)) { + if (pWidget->GetAAction(CPDF_AAction::LoseFocus).GetDict()) { m_bNotifying = TRUE; pWidget->ClearAppModified(); @@ -642,7 +642,7 @@ void CFFL_IFormFiller::OnKeyStrokeCommit(CPDFSDK_Widget* pWidget, FX_BOOL& bExit, FX_DWORD nFlag) { if (!m_bNotifying) { - if (pWidget->GetAAction(CPDF_AAction::KeyStroke)) { + if (pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { m_bNotifying = TRUE; pWidget->ClearAppModified(); @@ -674,7 +674,7 @@ void CFFL_IFormFiller::OnValidate(CPDFSDK_Widget* pWidget, FX_BOOL& bExit, FX_DWORD nFlag) { if (!m_bNotifying) { - if (pWidget->GetAAction(CPDF_AAction::Validate)) { + if (pWidget->GetAAction(CPDF_AAction::Validate).GetDict()) { m_bNotifying = TRUE; pWidget->ClearAppModified(); @@ -951,7 +951,7 @@ void CFFL_IFormFiller::OnBeforeKeyStroke(void* pPrivateData, #endif // PDF_ENABLE_XFA if (!m_bNotifying) { - if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke)) { + if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { m_bNotifying = TRUE; int nAge = pData->pWidget->GetAppearanceAge(); int nValueAge = pData->pWidget->GetValueAge(); diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp index c88dccd86a..50f3e2c904 100644 --- a/fpdfsdk/src/fpdfdoc.cpp +++ b/fpdfsdk/src/fpdfdoc.cpp @@ -15,16 +15,17 @@ int THISMODULE = 0; CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, CPDF_Bookmark bookmark, const CFX_WideString& title) { - if (bookmark && bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { + if (bookmark.GetDict() && + bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { // First check this item return bookmark; } // go into children items CPDF_Bookmark child = tree.GetFirstChild(bookmark); - while (child) { + while (child.GetDict()) { // check if this item CPDF_Bookmark found = FindBookmark(tree, child, title); - if (found) + if (found.GetDict()) return found; child = tree.GetNextSibling(child); } @@ -112,12 +113,12 @@ DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, return nullptr; CPDF_Bookmark bookmark(ToDictionary(static_cast(pDict))); CPDF_Dest dest = bookmark.GetDest(pDoc); - if (dest) + if (dest.GetObject()) return dest.GetObject(); // If this bookmark is not directly associated with a dest, we try to get // action CPDF_Action action = bookmark.GetAction(); - if (!action) + if (!action.GetDict()) return nullptr; return action.GetDest(pDoc).GetObject(); } @@ -244,7 +245,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, return dest; // If this link is not directly associated with a dest, we try to get action CPDF_Action action = link.GetAction(); - if (!action) + if (!action.GetDict()) return nullptr; return action.GetDest(pDoc).GetObject(); } diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp index c2e75c34d5..874082e277 100644 --- a/fpdfsdk/src/fpdfformfill.cpp +++ b/fpdfsdk/src/fpdfformfill.cpp @@ -691,7 +691,7 @@ DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, if (!pDic) return; - CPDF_AAction aa = pDic->GetDictBy("AA"); + CPDF_AAction aa(pDic->GetDictBy("AA")); if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); CPDFSDK_ActionHandler* pActionHandler = @@ -715,7 +715,7 @@ DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv(); CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; - CPDF_AAction aa = pPageDict->GetDictBy("AA"); + CPDF_AAction aa(pPageDict->GetDictBy("AA")); if (FPDFPAGE_AACTION_OPEN == aaType) { if (aa.ActionExist(CPDF_AAction::OpenPage)) { CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); diff --git a/fpdfsdk/src/fsdk_actionhandler.cpp b/fpdfsdk/src/fsdk_actionhandler.cpp index c429373f08..496e1131dc 100644 --- a/fpdfsdk/src/fsdk_actionhandler.cpp +++ b/fpdfsdk/src/fsdk_actionhandler.cpp @@ -421,7 +421,7 @@ FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument) { void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, const CPDF_Action& action) { - ASSERT(action); + ASSERT(action.GetDict()); CPDF_Document* pPDFDocument = pDocument->GetPDFDocument(); ASSERT(pPDFDocument); @@ -454,7 +454,7 @@ void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action) { - ASSERT(action); + ASSERT(action.GetDict()); CPDFDoc_Environment* pApp = pDocument->GetEnv(); CFX_ByteString sURI = action.GetURI(pDocument->GetPDFDocument()); @@ -463,7 +463,7 @@ void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action) { - ASSERT(action); + ASSERT(action.GetDict()); CFX_ByteString csName = action.GetNamedAction(); pDocument->GetEnv()->FFI_ExecuteNamedAction(csName); diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp index 132d30b857..bd73ee3211 100644 --- a/fpdfsdk/src/fsdk_baseannot.cpp +++ b/fpdfsdk/src/fsdk_baseannot.cpp @@ -892,9 +892,8 @@ CPDF_Action CPDFSDK_BAAnnot::GetAction() const { } void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) { - ASSERT(action); - if ((CPDF_Action&)action != - CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictBy("A"))) { + ASSERT(action.GetDict()); + if (action.GetDict() != m_pAnnot->GetAnnotDict()->GetDictBy("A")) { CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); CPDF_Dictionary* pDict = action.GetDict(); if (pDict && pDict->GetObjNum() == 0) { @@ -909,12 +908,12 @@ void CPDFSDK_BAAnnot::RemoveAction() { } CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const { - return m_pAnnot->GetAnnotDict()->GetDictBy("AA"); + return CPDF_AAction(m_pAnnot->GetAnnotDict()->GetDictBy("AA")); } void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) { - if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDictBy("AA")) - m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa); + if (aa.GetDict() != m_pAnnot->GetAnnotDict()->GetDictBy("AA")) + m_pAnnot->GetAnnotDict()->SetAt("AA", aa.GetDict()); } void CPDFSDK_BAAnnot::RemoveAAction() { diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp index 8245980fbb..8d8b95f38e 100644 --- a/fpdfsdk/src/fsdk_baseform.cpp +++ b/fpdfsdk/src/fsdk_baseform.cpp @@ -1912,7 +1912,7 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, #endif // PDF_ENABLE_XFA CPDF_Action action = GetAAction(type); - if (action && action.GetType() != CPDF_Action::Unknown) { + if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); return pActionHandler->DoAction_Field(action, type, pDocument, GetFormField(), data); @@ -1939,8 +1939,8 @@ CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { case CPDF_AAction::Validate: case CPDF_AAction::Calculate: { CPDF_FormField* pField = GetFormField(); - if (CPDF_AAction aa = pField->GetAdditionalAction()) - return aa.GetAction(eAAT); + if (pField->GetAdditionalAction().GetDict()) + return pField->GetAdditionalAction().GetAction(eAAT); return CPDFSDK_BAAnnot::GetAAction(eAAT); } default: @@ -2200,9 +2200,10 @@ void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) { int nType = pField->GetFieldType(); if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { CPDF_AAction aAction = pField->GetAdditionalAction(); - if (aAction && aAction.ActionExist(CPDF_AAction::Calculate)) { + if (aAction.GetDict() && + aAction.ActionExist(CPDF_AAction::Calculate)) { CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate); - if (action) { + if (action.GetDict()) { CFX_WideString csJS = action.GetJavaScript(); if (!csJS.IsEmpty()) { IJS_Context* pContext = pRuntime->NewContext(); @@ -2256,9 +2257,9 @@ CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, bFormated = FALSE; CPDF_AAction aAction = pFormField->GetAdditionalAction(); - if (aAction && aAction.ActionExist(CPDF_AAction::Format)) { + if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) { CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); - if (action) { + if (action.GetDict()) { CFX_WideString script = action.GetJavaScript(); if (!script.IsEmpty()) { CFX_WideString Value = sValue; @@ -2313,11 +2314,11 @@ void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, const CFX_WideString& csValue) { CPDF_AAction aAction = pFormField->GetAdditionalAction(); - if (!aAction || !aAction.ActionExist(CPDF_AAction::KeyStroke)) + if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke)) return TRUE; CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); - if (!action) + if (!action.GetDict()) return TRUE; CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); @@ -2334,11 +2335,11 @@ FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, const CFX_WideString& csValue) { CPDF_AAction aAction = pFormField->GetAdditionalAction(); - if (!aAction || !aAction.ActionExist(CPDF_AAction::Validate)) + if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate)) return TRUE; CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); - if (!action) + if (!action.GetDict()) return TRUE; CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); @@ -2353,9 +2354,9 @@ FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, } FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { - ASSERT(action); + ASSERT(action.GetDict()); - CPDF_ActionFields af = action.GetWidgets(); + CPDF_ActionFields af(&action); std::vector fieldObjects = af.GetAllFields(); std::vector fields = GetFieldFromObjects(fieldObjects); @@ -2392,7 +2393,7 @@ FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { CPDF_Dictionary* pActionDict = action.GetDict(); if (pActionDict->KeyExist("Fields")) { - CPDF_ActionFields af = action.GetWidgets(); + CPDF_ActionFields af(&action); FX_DWORD dwFlags = action.GetFlags(); std::vector fieldObjects = af.GetAllFields(); std::vector fields = GetFieldFromObjects(fieldObjects); @@ -2559,13 +2560,13 @@ FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { } FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { - ASSERT(action); + ASSERT(action.GetDict()); CPDF_Dictionary* pActionDict = action.GetDict(); if (!pActionDict->KeyExist("Fields")) return m_pInterForm->ResetForm(true); - CPDF_ActionFields af = action.GetWidgets(); + CPDF_ActionFields af(&action); FX_DWORD dwFlags = action.GetFlags(); std::vector fieldObjects = af.GetAllFields(); diff --git a/fpdfsdk/src/pdfwindow/PWL_Icon.cpp b/fpdfsdk/src/pdfwindow/PWL_Icon.cpp index 1bfa1a6d3a..d8e11c2c02 100644 --- a/fpdfsdk/src/pdfwindow/PWL_Icon.cpp +++ b/fpdfsdk/src/pdfwindow/PWL_Icon.cpp @@ -128,7 +128,7 @@ void CPWL_Icon::GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom) { fLeft = 0.0f; fBottom = 0.0f; CPDF_Array* pA = - m_pIconFit->m_pDict ? m_pIconFit->m_pDict->GetArrayBy("A") : NULL; + m_pIconFit->GetDict() ? m_pIconFit->GetDict()->GetArrayBy("A") : NULL; if (pA) { FX_DWORD dwCount = pA->GetCount(); if (dwCount > 0) -- cgit v1.2.3