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 2504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2515 FinishLoadingDocument(); | 2515 FinishLoadingDocument(); |
2516 } | 2516 } |
2517 | 2517 |
2518 void PDFiumEngine::LoadPageInfo(bool reload) { | 2518 void PDFiumEngine::LoadPageInfo(bool reload) { |
2519 pending_pages_.clear(); | 2519 pending_pages_.clear(); |
2520 pp::Size old_document_size = document_size_; | 2520 pp::Size old_document_size = document_size_; |
2521 document_size_ = pp::Size(); | 2521 document_size_ = pp::Size(); |
2522 std::vector<pp::Rect> page_rects; | 2522 std::vector<pp::Rect> page_rects; |
2523 int page_count = FPDF_GetPageCount(doc_); | 2523 int page_count = FPDF_GetPageCount(doc_); |
2524 bool doc_complete = doc_loader_.IsDocumentComplete(); | 2524 bool doc_complete = doc_loader_.IsDocumentComplete(); |
| 2525 bool is_linear = FPDFAvail_IsLinearized(fpdf_availability_) == PDF_LINEARIZED; |
2525 for (int i = 0; i < page_count; ++i) { | 2526 for (int i = 0; i < page_count; ++i) { |
2526 if (i != 0) { | 2527 if (i != 0) { |
2527 // Add space for horizontal separator. | 2528 // Add space for horizontal separator. |
2528 document_size_.Enlarge(0, kPageSeparatorThickness); | 2529 document_size_.Enlarge(0, kPageSeparatorThickness); |
2529 } | 2530 } |
2530 | 2531 |
2531 // Get page availability. If reload==false, and document is not loaded yet | 2532 // Get page availability. If |reload| == true, then the document has been |
2532 // (we are using async loading) - mark all pages as unavailable. | 2533 // constructed already. Get page availability flag from already existing |
2533 // If reload==true (we have document constructed already), get page | 2534 // PDFiumPage class. |
2534 // availability flag from already existing PDFiumPage class. | 2535 // If |reload| == false, then the document may not be fully loaded yet. |
2535 bool page_available = reload ? pages_[i]->available() : doc_complete; | 2536 bool page_available; |
| 2537 if (reload) { |
| 2538 page_available = pages_[i]->available(); |
| 2539 } else if (is_linear) { |
| 2540 int linear_page_avail = |
| 2541 FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_); |
| 2542 page_available = linear_page_avail == PDF_DATA_AVAIL; |
| 2543 } else { |
| 2544 page_available = doc_complete; |
| 2545 } |
2536 | 2546 |
2537 pp::Size size = page_available ? GetPageSize(i) : default_page_size_; | 2547 pp::Size size = page_available ? GetPageSize(i) : default_page_size_; |
2538 size.Enlarge(kPageShadowLeft + kPageShadowRight, | 2548 size.Enlarge(kPageShadowLeft + kPageShadowRight, |
2539 kPageShadowTop + kPageShadowBottom); | 2549 kPageShadowTop + kPageShadowBottom); |
2540 pp::Rect rect(pp::Point(0, document_size_.height()), size); | 2550 pp::Rect rect(pp::Point(0, document_size_.height()), size); |
2541 page_rects.push_back(rect); | 2551 page_rects.push_back(rect); |
2542 | 2552 |
2543 if (size.width() > document_size_.width()) | 2553 if (size.width() > document_size_.width()) |
2544 document_size_.set_width(size.width()); | 2554 document_size_.set_width(size.width()); |
2545 | 2555 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2625 | 2635 |
2626 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { | 2636 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { |
2627 if (!doc_ || !form_) | 2637 if (!doc_ || !form_) |
2628 return false; | 2638 return false; |
2629 | 2639 |
2630 const int num_pages = static_cast<int>(pages_.size()); | 2640 const int num_pages = static_cast<int>(pages_.size()); |
2631 if (index < num_pages && pages_[index]->available()) | 2641 if (index < num_pages && pages_[index]->available()) |
2632 return true; | 2642 return true; |
2633 | 2643 |
2634 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { | 2644 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { |
2635 size_t j; | 2645 if (!ContainsValue(*pending, index)) |
2636 for (j = 0; j < pending->size(); ++j) { | |
2637 if ((*pending)[j] == index) | |
2638 break; | |
2639 } | |
2640 | |
2641 if (j == pending->size()) | |
2642 pending->push_back(index); | 2646 pending->push_back(index); |
2643 return false; | 2647 return false; |
2644 } | 2648 } |
2645 | 2649 |
2646 if (index < num_pages) | 2650 if (index < num_pages) |
2647 pages_[index]->set_available(true); | 2651 pages_[index]->set_available(true); |
2648 if (!default_page_size_.GetArea()) | 2652 if (!default_page_size_.GetArea()) |
2649 default_page_size_ = GetPageSize(index); | 2653 default_page_size_ = GetPageSize(index); |
2650 return true; | 2654 return true; |
2651 } | 2655 } |
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3873 FPDF_DOCUMENT doc = | 3877 FPDF_DOCUMENT doc = |
3874 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 3878 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
3875 if (!doc) | 3879 if (!doc) |
3876 return false; | 3880 return false; |
3877 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3881 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3878 FPDF_CloseDocument(doc); | 3882 FPDF_CloseDocument(doc); |
3879 return success; | 3883 return success; |
3880 } | 3884 } |
3881 | 3885 |
3882 } // namespace chrome_pdf | 3886 } // namespace chrome_pdf |
OLD | NEW |