OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 #include "pdf/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "ppapi/c/ppb_core.h" | 23 #include "ppapi/c/ppb_core.h" |
24 #include "ppapi/c/private/ppb_pdf.h" | 24 #include "ppapi/c/private/ppb_pdf.h" |
25 #include "ppapi/cpp/dev/memory_dev.h" | 25 #include "ppapi/cpp/dev/memory_dev.h" |
26 #include "ppapi/cpp/input_event.h" | 26 #include "ppapi/cpp/input_event.h" |
27 #include "ppapi/cpp/instance.h" | 27 #include "ppapi/cpp/instance.h" |
28 #include "ppapi/cpp/module.h" | 28 #include "ppapi/cpp/module.h" |
29 #include "ppapi/cpp/private/pdf.h" | 29 #include "ppapi/cpp/private/pdf.h" |
30 #include "ppapi/cpp/trusted/browser_font_trusted.h" | 30 #include "ppapi/cpp/trusted/browser_font_trusted.h" |
31 #include "ppapi/cpp/url_response_info.h" | 31 #include "ppapi/cpp/url_response_info.h" |
32 #include "ppapi/cpp/var.h" | 32 #include "ppapi/cpp/var.h" |
33 #include "ppapi/cpp/var_dictionary.h" | |
33 #include "third_party/pdfium/fpdfsdk/include/fpdf_ext.h" | 34 #include "third_party/pdfium/fpdfsdk/include/fpdf_ext.h" |
34 #include "third_party/pdfium/fpdfsdk/include/fpdf_flatten.h" | 35 #include "third_party/pdfium/fpdfsdk/include/fpdf_flatten.h" |
35 #include "third_party/pdfium/fpdfsdk/include/fpdf_searchex.h" | 36 #include "third_party/pdfium/fpdfsdk/include/fpdf_searchex.h" |
36 #include "third_party/pdfium/fpdfsdk/include/fpdf_sysfontinfo.h" | 37 #include "third_party/pdfium/fpdfsdk/include/fpdf_sysfontinfo.h" |
37 #include "third_party/pdfium/fpdfsdk/include/fpdf_transformpage.h" | 38 #include "third_party/pdfium/fpdfsdk/include/fpdf_transformpage.h" |
38 #include "third_party/pdfium/fpdfsdk/include/fpdfedit.h" | 39 #include "third_party/pdfium/fpdfsdk/include/fpdfedit.h" |
39 #include "third_party/pdfium/fpdfsdk/include/fpdfoom.h" | 40 #include "third_party/pdfium/fpdfsdk/include/fpdfoom.h" |
40 #include "third_party/pdfium/fpdfsdk/include/fpdfppo.h" | 41 #include "third_party/pdfium/fpdfsdk/include/fpdfppo.h" |
41 #include "third_party/pdfium/fpdfsdk/include/fpdfsave.h" | 42 #include "third_party/pdfium/fpdfsdk/include/fpdfsave.h" |
42 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PDFWindow.h" | 43 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PDFWindow.h" |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 static const base::char16 kCr[] = {L'\r', L'\0'}; | 521 static const base::char16 kCr[] = {L'\r', L'\0'}; |
521 static const base::char16 kBlank[] = {L'\0'}; | 522 static const base::char16 kBlank[] = {L'\0'}; |
522 base::ReplaceChars(*text, kCr, kBlank, text); | 523 base::ReplaceChars(*text, kCr, kBlank, text); |
523 #elif defined(OS_WIN) | 524 #elif defined(OS_WIN) |
524 // Do nothing | 525 // Do nothing |
525 #else | 526 #else |
526 NOTIMPLEMENTED(); | 527 NOTIMPLEMENTED(); |
527 #endif | 528 #endif |
528 } | 529 } |
529 | 530 |
531 // Returns a VarDictionary (representing a bookmark), which in turn contains | |
532 // child VarDictionaries (representing the child bookmarks). | |
533 // If NULL is passed in as the bookmark then we traverse from the "root". | |
534 // Note that the "root" bookmark contains no useful information. | |
535 pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc, FPDF_BOOKMARK bookmark) { | |
536 pp::VarDictionary dict; | |
537 base::string16 title; | |
538 size_t buffer_size = FPDFBookmark_GetTitle(bookmark, NULL, 0); | |
539 if (buffer_size > 0) { | |
540 FPDFBookmark_GetTitle(bookmark, | |
541 WriteInto(&title, buffer_size), buffer_size); | |
542 } | |
543 dict.Set(pp::Var("title"), pp::Var(base::UTF16ToUTF8(title))); | |
544 | |
545 FPDF_DEST dest = FPDFBookmark_GetDest(doc, bookmark); | |
546 // Some bookmarks don't have a page to select. | |
547 if (dest) { | |
548 int page_index = FPDFDest_GetPageIndex(doc, dest); | |
549 dict.Set(pp::Var("page"), pp::Var(page_index)); | |
550 } | |
551 | |
552 pp::VarArray children; | |
553 int child_index = 0; | |
554 for (FPDF_BOOKMARK child_bookmark = FPDFBookmark_GetFirstChild(doc, bookmark); | |
555 child_bookmark != NULL; | |
556 child_bookmark = FPDFBookmark_GetNextSibling(doc, child_bookmark)) { | |
557 pp::VarDictionary childDict = TraverseBookmarks(doc, child_bookmark); | |
Sam McNally
2014/12/17 02:48:45
child_dict or better yet, pass this directly to ch
Alexandre Carlton
2014/12/17 02:57:09
Done.
| |
558 children.Set(child_index, childDict); | |
559 child_index++; | |
560 } | |
561 dict.Set(pp::Var("children"), children); | |
562 return dict; | |
563 } | |
564 | |
530 } // namespace | 565 } // namespace |
531 | 566 |
532 bool InitializeSDK(void* data) { | 567 bool InitializeSDK(void* data) { |
533 FPDF_InitLibrary(data); | 568 FPDF_InitLibrary(data); |
534 | 569 |
535 #if defined(OS_LINUX) | 570 #if defined(OS_LINUX) |
536 // Font loading doesn't work in the renderer sandbox in Linux. | 571 // Font loading doesn't work in the renderer sandbox in Linux. |
537 FPDF_SetSystemFontInfo(&g_font_info); | 572 FPDF_SetSystemFontInfo(&g_font_info); |
538 #endif | 573 #endif |
539 | 574 |
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2290 if (pages_[i]->available()) { | 2325 if (pages_[i]->available()) { |
2291 selection_.push_back(PDFiumRange(pages_[i], 0, | 2326 selection_.push_back(PDFiumRange(pages_[i], 0, |
2292 pages_[i]->GetCharCount())); | 2327 pages_[i]->GetCharCount())); |
2293 } | 2328 } |
2294 } | 2329 } |
2295 | 2330 |
2296 int PDFiumEngine::GetNumberOfPages() { | 2331 int PDFiumEngine::GetNumberOfPages() { |
2297 return pages_.size(); | 2332 return pages_.size(); |
2298 } | 2333 } |
2299 | 2334 |
2335 | |
2336 pp::VarArray PDFiumEngine::GetBookmarks() { | |
2337 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL); | |
2338 // The root bookmark contains no useful information. | |
2339 return pp::VarArray(dict.Get(pp::Var("children"))); | |
2340 } | |
2341 | |
2300 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { | 2342 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { |
2301 // Look for the destination. | 2343 // Look for the destination. |
2302 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); | 2344 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); |
2303 if (!dest) { | 2345 if (!dest) { |
2304 // Look for a bookmark with the same name. | 2346 // Look for a bookmark with the same name. |
2305 base::string16 destination_wide = base::UTF8ToUTF16(destination); | 2347 base::string16 destination_wide = base::UTF8ToUTF16(destination); |
2306 FPDF_WIDESTRING destination_pdf_wide = | 2348 FPDF_WIDESTRING destination_pdf_wide = |
2307 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); | 2349 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); |
2308 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); | 2350 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); |
2309 if (!bookmark) | 2351 if (!bookmark) |
(...skipping 1586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3896 double* height) { | 3938 double* height) { |
3897 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3939 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3898 if (!doc) | 3940 if (!doc) |
3899 return false; | 3941 return false; |
3900 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3942 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3901 FPDF_CloseDocument(doc); | 3943 FPDF_CloseDocument(doc); |
3902 return success; | 3944 return success; |
3903 } | 3945 } |
3904 | 3946 |
3905 } // namespace chrome_pdf | 3947 } // namespace chrome_pdf |
OLD | NEW |