| 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; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 46 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 47 return tree.GetNextSibling(bookmark).GetDict(); | 47 return tree.GetNextSibling(bookmark).GetDict(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, void*
buffer, unsigned long buflen) | 50 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, void*
buffer, unsigned long buflen) |
| 51 { | 51 { |
| 52 if (!pDict) | 52 if (!pDict) |
| 53 return 0; | 53 return 0; |
| 54 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 54 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 55 CFX_WideString title = bookmark.GetTitle(); | 55 CFX_WideString title = bookmark.GetTitle(); |
| 56 CFX_ByteString encodedTitle = title.UTF16LE_Encode(FALSE); | 56 CFX_ByteString encodedTitle = title.UTF16LE_Encode(); |
| 57 unsigned long len = encodedTitle.GetLength(); | 57 unsigned long len = encodedTitle.GetLength(); |
| 58 if (buffer && buflen >= len + 2) { | 58 if (buffer && buflen >= len) { |
| 59 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); | 59 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); |
| 60 ((FX_BYTE*)buffer)[len] = 0; | |
| 61 ((FX_BYTE*)buffer)[len + 1] = 0; | |
| 62 } | 60 } |
| 63 return len + 2; | 61 return len; |
| 64 } | 62 } |
| 65 | 63 |
| 66 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_W
IDESTRING title) | 64 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_W
IDESTRING title) |
| 67 { | 65 { |
| 68 if (!document) | 66 if (!document) |
| 69 return NULL; | 67 return NULL; |
| 70 if (!title || title[0] == 0) | 68 if (!title || title[0] == 0) |
| 71 return NULL; | 69 return NULL; |
| 72 CPDF_Document* pDoc = (CPDF_Document*)document; | 70 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 73 CPDF_BookmarkTree tree(pDoc); | 71 CPDF_BookmarkTree tree(pDoc); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return 0; | 283 return 0; |
| 286 CPDF_Document* pDoc = (CPDF_Document*)doc; | 284 CPDF_Document* pDoc = (CPDF_Document*)doc; |
| 287 // Get info dictionary | 285 // Get info dictionary |
| 288 CPDF_Dictionary* pInfo = pDoc->GetInfo(); | 286 CPDF_Dictionary* pInfo = pDoc->GetInfo(); |
| 289 if (!pInfo) | 287 if (!pInfo) |
| 290 return 0; | 288 return 0; |
| 291 CFX_WideString text = pInfo->GetUnicodeText(tag); | 289 CFX_WideString text = pInfo->GetUnicodeText(tag); |
| 292 // Use UTF-16LE encoding | 290 // Use UTF-16LE encoding |
| 293 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 291 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 294 unsigned long len = encodedText.GetLength(); | 292 unsigned long len = encodedText.GetLength(); |
| 295 » if (buffer && buflen >= len + 2) { | 293 » if (buffer && buflen >= len) { |
| 296 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 294 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| 297 // use double zero as trailer | |
| 298 ((FX_BYTE*)buffer)[len] = 0; | |
| 299 ((FX_BYTE*)buffer)[len + 1] = 0; | |
| 300 } | 295 } |
| 301 » return len+2; | 296 » return len; |
| 302 } | 297 } |
| OLD | NEW |