OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
8 #include "../../public/fpdf_doc.h" | 8 #include "../../public/fpdf_doc.h" |
9 | 9 |
10 static int THISMODULE = 0; | 10 namespace { |
11 | 11 |
12 static CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, | 12 int THISMODULE = 0; |
13 CPDF_Bookmark bookmark, | 13 |
14 const CFX_WideString& title) { | 14 CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, |
| 15 CPDF_Bookmark bookmark, |
| 16 const CFX_WideString& title) { |
15 if (bookmark && bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { | 17 if (bookmark && bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { |
16 // First check this item | 18 // First check this item |
17 return bookmark; | 19 return bookmark; |
18 } | 20 } |
19 // go into children items | 21 // go into children items |
20 CPDF_Bookmark child = tree.GetFirstChild(bookmark); | 22 CPDF_Bookmark child = tree.GetFirstChild(bookmark); |
21 while (child) { | 23 while (child) { |
22 // check if this item | 24 // check if this item |
23 CPDF_Bookmark found = FindBookmark(tree, child, title); | 25 CPDF_Bookmark found = FindBookmark(tree, child, title); |
24 if (found) | 26 if (found) |
25 return found; | 27 return found; |
26 child = tree.GetNextSibling(child); | 28 child = tree.GetNextSibling(child); |
27 } | 29 } |
28 return CPDF_Bookmark(); | 30 return CPDF_Bookmark(); |
29 } | 31 } |
30 | 32 |
| 33 void ReleaseLinkList(void* data) { |
| 34 delete (CPDF_LinkList*)data; |
| 35 } |
| 36 |
| 37 CPDF_LinkList* GetLinkList(CPDF_Page* page) { |
| 38 if (!page) |
| 39 return nullptr; |
| 40 |
| 41 // Link list is stored with the document |
| 42 CPDF_Document* pDoc = page->m_pDocument; |
| 43 CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE); |
| 44 if (!pLinkList) { |
| 45 pLinkList = new CPDF_LinkList; |
| 46 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); |
| 47 } |
| 48 return pLinkList; |
| 49 } |
| 50 |
| 51 } // namespace |
| 52 |
31 DLLEXPORT FPDF_BOOKMARK STDCALL | 53 DLLEXPORT FPDF_BOOKMARK STDCALL |
32 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { | 54 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
33 if (!document) | 55 if (!document) |
34 return NULL; | 56 return NULL; |
35 CPDF_Document* pDoc = (CPDF_Document*)document; | 57 CPDF_Document* pDoc = (CPDF_Document*)document; |
36 CPDF_BookmarkTree tree(pDoc); | 58 CPDF_BookmarkTree tree(pDoc); |
37 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 59 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
38 return tree.GetFirstChild(bookmark).GetDict(); | 60 return tree.GetFirstChild(bookmark).GetDict(); |
39 } | 61 } |
40 | 62 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 FPDF_DEST pDict) { | 176 FPDF_DEST pDict) { |
155 if (!document) | 177 if (!document) |
156 return 0; | 178 return 0; |
157 if (!pDict) | 179 if (!pDict) |
158 return 0; | 180 return 0; |
159 CPDF_Document* pDoc = (CPDF_Document*)document; | 181 CPDF_Document* pDoc = (CPDF_Document*)document; |
160 CPDF_Dest dest((CPDF_Array*)pDict); | 182 CPDF_Dest dest((CPDF_Array*)pDict); |
161 return dest.GetPageIndex(pDoc); | 183 return dest.GetPageIndex(pDoc); |
162 } | 184 } |
163 | 185 |
164 static void ReleaseLinkList(void* data) { | 186 DLLEXPORT FPDF_LINK STDCALL |
165 delete (CPDF_LinkList*)data; | 187 FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { |
| 188 CPDF_Page* pPage = (CPDF_Page*)page; |
| 189 CPDF_LinkList* pLinkList = GetLinkList(pPage); |
| 190 if (!pLinkList) |
| 191 return nullptr; |
| 192 |
| 193 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, nullptr) |
| 194 .GetDict(); |
166 } | 195 } |
167 | 196 |
168 DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, | 197 DLLEXPORT int STDCALL |
169 double x, | 198 FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, double x, double y) { |
170 double y) { | |
171 if (!page) | |
172 return NULL; | |
173 CPDF_Page* pPage = (CPDF_Page*)page; | 199 CPDF_Page* pPage = (CPDF_Page*)page; |
174 // Link list is stored with the document | 200 CPDF_LinkList* pLinkList = GetLinkList(pPage); |
175 CPDF_Document* pDoc = pPage->m_pDocument; | 201 if (!pLinkList) |
176 CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE); | 202 return -1; |
177 if (!pLinkList) { | 203 |
178 pLinkList = new CPDF_LinkList(pDoc); | 204 int z_order = -1; |
179 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); | 205 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); |
180 } | 206 return z_order; |
181 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y).GetDict(); | |
182 } | 207 } |
183 | 208 |
184 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, | 209 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, |
185 FPDF_LINK pDict) { | 210 FPDF_LINK pDict) { |
186 if (!document) | 211 if (!document) |
187 return NULL; | 212 return NULL; |
188 if (!pDict) | 213 if (!pDict) |
189 return NULL; | 214 return NULL; |
190 CPDF_Document* pDoc = (CPDF_Document*)document; | 215 CPDF_Document* pDoc = (CPDF_Document*)document; |
191 CPDF_Link link((CPDF_Dictionary*)pDict); | 216 CPDF_Link link((CPDF_Dictionary*)pDict); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 return 0; | 315 return 0; |
291 CFX_WideString text = pInfo->GetUnicodeText(tag); | 316 CFX_WideString text = pInfo->GetUnicodeText(tag); |
292 // Use UTF-16LE encoding | 317 // Use UTF-16LE encoding |
293 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 318 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
294 unsigned long len = encodedText.GetLength(); | 319 unsigned long len = encodedText.GetLength(); |
295 if (buffer && buflen >= len) { | 320 if (buffer && buflen >= len) { |
296 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 321 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
297 } | 322 } |
298 return len; | 323 return len; |
299 } | 324 } |
OLD | NEW |