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 | |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 9 | #include <set> |
| 10 | |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 11 | #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 12 | #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 13 | #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 14 | #include "fpdfsdk/include/fsdk_define.h" |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 15 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 16 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 17 | namespace { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 18 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 19 | CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, |
| 20 | CPDF_Bookmark bookmark, |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 21 | const CFX_WideString& title, |
| 22 | std::set<CPDF_Dictionary*>* visited) { |
| 23 | // Return if already checked to avoid circular calling. |
| 24 | if (pdfium::ContainsKey(*visited, bookmark.GetDict())) |
| 25 | return CPDF_Bookmark(); |
| 26 | visited->insert(bookmark.GetDict()); |
| 27 | |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 28 | if (bookmark.GetDict() && |
| 29 | bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 30 | // First check this item. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | return bookmark; |
| 32 | } |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 33 | |
| 34 | // Go into children items. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | CPDF_Bookmark child = tree.GetFirstChild(bookmark); |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 36 | while (child.GetDict() && !pdfium::ContainsKey(*visited, child.GetDict())) { |
| 37 | // Check this item and its children. |
| 38 | CPDF_Bookmark found = FindBookmark(tree, child, title, visited); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 39 | if (found.GetDict()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | return found; |
| 41 | child = tree.GetNextSibling(child); |
| 42 | } |
| 43 | return CPDF_Bookmark(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 46 | CPDF_LinkList* GetLinkList(CPDF_Page* page) { |
| 47 | if (!page) |
| 48 | return nullptr; |
| 49 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 50 | CPDF_Document* pDoc = page->m_pDocument; |
tsepez | 5ce0968 | 2016-05-25 16:16:32 -0700 | [diff] [blame] | 51 | std::unique_ptr<CPDF_LinkList>* pHolder = pDoc->LinksContext(); |
| 52 | if (!pHolder->get()) |
| 53 | pHolder->reset(new CPDF_LinkList); |
| 54 | return pHolder->get(); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | } // namespace |
| 58 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 59 | DLLEXPORT FPDF_BOOKMARK STDCALL |
| 60 | FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 61 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 62 | if (!pDoc) |
| 63 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | CPDF_BookmarkTree tree(pDoc); |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 65 | CPDF_Bookmark bookmark = |
| 66 | CPDF_Bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | return tree.GetFirstChild(bookmark).GetDict(); |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | DLLEXPORT FPDF_BOOKMARK STDCALL |
| 71 | FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 72 | if (!pDict) |
| 73 | return nullptr; |
| 74 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 75 | if (!pDoc) |
| 76 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 77 | CPDF_BookmarkTree tree(pDoc); |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 78 | CPDF_Bookmark bookmark = |
| 79 | CPDF_Bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | return tree.GetNextSibling(bookmark).GetDict(); |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, |
| 84 | void* buffer, |
| 85 | unsigned long buflen) { |
| 86 | if (!pDict) |
| 87 | return 0; |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 88 | CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | CFX_WideString title = bookmark.GetTitle(); |
| 90 | CFX_ByteString encodedTitle = title.UTF16LE_Encode(); |
| 91 | unsigned long len = encodedTitle.GetLength(); |
| 92 | if (buffer && buflen >= len) { |
| 93 | FXSYS_memcpy(buffer, encodedTitle.c_str(), len); |
| 94 | } |
| 95 | return len; |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, |
| 99 | FPDF_WIDESTRING title) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | if (!title || title[0] == 0) |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 101 | return nullptr; |
| 102 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 103 | if (!pDoc) |
| 104 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 105 | CPDF_BookmarkTree tree(pDoc); |
| 106 | FX_STRSIZE len = CFX_WideString::WStringLength(title); |
| 107 | CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); |
Wei Li | 0e2e5d7 | 2016-03-03 11:28:06 -0800 | [diff] [blame] | 108 | std::set<CPDF_Dictionary*> visited; |
| 109 | return FindBookmark(tree, CPDF_Bookmark(), encodedTitle, &visited).GetDict(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, |
| 113 | FPDF_BOOKMARK pDict) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | if (!pDict) |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 115 | return nullptr; |
| 116 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 117 | if (!pDoc) |
| 118 | return nullptr; |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 119 | CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 120 | CPDF_Dest dest = bookmark.GetDest(pDoc); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 121 | if (dest.GetObject()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 122 | return dest.GetObject(); |
| 123 | // If this bookmark is not directly associated with a dest, we try to get |
| 124 | // action |
| 125 | CPDF_Action action = bookmark.GetAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 126 | if (!action.GetDict()) |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 127 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 128 | return action.GetDest(pDoc).GetObject(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 131 | DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) { |
| 132 | if (!pDict) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 133 | return nullptr; |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 134 | CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | return bookmark.GetAction().GetDict(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 138 | DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) { |
| 139 | if (!pDict) |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 140 | return PDFACTION_UNSUPPORTED; |
| 141 | |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 142 | CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | CPDF_Action::ActionType type = action.GetType(); |
| 144 | switch (type) { |
| 145 | case CPDF_Action::GoTo: |
| 146 | return PDFACTION_GOTO; |
| 147 | case CPDF_Action::GoToR: |
| 148 | return PDFACTION_REMOTEGOTO; |
| 149 | case CPDF_Action::URI: |
| 150 | return PDFACTION_URI; |
| 151 | case CPDF_Action::Launch: |
| 152 | return PDFACTION_LAUNCH; |
| 153 | default: |
| 154 | return PDFACTION_UNSUPPORTED; |
| 155 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 158 | DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, |
| 159 | FPDF_ACTION pDict) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 160 | if (!pDict) |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 161 | return nullptr; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 162 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 163 | if (!pDoc) |
| 164 | return nullptr; |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 165 | CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | return action.GetDest(pDoc).GetObject(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 169 | DLLEXPORT unsigned long STDCALL FPDFAction_GetFilePath(FPDF_ACTION pDict, |
| 170 | void* buffer, |
| 171 | unsigned long buflen) { |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 172 | unsigned long type = FPDFAction_GetType(pDict); |
| 173 | if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) |
| 174 | return 0; |
| 175 | |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 176 | CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 177 | CFX_ByteString path = action.GetFilePath().UTF8Encode(); |
| 178 | unsigned long len = path.GetLength() + 1; |
| 179 | if (buffer && buflen >= len) |
| 180 | FXSYS_memcpy(buffer, path.c_str(), len); |
| 181 | return len; |
| 182 | } |
| 183 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 184 | DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, |
| 185 | FPDF_ACTION pDict, |
| 186 | void* buffer, |
| 187 | unsigned long buflen) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 188 | if (!pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 189 | return 0; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 190 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 191 | if (!pDoc) |
| 192 | return 0; |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 193 | CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 194 | CFX_ByteString path = action.GetURI(pDoc); |
| 195 | unsigned long len = path.GetLength() + 1; |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 196 | if (buffer && buflen >= len) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 197 | FXSYS_memcpy(buffer, path.c_str(), len); |
| 198 | return len; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 201 | DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, |
| 202 | FPDF_DEST pDict) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 203 | if (!pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 204 | return 0; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 205 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 206 | if (!pDoc) |
| 207 | return 0; |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 208 | CPDF_Dest dest(static_cast<CPDF_Array*>(pDict)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | return dest.GetPageIndex(pDoc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 212 | DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, |
| 213 | double x, |
| 214 | double y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 215 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 216 | if (!pPage) |
| 217 | return nullptr; |
| 218 | |
| 219 | CPDF_LinkList* pLinkList = GetLinkList(pPage); |
| 220 | if (!pLinkList) |
| 221 | return nullptr; |
| 222 | |
| 223 | return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, nullptr) |
| 224 | .GetDict(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 227 | DLLEXPORT int STDCALL FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, |
| 228 | double x, |
| 229 | double y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 230 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 231 | if (!pPage) |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 232 | return -1; |
| 233 | |
| 234 | CPDF_LinkList* pLinkList = GetLinkList(pPage); |
| 235 | if (!pLinkList) |
| 236 | return -1; |
| 237 | |
| 238 | int z_order = -1; |
| 239 | pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); |
| 240 | return z_order; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 243 | DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, |
| 244 | FPDF_LINK pDict) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 245 | if (!pDict) |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 246 | return nullptr; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 247 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 248 | if (!pDoc) |
| 249 | return nullptr; |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 250 | CPDF_Link link(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | FPDF_DEST dest = link.GetDest(pDoc).GetObject(); |
| 252 | if (dest) |
| 253 | return dest; |
| 254 | // If this link is not directly associated with a dest, we try to get action |
| 255 | CPDF_Action action = link.GetAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 256 | if (!action.GetDict()) |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 257 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 258 | return action.GetDest(pDoc).GetObject(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 261 | DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) { |
| 262 | if (!pDict) |
Lei Zhang | e0947b3 | 2015-09-17 14:51:48 -0700 | [diff] [blame] | 263 | return nullptr; |
| 264 | |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 265 | CPDF_Link link(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 266 | return link.GetAction().GetDict(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 269 | DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, |
| 270 | int* startPos, |
| 271 | FPDF_LINK* linkAnnot) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 272 | if (!startPos || !linkAnnot) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 273 | return FALSE; |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 274 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 275 | if (!pPage || !pPage->m_pFormDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | return FALSE; |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 277 | CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 278 | if (!pAnnots) |
| 279 | return FALSE; |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 280 | for (size_t i = *startPos; i < pAnnots->GetCount(); i++) { |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 281 | CPDF_Dictionary* pDict = |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 282 | ToDictionary(static_cast<CPDF_Object*>(pAnnots->GetDirectObjectAt(i))); |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 283 | if (!pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 284 | continue; |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 285 | if (pDict->GetStringBy("Subtype") == "Link") { |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 286 | *startPos = static_cast<int>(i + 1); |
| 287 | *linkAnnot = static_cast<FPDF_LINK>(pDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 288 | return TRUE; |
| 289 | } |
| 290 | } |
| 291 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 294 | DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot, |
| 295 | FS_RECTF* rect) { |
| 296 | if (!linkAnnot || !rect) |
| 297 | return FALSE; |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 298 | CPDF_Dictionary* pAnnotDict = |
| 299 | ToDictionary(static_cast<CPDF_Object*>(linkAnnot)); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 300 | CFX_FloatRect rt = pAnnotDict->GetRectBy("Rect"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | rect->left = rt.left; |
| 302 | rect->bottom = rt.bottom; |
| 303 | rect->right = rt.right; |
| 304 | rect->top = rt.top; |
| 305 | return TRUE; |
| 306 | } |
| 307 | |
| 308 | DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot) { |
| 309 | if (!linkAnnot) |
| 310 | return 0; |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 311 | CPDF_Dictionary* pAnnotDict = |
| 312 | ToDictionary(static_cast<CPDF_Object*>(linkAnnot)); |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 313 | CPDF_Array* pArray = pAnnotDict->GetArrayBy("QuadPoints"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 314 | if (!pArray) |
| 315 | return 0; |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 316 | return static_cast<int>(pArray->GetCount() / 8); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot, |
| 320 | int quadIndex, |
| 321 | FS_QUADPOINTSF* quadPoints) { |
| 322 | if (!linkAnnot || !quadPoints) |
| 323 | return FALSE; |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 324 | CPDF_Dictionary* pAnnotDict = |
| 325 | ToDictionary(static_cast<CPDF_Object*>(linkAnnot)); |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 326 | CPDF_Array* pArray = pAnnotDict->GetArrayBy("QuadPoints"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 327 | if (pArray) { |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 328 | if (quadIndex < 0 || |
| 329 | static_cast<size_t>(quadIndex) >= pArray->GetCount() / 8 || |
| 330 | (static_cast<size_t>(quadIndex * 8 + 7) >= pArray->GetCount())) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 331 | return FALSE; |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 332 | quadPoints->x1 = pArray->GetNumberAt(quadIndex * 8); |
| 333 | quadPoints->y1 = pArray->GetNumberAt(quadIndex * 8 + 1); |
| 334 | quadPoints->x2 = pArray->GetNumberAt(quadIndex * 8 + 2); |
| 335 | quadPoints->y2 = pArray->GetNumberAt(quadIndex * 8 + 3); |
| 336 | quadPoints->x3 = pArray->GetNumberAt(quadIndex * 8 + 4); |
| 337 | quadPoints->y3 = pArray->GetNumberAt(quadIndex * 8 + 5); |
| 338 | quadPoints->x4 = pArray->GetNumberAt(quadIndex * 8 + 6); |
| 339 | quadPoints->y4 = pArray->GetNumberAt(quadIndex * 8 + 7); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 340 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 341 | } |
| 342 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 345 | DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, |
| 346 | FPDF_BYTESTRING tag, |
| 347 | void* buffer, |
| 348 | unsigned long buflen) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 349 | if (!tag) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 350 | return 0; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 351 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); |
| 352 | if (!pDoc) |
| 353 | return 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | CPDF_Dictionary* pInfo = pDoc->GetInfo(); |
| 355 | if (!pInfo) |
| 356 | return 0; |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 357 | CFX_WideString text = pInfo->GetUnicodeTextBy(tag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 358 | // Use UTF-16LE encoding |
| 359 | CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 360 | unsigned long len = encodedText.GetLength(); |
| 361 | if (buffer && buflen >= len) { |
| 362 | FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| 363 | } |
| 364 | return len; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 365 | } |