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 2348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2359 if (pages_[i]->available()) { | 2359 if (pages_[i]->available()) { |
2360 selection_.push_back(PDFiumRange(pages_[i], 0, | 2360 selection_.push_back(PDFiumRange(pages_[i], 0, |
2361 pages_[i]->GetCharCount())); | 2361 pages_[i]->GetCharCount())); |
2362 } | 2362 } |
2363 } | 2363 } |
2364 | 2364 |
2365 int PDFiumEngine::GetNumberOfPages() { | 2365 int PDFiumEngine::GetNumberOfPages() { |
2366 return pages_.size(); | 2366 return pages_.size(); |
2367 } | 2367 } |
2368 | 2368 |
| 2369 uint32 PDFiumEngine::GetBackgroundColor() { |
| 2370 return background_color_; |
| 2371 } |
| 2372 |
| 2373 void PDFiumEngine::SetBackgroundColor(uint32 background_color) { |
| 2374 background_color_ = background_color; |
| 2375 } |
| 2376 |
2369 pp::VarArray PDFiumEngine::GetBookmarks() { | 2377 pp::VarArray PDFiumEngine::GetBookmarks() { |
2370 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL); | 2378 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL); |
2371 // The root bookmark contains no useful information. | 2379 // The root bookmark contains no useful information. |
2372 return pp::VarArray(dict.Get(pp::Var("children"))); | 2380 return pp::VarArray(dict.Get(pp::Var("children"))); |
2373 } | 2381 } |
2374 | 2382 |
2375 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { | 2383 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { |
2376 // Look for the destination. | 2384 // Look for the destination. |
2377 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); | 2385 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); |
2378 if (!dest) { | 2386 if (!dest) { |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2929 if (page_rect.x() > 0) { | 2937 if (page_rect.x() > 0) { |
2930 pp::Rect left(0, | 2938 pp::Rect left(0, |
2931 page_rect.y() - kPageShadowTop, | 2939 page_rect.y() - kPageShadowTop, |
2932 page_rect.x() - kPageShadowLeft, | 2940 page_rect.x() - kPageShadowLeft, |
2933 page_rect.height() + kPageShadowTop + | 2941 page_rect.height() + kPageShadowTop + |
2934 kPageShadowBottom + kPageSeparatorThickness); | 2942 kPageShadowBottom + kPageSeparatorThickness); |
2935 left = GetScreenRect(left).Intersect(dirty_in_screen); | 2943 left = GetScreenRect(left).Intersect(dirty_in_screen); |
2936 | 2944 |
2937 FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(), | 2945 FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(), |
2938 left.y() - dirty_in_screen.y(), left.width(), | 2946 left.y() - dirty_in_screen.y(), left.width(), |
2939 left.height(), kBackgroundColor); | 2947 left.height(), background_color_); |
2940 } | 2948 } |
2941 | 2949 |
2942 if (page_rect.right() < document_size_.width()) { | 2950 if (page_rect.right() < document_size_.width()) { |
2943 pp::Rect right(page_rect.right() + kPageShadowRight, | 2951 pp::Rect right(page_rect.right() + kPageShadowRight, |
2944 page_rect.y() - kPageShadowTop, | 2952 page_rect.y() - kPageShadowTop, |
2945 document_size_.width() - page_rect.right() - | 2953 document_size_.width() - page_rect.right() - |
2946 kPageShadowRight, | 2954 kPageShadowRight, |
2947 page_rect.height() + kPageShadowTop + | 2955 page_rect.height() + kPageShadowTop + |
2948 kPageShadowBottom + kPageSeparatorThickness); | 2956 kPageShadowBottom + kPageSeparatorThickness); |
2949 right = GetScreenRect(right).Intersect(dirty_in_screen); | 2957 right = GetScreenRect(right).Intersect(dirty_in_screen); |
2950 | 2958 |
2951 FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(), | 2959 FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(), |
2952 right.y() - dirty_in_screen.y(), right.width(), | 2960 right.y() - dirty_in_screen.y(), right.width(), |
2953 right.height(), kBackgroundColor); | 2961 right.height(), background_color_); |
2954 } | 2962 } |
2955 | 2963 |
2956 // Paint separator. | 2964 // Paint separator. |
2957 pp::Rect bottom(page_rect.x() - kPageShadowLeft, | 2965 pp::Rect bottom(page_rect.x() - kPageShadowLeft, |
2958 page_rect.bottom() + kPageShadowBottom, | 2966 page_rect.bottom() + kPageShadowBottom, |
2959 page_rect.width() + kPageShadowLeft + kPageShadowRight, | 2967 page_rect.width() + kPageShadowLeft + kPageShadowRight, |
2960 kPageSeparatorThickness); | 2968 kPageSeparatorThickness); |
2961 bottom = GetScreenRect(bottom).Intersect(dirty_in_screen); | 2969 bottom = GetScreenRect(bottom).Intersect(dirty_in_screen); |
2962 | 2970 |
2963 FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(), | 2971 FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(), |
2964 bottom.y() - dirty_in_screen.y(), bottom.width(), | 2972 bottom.y() - dirty_in_screen.y(), bottom.width(), |
2965 bottom.height(), kBackgroundColor); | 2973 bottom.height(), background_color_); |
2966 } | 2974 } |
2967 | 2975 |
2968 void PDFiumEngine::PaintPageShadow(int progressive_index, | 2976 void PDFiumEngine::PaintPageShadow(int progressive_index, |
2969 pp::ImageData* image_data) { | 2977 pp::ImageData* image_data) { |
2970 DCHECK_GE(progressive_index, 0); | 2978 DCHECK_GE(progressive_index, 0); |
2971 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); | 2979 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); |
2972 DCHECK(image_data); | 2980 DCHECK(image_data); |
2973 | 2981 |
2974 int page_index = progressive_paints_[progressive_index].page_index; | 2982 int page_index = progressive_paints_[progressive_index].page_index; |
2975 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; | 2983 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3407 const double factor = 0.5; | 3415 const double factor = 0.5; |
3408 uint32 depth = std::max( | 3416 uint32 depth = std::max( |
3409 std::max(page_rect.x() - shadow_rect.x(), | 3417 std::max(page_rect.x() - shadow_rect.x(), |
3410 page_rect.y() - shadow_rect.y()), | 3418 page_rect.y() - shadow_rect.y()), |
3411 std::max(shadow_rect.right() - page_rect.right(), | 3419 std::max(shadow_rect.right() - page_rect.right(), |
3412 shadow_rect.bottom() - page_rect.bottom())); | 3420 shadow_rect.bottom() - page_rect.bottom())); |
3413 depth = static_cast<uint32>(depth * 1.5) + 1; | 3421 depth = static_cast<uint32>(depth * 1.5) + 1; |
3414 | 3422 |
3415 // We need to check depth only to verify our copy of shadow matrix is correct. | 3423 // We need to check depth only to verify our copy of shadow matrix is correct. |
3416 if (!page_shadow_.get() || page_shadow_->depth() != depth) | 3424 if (!page_shadow_.get() || page_shadow_->depth() != depth) |
3417 page_shadow_.reset(new ShadowMatrix(depth, factor, kBackgroundColor)); | 3425 page_shadow_.reset(new ShadowMatrix(depth, factor, background_color_)); |
3418 | 3426 |
3419 DCHECK(!image_data->is_null()); | 3427 DCHECK(!image_data->is_null()); |
3420 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_); | 3428 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_); |
3421 } | 3429 } |
3422 | 3430 |
3423 void PDFiumEngine::GetRegion(const pp::Point& location, | 3431 void PDFiumEngine::GetRegion(const pp::Point& location, |
3424 pp::ImageData* image_data, | 3432 pp::ImageData* image_data, |
3425 void** region, | 3433 void** region, |
3426 int* stride) const { | 3434 int* stride) const { |
3427 if (image_data->is_null()) { | 3435 if (image_data->is_null()) { |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4017 double* height) { | 4025 double* height) { |
4018 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 4026 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
4019 if (!doc) | 4027 if (!doc) |
4020 return false; | 4028 return false; |
4021 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4029 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4022 FPDF_CloseDocument(doc); | 4030 FPDF_CloseDocument(doc); |
4023 return success; | 4031 return success; |
4024 } | 4032 } |
4025 | 4033 |
4026 } // namespace chrome_pdf | 4034 } // namespace chrome_pdf |
OLD | NEW |