diff options
-rw-r--r-- | core/fpdftext/fpdf_text_int.cpp | 79 | ||||
-rw-r--r-- | core/fpdftext/include/cpdf_linkextract.h | 2 | ||||
-rw-r--r-- | core/fpdftext/include/cpdf_textpage.h | 8 | ||||
-rw-r--r-- | core/fpdftext/include/cpdf_textpagefind.h | 3 | ||||
-rw-r--r-- | core/fxcrt/include/fx_coordinates.h | 1 | ||||
-rw-r--r-- | fpdfsdk/fpdftext.cpp | 19 | ||||
-rw-r--r-- | fpdfsdk/fsdk_mgr.cpp | 8 | ||||
-rw-r--r-- | fpdfsdk/include/fsdk_mgr.h | 2 | ||||
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 4 |
9 files changed, 57 insertions, 69 deletions
diff --git a/core/fpdftext/fpdf_text_int.cpp b/core/fpdftext/fpdf_text_int.cpp index 4db4d5c09f..92c4097fc3 100644 --- a/core/fpdftext/fpdf_text_int.cpp +++ b/core/fpdftext/fpdf_text_int.cpp @@ -260,23 +260,21 @@ int CPDF_TextPage::TextIndexFromCharIndex(int CharIndex) const { return -1; } -void CPDF_TextPage::GetRectArray(int start, - int nCount, - CFX_RectArray* rectArray) const { - if (start < 0 || nCount == 0) { - return; - } - if (!m_bIsParsed) { - return; - } - CPDF_TextObject* pCurObj = NULL; - CFX_FloatRect rect; - int curPos = start; - FX_BOOL flagNewRect = TRUE; +std::vector<CFX_FloatRect> CPDF_TextPage::GetRectArray(int start, + int nCount) const { + if (start < 0 || nCount == 0 || !m_bIsParsed) + return std::vector<CFX_FloatRect>(); + if (nCount + start > pdfium::CollectionSize<int>(m_CharList) || nCount == -1) { nCount = pdfium::CollectionSize<int>(m_CharList) - start; } + + std::vector<CFX_FloatRect> rectArray; + CPDF_TextObject* pCurObj = nullptr; + CFX_FloatRect rect; + int curPos = start; + FX_BOOL flagNewRect = TRUE; while (nCount--) { PAGECHAR_INFO info_curchar = m_CharList[curPos++]; if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) { @@ -290,7 +288,7 @@ void CPDF_TextPage::GetRectArray(int start, pCurObj = info_curchar.m_pTextObj; } if (pCurObj != info_curchar.m_pTextObj) { - rectArray->Add(rect); + rectArray.push_back(rect); pCurObj = info_curchar.m_pTextObj; flagNewRect = TRUE; } @@ -343,7 +341,8 @@ void CPDF_TextPage::GetRectArray(int start, } } } - rectArray->Add(rect); + rectArray.push_back(rect); + return rectArray; } int CPDF_TextPage::GetIndexAtPos(CFX_FloatPoint point, @@ -427,12 +426,13 @@ CFX_WideString CPDF_TextPage::GetTextByRect(const CFX_FloatRect& rect) const { return strText; } -void CPDF_TextPage::GetRectsArrayByRect(const CFX_FloatRect& rect, - CFX_RectArray& resRectArray) const { +std::vector<CFX_FloatRect> CPDF_TextPage::GetRectsArrayByRect( + const CFX_FloatRect& rect) const { if (!m_bIsParsed) - return; + return std::vector<CFX_FloatRect>(); CFX_FloatRect curRect; + std::vector<CFX_FloatRect> result; bool flagNewRect = true; CPDF_TextObject* pCurObj = nullptr; for (auto info_curchar : m_CharList) { @@ -446,7 +446,7 @@ void CPDF_TextPage::GetRectsArrayByRect(const CFX_FloatRect& rect, pCurObj = info_curchar.m_pTextObj; } if (pCurObj != info_curchar.m_pTextObj) { - resRectArray.Add(curRect); + result.push_back(curRect); pCurObj = info_curchar.m_pTextObj; flagNewRect = true; } @@ -462,7 +462,8 @@ void CPDF_TextPage::GetRectsArrayByRect(const CFX_FloatRect& rect, curRect.top = std::max(curRect.top, info_curchar.m_CharBox.top); } } - resRectArray.Add(curRect); + result.push_back(curRect); + return result; } int CPDF_TextPage::GetIndexAtPos(FX_FLOAT x, @@ -591,9 +592,8 @@ int CPDF_TextPage::CountRects(int start, int nCount) { nCount + start > pdfium::CollectionSize<int>(m_CharList)) { nCount = pdfium::CollectionSize<int>(m_CharList) - start; } - m_SelRects.RemoveAll(); - GetRectArray(start, nCount, &m_SelRects); - return m_SelRects.GetSize(); + m_SelRects = GetRectArray(start, nCount); + return pdfium::CollectionSize<int>(m_SelRects); } void CPDF_TextPage::GetRect(int rectIndex, @@ -604,13 +604,13 @@ void CPDF_TextPage::GetRect(int rectIndex, if (!m_bIsParsed) return; - if (rectIndex < 0 || rectIndex >= m_SelRects.GetSize()) + if (rectIndex < 0 || rectIndex >= pdfium::CollectionSize<int>(m_SelRects)) return; - left = m_SelRects.GetAt(rectIndex).left; - top = m_SelRects.GetAt(rectIndex).top; - right = m_SelRects.GetAt(rectIndex).right; - bottom = m_SelRects.GetAt(rectIndex).bottom; + left = m_SelRects[rectIndex].left; + top = m_SelRects[rectIndex].top; + right = m_SelRects[rectIndex].right; + bottom = m_SelRects[rectIndex].bottom; } FX_BOOL CPDF_TextPage::GetBaselineRotate(int start, int end, int& Rotate) { @@ -1997,7 +1997,7 @@ FX_BOOL CPDF_TextPageFind::FindNext() { if (!m_pTextPage) { return FALSE; } - m_resArray.RemoveAll(); + m_resArray.clear(); if (m_findNextStart == -1) { return FALSE; } @@ -2089,7 +2089,7 @@ FX_BOOL CPDF_TextPageFind::FindNext() { m_IsFind = TRUE; int resStart = GetCharIndex(m_resStart); int resEnd = GetCharIndex(m_resEnd); - m_pTextPage->GetRectArray(resStart, resEnd - resStart + 1, &m_resArray); + m_resArray = m_pTextPage->GetRectArray(resStart, resEnd - resStart + 1); if (m_flags & FPDFTEXT_CONSECUTIVE) { m_findNextStart = m_resStart + 1; m_findPreStart = m_resEnd - 1; @@ -2104,7 +2104,7 @@ FX_BOOL CPDF_TextPageFind::FindPrev() { if (!m_pTextPage) { return FALSE; } - m_resArray.RemoveAll(); + m_resArray.clear(); if (m_strText.IsEmpty() || m_findPreStart < 0) { m_IsFind = FALSE; return m_IsFind; @@ -2135,7 +2135,7 @@ FX_BOOL CPDF_TextPageFind::FindPrev() { m_resStart = m_pTextPage->TextIndexFromCharIndex(order); m_resEnd = m_pTextPage->TextIndexFromCharIndex(order + MatchedCount - 1); m_IsFind = TRUE; - m_pTextPage->GetRectArray(order, MatchedCount, &m_resArray); + m_resArray = m_pTextPage->GetRectArray(order, MatchedCount); if (m_flags & FPDFTEXT_CONSECUTIVE) { m_findNextStart = m_resStart + 1; m_findPreStart = m_resEnd - 1; @@ -2279,10 +2279,6 @@ CFX_WideString CPDF_TextPageFind::MakeReverse(const CFX_WideString& str) { return str2; } -void CPDF_TextPageFind::GetRectArray(CFX_RectArray& rects) const { - rects.Copy(m_resArray); -} - int CPDF_TextPageFind::GetCurOrder() const { return GetCharIndex(m_resStart); } @@ -2446,9 +2442,10 @@ CFX_WideString CPDF_LinkExtract::GetURL(size_t index) const { return index < m_LinkArray.size() ? m_LinkArray[index].m_strUrl : L""; } -void CPDF_LinkExtract::GetRects(size_t index, CFX_RectArray* pRects) const { - if (index < m_LinkArray.size()) { - m_pTextPage->GetRectArray(m_LinkArray[index].m_Start, - m_LinkArray[index].m_Count, pRects); - } +std::vector<CFX_FloatRect> CPDF_LinkExtract::GetRects(size_t index) const { + if (index >= m_LinkArray.size()) + return std::vector<CFX_FloatRect>(); + + return m_pTextPage->GetRectArray(m_LinkArray[index].m_Start, + m_LinkArray[index].m_Count); } diff --git a/core/fpdftext/include/cpdf_linkextract.h b/core/fpdftext/include/cpdf_linkextract.h index 4f9537c799..5d471e0f1c 100644 --- a/core/fpdftext/include/cpdf_linkextract.h +++ b/core/fpdftext/include/cpdf_linkextract.h @@ -24,7 +24,7 @@ class CPDF_LinkExtract { void ExtractLinks(); size_t CountLinks() const { return m_LinkArray.size(); } CFX_WideString GetURL(size_t index) const; - void GetRects(size_t index, CFX_RectArray* pRects) const; + std::vector<CFX_FloatRect> GetRects(size_t index) const; protected: void ParseLink(); diff --git a/core/fpdftext/include/cpdf_textpage.h b/core/fpdftext/include/cpdf_textpage.h index 8d608b0bf0..1a60a2351d 100644 --- a/core/fpdftext/include/cpdf_textpage.h +++ b/core/fpdftext/include/cpdf_textpage.h @@ -67,7 +67,7 @@ class CPDF_TextPage { int TextIndexFromCharIndex(int CharIndex) const; int CountChars() const; void GetCharInfo(int index, FPDF_CHAR_INFO* info) const; - void GetRectArray(int start, int nCount, CFX_RectArray* rectArray) const; + std::vector<CFX_FloatRect> GetRectArray(int start, int nCount) const; int GetIndexAtPos(CFX_FloatPoint point, FX_FLOAT xTolerance, FX_FLOAT yTolerance) const; @@ -76,8 +76,8 @@ class CPDF_TextPage { FX_FLOAT xTolerance, FX_FLOAT yTolerance) const; CFX_WideString GetTextByRect(const CFX_FloatRect& rect) const; - void GetRectsArrayByRect(const CFX_FloatRect& rect, - CFX_RectArray& resRectArray) const; + std::vector<CFX_FloatRect> GetRectsArrayByRect( + const CFX_FloatRect& rect) const; CFX_WideString GetPageText(int start = 0, int nCount = -1) const; int CountRects(int start, int nCount); void GetRect(int rectIndex, @@ -146,7 +146,7 @@ class CPDF_TextPage { bool m_bIsParsed; CFX_Matrix m_DisplayMatrix; CFX_ArrayTemplate<FPDF_SEGMENT> m_Segments; - CFX_RectArray m_SelRects; + std::vector<CFX_FloatRect> m_SelRects; CFX_ArrayTemplate<PDFTEXT_Obj> m_LineObj; int32_t m_TextlineDir; CFX_FloatRect m_CurlineRect; diff --git a/core/fpdftext/include/cpdf_textpagefind.h b/core/fpdftext/include/cpdf_textpagefind.h index ec739e4896..d9937772d1 100644 --- a/core/fpdftext/include/cpdf_textpagefind.h +++ b/core/fpdftext/include/cpdf_textpagefind.h @@ -25,7 +25,6 @@ class CPDF_TextPageFind { int startPos = 0); FX_BOOL FindNext(); FX_BOOL FindPrev(); - void GetRectArray(CFX_RectArray& rects) const; int GetCurOrder() const; int GetMatchedCount() const; @@ -58,7 +57,7 @@ class CPDF_TextPageFind { FX_BOOL m_bMatchWholeWord; int m_resStart; int m_resEnd; - CFX_RectArray m_resArray; + std::vector<CFX_FloatRect> m_resArray; FX_BOOL m_IsFind; }; diff --git a/core/fxcrt/include/fx_coordinates.h b/core/fxcrt/include/fx_coordinates.h index a7f0b8d5dc..ec6b41c869 100644 --- a/core/fxcrt/include/fx_coordinates.h +++ b/core/fxcrt/include/fx_coordinates.h @@ -310,7 +310,6 @@ class CFX_FloatRect { FX_FLOAT right; FX_FLOAT top; }; -using CFX_RectArray = CFX_ArrayTemplate<CFX_FloatRect>; // LTWH rectangles (y-axis runs downwards). template <class baseType> diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp index 2a84131422..4d521da8ed 100644 --- a/fpdfsdk/fpdftext.cpp +++ b/fpdfsdk/fpdftext.cpp @@ -13,6 +13,7 @@ #include "core/fpdftext/include/cpdf_textpagefind.h" #include "fpdfsdk/include/fsdk_define.h" #include "third_party/base/numerics/safe_conversions.h" +#include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" @@ -315,10 +316,8 @@ DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page, if (!link_page || link_index < 0) return 0; - CFX_RectArray rects; CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); - pageLink->GetRects(link_index, &rects); - return rects.GetSize(); + return pdfium::CollectionSize<int>(pageLink->GetRects(link_index)); } DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page, @@ -331,17 +330,15 @@ DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page, if (!link_page || link_index < 0 || rect_index < 0) return; - CFX_RectArray rectArray; CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); - pageLink->GetRects(link_index, &rectArray); - if (rect_index >= rectArray.GetSize()) + std::vector<CFX_FloatRect> rectArray = pageLink->GetRects(link_index); + if (rect_index >= pdfium::CollectionSize<int>(rectArray)) return; - CFX_FloatRect rect = rectArray.GetAt(rect_index); - *left = rect.left; - *right = rect.right; - *top = rect.top; - *bottom = rect.bottom; + *left = rectArray[rect_index].left; + *right = rectArray[rect_index].right; + *top = rectArray[rect_index].top; + *bottom = rectArray[rect_index].bottom; } DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page) { diff --git a/fpdfsdk/fsdk_mgr.cpp b/fpdfsdk/fsdk_mgr.cpp index 7240fe1d0b..cfb1b8a8b3 100644 --- a/fpdfsdk/fsdk_mgr.cpp +++ b/fpdfsdk/fsdk_mgr.cpp @@ -1158,12 +1158,10 @@ void CPDFSDK_PageView::ClearFXAnnots() { SetLock(FALSE); } -void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) { - for (int i = 0; i < rects.GetSize(); i++) { - CFX_FloatRect rc = rects.GetAt(i); - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); +void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + for (const auto& rc : rects) pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); - } } void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h index 3d691c1f2d..0578a16e3d 100644 --- a/fpdfsdk/include/fsdk_mgr.h +++ b/fpdfsdk/include/fsdk_mgr.h @@ -614,7 +614,7 @@ class CPDFSDK_PageView final { int nFlag); bool IsValidAnnot(const CPDF_Annot* p) const; void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; } - void UpdateRects(CFX_RectArray& rects); + void UpdateRects(const std::vector<CFX_FloatRect>& rects); void UpdateView(CPDFSDK_Annot* pAnnot); const std::vector<CPDFSDK_Annot*>& GetAnnotList() const { return m_fxAnnotArray; diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index 551d649830..fa2f7ae4e4 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -494,9 +494,7 @@ FX_BOOL Document::removeField(IJS_Context* cc, ++rcAnnot.right; ++rcAnnot.top; - CFX_RectArray aRefresh; - aRefresh.Add(rcAnnot); - + std::vector<CFX_FloatRect> aRefresh(1, rcAnnot); UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); ASSERT(pPage); |