Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 1711753004: Cleanup misc nits in the PDF plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pdf/pdfium/pdfium_page.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 FPDF_AddInstalledFont(mapper, font_map->fontname, font_map->charset); 149 FPDF_AddInstalledFont(mapper, font_map->fontname, font_map->charset);
150 } 150 }
151 } 151 }
152 152
153 void* MapFont(struct _FPDF_SYSFONTINFO*, int weight, int italic, 153 void* MapFont(struct _FPDF_SYSFONTINFO*, int weight, int italic,
154 int charset, int pitch_family, const char* face, int* exact) { 154 int charset, int pitch_family, const char* face, int* exact) {
155 // Do not attempt to map fonts if pepper is not initialized (for privet local 155 // Do not attempt to map fonts if pepper is not initialized (for privet local
156 // printing). 156 // printing).
157 // TODO(noamsml): Real font substitution (http://crbug.com/391978) 157 // TODO(noamsml): Real font substitution (http://crbug.com/391978)
158 if (!pp::Module::Get()) 158 if (!pp::Module::Get())
159 return NULL; 159 return nullptr;
160 160
161 pp::BrowserFontDescription description; 161 pp::BrowserFontDescription description;
162 162
163 // Pretend the system does not have the Symbol font to force a fallback to 163 // Pretend the system does not have the Symbol font to force a fallback to
164 // the built in Symbol font in CFX_FontMapper::FindSubstFont(). 164 // the built in Symbol font in CFX_FontMapper::FindSubstFont().
165 if (strcmp(face, "Symbol") == 0) 165 if (strcmp(face, "Symbol") == 0)
166 return NULL; 166 return nullptr;
167 167
168 if (pitch_family & FXFONT_FF_FIXEDPITCH) { 168 if (pitch_family & FXFONT_FF_FIXEDPITCH) {
169 description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE); 169 description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE);
170 } else if (pitch_family & FXFONT_FF_ROMAN) { 170 } else if (pitch_family & FXFONT_FF_ROMAN) {
171 description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF); 171 description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF);
172 } 172 }
173 173
174 static const struct { 174 static const struct {
175 const char* pdf_name; 175 const char* pdf_name;
176 const char* face; 176 const char* face;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 if (face_utf8.empty()) 247 if (face_utf8.empty())
248 return nullptr; 248 return nullptr;
249 249
250 description.set_face(face_utf8); 250 description.set_face(face_utf8);
251 description.set_weight(WeightToBrowserFontTrustedWeight(weight)); 251 description.set_weight(WeightToBrowserFontTrustedWeight(weight));
252 description.set_italic(italic > 0); 252 description.set_italic(italic > 0);
253 } 253 }
254 254
255 if (!pp::PDF::IsAvailable()) { 255 if (!pp::PDF::IsAvailable()) {
256 NOTREACHED(); 256 NOTREACHED();
257 return NULL; 257 return nullptr;
258 } 258 }
259 259
260 PP_Resource font_resource = pp::PDF::GetFontFileWithFallback( 260 PP_Resource font_resource = pp::PDF::GetFontFileWithFallback(
261 pp::InstanceHandle(g_last_instance_id), 261 pp::InstanceHandle(g_last_instance_id),
262 &description.pp_font_description(), 262 &description.pp_font_description(),
263 static_cast<PP_PrivateFontCharset>(charset)); 263 static_cast<PP_PrivateFontCharset>(charset));
264 long res_id = font_resource; 264 long res_id = font_resource;
265 return reinterpret_cast<void*>(res_id); 265 return reinterpret_cast<void*>(res_id);
266 } 266 }
267 267
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 base::ReplaceChars(*text, kCr, kBlank, text); 399 base::ReplaceChars(*text, kCr, kBlank, text);
400 #elif defined(OS_WIN) 400 #elif defined(OS_WIN)
401 // Do nothing 401 // Do nothing
402 #else 402 #else
403 NOTIMPLEMENTED(); 403 NOTIMPLEMENTED();
404 #endif 404 #endif
405 } 405 }
406 406
407 // Returns a VarDictionary (representing a bookmark), which in turn contains 407 // Returns a VarDictionary (representing a bookmark), which in turn contains
408 // child VarDictionaries (representing the child bookmarks). 408 // child VarDictionaries (representing the child bookmarks).
409 // If NULL is passed in as the bookmark then we traverse from the "root". 409 // If nullptr is passed in as the bookmark then we traverse from the "root".
410 // Note that the "root" bookmark contains no useful information. 410 // Note that the "root" bookmark contains no useful information.
411 pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc, 411 pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc,
412 FPDF_BOOKMARK bookmark, 412 FPDF_BOOKMARK bookmark,
413 unsigned int depth) { 413 unsigned int depth) {
414 pp::VarDictionary dict; 414 pp::VarDictionary dict;
415 base::string16 title; 415 base::string16 title;
416 unsigned long buffer_size = FPDFBookmark_GetTitle(bookmark, nullptr, 0); 416 unsigned long buffer_size = FPDFBookmark_GetTitle(bookmark, nullptr, 0);
417 if (buffer_size > 0) { 417 if (buffer_size > 0) {
418 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> api_string_adapter( 418 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> api_string_adapter(
419 &title, buffer_size, true); 419 &title, buffer_size, true);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 PDFEngine* PDFEngine::Create(PDFEngine::Client* client) { 525 PDFEngine* PDFEngine::Create(PDFEngine::Client* client) {
526 return new PDFiumEngine(client); 526 return new PDFiumEngine(client);
527 } 527 }
528 528
529 PDFiumEngine::PDFiumEngine(PDFEngine::Client* client) 529 PDFiumEngine::PDFiumEngine(PDFEngine::Client* client)
530 : client_(client), 530 : client_(client),
531 current_zoom_(1.0), 531 current_zoom_(1.0),
532 current_rotation_(0), 532 current_rotation_(0),
533 doc_loader_(this), 533 doc_loader_(this),
534 password_tries_remaining_(0), 534 password_tries_remaining_(0),
535 doc_(NULL), 535 doc_(nullptr),
536 form_(NULL), 536 form_(nullptr),
537 defer_page_unload_(false), 537 defer_page_unload_(false),
538 selecting_(false), 538 selecting_(false),
539 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, 539 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA,
540 PDFiumPage::LinkTarget()), 540 PDFiumPage::LinkTarget()),
541 next_page_to_search_(-1), 541 next_page_to_search_(-1),
542 last_page_to_search_(-1), 542 last_page_to_search_(-1),
543 last_character_index_to_search_(-1), 543 last_character_index_to_search_(-1),
544 permissions_(0), 544 permissions_(0),
545 permissions_handler_revision_(-1), 545 permissions_handler_revision_(-1),
546 fpdf_availability_(NULL), 546 fpdf_availability_(nullptr),
547 next_timer_id_(0), 547 next_timer_id_(0),
548 last_page_mouse_down_(-1), 548 last_page_mouse_down_(-1),
549 most_visible_page_(-1), 549 most_visible_page_(-1),
550 called_do_document_action_(false), 550 called_do_document_action_(false),
551 render_grayscale_(false), 551 render_grayscale_(false),
552 progressive_paint_timeout_(0), 552 progressive_paint_timeout_(0),
553 getting_password_(false) { 553 getting_password_(false) {
554 find_factory_.Initialize(this); 554 find_factory_.Initialize(this);
555 password_factory_.Initialize(this); 555 password_factory_.Initialize(this);
556 556
557 file_access_.m_FileLen = 0; 557 file_access_.m_FileLen = 0;
558 file_access_.m_GetBlock = &GetBlock; 558 file_access_.m_GetBlock = &GetBlock;
559 file_access_.m_Param = &doc_loader_; 559 file_access_.m_Param = &doc_loader_;
560 560
561 file_availability_.version = 1; 561 file_availability_.version = 1;
562 file_availability_.IsDataAvail = &IsDataAvail; 562 file_availability_.IsDataAvail = &IsDataAvail;
563 file_availability_.loader = &doc_loader_; 563 file_availability_.loader = &doc_loader_;
564 564
565 download_hints_.version = 1; 565 download_hints_.version = 1;
566 download_hints_.AddSegment = &AddSegment; 566 download_hints_.AddSegment = &AddSegment;
567 download_hints_.loader = &doc_loader_; 567 download_hints_.loader = &doc_loader_;
568 568
569 // Initialize FPDF_FORMFILLINFO member variables. Deriving from this struct 569 // Initialize FPDF_FORMFILLINFO member variables. Deriving from this struct
570 // allows the static callbacks to be able to cast the FPDF_FORMFILLINFO in 570 // allows the static callbacks to be able to cast the FPDF_FORMFILLINFO in
571 // callbacks to ourself instead of maintaining a map of them to 571 // callbacks to ourself instead of maintaining a map of them to
572 // PDFiumEngine. 572 // PDFiumEngine.
573 FPDF_FORMFILLINFO::version = 1; 573 FPDF_FORMFILLINFO::version = 1;
574 FPDF_FORMFILLINFO::m_pJsPlatform = this; 574 FPDF_FORMFILLINFO::m_pJsPlatform = this;
575 FPDF_FORMFILLINFO::Release = NULL; 575 FPDF_FORMFILLINFO::Release = nullptr;
576 FPDF_FORMFILLINFO::FFI_Invalidate = Form_Invalidate; 576 FPDF_FORMFILLINFO::FFI_Invalidate = Form_Invalidate;
577 FPDF_FORMFILLINFO::FFI_OutputSelectedRect = Form_OutputSelectedRect; 577 FPDF_FORMFILLINFO::FFI_OutputSelectedRect = Form_OutputSelectedRect;
578 FPDF_FORMFILLINFO::FFI_SetCursor = Form_SetCursor; 578 FPDF_FORMFILLINFO::FFI_SetCursor = Form_SetCursor;
579 FPDF_FORMFILLINFO::FFI_SetTimer = Form_SetTimer; 579 FPDF_FORMFILLINFO::FFI_SetTimer = Form_SetTimer;
580 FPDF_FORMFILLINFO::FFI_KillTimer = Form_KillTimer; 580 FPDF_FORMFILLINFO::FFI_KillTimer = Form_KillTimer;
581 FPDF_FORMFILLINFO::FFI_GetLocalTime = Form_GetLocalTime; 581 FPDF_FORMFILLINFO::FFI_GetLocalTime = Form_GetLocalTime;
582 FPDF_FORMFILLINFO::FFI_OnChange = Form_OnChange; 582 FPDF_FORMFILLINFO::FFI_OnChange = Form_OnChange;
583 FPDF_FORMFILLINFO::FFI_GetPage = Form_GetPage; 583 FPDF_FORMFILLINFO::FFI_GetPage = Form_GetPage;
584 FPDF_FORMFILLINFO::FFI_GetCurrentPage = Form_GetCurrentPage; 584 FPDF_FORMFILLINFO::FFI_GetCurrentPage = Form_GetCurrentPage;
585 FPDF_FORMFILLINFO::FFI_GetRotation = Form_GetRotation; 585 FPDF_FORMFILLINFO::FFI_GetRotation = Form_GetRotation;
(...skipping 23 matching lines...) Expand all
609 IPDF_JSPLATFORM::app_beep = Form_Beep; 609 IPDF_JSPLATFORM::app_beep = Form_Beep;
610 IPDF_JSPLATFORM::app_response = Form_Response; 610 IPDF_JSPLATFORM::app_response = Form_Response;
611 IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath; 611 IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath;
612 IPDF_JSPLATFORM::Doc_mail = Form_Mail; 612 IPDF_JSPLATFORM::Doc_mail = Form_Mail;
613 IPDF_JSPLATFORM::Doc_print = Form_Print; 613 IPDF_JSPLATFORM::Doc_print = Form_Print;
614 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm; 614 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm;
615 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage; 615 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage;
616 IPDF_JSPLATFORM::Field_browse = Form_Browse; 616 IPDF_JSPLATFORM::Field_browse = Form_Browse;
617 617
618 IFSDK_PAUSE::version = 1; 618 IFSDK_PAUSE::version = 1;
619 IFSDK_PAUSE::user = NULL; 619 IFSDK_PAUSE::user = nullptr;
620 IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow; 620 IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow;
621 621
622 #if defined(OS_LINUX) 622 #if defined(OS_LINUX)
623 // PreviewModeClient does not know its pp::Instance. 623 // PreviewModeClient does not know its pp::Instance.
624 pp::Instance* instance = client_->GetPluginInstance(); 624 pp::Instance* instance = client_->GetPluginInstance();
625 if (instance) 625 if (instance)
626 g_last_instance_id = instance->pp_instance(); 626 g_last_instance_id = instance->pp_instance();
627 #endif 627 #endif
628 } 628 }
629 629
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 print_settings, 1344 print_settings,
1345 &pages_to_print[i]); 1345 &pages_to_print[i]);
1346 1346
1347 if (!temp_doc) 1347 if (!temp_doc)
1348 break; 1348 break;
1349 1349
1350 pp::Buffer_Dev buffer = GetFlattenedPrintData(temp_doc); 1350 pp::Buffer_Dev buffer = GetFlattenedPrintData(temp_doc);
1351 FPDF_CloseDocument(temp_doc); 1351 FPDF_CloseDocument(temp_doc);
1352 1352
1353 PDFiumMemBufferFileRead file_read(buffer.data(), buffer.size()); 1353 PDFiumMemBufferFileRead file_read(buffer.data(), buffer.size());
1354 temp_doc = FPDF_LoadCustomDocument(&file_read, NULL); 1354 temp_doc = FPDF_LoadCustomDocument(&file_read, nullptr);
1355 1355
1356 FPDF_BOOL imported = FPDF_ImportPages(output_doc, temp_doc, "1", i); 1356 FPDF_BOOL imported = FPDF_ImportPages(output_doc, temp_doc, "1", i);
1357 FPDF_CloseDocument(temp_doc); 1357 FPDF_CloseDocument(temp_doc);
1358 if (!imported) 1358 if (!imported)
1359 break; 1359 break;
1360 } 1360 }
1361 1361
1362 pp::Buffer_Dev buffer; 1362 pp::Buffer_Dev buffer;
1363 if (i == pages_to_print.size()) { 1363 if (i == pages_to_print.size()) {
1364 FPDF_CopyViewerPreferences(output_doc, doc_); 1364 FPDF_CopyViewerPreferences(output_doc, doc_);
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
2229 if (page->available()) 2229 if (page->available())
2230 selection_.push_back(PDFiumRange(page, 0, page->GetCharCount())); 2230 selection_.push_back(PDFiumRange(page, 0, page->GetCharCount()));
2231 } 2231 }
2232 } 2232 }
2233 2233
2234 int PDFiumEngine::GetNumberOfPages() { 2234 int PDFiumEngine::GetNumberOfPages() {
2235 return pages_.size(); 2235 return pages_.size();
2236 } 2236 }
2237 2237
2238 pp::VarArray PDFiumEngine::GetBookmarks() { 2238 pp::VarArray PDFiumEngine::GetBookmarks() {
2239 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL, 0); 2239 pp::VarDictionary dict = TraverseBookmarks(doc_, nullptr, 0);
2240 // The root bookmark contains no useful information. 2240 // The root bookmark contains no useful information.
2241 return pp::VarArray(dict.Get(pp::Var("children"))); 2241 return pp::VarArray(dict.Get(pp::Var("children")));
2242 } 2242 }
2243 2243
2244 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { 2244 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) {
2245 // Look for the destination. 2245 // Look for the destination.
2246 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); 2246 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str());
2247 if (!dest) { 2247 if (!dest) {
2248 // Look for a bookmark with the same name. 2248 // Look for a bookmark with the same name.
2249 base::string16 destination_wide = base::UTF8ToUTF16(destination); 2249 base::string16 destination_wide = base::UTF8ToUTF16(destination);
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2619 } 2619 }
2620 2620
2621 bool PDFiumEngine::IsPageVisible(int index) const { 2621 bool PDFiumEngine::IsPageVisible(int index) const {
2622 return ContainsValue(visible_pages_, index); 2622 return ContainsValue(visible_pages_, index);
2623 } 2623 }
2624 2624
2625 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { 2625 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) {
2626 if (!doc_ || !form_) 2626 if (!doc_ || !form_)
2627 return false; 2627 return false;
2628 2628
2629 if (static_cast<int>(pages_.size()) > index && pages_[index]->available()) 2629 const int num_pages = static_cast<int>(pages_.size());
2630 if (index < num_pages && pages_[index]->available())
2630 return true; 2631 return true;
2631 2632
2632 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { 2633 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) {
2633 size_t j; 2634 size_t j;
2634 for (j = 0; j < pending->size(); ++j) { 2635 for (j = 0; j < pending->size(); ++j) {
2635 if ((*pending)[j] == index) 2636 if ((*pending)[j] == index)
2636 break; 2637 break;
2637 } 2638 }
2638 2639
2639 if (j == pending->size()) 2640 if (j == pending->size())
2640 pending->push_back(index); 2641 pending->push_back(index);
2641 return false; 2642 return false;
2642 } 2643 }
2643 2644
2644 if (static_cast<int>(pages_.size()) > index) 2645 if (index < num_pages)
2645 pages_[index]->set_available(true); 2646 pages_[index]->set_available(true);
2646 if (!default_page_size_.GetArea()) 2647 if (!default_page_size_.GetArea())
2647 default_page_size_ = GetPageSize(index); 2648 default_page_size_ = GetPageSize(index);
2648 return true; 2649 return true;
2649 } 2650 }
2650 2651
2651 pp::Size PDFiumEngine::GetPageSize(int index) { 2652 pp::Size PDFiumEngine::GetPageSize(int index) {
2652 pp::Size size; 2653 pp::Size size;
2653 double width_in_points = 0; 2654 double width_in_points = 0;
2654 double height_in_points = 0; 2655 double height_in_points = 0;
(...skipping 12 matching lines...) Expand all
2667 return size; 2668 return size;
2668 } 2669 }
2669 2670
2670 int PDFiumEngine::StartPaint(int page_index, const pp::Rect& dirty) { 2671 int PDFiumEngine::StartPaint(int page_index, const pp::Rect& dirty) {
2671 // For the first time we hit paint, do nothing and just record the paint for 2672 // For the first time we hit paint, do nothing and just record the paint for
2672 // the next callback. This keeps the UI responsive in case the user is doing 2673 // the next callback. This keeps the UI responsive in case the user is doing
2673 // a lot of scrolling. 2674 // a lot of scrolling.
2674 ProgressivePaint progressive; 2675 ProgressivePaint progressive;
2675 progressive.rect = dirty; 2676 progressive.rect = dirty;
2676 progressive.page_index = page_index; 2677 progressive.page_index = page_index;
2677 progressive.bitmap = NULL; 2678 progressive.bitmap = nullptr;
2678 progressive.painted_ = false; 2679 progressive.painted_ = false;
2679 progressive_paints_.push_back(progressive); 2680 progressive_paints_.push_back(progressive);
2680 return progressive_paints_.size() - 1; 2681 return progressive_paints_.size() - 1;
2681 } 2682 }
2682 2683
2683 bool PDFiumEngine::ContinuePaint(int progressive_index, 2684 bool PDFiumEngine::ContinuePaint(int progressive_index,
2684 pp::ImageData* image_data) { 2685 pp::ImageData* image_data) {
2685 DCHECK_GE(progressive_index, 0); 2686 DCHECK_GE(progressive_index, 0);
2686 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); 2687 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size());
2687 DCHECK(image_data); 2688 DCHECK(image_data);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2833 2834
2834 void PDFiumEngine::DrawSelections(int progressive_index, 2835 void PDFiumEngine::DrawSelections(int progressive_index,
2835 pp::ImageData* image_data) { 2836 pp::ImageData* image_data) {
2836 DCHECK_GE(progressive_index, 0); 2837 DCHECK_GE(progressive_index, 0);
2837 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); 2838 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size());
2838 DCHECK(image_data); 2839 DCHECK(image_data);
2839 2840
2840 int page_index = progressive_paints_[progressive_index].page_index; 2841 int page_index = progressive_paints_[progressive_index].page_index;
2841 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; 2842 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect;
2842 2843
2843 void* region = NULL; 2844 void* region = nullptr;
2844 int stride; 2845 int stride;
2845 GetRegion(dirty_in_screen.point(), image_data, &region, &stride); 2846 GetRegion(dirty_in_screen.point(), image_data, &region, &stride);
2846 2847
2847 std::vector<pp::Rect> highlighted_rects; 2848 std::vector<pp::Rect> highlighted_rects;
2848 pp::Rect visible_rect = GetVisibleRect(); 2849 pp::Rect visible_rect = GetVisibleRect();
2849 for (auto& range : selection_) { 2850 for (auto& range : selection_) {
2850 if (range.page_index() != page_index) 2851 if (range.page_index() != page_index)
2851 continue; 2852 continue;
2852 2853
2853 std::vector<pp::Rect> rects = range.GetScreenRects( 2854 std::vector<pp::Rect> rects = range.GetScreenRects(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2898 } 2899 }
2899 return -1; 2900 return -1;
2900 } 2901 }
2901 2902
2902 FPDF_BITMAP PDFiumEngine::CreateBitmap(const pp::Rect& rect, 2903 FPDF_BITMAP PDFiumEngine::CreateBitmap(const pp::Rect& rect,
2903 pp::ImageData* image_data) const { 2904 pp::ImageData* image_data) const {
2904 void* region; 2905 void* region;
2905 int stride; 2906 int stride;
2906 GetRegion(rect.point(), image_data, &region, &stride); 2907 GetRegion(rect.point(), image_data, &region, &stride);
2907 if (!region) 2908 if (!region)
2908 return NULL; 2909 return nullptr;
2909 return FPDFBitmap_CreateEx( 2910 return FPDFBitmap_CreateEx(
2910 rect.width(), rect.height(), FPDFBitmap_BGRx, region, stride); 2911 rect.width(), rect.height(), FPDFBitmap_BGRx, region, stride);
2911 } 2912 }
2912 2913
2913 void PDFiumEngine::GetPDFiumRect( 2914 void PDFiumEngine::GetPDFiumRect(
2914 int page_index, const pp::Rect& rect, int* start_x, int* start_y, 2915 int page_index, const pp::Rect& rect, int* start_x, int* start_y,
2915 int* size_x, int* size_y) const { 2916 int* size_x, int* size_y) const {
2916 pp::Rect page_rect = GetScreenRect(pages_[page_index]->rect()); 2917 pp::Rect page_rect = GetScreenRect(pages_[page_index]->rect());
2917 page_rect.Offset(-rect.x(), -rect.y()); 2918 page_rect.Offset(-rect.x(), -rect.y());
2918 2919
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
3277 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_); 3278 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_);
3278 } 3279 }
3279 3280
3280 void PDFiumEngine::GetRegion(const pp::Point& location, 3281 void PDFiumEngine::GetRegion(const pp::Point& location,
3281 pp::ImageData* image_data, 3282 pp::ImageData* image_data,
3282 void** region, 3283 void** region,
3283 int* stride) const { 3284 int* stride) const {
3284 if (image_data->is_null()) { 3285 if (image_data->is_null()) {
3285 DCHECK(plugin_size_.IsEmpty()); 3286 DCHECK(plugin_size_.IsEmpty());
3286 *stride = 0; 3287 *stride = 0;
3287 *region = NULL; 3288 *region = nullptr;
3288 return; 3289 return;
3289 } 3290 }
3290 char* buffer = static_cast<char*>(image_data->data()); 3291 char* buffer = static_cast<char*>(image_data->data());
3291 *stride = image_data->stride(); 3292 *stride = image_data->stride();
3292 3293
3293 pp::Point offset_location = location + page_offset_; 3294 pp::Point offset_location = location + page_offset_;
3294 // TODO: update this when we support BIDI and scrollbars can be on the left. 3295 // TODO: update this when we support BIDI and scrollbars can be on the left.
3295 if (!buffer || 3296 if (!buffer ||
3296 !pp::Rect(page_offset_, plugin_size_).Contains(offset_location)) { 3297 !pp::Rect(page_offset_, plugin_size_).Contains(offset_location)) {
3297 *region = NULL; 3298 *region = nullptr;
3298 return; 3299 return;
3299 } 3300 }
3300 3301
3301 buffer += location.y() * (*stride); 3302 buffer += location.y() * (*stride);
3302 buffer += (location.x() + page_offset_.x()) * 4; 3303 buffer += (location.x() + page_offset_.x()) * 4;
3303 *region = buffer; 3304 *region = buffer;
3304 } 3305 }
3305 3306
3306 void PDFiumEngine::OnSelectionChanged() { 3307 void PDFiumEngine::OnSelectionChanged() {
3307 pp::PDF::SetSelectedText(GetPluginInstance(), GetSelectedText().c_str()); 3308 pp::PDF::SetSelectedText(GetPluginInstance(), GetSelectedText().c_str());
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
3409 3410
3410 void PDFiumEngine::Form_OnChange(FPDF_FORMFILLINFO* param) { 3411 void PDFiumEngine::Form_OnChange(FPDF_FORMFILLINFO* param) {
3411 // Don't care about. 3412 // Don't care about.
3412 } 3413 }
3413 3414
3414 FPDF_PAGE PDFiumEngine::Form_GetPage(FPDF_FORMFILLINFO* param, 3415 FPDF_PAGE PDFiumEngine::Form_GetPage(FPDF_FORMFILLINFO* param,
3415 FPDF_DOCUMENT document, 3416 FPDF_DOCUMENT document,
3416 int page_index) { 3417 int page_index) {
3417 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); 3418 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
3418 if (page_index < 0 || page_index >= static_cast<int>(engine->pages_.size())) 3419 if (page_index < 0 || page_index >= static_cast<int>(engine->pages_.size()))
3419 return NULL; 3420 return nullptr;
3420 return engine->pages_[page_index]->GetPage(); 3421 return engine->pages_[page_index]->GetPage();
3421 } 3422 }
3422 3423
3423 FPDF_PAGE PDFiumEngine::Form_GetCurrentPage(FPDF_FORMFILLINFO* param, 3424 FPDF_PAGE PDFiumEngine::Form_GetCurrentPage(FPDF_FORMFILLINFO* param,
3424 FPDF_DOCUMENT document) { 3425 FPDF_DOCUMENT document) {
3425 // TODO(jam): find out what this is used for. 3426 // TODO(jam): find out what this is used for.
3426 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); 3427 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
3427 int index = engine->last_page_mouse_down_; 3428 int index = engine->last_page_mouse_down_;
3428 if (index == -1) { 3429 if (index == -1) {
3429 index = engine->GetMostVisiblePage(); 3430 index = engine->GetMostVisiblePage();
3430 if (index == -1) { 3431 if (index == -1) {
3431 NOTREACHED(); 3432 NOTREACHED();
3432 return NULL; 3433 return nullptr;
3433 } 3434 }
3434 } 3435 }
3435 3436
3436 return engine->pages_[index]->GetPage(); 3437 return engine->pages_[index]->GetPage();
3437 } 3438 }
3438 3439
3439 int PDFiumEngine::Form_GetRotation(FPDF_FORMFILLINFO* param, FPDF_PAGE page) { 3440 int PDFiumEngine::Form_GetRotation(FPDF_FORMFILLINFO* param, FPDF_PAGE page) {
3440 return 0; 3441 return 0;
3441 } 3442 }
3442 3443
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
3726 PDFEngineExports* PDFEngineExports::Get() { 3727 PDFEngineExports* PDFEngineExports::Get() {
3727 return g_pdf_engine_exports.Pointer(); 3728 return g_pdf_engine_exports.Pointer();
3728 } 3729 }
3729 3730
3730 #if defined(OS_WIN) 3731 #if defined(OS_WIN)
3731 bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer, 3732 bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer,
3732 int buffer_size, 3733 int buffer_size,
3733 int page_number, 3734 int page_number,
3734 const RenderingSettings& settings, 3735 const RenderingSettings& settings,
3735 HDC dc) { 3736 HDC dc) {
3736 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, buffer_size, NULL); 3737 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, buffer_size, nullptr);
3737 if (!doc) 3738 if (!doc)
3738 return false; 3739 return false;
3739 FPDF_PAGE page = FPDF_LoadPage(doc, page_number); 3740 FPDF_PAGE page = FPDF_LoadPage(doc, page_number);
3740 if (!page) { 3741 if (!page) {
3741 FPDF_CloseDocument(doc); 3742 FPDF_CloseDocument(doc);
3742 return false; 3743 return false;
3743 } 3744 }
3744 RenderingSettings new_settings = settings; 3745 RenderingSettings new_settings = settings;
3745 // calculate the page size 3746 // calculate the page size
3746 if (new_settings.dpi_x == -1) 3747 if (new_settings.dpi_x == -1)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3798 return true; 3799 return true;
3799 } 3800 }
3800 #endif // defined(OS_WIN) 3801 #endif // defined(OS_WIN)
3801 3802
3802 bool PDFiumEngineExports::RenderPDFPageToBitmap( 3803 bool PDFiumEngineExports::RenderPDFPageToBitmap(
3803 const void* pdf_buffer, 3804 const void* pdf_buffer,
3804 int pdf_buffer_size, 3805 int pdf_buffer_size,
3805 int page_number, 3806 int page_number,
3806 const RenderingSettings& settings, 3807 const RenderingSettings& settings,
3807 void* bitmap_buffer) { 3808 void* bitmap_buffer) {
3808 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3809 FPDF_DOCUMENT doc =
3810 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3809 if (!doc) 3811 if (!doc)
3810 return false; 3812 return false;
3811 FPDF_PAGE page = FPDF_LoadPage(doc, page_number); 3813 FPDF_PAGE page = FPDF_LoadPage(doc, page_number);
3812 if (!page) { 3814 if (!page) {
3813 FPDF_CloseDocument(doc); 3815 FPDF_CloseDocument(doc);
3814 return false; 3816 return false;
3815 } 3817 }
3816 3818
3817 pp::Rect dest; 3819 pp::Rect dest;
3818 int rotate = CalculatePosition(page, settings, &dest); 3820 int rotate = CalculatePosition(page, settings, &dest);
(...skipping 13 matching lines...) Expand all
3832 FPDFBitmap_Destroy(bitmap); 3834 FPDFBitmap_Destroy(bitmap);
3833 FPDF_ClosePage(page); 3835 FPDF_ClosePage(page);
3834 FPDF_CloseDocument(doc); 3836 FPDF_CloseDocument(doc);
3835 return true; 3837 return true;
3836 } 3838 }
3837 3839
3838 bool PDFiumEngineExports::GetPDFDocInfo(const void* pdf_buffer, 3840 bool PDFiumEngineExports::GetPDFDocInfo(const void* pdf_buffer,
3839 int buffer_size, 3841 int buffer_size,
3840 int* page_count, 3842 int* page_count,
3841 double* max_page_width) { 3843 double* max_page_width) {
3842 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, buffer_size, NULL); 3844 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, buffer_size, nullptr);
3843 if (!doc) 3845 if (!doc)
3844 return false; 3846 return false;
3845 int page_count_local = FPDF_GetPageCount(doc); 3847 int page_count_local = FPDF_GetPageCount(doc);
3846 if (page_count) { 3848 if (page_count) {
3847 *page_count = page_count_local; 3849 *page_count = page_count_local;
3848 } 3850 }
3849 if (max_page_width) { 3851 if (max_page_width) {
3850 *max_page_width = 0; 3852 *max_page_width = 0;
3851 for (int page_number = 0; page_number < page_count_local; page_number++) { 3853 for (int page_number = 0; page_number < page_count_local; page_number++) {
3852 double page_width = 0; 3854 double page_width = 0;
3853 double page_height = 0; 3855 double page_height = 0;
3854 FPDF_GetPageSizeByIndex(doc, page_number, &page_width, &page_height); 3856 FPDF_GetPageSizeByIndex(doc, page_number, &page_width, &page_height);
3855 if (page_width > *max_page_width) { 3857 if (page_width > *max_page_width) {
3856 *max_page_width = page_width; 3858 *max_page_width = page_width;
3857 } 3859 }
3858 } 3860 }
3859 } 3861 }
3860 FPDF_CloseDocument(doc); 3862 FPDF_CloseDocument(doc);
3861 return true; 3863 return true;
3862 } 3864 }
3863 3865
3864 bool PDFiumEngineExports::GetPDFPageSizeByIndex( 3866 bool PDFiumEngineExports::GetPDFPageSizeByIndex(
3865 const void* pdf_buffer, 3867 const void* pdf_buffer,
3866 int pdf_buffer_size, 3868 int pdf_buffer_size,
3867 int page_number, 3869 int page_number,
3868 double* width, 3870 double* width,
3869 double* height) { 3871 double* height) {
3870 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3872 FPDF_DOCUMENT doc =
3873 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3871 if (!doc) 3874 if (!doc)
3872 return false; 3875 return false;
3873 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3876 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3874 FPDF_CloseDocument(doc); 3877 FPDF_CloseDocument(doc);
3875 return success; 3878 return success;
3876 } 3879 }
3877 3880
3878 } // namespace chrome_pdf 3881 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « no previous file | pdf/pdfium/pdfium_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698