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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, | 520 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, |
521 PDFiumPage::LinkTarget()), | 521 PDFiumPage::LinkTarget()), |
522 next_page_to_search_(-1), | 522 next_page_to_search_(-1), |
523 last_page_to_search_(-1), | 523 last_page_to_search_(-1), |
524 last_character_index_to_search_(-1), | 524 last_character_index_to_search_(-1), |
525 permissions_(0), | 525 permissions_(0), |
526 permissions_handler_revision_(-1), | 526 permissions_handler_revision_(-1), |
527 fpdf_availability_(NULL), | 527 fpdf_availability_(NULL), |
528 next_timer_id_(0), | 528 next_timer_id_(0), |
529 last_page_mouse_down_(-1), | 529 last_page_mouse_down_(-1), |
| 530 first_visible_page_(-1), |
530 most_visible_page_(-1), | 531 most_visible_page_(-1), |
531 called_do_document_action_(false), | 532 called_do_document_action_(false), |
532 render_grayscale_(false), | 533 render_grayscale_(false), |
533 progressive_paint_timeout_(0), | 534 progressive_paint_timeout_(0), |
534 getting_password_(false) { | 535 getting_password_(false) { |
535 find_factory_.Initialize(this); | 536 find_factory_.Initialize(this); |
536 password_factory_.Initialize(this); | 537 password_factory_.Initialize(this); |
537 | 538 |
538 file_access_.m_FileLen = 0; | 539 file_access_.m_FileLen = 0; |
539 file_access_.m_GetBlock = &GetBlock; | 540 file_access_.m_GetBlock = &GetBlock; |
(...skipping 1729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 int page_index = -1; | 2270 int page_index = -1; |
2270 int form_type = FPDF_FORMFIELD_UNKNOWN; | 2271 int form_type = FPDF_FORMFIELD_UNKNOWN; |
2271 PDFiumPage::LinkTarget target; | 2272 PDFiumPage::LinkTarget target; |
2272 PDFiumPage::Area area = | 2273 PDFiumPage::Area area = |
2273 GetCharIndex(point, &page_index, &temp, &form_type, &target); | 2274 GetCharIndex(point, &page_index, &temp, &form_type, &target); |
2274 if (area == PDFiumPage::WEBLINK_AREA) | 2275 if (area == PDFiumPage::WEBLINK_AREA) |
2275 url = target.url; | 2276 url = target.url; |
2276 return url; | 2277 return url; |
2277 } | 2278 } |
2278 | 2279 |
| 2280 bool PDFiumEngine::IsSelecting() { |
| 2281 return selecting_; |
| 2282 } |
| 2283 |
2279 bool PDFiumEngine::HasPermission(DocumentPermission permission) const { | 2284 bool PDFiumEngine::HasPermission(DocumentPermission permission) const { |
2280 // PDF 1.7 spec, section 3.5.2 says: "If the revision number is 2 or greater, | 2285 // PDF 1.7 spec, section 3.5.2 says: "If the revision number is 2 or greater, |
2281 // the operations to which user access can be controlled are as follows: ..." | 2286 // the operations to which user access can be controlled are as follows: ..." |
2282 // | 2287 // |
2283 // Thus for revision numbers less than 2, permissions are ignored and this | 2288 // Thus for revision numbers less than 2, permissions are ignored and this |
2284 // always returns true. | 2289 // always returns true. |
2285 if (permissions_handler_revision_ < 2) | 2290 if (permissions_handler_revision_ < 2) |
2286 return true; | 2291 return true; |
2287 | 2292 |
2288 // Handle high quality printing permission separately for security handler | 2293 // Handle high quality printing permission separately for security handler |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2338 FPDF_WIDESTRING destination_pdf_wide = | 2343 FPDF_WIDESTRING destination_pdf_wide = |
2339 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); | 2344 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); |
2340 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); | 2345 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); |
2341 if (!bookmark) | 2346 if (!bookmark) |
2342 return -1; | 2347 return -1; |
2343 dest = FPDFBookmark_GetDest(doc_, bookmark); | 2348 dest = FPDFBookmark_GetDest(doc_, bookmark); |
2344 } | 2349 } |
2345 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; | 2350 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; |
2346 } | 2351 } |
2347 | 2352 |
| 2353 int PDFiumEngine::GetFirstVisiblePage() { |
| 2354 CalculateVisiblePages(); |
| 2355 return first_visible_page_; |
| 2356 } |
| 2357 |
2348 int PDFiumEngine::GetMostVisiblePage() { | 2358 int PDFiumEngine::GetMostVisiblePage() { |
2349 CalculateVisiblePages(); | 2359 CalculateVisiblePages(); |
2350 return most_visible_page_; | 2360 return most_visible_page_; |
2351 } | 2361 } |
2352 | 2362 |
2353 pp::Rect PDFiumEngine::GetPageRect(int index) { | 2363 pp::Rect PDFiumEngine::GetPageRect(int index) { |
2354 pp::Rect rc(pages_[index]->rect()); | 2364 pp::Rect rc(pages_[index]->rect()); |
2355 rc.Inset(-kPageShadowLeft, -kPageShadowTop, | 2365 rc.Inset(-kPageShadowLeft, -kPageShadowTop, |
2356 -kPageShadowRight, -kPageShadowBottom); | 2366 -kPageShadowRight, -kPageShadowBottom); |
2357 return rc; | 2367 return rc; |
2358 } | 2368 } |
2359 | 2369 |
2360 pp::Rect PDFiumEngine::GetPageContentsRect(int index) { | 2370 pp::Rect PDFiumEngine::GetPageContentsRect(int index) { |
2361 return GetScreenRect(pages_[index]->rect()); | 2371 return GetScreenRect(pages_[index]->rect()); |
2362 } | 2372 } |
2363 | 2373 |
| 2374 void PDFiumEngine::PaintThumbnail(pp::ImageData* image_data, int index) { |
| 2375 FPDF_BITMAP bitmap = FPDFBitmap_CreateEx( |
| 2376 image_data->size().width(), image_data->size().height(), |
| 2377 FPDFBitmap_BGRx, image_data->data(), image_data->stride()); |
| 2378 |
| 2379 if (pages_[index]->available()) { |
| 2380 FPDFBitmap_FillRect(bitmap, 0, 0, image_data->size().width(), |
| 2381 image_data->size().height(), 0xFFFFFFFF); |
| 2382 |
| 2383 FPDF_RenderPageBitmap( |
| 2384 bitmap, pages_[index]->GetPage(), 0, 0, image_data->size().width(), |
| 2385 image_data->size().height(), 0, GetRenderingFlags()); |
| 2386 } else { |
| 2387 FPDFBitmap_FillRect(bitmap, 0, 0, image_data->size().width(), |
| 2388 image_data->size().height(), kPendingPageColor); |
| 2389 } |
| 2390 |
| 2391 FPDFBitmap_Destroy(bitmap); |
| 2392 } |
| 2393 |
2364 void PDFiumEngine::SetGrayscale(bool grayscale) { | 2394 void PDFiumEngine::SetGrayscale(bool grayscale) { |
2365 render_grayscale_ = grayscale; | 2395 render_grayscale_ = grayscale; |
2366 } | 2396 } |
2367 | 2397 |
2368 void PDFiumEngine::OnCallback(int id) { | 2398 void PDFiumEngine::OnCallback(int id) { |
2369 if (!timers_.count(id)) | 2399 if (!timers_.count(id)) |
2370 return; | 2400 return; |
2371 | 2401 |
2372 timers_[id].second(id); | 2402 timers_[id].second(id); |
2373 if (timers_.count(id)) // The callback might delete the timer. | 2403 if (timers_.count(id)) // The callback might delete the timer. |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2682 // will be lost when the page is first closed anyways). | 2712 // will be lost when the page is first closed anyways). |
2683 if (static_cast<int>(i) == last_page_mouse_down_) | 2713 if (static_cast<int>(i) == last_page_mouse_down_) |
2684 last_page_mouse_down_ = -1; | 2714 last_page_mouse_down_ = -1; |
2685 } | 2715 } |
2686 } | 2716 } |
2687 | 2717 |
2688 // Any pending highlighting of form fields will be invalid since these are in | 2718 // Any pending highlighting of form fields will be invalid since these are in |
2689 // screen coordinates. | 2719 // screen coordinates. |
2690 form_highlights_.clear(); | 2720 form_highlights_.clear(); |
2691 | 2721 |
2692 int most_visible_page = visible_pages_.empty() ? 0 : visible_pages_.front(); | 2722 if (visible_pages_.size() == 0) |
2693 DCHECK_GE(most_visible_page, 0); | 2723 first_visible_page_ = -1; |
| 2724 else |
| 2725 first_visible_page_ = visible_pages_.front(); |
| 2726 |
| 2727 int most_visible_page = first_visible_page_; |
2694 // Check if the next page is more visible than the first one. | 2728 // Check if the next page is more visible than the first one. |
2695 if (!pages_.empty() && | 2729 if (most_visible_page != -1 && |
| 2730 pages_.size() > 0 && |
2696 most_visible_page < static_cast<int>(pages_.size()) - 1) { | 2731 most_visible_page < static_cast<int>(pages_.size()) - 1) { |
2697 pp::Rect rc_first = | 2732 pp::Rect rc_first = |
2698 visible_rect.Intersect(GetPageScreenRect(most_visible_page)); | 2733 visible_rect.Intersect(GetPageScreenRect(most_visible_page)); |
2699 pp::Rect rc_next = | 2734 pp::Rect rc_next = |
2700 visible_rect.Intersect(GetPageScreenRect(most_visible_page + 1)); | 2735 visible_rect.Intersect(GetPageScreenRect(most_visible_page + 1)); |
2701 if (rc_next.height() > rc_first.height()) | 2736 if (rc_next.height() > rc_first.height()) |
2702 most_visible_page++; | 2737 most_visible_page++; |
2703 } | 2738 } |
2704 | 2739 |
2705 SetCurrentPage(most_visible_page); | 2740 SetCurrentPage(most_visible_page); |
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3973 double* height) { | 4008 double* height) { |
3974 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 4009 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3975 if (!doc) | 4010 if (!doc) |
3976 return false; | 4011 return false; |
3977 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4012 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3978 FPDF_CloseDocument(doc); | 4013 FPDF_CloseDocument(doc); |
3979 return success; | 4014 return success; |
3980 } | 4015 } |
3981 | 4016 |
3982 } // namespace chrome_pdf | 4017 } // namespace chrome_pdf |
OLD | NEW |