| 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> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "../../../third_party/base/nonstd_unique_ptr.h" | 9 #include "../../../third_party/base/nonstd_unique_ptr.h" |
| 10 #include "../../include/fpdfdoc/fpdf_doc.h" | 10 #include "../../include/fpdfdoc/fpdf_doc.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title"); | 57 CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title"); |
| 58 if (!pString || pString->GetType() != PDFOBJ_STRING) { | 58 if (!pString || pString->GetType() != PDFOBJ_STRING) { |
| 59 return CFX_WideString(); | 59 return CFX_WideString(); |
| 60 } | 60 } |
| 61 CFX_WideString title = pString->GetUnicodeText(); | 61 CFX_WideString title = pString->GetUnicodeText(); |
| 62 int len = title.GetLength(); | 62 int len = title.GetLength(); |
| 63 if (!len) { | 63 if (!len) { |
| 64 return CFX_WideString(); | 64 return CFX_WideString(); |
| 65 } | 65 } |
| 66 nonstd::unique_ptr<std::vector<FX_WCHAR> > vec; | 66 nonstd::unique_ptr<FX_WCHAR[]> buf(new FX_WCHAR[len]); |
| 67 vec.reset(new std::vector<FX_WCHAR>(len)); | |
| 68 FX_WCHAR* buf = &vec->front(); | |
| 69 for (int i = 0; i < len; i++) { | 67 for (int i = 0; i < len; i++) { |
| 70 FX_WCHAR w = title[i]; | 68 FX_WCHAR w = title[i]; |
| 71 buf[i] = w > 0x20 ? w : 0x20; | 69 buf[i] = w > 0x20 ? w : 0x20; |
| 72 } | 70 } |
| 73 return CFX_WideString(buf, len); | 71 return CFX_WideString(buf.get(), len); |
| 74 } | 72 } |
| 75 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const | 73 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const |
| 76 { | 74 { |
| 77 if (!m_pDict) { | 75 if (!m_pDict) { |
| 78 return CPDF_Dest(); | 76 return CPDF_Dest(); |
| 79 } | 77 } |
| 80 CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); | 78 CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); |
| 81 if (!pDest) { | 79 if (!pDest) { |
| 82 return CPDF_Dest(); | 80 return CPDF_Dest(); |
| 83 } | 81 } |
| 84 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { | 82 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { |
| 85 CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests")); | 83 CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests")); |
| 86 CFX_ByteStringC name = pDest->GetString(); | 84 CFX_ByteStringC name = pDest->GetString(); |
| 87 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name)); | 85 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name)); |
| 88 } | 86 } |
| 89 if (pDest->GetType() == PDFOBJ_ARRAY) { | 87 if (pDest->GetType() == PDFOBJ_ARRAY) { |
| 90 return CPDF_Dest((CPDF_Array*)pDest); | 88 return CPDF_Dest((CPDF_Array*)pDest); |
| 91 } | 89 } |
| 92 return CPDF_Dest(); | 90 return CPDF_Dest(); |
| 93 } | 91 } |
| 94 CPDF_Action CPDF_Bookmark::GetAction() const | 92 CPDF_Action CPDF_Bookmark::GetAction() const |
| 95 { | 93 { |
| 96 if (!m_pDict) { | 94 if (!m_pDict) { |
| 97 return CPDF_Action(); | 95 return CPDF_Action(); |
| 98 } | 96 } |
| 99 return CPDF_Action(m_pDict->GetDict("A")); | 97 return CPDF_Action(m_pDict->GetDict("A")); |
| 100 } | 98 } |
| OLD | NEW |