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 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 if (!pHolder->get()) | 57 if (!pHolder->get()) |
58 pHolder->reset(new CPDF_LinkList); | 58 pHolder->reset(new CPDF_LinkList); |
59 return pHolder->get(); | 59 return pHolder->get(); |
60 } | 60 } |
61 | 61 |
62 unsigned long Utf16EncodeMaybeCopyAndReturnLength(const CFX_WideString& text, | 62 unsigned long Utf16EncodeMaybeCopyAndReturnLength(const CFX_WideString& text, |
63 void* buffer, | 63 void* buffer, |
64 unsigned long buflen) { | 64 unsigned long buflen) { |
65 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 65 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
66 unsigned long len = encodedText.GetLength(); | 66 unsigned long len = encodedText.GetLength(); |
67 if (buffer && buflen >= len) | 67 if (buffer && len <= buflen) |
68 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 68 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
69 return len; | 69 return len; |
70 } | 70 } |
71 | 71 |
72 } // namespace | 72 } // namespace |
73 | 73 |
74 DLLEXPORT FPDF_BOOKMARK STDCALL | 74 DLLEXPORT FPDF_BOOKMARK STDCALL |
75 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { | 75 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
76 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 76 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
77 if (!pDoc) | 77 if (!pDoc) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 DLLEXPORT unsigned long STDCALL FPDFAction_GetFilePath(FPDF_ACTION pDict, | 179 DLLEXPORT unsigned long STDCALL FPDFAction_GetFilePath(FPDF_ACTION pDict, |
180 void* buffer, | 180 void* buffer, |
181 unsigned long buflen) { | 181 unsigned long buflen) { |
182 unsigned long type = FPDFAction_GetType(pDict); | 182 unsigned long type = FPDFAction_GetType(pDict); |
183 if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) | 183 if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) |
184 return 0; | 184 return 0; |
185 | 185 |
186 CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict))); | 186 CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
187 CFX_ByteString path = action.GetFilePath().UTF8Encode(); | 187 CFX_ByteString path = action.GetFilePath().UTF8Encode(); |
188 unsigned long len = path.GetLength() + 1; | 188 unsigned long len = path.GetLength() + 1; |
189 if (buffer && buflen >= len) | 189 if (buffer && len <= buflen) |
190 FXSYS_memcpy(buffer, path.c_str(), len); | 190 FXSYS_memcpy(buffer, path.c_str(), len); |
191 return len; | 191 return len; |
192 } | 192 } |
193 | 193 |
194 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, | 194 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, |
195 FPDF_ACTION pDict, | 195 FPDF_ACTION pDict, |
196 void* buffer, | 196 void* buffer, |
197 unsigned long buflen) { | 197 unsigned long buflen) { |
198 if (!pDict) | 198 if (!pDict) |
199 return 0; | 199 return 0; |
200 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 200 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
201 if (!pDoc) | 201 if (!pDoc) |
202 return 0; | 202 return 0; |
203 CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict))); | 203 CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict))); |
204 CFX_ByteString path = action.GetURI(pDoc); | 204 CFX_ByteString path = action.GetURI(pDoc); |
205 unsigned long len = path.GetLength() + 1; | 205 unsigned long len = path.GetLength() + 1; |
206 if (buffer && buflen >= len) | 206 if (buffer && len <= buflen) |
207 FXSYS_memcpy(buffer, path.c_str(), len); | 207 FXSYS_memcpy(buffer, path.c_str(), len); |
208 return len; | 208 return len; |
209 } | 209 } |
210 | 210 |
211 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, | 211 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, |
212 FPDF_DEST pDict) { | 212 FPDF_DEST pDict) { |
213 if (!pDict) | 213 if (!pDict) |
214 return 0; | 214 return 0; |
215 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 215 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
216 if (!pDoc) | 216 if (!pDoc) |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 if (page_index < 0) | 403 if (page_index < 0) |
404 return 0; | 404 return 0; |
405 | 405 |
406 // CPDF_PageLabel can deal with NULL |document|. | 406 // CPDF_PageLabel can deal with NULL |document|. |
407 CPDF_PageLabel label(CPDFDocumentFromFPDFDocument(document)); | 407 CPDF_PageLabel label(CPDFDocumentFromFPDFDocument(document)); |
408 CFX_WideString str; | 408 CFX_WideString str; |
409 if (!label.GetLabel(page_index, &str)) | 409 if (!label.GetLabel(page_index, &str)) |
410 return 0; | 410 return 0; |
411 return Utf16EncodeMaybeCopyAndReturnLength(str, buffer, buflen); | 411 return Utf16EncodeMaybeCopyAndReturnLength(str, buffer, buflen); |
412 } | 412 } |
OLD | NEW |