Chromium Code Reviews| 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 "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
| 8 #include "../include/fpdfdoc.h" | 8 #include "../include/fpdfdoc.h" |
| 9 | 9 |
| 10 static int THISMODULE = 0; | 10 static int THISMODULE = 0; |
| 11 | 11 |
| 12 static CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, CPDF_Bookmark b ookmark, const CFX_WideString& title) | 12 static CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, CPDF_Bookmark b ookmark, const CFX_WideString& title) |
| 13 { | 13 { |
| 14 if (bookmark && bookmark.GetTitle().CompareNoCase(title) == 0) { | 14 if (bookmark && bookmark.GetTitle().CompareNoCase(title) == 0) { |
| 15 // First check this item | 15 // First check this item |
| 16 return bookmark; | 16 return bookmark; |
| 17 } | 17 } |
| 18 // go into children items | 18 // go into children items |
| 19 CPDF_Bookmark child = tree.GetFirstChild(bookmark); | 19 CPDF_Bookmark child = tree.GetFirstChild(bookmark); |
| 20 while (child) { | 20 while (child) { |
| 21 // check if this item | 21 // check if this item |
| 22 CPDF_Bookmark found = FindBookmark(tree, child, title); | 22 CPDF_Bookmark found = FindBookmark(tree, child, title); |
| 23 if (found) | 23 if (found) |
| 24 return found; | 24 return found; |
| 25 child = tree.GetNextSibling(child); | 25 child = tree.GetNextSibling(child); |
| 26 } | 26 } |
| 27 return CPDF_Bookmark(); | 27 return CPDF_Bookmark(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_GetFirstChild(FPDF_DOCUMENT documen t, FPDF_BOOKMARK pDict) | |
| 31 { | |
| 32 if (!document) | |
|
raymes
2015/01/08 03:55:44
should you check if pDict is null here too (as in
Bo Xu
2015/01/09 19:35:21
Done.
| |
| 33 return NULL; | |
| 34 CPDF_Document* pDoc = (CPDF_Document*)document; | |
| 35 CPDF_BookmarkTree tree(pDoc); | |
| 36 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | |
|
raymes
2015/01/08 03:55:44
nit: indentation
Bo Xu
2015/01/09 19:35:21
Done.
| |
| 37 return tree.GetFirstChild(bookmark).GetDict(); | |
| 38 } | |
| 39 | |
| 40 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_GetNextSibling(FPDF_DOCUMENT docume nt, FPDF_BOOKMARK pDict) | |
| 41 { | |
| 42 if (!document || !pDict) | |
| 43 return NULL; | |
| 44 CPDF_Document* pDoc = (CPDF_Document*)document; | |
| 45 CPDF_BookmarkTree tree(pDoc); | |
| 46 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | |
|
raymes
2015/01/08 03:55:44
nit: indentation (here and the next line)
Bo Xu
2015/01/09 19:35:21
Done.
| |
| 47 return tree.GetNextSibling(bookmark).GetDict(); | |
| 48 } | |
| 49 | |
| 50 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, void* buffer, unsigned long buflen) | |
| 51 { | |
| 52 if (!NULL) | |
|
raymes
2015/01/08 03:55:44
I think you want pDict here
Bo Xu
2015/01/09 19:35:21
Done.
| |
| 53 return 0; | |
| 54 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | |
| 55 CFX_WideString title = bookmark.GetTitle(); | |
| 56 CFX_ByteString encodedTitle = title.UTF16LE_Encode(FALSE); | |
| 57 unsigned long len = encodedTitle.GetLength(); | |
|
raymes
2015/01/08 03:55:44
nit: indentation
Bo Xu
2015/01/09 19:35:21
Done.
| |
| 58 if (buffer && buflen >= len + 2) { | |
| 59 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); | |
| 60 ((FX_BYTE*)buffer)[len] = 0; | |
| 61 ((FX_BYTE*)buffer)[len + 1] = 0; | |
| 62 } | |
| 63 return len + 2; | |
| 64 } | |
| 65 | |
| 30 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_W IDESTRING title) | 66 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_W IDESTRING title) |
| 31 { | 67 { |
| 32 if (!document) | 68 if (!document) |
| 33 return NULL; | 69 return NULL; |
| 34 if (!title || title[0] == 0) | 70 if (!title || title[0] == 0) |
| 35 return NULL; | 71 return NULL; |
| 36 CPDF_Document* pDoc = (CPDF_Document*)document; | 72 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 37 CPDF_BookmarkTree tree(pDoc); | 73 CPDF_BookmarkTree tree(pDoc); |
| 38 FX_STRSIZE len = CFX_WideString::WStringLength(title); | 74 FX_STRSIZE len = CFX_WideString::WStringLength(title); |
| 39 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); | 75 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 293 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 258 unsigned long len = encodedText.GetLength(); | 294 unsigned long len = encodedText.GetLength(); |
| 259 if (buffer && buflen >= len + 2) { | 295 if (buffer && buflen >= len + 2) { |
| 260 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 296 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| 261 // use double zero as trailer | 297 // use double zero as trailer |
| 262 ((FX_BYTE*)buffer)[len] = 0; | 298 ((FX_BYTE*)buffer)[len] = 0; |
| 263 ((FX_BYTE*)buffer)[len + 1] = 0; | 299 ((FX_BYTE*)buffer)[len + 1] = 0; |
| 264 } | 300 } |
| 265 return len+2; | 301 return len+2; |
| 266 } | 302 } |
| OLD | NEW |