Chromium Code Reviews| 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/fpdfppo.h" | 40 #include "third_party/pdfium/fpdfsdk/include/fpdfppo.h" |
| 40 #include "third_party/pdfium/fpdfsdk/include/fpdfsave.h" | 41 #include "third_party/pdfium/fpdfsdk/include/fpdfsave.h" |
| 41 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PDFWindow.h" | 42 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PDFWindow.h" |
| 42 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PWL_FontMap.h" | 43 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PWL_FontMap.h" |
| (...skipping 2284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2327 FPDF_WIDESTRING destination_pdf_wide = | 2328 FPDF_WIDESTRING destination_pdf_wide = |
| 2328 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); | 2329 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); |
| 2329 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); | 2330 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); |
| 2330 if (!bookmark) | 2331 if (!bookmark) |
| 2331 return -1; | 2332 return -1; |
| 2332 dest = FPDFBookmark_GetDest(doc_, bookmark); | 2333 dest = FPDFBookmark_GetDest(doc_, bookmark); |
| 2333 } | 2334 } |
| 2334 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; | 2335 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; |
| 2335 } | 2336 } |
| 2336 | 2337 |
| 2338 pp::VarDictionary PDFiumEngine::GetNamedDestinations() { | |
| 2339 pp::VarDictionary named_destinations; | |
| 2340 for (unsigned long i = 0; i < FPDF_CountNamedDests(doc_); i++) { | |
| 2341 base::string16 name; | |
| 2342 unsigned long buffer_bytes; | |
| 2343 FPDF_GetNamedDest(doc_, i, NULL, buffer_bytes); | |
| 2344 unsigned long name_length = | |
| 2345 buffer_bytes / sizeof(base::string16::value_type); | |
| 2346 if (name_length > 0) { | |
| 2347 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter( | |
| 2348 &name, name_length, true); | |
| 2349 FPDF_DEST dest = FPDF_GetNamedDest(doc_, i, api_string_adapter.GetData(), | |
| 2350 buffer_bytes); | |
| 2351 api_string_adapter.Close(name_length); | |
| 2352 if (dest) { | |
| 2353 std::string name_dest = base::UTF16ToUTF8(name); | |
|
raymes
2015/01/15 23:07:43
nit: name_dest->named_dest
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:43, raymes wrote:
Done.
| |
| 2354 int page_number = GetNamedDestinationPage(name_dest); | |
| 2355 if (page_number >= 0) { | |
| 2356 named_destinations.Set(pp::Var(name_dest.c_str()), | |
| 2357 pp::Var(page_number)); | |
| 2358 } | |
| 2359 } | |
| 2360 } | |
| 2361 } | |
| 2362 return named_destinations; | |
| 2363 } | |
| 2364 | |
| 2337 int PDFiumEngine::GetFirstVisiblePage() { | 2365 int PDFiumEngine::GetFirstVisiblePage() { |
| 2338 CalculateVisiblePages(); | 2366 CalculateVisiblePages(); |
| 2339 return first_visible_page_; | 2367 return first_visible_page_; |
| 2340 } | 2368 } |
| 2341 | 2369 |
| 2342 int PDFiumEngine::GetMostVisiblePage() { | 2370 int PDFiumEngine::GetMostVisiblePage() { |
| 2343 CalculateVisiblePages(); | 2371 CalculateVisiblePages(); |
| 2344 return most_visible_page_; | 2372 return most_visible_page_; |
| 2345 } | 2373 } |
| 2346 | 2374 |
| (...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3916 double* height) { | 3944 double* height) { |
| 3917 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3945 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3918 if (!doc) | 3946 if (!doc) |
| 3919 return false; | 3947 return false; |
| 3920 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3948 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3921 FPDF_CloseDocument(doc); | 3949 FPDF_CloseDocument(doc); |
| 3922 return success; | 3950 return success; |
| 3923 } | 3951 } |
| 3924 | 3952 |
| 3925 } // namespace chrome_pdf | 3953 } // namespace chrome_pdf |
| OLD | NEW |