From c2c3f7b5f0396409451a9d344f35ec1929a76e9f Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 14 Aug 2015 14:07:43 -0700 Subject: Use override in more classes in core/ R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1292613003 . --- core/src/fpdfdoc/doc_ap.cpp | 11 ++- core/src/fpdfdoc/doc_vt.cpp | 21 ++--- core/src/fpdfdoc/pdf_vt.h | 176 ++++++++++++++++++++++++------------------ core/src/fpdfdoc/tagged_int.h | 44 ++++++----- 4 files changed, 143 insertions(+), 109 deletions(-) (limited to 'core/src/fpdfdoc') diff --git a/core/src/fpdfdoc/doc_ap.cpp b/core/src/fpdfdoc/doc_ap.cpp index feedb32989..cffaad9900 100644 --- a/core/src/fpdfdoc/doc_ap.cpp +++ b/core/src/fpdfdoc/doc_ap.cpp @@ -38,15 +38,19 @@ FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { } return FALSE; } + class CPVT_FontMap : public IPVT_FontMap { public: CPVT_FontMap(CPDF_Document* pDoc, CPDF_Dictionary* pResDict, CPDF_Font* pDefFont, const CFX_ByteString& sDefFontAlias); - virtual ~CPVT_FontMap(); - CPDF_Font* GetPDFFont(int32_t nFontIndex); - CFX_ByteString GetPDFFontAlias(int32_t nFontIndex); + ~CPVT_FontMap() override; + + // IPVT_FontMap + CPDF_Font* GetPDFFont(int32_t nFontIndex) override; + CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) override; + static void GetAnnotSysPDFFont(CPDF_Document* pDoc, CPDF_Dictionary* pResDict, CPDF_Font*& pSysFont, @@ -60,6 +64,7 @@ class CPVT_FontMap : public IPVT_FontMap { CPDF_Font* m_pSysFont; CFX_ByteString m_sSysFontAlias; }; + CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc, CPDF_Dictionary* pResDict, CPDF_Font* pDefFont, diff --git a/core/src/fpdfdoc/doc_vt.cpp b/core/src/fpdfdoc/doc_vt.cpp index b7c8ed80f6..396a7d6b71 100644 --- a/core/src/fpdfdoc/doc_vt.cpp +++ b/core/src/fpdfdoc/doc_vt.cpp @@ -960,10 +960,10 @@ CPVT_WordPlace CPDF_VariableText::DeleteWords( return PlaceRange.BeginPos; } CPVT_WordPlace CPDF_VariableText::DeleteWord(const CPVT_WordPlace& place) { - return ClearRightWord(AjustLineHeader(place, TRUE)); + return ClearRightWord(AdjustLineHeader(place, TRUE)); } CPVT_WordPlace CPDF_VariableText::BackSpaceWord(const CPVT_WordPlace& place) { - return ClearLeftWord(AjustLineHeader(place, TRUE)); + return ClearLeftWord(AdjustLineHeader(place, TRUE)); } void CPDF_VariableText::SetText(const FX_WCHAR* text, int32_t charset, @@ -1032,7 +1032,7 @@ void CPDF_VariableText::UpdateWordPlace(CPVT_WordPlace& place) const { if (place.nSecIndex >= m_SectionArray.GetSize()) { place = GetEndWordPlace(); } - place = AjustLineHeader(place, TRUE); + place = AdjustLineHeader(place, TRUE); if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { pSection->UpdateWordPlace(place); } @@ -1429,7 +1429,7 @@ int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { : m_nHorzScale; } void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { - CPVT_WordPlace wordplace = AjustLineHeader(place, TRUE); + CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE); if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { for (int32_t w = pSection->m_WordArray.GetSize() - 1; w > wordplace.nWordIndex; w--) { @@ -1438,8 +1438,8 @@ void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { } } } -CPVT_WordPlace CPDF_VariableText::AjustLineHeader(const CPVT_WordPlace& place, - FX_BOOL bPrevOrNext) const { +CPVT_WordPlace CPDF_VariableText::AdjustLineHeader(const CPVT_WordPlace& place, + FX_BOOL bPrevOrNext) const { if (place.nWordIndex < 0 && place.nLineIndex > 0) { return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); } @@ -1467,7 +1467,7 @@ void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) { } } void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { - CPVT_WordPlace oldplace = AjustLineHeader(place, TRUE); + CPVT_WordPlace oldplace = AdjustLineHeader(place, TRUE); if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz; @@ -1484,8 +1484,8 @@ void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { } void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) { CPVT_WordRange NewRange; - NewRange.BeginPos = AjustLineHeader(PlaceRange.BeginPos, TRUE); - NewRange.EndPos = AjustLineHeader(PlaceRange.EndPos, TRUE); + NewRange.BeginPos = AdjustLineHeader(PlaceRange.BeginPos, TRUE); + NewRange.EndPos = AdjustLineHeader(PlaceRange.EndPos, TRUE); for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex; s--) { if (CSection* pSection = m_SectionArray.GetAt(s)) { @@ -1513,7 +1513,8 @@ CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) { } CPVT_WordPlace CPDF_VariableText::ClearRightWord(const CPVT_WordPlace& place) { if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { - CPVT_WordPlace rightplace = AjustLineHeader(GetNextWordPlace(place), FALSE); + CPVT_WordPlace rightplace = + AdjustLineHeader(GetNextWordPlace(place), FALSE); if (rightplace != place) { if (rightplace.nSecIndex != place.nSecIndex) { LinkLatterSection(place); diff --git a/core/src/fpdfdoc/pdf_vt.h b/core/src/fpdfdoc/pdf_vt.h index d3010da73b..207daab98d 100644 --- a/core/src/fpdfdoc/pdf_vt.h +++ b/core/src/fpdfdoc/pdf_vt.h @@ -343,6 +343,7 @@ class CPDF_EditContainer { CPDF_Rect m_rcPlate; CPVT_FloatRect m_rcContent; }; + class CPDF_VariableText : public IPDF_VariableText, private CPDF_EditContainer { friend class CTypeset; friend class CSection; @@ -350,80 +351,102 @@ class CPDF_VariableText : public IPDF_VariableText, private CPDF_EditContainer { public: CPDF_VariableText(); - virtual ~CPDF_VariableText(); + ~CPDF_VariableText() override; + + // IPDF_VariableText IPDF_VariableText_Provider* SetProvider( - IPDF_VariableText_Provider* pProvider); - IPDF_VariableText_Iterator* GetIterator(); - void SetPlateRect(const CPDF_Rect& rect) { + IPDF_VariableText_Provider* pProvider) override; + IPDF_VariableText_Iterator* GetIterator() override; + void SetPlateRect(const CPDF_Rect& rect) override { CPDF_EditContainer::SetPlateRect(rect); } - void SetAlignment(int32_t nFormat = 0) { m_nAlignment = nFormat; } - void SetPasswordChar(FX_WORD wSubWord = '*') { m_wSubWord = wSubWord; } - void SetLimitChar(int32_t nLimitChar = 0) { m_nLimitChar = nLimitChar; } - void SetCharSpace(FX_FLOAT fCharSpace = 0.0f) { m_fCharSpace = fCharSpace; } - void SetHorzScale(int32_t nHorzScale = 100) { m_nHorzScale = nHorzScale; } - void SetMultiLine(FX_BOOL bMultiLine = TRUE) { m_bMultiLine = bMultiLine; } - void SetAutoReturn(FX_BOOL bAuto = TRUE) { m_bLimitWidth = bAuto; } - void SetFontSize(FX_FLOAT fFontSize) { m_fFontSize = fFontSize; } - void SetCharArray(int32_t nCharArray = 0) { m_nCharArray = nCharArray; } - void SetAutoFontSize(FX_BOOL bAuto = TRUE) { m_bAutoFontSize = bAuto; } - void SetRichText(FX_BOOL bRichText) { m_bRichText = bRichText; } - void SetLineLeading(FX_FLOAT fLineLeading) { m_fLineLeading = fLineLeading; } - void Initialize(); - FX_BOOL IsValid() const { return m_bInitial; } - FX_BOOL IsRichText() const { return m_bRichText; } - void RearrangeAll(); - void RearrangePart(const CPVT_WordRange& PlaceRange); - void ResetAll(); + void SetAlignment(int32_t nFormat = 0) override { m_nAlignment = nFormat; } + void SetPasswordChar(FX_WORD wSubWord = '*') override { + m_wSubWord = wSubWord; + } + void SetLimitChar(int32_t nLimitChar = 0) override { + m_nLimitChar = nLimitChar; + } + void SetCharSpace(FX_FLOAT fCharSpace = 0.0f) override { + m_fCharSpace = fCharSpace; + } + void SetHorzScale(int32_t nHorzScale = 100) override { + m_nHorzScale = nHorzScale; + } + void SetMultiLine(FX_BOOL bMultiLine = TRUE) override { + m_bMultiLine = bMultiLine; + } + void SetAutoReturn(FX_BOOL bAuto = TRUE) override { m_bLimitWidth = bAuto; } + void SetFontSize(FX_FLOAT fFontSize) override { m_fFontSize = fFontSize; } + void SetCharArray(int32_t nCharArray = 0) override { + m_nCharArray = nCharArray; + } + void SetAutoFontSize(FX_BOOL bAuto = TRUE) override { + m_bAutoFontSize = bAuto; + } + void SetRichText(FX_BOOL bRichText) override { m_bRichText = bRichText; } + void SetLineLeading(FX_FLOAT fLineLeading) override { + m_fLineLeading = fLineLeading; + } + void Initialize() override; + FX_BOOL IsValid() const override { return m_bInitial; } + FX_BOOL IsRichText() const override { return m_bRichText; } + void RearrangeAll() override; + void RearrangePart(const CPVT_WordRange& PlaceRange) override; + void ResetAll() override; void SetText(const FX_WCHAR* text, int32_t charset = 1, const CPVT_SecProps* pSecProps = NULL, - const CPVT_WordProps* pWordProps = NULL); + const CPVT_WordProps* pWordProps = NULL) override; CPVT_WordPlace InsertWord(const CPVT_WordPlace& place, FX_WORD word, int32_t charset = 1, - const CPVT_WordProps* pWordProps = NULL); - CPVT_WordPlace InsertSection(const CPVT_WordPlace& place, - const CPVT_SecProps* pSecProps = NULL, - const CPVT_WordProps* pWordProps = NULL); + const CPVT_WordProps* pWordProps = NULL) override; + CPVT_WordPlace InsertSection( + const CPVT_WordPlace& place, + const CPVT_SecProps* pSecProps = NULL, + const CPVT_WordProps* pWordProps = NULL) override; CPVT_WordPlace InsertText(const CPVT_WordPlace& place, const FX_WCHAR* text, int32_t charset = 1, const CPVT_SecProps* pSecProps = NULL, - const CPVT_WordProps* pWordProps = NULL); - CPVT_WordPlace DeleteWords(const CPVT_WordRange& PlaceRange); - CPVT_WordPlace DeleteWord(const CPVT_WordPlace& place); - CPVT_WordPlace BackSpaceWord(const CPVT_WordPlace& place); - const CPDF_Rect& GetPlateRect() const { + const CPVT_WordProps* pWordProps = NULL) override; + CPVT_WordPlace DeleteWords(const CPVT_WordRange& PlaceRange) override; + CPVT_WordPlace DeleteWord(const CPVT_WordPlace& place) override; + CPVT_WordPlace BackSpaceWord(const CPVT_WordPlace& place) override; + const CPDF_Rect& GetPlateRect() const override { return CPDF_EditContainer::GetPlateRect(); } - CPDF_Rect GetContentRect() const; - int32_t GetTotalWords() const; - FX_FLOAT GetFontSize() const { return m_fFontSize; } - int32_t GetAlignment() const { return m_nAlignment; } - int32_t GetCharArray() const { return m_nCharArray; } - int32_t GetLimitChar() const { return m_nLimitChar; } - FX_BOOL IsMultiLine() const { return m_bMultiLine; } - int32_t GetHorzScale() const { return m_nHorzScale; } - FX_FLOAT GetCharSpace() const { return m_fCharSpace; } - - CPVT_WordPlace GetBeginWordPlace() const; - CPVT_WordPlace GetEndWordPlace() const; - CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const; - CPVT_WordPlace GetNextWordPlace(const CPVT_WordPlace& place) const; - CPVT_WordPlace SearchWordPlace(const CPDF_Point& point) const; + CPDF_Rect GetContentRect() const override; + int32_t GetTotalWords() const override; + FX_FLOAT GetFontSize() const override { return m_fFontSize; } + int32_t GetAlignment() const override { return m_nAlignment; } + FX_WORD GetPasswordChar() const override { return GetSubWord(); } + int32_t GetCharArray() const override { return m_nCharArray; } + int32_t GetLimitChar() const override { return m_nLimitChar; } + FX_BOOL IsMultiLine() const override { return m_bMultiLine; } + int32_t GetHorzScale() const override { return m_nHorzScale; } + FX_FLOAT GetCharSpace() const override { return m_fCharSpace; } + CPVT_WordPlace GetBeginWordPlace() const override; + CPVT_WordPlace GetEndWordPlace() const override; + CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const override; + CPVT_WordPlace GetNextWordPlace(const CPVT_WordPlace& place) const override; + CPVT_WordPlace SearchWordPlace(const CPDF_Point& point) const override; CPVT_WordPlace GetUpWordPlace(const CPVT_WordPlace& place, - const CPDF_Point& point) const; + const CPDF_Point& point) const override; CPVT_WordPlace GetDownWordPlace(const CPVT_WordPlace& place, - const CPDF_Point& point) const; - CPVT_WordPlace GetLineBeginPlace(const CPVT_WordPlace& place) const; - CPVT_WordPlace GetLineEndPlace(const CPVT_WordPlace& place) const; - CPVT_WordPlace GetSectionBeginPlace(const CPVT_WordPlace& place) const; - CPVT_WordPlace GetSectionEndPlace(const CPVT_WordPlace& place) const; - void UpdateWordPlace(CPVT_WordPlace& place) const; - int32_t WordPlaceToWordIndex(const CPVT_WordPlace& place) const; - CPVT_WordPlace WordIndexToWordPlace(int32_t index) const; - FX_WORD GetPasswordChar() const { return GetSubWord(); } + const CPDF_Point& point) const override; + CPVT_WordPlace GetLineBeginPlace(const CPVT_WordPlace& place) const override; + CPVT_WordPlace GetLineEndPlace(const CPVT_WordPlace& place) const override; + CPVT_WordPlace GetSectionBeginPlace( + const CPVT_WordPlace& place) const override; + CPVT_WordPlace GetSectionEndPlace(const CPVT_WordPlace& place) const override; + void UpdateWordPlace(CPVT_WordPlace& place) const override; + CPVT_WordPlace AdjustLineHeader(const CPVT_WordPlace& place, + FX_BOOL bPrevOrNext) const override; + int32_t WordPlaceToWordIndex(const CPVT_WordPlace& place) const override; + CPVT_WordPlace WordIndexToWordPlace(int32_t index) const override; + FX_WORD GetSubWord() const { return m_wSubWord; } private: @@ -437,7 +460,6 @@ class CPDF_VariableText : public IPDF_VariableText, private CPDF_EditContainer { int32_t GetDefaultFontIndex(); FX_BOOL IsLatinWord(FX_WORD word); - private: CPVT_WordPlace AddSection(const CPVT_WordPlace& place, const CPVT_SectionInfo& secinfo); CPVT_WordPlace AddLine(const CPVT_WordPlace& place, @@ -479,8 +501,7 @@ class CPDF_VariableText : public IPDF_VariableText, private CPDF_EditContainer { int32_t GetAlignment(const CPVT_SectionInfo& SecInfo); void ClearSectionRightWords(const CPVT_WordPlace& place); - CPVT_WordPlace AjustLineHeader(const CPVT_WordPlace& place, - FX_BOOL bPrevOrNext) const; + FX_BOOL ClearEmptySection(const CPVT_WordPlace& place); void ClearEmptySections(const CPVT_WordRange& PlaceRange); void LinkLatterSection(const CPVT_WordPlace& place); @@ -494,10 +515,8 @@ class CPDF_VariableText : public IPDF_VariableText, private CPDF_EditContainer { FX_BOOL IsBigger(FX_FLOAT fFontSize); CPVT_FloatRect RearrangeSections(const CPVT_WordRange& PlaceRange); - private: void ResetSectionArray(); - private: CPVT_ArrayTemplate m_SectionArray; int32_t m_nLimitChar; int32_t m_nCharArray; @@ -517,24 +536,27 @@ class CPDF_VariableText : public IPDF_VariableText, private CPDF_EditContainer { IPDF_VariableText_Provider* m_pVTProvider; CPDF_VariableText_Iterator* m_pVTIterator; }; + class CPDF_VariableText_Iterator : public IPDF_VariableText_Iterator { public: CPDF_VariableText_Iterator(CPDF_VariableText* pVT); - virtual ~CPDF_VariableText_Iterator(); - FX_BOOL NextWord(); - FX_BOOL PrevWord(); - FX_BOOL NextLine(); - FX_BOOL PrevLine(); - FX_BOOL NextSection(); - FX_BOOL PrevSection(); - FX_BOOL SetWord(const CPVT_Word& word); - FX_BOOL GetWord(CPVT_Word& word) const; - FX_BOOL GetLine(CPVT_Line& line) const; - FX_BOOL GetSection(CPVT_Section& section) const; - FX_BOOL SetSection(const CPVT_Section& section); - void SetAt(int32_t nWordIndex); - void SetAt(const CPVT_WordPlace& place); - const CPVT_WordPlace& GetAt() const { return m_CurPos; }; + ~CPDF_VariableText_Iterator() override; + + // IPDF_VariableText_Iterator + FX_BOOL NextWord() override; + FX_BOOL PrevWord() override; + FX_BOOL NextLine() override; + FX_BOOL PrevLine() override; + FX_BOOL NextSection() override; + FX_BOOL PrevSection() override; + FX_BOOL SetWord(const CPVT_Word& word) override; + FX_BOOL GetWord(CPVT_Word& word) const override; + FX_BOOL GetLine(CPVT_Line& line) const override; + FX_BOOL GetSection(CPVT_Section& section) const override; + FX_BOOL SetSection(const CPVT_Section& section) override; + void SetAt(int32_t nWordIndex) override; + void SetAt(const CPVT_WordPlace& place) override; + const CPVT_WordPlace& GetAt() const override { return m_CurPos; }; private: CPVT_WordPlace m_CurPos; diff --git a/core/src/fpdfdoc/tagged_int.h b/core/src/fpdfdoc/tagged_int.h index 7cf368083c..de6854ea0b 100644 --- a/core/src/fpdfdoc/tagged_int.h +++ b/core/src/fpdfdoc/tagged_int.h @@ -10,14 +10,18 @@ #include "../../include/fpdfdoc/fpdf_tagged.h" class CPDF_StructElementImpl; + class CPDF_StructTreeImpl : public CPDF_StructTree { public: - CPDF_StructTreeImpl(const CPDF_Document* pDoc); - ~CPDF_StructTreeImpl(); - int CountTopElements() const { return m_Kids.GetSize(); } - CPDF_StructElement* GetTopElement(int i) const { + explicit CPDF_StructTreeImpl(const CPDF_Document* pDoc); + ~CPDF_StructTreeImpl() override; + + // CPDF_StructTree + int CountTopElements() const override { return m_Kids.GetSize(); } + CPDF_StructElement* GetTopElement(int i) const override { return (CPDF_StructElement*)m_Kids.GetAt(i); } + void LoadDocTree(); void LoadPageTree(const CPDF_Dictionary* pPageDict); CPDF_StructElementImpl* AddPageNode(CPDF_Dictionary* pElement, @@ -33,46 +37,48 @@ class CPDF_StructTreeImpl : public CPDF_StructTree { CFX_ArrayTemplate m_Kids; friend class CPDF_StructElementImpl; }; + class CPDF_StructElementImpl final : public CPDF_StructElement { public: CPDF_StructElementImpl(CPDF_StructTreeImpl* pTree, CPDF_StructElementImpl* pParent, CPDF_Dictionary* pDict); - CPDF_StructTree* GetTree() const { return m_pTree; } - const CFX_ByteString& GetType() const { return m_Type; } - CPDF_StructElement* GetParent() const { return m_pParent; } - CPDF_Dictionary* GetDict() const { return m_pDict; } - int CountKids() const { return m_Kids.GetSize(); } - const CPDF_StructKid& GetKid(int index) const { + + // CPDF_StructTreeImpl + CPDF_StructTree* GetTree() const override { return m_pTree; } + const CFX_ByteString& GetType() const override { return m_Type; } + CPDF_StructElement* GetParent() const override { return m_pParent; } + CPDF_Dictionary* GetDict() const override { return m_pDict; } + int CountKids() const override { return m_Kids.GetSize(); } + const CPDF_StructKid& GetKid(int index) const override { return m_Kids.GetData()[index]; } - CFX_PtrArray* GetObjectArray() { return &m_ObjectArray; } - + CFX_PtrArray* GetObjectArray() override { return &m_ObjectArray; } CPDF_Object* GetAttr(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, FX_BOOL bInheritable = FALSE, - FX_FLOAT fLevel = 0.0F); - + FX_FLOAT fLevel = 0.0F) override; CFX_ByteString GetName(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, const CFX_ByteStringC& default_value, FX_BOOL bInheritable = FALSE, - int subindex = -1); + int subindex = -1) override; FX_ARGB GetColor(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, FX_ARGB default_value, FX_BOOL bInheritable = FALSE, - int subindex = -1); + int subindex = -1) override; FX_FLOAT GetNumber(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, FX_FLOAT default_value, FX_BOOL bInheritable = FALSE, - int subindex = -1); + int subindex = -1) override; int GetInteger(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, int default_value, FX_BOOL bInheritable = FALSE, - int subindex = -1); + int subindex = -1) override; + CFX_PtrArray m_ObjectArray; void LoadKids(CPDF_Dictionary* pDict); void LoadKid(FX_DWORD PageObjNum, CPDF_Object* pObj, CPDF_StructKid* pKid); @@ -84,7 +90,7 @@ class CPDF_StructElementImpl final : public CPDF_StructElement { void Release(); protected: - ~CPDF_StructElementImpl(); + ~CPDF_StructElementImpl() override; CPDF_StructTreeImpl* m_pTree; CFX_ByteString m_Type; -- cgit v1.2.3