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 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1957 | 1957 |
1958 std::string PDFiumEngine::GetPageAsJSON(int index) { | 1958 std::string PDFiumEngine::GetPageAsJSON(int index) { |
1959 if (!(HasPermission(PERMISSION_COPY) || | 1959 if (!(HasPermission(PERMISSION_COPY) || |
1960 HasPermission(PERMISSION_COPY_ACCESSIBLE))) { | 1960 HasPermission(PERMISSION_COPY_ACCESSIBLE))) { |
1961 return "{}"; | 1961 return "{}"; |
1962 } | 1962 } |
1963 | 1963 |
1964 if (index < 0 || static_cast<size_t>(index) > pages_.size() - 1) | 1964 if (index < 0 || static_cast<size_t>(index) > pages_.size() - 1) |
1965 return "{}"; | 1965 return "{}"; |
1966 | 1966 |
| 1967 // TODO(thestig) Remove after debugging http://crbug.com/402035 |
| 1968 CHECK(pages_[index]); |
1967 scoped_ptr<base::Value> node( | 1969 scoped_ptr<base::Value> node( |
1968 pages_[index]->GetAccessibleContentAsValue(current_rotation_)); | 1970 pages_[index]->GetAccessibleContentAsValue(current_rotation_)); |
1969 std::string page_json; | 1971 std::string page_json; |
1970 base::JSONWriter::Write(node.get(), &page_json); | 1972 base::JSONWriter::Write(node.get(), &page_json); |
1971 return page_json; | 1973 return page_json; |
1972 } | 1974 } |
1973 | 1975 |
1974 bool PDFiumEngine::GetPrintScaling() { | 1976 bool PDFiumEngine::GetPrintScaling() { |
1975 return !!FPDF_VIEWERREF_GetPrintScaling(doc_); | 1977 return !!FPDF_VIEWERREF_GetPrintScaling(doc_); |
1976 } | 1978 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2014 for (int i = 1; i < num_pages; ++i) { | 2016 for (int i = 1; i < num_pages; ++i) { |
2015 pp::Rect page_rect(page_rects[i]); | 2017 pp::Rect page_rect(page_rects[i]); |
2016 page_rect.Inset(kPageShadowLeft, kPageShadowTop, | 2018 page_rect.Inset(kPageShadowLeft, kPageShadowTop, |
2017 kPageShadowRight, kPageShadowBottom); | 2019 kPageShadowRight, kPageShadowBottom); |
2018 double width_in_points = | 2020 double width_in_points = |
2019 page_rect.width() * kPointsPerInch / kPixelsPerInch; | 2021 page_rect.width() * kPointsPerInch / kPixelsPerInch; |
2020 double height_in_points = | 2022 double height_in_points = |
2021 page_rect.height() * kPointsPerInch / kPixelsPerInch; | 2023 page_rect.height() * kPointsPerInch / kPixelsPerInch; |
2022 FPDFPage_New(doc_, i, width_in_points, height_in_points); | 2024 FPDFPage_New(doc_, i, width_in_points, height_in_points); |
2023 pages_.push_back(new PDFiumPage(this, i, page_rect, true)); | 2025 pages_.push_back(new PDFiumPage(this, i, page_rect, true)); |
| 2026 // TODO(thestig) Remove after debugging http://crbug.com/402035 |
| 2027 CHECK(pages_.back()); |
2024 } | 2028 } |
2025 | 2029 |
2026 CalculateVisiblePages(); | 2030 CalculateVisiblePages(); |
2027 if (document_size_ != old_document_size) | 2031 if (document_size_ != old_document_size) |
2028 client_->DocumentSizeUpdated(document_size_); | 2032 client_->DocumentSizeUpdated(document_size_); |
2029 } | 2033 } |
2030 | 2034 |
2031 void PDFiumEngine::LoadDocument() { | 2035 void PDFiumEngine::LoadDocument() { |
2032 // Check if the document is ready for loading. If it isn't just bail for now, | 2036 // Check if the document is ready for loading. If it isn't just bail for now, |
2033 // we will call LoadDocument() again later. | 2037 // we will call LoadDocument() again later. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 for (int i = 0; i < page_count; ++i) { | 2185 for (int i = 0; i < page_count; ++i) { |
2182 // Center pages relative to the entire document. | 2186 // Center pages relative to the entire document. |
2183 page_rects[i].set_x((document_size_.width() - page_rects[i].width()) / 2); | 2187 page_rects[i].set_x((document_size_.width() - page_rects[i].width()) / 2); |
2184 pp::Rect page_rect(page_rects[i]); | 2188 pp::Rect page_rect(page_rects[i]); |
2185 page_rect.Inset(kPageShadowLeft, kPageShadowTop, | 2189 page_rect.Inset(kPageShadowLeft, kPageShadowTop, |
2186 kPageShadowRight, kPageShadowBottom); | 2190 kPageShadowRight, kPageShadowBottom); |
2187 if (reload) { | 2191 if (reload) { |
2188 pages_[i]->set_rect(page_rect); | 2192 pages_[i]->set_rect(page_rect); |
2189 } else { | 2193 } else { |
2190 pages_.push_back(new PDFiumPage(this, i, page_rect, doc_complete)); | 2194 pages_.push_back(new PDFiumPage(this, i, page_rect, doc_complete)); |
| 2195 // TODO(thestig) Remove after debugging http://crbug.com/402035 |
| 2196 CHECK(pages_.back()); |
2191 } | 2197 } |
2192 } | 2198 } |
2193 | 2199 |
2194 CalculateVisiblePages(); | 2200 CalculateVisiblePages(); |
2195 if (document_size_ != old_document_size) | 2201 if (document_size_ != old_document_size) |
2196 client_->DocumentSizeUpdated(document_size_); | 2202 client_->DocumentSizeUpdated(document_size_); |
2197 } | 2203 } |
2198 | 2204 |
2199 void PDFiumEngine::CalculateVisiblePages() { | 2205 void PDFiumEngine::CalculateVisiblePages() { |
2200 // Clear pending requests queue, since it may contain requests to the pages | 2206 // Clear pending requests queue, since it may contain requests to the pages |
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3397 double* height) { | 3403 double* height) { |
3398 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3404 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3399 if (!doc) | 3405 if (!doc) |
3400 return false; | 3406 return false; |
3401 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3407 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3402 FPDF_CloseDocument(doc); | 3408 FPDF_CloseDocument(doc); |
3403 return success; | 3409 return success; |
3404 } | 3410 } |
3405 | 3411 |
3406 } // namespace chrome_pdf | 3412 } // namespace chrome_pdf |
OLD | NEW |