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 2247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2290 if (pages_[i]->available()) { | 2291 if (pages_[i]->available()) { |
2291 selection_.push_back(PDFiumRange(pages_[i], 0, | 2292 selection_.push_back(PDFiumRange(pages_[i], 0, |
2292 pages_[i]->GetCharCount())); | 2293 pages_[i]->GetCharCount())); |
2293 } | 2294 } |
2294 } | 2295 } |
2295 | 2296 |
2296 int PDFiumEngine::GetNumberOfPages() { | 2297 int PDFiumEngine::GetNumberOfPages() { |
2297 return pages_.size(); | 2298 return pages_.size(); |
2298 } | 2299 } |
2299 | 2300 |
2301 int NumChildren(FPDF_DOCUMENT doc, FPDF_BOOKMARK bookmark) | |
2302 { | |
2303 int num = 0; | |
2304 FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(doc, bookmark); | |
2305 while (child != NULL) { | |
2306 child = FPDFBookmark_GetNextSibling(doc, child); | |
2307 num++; | |
2308 } | |
2309 return num; | |
2310 } | |
2311 | |
2312 void TraverseBookmarks(FPDF_BOOKMARK bookmark, pp::VarDictionary *dict, | |
Sam McNally
2014/12/16 05:58:34
Put this in the anonymous namespace above.
Return
Alexandre Carlton
2014/12/16 22:14:51
Done.
| |
2313 FPDF_DOCUMENT doc) { | |
2314 base::string16 title; | |
2315 size_t buffer_size = FPDFBookmark_GetTitle(bookmark, NULL, 0); | |
2316 if (buffer_size > 1) { | |
2317 void *data = WriteInto(&title, buffer_size + 1); | |
2318 FPDFBookmark_GetTitle(bookmark, data, buffer_size); | |
Sam McNally
2014/12/16 05:58:34
I would pass the result of WriteInto(...) directly
Alexandre Carlton
2014/12/16 22:14:51
Done.
| |
2319 } | |
2320 std::string shortTitle = base::UTF16ToUTF8(title); | |
2321 dict->Set(pp::Var("title"), pp::Var(shortTitle)); | |
Sam McNally
2014/12/16 05:58:34
Remove shortTitle and pass base::UTF16ToUTF8(title
Alexandre Carlton
2014/12/16 22:14:51
Done.
| |
2322 | |
2323 FPDF_DEST dest = FPDFBookmark_GetDest(doc, bookmark); | |
2324 int pageIndex = dest ? FPDFDest_GetPageIndex(doc, dest) : -1; | |
Sam McNally
2014/12/16 05:58:34
How about only setting "page" for bookmarks that h
Alexandre Carlton
2014/12/16 22:14:51
Done.
| |
2325 dict->Set(pp::Var("page"), pp::Var(pageIndex)); | |
2326 | |
2327 int length = NumChildren(doc, bookmark); | |
2328 pp::VarArray *children = new pp::VarArray(); | |
Sam McNally
2014/12/16 05:58:35
Put this on the stack. Otherwise, it will leak.
Alexandre Carlton
2014/12/16 22:14:51
Done.
| |
2329 children->SetLength(length); | |
Sam McNally
2014/12/16 05:58:34
You don't need this. VarArray resizes to fit on ca
Alexandre Carlton
2014/12/16 22:14:51
Done.
| |
2330 | |
2331 int i = 0; | |
2332 pp::VarDictionary *childDict; | |
Sam McNally
2014/12/16 05:58:34
Declare this inside the loop (or remove it entirel
Alexandre Carlton
2014/12/16 22:14:51
Done.
| |
2333 bookmark = FPDFBookmark_GetFirstChild(doc, bookmark); | |
Sam McNally
2014/12/16 05:58:35
Use a different variable for the child bookmarks.
Alexandre Carlton
2014/12/16 22:14:51
Done.
| |
2334 while (bookmark != NULL) { | |
Sam McNally
2014/12/16 05:58:34
I think this would be nicer as a for loop.
Alexandre Carlton
2014/12/16 22:14:51
Done.
| |
2335 childDict = new pp::VarDictionary(); | |
2336 TraverseBookmarks(bookmark, childDict, doc); | |
2337 children->Set(i, *childDict); | |
2338 bookmark = FPDFBookmark_GetNextSibling(doc, bookmark); | |
2339 i++; | |
2340 } | |
2341 dict->Set(pp::Var("children"), *children); | |
2342 } | |
2343 | |
2344 pp::VarDictionary PDFiumEngine::GetBookmarks() { | |
2345 pp::VarDictionary *dict = new pp::VarDictionary(); | |
2346 TraverseBookmarks(NULL, dict, doc_); | |
2347 return *dict; | |
2348 } | |
2349 | |
2300 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { | 2350 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { |
2301 // Look for the destination. | 2351 // Look for the destination. |
2302 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); | 2352 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); |
2303 if (!dest) { | 2353 if (!dest) { |
2304 // Look for a bookmark with the same name. | 2354 // Look for a bookmark with the same name. |
2305 base::string16 destination_wide = base::UTF8ToUTF16(destination); | 2355 base::string16 destination_wide = base::UTF8ToUTF16(destination); |
2306 FPDF_WIDESTRING destination_pdf_wide = | 2356 FPDF_WIDESTRING destination_pdf_wide = |
2307 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); | 2357 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); |
2308 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); | 2358 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); |
2309 if (!bookmark) | 2359 if (!bookmark) |
(...skipping 1586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3896 double* height) { | 3946 double* height) { |
3897 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3947 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3898 if (!doc) | 3948 if (!doc) |
3899 return false; | 3949 return false; |
3900 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3950 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3901 FPDF_CloseDocument(doc); | 3951 FPDF_CloseDocument(doc); |
3902 return success; | 3952 return success; |
3903 } | 3953 } |
3904 | 3954 |
3905 } // namespace chrome_pdf | 3955 } // namespace chrome_pdf |
OLD | NEW |