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

Side by Side Diff: fpdfsdk/fpdfdoc.cpp

Issue 2521843003: Add API for getting page labels. (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | fpdfsdk/fpdfview_c_api_test.c » ('j') | public/fpdf_doc.h » ('J')
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 "public/fpdf_doc.h" 7 #include "public/fpdf_doc.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 11
12 #include "core/fpdfapi/page/cpdf_page.h" 12 #include "core/fpdfapi/page/cpdf_page.h"
13 #include "core/fpdfapi/parser/cpdf_array.h" 13 #include "core/fpdfapi/parser/cpdf_array.h"
14 #include "core/fpdfapi/parser/cpdf_document.h" 14 #include "core/fpdfapi/parser/cpdf_document.h"
15 #include "core/fpdfdoc/cpdf_bookmark.h" 15 #include "core/fpdfdoc/cpdf_bookmark.h"
16 #include "core/fpdfdoc/cpdf_bookmarktree.h" 16 #include "core/fpdfdoc/cpdf_bookmarktree.h"
17 #include "core/fpdfdoc/cpdf_dest.h" 17 #include "core/fpdfdoc/cpdf_dest.h"
18 #include "core/fpdfdoc/cpdf_pagelabel.h"
18 #include "fpdfsdk/fsdk_define.h" 19 #include "fpdfsdk/fsdk_define.h"
19 #include "third_party/base/stl_util.h" 20 #include "third_party/base/stl_util.h"
20 21
21 namespace { 22 namespace {
22 23
23 CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, 24 CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree,
24 CPDF_Bookmark bookmark, 25 CPDF_Bookmark bookmark,
25 const CFX_WideString& title, 26 const CFX_WideString& title,
26 std::set<CPDF_Dictionary*>* visited) { 27 std::set<CPDF_Dictionary*>* visited) {
27 // Return if already checked to avoid circular calling. 28 // Return if already checked to avoid circular calling.
(...skipping 23 matching lines...) Expand all
51 if (!page) 52 if (!page)
52 return nullptr; 53 return nullptr;
53 54
54 CPDF_Document* pDoc = page->m_pDocument; 55 CPDF_Document* pDoc = page->m_pDocument;
55 std::unique_ptr<CPDF_LinkList>* pHolder = pDoc->LinksContext(); 56 std::unique_ptr<CPDF_LinkList>* pHolder = pDoc->LinksContext();
56 if (!pHolder->get()) 57 if (!pHolder->get())
57 pHolder->reset(new CPDF_LinkList); 58 pHolder->reset(new CPDF_LinkList);
58 return pHolder->get(); 59 return pHolder->get();
59 } 60 }
60 61
62 unsigned long Utf16EncodeMaybeCopyAndReturnLength(const CFX_WideString& text,
63 void* buffer,
64 unsigned long buflen) {
65 CFX_ByteString encodedText = text.UTF16LE_Encode();
66 unsigned long len = encodedText.GetLength();
67 if (buffer && buflen >= len)
68 FXSYS_memcpy(buffer, encodedText.c_str(), len);
dsinclair 2016/11/22 14:14:58 Doesn't this need to copy len+1 to get the \0?
Lei Zhang 2016/11/23 00:20:43 This is lifted out of FPDFBookmark_GetTitle(), and
Lei Zhang 2016/11/23 01:53:42 UTF16LE_Encode() already added a double NUL.
69 return len;
70 }
71
61 } // namespace 72 } // namespace
62 73
63 DLLEXPORT FPDF_BOOKMARK STDCALL 74 DLLEXPORT FPDF_BOOKMARK STDCALL
64 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { 75 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
65 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 76 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
66 if (!pDoc) 77 if (!pDoc)
67 return nullptr; 78 return nullptr;
68 CPDF_BookmarkTree tree(pDoc); 79 CPDF_BookmarkTree tree(pDoc);
69 CPDF_Bookmark bookmark = 80 CPDF_Bookmark bookmark =
70 CPDF_Bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict))); 81 CPDF_Bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
(...skipping 13 matching lines...) Expand all
84 return tree.GetNextSibling(bookmark).GetDict(); 95 return tree.GetNextSibling(bookmark).GetDict();
85 } 96 }
86 97
87 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, 98 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict,
88 void* buffer, 99 void* buffer,
89 unsigned long buflen) { 100 unsigned long buflen) {
90 if (!pDict) 101 if (!pDict)
91 return 0; 102 return 0;
92 CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict))); 103 CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
93 CFX_WideString title = bookmark.GetTitle(); 104 CFX_WideString title = bookmark.GetTitle();
94 CFX_ByteString encodedTitle = title.UTF16LE_Encode(); 105 return Utf16EncodeMaybeCopyAndReturnLength(title, buffer, buflen);
95 unsigned long len = encodedTitle.GetLength();
96 if (buffer && buflen >= len) {
97 FXSYS_memcpy(buffer, encodedTitle.c_str(), len);
98 }
99 return len;
100 } 106 }
101 107
102 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, 108 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document,
103 FPDF_WIDESTRING title) { 109 FPDF_WIDESTRING title) {
104 if (!title || title[0] == 0) 110 if (!title || title[0] == 0)
105 return nullptr; 111 return nullptr;
106 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 112 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
107 if (!pDoc) 113 if (!pDoc)
108 return nullptr; 114 return nullptr;
109 CPDF_BookmarkTree tree(pDoc); 115 CPDF_BookmarkTree tree(pDoc);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 quadPoints->y2 = pArray->GetNumberAt(quadIndex * 8 + 3); 371 quadPoints->y2 = pArray->GetNumberAt(quadIndex * 8 + 3);
366 quadPoints->x3 = pArray->GetNumberAt(quadIndex * 8 + 4); 372 quadPoints->x3 = pArray->GetNumberAt(quadIndex * 8 + 4);
367 quadPoints->y3 = pArray->GetNumberAt(quadIndex * 8 + 5); 373 quadPoints->y3 = pArray->GetNumberAt(quadIndex * 8 + 5);
368 quadPoints->x4 = pArray->GetNumberAt(quadIndex * 8 + 6); 374 quadPoints->x4 = pArray->GetNumberAt(quadIndex * 8 + 6);
369 quadPoints->y4 = pArray->GetNumberAt(quadIndex * 8 + 7); 375 quadPoints->y4 = pArray->GetNumberAt(quadIndex * 8 + 7);
370 return true; 376 return true;
371 } 377 }
372 return false; 378 return false;
373 } 379 }
374 380
375 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, 381 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT document,
376 FPDF_BYTESTRING tag, 382 FPDF_BYTESTRING tag,
377 void* buffer, 383 void* buffer,
378 unsigned long buflen) { 384 unsigned long buflen) {
379 if (!tag) 385 if (!tag)
380 return 0; 386 return 0;
381 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); 387 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
382 if (!pDoc) 388 if (!pDoc)
383 return 0; 389 return 0;
384 CPDF_Dictionary* pInfo = pDoc->GetInfo(); 390 CPDF_Dictionary* pInfo = pDoc->GetInfo();
385 if (!pInfo) 391 if (!pInfo)
386 return 0; 392 return 0;
387 CFX_WideString text = pInfo->GetUnicodeTextFor(tag); 393 CFX_WideString text = pInfo->GetUnicodeTextFor(tag);
388 // Use UTF-16LE encoding 394 return Utf16EncodeMaybeCopyAndReturnLength(text, buffer, buflen);
389 CFX_ByteString encodedText = text.UTF16LE_Encode();
390 unsigned long len = encodedText.GetLength();
391 if (buffer && buflen >= len) {
392 FXSYS_memcpy(buffer, encodedText.c_str(), len);
393 }
394 return len;
395 } 395 }
396
397 DLLEXPORT unsigned long STDCALL FPDF_GetPagelLabel(FPDF_DOCUMENT document,
398 int page_index,
399 void* buffer,
400 unsigned long buflen) {
401 if (page_index < 0)
402 return 0;
403
404 // CPDF_PageLabel can deal with NULL |document|.
405 CPDF_PageLabel label(CPDFDocumentFromFPDFDocument(document));
406 CFX_WideString text = label.GetLabel(page_index);
dsinclair 2016/11/22 14:14:58 Don't need to store text as it's only used once.
Lei Zhang 2016/11/23 01:53:42 Done.
407 return Utf16EncodeMaybeCopyAndReturnLength(text, buffer, buflen);
408 }
OLDNEW
« no previous file with comments | « no previous file | fpdfsdk/fpdfview_c_api_test.c » ('j') | public/fpdf_doc.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698