diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdf_edit_embeddertest.cpp | 8 | ||||
-rw-r--r-- | fpdfsdk/fpdf_editpage.cpp | 55 | ||||
-rw-r--r-- | fpdfsdk/fpdf_view_c_api_test.c | 3 |
3 files changed, 66 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index 8f54bf8eab..ec6b893530 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -473,6 +473,14 @@ TEST_F(FPDFEditEmbeddertest, RemoveMarkedObjectsPrime) { } else if (name == L"Square") { square_count++; EXPECT_EQ(1, FPDFPageObjMark_CountParams(mark)); + ASSERT_GT(FPDFPageObjMark_GetParamKey(mark, 0, buffer, 256), 0u); + std::wstring key = + GetPlatformWString(reinterpret_cast<unsigned short*>(buffer)); + EXPECT_EQ(L"Factor", key); + EXPECT_EQ(FPDF_OBJECT_NUMBER, + FPDFPageObjMark_GetParamValueType(mark, 0)); + int square_root = FPDFPageObjMark_GetParamIntValue(mark, 0); + EXPECT_EQ(i + 1, square_root * square_root); } else if (name == L"GreaterThanTen") { greater_than_ten_count++; EXPECT_EQ(0, FPDFPageObjMark_CountParams(mark)); diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp index 7a8bbabf2d..241025f3a6 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp @@ -99,6 +99,28 @@ void CalcBoundingBox(CPDF_PageObject* pPageObj) { } } +const std::pair<const ByteString, std::unique_ptr<CPDF_Object>>* +GetMarkParamPairAtIndex(FPDF_PAGEOBJECTMARK mark, unsigned long index) { + if (!mark) + return nullptr; + + const CPDF_ContentMarkItem* pMarkItem = + CPDFContentMarkItemFromFPDFPageObjectMark(mark); + + const CPDF_Dictionary* pParams = pMarkItem->GetParam(); + if (!pParams) + return nullptr; + + for (auto& it : *pParams) { + if (index == 0) + return ⁢ + + --index; + } + + return nullptr; +} + } // namespace FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument() { @@ -284,6 +306,39 @@ FPDFPageObjMark_CountParams(FPDF_PAGEOBJECTMARK mark) { return pParams->GetCount(); } +FPDF_EXPORT unsigned long FPDF_CALLCONV +FPDFPageObjMark_GetParamKey(FPDF_PAGEOBJECTMARK mark, + unsigned long index, + void* buffer, + unsigned long buflen) { + auto* param_pair = GetMarkParamPairAtIndex(mark, index); + if (!param_pair) + return 0; + + return Utf16EncodeMaybeCopyAndReturnLength( + WideString::FromUTF8(param_pair->first.AsStringView()), buffer, buflen); +} + +FPDF_EXPORT FPDF_OBJECT_TYPE FPDF_CALLCONV +FPDFPageObjMark_GetParamValueType(FPDF_PAGEOBJECTMARK mark, + unsigned long index) { + auto* param_pair = GetMarkParamPairAtIndex(mark, index); + if (!param_pair) + return FPDF_OBJECT_UNKNOWN; + + return param_pair->second->GetType(); +} + +FPDF_EXPORT int FPDF_CALLCONV +FPDFPageObjMark_GetParamIntValue(FPDF_PAGEOBJECTMARK mark, + unsigned long index) { + auto* param_pair = GetMarkParamPairAtIndex(mark, index); + if (!param_pair) + return 0; + + return param_pair->second->GetInteger(); +} + FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { if (!pageObject) diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c index 017487246b..dd93095550 100644 --- a/fpdfsdk/fpdf_view_c_api_test.c +++ b/fpdfsdk/fpdf_view_c_api_test.c @@ -149,6 +149,9 @@ int CheckPDFiumCApi() { CHK(FPDFPageObj_GetMark); CHK(FPDFPageObjMark_GetName); CHK(FPDFPageObjMark_CountParams); + CHK(FPDFPageObjMark_GetParamKey); + CHK(FPDFPageObjMark_GetParamValueType); + CHK(FPDFPageObjMark_GetParamIntValue); CHK(FPDFImageObj_LoadJpegFile); CHK(FPDFImageObj_LoadJpegFileInline); CHK(FPDFImageObj_SetMatrix); |