diff options
author | Lei Zhang <thestig@chromium.org> | 2018-04-17 17:01:52 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-17 17:01:52 +0000 |
commit | 2617056df6d6e1d0f17031f0c9db09f9192cb0fa (patch) | |
tree | 3e286a9d2f7c754ca8521ea878d7a1c795bea82f /core/fpdfapi | |
parent | b7973bb5a0ad2f83a71362d601a928964559004a (diff) | |
download | pdfium-2617056df6d6e1d0f17031f0c9db09f9192cb0fa.tar.xz |
Add constants for PDF 1.7 spec, table 3.4.
Add constants/stream_dict_common.h. The header lists all the constants
in the table in the same order. Constants that are not used at all are
commented out.
BUG=pdfium:1049
Change-Id: I6539090e0ad56319ea628883e388aeacef044e52
Reviewed-on: https://pdfium-review.googlesource.com/29090
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/edit/cpdf_flateencoder.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_image.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamparser.cpp | 5 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_object_unittest.cpp | 37 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_stream.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode.cpp | 3 |
6 files changed, 34 insertions, 21 deletions
diff --git a/core/fpdfapi/edit/cpdf_flateencoder.cpp b/core/fpdfapi/edit/cpdf_flateencoder.cpp index 9826932d2a..f6125b8847 100644 --- a/core/fpdfapi/edit/cpdf_flateencoder.cpp +++ b/core/fpdfapi/edit/cpdf_flateencoder.cpp @@ -8,6 +8,7 @@ #include <memory> +#include "constants/stream_dict_common.h" #include "core/fpdfapi/parser/cpdf_name.h" #include "core/fpdfapi/parser/cpdf_number.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" @@ -43,7 +44,7 @@ CPDF_FlateEncoder::CPDF_FlateEncoder(const CPDF_Stream* pStream, m_pDict = ToDictionary(pStream->GetDict()->Clone()); m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(m_dwSize)); m_pDict->SetNewFor<CPDF_Name>("Filter", "FlateDecode"); - m_pDict->RemoveFor("DecodeParms"); + m_pDict->RemoveFor(pdfium::stream::kDecodeParms); } CPDF_FlateEncoder::~CPDF_FlateEncoder() {} diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp index ec826dc5ed..68a6a3243c 100644 --- a/core/fpdfapi/page/cpdf_image.cpp +++ b/core/fpdfapi/page/cpdf_image.cpp @@ -11,6 +11,7 @@ #include <utility> #include <vector> +#include "constants/stream_dict_common.h" #include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/parser/cpdf_array.h" @@ -105,7 +106,8 @@ std::unique_ptr<CPDF_Dictionary> CPDF_Image::InitJPEG(uint8_t* pData, pDict->SetNewFor<CPDF_Number>("BitsPerComponent", bits); pDict->SetNewFor<CPDF_Name>("Filter", "DCTDecode"); if (!color_trans) { - CPDF_Dictionary* pParms = pDict->SetNewFor<CPDF_Dictionary>("DecodeParms"); + CPDF_Dictionary* pParms = + pDict->SetNewFor<CPDF_Dictionary>(pdfium::stream::kDecodeParms); pParms->SetNewFor<CPDF_Number>("ColorTransform", 0); } m_bIsMask = false; diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp index 82f31dd007..b6658ee5fb 100644 --- a/core/fpdfapi/page/cpdf_streamparser.cpp +++ b/core/fpdfapi/page/cpdf_streamparser.cpp @@ -13,6 +13,7 @@ #include <sstream> #include <utility> +#include "constants/stream_dict_common.h" #include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fpdfapi/page/cpdf_docpagedata.h" #include "core/fpdfapi/parser/cpdf_array.h" @@ -126,12 +127,12 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream( if (pFilter) { if (CPDF_Array* pArray = pFilter->AsArray()) { Decoder = pArray->GetStringAt(0); - CPDF_Array* pParams = pDict->GetArrayFor("DecodeParms"); + CPDF_Array* pParams = pDict->GetArrayFor(pdfium::stream::kDecodeParms); if (pParams) pParam = pParams->GetDictAt(0); } else { Decoder = pFilter->GetString(); - pParam = pDict->GetDictFor("DecodeParms"); + pParam = pDict->GetDictFor(pdfium::stream::kDecodeParms); } } uint32_t width = pDict->GetIntegerFor("Width"); diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp index 4b16021069..4780e87bc0 100644 --- a/core/fpdfapi/parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp @@ -7,6 +7,7 @@ #include <utility> #include <vector> +#include "constants/stream_dict_common.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_boolean.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -790,21 +791,25 @@ TEST(PDFStreamTest, SetData) { stream->InitStream(data.data(), data.size(), pdfium::MakeUnique<CPDF_Dictionary>()); EXPECT_EQ(static_cast<int>(data.size()), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); - stream->GetDict()->SetNewFor<CPDF_String>("Filter", L"SomeFilter"); - stream->GetDict()->SetNewFor<CPDF_String>("DecodeParms", L"SomeParams"); + stream->GetDict()->SetNewFor<CPDF_String>(pdfium::stream::kFilter, + L"SomeFilter"); + stream->GetDict()->SetNewFor<CPDF_String>(pdfium::stream::kDecodeParms, + L"SomeParams"); std::vector<uint8_t> new_data(data.size() * 2); stream->SetData(new_data.data(), new_data.size()); // The "Length" field should be updated for new data size. EXPECT_EQ(static_cast<int>(new_data.size()), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); // The "Filter" and "DecodeParms" fields should not be changed. - EXPECT_EQ(stream->GetDict()->GetUnicodeTextFor("Filter"), L"SomeFilter"); - EXPECT_EQ(stream->GetDict()->GetUnicodeTextFor("DecodeParms"), L"SomeParams"); + EXPECT_EQ(stream->GetDict()->GetUnicodeTextFor(pdfium::stream::kFilter), + L"SomeFilter"); + EXPECT_EQ(stream->GetDict()->GetUnicodeTextFor(pdfium::stream::kDecodeParms), + L"SomeParams"); } TEST(PDFStreamTest, SetDataAndRemoveFilter) { @@ -813,20 +818,22 @@ TEST(PDFStreamTest, SetDataAndRemoveFilter) { stream->InitStream(data.data(), data.size(), pdfium::MakeUnique<CPDF_Dictionary>()); EXPECT_EQ(static_cast<int>(data.size()), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); - stream->GetDict()->SetNewFor<CPDF_String>("Filter", L"SomeFilter"); - stream->GetDict()->SetNewFor<CPDF_String>("DecodeParms", L"SomeParams"); + stream->GetDict()->SetNewFor<CPDF_String>(pdfium::stream::kFilter, + L"SomeFilter"); + stream->GetDict()->SetNewFor<CPDF_String>(pdfium::stream::kDecodeParms, + L"SomeParams"); std::vector<uint8_t> new_data(data.size() * 2); stream->SetDataAndRemoveFilter(new_data.data(), new_data.size()); // The "Length" field should be updated for new data size. EXPECT_EQ(static_cast<int>(new_data.size()), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); // The "Filter" and "DecodeParms" should be removed. - EXPECT_FALSE(stream->GetDict()->KeyExist("Filter")); - EXPECT_FALSE(stream->GetDict()->KeyExist("DecodeParms")); + EXPECT_FALSE(stream->GetDict()->KeyExist(pdfium::stream::kFilter)); + EXPECT_FALSE(stream->GetDict()->KeyExist(pdfium::stream::kDecodeParms)); } TEST(PDFStreamTest, LengthInDictionaryOnCreate) { @@ -838,18 +845,18 @@ TEST(PDFStreamTest, LengthInDictionaryOnCreate) { auto stream = pdfium::MakeUnique<CPDF_Stream>( std::move(data), kBufSize, pdfium::MakeUnique<CPDF_Dictionary>()); EXPECT_EQ(static_cast<int>(kBufSize), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); } // The length field should be corrected on stream create. { std::unique_ptr<uint8_t, FxFreeDeleter> data; data.reset(FX_Alloc(uint8_t, kBufSize)); auto dict = pdfium::MakeUnique<CPDF_Dictionary>(); - dict->SetNewFor<CPDF_Number>("Length", 30000); + dict->SetNewFor<CPDF_Number>(pdfium::stream::kLength, 30000); auto stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), kBufSize, std::move(dict)); EXPECT_EQ(static_cast<int>(kBufSize), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); } } diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp index 5ff748469b..45d2ebb30d 100644 --- a/core/fpdfapi/parser/cpdf_stream.cpp +++ b/core/fpdfapi/parser/cpdf_stream.cpp @@ -8,6 +8,7 @@ #include <utility> +#include "constants/stream_dict_common.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_number.h" #include "core/fpdfapi/parser/cpdf_stream_acc.h" @@ -96,7 +97,7 @@ std::unique_ptr<CPDF_Object> CPDF_Stream::CloneNonCyclic( void CPDF_Stream::SetDataAndRemoveFilter(const uint8_t* pData, uint32_t size) { SetData(pData, size); m_pDict->RemoveFor("Filter"); - m_pDict->RemoveFor("DecodeParms"); + m_pDict->RemoveFor(pdfium::stream::kDecodeParms); } void CPDF_Stream::SetDataAndRemoveFilter(std::ostringstream* stream) { diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp index 90dca2edcb..e879615ddd 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp @@ -13,6 +13,7 @@ #include <utility> #include <vector> +#include "constants/stream_dict_common.h" #include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -344,7 +345,7 @@ bool PDF_DataDecode(const uint8_t* src_buf, return false; CPDF_Object* pParams = - pDict ? pDict->GetDirectObjectFor("DecodeParms") : nullptr; + pDict ? pDict->GetDirectObjectFor(pdfium::stream::kDecodeParms) : nullptr; std::vector<std::pair<ByteString, CPDF_Object*>> DecoderArray; if (CPDF_Array* pDecoders = pDecoder->AsArray()) { |