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

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

Issue 1053613004: Make CFX_WideString::LockBuffer() completely unused. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Avoid VS compiler issue. 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"
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
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 nonstd::unique_ptr<std::vector<FX_WCHAR> > vec;
64 vec.reset(new std::vector<FX_WCHAR>(len));
65 FX_WCHAR* buf = &vec->front();
Lei Zhang 2015/04/27 22:50:46 Can we first check |len| and just return a CFX_Wid
Tom Sepez 2015/04/28 19:02:20 Done.
60 for (int i = 0; i < len; i++) { 66 for (int i = 0; i < len; i++) {
61 if (buf[i] < 0x20) { 67 FX_WCHAR w = title[i];
62 buf[i] = 0x20; 68 buf[i] = w > 0x20 ? w : 0x20;
63 }
64 } 69 }
65 title.ReleaseBuffer(len); 70 return CFX_WideString(buf, len);
66 return title;
67 } 71 }
68 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const 72 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const
69 { 73 {
70 if (!m_pDict) { 74 if (!m_pDict) {
71 return CPDF_Dest(); 75 return CPDF_Dest();
72 } 76 }
73 CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); 77 CPDF_Object* pDest = m_pDict->GetElementValue("Dest");
74 if (!pDest) { 78 if (!pDest) {
75 return CPDF_Dest(); 79 return CPDF_Dest();
76 } 80 }
77 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { 81 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
78 CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests")); 82 CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests"));
79 CFX_ByteStringC name = pDest->GetString(); 83 CFX_ByteStringC name = pDest->GetString();
80 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name)); 84 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name));
81 } 85 }
82 if (pDest->GetType() == PDFOBJ_ARRAY) { 86 if (pDest->GetType() == PDFOBJ_ARRAY) {
83 return CPDF_Dest((CPDF_Array*)pDest); 87 return CPDF_Dest((CPDF_Array*)pDest);
84 } 88 }
85 return CPDF_Dest(); 89 return CPDF_Dest();
86 } 90 }
87 CPDF_Action CPDF_Bookmark::GetAction() const 91 CPDF_Action CPDF_Bookmark::GetAction() const
88 { 92 {
89 if (!m_pDict) { 93 if (!m_pDict) {
90 return CPDF_Action(); 94 return CPDF_Action();
91 } 95 }
92 return CPDF_Action(m_pDict->GetDict("A")); 96 return CPDF_Action(m_pDict->GetDict("A"));
93 } 97 }
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