summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/fpdfformfill.cpp68
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp9
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp8
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_Edit.cpp8
4 files changed, 49 insertions, 44 deletions
diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp
index 5825456b19..e39d623307 100644
--- a/fpdfsdk/src/fpdfformfill.cpp
+++ b/fpdfsdk/src/fpdfformfill.cpp
@@ -7,10 +7,12 @@
#include "public/fpdf_formfill.h"
#include <memory>
+#include <vector>
#include "fpdfsdk/include/fsdk_define.h"
#include "fpdfsdk/include/fsdk_mgr.h"
#include "public/fpdfview.h"
+#include "third_party/base/stl_util.h"
#ifdef PDF_ENABLE_XFA
#include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h"
@@ -35,6 +37,16 @@ CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle,
return pSDKDoc ? pSDKDoc->GetPageView(pPage, TRUE) : nullptr;
}
+#ifdef PDF_ENABLE_XFA
+std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) {
+ return reinterpret_cast<std::vector<CFX_ByteString>*>(handle);
+}
+
+FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) {
+ return reinterpret_cast<FPDF_STRINGHANDLE>(strings);
+}
+#endif // PDF_ENABLE_XFA
+
} // namespace
DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
@@ -467,6 +479,7 @@ DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document,
}
*size = real_size;
}
+
DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document,
FPDF_WIDGET hWidget,
FPDF_WIDESTRING wsText,
@@ -502,6 +515,7 @@ DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document,
}
*size = real_size;
}
+
DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document,
FPDF_WIDGET hWidget,
FPDF_WIDESTRING wsText,
@@ -522,6 +536,7 @@ DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document,
CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
pXFAMenuHander->Paste((IXFA_Widget*)hWidget, wstr);
}
+
DLLEXPORT void STDCALL
FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document,
FPDF_WIDGET hWidget,
@@ -547,13 +562,14 @@ FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document,
CFX_ByteStringC bs(bsText);
pXFAMenuHander->ReplaceSpellCheckWord((IXFA_Widget*)hWidget, ptPopup, bs);
}
+
DLLEXPORT void STDCALL
FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
FPDF_WIDGET hWidget,
float x,
float y,
FPDF_STRINGHANDLE* stringHandle) {
- if (NULL == hWidget || NULL == document)
+ if (!hWidget || !document)
return;
CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
@@ -563,69 +579,63 @@ FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
IXFA_MenuHandler* pXFAMenuHander =
CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler();
- if (pXFAMenuHander == NULL)
+ if (!pXFAMenuHander)
return;
- CFX_ByteStringArray* sSuggestWords = new CFX_ByteStringArray;
+ std::vector<CFX_ByteString>* sSuggestWords = new std::vector<CFX_ByteString>;
CFX_PointF ptPopup;
ptPopup.x = x;
ptPopup.y = y;
- pXFAMenuHander->GetSuggestWords((IXFA_Widget*)hWidget, ptPopup,
- *sSuggestWords);
- *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords;
+ pXFAMenuHander->GetSuggestWords(reinterpret_cast<IXFA_Widget*>(hWidget),
+ ptPopup, *sSuggestWords);
+ *stringHandle = ToFPDFStringHandle(sSuggestWords);
}
-DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE stringHandle) {
- if (stringHandle == NULL)
- return -1;
- CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle;
- return sSuggestWords->GetSize();
+
+DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) {
+ std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
+ return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1;
}
+
DLLEXPORT FPDF_BOOL STDCALL
-FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE stringHandle,
+FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle,
int index,
FPDF_BYTESTRING bsText,
FPDF_DWORD* size) {
- if (stringHandle == NULL || size == NULL)
+ if (!sHandle || !size)
return FALSE;
- int count = FPDF_StringHandleCounts(stringHandle);
+
+ int count = FPDF_StringHandleCounts(sHandle);
if (index < 0 || index >= count)
return FALSE;
- CFX_ByteStringArray sSuggestWords = *(CFX_ByteStringArray*)stringHandle;
- int len = sSuggestWords[index].GetLength();
-
- if (bsText == NULL) {
+ std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle);
+ int len = (*sSuggestWords)[index].GetLength();
+ if (!bsText) {
*size = len;
return TRUE;
}
int real_size = len < *size ? len : *size;
if (real_size > 0)
- FXSYS_memcpy((void*)bsText, (const FX_CHAR*)(sSuggestWords[index]),
+ FXSYS_memcpy((void*)bsText, (const FX_CHAR*)(*sSuggestWords)[index],
real_size);
*size = real_size;
-
return TRUE;
}
+
DLLEXPORT void STDCALL
FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) {
- if (stringHandle == NULL)
- return;
- CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle;
- delete sSuggestWords;
+ delete FromFPDFStringHandle(stringHandle);
}
DLLEXPORT FPDF_BOOL STDCALL
FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle,
FPDF_BYTESTRING bsText,
FPDF_DWORD size) {
- if (stringHandle == NULL || bsText == NULL || size <= 0)
+ if (!stringHandle || !bsText || size == 0)
return FALSE;
- CFX_ByteStringArray* stringArr = (CFX_ByteStringArray*)stringHandle;
- CFX_ByteString bsStr(bsText, size);
-
- stringArr->Add(bsStr);
+ FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size));
return TRUE;
}
#endif // PDF_ENABLE_XFA
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index 65dc926fb3..fd30cf1f18 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -176,14 +176,11 @@ FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(
if (!pFontMapper)
return FALSE;
- int nSize = pFontMapper->m_InstalledTTFonts.GetSize();
- if (nSize == 0) {
+ if (pFontMapper->m_InstalledTTFonts.empty())
pFontMapper->LoadInstalledFonts();
- nSize = pFontMapper->m_InstalledTTFonts.GetSize();
- }
- for (int i = 0; i < nSize; ++i) {
- if (pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName))
+ for (const auto& font : pFontMapper->m_InstalledTTFonts) {
+ if (font.Compare(sFontFaceName))
return TRUE;
}
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index 3c6d36fdd8..1a5c83cc46 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -1201,19 +1201,19 @@ FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc,
}
double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue) {
- CFX_WideStringArray wsArray;
+ std::vector<CFX_WideString> wsArray;
CFX_WideString sTemp = L"";
for (int i = 0; i < strValue.GetLength(); ++i) {
FX_WCHAR c = strValue.GetAt(i);
if (c == L' ' || c == L':') {
- wsArray.Add(sTemp);
+ wsArray.push_back(sTemp);
sTemp = L"";
continue;
}
sTemp += c;
}
- wsArray.Add(sTemp);
- if (wsArray.GetSize() != 8)
+ wsArray.push_back(sTemp);
+ if (wsArray.size() != 8)
return 0;
int nMonth = 1;
diff --git a/fpdfsdk/src/pdfwindow/PWL_Edit.cpp b/fpdfsdk/src/pdfwindow/PWL_Edit.cpp
index 057cb4191e..4b3886a11d 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Edit.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Edit.cpp
@@ -15,6 +15,7 @@
#include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
#include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
#include "public/fpdf_fwlevent.h"
+#include "third_party/base/stl_util.h"
CPWL_Edit::CPWL_Edit()
: m_pFillerNotify(NULL), m_pSpellCheck(NULL), m_bFocus(FALSE) {
@@ -519,24 +520,21 @@ FX_BOOL CPWL_Edit::OnRButtonUp(const CPDF_Point& point, FX_DWORD nFlag) {
if (!hPopup)
return FALSE;
- CFX_ByteStringArray sSuggestWords;
+ std::vector<CFX_ByteString> sSuggestWords;
CPDF_Point ptPopup = point;
if (!IsReadOnly()) {
if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty()) {
if (m_pSpellCheck) {
CFX_ByteString sLatin = CFX_ByteString::FromUnicode(swLatin);
-
if (!m_pSpellCheck->CheckWord(sLatin)) {
m_pSpellCheck->SuggestWords(sLatin, sSuggestWords);
- int32_t nSuggest = sSuggestWords.GetSize();
-
+ int32_t nSuggest = pdfium::CollectionSize<int32_t>(sSuggestWords);
for (int32_t nWord = 0; nWord < nSuggest; nWord++) {
pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SUGGEST + nWord,
sSuggestWords[nWord].UTF8Decode());
}
-
if (nSuggest > 0)
pSH->AppendMenuItem(hPopup, 0, L"");