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