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 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 2323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2334 void PDFiumEngine::OnCallback(int id) { | 2334 void PDFiumEngine::OnCallback(int id) { |
2335 if (!timers_.count(id)) | 2335 if (!timers_.count(id)) |
2336 return; | 2336 return; |
2337 | 2337 |
2338 timers_[id].second(id); | 2338 timers_[id].second(id); |
2339 if (timers_.count(id)) // The callback might delete the timer. | 2339 if (timers_.count(id)) // The callback might delete the timer. |
2340 client_->ScheduleCallback(id, timers_[id].first); | 2340 client_->ScheduleCallback(id, timers_[id].first); |
2341 } | 2341 } |
2342 | 2342 |
2343 int PDFiumEngine::GetCharCount(int page_index) { | 2343 int PDFiumEngine::GetCharCount(int page_index) { |
2344 DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size())); | 2344 DCHECK(PageIndexInBounds(page_index)); |
2345 return pages_[page_index]->GetCharCount(); | 2345 return pages_[page_index]->GetCharCount(); |
2346 } | 2346 } |
2347 | 2347 |
2348 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) { | 2348 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) { |
2349 DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size())); | 2349 DCHECK(PageIndexInBounds(page_index)); |
2350 return pages_[page_index]->GetCharBounds(char_index); | 2350 return pages_[page_index]->GetCharBounds(char_index); |
2351 } | 2351 } |
2352 | 2352 |
2353 uint32_t PDFiumEngine::GetCharUnicode(int page_index, int char_index) { | 2353 uint32_t PDFiumEngine::GetCharUnicode(int page_index, int char_index) { |
2354 DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size())); | 2354 DCHECK(PageIndexInBounds(page_index)); |
2355 return pages_[page_index]->GetCharUnicode(char_index); | 2355 return pages_[page_index]->GetCharUnicode(char_index); |
2356 } | 2356 } |
2357 | 2357 |
2358 void PDFiumEngine::GetTextRunInfo(int page_index, | 2358 void PDFiumEngine::GetTextRunInfo(int page_index, |
2359 int start_char_index, | 2359 int start_char_index, |
2360 uint32_t* out_len, | 2360 uint32_t* out_len, |
2361 double* out_font_size, | 2361 double* out_font_size, |
2362 pp::FloatRect* out_bounds) { | 2362 pp::FloatRect* out_bounds) { |
2363 DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size())); | 2363 DCHECK(PageIndexInBounds(page_index)); |
2364 return pages_[page_index]->GetTextRunInfo(start_char_index, out_len, | 2364 return pages_[page_index]->GetTextRunInfo(start_char_index, out_len, |
2365 out_font_size, out_bounds); | 2365 out_font_size, out_bounds); |
2366 } | 2366 } |
2367 | 2367 |
2368 bool PDFiumEngine::GetPrintScaling() { | 2368 bool PDFiumEngine::GetPrintScaling() { |
2369 return !!FPDF_VIEWERREF_GetPrintScaling(doc_); | 2369 return !!FPDF_VIEWERREF_GetPrintScaling(doc_); |
2370 } | 2370 } |
2371 | 2371 |
2372 int PDFiumEngine::GetCopiesToPrint() { | 2372 int PDFiumEngine::GetCopiesToPrint() { |
2373 return FPDF_VIEWERREF_GetNumCopies(doc_); | 2373 return FPDF_VIEWERREF_GetNumCopies(doc_); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2694 } | 2694 } |
2695 | 2695 |
2696 SetCurrentPage(most_visible_page); | 2696 SetCurrentPage(most_visible_page); |
2697 } | 2697 } |
2698 | 2698 |
2699 bool PDFiumEngine::IsPageVisible(int index) const { | 2699 bool PDFiumEngine::IsPageVisible(int index) const { |
2700 return base::ContainsValue(visible_pages_, index); | 2700 return base::ContainsValue(visible_pages_, index); |
2701 } | 2701 } |
2702 | 2702 |
2703 void PDFiumEngine::ScrollToPage(int page) { | 2703 void PDFiumEngine::ScrollToPage(int page) { |
| 2704 if (!PageIndexInBounds(page)) |
| 2705 return; |
| 2706 |
2704 in_flight_visible_page_ = page; | 2707 in_flight_visible_page_ = page; |
2705 client_->ScrollToPage(page); | 2708 client_->ScrollToPage(page); |
2706 } | 2709 } |
2707 | 2710 |
2708 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { | 2711 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { |
2709 if (!doc_ || !form_) | 2712 if (!doc_ || !form_) |
2710 return false; | 2713 return false; |
2711 | 2714 |
2712 const int num_pages = static_cast<int>(pages_.size()); | 2715 const int num_pages = static_cast<int>(pages_.size()); |
2713 if (index < num_pages && pages_[index]->available()) | 2716 if (index < num_pages && pages_[index]->available()) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2764 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); | 2767 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); |
2765 DCHECK(image_data); | 2768 DCHECK(image_data); |
2766 | 2769 |
2767 #if defined(OS_LINUX) | 2770 #if defined(OS_LINUX) |
2768 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); | 2771 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); |
2769 #endif | 2772 #endif |
2770 | 2773 |
2771 int rv; | 2774 int rv; |
2772 FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap; | 2775 FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap; |
2773 int page_index = progressive_paints_[progressive_index].page_index; | 2776 int page_index = progressive_paints_[progressive_index].page_index; |
2774 DCHECK_GE(page_index, 0); | 2777 DCHECK(PageIndexInBounds(page_index)); |
2775 DCHECK_LT(static_cast<size_t>(page_index), pages_.size()); | |
2776 FPDF_PAGE page = pages_[page_index]->GetPage(); | 2778 FPDF_PAGE page = pages_[page_index]->GetPage(); |
2777 | 2779 |
2778 last_progressive_start_time_ = base::Time::Now(); | 2780 last_progressive_start_time_ = base::Time::Now(); |
2779 if (bitmap) { | 2781 if (bitmap) { |
2780 rv = FPDF_RenderPage_Continue(page, static_cast<IFSDK_PAUSE*>(this)); | 2782 rv = FPDF_RenderPage_Continue(page, static_cast<IFSDK_PAUSE*>(this)); |
2781 } else { | 2783 } else { |
2782 pp::Rect dirty = progressive_paints_[progressive_index].rect; | 2784 pp::Rect dirty = progressive_paints_[progressive_index].rect; |
2783 bitmap = CreateBitmap(dirty, image_data); | 2785 bitmap = CreateBitmap(dirty, image_data); |
2784 int start_x, start_y, size_x, size_y; | 2786 int start_x, start_y, size_x, size_y; |
2785 GetPDFiumRect(page_index, dirty, &start_x, &start_y, &size_x, &size_y); | 2787 GetPDFiumRect(page_index, dirty, &start_x, &start_y, &size_x, &size_y); |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3417 client_->ScrollToPage(most_visible_page); | 3419 client_->ScrollToPage(most_visible_page); |
3418 } | 3420 } |
3419 | 3421 |
3420 void PDFiumEngine::SetSelecting(bool selecting) { | 3422 void PDFiumEngine::SetSelecting(bool selecting) { |
3421 bool was_selecting = selecting_; | 3423 bool was_selecting = selecting_; |
3422 selecting_ = selecting; | 3424 selecting_ = selecting; |
3423 if (selecting_ != was_selecting) | 3425 if (selecting_ != was_selecting) |
3424 client_->IsSelectingChanged(selecting); | 3426 client_->IsSelectingChanged(selecting); |
3425 } | 3427 } |
3426 | 3428 |
| 3429 bool PDFiumEngine::PageIndexInBounds(int index) const { |
| 3430 return index >= 0 && index < static_cast<int>(pages_.size()); |
| 3431 } |
| 3432 |
3427 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, | 3433 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, |
3428 FPDF_PAGE page, | 3434 FPDF_PAGE page, |
3429 double left, | 3435 double left, |
3430 double top, | 3436 double top, |
3431 double right, | 3437 double right, |
3432 double bottom) { | 3438 double bottom) { |
3433 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3439 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3434 int page_index = engine->GetVisiblePageIndex(page); | 3440 int page_index = engine->GetVisiblePageIndex(page); |
3435 if (page_index == -1) { | 3441 if (page_index == -1) { |
3436 // This can sometime happen when the page is closed because it went off | 3442 // This can sometime happen when the page is closed because it went off |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3500 } | 3506 } |
3501 | 3507 |
3502 void PDFiumEngine::Form_OnChange(FPDF_FORMFILLINFO* param) { | 3508 void PDFiumEngine::Form_OnChange(FPDF_FORMFILLINFO* param) { |
3503 // Don't care about. | 3509 // Don't care about. |
3504 } | 3510 } |
3505 | 3511 |
3506 FPDF_PAGE PDFiumEngine::Form_GetPage(FPDF_FORMFILLINFO* param, | 3512 FPDF_PAGE PDFiumEngine::Form_GetPage(FPDF_FORMFILLINFO* param, |
3507 FPDF_DOCUMENT document, | 3513 FPDF_DOCUMENT document, |
3508 int page_index) { | 3514 int page_index) { |
3509 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3515 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3510 if (page_index < 0 || page_index >= static_cast<int>(engine->pages_.size())) | 3516 if (!engine->PageIndexInBounds(page_index)) |
3511 return nullptr; | 3517 return nullptr; |
3512 return engine->pages_[page_index]->GetPage(); | 3518 return engine->pages_[page_index]->GetPage(); |
3513 } | 3519 } |
3514 | 3520 |
3515 FPDF_PAGE PDFiumEngine::Form_GetCurrentPage(FPDF_FORMFILLINFO* param, | 3521 FPDF_PAGE PDFiumEngine::Form_GetCurrentPage(FPDF_FORMFILLINFO* param, |
3516 FPDF_DOCUMENT document) { | 3522 FPDF_DOCUMENT document) { |
3517 // TODO(jam): find out what this is used for. | |
3518 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3523 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3519 int index = engine->last_page_mouse_down_; | 3524 int index = engine->last_page_mouse_down_; |
3520 if (index == -1) { | 3525 if (index == -1) { |
3521 index = engine->GetMostVisiblePage(); | 3526 index = engine->GetMostVisiblePage(); |
3522 if (index == -1) { | 3527 if (index == -1) { |
3523 NOTREACHED(); | 3528 NOTREACHED(); |
3524 return nullptr; | 3529 return nullptr; |
3525 } | 3530 } |
3526 } | 3531 } |
3527 | 3532 |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4003 FPDF_DOCUMENT doc = | 4008 FPDF_DOCUMENT doc = |
4004 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4009 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4005 if (!doc) | 4010 if (!doc) |
4006 return false; | 4011 return false; |
4007 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4012 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4008 FPDF_CloseDocument(doc); | 4013 FPDF_CloseDocument(doc); |
4009 return success; | 4014 return success; |
4010 } | 4015 } |
4011 | 4016 |
4012 } // namespace chrome_pdf | 4017 } // namespace chrome_pdf |
OLD | NEW |