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 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2375 FPDF_WIDESTRING destination_pdf_wide = | 2375 FPDF_WIDESTRING destination_pdf_wide = |
2376 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); | 2376 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); |
2377 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); | 2377 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); |
2378 if (!bookmark) | 2378 if (!bookmark) |
2379 return -1; | 2379 return -1; |
2380 dest = FPDFBookmark_GetDest(doc_, bookmark); | 2380 dest = FPDFBookmark_GetDest(doc_, bookmark); |
2381 } | 2381 } |
2382 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; | 2382 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; |
2383 } | 2383 } |
2384 | 2384 |
| 2385 pp::VarDictionary PDFiumEngine::GetNamedDestinations() { |
| 2386 pp::VarDictionary named_destinations; |
| 2387 for (unsigned long i = 0; i < FPDF_CountNamedDests(doc_); i++) { |
| 2388 base::string16 name; |
| 2389 unsigned long buffer_bytes; |
| 2390 FPDF_GetNamedDest(doc_, i, NULL, buffer_bytes); |
| 2391 size_t name_length = buffer_bytes / sizeof(base::string16::value_type); |
| 2392 if (name_length > 0) { |
| 2393 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter( |
| 2394 &name, name_length, true); |
| 2395 FPDF_DEST dest = FPDF_GetNamedDest(doc_, i, api_string_adapter.GetData(), |
| 2396 buffer_bytes); |
| 2397 api_string_adapter.Close(name_length); |
| 2398 if (dest) { |
| 2399 std::string named_dest = base::UTF16ToUTF8(name); |
| 2400 int page_number = GetNamedDestinationPage(named_dest); |
| 2401 if (page_number >= 0) { |
| 2402 named_destinations.Set(pp::Var(named_dest.c_str()), |
| 2403 pp::Var(page_number)); |
| 2404 } |
| 2405 } |
| 2406 } |
| 2407 } |
| 2408 return named_destinations; |
| 2409 } |
| 2410 |
2385 int PDFiumEngine::GetFirstVisiblePage() { | 2411 int PDFiumEngine::GetFirstVisiblePage() { |
2386 CalculateVisiblePages(); | 2412 CalculateVisiblePages(); |
2387 return first_visible_page_; | 2413 return first_visible_page_; |
2388 } | 2414 } |
2389 | 2415 |
2390 int PDFiumEngine::GetMostVisiblePage() { | 2416 int PDFiumEngine::GetMostVisiblePage() { |
2391 CalculateVisiblePages(); | 2417 CalculateVisiblePages(); |
2392 return most_visible_page_; | 2418 return most_visible_page_; |
2393 } | 2419 } |
2394 | 2420 |
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3965 double* height) { | 3991 double* height) { |
3966 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3992 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3967 if (!doc) | 3993 if (!doc) |
3968 return false; | 3994 return false; |
3969 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3995 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3970 FPDF_CloseDocument(doc); | 3996 FPDF_CloseDocument(doc); |
3971 return success; | 3997 return success; |
3972 } | 3998 } |
3973 | 3999 |
3974 } // namespace chrome_pdf | 4000 } // namespace chrome_pdf |
OLD | NEW |