Add constants for ISO 32000-1:2008 spec, table 28 Create constants/catalog.h with some of the entries from the spec. Use the constants where applicable. Bug: 42270045 Change-Id: Id1edafe9c8defd7ca574dc8787524794379bb9c6 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/149230 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/constants/BUILD.gn b/constants/BUILD.gn index 536e34c..4878c5c 100644 --- a/constants/BUILD.gn +++ b/constants/BUILD.gn
@@ -11,6 +11,7 @@ "annotation_flags.h", "appearance.h", "ascii.h", + "catalog.h", "font_encodings.h", "form_fields.h", "form_flags.h",
diff --git a/constants/catalog.h b/constants/catalog.h new file mode 100644 index 0000000..692dd42 --- /dev/null +++ b/constants/catalog.h
@@ -0,0 +1,23 @@ +// Copyright 2026 The PDFium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONSTANTS_CATALOG_H_ +#define CONSTANTS_CATALOG_H_ + +namespace pdfium::catalog { + +// ISO 32000-1:2008 spec, table 28. +// Entries in the catalog dictionary. +inline constexpr char kVersion[] = "Version"; +inline constexpr char kPages[] = "Pages"; +inline constexpr char kPageLabels[] = "PageLabels"; +inline constexpr char kNames[] = "Names"; +inline constexpr char kDests[] = "Dests"; +inline constexpr char kViewerPreferences[] = "ViewerPreferences"; +inline constexpr char kOutlines[] = "Outlines"; +inline constexpr char kAcroForm[] = "AcroForm"; + +} // namespace pdfium::catalog + +#endif // CONSTANTS_CATALOG_H_
diff --git a/core/fpdfapi/edit/cpdf_pageorganizer.cpp b/core/fpdfapi/edit/cpdf_pageorganizer.cpp index cb63f2b..b5aa063 100644 --- a/core/fpdfapi/edit/cpdf_pageorganizer.cpp +++ b/core/fpdfapi/edit/cpdf_pageorganizer.cpp
@@ -10,6 +10,7 @@ #include <utility> #include <vector> +#include "constants/catalog.h" #include "constants/page_object.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -52,13 +53,15 @@ } RetainPtr<CPDF_Dictionary> pages; - if (RetainPtr<CPDF_Object> current_pages = root->GetMutableObjectFor("Pages"); + if (RetainPtr<CPDF_Object> current_pages = + root->GetMutableObjectFor(pdfium::catalog::kPages); current_pages) { pages = ToDictionary(current_pages->GetMutableDirect()); } if (!pages) { pages = dest()->NewIndirect<CPDF_Dictionary>(); - root->SetNewFor<CPDF_Reference>("Pages", dest(), pages->GetObjNum()); + root->SetNewFor<CPDF_Reference>(pdfium::catalog::kPages, dest(), + pages->GetObjNum()); } if (pages->GetByteStringFor("Type", ByteStringView()).IsEmpty()) { pages->SetNewFor<CPDF_Name>("Type", "Pages");
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index af4fc90..305eb7b 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -10,6 +10,7 @@ #include <memory> #include <utility> +#include "constants/catalog.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_cross_ref_avail.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -269,7 +270,7 @@ } RetainPtr<const CPDF_Reference> pRef = - ToReference(root_->GetObjectFor("Pages")); + ToReference(root_->GetObjectFor(pdfium::catalog::kPages)); if (!pRef) { internal_status_ = InternalStatus::kError; return false; @@ -288,7 +289,7 @@ } RetainPtr<const CPDF_Reference> pRef = - ToReference(pRoot->GetObjectFor("Pages")); + ToReference(pRoot->GetObjectFor(pdfium::catalog::kPages)); if (!pRef) { internal_status_ = InternalStatus::kError; return false; @@ -1052,7 +1053,8 @@ return kFormAvailable; } - RetainPtr<const CPDF_Object> pAcroForm = pRoot->GetObjectFor("AcroForm"); + RetainPtr<const CPDF_Object> pAcroForm = + pRoot->GetObjectFor(pdfium::catalog::kAcroForm); if (!pAcroForm) { return kFormNotExist; }
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index abab315..1ca95b1 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -11,6 +11,7 @@ #include <optional> #include <utility> +#include "constants/catalog.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_linearized_header.h" @@ -351,7 +352,7 @@ RetainPtr<const CPDF_Dictionary> CPDF_Document::GetPagesDict() const { const CPDF_Dictionary* pRoot = GetRoot(); - return pRoot ? pRoot->GetDictFor("Pages") : nullptr; + return pRoot ? pRoot->GetDictFor(pdfium::catalog::kPages) : nullptr; } RetainPtr<CPDF_Dictionary> CPDF_Document::GetMutablePagesDict() { @@ -499,7 +500,8 @@ pPages->SetNewFor<CPDF_Name>("Type", "Pages"); pPages->SetNewFor<CPDF_Number>("Count", 0); pPages->SetNewFor<CPDF_Array>("Kids"); - root_dict_->SetNewFor<CPDF_Reference>("Pages", this, pPages->GetObjNum()); + root_dict_->SetNewFor<CPDF_Reference>(pdfium::catalog::kPages, this, + pPages->GetObjNum()); info_dict_ = NewIndirect<CPDF_Dictionary>(); } @@ -575,7 +577,8 @@ return false; } - RetainPtr<CPDF_Dictionary> pPages = pRoot->GetMutableDictFor("Pages"); + RetainPtr<CPDF_Dictionary> pPages = + pRoot->GetMutableDictFor(pdfium::catalog::kPages); if (!pPages) { return false; }
diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp index 64d7fc1..abed319 100644 --- a/core/fpdfapi/parser/cpdf_document_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp
@@ -7,6 +7,7 @@ #include <memory> #include <utility> +#include "constants/catalog.h" #include "core/fpdfapi/page/test_with_page_module.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_boolean.h" @@ -90,7 +91,7 @@ CreatePageTreeNode(std::move(allPages), this, kNumTestPages); SetRootForTesting(NewIndirect<CPDF_Dictionary>()); - GetMutableRoot()->SetNewFor<CPDF_Reference>("Pages", this, + GetMutableRoot()->SetNewFor<CPDF_Reference>(pdfium::catalog::kPages, this, pagesDict->GetObjNum()); ResizePageListForTesting(kNumTestPages); } @@ -116,7 +117,7 @@ RetainPtr<CPDF_Dictionary> pagesDict = CreatePageTreeNode(std::move(allPages), this, 3); SetRootForTesting(NewIndirect<CPDF_Dictionary>()); - GetMutableRoot()->SetNewFor<CPDF_Reference>("Pages", this, + GetMutableRoot()->SetNewFor<CPDF_Reference>(pdfium::catalog::kPages, this, pagesDict->GetObjNum()); ResizePageListForTesting(3); } @@ -141,7 +142,7 @@ pagesDict->SetNewFor<CPDF_Number>("Count", 3); ResizePageListForTesting(10); SetRootForTesting(NewIndirect<CPDF_Dictionary>()); - GetMutableRoot()->SetNewFor<CPDF_Reference>("Pages", this, + GetMutableRoot()->SetNewFor<CPDF_Reference>(pdfium::catalog::kPages, this, pagesDict->GetObjNum()); } };
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp index db8be16..c35c27e 100644 --- a/core/fpdfdoc/cpdf_annotlist.cpp +++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -12,6 +12,7 @@ #include "constants/annotation_common.h" #include "constants/annotation_flags.h" +#include "constants/catalog.h" #include "constants/form_fields.h" #include "constants/form_flags.h" #include "core/fpdfapi/page/cpdf_occontext.h" @@ -186,7 +187,8 @@ } const CPDF_Dictionary* pRoot = document_->GetRoot(); - RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm"); + RetainPtr<const CPDF_Dictionary> pAcroForm = + pRoot->GetDictFor(pdfium::catalog::kAcroForm); bool bRegenerateAP = pAcroForm && pAcroForm->GetBooleanFor("NeedAppearances", false); for (size_t i = 0; i < pAnnots->size(); ++i) {
diff --git a/core/fpdfdoc/cpdf_bafontmap.cpp b/core/fpdfdoc/cpdf_bafontmap.cpp index f330fda..7295ceb 100644 --- a/core/fpdfdoc/cpdf_bafontmap.cpp +++ b/core/fpdfdoc/cpdf_bafontmap.cpp
@@ -10,6 +10,7 @@ #include <utility> #include "constants/annotation_common.h" +#include "constants/catalog.h" #include "core/fpdfapi/font/cpdf_font.h" #include "core/fpdfapi/font/cpdf_fontencoding.h" #include "core/fpdfapi/page/cpdf_docpagedata.h" @@ -196,7 +197,7 @@ } RetainPtr<const CPDF_Dictionary> pAcroFormDict = - pRootDict->GetDictFor("AcroForm"); + pRootDict->GetDictFor(pdfium::catalog::kAcroForm); if (!pAcroFormDict) { return nullptr; } @@ -254,7 +255,7 @@ if (bWidget) { RetainPtr<CPDF_Dictionary> pRootDict = document_->GetMutableRoot(); if (pRootDict) { - pAcroFormDict = pRootDict->GetMutableDictFor("AcroForm"); + pAcroFormDict = pRootDict->GetMutableDictFor(pdfium::catalog::kAcroForm); } }
diff --git a/core/fpdfdoc/cpdf_bafontmap_unittest.cpp b/core/fpdfdoc/cpdf_bafontmap_unittest.cpp index db85b9f..6204d69 100644 --- a/core/fpdfdoc/cpdf_bafontmap_unittest.cpp +++ b/core/fpdfdoc/cpdf_bafontmap_unittest.cpp
@@ -8,6 +8,7 @@ #include "build/build_config.h" #include "constants/annotation_common.h" +#include "constants/catalog.h" #include "core/fpdfapi/font/cpdf_font.h" #include "core/fpdfapi/page/test_with_page_module.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -39,7 +40,8 @@ TEST_F(BAFontMapTest, Bug853238) { CPDF_TestDocument doc; auto root_dict = pdfium::MakeRetain<CPDF_Dictionary>(); - auto acroform_dict = root_dict->SetNewFor<CPDF_Dictionary>("AcroForm"); + auto acroform_dict = + root_dict->SetNewFor<CPDF_Dictionary>(pdfium::catalog::kAcroForm); auto annot_dr_dict = acroform_dict->SetNewFor<CPDF_Dictionary>("DR"); auto annot_font_dict = annot_dr_dict->SetNewFor<CPDF_Dictionary>("Font"); auto annot_font_f1_dict = annot_font_dict->SetNewFor<CPDF_Dictionary>("F1");
diff --git a/core/fpdfdoc/cpdf_bookmarktree.cpp b/core/fpdfdoc/cpdf_bookmarktree.cpp index 158da88..ae34e63 100644 --- a/core/fpdfdoc/cpdf_bookmarktree.cpp +++ b/core/fpdfdoc/cpdf_bookmarktree.cpp
@@ -8,6 +8,7 @@ #include <utility> +#include "constants/catalog.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" @@ -28,7 +29,8 @@ return CPDF_Bookmark(); } - RetainPtr<const CPDF_Dictionary> outlines = root->GetDictFor("Outlines"); + RetainPtr<const CPDF_Dictionary> outlines = + root->GetDictFor(pdfium::catalog::kOutlines); return outlines ? CPDF_Bookmark(outlines->GetDictFor("First")) : CPDF_Bookmark(); }
diff --git a/core/fpdfdoc/cpdf_generateap.cpp b/core/fpdfdoc/cpdf_generateap.cpp index 4a9d729..d39980e 100644 --- a/core/fpdfdoc/cpdf_generateap.cpp +++ b/core/fpdfdoc/cpdf_generateap.cpp
@@ -12,6 +12,7 @@ #include "constants/annotation_common.h" #include "constants/appearance.h" +#include "constants/catalog.h" #include "constants/font_encodings.h" #include "constants/form_fields.h" #include "core/fpdfapi/edit/cpdf_contentstream_write_utils.h" @@ -1035,7 +1036,7 @@ } RetainPtr<CPDF_Dictionary> form_dict = - root_dict->GetMutableDictFor("AcroForm"); + root_dict->GetMutableDictFor(pdfium::catalog::kAcroForm); if (!form_dict) { form_dict = CPDF_InteractiveForm::InitAcroFormDict(doc); CHECK(form_dict); @@ -1438,7 +1439,7 @@ } RetainPtr<CPDF_Dictionary> form_dict = - root_dict->GetMutableDictFor("AcroForm"); + root_dict->GetMutableDictFor(pdfium::catalog::kAcroForm); if (!form_dict) { return; } @@ -1617,7 +1618,7 @@ } RetainPtr<CPDF_Dictionary> acroform_dict = - root_dict->GetMutableDictFor("AcroForm"); + root_dict->GetMutableDictFor(pdfium::catalog::kAcroForm); if (!acroform_dict) { acroform_dict = CPDF_InteractiveForm::InitAcroFormDict(doc); CHECK(acroform_dict);
diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp index 24bf93a..4e0bb21 100644 --- a/core/fpdfdoc/cpdf_interactiveform.cpp +++ b/core/fpdfdoc/cpdf_interactiveform.cpp
@@ -12,6 +12,7 @@ #include <vector> #include "build/build_config.h" +#include "constants/catalog.h" #include "constants/form_fields.h" #include "constants/form_flags.h" #include "constants/stream_dict_common.h" @@ -303,8 +304,8 @@ RetainPtr<CPDF_Dictionary> InitDict(CPDF_Document* document) { auto form_dict = document->NewIndirect<CPDF_Dictionary>(); - document->GetMutableRoot()->SetNewFor<CPDF_Reference>("AcroForm", document, - form_dict->GetObjNum()); + document->GetMutableRoot()->SetNewFor<CPDF_Reference>( + pdfium::catalog::kAcroForm, document, form_dict->GetObjNum()); ByteString base_name; FX_Charset charset = GetNativeCharSet(); @@ -593,7 +594,7 @@ return; } - form_dict_ = pRoot->GetMutableDictFor("AcroForm"); + form_dict_ = pRoot->GetMutableDictFor(pdfium::catalog::kAcroForm); if (!form_dict_) { return; } @@ -630,7 +631,7 @@ DCHECK(name_tag); RetainPtr<CPDF_Dictionary> form_dict = - document->GetMutableRoot()->GetMutableDictFor("AcroForm"); + document->GetMutableRoot()->GetMutableDictFor(pdfium::catalog::kAcroForm); if (!form_dict) { form_dict = InitDict(document); }
diff --git a/core/fpdfdoc/cpdf_interactiveform_unittest.cpp b/core/fpdfdoc/cpdf_interactiveform_unittest.cpp index 9866687..a99e8d5 100644 --- a/core/fpdfdoc/cpdf_interactiveform_unittest.cpp +++ b/core/fpdfdoc/cpdf_interactiveform_unittest.cpp
@@ -6,6 +6,7 @@ #include <memory> +#include "constants/catalog.h" #include "core/fpdfapi/page/test_with_page_module.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -33,7 +34,8 @@ auto bad_stream = doc->NewIndirect<CPDF_Stream>(doc->New<CPDF_Dictionary>()); bad_stream->SetData(ByteStringView("bad_stream").unsigned_span()); - auto acroform_dict = root->SetNewFor<CPDF_Dictionary>("AcroForm"); + auto acroform_dict = + root->SetNewFor<CPDF_Dictionary>(pdfium::catalog::kAcroForm); auto fields_array = acroform_dict->SetNewFor<CPDF_Array>("Fields"); auto good_string_field_dict = fields_array->AppendNew<CPDF_Dictionary>();
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp index 28ac0de..13cc7bd 100644 --- a/core/fpdfdoc/cpdf_nametree.cpp +++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -9,6 +9,7 @@ #include <utility> #include <vector> +#include "constants/catalog.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" @@ -453,7 +454,8 @@ RetainPtr<const CPDF_Array> LookupOldStyleNamedDest(CPDF_Document* doc, const ByteString& name) { - RetainPtr<const CPDF_Dictionary> pDests = doc->GetRoot()->GetDictFor("Dests"); + RetainPtr<const CPDF_Dictionary> pDests = + doc->GetRoot()->GetDictFor(pdfium::catalog::kDests); if (!pDests) { return nullptr; } @@ -478,7 +480,8 @@ return nullptr; } - RetainPtr<CPDF_Dictionary> pNames = pRoot->GetMutableDictFor("Names"); + RetainPtr<CPDF_Dictionary> pNames = + pRoot->GetMutableDictFor(pdfium::catalog::kNames); if (!pNames) { return nullptr; } @@ -502,10 +505,12 @@ } // Retrieve the document's Names dictionary; create it if missing. - RetainPtr<CPDF_Dictionary> pNames = pRoot->GetMutableDictFor("Names"); + RetainPtr<CPDF_Dictionary> pNames = + pRoot->GetMutableDictFor(pdfium::catalog::kNames); if (!pNames) { pNames = doc->NewIndirect<CPDF_Dictionary>(); - pRoot->SetNewFor<CPDF_Reference>("Names", doc, pNames->GetObjNum()); + pRoot->SetNewFor<CPDF_Reference>(pdfium::catalog::kNames, doc, + pNames->GetObjNum()); } // Create the |category| dictionary if missing. @@ -552,7 +557,8 @@ NodeToInsert node_to_insert; // Handle the corner case where the root node is empty. i.e. No kids and no // names. In which case, just insert into it and skip all the searches. - RetainPtr<CPDF_Array> pNames = root_->GetMutableArrayFor("Names"); + RetainPtr<CPDF_Array> pNames = + root_->GetMutableArrayFor(pdfium::catalog::kNames); if (pNames && pNames->IsEmpty() && !root_->GetArrayFor("Kids")) { node_to_insert.names = pNames; }
diff --git a/core/fpdfdoc/cpdf_nametree_unittest.cpp b/core/fpdfdoc/cpdf_nametree_unittest.cpp index 4f12ca1..9801585 100644 --- a/core/fpdfdoc/cpdf_nametree_unittest.cpp +++ b/core/fpdfdoc/cpdf_nametree_unittest.cpp
@@ -3,6 +3,8 @@ // found in the LICENSE file. #include "core/fpdfdoc/cpdf_nametree.h" + +#include "constants/catalog.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_number.h" @@ -106,7 +108,7 @@ TEST(CPDFNameTreeTest, GetUnicodeNameWithBOM) { // Set up the root dictionary with a Names array. auto pRootDict = pdfium::MakeRetain<CPDF_Dictionary>(); - auto pNames = pRootDict->SetNewFor<CPDF_Array>("Names"); + auto pNames = pRootDict->SetNewFor<CPDF_Array>(pdfium::catalog::kNames); // Add the key "1" (with BOM) and value 100 into the array. static constexpr uint8_t kData[] = {0xFE, 0xFF, 0x00, 0x31}; @@ -179,7 +181,7 @@ TEST(CPDFNameTreeTest, AddIntoNames) { // Set up a name tree with a single Names array. auto pRootDict = pdfium::MakeRetain<CPDF_Dictionary>(); - auto pNames = pRootDict->SetNewFor<CPDF_Array>("Names"); + auto pNames = pRootDict->SetNewFor<CPDF_Array>(pdfium::catalog::kNames); AddNameKeyValue(pNames.Get(), "2.txt", 222); AddNameKeyValue(pNames.Get(), "7.txt", 777); @@ -213,7 +215,7 @@ TEST(CPDFNameTreeTest, AddIntoEmptyNames) { // Set up a name tree with an empty Names array. auto pRootDict = pdfium::MakeRetain<CPDF_Dictionary>(); - auto pNames = pRootDict->SetNewFor<CPDF_Array>("Names"); + auto pNames = pRootDict->SetNewFor<CPDF_Array>(pdfium::catalog::kNames); std::unique_ptr<CPDF_NameTree> name_tree = CPDF_NameTree::CreateForTesting(pRootDict.Get());
diff --git a/core/fpdfdoc/cpdf_pagelabel.cpp b/core/fpdfdoc/cpdf_pagelabel.cpp index 74adad1..b844545 100644 --- a/core/fpdfdoc/cpdf_pagelabel.cpp +++ b/core/fpdfdoc/cpdf_pagelabel.cpp
@@ -10,6 +10,7 @@ #include <array> #include <utility> +#include "constants/catalog.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" @@ -107,7 +108,7 @@ } RetainPtr<const CPDF_Dictionary> labels_dict = - root_dict->GetDictFor("PageLabels"); + root_dict->GetDictFor(pdfium::catalog::kPageLabels); if (!labels_dict) { return std::nullopt; }
diff --git a/core/fpdfdoc/cpdf_pagelabel_unittest.cpp b/core/fpdfdoc/cpdf_pagelabel_unittest.cpp index a31414a..9edaf8d 100644 --- a/core/fpdfdoc/cpdf_pagelabel_unittest.cpp +++ b/core/fpdfdoc/cpdf_pagelabel_unittest.cpp
@@ -8,6 +8,7 @@ #include <optional> #include <utility> +#include "constants/catalog.h" #include "core/fpdfapi/page/test_with_page_module.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -137,8 +138,9 @@ TestWithPageModule::SetUp(); auto root_dict = pdfium::MakeRetain<CPDF_Dictionary>(); - root_dict->SetNewFor<CPDF_Dictionary>("Pages"); - auto page_labels_dict = root_dict->SetNewFor<CPDF_Dictionary>("PageLabels"); + root_dict->SetNewFor<CPDF_Dictionary>(pdfium::catalog::kPages); + auto page_labels_dict = + root_dict->SetNewFor<CPDF_Dictionary>(pdfium::catalog::kPageLabels); FillPageLabelsTreeDict(page_labels_dict.Get()); doc_ = std::make_unique<CPDF_TestDocument>();
diff --git a/core/fpdfdoc/cpdf_viewerpreferences.cpp b/core/fpdfdoc/cpdf_viewerpreferences.cpp index 4915373..8e2f273 100644 --- a/core/fpdfdoc/cpdf_viewerpreferences.cpp +++ b/core/fpdfdoc/cpdf_viewerpreferences.cpp
@@ -6,6 +6,7 @@ #include "core/fpdfdoc/cpdf_viewerpreferences.h" +#include "constants/catalog.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" @@ -59,5 +60,5 @@ RetainPtr<const CPDF_Dictionary> CPDF_ViewerPreferences::GetViewerPreferences() const { const CPDF_Dictionary* dict = doc_->GetRoot(); - return dict ? dict->GetDictFor("ViewerPreferences") : nullptr; + return dict ? dict->GetDictFor(pdfium::catalog::kViewerPreferences) : nullptr; }
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp index 4734956..208c93d 100644 --- a/fpdfsdk/cpdfsdk_helpers.cpp +++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -9,6 +9,7 @@ #include <utility> #include "build/build_config.h" +#include "constants/catalog.h" #include "constants/form_fields.h" #include "constants/stream_dict_common.h" #include "core/fpdfapi/page/cpdf_page.h" @@ -61,7 +62,8 @@ return false; } - RetainPtr<const CPDF_Dictionary> form = root->GetDictFor("AcroForm"); + RetainPtr<const CPDF_Dictionary> form = + root->GetDictFor(pdfium::catalog::kAcroForm); return form && form->GetArrayFor("XFA"); } @@ -424,7 +426,8 @@ RaiseUnsupportedError(FPDF_UNSP_DOC_PORTABLECOLLECTION); } - RetainPtr<const CPDF_Dictionary> pNameDict = pRootDict->GetDictFor("Names"); + RetainPtr<const CPDF_Dictionary> pNameDict = + pRootDict->GetDictFor(pdfium::catalog::kNames); if (pNameDict) { if (pNameDict->KeyExist("EmbeddedFiles")) { RaiseUnsupportedError(FPDF_UNSP_DOC_ATTACHMENT);
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp index 956c24c..d2c4d28 100644 --- a/fpdfsdk/fpdf_annot.cpp +++ b/fpdfsdk/fpdf_annot.cpp
@@ -11,6 +11,7 @@ #include <vector> #include "constants/annotation_common.h" +#include "constants/catalog.h" #include "core/fpdfapi/edit/cpdf_pagecontentgenerator.h" #include "core/fpdfapi/page/cpdf_annotcontext.h" #include "core/fpdfapi/page/cpdf_form.h" @@ -367,7 +368,7 @@ CPDF_Document* doc = form ? form->GetInteractiveForm()->document() : nullptr; const CPDF_Dictionary* root_dict = doc ? doc->GetRoot() : nullptr; RetainPtr<const CPDF_Dictionary> acroform_dict = - root_dict ? root_dict->GetDictFor("AcroForm") : nullptr; + root_dict ? root_dict->GetDictFor(pdfium::catalog::kAcroForm) : nullptr; CPDF_DefaultAppearance default_appearance(annot_dict, acroform_dict); return default_appearance.GetColorARGB(); }
diff --git a/fpdfsdk/fpdf_doc_unittest.cpp b/fpdfsdk/fpdf_doc_unittest.cpp index 96ae7cc..250af62 100644 --- a/fpdfsdk/fpdf_doc_unittest.cpp +++ b/fpdfsdk/fpdf_doc_unittest.cpp
@@ -7,6 +7,7 @@ #include <memory> #include <vector> +#include "constants/catalog.h" #include "core/fpdfapi/page/test_with_page_module.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -73,7 +74,7 @@ } { // Empty bookmark tree. - root_obj_->SetNewFor<CPDF_Dictionary>("Outlines"); + root_obj_->SetNewFor<CPDF_Dictionary>(pdfium::catalog::kOutlines); ScopedFPDFWideString title = GetFPDFWideString(L""); EXPECT_FALSE(FPDFBookmark_Find(doc_.get(), title.get())); @@ -103,8 +104,8 @@ bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", indirect_objs_, bookmarks[2].num); - root_obj_->SetNewFor<CPDF_Reference>("Outlines", indirect_objs_, - bookmarks[0].num); + root_obj_->SetNewFor<CPDF_Reference>(pdfium::catalog::kOutlines, + indirect_objs_, bookmarks[0].num); // Title with no match. ScopedFPDFWideString title = GetFPDFWideString(L"Chapter 3"); @@ -147,8 +148,8 @@ bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", indirect_objs_, bookmarks[2].num); - root_obj_->SetNewFor<CPDF_Reference>("Outlines", indirect_objs_, - bookmarks[0].num); + root_obj_->SetNewFor<CPDF_Reference>(pdfium::catalog::kOutlines, + indirect_objs_, bookmarks[0].num); // Title with no match. ScopedFPDFWideString title = GetFPDFWideString(L"Chapter 3"); @@ -188,8 +189,8 @@ bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", indirect_objs_, bookmarks[2].num); - root_obj_->SetNewFor<CPDF_Reference>("Outlines", indirect_objs_, - bookmarks[0].num); + root_obj_->SetNewFor<CPDF_Reference>(pdfium::catalog::kOutlines, + indirect_objs_, bookmarks[0].num); // Title with no match. ScopedFPDFWideString title = GetFPDFWideString(L"Chapter 8");
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp index 91ec4b1..c578013 100644 --- a/fpdfsdk/fpdf_ppo.cpp +++ b/fpdfsdk/fpdf_ppo.cpp
@@ -11,6 +11,7 @@ #include <utility> #include <vector> +#include "constants/catalog.h" #include "core/fpdfapi/edit/cpdf_npagetooneexporter.h" #include "core/fpdfapi/edit/cpdf_pageexporter.h" #include "core/fpdfapi/page/cpdf_form.h" @@ -256,7 +257,7 @@ } RetainPtr<const CPDF_Dictionary> pref_dict = - csrc_doc->GetRoot()->GetDictFor("ViewerPreferences"); + csrc_doc->GetRoot()->GetDictFor(pdfium::catalog::kViewerPreferences); if (!pref_dict) { return false; } @@ -274,6 +275,7 @@ } } - dest_dict->SetFor("ViewerPreferences", std::move(cloned_dict)); + dest_dict->SetFor(pdfium::catalog::kViewerPreferences, + std::move(cloned_dict)); return true; }
diff --git a/fpdfsdk/fpdf_ppo_embeddertest.cpp b/fpdfsdk/fpdf_ppo_embeddertest.cpp index 6b385c0..fc32b27 100644 --- a/fpdfsdk/fpdf_ppo_embeddertest.cpp +++ b/fpdfsdk/fpdf_ppo_embeddertest.cpp
@@ -2,12 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "public/fpdf_ppo.h" + #include <array> #include <iterator> #include <memory> #include <string> #include <vector> +#include "constants/catalog.h" #include "core/fpdfapi/page/cpdf_form.h" #include "core/fpdfapi/page/cpdf_formobject.h" #include "core/fpdfapi/parser/cpdf_array.h" @@ -21,7 +24,6 @@ #include "fpdfsdk/cpdfsdk_helpers.h" #include "public/cpp/fpdf_scopers.h" #include "public/fpdf_edit.h" -#include "public/fpdf_ppo.h" #include "public/fpdf_save.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" @@ -397,7 +399,8 @@ const CPDF_Document* output_doc_impl = CPDFDocumentFromFPDFDocument(output_doc.get()); RetainPtr<const CPDF_Dictionary> prefs = - output_doc_impl->GetRoot()->GetDictFor("ViewerPreferences"); + output_doc_impl->GetRoot()->GetDictFor( + pdfium::catalog::kViewerPreferences); ASSERT_TRUE(prefs); EXPECT_EQ(6u, prefs->size());
diff --git a/fpdfsdk/fpdf_save.cpp b/fpdfsdk/fpdf_save.cpp index 3cf5078..8aa49ee 100644 --- a/fpdfsdk/fpdf_save.cpp +++ b/fpdfsdk/fpdf_save.cpp
@@ -13,6 +13,7 @@ #include <vector> #include "build/build_config.h" +#include "constants/catalog.h" #include "core/fpdfapi/edit/cpdf_creator.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -67,7 +68,8 @@ return false; } - RetainPtr<CPDF_Dictionary> acro_form = root->GetMutableDictFor("AcroForm"); + RetainPtr<CPDF_Dictionary> acro_form = + root->GetMutableDictFor(pdfium::catalog::kAcroForm); if (!acro_form) { return false; }
diff --git a/fpdfsdk/fpdf_signature.cpp b/fpdfsdk/fpdf_signature.cpp index 66b5c38..915e3a5 100644 --- a/fpdfsdk/fpdf_signature.cpp +++ b/fpdfsdk/fpdf_signature.cpp
@@ -7,6 +7,7 @@ #include <utility> #include <vector> +#include "constants/catalog.h" #include "constants/form_fields.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -28,7 +29,8 @@ return signatures; } - RetainPtr<const CPDF_Dictionary> acro_form = root->GetDictFor("AcroForm"); + RetainPtr<const CPDF_Dictionary> acro_form = + root->GetDictFor(pdfium::catalog::kAcroForm); if (!acro_form) { return signatures; }
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index 2b2f253..77f8d0e 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp
@@ -12,6 +12,7 @@ #include <vector> #include "build/build_config.h" +#include "constants/catalog.h" #include "core/fpdfapi/page/cpdf_docpagedata.h" #include "core/fpdfapi/page/cpdf_occontext.h" #include "core/fpdfapi/page/cpdf_page.h" @@ -116,7 +117,8 @@ return nullptr; } - RetainPtr<const CPDF_Dictionary> acro_form = root->GetDictFor("AcroForm"); + RetainPtr<const CPDF_Dictionary> acro_form = + root->GetDictFor(pdfium::catalog::kAcroForm); return acro_form ? acro_form->GetObjectFor("XFA") : nullptr; } @@ -300,7 +302,8 @@ return FORMTYPE_NONE; } - RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm"); + RetainPtr<const CPDF_Dictionary> pAcroForm = + pRoot->GetDictFor(pdfium::catalog::kAcroForm); if (!pAcroForm) { return FORMTYPE_NONE; } @@ -383,7 +386,7 @@ const CPDF_Dictionary* root_dict = document->GetRoot(); if (root_dict) { - ByteString version = root_dict->GetNameFor("Version"); + ByteString version = root_dict->GetNameFor(pdfium::catalog::kVersion); if (!version.IsEmpty()) { // Check for valid PDF version format "X.Y" const bool has_valid_length = version.GetLength() == 3; @@ -1240,7 +1243,8 @@ auto name_tree = CPDF_NameTree::Create(doc, "Dests"); FX_SAFE_UINT32 count = name_tree ? name_tree->GetCount() : 0; - RetainPtr<const CPDF_Dictionary> pOldStyleDests = pRoot->GetDictFor("Dests"); + RetainPtr<const CPDF_Dictionary> pOldStyleDests = + pRoot->GetDictFor(pdfium::catalog::kDests); if (pOldStyleDests) { count += pOldStyleDests->size(); } @@ -1367,7 +1371,8 @@ if (static_cast<size_t>(index) >= name_tree_count) { // If |index| is out of bounds, then try to retrieve the Nth old style named // destination. Where N is 0-indexed, with N = index - name_tree_count. - RetainPtr<const CPDF_Dictionary> pDest = pRoot->GetDictFor("Dests"); + RetainPtr<const CPDF_Dictionary> pDest = + pRoot->GetDictFor(pdfium::catalog::kDests); if (!pDest) { return nullptr; }
diff --git a/fpdfsdk/fpdfxfa/BUILD.gn b/fpdfsdk/fpdfxfa/BUILD.gn index 4374f59..64b18aa 100644 --- a/fpdfsdk/fpdfxfa/BUILD.gn +++ b/fpdfsdk/fpdfxfa/BUILD.gn
@@ -24,6 +24,7 @@ ] deps = [ "../../:pdfium_public_headers", + "../../constants", "../../core/fpdfapi/page", "../../core/fpdfapi/parser", "../../core/fpdfapi/render",
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index 5faafe5..e9ce2bb 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -11,6 +11,7 @@ #include <algorithm> #include <utility> +#include "constants/catalog.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" @@ -64,7 +65,8 @@ return nullptr; } - RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm"); + RetainPtr<const CPDF_Dictionary> pAcroForm = + pRoot->GetDictFor(pdfium::catalog::kAcroForm); if (!pAcroForm) { return nullptr; }
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 09b7a87..15c3e4a 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -8,6 +8,7 @@ #include <utility> +#include "constants/catalog.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_stream.h" @@ -522,7 +523,8 @@ return; } - RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm"); + RetainPtr<const CPDF_Dictionary> pAcroForm = + pRoot->GetDictFor(pdfium::catalog::kAcroForm); if (!pAcroForm) { return; }
diff --git a/xfa/fgas/font/BUILD.gn b/xfa/fgas/font/BUILD.gn index 69946df..f4f8ded 100644 --- a/xfa/fgas/font/BUILD.gn +++ b/xfa/fgas/font/BUILD.gn
@@ -28,6 +28,7 @@ "../../:xfa_warnings", ] deps = [ + "../../../constants", "../../../core/fpdfapi/font", "../../../core/fpdfapi/page", "../../../core/fpdfapi/parser",
diff --git a/xfa/fgas/font/cfgas_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp index e957f41..1808376 100644 --- a/xfa/fgas/font/cfgas_pdffontmgr.cpp +++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp
@@ -11,6 +11,7 @@ #include <iterator> #include <utility> +#include "constants/catalog.h" #include "core/fpdfapi/font/cpdf_font.h" #include "core/fpdfapi/page/cpdf_docpagedata.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -143,7 +144,7 @@ bool bItalic, bool bStrictMatch) { RetainPtr<const CPDF_Dictionary> font_set_dict = - doc_->GetRoot()->GetDictFor("AcroForm")->GetDictFor("DR"); + doc_->GetRoot()->GetDictFor(pdfium::catalog::kAcroForm)->GetDictFor("DR"); if (!font_set_dict) { return nullptr; }