diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2018-04-23 16:35:56 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-23 16:35:56 +0000 |
commit | 132c38e7bdd0bdd1aa526b35c7bcb79c286fb061 (patch) | |
tree | 20801fa3c9ce77a72d2195dcd6e2daba8298d853 /fpdfsdk | |
parent | fd016f4e9b0df99ed4670b50b30e5c6f18028f9a (diff) | |
download | pdfium-132c38e7bdd0bdd1aa526b35c7bcb79c286fb061.tar.xz |
Create API to get PageObject mark parameters.
New calls added in this cl:
- FPDFPageObjMark_GetParamKey
- FPDFPageObjMark_GetParamValueType
- FPDFPageObjMark_GetParamIntValue
Bug: pdfium:1037
Change-Id: Iedb74ddbf8a5483de62094ec295dadd6367d5175
Reviewed-on: https://pdfium-review.googlesource.com/30912
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
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); |