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 | |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 7 | #include "../../public/fpdf_doc.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 8 | #include "../include/fsdk_define.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 9 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 10 | #include "../include/fpdfxfa/fpdfxfa_page.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 11 | |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 12 | static int THISMODULE = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 14 | static CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, CPDF_Bookmark bookmark, const CFX_WideString& title) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | { |
Tom Sepez | 4f7bc04 | 2015-04-27 12:06:58 -0700 | [diff] [blame] | 16 | if (bookmark && bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | // First check this item |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 18 | return bookmark; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 19 | } |
| 20 | // go into children items |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 21 | CPDF_Bookmark child = tree.GetFirstChild(bookmark); |
| 22 | while (child) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 23 | // check if this item |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 24 | CPDF_Bookmark found = FindBookmark(tree, child, title); |
| 25 | if (found) |
| 26 | return found; |
| 27 | child = tree.GetNextSibling(child); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | } |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 29 | return CPDF_Bookmark(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 32 | DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) |
| 33 | { |
| 34 | if (!document || !pDict) |
| 35 | return NULL; |
| 36 | CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
| 37 | CPDF_BookmarkTree tree(pDoc); |
| 38 | CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 39 | return tree.GetFirstChild(bookmark).GetDict(); |
| 40 | } |
| 41 | |
| 42 | DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) |
| 43 | { |
| 44 | if (!document || !pDict) |
| 45 | return NULL; |
| 46 | CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
| 47 | CPDF_BookmarkTree tree(pDoc); |
| 48 | CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 49 | return tree.GetNextSibling(bookmark).GetDict(); |
| 50 | } |
| 51 | |
| 52 | DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, void* buffer, unsigned long buflen) |
| 53 | { |
| 54 | if (!pDict) |
| 55 | return 0; |
| 56 | CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 57 | CFX_WideString title = bookmark.GetTitle(); |
Bo Xu | a6f95eb | 2015-01-21 12:17:23 -0800 | [diff] [blame] | 58 | CFX_ByteString encodedTitle = title.UTF16LE_Encode(); |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 59 | unsigned long len = encodedTitle.GetLength(); |
Bo Xu | a6f95eb | 2015-01-21 12:17:23 -0800 | [diff] [blame] | 60 | if (buffer && buflen >= len) { |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 61 | FXSYS_memcpy(buffer, encodedTitle.c_str(), len); |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 62 | } |
Bo Xu | a6f95eb | 2015-01-21 12:17:23 -0800 | [diff] [blame] | 63 | return len; |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 64 | } |
| 65 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 66 | DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title) |
| 67 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 68 | if (!document) |
| 69 | return NULL; |
| 70 | if (!title || title[0] == 0) |
| 71 | return NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 72 | CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 73 | CPDF_BookmarkTree tree(pDoc); |
Bo Xu | 8daab31 | 2014-07-14 12:13:53 -0700 | [diff] [blame] | 74 | FX_STRSIZE len = CFX_WideString::WStringLength(title); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 75 | CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); |
| 76 | return FindBookmark(tree, CPDF_Bookmark(), encodedTitle).GetDict(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 79 | DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 80 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 81 | if (!document) |
| 82 | return NULL; |
| 83 | if (!pDict) |
| 84 | return NULL; |
| 85 | CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 86 | CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 87 | CPDF_Dest dest = bookmark.GetDest(pDoc); |
| 88 | if (dest) |
Tom Sepez | ac8d1e7 | 2015-03-06 10:52:05 -0800 | [diff] [blame] | 89 | return dest.GetObject(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | // If this bookmark is not directly associated with a dest, we try to get action |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 91 | CPDF_Action action = bookmark.GetAction(); |
| 92 | if (!action) |
| 93 | return NULL; |
Tom Sepez | ac8d1e7 | 2015-03-06 10:52:05 -0800 | [diff] [blame] | 94 | return action.GetDest(pDoc).GetObject(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 97 | DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 98 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 99 | if (!pDict) |
| 100 | return NULL; |
| 101 | CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 102 | return bookmark.GetAction().GetDict(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 105 | DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 106 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 107 | if (!pDict) |
| 108 | return 0; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 109 | CPDF_Action action((CPDF_Dictionary*)pDict); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 110 | CPDF_Action::ActionType type = action.GetType(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 111 | switch (type) { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 112 | case CPDF_Action::GoTo: |
| 113 | return PDFACTION_GOTO; |
| 114 | case CPDF_Action::GoToR: |
| 115 | return PDFACTION_REMOTEGOTO; |
| 116 | case CPDF_Action::URI: |
| 117 | return PDFACTION_URI; |
| 118 | case CPDF_Action::Launch: |
| 119 | return PDFACTION_LAUNCH; |
| 120 | default: |
| 121 | return PDFACTION_UNSUPPORTED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 122 | } |
| 123 | return PDFACTION_UNSUPPORTED; |
| 124 | } |
| 125 | |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 126 | DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTION pDict) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 127 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 128 | if (!document) |
| 129 | return NULL; |
| 130 | if (!pDict) |
| 131 | return NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 132 | CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 133 | CPDF_Action action((CPDF_Dictionary*)pDict); |
Tom Sepez | ac8d1e7 | 2015-03-06 10:52:05 -0800 | [diff] [blame] | 134 | return action.GetDest(pDoc).GetObject(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 137 | DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, FPDF_ACTION pDict, |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 138 | void* buffer, unsigned long buflen) |
| 139 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 140 | if (!document) |
| 141 | return 0; |
| 142 | if (!pDict) |
| 143 | return 0; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 144 | CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 145 | CPDF_Action action((CPDF_Dictionary*)pDict); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 146 | CFX_ByteString path = action.GetURI(pDoc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 147 | unsigned long len = path.GetLength() + 1; |
| 148 | if (buffer != NULL && buflen >= len) |
Bo Xu | c616483 | 2014-12-30 16:56:12 -0800 | [diff] [blame] | 149 | FXSYS_memcpy(buffer, path.c_str(), len); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 150 | return len; |
| 151 | } |
| 152 | |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 153 | DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FPDF_DEST pDict) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 154 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 155 | if (!document) |
| 156 | return 0; |
| 157 | if (!pDict) |
| 158 | return 0; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 159 | CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
Tom Sepez | ac8d1e7 | 2015-03-06 10:52:05 -0800 | [diff] [blame] | 160 | CPDF_Dest dest((CPDF_Array*)pDict); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 161 | return dest.GetPageIndex(pDoc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Tom Sepez | d7e5cc7 | 2015-06-10 14:33:37 -0700 | [diff] [blame] | 164 | static void ReleaseLinkList(void* data) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 165 | { |
| 166 | delete (CPDF_LinkList*)data; |
| 167 | } |
| 168 | |
| 169 | DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) |
| 170 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 171 | if (!page) |
| 172 | return NULL; |
| 173 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
Bo Xu | 9f78c2a | 2015-01-13 17:02:12 -0800 | [diff] [blame] | 174 | if (!pPage) |
| 175 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 176 | // Link list is stored with the document |
| 177 | CPDF_Document* pDoc = pPage->m_pDocument; |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 178 | CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE); |
| 179 | if (!pLinkList) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 180 | pLinkList = FX_NEW CPDF_LinkList(pDoc); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 181 | pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 182 | } |
Tom Sepez | 4cc9acb | 2015-03-06 12:37:13 -0800 | [diff] [blame] | 183 | return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y).GetDict(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 186 | DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK pDict) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 187 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 188 | if (!document) |
| 189 | return NULL; |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 190 | if (!pDict) |
| 191 | return NULL; |
Tom Sepez | 4cc9acb | 2015-03-06 12:37:13 -0800 | [diff] [blame] | 192 | CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
| 193 | CPDF_Link link((CPDF_Dictionary*)pDict); |
Tom Sepez | ac8d1e7 | 2015-03-06 10:52:05 -0800 | [diff] [blame] | 194 | FPDF_DEST dest = link.GetDest(pDoc).GetObject(); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 195 | if (dest) |
| 196 | return dest; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 197 | // If this link is not directly associated with a dest, we try to get action |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 198 | CPDF_Action action = link.GetAction(); |
| 199 | if (!action) |
| 200 | return NULL; |
Tom Sepez | ac8d1e7 | 2015-03-06 10:52:05 -0800 | [diff] [blame] | 201 | return action.GetDest(pDoc).GetObject(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 204 | DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 205 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 206 | if (!pDict) |
| 207 | return NULL; |
Tom Sepez | 4cc9acb | 2015-03-06 12:37:13 -0800 | [diff] [blame] | 208 | CPDF_Link link((CPDF_Dictionary*)pDict); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 209 | return link.GetAction().GetDict(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, int* startPos, FPDF_LINK* linkAnnot) |
| 213 | { |
| 214 | if(!page || !startPos || !linkAnnot) |
| 215 | return FALSE; |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 216 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 217 | if(!pPage->m_pFormDict) |
| 218 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 219 | CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots"); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 220 | if(!pAnnots) |
| 221 | return FALSE; |
| 222 | for (int i = *startPos; i < (int)pAnnots->GetCount(); i++) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 223 | CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 224 | if (!pDict || pDict->GetType() != PDFOBJ_DICTIONARY) |
| 225 | continue; |
| 226 | if(pDict->GetString(FX_BSTRC("Subtype")).Equal(FX_BSTRC("Link"))) { |
| 227 | *startPos = i + 1; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame^] | 228 | *linkAnnot = (FPDF_LINK)pDict; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 229 | return TRUE; |
| 230 | } |
| 231 | } |
| 232 | return FALSE; |
| 233 | } |
| 234 | |
| 235 | DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot, FS_RECTF* rect) |
| 236 | { |
| 237 | if(!linkAnnot || !rect) |
| 238 | return FALSE; |
| 239 | CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; |
| 240 | CPDF_Rect rt = pAnnotDict->GetRect(FX_BSTRC("Rect")); |
| 241 | rect->left = rt.left; |
| 242 | rect->bottom = rt.bottom; |
| 243 | rect->right = rt.right; |
| 244 | rect->top = rt.top; |
| 245 | return TRUE; |
| 246 | } |
| 247 | |
| 248 | DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot) |
| 249 | { |
| 250 | if(!linkAnnot) |
| 251 | return 0; |
| 252 | CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; |
| 253 | CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints")); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 254 | if (!pArray) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 255 | return 0; |
| 256 | else |
| 257 | return pArray->GetCount() / 8; |
| 258 | } |
| 259 | |
| 260 | DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot, int quadIndex, FS_QUADPOINTSF* quadPoints) |
| 261 | { |
| 262 | if(!linkAnnot || !quadPoints) |
| 263 | return FALSE; |
| 264 | CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; |
| 265 | CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints")); |
| 266 | if (pArray) { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 267 | if (quadIndex < 0 || quadIndex >= (int)pArray->GetCount()/8 || ((quadIndex*8+7) >= (int)pArray->GetCount())) |
| 268 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 269 | quadPoints->x1 = pArray->GetNumber(quadIndex*8); |
| 270 | quadPoints->y1 = pArray->GetNumber(quadIndex*8+1); |
| 271 | quadPoints->x2 = pArray->GetNumber(quadIndex*8+2); |
| 272 | quadPoints->y2 = pArray->GetNumber(quadIndex*8+3); |
| 273 | quadPoints->x3 = pArray->GetNumber(quadIndex*8+4); |
| 274 | quadPoints->y3 = pArray->GetNumber(quadIndex*8+5); |
| 275 | quadPoints->x4 = pArray->GetNumber(quadIndex*8+6); |
| 276 | quadPoints->y4 = pArray->GetNumber(quadIndex*8+7); |
| 277 | return TRUE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame^] | 278 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 279 | return FALSE; |
| 280 | } |
| 281 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 282 | DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, FPDF_BYTESTRING tag, |
| 283 | void* buffer, unsigned long buflen) |
| 284 | { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 285 | if (!doc || !tag) |
| 286 | return 0; |
| 287 | CPDF_Document* pDoc = ((CPDFXFA_Document*)doc)->GetPDFDoc(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 288 | // Get info dictionary |
| 289 | CPDF_Dictionary* pInfo = pDoc->GetInfo(); |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 290 | if (!pInfo) |
| 291 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 292 | CFX_WideString text = pInfo->GetUnicodeText(tag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 293 | // Use UTF-16LE encoding |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 294 | CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 295 | unsigned long len = encodedText.GetLength(); |
Bo Xu | a6f95eb | 2015-01-21 12:17:23 -0800 | [diff] [blame] | 296 | if (buffer && buflen >= len) { |
Bo Xu | 5d9acf8 | 2015-01-05 12:39:36 -0800 | [diff] [blame] | 297 | FXSYS_memcpy(buffer, encodedText.c_str(), len); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 298 | } |
Bo Xu | a6f95eb | 2015-01-21 12:17:23 -0800 | [diff] [blame] | 299 | return len; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 300 | } |