blob: 639fed9dfff68c99876c875501654539b169d9c2 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_doc.h"
8
Wei Li0e2e5d72016-03-03 11:28:06 -08009#include <set>
10
dsinclairc6c425a2016-09-29 12:01:30 -070011#include "core/fpdfapi/fpdf_parser/cpdf_array.h"
12#include "core/fpdfapi/fpdf_parser/cpdf_document.h"
dsinclair41872fa2016-10-04 11:29:35 -070013#include "core/fpdfapi/page/cpdf_page.h"
dsinclair1727aee2016-09-29 13:12:56 -070014#include "core/fpdfdoc/cpdf_bookmark.h"
15#include "core/fpdfdoc/cpdf_bookmarktree.h"
dsinclair114e46a2016-09-29 17:18:21 -070016#include "fpdfsdk/fsdk_define.h"
Wei Li0e2e5d72016-03-03 11:28:06 -080017#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018
Lei Zhangbdf72c32015-08-14 19:24:08 -070019namespace {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Lei Zhangbdf72c32015-08-14 19:24:08 -070021CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree,
22 CPDF_Bookmark bookmark,
Wei Li0e2e5d72016-03-03 11:28:06 -080023 const CFX_WideString& title,
24 std::set<CPDF_Dictionary*>* visited) {
25 // Return if already checked to avoid circular calling.
26 if (pdfium::ContainsKey(*visited, bookmark.GetDict()))
27 return CPDF_Bookmark();
28 visited->insert(bookmark.GetDict());
29
Wei Li0fc6b252016-03-01 16:29:41 -080030 if (bookmark.GetDict() &&
31 bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) {
Wei Li0e2e5d72016-03-03 11:28:06 -080032 // First check this item.
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 return bookmark;
34 }
Wei Li0e2e5d72016-03-03 11:28:06 -080035
36 // Go into children items.
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 CPDF_Bookmark child = tree.GetFirstChild(bookmark);
Wei Li0e2e5d72016-03-03 11:28:06 -080038 while (child.GetDict() && !pdfium::ContainsKey(*visited, child.GetDict())) {
39 // Check this item and its children.
40 CPDF_Bookmark found = FindBookmark(tree, child, title, visited);
Wei Li0fc6b252016-03-01 16:29:41 -080041 if (found.GetDict())
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 return found;
43 child = tree.GetNextSibling(child);
44 }
45 return CPDF_Bookmark();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046}
47
Lei Zhangbdf72c32015-08-14 19:24:08 -070048CPDF_LinkList* GetLinkList(CPDF_Page* page) {
49 if (!page)
50 return nullptr;
51
Lei Zhangbdf72c32015-08-14 19:24:08 -070052 CPDF_Document* pDoc = page->m_pDocument;
tsepez5ce09682016-05-25 16:16:32 -070053 std::unique_ptr<CPDF_LinkList>* pHolder = pDoc->LinksContext();
54 if (!pHolder->get())
55 pHolder->reset(new CPDF_LinkList);
56 return pHolder->get();
Lei Zhangbdf72c32015-08-14 19:24:08 -070057}
58
59} // namespace
60
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061DLLEXPORT FPDF_BOOKMARK STDCALL
62FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
Tom Sepez471a1032015-10-15 16:17:18 -070063 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
64 if (!pDoc)
65 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 CPDF_BookmarkTree tree(pDoc);
Dan Sinclairf1251c12015-10-20 16:24:45 -040067 CPDF_Bookmark bookmark =
68 CPDF_Bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 return tree.GetFirstChild(bookmark).GetDict();
Bo Xu4d62b6b2015-01-10 22:52:59 -080070}
71
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072DLLEXPORT FPDF_BOOKMARK STDCALL
73FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
Tom Sepez471a1032015-10-15 16:17:18 -070074 if (!pDict)
75 return nullptr;
76 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
77 if (!pDoc)
78 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 CPDF_BookmarkTree tree(pDoc);
Dan Sinclairf1251c12015-10-20 16:24:45 -040080 CPDF_Bookmark bookmark =
81 CPDF_Bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 return tree.GetNextSibling(bookmark).GetDict();
Bo Xu4d62b6b2015-01-10 22:52:59 -080083}
84
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict,
86 void* buffer,
87 unsigned long buflen) {
88 if (!pDict)
89 return 0;
Dan Sinclairf1251c12015-10-20 16:24:45 -040090 CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 CFX_WideString title = bookmark.GetTitle();
92 CFX_ByteString encodedTitle = title.UTF16LE_Encode();
93 unsigned long len = encodedTitle.GetLength();
94 if (buffer && buflen >= len) {
95 FXSYS_memcpy(buffer, encodedTitle.c_str(), len);
96 }
97 return len;
Bo Xu4d62b6b2015-01-10 22:52:59 -080098}
99
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document,
101 FPDF_WIDESTRING title) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 if (!title || title[0] == 0)
Tom Sepez471a1032015-10-15 16:17:18 -0700103 return nullptr;
104 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
105 if (!pDoc)
106 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 CPDF_BookmarkTree tree(pDoc);
108 FX_STRSIZE len = CFX_WideString::WStringLength(title);
109 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len);
Wei Li0e2e5d72016-03-03 11:28:06 -0800110 std::set<CPDF_Dictionary*> visited;
111 return FindBookmark(tree, CPDF_Bookmark(), encodedTitle, &visited).GetDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700112}
113
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document,
115 FPDF_BOOKMARK pDict) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 if (!pDict)
Tom Sepez471a1032015-10-15 16:17:18 -0700117 return nullptr;
118 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
119 if (!pDoc)
120 return nullptr;
Dan Sinclairf1251c12015-10-20 16:24:45 -0400121 CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122 CPDF_Dest dest = bookmark.GetDest(pDoc);
Wei Li0fc6b252016-03-01 16:29:41 -0800123 if (dest.GetObject())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124 return dest.GetObject();
125 // If this bookmark is not directly associated with a dest, we try to get
126 // action
127 CPDF_Action action = bookmark.GetAction();
Wei Li0fc6b252016-03-01 16:29:41 -0800128 if (!action.GetDict())
Tom Sepez471a1032015-10-15 16:17:18 -0700129 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700130 return action.GetDest(pDoc).GetObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700131}
132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) {
134 if (!pDict)
thestig1cd352e2016-06-07 17:53:06 -0700135 return nullptr;
Dan Sinclairf1251c12015-10-20 16:24:45 -0400136 CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137 return bookmark.GetAction().GetDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700138}
139
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) {
141 if (!pDict)
Lei Zhange0947b32015-09-17 14:51:48 -0700142 return PDFACTION_UNSUPPORTED;
143
Dan Sinclairf1251c12015-10-20 16:24:45 -0400144 CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 CPDF_Action::ActionType type = action.GetType();
146 switch (type) {
147 case CPDF_Action::GoTo:
148 return PDFACTION_GOTO;
149 case CPDF_Action::GoToR:
150 return PDFACTION_REMOTEGOTO;
151 case CPDF_Action::URI:
152 return PDFACTION_URI;
153 case CPDF_Action::Launch:
154 return PDFACTION_LAUNCH;
155 default:
156 return PDFACTION_UNSUPPORTED;
157 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700158}
159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document,
161 FPDF_ACTION pDict) {
Tom Sepez471a1032015-10-15 16:17:18 -0700162 if (!pDict)
Lei Zhange0947b32015-09-17 14:51:48 -0700163 return nullptr;
Tom Sepez471a1032015-10-15 16:17:18 -0700164 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
165 if (!pDoc)
166 return nullptr;
Dan Sinclairf1251c12015-10-20 16:24:45 -0400167 CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 return action.GetDest(pDoc).GetObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700169}
170
Dan Sinclairf766ad22016-03-14 13:51:24 -0400171DLLEXPORT unsigned long STDCALL FPDFAction_GetFilePath(FPDF_ACTION pDict,
172 void* buffer,
173 unsigned long buflen) {
Lei Zhange0947b32015-09-17 14:51:48 -0700174 unsigned long type = FPDFAction_GetType(pDict);
175 if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH)
176 return 0;
177
Dan Sinclairf1251c12015-10-20 16:24:45 -0400178 CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Lei Zhange0947b32015-09-17 14:51:48 -0700179 CFX_ByteString path = action.GetFilePath().UTF8Encode();
180 unsigned long len = path.GetLength() + 1;
181 if (buffer && buflen >= len)
182 FXSYS_memcpy(buffer, path.c_str(), len);
183 return len;
184}
185
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document,
187 FPDF_ACTION pDict,
188 void* buffer,
189 unsigned long buflen) {
Tom Sepez471a1032015-10-15 16:17:18 -0700190 if (!pDict)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 return 0;
Tom Sepez471a1032015-10-15 16:17:18 -0700192 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
193 if (!pDoc)
194 return 0;
Dan Sinclairf1251c12015-10-20 16:24:45 -0400195 CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 CFX_ByteString path = action.GetURI(pDoc);
197 unsigned long len = path.GetLength() + 1;
Lei Zhange0947b32015-09-17 14:51:48 -0700198 if (buffer && buflen >= len)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 FXSYS_memcpy(buffer, path.c_str(), len);
200 return len;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201}
202
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document,
204 FPDF_DEST pDict) {
Tom Sepez471a1032015-10-15 16:17:18 -0700205 if (!pDict)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 return 0;
Tom Sepez471a1032015-10-15 16:17:18 -0700207 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
208 if (!pDoc)
209 return 0;
Dan Sinclair2b11dc12015-10-22 15:02:06 -0400210 CPDF_Dest dest(static_cast<CPDF_Array*>(pDict));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 return dest.GetPageIndex(pDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700212}
213
Dan Sinclairf766ad22016-03-14 13:51:24 -0400214DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page,
215 double x,
216 double y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700217 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Lei Zhangbdf72c32015-08-14 19:24:08 -0700218 if (!pPage)
219 return nullptr;
220
221 CPDF_LinkList* pLinkList = GetLinkList(pPage);
222 if (!pLinkList)
223 return nullptr;
224
225 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, nullptr)
226 .GetDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227}
228
Dan Sinclairf766ad22016-03-14 13:51:24 -0400229DLLEXPORT int STDCALL FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page,
230 double x,
231 double y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700232 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233 if (!pPage)
Lei Zhangbdf72c32015-08-14 19:24:08 -0700234 return -1;
235
236 CPDF_LinkList* pLinkList = GetLinkList(pPage);
237 if (!pLinkList)
238 return -1;
239
240 int z_order = -1;
241 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order);
242 return z_order;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243}
244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document,
246 FPDF_LINK pDict) {
Tom Sepez471a1032015-10-15 16:17:18 -0700247 if (!pDict)
Lei Zhange0947b32015-09-17 14:51:48 -0700248 return nullptr;
Tom Sepez471a1032015-10-15 16:17:18 -0700249 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
250 if (!pDoc)
251 return nullptr;
Dan Sinclairf1251c12015-10-20 16:24:45 -0400252 CPDF_Link link(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253 FPDF_DEST dest = link.GetDest(pDoc).GetObject();
254 if (dest)
255 return dest;
256 // If this link is not directly associated with a dest, we try to get action
257 CPDF_Action action = link.GetAction();
Wei Li0fc6b252016-03-01 16:29:41 -0800258 if (!action.GetDict())
Lei Zhange0947b32015-09-17 14:51:48 -0700259 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 return action.GetDest(pDoc).GetObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700261}
262
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) {
264 if (!pDict)
Lei Zhange0947b32015-09-17 14:51:48 -0700265 return nullptr;
266
Dan Sinclairf1251c12015-10-20 16:24:45 -0400267 CPDF_Link link(ToDictionary(static_cast<CPDF_Object*>(pDict)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 return link.GetAction().GetDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269}
270
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page,
272 int* startPos,
273 FPDF_LINK* linkAnnot) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700274 if (!startPos || !linkAnnot)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700275 return FALSE;
Tom Sepezdb0be962015-10-16 14:00:21 -0700276 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
277 if (!pPage || !pPage->m_pFormDict)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 return FALSE;
dsinclair38fd8442016-09-15 10:15:32 -0700279 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayFor("Annots");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 if (!pAnnots)
281 return FALSE;
Wei Lie1aebd42016-04-11 10:02:09 -0700282 for (size_t i = *startPos; i < pAnnots->GetCount(); i++) {
Dan Sinclairf1251c12015-10-20 16:24:45 -0400283 CPDF_Dictionary* pDict =
tsepezbd567552016-03-29 14:51:50 -0700284 ToDictionary(static_cast<CPDF_Object*>(pAnnots->GetDirectObjectAt(i)));
Dan Sinclairf1251c12015-10-20 16:24:45 -0400285 if (!pDict)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286 continue;
dsinclair38fd8442016-09-15 10:15:32 -0700287 if (pDict->GetStringFor("Subtype") == "Link") {
Wei Lie1aebd42016-04-11 10:02:09 -0700288 *startPos = static_cast<int>(i + 1);
289 *linkAnnot = static_cast<FPDF_LINK>(pDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 return TRUE;
291 }
292 }
293 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700294}
295
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot,
297 FS_RECTF* rect) {
298 if (!linkAnnot || !rect)
299 return FALSE;
Dan Sinclairf1251c12015-10-20 16:24:45 -0400300 CPDF_Dictionary* pAnnotDict =
301 ToDictionary(static_cast<CPDF_Object*>(linkAnnot));
dsinclair38fd8442016-09-15 10:15:32 -0700302 CFX_FloatRect rt = pAnnotDict->GetRectFor("Rect");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 rect->left = rt.left;
304 rect->bottom = rt.bottom;
305 rect->right = rt.right;
306 rect->top = rt.top;
307 return TRUE;
308}
309
310DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot) {
311 if (!linkAnnot)
312 return 0;
Dan Sinclairf1251c12015-10-20 16:24:45 -0400313 CPDF_Dictionary* pAnnotDict =
314 ToDictionary(static_cast<CPDF_Object*>(linkAnnot));
dsinclair38fd8442016-09-15 10:15:32 -0700315 CPDF_Array* pArray = pAnnotDict->GetArrayFor("QuadPoints");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316 if (!pArray)
317 return 0;
Wei Lie1aebd42016-04-11 10:02:09 -0700318 return static_cast<int>(pArray->GetCount() / 8);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319}
320
321DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot,
322 int quadIndex,
323 FS_QUADPOINTSF* quadPoints) {
324 if (!linkAnnot || !quadPoints)
325 return FALSE;
Dan Sinclairf1251c12015-10-20 16:24:45 -0400326 CPDF_Dictionary* pAnnotDict =
327 ToDictionary(static_cast<CPDF_Object*>(linkAnnot));
dsinclair38fd8442016-09-15 10:15:32 -0700328 CPDF_Array* pArray = pAnnotDict->GetArrayFor("QuadPoints");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329 if (pArray) {
Wei Lie1aebd42016-04-11 10:02:09 -0700330 if (quadIndex < 0 ||
331 static_cast<size_t>(quadIndex) >= pArray->GetCount() / 8 ||
332 (static_cast<size_t>(quadIndex * 8 + 7) >= pArray->GetCount()))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 return FALSE;
Wei Li9b761132016-01-29 15:44:20 -0800334 quadPoints->x1 = pArray->GetNumberAt(quadIndex * 8);
335 quadPoints->y1 = pArray->GetNumberAt(quadIndex * 8 + 1);
336 quadPoints->x2 = pArray->GetNumberAt(quadIndex * 8 + 2);
337 quadPoints->y2 = pArray->GetNumberAt(quadIndex * 8 + 3);
338 quadPoints->x3 = pArray->GetNumberAt(quadIndex * 8 + 4);
339 quadPoints->y3 = pArray->GetNumberAt(quadIndex * 8 + 5);
340 quadPoints->x4 = pArray->GetNumberAt(quadIndex * 8 + 6);
341 quadPoints->y4 = pArray->GetNumberAt(quadIndex * 8 + 7);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700342 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343 }
344 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700345}
346
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700347DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc,
348 FPDF_BYTESTRING tag,
349 void* buffer,
350 unsigned long buflen) {
Tom Sepez471a1032015-10-15 16:17:18 -0700351 if (!tag)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352 return 0;
Tom Sepez471a1032015-10-15 16:17:18 -0700353 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc);
354 if (!pDoc)
355 return 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356 CPDF_Dictionary* pInfo = pDoc->GetInfo();
357 if (!pInfo)
358 return 0;
dsinclair38fd8442016-09-15 10:15:32 -0700359 CFX_WideString text = pInfo->GetUnicodeTextFor(tag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 // Use UTF-16LE encoding
361 CFX_ByteString encodedText = text.UTF16LE_Encode();
362 unsigned long len = encodedText.GetLength();
363 if (buffer && buflen >= len) {
364 FXSYS_memcpy(buffer, encodedText.c_str(), len);
365 }
366 return len;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367}