Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: core/src/fpdfdoc/doc_bookmark.cpp

Issue 1112673002: Revert "Make CFX_WideString::LockBuffer() completely unused." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/include/fxcrt/fx_string.h ('k') | core/src/fxcrt/fx_basic_bstring.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 #include "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../include/fpdfdoc/fpdf_doc.h"
11
12 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(const CPDF_Bookmark& parent) cons t 8 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(const CPDF_Bookmark& parent) cons t
13 { 9 {
14 if (!parent.m_pDict) { 10 if (!parent.m_pDict) {
15 CPDF_Dictionary* pRoot = m_pDocument->GetRoot()->GetDict("Outlines"); 11 CPDF_Dictionary* pRoot = m_pDocument->GetRoot()->GetDict("Outlines");
16 if (!pRoot) { 12 if (!pRoot) {
17 return CPDF_Bookmark(); 13 return CPDF_Bookmark();
18 } 14 }
19 return CPDF_Bookmark(pRoot->GetDict("First")); 15 return CPDF_Bookmark(pRoot->GetDict("First"));
20 } 16 }
21 return CPDF_Bookmark(parent.m_pDict->GetDict("First")); 17 return CPDF_Bookmark(parent.m_pDict->GetDict("First"));
(...skipping 30 matching lines...) Expand all
52 CFX_WideString CPDF_Bookmark::GetTitle() const 48 CFX_WideString CPDF_Bookmark::GetTitle() const
53 { 49 {
54 if (!m_pDict) { 50 if (!m_pDict) {
55 return CFX_WideString(); 51 return CFX_WideString();
56 } 52 }
57 CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title"); 53 CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title");
58 if (!pString || pString->GetType() != PDFOBJ_STRING) { 54 if (!pString || pString->GetType() != PDFOBJ_STRING) {
59 return CFX_WideString(); 55 return CFX_WideString();
60 } 56 }
61 CFX_WideString title = pString->GetUnicodeText(); 57 CFX_WideString title = pString->GetUnicodeText();
58 FX_LPWSTR buf = title.LockBuffer();
62 int len = title.GetLength(); 59 int len = title.GetLength();
63 if (!len) { 60 for (int i = 0; i < len; i++) {
64 return CFX_WideString(); 61 if (buf[i] < 0x20) {
62 buf[i] = 0x20;
63 }
65 } 64 }
66 nonstd::unique_ptr<std::vector<FX_WCHAR> > vec; 65 title.ReleaseBuffer(len);
67 vec.reset(new std::vector<FX_WCHAR>(len)); 66 return title;
68 FX_WCHAR* buf = &vec->front();
69 for (int i = 0; i < len; i++) {
70 FX_WCHAR w = title[i];
71 buf[i] = w > 0x20 ? w : 0x20;
72 }
73 return CFX_WideString(buf, len);
74 } 67 }
75 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const 68 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const
76 { 69 {
77 if (!m_pDict) { 70 if (!m_pDict) {
78 return CPDF_Dest(); 71 return CPDF_Dest();
79 } 72 }
80 CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); 73 CPDF_Object* pDest = m_pDict->GetElementValue("Dest");
81 if (!pDest) { 74 if (!pDest) {
82 return CPDF_Dest(); 75 return CPDF_Dest();
83 } 76 }
84 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { 77 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
85 CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests")); 78 CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests"));
86 CFX_ByteStringC name = pDest->GetString(); 79 CFX_ByteStringC name = pDest->GetString();
87 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name)); 80 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name));
88 } 81 }
89 if (pDest->GetType() == PDFOBJ_ARRAY) { 82 if (pDest->GetType() == PDFOBJ_ARRAY) {
90 return CPDF_Dest((CPDF_Array*)pDest); 83 return CPDF_Dest((CPDF_Array*)pDest);
91 } 84 }
92 return CPDF_Dest(); 85 return CPDF_Dest();
93 } 86 }
94 CPDF_Action CPDF_Bookmark::GetAction() const 87 CPDF_Action CPDF_Bookmark::GetAction() const
95 { 88 {
96 if (!m_pDict) { 89 if (!m_pDict) {
97 return CPDF_Action(); 90 return CPDF_Action();
98 } 91 }
99 return CPDF_Action(m_pDict->GetDict("A")); 92 return CPDF_Action(m_pDict->GetDict("A"));
100 } 93 }
OLDNEW
« no previous file with comments | « core/include/fxcrt/fx_string.h ('k') | core/src/fxcrt/fx_basic_bstring.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698