| 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 <vector> |
| 8 |
| 9 #include "../../../third_party/base/nonstd_unique_ptr.h" |
| 7 #include "../../include/fpdfdoc/fpdf_doc.h" | 10 #include "../../include/fpdfdoc/fpdf_doc.h" |
| 11 |
| 8 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(const CPDF_Bookmark& parent) cons
t | 12 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(const CPDF_Bookmark& parent) cons
t |
| 9 { | 13 { |
| 10 if (!parent.m_pDict) { | 14 if (!parent.m_pDict) { |
| 11 CPDF_Dictionary* pRoot = m_pDocument->GetRoot()->GetDict("Outlines"); | 15 CPDF_Dictionary* pRoot = m_pDocument->GetRoot()->GetDict("Outlines"); |
| 12 if (!pRoot) { | 16 if (!pRoot) { |
| 13 return CPDF_Bookmark(); | 17 return CPDF_Bookmark(); |
| 14 } | 18 } |
| 15 return CPDF_Bookmark(pRoot->GetDict("First")); | 19 return CPDF_Bookmark(pRoot->GetDict("First")); |
| 16 } | 20 } |
| 17 return CPDF_Bookmark(parent.m_pDict->GetDict("First")); | 21 return CPDF_Bookmark(parent.m_pDict->GetDict("First")); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 48 CFX_WideString CPDF_Bookmark::GetTitle() const | 52 CFX_WideString CPDF_Bookmark::GetTitle() const |
| 49 { | 53 { |
| 50 if (!m_pDict) { | 54 if (!m_pDict) { |
| 51 return CFX_WideString(); | 55 return CFX_WideString(); |
| 52 } | 56 } |
| 53 CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title"); | 57 CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title"); |
| 54 if (!pString || pString->GetType() != PDFOBJ_STRING) { | 58 if (!pString || pString->GetType() != PDFOBJ_STRING) { |
| 55 return CFX_WideString(); | 59 return CFX_WideString(); |
| 56 } | 60 } |
| 57 CFX_WideString title = pString->GetUnicodeText(); | 61 CFX_WideString title = pString->GetUnicodeText(); |
| 58 FX_LPWSTR buf = title.LockBuffer(); | |
| 59 int len = title.GetLength(); | 62 int len = title.GetLength(); |
| 63 if (!len) { |
| 64 return CFX_WideString(); |
| 65 } |
| 66 nonstd::unique_ptr<std::vector<FX_WCHAR> > vec; |
| 67 vec.reset(new std::vector<FX_WCHAR>(len)); |
| 68 FX_WCHAR* buf = &vec->front(); |
| 60 for (int i = 0; i < len; i++) { | 69 for (int i = 0; i < len; i++) { |
| 61 if (buf[i] < 0x20) { | 70 FX_WCHAR w = title[i]; |
| 62 buf[i] = 0x20; | 71 buf[i] = w > 0x20 ? w : 0x20; |
| 63 } | |
| 64 } | 72 } |
| 65 title.ReleaseBuffer(len); | 73 return CFX_WideString(buf, len); |
| 66 return title; | |
| 67 } | 74 } |
| 68 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const | 75 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const |
| 69 { | 76 { |
| 70 if (!m_pDict) { | 77 if (!m_pDict) { |
| 71 return CPDF_Dest(); | 78 return CPDF_Dest(); |
| 72 } | 79 } |
| 73 CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); | 80 CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); |
| 74 if (!pDest) { | 81 if (!pDest) { |
| 75 return CPDF_Dest(); | 82 return CPDF_Dest(); |
| 76 } | 83 } |
| 77 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { | 84 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { |
| 78 CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests")); | 85 CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests")); |
| 79 CFX_ByteStringC name = pDest->GetString(); | 86 CFX_ByteStringC name = pDest->GetString(); |
| 80 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name)); | 87 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name)); |
| 81 } | 88 } |
| 82 if (pDest->GetType() == PDFOBJ_ARRAY) { | 89 if (pDest->GetType() == PDFOBJ_ARRAY) { |
| 83 return CPDF_Dest((CPDF_Array*)pDest); | 90 return CPDF_Dest((CPDF_Array*)pDest); |
| 84 } | 91 } |
| 85 return CPDF_Dest(); | 92 return CPDF_Dest(); |
| 86 } | 93 } |
| 87 CPDF_Action CPDF_Bookmark::GetAction() const | 94 CPDF_Action CPDF_Bookmark::GetAction() const |
| 88 { | 95 { |
| 89 if (!m_pDict) { | 96 if (!m_pDict) { |
| 90 return CPDF_Action(); | 97 return CPDF_Action(); |
| 91 } | 98 } |
| 92 return CPDF_Action(m_pDict->GetDict("A")); | 99 return CPDF_Action(m_pDict->GetDict("A")); |
| 93 } | 100 } |
| OLD | NEW |