| 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> |
| 11 | 11 |
| 12 #include "core/fpdfapi/page/cpdf_page.h" | 12 #include "core/fpdfapi/page/cpdf_page.h" |
| 13 #include "core/fpdfapi/parser/cpdf_array.h" | 13 #include "core/fpdfapi/parser/cpdf_array.h" |
| 14 #include "core/fpdfapi/parser/cpdf_document.h" | 14 #include "core/fpdfapi/parser/cpdf_document.h" |
| 15 #include "core/fpdfdoc/cpdf_bookmark.h" | 15 #include "core/fpdfdoc/cpdf_bookmark.h" |
| 16 #include "core/fpdfdoc/cpdf_bookmarktree.h" | 16 #include "core/fpdfdoc/cpdf_bookmarktree.h" |
| 17 #include "core/fpdfdoc/cpdf_dest.h" | 17 #include "core/fpdfdoc/cpdf_dest.h" |
| 18 #include "core/fpdfdoc/cpdf_pagelabel.h" | 18 #include "core/fpdfdoc/cpdf_pagelabel.h" |
| 19 #include "fpdfsdk/fsdk_define.h" | 19 #include "fpdfsdk/fsdk_define.h" |
| 20 #include "third_party/base/ptr_util.h" |
| 20 #include "third_party/base/stl_util.h" | 21 #include "third_party/base/stl_util.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, | 25 CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, |
| 25 CPDF_Bookmark bookmark, | 26 CPDF_Bookmark bookmark, |
| 26 const CFX_WideString& title, | 27 const CFX_WideString& title, |
| 27 std::set<CPDF_Dictionary*>* visited) { | 28 std::set<CPDF_Dictionary*>* visited) { |
| 28 // Return if already checked to avoid circular calling. | 29 // Return if already checked to avoid circular calling. |
| 29 if (pdfium::ContainsKey(*visited, bookmark.GetDict())) | 30 if (pdfium::ContainsKey(*visited, bookmark.GetDict())) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 48 return CPDF_Bookmark(); | 49 return CPDF_Bookmark(); |
| 49 } | 50 } |
| 50 | 51 |
| 51 CPDF_LinkList* GetLinkList(CPDF_Page* page) { | 52 CPDF_LinkList* GetLinkList(CPDF_Page* page) { |
| 52 if (!page) | 53 if (!page) |
| 53 return nullptr; | 54 return nullptr; |
| 54 | 55 |
| 55 CPDF_Document* pDoc = page->m_pDocument; | 56 CPDF_Document* pDoc = page->m_pDocument; |
| 56 std::unique_ptr<CPDF_LinkList>* pHolder = pDoc->LinksContext(); | 57 std::unique_ptr<CPDF_LinkList>* pHolder = pDoc->LinksContext(); |
| 57 if (!pHolder->get()) | 58 if (!pHolder->get()) |
| 58 pHolder->reset(new CPDF_LinkList); | 59 *pHolder = pdfium::MakeUnique<CPDF_LinkList>(); |
| 59 return pHolder->get(); | 60 return pHolder->get(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 unsigned long Utf16EncodeMaybeCopyAndReturnLength(const CFX_WideString& text, | 63 unsigned long Utf16EncodeMaybeCopyAndReturnLength(const CFX_WideString& text, |
| 63 void* buffer, | 64 void* buffer, |
| 64 unsigned long buflen) { | 65 unsigned long buflen) { |
| 65 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 66 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 66 unsigned long len = encodedText.GetLength(); | 67 unsigned long len = encodedText.GetLength(); |
| 67 if (buffer && len <= buflen) | 68 if (buffer && len <= buflen) |
| 68 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 69 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 if (page_index < 0) | 404 if (page_index < 0) |
| 404 return 0; | 405 return 0; |
| 405 | 406 |
| 406 // CPDF_PageLabel can deal with NULL |document|. | 407 // CPDF_PageLabel can deal with NULL |document|. |
| 407 CPDF_PageLabel label(CPDFDocumentFromFPDFDocument(document)); | 408 CPDF_PageLabel label(CPDFDocumentFromFPDFDocument(document)); |
| 408 CFX_WideString str; | 409 CFX_WideString str; |
| 409 if (!label.GetLabel(page_index, &str)) | 410 if (!label.GetLabel(page_index, &str)) |
| 410 return 0; | 411 return 0; |
| 411 return Utf16EncodeMaybeCopyAndReturnLength(str, buffer, buflen); | 412 return Utf16EncodeMaybeCopyAndReturnLength(str, buffer, buflen); |
| 412 } | 413 } |
| OLD | NEW |