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 "../../public/fpdf_doc.h" | 7 #include "../../public/fpdf_doc.h" |
8 #include "../include/fsdk_define.h" | 8 #include "../include/fsdk_define.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 pLinkList = new CPDF_LinkList; | 45 pLinkList = new CPDF_LinkList; |
46 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); | 46 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); |
47 } | 47 } |
48 return pLinkList; | 48 return pLinkList; |
49 } | 49 } |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 DLLEXPORT FPDF_BOOKMARK STDCALL | 53 DLLEXPORT FPDF_BOOKMARK STDCALL |
54 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { | 54 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
55 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); | 55 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
56 if (!pDoc) | 56 if (!pDoc) |
57 return nullptr; | 57 return nullptr; |
58 CPDF_BookmarkTree tree(pDoc); | 58 CPDF_BookmarkTree tree(pDoc); |
59 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 59 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
60 return tree.GetFirstChild(bookmark).GetDict(); | 60 return tree.GetFirstChild(bookmark).GetDict(); |
61 } | 61 } |
62 | 62 |
63 DLLEXPORT FPDF_BOOKMARK STDCALL | 63 DLLEXPORT FPDF_BOOKMARK STDCALL |
64 FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { | 64 FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
65 if (!pDict) | 65 if (!pDict) |
66 return nullptr; | 66 return nullptr; |
67 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); | 67 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
68 if (!pDoc) | 68 if (!pDoc) |
69 return nullptr; | 69 return nullptr; |
70 CPDF_BookmarkTree tree(pDoc); | 70 CPDF_BookmarkTree tree(pDoc); |
71 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 71 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
72 return tree.GetNextSibling(bookmark).GetDict(); | 72 return tree.GetNextSibling(bookmark).GetDict(); |
73 } | 73 } |
74 | 74 |
75 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, | 75 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, |
76 void* buffer, | 76 void* buffer, |
77 unsigned long buflen) { | 77 unsigned long buflen) { |
78 if (!pDict) | 78 if (!pDict) |
79 return 0; | 79 return 0; |
80 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 80 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
81 CFX_WideString title = bookmark.GetTitle(); | 81 CFX_WideString title = bookmark.GetTitle(); |
82 CFX_ByteString encodedTitle = title.UTF16LE_Encode(); | 82 CFX_ByteString encodedTitle = title.UTF16LE_Encode(); |
83 unsigned long len = encodedTitle.GetLength(); | 83 unsigned long len = encodedTitle.GetLength(); |
84 if (buffer && buflen >= len) { | 84 if (buffer && buflen >= len) { |
85 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); | 85 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); |
86 } | 86 } |
87 return len; | 87 return len; |
88 } | 88 } |
89 | 89 |
90 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, | 90 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, |
91 FPDF_WIDESTRING title) { | 91 FPDF_WIDESTRING title) { |
92 if (!title || title[0] == 0) | 92 if (!title || title[0] == 0) |
93 return nullptr; | 93 return nullptr; |
94 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); | 94 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
95 if (!pDoc) | 95 if (!pDoc) |
96 return nullptr; | 96 return nullptr; |
97 CPDF_BookmarkTree tree(pDoc); | 97 CPDF_BookmarkTree tree(pDoc); |
98 FX_STRSIZE len = CFX_WideString::WStringLength(title); | 98 FX_STRSIZE len = CFX_WideString::WStringLength(title); |
99 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); | 99 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); |
100 return FindBookmark(tree, CPDF_Bookmark(), encodedTitle).GetDict(); | 100 return FindBookmark(tree, CPDF_Bookmark(), encodedTitle).GetDict(); |
101 } | 101 } |
102 | 102 |
103 DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, | 103 DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, |
104 FPDF_BOOKMARK pDict) { | 104 FPDF_BOOKMARK pDict) { |
105 if (!pDict) | 105 if (!pDict) |
106 return nullptr; | 106 return nullptr; |
107 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); | 107 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
108 if (!pDoc) | 108 if (!pDoc) |
109 return nullptr; | 109 return nullptr; |
110 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 110 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
111 CPDF_Dest dest = bookmark.GetDest(pDoc); | 111 CPDF_Dest dest = bookmark.GetDest(pDoc); |
112 if (dest) | 112 if (dest) |
113 return dest.GetObject(); | 113 return dest.GetObject(); |
114 // If this bookmark is not directly associated with a dest, we try to get | 114 // If this bookmark is not directly associated with a dest, we try to get |
115 // action | 115 // action |
116 CPDF_Action action = bookmark.GetAction(); | 116 CPDF_Action action = bookmark.GetAction(); |
117 if (!action) | 117 if (!action) |
(...skipping 25 matching lines...) Expand all Loading... |
143 return PDFACTION_LAUNCH; | 143 return PDFACTION_LAUNCH; |
144 default: | 144 default: |
145 return PDFACTION_UNSUPPORTED; | 145 return PDFACTION_UNSUPPORTED; |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, | 149 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, |
150 FPDF_ACTION pDict) { | 150 FPDF_ACTION pDict) { |
151 if (!pDict) | 151 if (!pDict) |
152 return nullptr; | 152 return nullptr; |
153 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); | 153 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
154 if (!pDoc) | 154 if (!pDoc) |
155 return nullptr; | 155 return nullptr; |
156 CPDF_Action action((CPDF_Dictionary*)pDict); | 156 CPDF_Action action((CPDF_Dictionary*)pDict); |
157 return action.GetDest(pDoc).GetObject(); | 157 return action.GetDest(pDoc).GetObject(); |
158 } | 158 } |
159 | 159 |
160 DLLEXPORT unsigned long STDCALL | 160 DLLEXPORT unsigned long STDCALL |
161 FPDFAction_GetFilePath(FPDF_ACTION pDict, void* buffer, unsigned long buflen) { | 161 FPDFAction_GetFilePath(FPDF_ACTION pDict, void* buffer, unsigned long buflen) { |
162 unsigned long type = FPDFAction_GetType(pDict); | 162 unsigned long type = FPDFAction_GetType(pDict); |
163 if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) | 163 if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) |
164 return 0; | 164 return 0; |
165 | 165 |
166 CPDF_Action action((CPDF_Dictionary*)pDict); | 166 CPDF_Action action((CPDF_Dictionary*)pDict); |
167 CFX_ByteString path = action.GetFilePath().UTF8Encode(); | 167 CFX_ByteString path = action.GetFilePath().UTF8Encode(); |
168 unsigned long len = path.GetLength() + 1; | 168 unsigned long len = path.GetLength() + 1; |
169 if (buffer && buflen >= len) | 169 if (buffer && buflen >= len) |
170 FXSYS_memcpy(buffer, path.c_str(), len); | 170 FXSYS_memcpy(buffer, path.c_str(), len); |
171 return len; | 171 return len; |
172 } | 172 } |
173 | 173 |
174 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, | 174 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, |
175 FPDF_ACTION pDict, | 175 FPDF_ACTION pDict, |
176 void* buffer, | 176 void* buffer, |
177 unsigned long buflen) { | 177 unsigned long buflen) { |
178 if (!pDict) | 178 if (!pDict) |
179 return 0; | 179 return 0; |
180 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); | 180 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
181 if (!pDoc) | 181 if (!pDoc) |
182 return 0; | 182 return 0; |
183 CPDF_Action action((CPDF_Dictionary*)pDict); | 183 CPDF_Action action((CPDF_Dictionary*)pDict); |
184 CFX_ByteString path = action.GetURI(pDoc); | 184 CFX_ByteString path = action.GetURI(pDoc); |
185 unsigned long len = path.GetLength() + 1; | 185 unsigned long len = path.GetLength() + 1; |
186 if (buffer && buflen >= len) | 186 if (buffer && buflen >= len) |
187 FXSYS_memcpy(buffer, path.c_str(), len); | 187 FXSYS_memcpy(buffer, path.c_str(), len); |
188 return len; | 188 return len; |
189 } | 189 } |
190 | 190 |
191 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, | 191 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, |
192 FPDF_DEST pDict) { | 192 FPDF_DEST pDict) { |
193 if (!pDict) | 193 if (!pDict) |
194 return 0; | 194 return 0; |
195 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); | 195 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
196 if (!pDoc) | 196 if (!pDoc) |
197 return 0; | 197 return 0; |
198 CPDF_Dest dest((CPDF_Array*)pDict); | 198 CPDF_Dest dest((CPDF_Array*)pDict); |
199 return dest.GetPageIndex(pDoc); | 199 return dest.GetPageIndex(pDoc); |
200 } | 200 } |
201 | 201 |
202 DLLEXPORT FPDF_LINK STDCALL | 202 DLLEXPORT FPDF_LINK STDCALL |
203 FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { | 203 FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { |
204 CPDF_Page* pPage = (CPDF_Page*)page; | 204 CPDF_Page* pPage = (CPDF_Page*)page; |
205 CPDF_LinkList* pLinkList = GetLinkList(pPage); | 205 CPDF_LinkList* pLinkList = GetLinkList(pPage); |
(...skipping 13 matching lines...) Expand all Loading... |
219 | 219 |
220 int z_order = -1; | 220 int z_order = -1; |
221 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); | 221 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); |
222 return z_order; | 222 return z_order; |
223 } | 223 } |
224 | 224 |
225 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, | 225 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, |
226 FPDF_LINK pDict) { | 226 FPDF_LINK pDict) { |
227 if (!pDict) | 227 if (!pDict) |
228 return nullptr; | 228 return nullptr; |
229 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); | 229 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
230 if (!pDoc) | 230 if (!pDoc) |
231 return nullptr; | 231 return nullptr; |
232 CPDF_Link link((CPDF_Dictionary*)pDict); | 232 CPDF_Link link((CPDF_Dictionary*)pDict); |
233 FPDF_DEST dest = link.GetDest(pDoc).GetObject(); | 233 FPDF_DEST dest = link.GetDest(pDoc).GetObject(); |
234 if (dest) | 234 if (dest) |
235 return dest; | 235 return dest; |
236 // If this link is not directly associated with a dest, we try to get action | 236 // If this link is not directly associated with a dest, we try to get action |
237 CPDF_Action action = link.GetAction(); | 237 CPDF_Action action = link.GetAction(); |
238 if (!action) | 238 if (!action) |
239 return nullptr; | 239 return nullptr; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 } | 318 } |
319 return FALSE; | 319 return FALSE; |
320 } | 320 } |
321 | 321 |
322 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, | 322 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, |
323 FPDF_BYTESTRING tag, | 323 FPDF_BYTESTRING tag, |
324 void* buffer, | 324 void* buffer, |
325 unsigned long buflen) { | 325 unsigned long buflen) { |
326 if (!tag) | 326 if (!tag) |
327 return 0; | 327 return 0; |
328 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(doc); | 328 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); |
329 if (!pDoc) | 329 if (!pDoc) |
330 return 0; | 330 return 0; |
331 CPDF_Dictionary* pInfo = pDoc->GetInfo(); | 331 CPDF_Dictionary* pInfo = pDoc->GetInfo(); |
332 if (!pInfo) | 332 if (!pInfo) |
333 return 0; | 333 return 0; |
334 CFX_WideString text = pInfo->GetUnicodeText(tag); | 334 CFX_WideString text = pInfo->GetUnicodeText(tag); |
335 // Use UTF-16LE encoding | 335 // Use UTF-16LE encoding |
336 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 336 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
337 unsigned long len = encodedText.GetLength(); | 337 unsigned long len = encodedText.GetLength(); |
338 if (buffer && buflen >= len) { | 338 if (buffer && buflen >= len) { |
339 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 339 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
340 } | 340 } |
341 return len; | 341 return len; |
342 } | 342 } |
OLD | NEW |