John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_doc.h" |
| 8 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 9 | #include <memory> |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 10 | #include <set> |
Tom Sepez | d524d32 | 2019-05-28 21:52:27 +0000 | [diff] [blame] | 11 | #include <utility> |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 12 | |
Zhouhan Chen | 16760b5 | 2020-08-12 05:14:00 +0000 | [diff] [blame] | 13 | #include "constants/form_fields.h" |
Virender Singh | ceea607 | 2020-06-18 20:31:25 +0000 | [diff] [blame] | 14 | #include "core/fpdfapi/page/cpdf_annotcontext.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 15 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 16 | #include "core/fpdfapi/parser/cpdf_array.h" |
Lei Zhang | 8153561 | 2018-10-09 21:15:17 +0000 | [diff] [blame] | 17 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 18 | #include "core/fpdfapi/parser/cpdf_document.h" |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 19 | #include "core/fpdfapi/parser/cpdf_number.h" |
Daniel Hosseinian | f2e3601 | 2020-04-14 02:40:57 +0000 | [diff] [blame] | 20 | #include "core/fpdfapi/parser/cpdf_string.h" |
| 21 | #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
Zhouhan Chen | 16760b5 | 2020-08-12 05:14:00 +0000 | [diff] [blame] | 22 | #include "core/fpdfdoc/cpdf_aaction.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 23 | #include "core/fpdfdoc/cpdf_bookmark.h" |
| 24 | #include "core/fpdfdoc/cpdf_bookmarktree.h" |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 25 | #include "core/fpdfdoc/cpdf_dest.h" |
Tom Sepez | d524d32 | 2019-05-28 21:52:27 +0000 | [diff] [blame] | 26 | #include "core/fpdfdoc/cpdf_linklist.h" |
thestig | 733e068 | 2016-11-23 05:52:39 -0800 | [diff] [blame] | 27 | #include "core/fpdfdoc/cpdf_pagelabel.h" |
Dan Sinclair | 00d47a6 | 2018-03-28 18:39:04 +0000 | [diff] [blame] | 28 | #include "fpdfsdk/cpdfsdk_helpers.h" |
Zhouhan Chen | 16760b5 | 2020-08-12 05:14:00 +0000 | [diff] [blame] | 29 | #include "public/fpdf_formfill.h" |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 30 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 31 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 32 | namespace { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 33 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 34 | CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, |
| 35 | CPDF_Bookmark bookmark, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 36 | const WideString& title, |
Lei Zhang | 5cee3f2 | 2018-05-25 21:48:49 +0000 | [diff] [blame] | 37 | std::set<const CPDF_Dictionary*>* visited) { |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 38 | // Return if already checked to avoid circular calling. |
Lei Zhang | f245ae6 | 2020-05-15 21:49:46 +0000 | [diff] [blame] | 39 | if (pdfium::Contains(*visited, bookmark.GetDict())) |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 40 | return CPDF_Bookmark(); |
| 41 | visited->insert(bookmark.GetDict()); |
| 42 | |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 43 | if (bookmark.GetDict() && |
| 44 | bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 45 | // First check this item. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | return bookmark; |
| 47 | } |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 48 | |
| 49 | // Go into children items. |
Tom Sepez | 2292360 | 2019-07-15 21:33:35 +0000 | [diff] [blame] | 50 | CPDF_Bookmark child = tree.GetFirstChild(&bookmark); |
Lei Zhang | f245ae6 | 2020-05-15 21:49:46 +0000 | [diff] [blame] | 51 | while (child.GetDict() && !pdfium::Contains(*visited, child.GetDict())) { |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 52 | // Check this item and its children. |
| 53 | CPDF_Bookmark found = FindBookmark(tree, child, title, visited); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 54 | if (found.GetDict()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | return found; |
Tom Sepez | 2292360 | 2019-07-15 21:33:35 +0000 | [diff] [blame] | 56 | child = tree.GetNextSibling(&child); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | } |
| 58 | return CPDF_Bookmark(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 61 | CPDF_LinkList* GetLinkList(CPDF_Page* page) { |
Lei Zhang | 8f63763 | 2018-05-07 23:36:26 +0000 | [diff] [blame] | 62 | CPDF_Document* pDoc = page->GetDocument(); |
Tom Sepez | d524d32 | 2019-05-28 21:52:27 +0000 | [diff] [blame] | 63 | auto* pList = static_cast<CPDF_LinkList*>(pDoc->GetLinksContext()); |
| 64 | if (pList) |
| 65 | return pList; |
| 66 | |
Tom Sepez | 5af9543 | 2020-05-15 22:55:16 +0000 | [diff] [blame] | 67 | auto pNewList = std::make_unique<CPDF_LinkList>(); |
Tom Sepez | d524d32 | 2019-05-28 21:52:27 +0000 | [diff] [blame] | 68 | pList = pNewList.get(); |
| 69 | pDoc->SetLinksContext(std::move(pNewList)); |
| 70 | return pList; |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 73 | } // namespace |
Lei Zhang | aaed698 | 2018-03-22 18:39:05 +0000 | [diff] [blame] | 74 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 75 | FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 76 | FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 77 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 78 | if (!pDoc) |
| 79 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | CPDF_BookmarkTree tree(pDoc); |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 81 | CPDF_Bookmark cBookmark(CPDFDictionaryFromFPDFBookmark(bookmark)); |
| 82 | return FPDFBookmarkFromCPDFDictionary( |
Tom Sepez | 2292360 | 2019-07-15 21:33:35 +0000 | [diff] [blame] | 83 | tree.GetFirstChild(&cBookmark).GetDict()); |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 86 | FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 87 | FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 88 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 89 | if (!pDoc) |
| 90 | return nullptr; |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 91 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 92 | if (!bookmark) |
Tom Sepez | 8c62883 | 2018-10-09 21:02:15 +0000 | [diff] [blame] | 93 | return nullptr; |
| 94 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 95 | CPDF_BookmarkTree tree(pDoc); |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 96 | CPDF_Bookmark cBookmark(CPDFDictionaryFromFPDFBookmark(bookmark)); |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 97 | return FPDFBookmarkFromCPDFDictionary( |
Tom Sepez | 2292360 | 2019-07-15 21:33:35 +0000 | [diff] [blame] | 98 | tree.GetNextSibling(&cBookmark).GetDict()); |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 101 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 102 | FPDFBookmark_GetTitle(FPDF_BOOKMARK bookmark, |
| 103 | void* buffer, |
| 104 | unsigned long buflen) { |
| 105 | if (!bookmark) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | return 0; |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 107 | CPDF_Bookmark cBookmark(CPDFDictionaryFromFPDFBookmark(bookmark)); |
| 108 | WideString title = cBookmark.GetTitle(); |
thestig | 733e068 | 2016-11-23 05:52:39 -0800 | [diff] [blame] | 109 | return Utf16EncodeMaybeCopyAndReturnLength(title, buffer, buflen); |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 112 | FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV |
| 113 | FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 114 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 115 | if (!pDoc) |
| 116 | return nullptr; |
Tom Sepez | 8c62883 | 2018-10-09 21:02:15 +0000 | [diff] [blame] | 117 | |
Lei Zhang | b46a763 | 2019-01-09 02:56:16 +0000 | [diff] [blame] | 118 | WideString encodedTitle = WideStringFromFPDFWideString(title); |
| 119 | if (encodedTitle.IsEmpty()) |
Tom Sepez | 8c62883 | 2018-10-09 21:02:15 +0000 | [diff] [blame] | 120 | return nullptr; |
| 121 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 122 | CPDF_BookmarkTree tree(pDoc); |
Lei Zhang | 5cee3f2 | 2018-05-25 21:48:49 +0000 | [diff] [blame] | 123 | std::set<const CPDF_Dictionary*> visited; |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 124 | return FPDFBookmarkFromCPDFDictionary( |
| 125 | FindBookmark(tree, CPDF_Bookmark(), encodedTitle, &visited).GetDict()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 128 | FPDF_EXPORT FPDF_DEST FPDF_CALLCONV |
| 129 | FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 130 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 131 | if (!pDoc) |
| 132 | return nullptr; |
Tom Sepez | 8c62883 | 2018-10-09 21:02:15 +0000 | [diff] [blame] | 133 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 134 | if (!bookmark) |
Tom Sepez | 8c62883 | 2018-10-09 21:02:15 +0000 | [diff] [blame] | 135 | return nullptr; |
| 136 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 137 | CPDF_Bookmark cBookmark(CPDFDictionaryFromFPDFBookmark(bookmark)); |
| 138 | CPDF_Dest dest = cBookmark.GetDest(pDoc); |
Lei Zhang | 76525c4 | 2018-08-27 18:57:36 +0000 | [diff] [blame] | 139 | if (dest.GetArray()) |
| 140 | return FPDFDestFromCPDFArray(dest.GetArray()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 141 | // If this bookmark is not directly associated with a dest, we try to get |
| 142 | // action |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 143 | CPDF_Action action = cBookmark.GetAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 144 | if (!action.GetDict()) |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 145 | return nullptr; |
Lei Zhang | 76525c4 | 2018-08-27 18:57:36 +0000 | [diff] [blame] | 146 | return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetArray()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 149 | FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 150 | FPDFBookmark_GetAction(FPDF_BOOKMARK bookmark) { |
| 151 | if (!bookmark) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 152 | return nullptr; |
Tom Sepez | 8c62883 | 2018-10-09 21:02:15 +0000 | [diff] [blame] | 153 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 154 | CPDF_Bookmark cBookmark(CPDFDictionaryFromFPDFBookmark(bookmark)); |
| 155 | return FPDFActionFromCPDFDictionary(cBookmark.GetAction().GetDict()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 158 | FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAction_GetType(FPDF_ACTION action) { |
| 159 | if (!action) |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 160 | return PDFACTION_UNSUPPORTED; |
| 161 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 162 | CPDF_Action cAction(CPDFDictionaryFromFPDFAction(action)); |
| 163 | CPDF_Action::ActionType type = cAction.GetType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | switch (type) { |
| 165 | case CPDF_Action::GoTo: |
| 166 | return PDFACTION_GOTO; |
| 167 | case CPDF_Action::GoToR: |
| 168 | return PDFACTION_REMOTEGOTO; |
Zhouhan Chen | b70f99d | 2020-08-08 00:21:07 +0000 | [diff] [blame] | 169 | case CPDF_Action::GoToE: |
| 170 | return PDFACTION_EMBEDDEDGOTO; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | case CPDF_Action::URI: |
| 172 | return PDFACTION_URI; |
| 173 | case CPDF_Action::Launch: |
| 174 | return PDFACTION_LAUNCH; |
| 175 | default: |
| 176 | return PDFACTION_UNSUPPORTED; |
| 177 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 180 | FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFAction_GetDest(FPDF_DOCUMENT document, |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 181 | FPDF_ACTION action) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 182 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 183 | if (!pDoc) |
| 184 | return nullptr; |
Tom Sepez | 7bf8164 | 2018-10-10 17:27:33 +0000 | [diff] [blame] | 185 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 186 | unsigned long type = FPDFAction_GetType(action); |
Zhouhan Chen | b70f99d | 2020-08-08 00:21:07 +0000 | [diff] [blame] | 187 | if (type != PDFACTION_GOTO && type != PDFACTION_REMOTEGOTO && |
| 188 | type != PDFACTION_EMBEDDEDGOTO) { |
Tom Sepez | 7bf8164 | 2018-10-10 17:27:33 +0000 | [diff] [blame] | 189 | return nullptr; |
Zhouhan Chen | b70f99d | 2020-08-08 00:21:07 +0000 | [diff] [blame] | 190 | } |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 191 | CPDF_Action cAction(CPDFDictionaryFromFPDFAction(action)); |
| 192 | return FPDFDestFromCPDFArray(cAction.GetDest(pDoc).GetArray()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 195 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 196 | FPDFAction_GetFilePath(FPDF_ACTION action, void* buffer, unsigned long buflen) { |
| 197 | unsigned long type = FPDFAction_GetType(action); |
Zhouhan Chen | b70f99d | 2020-08-08 00:21:07 +0000 | [diff] [blame] | 198 | if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_EMBEDDEDGOTO && |
| 199 | type != PDFACTION_LAUNCH) { |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 200 | return 0; |
Zhouhan Chen | b70f99d | 2020-08-08 00:21:07 +0000 | [diff] [blame] | 201 | } |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 202 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 203 | CPDF_Action cAction(CPDFDictionaryFromFPDFAction(action)); |
| 204 | ByteString path = cAction.GetFilePath().ToUTF8(); |
Daniel Hosseinian | 5bc1f98 | 2020-04-14 01:05:27 +0000 | [diff] [blame] | 205 | return NulTerminateMaybeCopyAndReturnLength(path, buffer, buflen); |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 208 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
| 209 | FPDFAction_GetURIPath(FPDF_DOCUMENT document, |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 210 | FPDF_ACTION action, |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 211 | void* buffer, |
| 212 | unsigned long buflen) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 213 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 214 | if (!pDoc) |
| 215 | return 0; |
Tom Sepez | 7bf8164 | 2018-10-10 17:27:33 +0000 | [diff] [blame] | 216 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 217 | unsigned long type = FPDFAction_GetType(action); |
Tom Sepez | 7bf8164 | 2018-10-10 17:27:33 +0000 | [diff] [blame] | 218 | if (type != PDFACTION_URI) |
| 219 | return 0; |
| 220 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 221 | CPDF_Action cAction(CPDFDictionaryFromFPDFAction(action)); |
| 222 | ByteString path = cAction.GetURI(pDoc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 223 | unsigned long len = path.GetLength() + 1; |
thestig | 9067fd6 | 2016-11-23 14:10:06 -0800 | [diff] [blame] | 224 | if (buffer && len <= buflen) |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 225 | memcpy(buffer, path.c_str(), len); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 226 | return len; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Henrique Nakashima | e899dd7 | 2018-02-01 19:17:04 +0000 | [diff] [blame] | 229 | FPDF_EXPORT int FPDF_CALLCONV FPDFDest_GetDestPageIndex(FPDF_DOCUMENT document, |
Lei Zhang | aca3efc | 2018-03-16 20:27:04 +0000 | [diff] [blame] | 230 | FPDF_DEST dest) { |
Henrique Nakashima | 71a7d37 | 2018-02-01 17:07:13 +0000 | [diff] [blame] | 231 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 232 | if (!pDoc) |
| 233 | return -1; |
| 234 | |
Tom Sepez | 69c3285 | 2018-10-09 21:42:39 +0000 | [diff] [blame] | 235 | if (!dest) |
| 236 | return -1; |
| 237 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 238 | CPDF_Dest destination(CPDFArrayFromFPDFDest(dest)); |
Lei Zhang | aca3efc | 2018-03-16 20:27:04 +0000 | [diff] [blame] | 239 | return destination.GetDestPageIndex(pDoc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Henrique Nakashima | de3f3fc | 2018-01-04 11:54:18 -0500 | [diff] [blame] | 242 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
Lei Zhang | 537d3a6 | 2019-12-13 17:39:38 +0000 | [diff] [blame] | 243 | FPDFDest_GetView(FPDF_DEST dest, unsigned long* pNumParams, FS_FLOAT* pParams) { |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 244 | if (!dest) { |
Lei Zhang | 326c38c | 2018-01-10 20:10:05 +0000 | [diff] [blame] | 245 | *pNumParams = 0; |
Henrique Nakashima | de3f3fc | 2018-01-04 11:54:18 -0500 | [diff] [blame] | 246 | return 0; |
| 247 | } |
| 248 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 249 | CPDF_Dest destination(CPDFArrayFromFPDFDest(dest)); |
Lei Zhang | 11767d3 | 2018-03-21 18:59:44 +0000 | [diff] [blame] | 250 | unsigned long nParams = destination.GetNumParams(); |
Lei Zhang | 326c38c | 2018-01-10 20:10:05 +0000 | [diff] [blame] | 251 | ASSERT(nParams <= 4); |
| 252 | *pNumParams = nParams; |
| 253 | for (unsigned long i = 0; i < nParams; ++i) |
Lei Zhang | 11767d3 | 2018-03-21 18:59:44 +0000 | [diff] [blame] | 254 | pParams[i] = destination.GetParam(i); |
| 255 | return destination.GetZoomMode(); |
Henrique Nakashima | de3f3fc | 2018-01-04 11:54:18 -0500 | [diff] [blame] | 256 | } |
| 257 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 258 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 259 | FPDFDest_GetLocationInPage(FPDF_DEST dest, |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 260 | FPDF_BOOL* hasXVal, |
| 261 | FPDF_BOOL* hasYVal, |
| 262 | FPDF_BOOL* hasZoomVal, |
| 263 | FS_FLOAT* x, |
| 264 | FS_FLOAT* y, |
| 265 | FS_FLOAT* zoom) { |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 266 | if (!dest) |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 267 | return false; |
| 268 | |
Tom Sepez | 5af9543 | 2020-05-15 22:55:16 +0000 | [diff] [blame] | 269 | auto destination = std::make_unique<CPDF_Dest>(CPDFArrayFromFPDFDest(dest)); |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 270 | |
| 271 | // FPDF_BOOL is an int, GetXYZ expects bools. |
| 272 | bool bHasX; |
| 273 | bool bHasY; |
| 274 | bool bHasZoom; |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 275 | if (!destination->GetXYZ(&bHasX, &bHasY, &bHasZoom, x, y, zoom)) |
dsinclair | c59fa88 | 2016-11-08 06:55:40 -0800 | [diff] [blame] | 276 | return false; |
| 277 | |
| 278 | *hasXVal = bHasX; |
| 279 | *hasYVal = bHasY; |
| 280 | *hasZoomVal = bHasZoom; |
| 281 | return true; |
| 282 | } |
| 283 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 284 | FPDF_EXPORT FPDF_LINK FPDF_CALLCONV FPDFLink_GetLinkAtPoint(FPDF_PAGE page, |
| 285 | double x, |
| 286 | double y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 287 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 288 | if (!pPage) |
| 289 | return nullptr; |
| 290 | |
| 291 | CPDF_LinkList* pLinkList = GetLinkList(pPage); |
| 292 | if (!pLinkList) |
| 293 | return nullptr; |
| 294 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 295 | CPDF_Link link = pLinkList->GetLinkAtPoint( |
| 296 | pPage, CFX_PointF(static_cast<float>(x), static_cast<float>(y)), nullptr); |
| 297 | |
| 298 | return FPDFLinkFromCPDFDictionary(link.GetDict()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 301 | FPDF_EXPORT int FPDF_CALLCONV FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, |
| 302 | double x, |
| 303 | double y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 304 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 305 | if (!pPage) |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 306 | return -1; |
| 307 | |
| 308 | CPDF_LinkList* pLinkList = GetLinkList(pPage); |
| 309 | if (!pLinkList) |
| 310 | return -1; |
| 311 | |
| 312 | int z_order = -1; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 313 | pLinkList->GetLinkAtPoint( |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 314 | pPage, CFX_PointF(static_cast<float>(x), static_cast<float>(y)), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 315 | &z_order); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 316 | return z_order; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 319 | FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFLink_GetDest(FPDF_DOCUMENT document, |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 320 | FPDF_LINK link) { |
| 321 | if (!link) |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 322 | return nullptr; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 323 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 324 | if (!pDoc) |
| 325 | return nullptr; |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 326 | CPDF_Link cLink(CPDFDictionaryFromFPDFLink(link)); |
| 327 | FPDF_DEST dest = FPDFDestFromCPDFArray(cLink.GetDest(pDoc).GetArray()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 328 | if (dest) |
| 329 | return dest; |
| 330 | // If this link is not directly associated with a dest, we try to get action |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 331 | CPDF_Action action = cLink.GetAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 332 | if (!action.GetDict()) |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 333 | return nullptr; |
Lei Zhang | 76525c4 | 2018-08-27 18:57:36 +0000 | [diff] [blame] | 334 | return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetArray()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 337 | FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFLink_GetAction(FPDF_LINK link) { |
| 338 | if (!link) |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 339 | return nullptr; |
| 340 | |
Andrew Weintraub | fe111d9 | 2019-06-24 17:19:20 +0000 | [diff] [blame] | 341 | CPDF_Link cLink(CPDFDictionaryFromFPDFLink(link)); |
| 342 | return FPDFActionFromCPDFDictionary(cLink.GetAction().GetDict()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 345 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_Enumerate(FPDF_PAGE page, |
Lei Zhang | c3cffbe | 2018-03-21 13:37:46 +0000 | [diff] [blame] | 346 | int* start_pos, |
| 347 | FPDF_LINK* link_annot) { |
| 348 | if (!start_pos || !link_annot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 349 | return false; |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 350 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Lei Zhang | 197d498 | 2019-08-09 21:40:49 +0000 | [diff] [blame] | 351 | if (!pPage) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 352 | return false; |
Henrique Nakashima | 888af47 | 2018-06-07 19:43:42 +0000 | [diff] [blame] | 353 | CPDF_Array* pAnnots = pPage->GetDict()->GetArrayFor("Annots"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | if (!pAnnots) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 355 | return false; |
Lei Zhang | f40380f | 2018-10-12 18:31:51 +0000 | [diff] [blame] | 356 | for (size_t i = *start_pos; i < pAnnots->size(); i++) { |
Lei Zhang | 11767d3 | 2018-03-21 18:59:44 +0000 | [diff] [blame] | 357 | CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 358 | if (!pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 359 | continue; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 360 | if (pDict->GetStringFor("Subtype") == "Link") { |
Lei Zhang | c3cffbe | 2018-03-21 13:37:46 +0000 | [diff] [blame] | 361 | *start_pos = static_cast<int>(i + 1); |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 362 | *link_annot = FPDFLinkFromCPDFDictionary(pDict); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 363 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 364 | } |
| 365 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 366 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Virender Singh | ceea607 | 2020-06-18 20:31:25 +0000 | [diff] [blame] | 369 | FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV |
| 370 | FPDFLink_GetAnnot(FPDF_PAGE page, FPDF_LINK link_annot) { |
| 371 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 372 | CPDF_Dictionary* pAnnotDict = CPDFDictionaryFromFPDFLink(link_annot); |
| 373 | if (!pPage || !pAnnotDict) |
| 374 | return nullptr; |
| 375 | |
| 376 | auto pAnnotContext = std::make_unique<CPDF_AnnotContext>( |
| 377 | pAnnotDict, IPDFPageFromFPDFPage(page)); |
| 378 | |
| 379 | // Caller takes the ownership of the object. |
| 380 | return FPDFAnnotationFromCPDFAnnotContext(pAnnotContext.release()); |
| 381 | } |
| 382 | |
Lei Zhang | c3cffbe | 2018-03-21 13:37:46 +0000 | [diff] [blame] | 383 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetAnnotRect(FPDF_LINK link_annot, |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 384 | FS_RECTF* rect) { |
Lei Zhang | c3cffbe | 2018-03-21 13:37:46 +0000 | [diff] [blame] | 385 | if (!link_annot || !rect) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 386 | return false; |
Lei Zhang | 3567c61 | 2019-11-18 18:10:02 +0000 | [diff] [blame] | 387 | |
Lei Zhang | 11767d3 | 2018-03-21 18:59:44 +0000 | [diff] [blame] | 388 | CPDF_Dictionary* pAnnotDict = CPDFDictionaryFromFPDFLink(link_annot); |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 389 | *rect = FSRectFFromCFXFloatRect(pAnnotDict->GetRectFor("Rect")); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 390 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Lei Zhang | c3cffbe | 2018-03-21 13:37:46 +0000 | [diff] [blame] | 393 | FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountQuadPoints(FPDF_LINK link_annot) { |
Lei Zhang | aaed698 | 2018-03-22 18:39:05 +0000 | [diff] [blame] | 394 | const CPDF_Array* pArray = |
| 395 | GetQuadPointsArrayFromDictionary(CPDFDictionaryFromFPDFLink(link_annot)); |
Lei Zhang | f40380f | 2018-10-12 18:31:51 +0000 | [diff] [blame] | 396 | return pArray ? static_cast<int>(pArray->size() / 8) : 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 399 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
Lei Zhang | c3cffbe | 2018-03-21 13:37:46 +0000 | [diff] [blame] | 400 | FPDFLink_GetQuadPoints(FPDF_LINK link_annot, |
| 401 | int quad_index, |
| 402 | FS_QUADPOINTSF* quad_points) { |
Lei Zhang | aaed698 | 2018-03-22 18:39:05 +0000 | [diff] [blame] | 403 | if (!quad_points || quad_index < 0) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 404 | return false; |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 405 | |
Lei Zhang | eda4e7a | 2019-03-22 21:26:24 +0000 | [diff] [blame] | 406 | const CPDF_Dictionary* pLinkDict = CPDFDictionaryFromFPDFLink(link_annot); |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 407 | if (!pLinkDict) |
| 408 | return false; |
| 409 | |
| 410 | const CPDF_Array* pArray = GetQuadPointsArrayFromDictionary(pLinkDict); |
| 411 | if (!pArray) |
| 412 | return false; |
| 413 | |
| 414 | return GetQuadPointsAtIndex(pArray, static_cast<size_t>(quad_index), |
| 415 | quad_points); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Zhouhan Chen | 16760b5 | 2020-08-12 05:14:00 +0000 | [diff] [blame] | 418 | FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDF_GetPageAAction(FPDF_PAGE page, |
| 419 | int aa_type) { |
| 420 | CPDF_Page* pdf_page = CPDFPageFromFPDFPage(page); |
| 421 | if (!pdf_page) |
| 422 | return nullptr; |
| 423 | |
| 424 | CPDF_Dictionary* page_dict = pdf_page->GetDict(); |
| 425 | CPDF_AAction aa(page_dict->GetDictFor(pdfium::form_fields::kAA)); |
| 426 | |
| 427 | CPDF_AAction::AActionType type; |
| 428 | if (aa_type == FPDFPAGE_AACTION_OPEN) |
| 429 | type = CPDF_AAction::kOpenPage; |
| 430 | else if (aa_type == FPDFPAGE_AACTION_CLOSE) |
| 431 | type = CPDF_AAction::kClosePage; |
| 432 | else |
| 433 | return nullptr; |
| 434 | |
| 435 | if (!aa.ActionExist(type)) |
| 436 | return nullptr; |
| 437 | |
| 438 | CPDF_Action action = aa.GetAction(type); |
| 439 | return FPDFActionFromCPDFDictionary(action.GetDict()); |
| 440 | } |
| 441 | |
Daniel Hosseinian | f2e3601 | 2020-04-14 02:40:57 +0000 | [diff] [blame] | 442 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
| 443 | FPDF_GetFileIdentifier(FPDF_DOCUMENT document, |
| 444 | FPDF_FILEIDTYPE id_type, |
| 445 | void* buffer, |
| 446 | unsigned long buflen) { |
| 447 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 448 | if (!pDoc) |
| 449 | return 0; |
| 450 | |
| 451 | // Check if |id_type| is valid. |
| 452 | if (id_type != FILEIDTYPE_PERMANENT && id_type != FILEIDTYPE_CHANGING) |
| 453 | return 0; |
| 454 | |
| 455 | const CPDF_Array* pFileId = pDoc->GetFileIdentifier(); |
| 456 | if (!pFileId) |
| 457 | return 0; |
| 458 | |
| 459 | size_t nIndex = id_type == FILEIDTYPE_PERMANENT ? 0 : 1; |
| 460 | const CPDF_String* pValue = ToString(pFileId->GetDirectObjectAt(nIndex)); |
| 461 | if (!pValue) |
| 462 | return 0; |
| 463 | |
| 464 | return NulTerminateMaybeCopyAndReturnLength(pValue->GetString(), buffer, |
| 465 | buflen); |
| 466 | } |
| 467 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 468 | FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetMetaText(FPDF_DOCUMENT document, |
| 469 | FPDF_BYTESTRING tag, |
| 470 | void* buffer, |
| 471 | unsigned long buflen) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 472 | if (!tag) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | return 0; |
thestig | 733e068 | 2016-11-23 05:52:39 -0800 | [diff] [blame] | 474 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 475 | if (!pDoc) |
| 476 | return 0; |
Artem Strygin | a327030 | 2018-06-22 12:45:14 +0000 | [diff] [blame] | 477 | |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 478 | const CPDF_Dictionary* pInfo = pDoc->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | if (!pInfo) |
| 480 | return 0; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 481 | WideString text = pInfo->GetUnicodeTextFor(tag); |
thestig | 733e068 | 2016-11-23 05:52:39 -0800 | [diff] [blame] | 482 | return Utf16EncodeMaybeCopyAndReturnLength(text, buffer, buflen); |
| 483 | } |
| 484 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 485 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
| 486 | FPDF_GetPageLabel(FPDF_DOCUMENT document, |
| 487 | int page_index, |
| 488 | void* buffer, |
| 489 | unsigned long buflen) { |
thestig | 733e068 | 2016-11-23 05:52:39 -0800 | [diff] [blame] | 490 | if (page_index < 0) |
| 491 | return 0; |
| 492 | |
| 493 | // CPDF_PageLabel can deal with NULL |document|. |
| 494 | CPDF_PageLabel label(CPDFDocumentFromFPDFDocument(document)); |
Ryan Harrison | 8eeee77 | 2018-01-05 13:39:22 -0500 | [diff] [blame] | 495 | Optional<WideString> str = label.GetLabel(page_index); |
| 496 | return str.has_value() |
| 497 | ? Utf16EncodeMaybeCopyAndReturnLength(str.value(), buffer, buflen) |
| 498 | : 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 499 | } |