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