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 size_t bytes_in_char16 = sizeof(base::string16::value_type); | |
2345 unsigned long name_length = buffer_bytes / bytes_in_char16; | |
raymes
2015/01/15 04:51:11
nit: merge the above 2 lines
Deepak
2015/01/15 06:30:06
Done.
| |
2346 if (name_length > 1) { | |
raymes
2015/01/15 04:51:11
this should just be name_length > 0 when switching
Deepak
2015/01/15 06:30:06
Done.
| |
2347 FPDF_DEST dest = FPDF_GetNamedDest(doc_, i, WriteInto(&name, name_length), | |
2348 buffer_bytes); | |
raymes
2015/01/15 04:51:11
thestig just added a class which will make doing t
Deepak
2015/01/15 06:30:06
These changes are not yet rolled in.Once These rol
| |
2349 if (dest) { | |
2350 std::string name_dest = base::UTF16ToUTF8(name); | |
2351 int page_number = GetNamedDestinationPage(name_dest); | |
2352 if (page_number >= 0) { | |
2353 named_destinations.Set(pp::Var(name_dest.c_str()), | |
2354 pp::Var(page_number)); | |
2355 } | |
2356 } | |
2357 } | |
2358 } | |
2359 return named_destinations; | |
2360 } | |
2361 | |
2337 int PDFiumEngine::GetFirstVisiblePage() { | 2362 int PDFiumEngine::GetFirstVisiblePage() { |
2338 CalculateVisiblePages(); | 2363 CalculateVisiblePages(); |
2339 return first_visible_page_; | 2364 return first_visible_page_; |
2340 } | 2365 } |
2341 | 2366 |
2342 int PDFiumEngine::GetMostVisiblePage() { | 2367 int PDFiumEngine::GetMostVisiblePage() { |
2343 CalculateVisiblePages(); | 2368 CalculateVisiblePages(); |
2344 return most_visible_page_; | 2369 return most_visible_page_; |
2345 } | 2370 } |
2346 | 2371 |
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3916 double* height) { | 3941 double* height) { |
3917 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3942 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3918 if (!doc) | 3943 if (!doc) |
3919 return false; | 3944 return false; |
3920 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3945 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3921 FPDF_CloseDocument(doc); | 3946 FPDF_CloseDocument(doc); |
3922 return success; | 3947 return success; |
3923 } | 3948 } |
3924 | 3949 |
3925 } // namespace chrome_pdf | 3950 } // namespace chrome_pdf |
OLD | NEW |