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