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 2371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2382 FPDF_WIDESTRING destination_pdf_wide = | 2382 FPDF_WIDESTRING destination_pdf_wide = |
2383 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); | 2383 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); |
2384 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); | 2384 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); |
2385 if (!bookmark) | 2385 if (!bookmark) |
2386 return -1; | 2386 return -1; |
2387 dest = FPDFBookmark_GetDest(doc_, bookmark); | 2387 dest = FPDFBookmark_GetDest(doc_, bookmark); |
2388 } | 2388 } |
2389 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; | 2389 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; |
2390 } | 2390 } |
2391 | 2391 |
2392 pp::VarDictionary PDFiumEngine::GetNamedDestinations() { | |
2393 pp::VarDictionary named_destinations; | |
2394 for (unsigned long i = 0; i < FPDF_CountNamedDests(doc_); i++) { | |
2395 base::string16 name; | |
2396 long buffer_bytes; | |
2397 FPDF_GetNamedDest(doc_, i, NULL, buffer_bytes); | |
2398 size_t name_length = base::checked_cast<size_t>(buffer_bytes) / | |
2399 sizeof(base::string16::value_type); | |
2400 if (name_length > 0) { | |
2401 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter( | |
2402 &name, name_length, true); | |
2403 FPDF_DEST dest = FPDF_GetNamedDest(doc_, i, api_string_adapter.GetData(), | |
2404 buffer_bytes); | |
2405 api_string_adapter.Close(name_length); | |
2406 if (dest) { | |
2407 std::string named_dest = base::UTF16ToUTF8(name); | |
2408 int page_number = GetNamedDestinationPage(named_dest); | |
2409 if (page_number >= 0) { | |
2410 named_destinations.Set(pp::Var(named_dest.c_str()), | |
2411 pp::Var(page_number)); | |
2412 } | |
2413 } | |
2414 } | |
2415 } | |
2416 return named_destinations; | |
2417 } | |
2418 | |
2419 int PDFiumEngine::GetFirstVisiblePage() { | 2392 int PDFiumEngine::GetFirstVisiblePage() { |
2420 CalculateVisiblePages(); | 2393 CalculateVisiblePages(); |
2421 return first_visible_page_; | 2394 return first_visible_page_; |
2422 } | 2395 } |
2423 | 2396 |
2424 int PDFiumEngine::GetMostVisiblePage() { | 2397 int PDFiumEngine::GetMostVisiblePage() { |
2425 CalculateVisiblePages(); | 2398 CalculateVisiblePages(); |
2426 return most_visible_page_; | 2399 return most_visible_page_; |
2427 } | 2400 } |
2428 | 2401 |
(...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4027 double* height) { | 4000 double* height) { |
4028 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 4001 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
4029 if (!doc) | 4002 if (!doc) |
4030 return false; | 4003 return false; |
4031 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4004 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4032 FPDF_CloseDocument(doc); | 4005 FPDF_CloseDocument(doc); |
4033 return success; | 4006 return success; |
4034 } | 4007 } |
4035 | 4008 |
4036 } // namespace chrome_pdf | 4009 } // namespace chrome_pdf |
OLD | NEW |