| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } else if (pitch_family & FXFONT_FF_ROMAN) { | 184 } else if (pitch_family & FXFONT_FF_ROMAN) { |
| 185 description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF); | 185 description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF); |
| 186 } | 186 } |
| 187 | 187 |
| 188 static const struct { | 188 static const struct { |
| 189 const char* pdf_name; | 189 const char* pdf_name; |
| 190 const char* face; | 190 const char* face; |
| 191 bool bold; | 191 bool bold; |
| 192 bool italic; | 192 bool italic; |
| 193 } kPdfFontSubstitutions[] = { | 193 } kPdfFontSubstitutions[] = { |
| 194 {"Courier", "Courier New", false, false}, | 194 {"Courier", "Courier New", false, false}, |
| 195 {"Courier-Bold", "Courier New", true, false}, | 195 {"Courier-Bold", "Courier New", true, false}, |
| 196 {"Courier-BoldOblique", "Courier New", true, true}, | 196 {"Courier-BoldOblique", "Courier New", true, true}, |
| 197 {"Courier-Oblique", "Courier New", false, true}, | 197 {"Courier-Oblique", "Courier New", false, true}, |
| 198 {"Helvetica", "Arial", false, false}, | 198 {"Helvetica", "Arial", false, false}, |
| 199 {"Helvetica-Bold", "Arial", true, false}, | 199 {"Helvetica-Bold", "Arial", true, false}, |
| 200 {"Helvetica-BoldOblique", "Arial", true, true}, | 200 {"Helvetica-BoldOblique", "Arial", true, true}, |
| 201 {"Helvetica-Oblique", "Arial", false, true}, | 201 {"Helvetica-Oblique", "Arial", false, true}, |
| 202 {"Times-Roman", "Times New Roman", false, false}, | 202 {"Times-Roman", "Times New Roman", false, false}, |
| 203 {"Times-Bold", "Times New Roman", true, false}, | 203 {"Times-Bold", "Times New Roman", true, false}, |
| 204 {"Times-BoldItalic", "Times New Roman", true, true}, | 204 {"Times-BoldItalic", "Times New Roman", true, true}, |
| 205 {"Times-Italic", "Times New Roman", false, true}, | 205 {"Times-Italic", "Times New Roman", false, true}, |
| 206 | 206 |
| 207 // MS P?(Mincho|Gothic) are the most notable fonts in Japanese PDF files | 207 // MS P?(Mincho|Gothic) are the most notable fonts in Japanese PDF files |
| 208 // without embedding the glyphs. Sometimes the font names are encoded | 208 // without embedding the glyphs. Sometimes the font names are encoded |
| 209 // in Japanese Windows's locale (CP932/Shift_JIS) without space. | 209 // in Japanese Windows's locale (CP932/Shift_JIS) without space. |
| 210 // Most Linux systems don't have the exact font, but for outsourcing | 210 // Most Linux systems don't have the exact font, but for outsourcing |
| 211 // fontconfig to find substitutable font in the system, we pass ASCII | 211 // fontconfig to find substitutable font in the system, we pass ASCII |
| 212 // font names to it. | 212 // font names to it. |
| 213 {"MS-PGothic", "MS PGothic", false, false}, | 213 {"MS-PGothic", "MS PGothic", false, false}, |
| 214 {"MS-Gothic", "MS Gothic", false, false}, | 214 {"MS-Gothic", "MS Gothic", false, false}, |
| 215 {"MS-PMincho", "MS PMincho", false, false}, | 215 {"MS-PMincho", "MS PMincho", false, false}, |
| 216 {"MS-Mincho", "MS Mincho", false, false}, | 216 {"MS-Mincho", "MS Mincho", false, false}, |
| 217 // MS PGothic in Shift_JIS encoding. | 217 // MS PGothic in Shift_JIS encoding. |
| 218 {"\x82\x6C\x82\x72\x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E", | 218 {"\x82\x6C\x82\x72\x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E", "MS PGothic", |
| 219 "MS PGothic", false, false}, | 219 false, false}, |
| 220 // MS Gothic in Shift_JIS encoding. | 220 // MS Gothic in Shift_JIS encoding. |
| 221 {"\x82\x6C\x82\x72\x83\x53\x83\x56\x83\x62\x83\x4E", | 221 {"\x82\x6C\x82\x72\x83\x53\x83\x56\x83\x62\x83\x4E", "MS Gothic", false, |
| 222 "MS Gothic", false, false}, | 222 false}, |
| 223 // MS PMincho in Shift_JIS encoding. | 223 // MS PMincho in Shift_JIS encoding. |
| 224 {"\x82\x6C\x82\x72\x82\x6F\x96\xBE\x92\xA9", | 224 {"\x82\x6C\x82\x72\x82\x6F\x96\xBE\x92\xA9", "MS PMincho", false, false}, |
| 225 "MS PMincho", false, false}, | 225 // MS Mincho in Shift_JIS encoding. |
| 226 // MS Mincho in Shift_JIS encoding. | 226 {"\x82\x6C\x82\x72\x96\xBE\x92\xA9", "MS Mincho", false, false}, |
| 227 {"\x82\x6C\x82\x72\x96\xBE\x92\xA9", | |
| 228 "MS Mincho", false, false}, | |
| 229 }; | 227 }; |
| 230 | 228 |
| 231 // Similar logic exists in PDFium's CFX_FolderFontInfo::FindFont(). | 229 // Similar logic exists in PDFium's CFX_FolderFontInfo::FindFont(). |
| 232 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) | 230 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) |
| 233 face = "Courier New"; | 231 face = "Courier New"; |
| 234 | 232 |
| 235 // Map from the standard PDF fonts to TrueType font names. | 233 // Map from the standard PDF fonts to TrueType font names. |
| 236 size_t i; | 234 size_t i; |
| 237 for (i = 0; i < arraysize(kPdfFontSubstitutions); ++i) { | 235 for (i = 0; i < arraysize(kPdfFontSubstitutions); ++i) { |
| 238 if (strcmp(face, kPdfFontSubstitutions[i].pdf_name) == 0) { | 236 if (strcmp(face, kPdfFontSubstitutions[i].pdf_name) == 0) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 if (!pp::PDF::GetFontTableForPrivateFontFile(res_id, table, buffer, &size)) | 295 if (!pp::PDF::GetFontTableForPrivateFontFile(res_id, table, buffer, &size)) |
| 298 return 0; | 296 return 0; |
| 299 return size; | 297 return size; |
| 300 } | 298 } |
| 301 | 299 |
| 302 void DeleteFont(FPDF_SYSFONTINFO*, void* font_id) { | 300 void DeleteFont(FPDF_SYSFONTINFO*, void* font_id) { |
| 303 long res_id = reinterpret_cast<long>(font_id); | 301 long res_id = reinterpret_cast<long>(font_id); |
| 304 pp::Module::Get()->core()->ReleaseResource(res_id); | 302 pp::Module::Get()->core()->ReleaseResource(res_id); |
| 305 } | 303 } |
| 306 | 304 |
| 307 FPDF_SYSFONTINFO g_font_info = { | 305 FPDF_SYSFONTINFO g_font_info = {1, 0, EnumFonts, MapFont, 0, |
| 308 1, | 306 GetFontData, 0, 0, DeleteFont}; |
| 309 0, | |
| 310 EnumFonts, | |
| 311 MapFont, | |
| 312 0, | |
| 313 GetFontData, | |
| 314 0, | |
| 315 0, | |
| 316 DeleteFont | |
| 317 }; | |
| 318 #else | 307 #else |
| 319 struct FPDF_SYSFONTINFO_WITHMETRICS : public FPDF_SYSFONTINFO { | 308 struct FPDF_SYSFONTINFO_WITHMETRICS : public FPDF_SYSFONTINFO { |
| 320 explicit FPDF_SYSFONTINFO_WITHMETRICS(FPDF_SYSFONTINFO* sysfontinfo) { | 309 explicit FPDF_SYSFONTINFO_WITHMETRICS(FPDF_SYSFONTINFO* sysfontinfo) { |
| 321 version = sysfontinfo->version; | 310 version = sysfontinfo->version; |
| 322 default_sysfontinfo = sysfontinfo; | 311 default_sysfontinfo = sysfontinfo; |
| 323 } | 312 } |
| 324 | 313 |
| 325 ~FPDF_SYSFONTINFO_WITHMETRICS() { | 314 ~FPDF_SYSFONTINFO_WITHMETRICS() { |
| 326 FPDF_FreeDefaultSystemFontInfo(default_sysfontinfo); | 315 FPDF_FreeDefaultSystemFontInfo(default_sysfontinfo); |
| 327 } | 316 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 415 |
| 427 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { | 416 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { |
| 428 if (!g_engine_for_unsupported) { | 417 if (!g_engine_for_unsupported) { |
| 429 NOTREACHED(); | 418 NOTREACHED(); |
| 430 return; | 419 return; |
| 431 } | 420 } |
| 432 | 421 |
| 433 g_engine_for_unsupported->UnsupportedFeature(type); | 422 g_engine_for_unsupported->UnsupportedFeature(type); |
| 434 } | 423 } |
| 435 | 424 |
| 436 UNSUPPORT_INFO g_unsupported_info = { | 425 UNSUPPORT_INFO g_unsupported_info = {1, Unsupported_Handler}; |
| 437 1, | |
| 438 Unsupported_Handler | |
| 439 }; | |
| 440 | 426 |
| 441 // Set the destination page size and content area in points based on source | 427 // Set the destination page size and content area in points based on source |
| 442 // page rotation and orientation. | 428 // page rotation and orientation. |
| 443 // | 429 // |
| 444 // |rotated| True if source page is rotated 90 degree or 270 degree. | 430 // |rotated| True if source page is rotated 90 degree or 270 degree. |
| 445 // |is_src_page_landscape| is true if the source page orientation is landscape. | 431 // |is_src_page_landscape| is true if the source page orientation is landscape. |
| 446 // |page_size| has the actual destination page size in points. | 432 // |page_size| has the actual destination page size in points. |
| 447 // |content_rect| has the actual destination page printable area values in | 433 // |content_rect| has the actual destination page printable area values in |
| 448 // points. | 434 // points. |
| 449 void SetPageSizeAndContentRect(bool rotated, | 435 void SetPageSizeAndContentRect(bool rotated, |
| 450 bool is_src_page_landscape, | 436 bool is_src_page_landscape, |
| 451 pp::Size* page_size, | 437 pp::Size* page_size, |
| 452 pp::Rect* content_rect) { | 438 pp::Rect* content_rect) { |
| 453 bool is_dst_page_landscape = page_size->width() > page_size->height(); | 439 bool is_dst_page_landscape = page_size->width() > page_size->height(); |
| 454 bool page_orientation_mismatched = is_src_page_landscape != | 440 bool page_orientation_mismatched = |
| 455 is_dst_page_landscape; | 441 is_src_page_landscape != is_dst_page_landscape; |
| 456 bool rotate_dst_page = rotated ^ page_orientation_mismatched; | 442 bool rotate_dst_page = rotated ^ page_orientation_mismatched; |
| 457 if (rotate_dst_page) { | 443 if (rotate_dst_page) { |
| 458 page_size->SetSize(page_size->height(), page_size->width()); | 444 page_size->SetSize(page_size->height(), page_size->width()); |
| 459 content_rect->SetRect(content_rect->y(), content_rect->x(), | 445 content_rect->SetRect(content_rect->y(), content_rect->x(), |
| 460 content_rect->height(), content_rect->width()); | 446 content_rect->height(), content_rect->width()); |
| 461 } | 447 } |
| 462 } | 448 } |
| 463 | 449 |
| 464 // This formats a string with special 0xfffe end-of-line hyphens the same way | 450 // This formats a string with special 0xfffe end-of-line hyphens the same way |
| 465 // as Adobe Reader. When a hyphen is encountered, the next non-CR/LF whitespace | 451 // as Adobe Reader. When a hyphen is encountered, the next non-CR/LF whitespace |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 // Some bookmarks don't have a page to select. | 536 // Some bookmarks don't have a page to select. |
| 551 if (dest) { | 537 if (dest) { |
| 552 int page_index = FPDFDest_GetPageIndex(doc, dest); | 538 int page_index = FPDFDest_GetPageIndex(doc, dest); |
| 553 dict.Set(pp::Var("page"), pp::Var(page_index)); | 539 dict.Set(pp::Var("page"), pp::Var(page_index)); |
| 554 } else { | 540 } else { |
| 555 // Extract URI for bookmarks linking to an external page. | 541 // Extract URI for bookmarks linking to an external page. |
| 556 FPDF_ACTION action = FPDFBookmark_GetAction(bookmark); | 542 FPDF_ACTION action = FPDFBookmark_GetAction(bookmark); |
| 557 buffer_size = FPDFAction_GetURIPath(doc, action, nullptr, 0); | 543 buffer_size = FPDFAction_GetURIPath(doc, action, nullptr, 0); |
| 558 if (buffer_size > 0) { | 544 if (buffer_size > 0) { |
| 559 std::string uri; | 545 std::string uri; |
| 560 PDFiumAPIStringBufferAdapter<std::string> | 546 PDFiumAPIStringBufferAdapter<std::string> api_string_adapter( |
| 561 api_string_adapter(&uri, buffer_size, true); | 547 &uri, buffer_size, true); |
| 562 api_string_adapter.Close(FPDFAction_GetURIPath( | 548 api_string_adapter.Close(FPDFAction_GetURIPath( |
| 563 doc, action, api_string_adapter.GetData(), buffer_size)); | 549 doc, action, api_string_adapter.GetData(), buffer_size)); |
| 564 dict.Set(pp::Var("uri"), pp::Var(uri)); | 550 dict.Set(pp::Var("uri"), pp::Var(uri)); |
| 565 } | 551 } |
| 566 } | 552 } |
| 567 | 553 |
| 568 pp::VarArray children; | 554 pp::VarArray children; |
| 569 | 555 |
| 570 // Don't trust PDFium to handle circular bookmarks. | 556 // Don't trust PDFium to handle circular bookmarks. |
| 571 const unsigned int kMaxDepth = 128; | 557 const unsigned int kMaxDepth = 128; |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 int platform_flag = -1; | 863 int platform_flag = -1; |
| 878 | 864 |
| 879 #if defined(WIN32) | 865 #if defined(WIN32) |
| 880 platform_flag = 0; | 866 platform_flag = 0; |
| 881 #elif defined(__linux__) | 867 #elif defined(__linux__) |
| 882 platform_flag = 1; | 868 platform_flag = 1; |
| 883 #else | 869 #else |
| 884 platform_flag = 2; | 870 platform_flag = 2; |
| 885 #endif | 871 #endif |
| 886 | 872 |
| 887 std::string javascript = "alert(\"Platform:" | 873 std::string javascript = |
| 888 + base::DoubleToString(platform_flag) | 874 "alert(\"Platform:" + base::DoubleToString(platform_flag) + "\")"; |
| 889 + "\")"; | |
| 890 | 875 |
| 891 return platform_flag; | 876 return platform_flag; |
| 892 } | 877 } |
| 893 | 878 |
| 894 FPDF_BOOL PDFiumEngine::Form_PopupMenu(FPDF_FORMFILLINFO* param, | 879 FPDF_BOOL PDFiumEngine::Form_PopupMenu(FPDF_FORMFILLINFO* param, |
| 895 FPDF_PAGE page, | 880 FPDF_PAGE page, |
| 896 FPDF_WIDGET widget, | 881 FPDF_WIDGET widget, |
| 897 int menu_flag, | 882 int menu_flag, |
| 898 float x, | 883 float x, |
| 899 float y) { | 884 float y) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 911 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 896 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); |
| 912 std::string data_str = | 897 std::string data_str = |
| 913 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(data)); | 898 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(data)); |
| 914 std::string content_type_str = | 899 std::string content_type_str = |
| 915 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(content_type)); | 900 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(content_type)); |
| 916 std::string encode_str = | 901 std::string encode_str = |
| 917 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(encode)); | 902 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(encode)); |
| 918 std::string header_str = | 903 std::string header_str = |
| 919 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(header)); | 904 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(header)); |
| 920 | 905 |
| 921 std::string javascript = "alert(\"Post:" | 906 std::string javascript = "alert(\"Post:" + url_str + "," + data_str + "," + |
| 922 + url_str + "," + data_str + "," + content_type_str + "," | 907 content_type_str + "," + encode_str + "," + |
| 923 + encode_str + "," + header_str | 908 header_str + "\")"; |
| 924 + "\")"; | |
| 925 return true; | 909 return true; |
| 926 } | 910 } |
| 927 | 911 |
| 928 FPDF_BOOL PDFiumEngine::Form_PutRequestURL(FPDF_FORMFILLINFO* param, | 912 FPDF_BOOL PDFiumEngine::Form_PutRequestURL(FPDF_FORMFILLINFO* param, |
| 929 FPDF_WIDESTRING url, | 913 FPDF_WIDESTRING url, |
| 930 FPDF_WIDESTRING data, | 914 FPDF_WIDESTRING data, |
| 931 FPDF_WIDESTRING encode) { | 915 FPDF_WIDESTRING encode) { |
| 932 std::string url_str = | 916 std::string url_str = |
| 933 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 917 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); |
| 934 std::string data_str = | 918 std::string data_str = |
| 935 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(data)); | 919 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(data)); |
| 936 std::string encode_str = | 920 std::string encode_str = |
| 937 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(encode)); | 921 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(encode)); |
| 938 | 922 |
| 939 std::string javascript = "alert(\"Put:" | 923 std::string javascript = |
| 940 + url_str + "," + data_str + "," + encode_str | 924 "alert(\"Put:" + url_str + "," + data_str + "," + encode_str + "\")"; |
| 941 + "\")"; | |
| 942 | 925 |
| 943 return true; | 926 return true; |
| 944 } | 927 } |
| 945 | 928 |
| 946 void PDFiumEngine::Form_UploadTo(FPDF_FORMFILLINFO* param, | 929 void PDFiumEngine::Form_UploadTo(FPDF_FORMFILLINFO* param, |
| 947 FPDF_FILEHANDLER* file_handle, | 930 FPDF_FILEHANDLER* file_handle, |
| 948 int file_flag, | 931 int file_flag, |
| 949 FPDF_WIDESTRING to) { | 932 FPDF_WIDESTRING to) { |
| 950 std::string to_str = | 933 std::string to_str = |
| 951 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); | 934 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 977 } | 960 } |
| 978 | 961 |
| 979 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param, | 962 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param, |
| 980 void* language, | 963 void* language, |
| 981 int length) { | 964 int length) { |
| 982 return 0; | 965 return 0; |
| 983 } | 966 } |
| 984 | 967 |
| 985 #endif // defined(PDF_ENABLE_XFA) | 968 #endif // defined(PDF_ENABLE_XFA) |
| 986 | 969 |
| 987 int PDFiumEngine::GetBlock(void* param, unsigned long position, | 970 int PDFiumEngine::GetBlock(void* param, |
| 988 unsigned char* buffer, unsigned long size) { | 971 unsigned long position, |
| 972 unsigned char* buffer, |
| 973 unsigned long size) { |
| 989 DocumentLoader* loader = static_cast<DocumentLoader*>(param); | 974 DocumentLoader* loader = static_cast<DocumentLoader*>(param); |
| 990 return loader->GetBlock(position, size, buffer); | 975 return loader->GetBlock(position, size, buffer); |
| 991 } | 976 } |
| 992 | 977 |
| 993 FPDF_BOOL PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, | 978 FPDF_BOOL PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, |
| 994 size_t offset, size_t size) { | 979 size_t offset, |
| 980 size_t size) { |
| 995 PDFiumEngine::FileAvail* file_avail = | 981 PDFiumEngine::FileAvail* file_avail = |
| 996 static_cast<PDFiumEngine::FileAvail*>(param); | 982 static_cast<PDFiumEngine::FileAvail*>(param); |
| 997 return file_avail->loader->IsDataAvailable(offset, size); | 983 return file_avail->loader->IsDataAvailable(offset, size); |
| 998 } | 984 } |
| 999 | 985 |
| 1000 void PDFiumEngine::AddSegment(FX_DOWNLOADHINTS* param, | 986 void PDFiumEngine::AddSegment(FX_DOWNLOADHINTS* param, |
| 1001 size_t offset, size_t size) { | 987 size_t offset, |
| 988 size_t size) { |
| 1002 PDFiumEngine::DownloadHints* download_hints = | 989 PDFiumEngine::DownloadHints* download_hints = |
| 1003 static_cast<PDFiumEngine::DownloadHints*>(param); | 990 static_cast<PDFiumEngine::DownloadHints*>(param); |
| 1004 return download_hints->loader->RequestData(offset, size); | 991 return download_hints->loader->RequestData(offset, size); |
| 1005 } | 992 } |
| 1006 | 993 |
| 1007 bool PDFiumEngine::New(const char* url, | 994 bool PDFiumEngine::New(const char* url, const char* headers) { |
| 1008 const char* headers) { | |
| 1009 url_ = url; | 995 url_ = url; |
| 1010 if (headers) | 996 if (headers) |
| 1011 headers_ = headers; | 997 headers_ = headers; |
| 1012 else | 998 else |
| 1013 headers_.clear(); | 999 headers_.clear(); |
| 1014 return true; | 1000 return true; |
| 1015 } | 1001 } |
| 1016 | 1002 |
| 1017 void PDFiumEngine::PageOffsetUpdated(const pp::Point& page_offset) { | 1003 void PDFiumEngine::PageOffsetUpdated(const pp::Point& page_offset) { |
| 1018 page_offset_ = page_offset; | 1004 page_offset_ = page_offset; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 } | 1105 } |
| 1120 | 1106 |
| 1121 void PDFiumEngine::PostPaint() { | 1107 void PDFiumEngine::PostPaint() { |
| 1122 for (size_t i = 0; i < progressive_paints_.size(); ++i) { | 1108 for (size_t i = 0; i < progressive_paints_.size(); ++i) { |
| 1123 if (progressive_paints_[i].painted_) | 1109 if (progressive_paints_[i].painted_) |
| 1124 continue; | 1110 continue; |
| 1125 | 1111 |
| 1126 // This rectangle must have been merged with another one, that's why we | 1112 // This rectangle must have been merged with another one, that's why we |
| 1127 // weren't asked to paint it. Remove it or otherwise we'll never finish | 1113 // weren't asked to paint it. Remove it or otherwise we'll never finish |
| 1128 // painting. | 1114 // painting. |
| 1129 FPDF_RenderPage_Close( | 1115 FPDF_RenderPage_Close(pages_[progressive_paints_[i].page_index]->GetPage()); |
| 1130 pages_[progressive_paints_[i].page_index]->GetPage()); | |
| 1131 FPDFBitmap_Destroy(progressive_paints_[i].bitmap); | 1116 FPDFBitmap_Destroy(progressive_paints_[i].bitmap); |
| 1132 progressive_paints_.erase(progressive_paints_.begin() + i); | 1117 progressive_paints_.erase(progressive_paints_.begin() + i); |
| 1133 --i; | 1118 --i; |
| 1134 } | 1119 } |
| 1135 } | 1120 } |
| 1136 | 1121 |
| 1137 bool PDFiumEngine::HandleDocumentLoad(const pp::URLLoader& loader) { | 1122 bool PDFiumEngine::HandleDocumentLoad(const pp::URLLoader& loader) { |
| 1138 password_tries_remaining_ = kMaxPasswordTries; | 1123 password_tries_remaining_ = kMaxPasswordTries; |
| 1139 return doc_loader_.Init(loader, url_, headers_); | 1124 return doc_loader_.Init(loader, url_, headers_); |
| 1140 } | 1125 } |
| 1141 | 1126 |
| 1142 pp::Instance* PDFiumEngine::GetPluginInstance() { | 1127 pp::Instance* PDFiumEngine::GetPluginInstance() { |
| 1143 return client_->GetPluginInstance(); | 1128 return client_->GetPluginInstance(); |
| 1144 } | 1129 } |
| 1145 | 1130 |
| 1146 pp::URLLoader PDFiumEngine::CreateURLLoader() { | 1131 pp::URLLoader PDFiumEngine::CreateURLLoader() { |
| 1147 return client_->CreateURLLoader(); | 1132 return client_->CreateURLLoader(); |
| 1148 } | 1133 } |
| 1149 | 1134 |
| 1150 void PDFiumEngine::AppendPage(PDFEngine* engine, int index) { | 1135 void PDFiumEngine::AppendPage(PDFEngine* engine, int index) { |
| 1151 // Unload and delete the blank page before appending. | 1136 // Unload and delete the blank page before appending. |
| 1152 pages_[index]->Unload(); | 1137 pages_[index]->Unload(); |
| 1153 pages_[index]->set_calculated_links(false); | 1138 pages_[index]->set_calculated_links(false); |
| 1154 pp::Size curr_page_size = GetPageSize(index); | 1139 pp::Size curr_page_size = GetPageSize(index); |
| 1155 FPDFPage_Delete(doc_, index); | 1140 FPDFPage_Delete(doc_, index); |
| 1156 FPDF_ImportPages(doc_, | 1141 FPDF_ImportPages(doc_, static_cast<PDFiumEngine*>(engine)->doc(), "1", index); |
| 1157 static_cast<PDFiumEngine*>(engine)->doc(), | |
| 1158 "1", | |
| 1159 index); | |
| 1160 pp::Size new_page_size = GetPageSize(index); | 1142 pp::Size new_page_size = GetPageSize(index); |
| 1161 if (curr_page_size != new_page_size) | 1143 if (curr_page_size != new_page_size) |
| 1162 LoadPageInfo(true); | 1144 LoadPageInfo(true); |
| 1163 client_->Invalidate(GetPageScreenRect(index)); | 1145 client_->Invalidate(GetPageScreenRect(index)); |
| 1164 } | 1146 } |
| 1165 | 1147 |
| 1166 #if defined(PDF_ENABLE_XFA) | 1148 #if defined(PDF_ENABLE_XFA) |
| 1167 void PDFiumEngine::SetScrollPosition(const pp::Point& position) { | 1149 void PDFiumEngine::SetScrollPosition(const pp::Point& position) { |
| 1168 position_ = position; | 1150 position_ = position; |
| 1169 } | 1151 } |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) | 1353 if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) |
| 1372 return PP_PRINTOUTPUTFORMAT_RASTER; | 1354 return PP_PRINTOUTPUTFORMAT_RASTER; |
| 1373 return 0; | 1355 return 0; |
| 1374 } | 1356 } |
| 1375 | 1357 |
| 1376 void PDFiumEngine::PrintBegin() { | 1358 void PDFiumEngine::PrintBegin() { |
| 1377 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WP); | 1359 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WP); |
| 1378 } | 1360 } |
| 1379 | 1361 |
| 1380 pp::Resource PDFiumEngine::PrintPages( | 1362 pp::Resource PDFiumEngine::PrintPages( |
| 1381 const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count, | 1363 const PP_PrintPageNumberRange_Dev* page_ranges, |
| 1364 uint32_t page_range_count, |
| 1382 const PP_PrintSettings_Dev& print_settings) { | 1365 const PP_PrintSettings_Dev& print_settings) { |
| 1383 ScopedSubstFont scoped_subst_font(this); | 1366 ScopedSubstFont scoped_subst_font(this); |
| 1384 if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY) && | 1367 if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY) && |
| 1385 (print_settings.format & PP_PRINTOUTPUTFORMAT_PDF)) { | 1368 (print_settings.format & PP_PRINTOUTPUTFORMAT_PDF)) { |
| 1386 return PrintPagesAsPDF(page_ranges, page_range_count, print_settings); | 1369 return PrintPagesAsPDF(page_ranges, page_range_count, print_settings); |
| 1387 } else if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) { | 1370 } else if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) { |
| 1388 return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings); | 1371 return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings); |
| 1389 } | 1372 } |
| 1390 | 1373 |
| 1391 return pp::Resource(); | 1374 return pp::Resource(); |
| 1392 } | 1375 } |
| 1393 | 1376 |
| 1394 FPDF_DOCUMENT PDFiumEngine::CreateSinglePageRasterPdf( | 1377 FPDF_DOCUMENT PDFiumEngine::CreateSinglePageRasterPdf( |
| 1395 double source_page_width, | 1378 double source_page_width, |
| 1396 double source_page_height, | 1379 double source_page_height, |
| 1397 const PP_PrintSettings_Dev& print_settings, | 1380 const PP_PrintSettings_Dev& print_settings, |
| 1398 PDFiumPage* page_to_print) { | 1381 PDFiumPage* page_to_print) { |
| 1399 FPDF_DOCUMENT temp_doc = FPDF_CreateNewDocument(); | 1382 FPDF_DOCUMENT temp_doc = FPDF_CreateNewDocument(); |
| 1400 if (!temp_doc) | 1383 if (!temp_doc) |
| 1401 return temp_doc; | 1384 return temp_doc; |
| 1402 | 1385 |
| 1403 const pp::Size& bitmap_size(page_to_print->rect().size()); | 1386 const pp::Size& bitmap_size(page_to_print->rect().size()); |
| 1404 | 1387 |
| 1405 FPDF_PAGE temp_page = | 1388 FPDF_PAGE temp_page = |
| 1406 FPDFPage_New(temp_doc, 0, source_page_width, source_page_height); | 1389 FPDFPage_New(temp_doc, 0, source_page_width, source_page_height); |
| 1407 | 1390 |
| 1408 pp::ImageData image = pp::ImageData(client_->GetPluginInstance(), | 1391 pp::ImageData image = |
| 1409 PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 1392 pp::ImageData(client_->GetPluginInstance(), |
| 1410 bitmap_size, | 1393 PP_IMAGEDATAFORMAT_BGRA_PREMUL, bitmap_size, false); |
| 1411 false); | |
| 1412 | 1394 |
| 1413 FPDF_BITMAP bitmap = FPDFBitmap_CreateEx(bitmap_size.width(), | 1395 FPDF_BITMAP bitmap = |
| 1414 bitmap_size.height(), | 1396 FPDFBitmap_CreateEx(bitmap_size.width(), bitmap_size.height(), |
| 1415 FPDFBitmap_BGRx, | 1397 FPDFBitmap_BGRx, image.data(), image.stride()); |
| 1416 image.data(), | |
| 1417 image.stride()); | |
| 1418 | 1398 |
| 1419 // Clear the bitmap | 1399 // Clear the bitmap |
| 1420 FPDFBitmap_FillRect( | 1400 FPDFBitmap_FillRect(bitmap, 0, 0, bitmap_size.width(), bitmap_size.height(), |
| 1421 bitmap, 0, 0, bitmap_size.width(), bitmap_size.height(), 0xFFFFFFFF); | 1401 0xFFFFFFFF); |
| 1422 | 1402 |
| 1423 pp::Rect page_rect = page_to_print->rect(); | 1403 pp::Rect page_rect = page_to_print->rect(); |
| 1424 FPDF_RenderPageBitmap(bitmap, | 1404 FPDF_RenderPageBitmap(bitmap, page_to_print->GetPrintPage(), page_rect.x(), |
| 1425 page_to_print->GetPrintPage(), | 1405 page_rect.y(), page_rect.width(), page_rect.height(), |
| 1426 page_rect.x(), | |
| 1427 page_rect.y(), | |
| 1428 page_rect.width(), | |
| 1429 page_rect.height(), | |
| 1430 print_settings.orientation, | 1406 print_settings.orientation, |
| 1431 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); | 1407 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 1432 | 1408 |
| 1433 unsigned char* bitmap_data = | 1409 unsigned char* bitmap_data = |
| 1434 static_cast<unsigned char*>(FPDFBitmap_GetBuffer(bitmap)); | 1410 static_cast<unsigned char*>(FPDFBitmap_GetBuffer(bitmap)); |
| 1435 double ratio_x = ConvertUnitDouble(bitmap_size.width(), | 1411 double ratio_x = ConvertUnitDouble(bitmap_size.width(), print_settings.dpi, |
| 1436 print_settings.dpi, | |
| 1437 kPointsPerInch); | 1412 kPointsPerInch); |
| 1438 double ratio_y = ConvertUnitDouble(bitmap_size.height(), | 1413 double ratio_y = ConvertUnitDouble(bitmap_size.height(), print_settings.dpi, |
| 1439 print_settings.dpi, | |
| 1440 kPointsPerInch); | 1414 kPointsPerInch); |
| 1441 | 1415 |
| 1442 // Add the bitmap to an image object and add the image object to the output | 1416 // Add the bitmap to an image object and add the image object to the output |
| 1443 // page. | 1417 // page. |
| 1444 FPDF_PAGEOBJECT temp_img = FPDFPageObj_NewImageObj(temp_doc); | 1418 FPDF_PAGEOBJECT temp_img = FPDFPageObj_NewImageObj(temp_doc); |
| 1445 | 1419 |
| 1446 std::vector<uint8_t> compressed_bitmap_data; | 1420 std::vector<uint8_t> compressed_bitmap_data; |
| 1447 // Use quality = 40 as this does not significantly degrade the printed | 1421 // Use quality = 40 as this does not significantly degrade the printed |
| 1448 // document relative to a normal bitmap and provides better compression than | 1422 // document relative to a normal bitmap and provides better compression than |
| 1449 // a higher quality setting. | 1423 // a higher quality setting. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1469 FPDFPage_GenerateContent(temp_page); | 1443 FPDFPage_GenerateContent(temp_page); |
| 1470 FPDF_ClosePage(temp_page); | 1444 FPDF_ClosePage(temp_page); |
| 1471 | 1445 |
| 1472 page_to_print->ClosePrintPage(); | 1446 page_to_print->ClosePrintPage(); |
| 1473 FPDFBitmap_Destroy(bitmap); | 1447 FPDFBitmap_Destroy(bitmap); |
| 1474 | 1448 |
| 1475 return temp_doc; | 1449 return temp_doc; |
| 1476 } | 1450 } |
| 1477 | 1451 |
| 1478 pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPDF( | 1452 pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPDF( |
| 1479 const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count, | 1453 const PP_PrintPageNumberRange_Dev* page_ranges, |
| 1454 uint32_t page_range_count, |
| 1480 const PP_PrintSettings_Dev& print_settings) { | 1455 const PP_PrintSettings_Dev& print_settings) { |
| 1481 if (!page_range_count) | 1456 if (!page_range_count) |
| 1482 return pp::Buffer_Dev(); | 1457 return pp::Buffer_Dev(); |
| 1483 | 1458 |
| 1484 // If document is not downloaded yet, disable printing. | 1459 // If document is not downloaded yet, disable printing. |
| 1485 if (doc_ && !doc_loader_.IsDocumentComplete()) | 1460 if (doc_ && !doc_loader_.IsDocumentComplete()) |
| 1486 return pp::Buffer_Dev(); | 1461 return pp::Buffer_Dev(); |
| 1487 | 1462 |
| 1488 FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); | 1463 FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); |
| 1489 if (!output_doc) | 1464 if (!output_doc) |
| 1490 return pp::Buffer_Dev(); | 1465 return pp::Buffer_Dev(); |
| 1491 | 1466 |
| 1492 SaveSelectedFormForPrint(); | 1467 SaveSelectedFormForPrint(); |
| 1493 | 1468 |
| 1494 std::vector<PDFiumPage> pages_to_print; | 1469 std::vector<PDFiumPage> pages_to_print; |
| 1495 // width and height of source PDF pages. | 1470 // width and height of source PDF pages. |
| 1496 std::vector<std::pair<double, double> > source_page_sizes; | 1471 std::vector<std::pair<double, double>> source_page_sizes; |
| 1497 // Collect pages to print and sizes of source pages. | 1472 // Collect pages to print and sizes of source pages. |
| 1498 std::vector<uint32_t> page_numbers = | 1473 std::vector<uint32_t> page_numbers = |
| 1499 GetPageNumbersFromPrintPageNumberRange(page_ranges, page_range_count); | 1474 GetPageNumbersFromPrintPageNumberRange(page_ranges, page_range_count); |
| 1500 for (uint32_t page_number : page_numbers) { | 1475 for (uint32_t page_number : page_numbers) { |
| 1501 FPDF_PAGE pdf_page = FPDF_LoadPage(doc_, page_number); | 1476 FPDF_PAGE pdf_page = FPDF_LoadPage(doc_, page_number); |
| 1502 double source_page_width = FPDF_GetPageWidth(pdf_page); | 1477 double source_page_width = FPDF_GetPageWidth(pdf_page); |
| 1503 double source_page_height = FPDF_GetPageHeight(pdf_page); | 1478 double source_page_height = FPDF_GetPageHeight(pdf_page); |
| 1504 source_page_sizes.push_back(std::make_pair(source_page_width, | 1479 source_page_sizes.push_back( |
| 1505 source_page_height)); | 1480 std::make_pair(source_page_width, source_page_height)); |
| 1506 | 1481 |
| 1507 int width_in_pixels = ConvertUnit(source_page_width, | 1482 int width_in_pixels = |
| 1508 kPointsPerInch, | 1483 ConvertUnit(source_page_width, kPointsPerInch, print_settings.dpi); |
| 1509 print_settings.dpi); | 1484 int height_in_pixels = |
| 1510 int height_in_pixels = ConvertUnit(source_page_height, | 1485 ConvertUnit(source_page_height, kPointsPerInch, print_settings.dpi); |
| 1511 kPointsPerInch, | |
| 1512 print_settings.dpi); | |
| 1513 | 1486 |
| 1514 pp::Rect rect(width_in_pixels, height_in_pixels); | 1487 pp::Rect rect(width_in_pixels, height_in_pixels); |
| 1515 pages_to_print.push_back(PDFiumPage(this, page_number, rect, true)); | 1488 pages_to_print.push_back(PDFiumPage(this, page_number, rect, true)); |
| 1516 FPDF_ClosePage(pdf_page); | 1489 FPDF_ClosePage(pdf_page); |
| 1517 } | 1490 } |
| 1518 | 1491 |
| 1519 #if defined(OS_LINUX) | 1492 #if defined(OS_LINUX) |
| 1520 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); | 1493 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); |
| 1521 #endif | 1494 #endif |
| 1522 | 1495 |
| 1523 size_t i = 0; | 1496 size_t i = 0; |
| 1524 for (; i < pages_to_print.size(); ++i) { | 1497 for (; i < pages_to_print.size(); ++i) { |
| 1525 double source_page_width = source_page_sizes[i].first; | 1498 double source_page_width = source_page_sizes[i].first; |
| 1526 double source_page_height = source_page_sizes[i].second; | 1499 double source_page_height = source_page_sizes[i].second; |
| 1527 | 1500 |
| 1528 // Use temp_doc to compress image by saving PDF to buffer. | 1501 // Use temp_doc to compress image by saving PDF to buffer. |
| 1529 FPDF_DOCUMENT temp_doc = CreateSinglePageRasterPdf(source_page_width, | 1502 FPDF_DOCUMENT temp_doc = |
| 1530 source_page_height, | 1503 CreateSinglePageRasterPdf(source_page_width, source_page_height, |
| 1531 print_settings, | 1504 print_settings, &pages_to_print[i]); |
| 1532 &pages_to_print[i]); | |
| 1533 | 1505 |
| 1534 if (!temp_doc) | 1506 if (!temp_doc) |
| 1535 break; | 1507 break; |
| 1536 | 1508 |
| 1537 pp::Buffer_Dev buffer = GetFlattenedPrintData(temp_doc); | 1509 pp::Buffer_Dev buffer = GetFlattenedPrintData(temp_doc); |
| 1538 FPDF_CloseDocument(temp_doc); | 1510 FPDF_CloseDocument(temp_doc); |
| 1539 | 1511 |
| 1540 PDFiumMemBufferFileRead file_read(buffer.data(), buffer.size()); | 1512 PDFiumMemBufferFileRead file_read(buffer.data(), buffer.size()); |
| 1541 temp_doc = FPDF_LoadCustomDocument(&file_read, nullptr); | 1513 temp_doc = FPDF_LoadCustomDocument(&file_read, nullptr); |
| 1542 | 1514 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1565 FPDF_PAGE page = FPDF_LoadPage(doc, i); | 1537 FPDF_PAGE page = FPDF_LoadPage(doc, i); |
| 1566 DCHECK(page); | 1538 DCHECK(page); |
| 1567 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT); | 1539 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT); |
| 1568 FPDF_ClosePage(page); | 1540 FPDF_ClosePage(page); |
| 1569 if (flatten_ret == FLATTEN_FAIL) | 1541 if (flatten_ret == FLATTEN_FAIL) |
| 1570 return buffer; | 1542 return buffer; |
| 1571 } | 1543 } |
| 1572 | 1544 |
| 1573 PDFiumMemBufferFileWrite output_file_write; | 1545 PDFiumMemBufferFileWrite output_file_write; |
| 1574 if (FPDF_SaveAsCopy(doc, &output_file_write, 0)) { | 1546 if (FPDF_SaveAsCopy(doc, &output_file_write, 0)) { |
| 1575 buffer = pp::Buffer_Dev( | 1547 buffer = |
| 1576 client_->GetPluginInstance(), output_file_write.size()); | 1548 pp::Buffer_Dev(client_->GetPluginInstance(), output_file_write.size()); |
| 1577 if (!buffer.is_null()) { | 1549 if (!buffer.is_null()) { |
| 1578 memcpy(buffer.data(), output_file_write.buffer().c_str(), | 1550 memcpy(buffer.data(), output_file_write.buffer().c_str(), |
| 1579 output_file_write.size()); | 1551 output_file_write.size()); |
| 1580 } | 1552 } |
| 1581 } | 1553 } |
| 1582 return buffer; | 1554 return buffer; |
| 1583 } | 1555 } |
| 1584 | 1556 |
| 1585 pp::Buffer_Dev PDFiumEngine::PrintPagesAsPDF( | 1557 pp::Buffer_Dev PDFiumEngine::PrintPagesAsPDF( |
| 1586 const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count, | 1558 const PP_PrintPageNumberRange_Dev* page_ranges, |
| 1559 uint32_t page_range_count, |
| 1587 const PP_PrintSettings_Dev& print_settings) { | 1560 const PP_PrintSettings_Dev& print_settings) { |
| 1588 if (!page_range_count) | 1561 if (!page_range_count) |
| 1589 return pp::Buffer_Dev(); | 1562 return pp::Buffer_Dev(); |
| 1590 | 1563 |
| 1591 DCHECK(doc_); | 1564 DCHECK(doc_); |
| 1592 FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); | 1565 FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); |
| 1593 if (!output_doc) | 1566 if (!output_doc) |
| 1594 return pp::Buffer_Dev(); | 1567 return pp::Buffer_Dev(); |
| 1595 | 1568 |
| 1596 SaveSelectedFormForPrint(); | 1569 SaveSelectedFormForPrint(); |
| 1597 | 1570 |
| 1598 std::string page_number_str; | 1571 std::string page_number_str; |
| 1599 for (uint32_t index = 0; index < page_range_count; ++index) { | 1572 for (uint32_t index = 0; index < page_range_count; ++index) { |
| 1600 if (!page_number_str.empty()) | 1573 if (!page_number_str.empty()) |
| 1601 page_number_str.append(","); | 1574 page_number_str.append(","); |
| 1602 page_number_str.append( | 1575 page_number_str.append( |
| 1603 base::UintToString(page_ranges[index].first_page_number + 1)); | 1576 base::UintToString(page_ranges[index].first_page_number + 1)); |
| 1604 if (page_ranges[index].first_page_number != | 1577 if (page_ranges[index].first_page_number != |
| 1605 page_ranges[index].last_page_number) { | 1578 page_ranges[index].last_page_number) { |
| 1606 page_number_str.append("-"); | 1579 page_number_str.append("-"); |
| 1607 page_number_str.append( | 1580 page_number_str.append( |
| 1608 base::UintToString(page_ranges[index].last_page_number + 1)); | 1581 base::UintToString(page_ranges[index].last_page_number + 1)); |
| 1609 } | 1582 } |
| 1610 } | 1583 } |
| 1611 | 1584 |
| 1612 std::vector<uint32_t> page_numbers = | 1585 std::vector<uint32_t> page_numbers = |
| 1613 GetPageNumbersFromPrintPageNumberRange(page_ranges, page_range_count); | 1586 GetPageNumbersFromPrintPageNumberRange(page_ranges, page_range_count); |
| 1614 for (uint32_t page_number : page_numbers) { | 1587 for (uint32_t page_number : page_numbers) { |
| 1615 pages_[page_number]->GetPage(); | 1588 pages_[page_number]->GetPage(); |
| 1616 if (!IsPageVisible(page_number)) | 1589 if (!IsPageVisible(page_number)) |
| 1617 pages_[page_number]->Unload(); | 1590 pages_[page_number]->Unload(); |
| 1618 } | 1591 } |
| 1619 | 1592 |
| 1620 FPDF_CopyViewerPreferences(output_doc, doc_); | 1593 FPDF_CopyViewerPreferences(output_doc, doc_); |
| 1621 if (!FPDF_ImportPages(output_doc, doc_, page_number_str.c_str(), 0)) { | 1594 if (!FPDF_ImportPages(output_doc, doc_, page_number_str.c_str(), 0)) { |
| 1622 FPDF_CloseDocument(output_doc); | 1595 FPDF_CloseDocument(output_doc); |
| 1623 return pp::Buffer_Dev(); | 1596 return pp::Buffer_Dev(); |
| 1624 } | 1597 } |
| 1625 | 1598 |
| 1626 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); | 1599 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); |
| 1627 | 1600 |
| 1628 // Now flatten all the output pages. | 1601 // Now flatten all the output pages. |
| 1629 pp::Buffer_Dev buffer = GetFlattenedPrintData(output_doc); | 1602 pp::Buffer_Dev buffer = GetFlattenedPrintData(output_doc); |
| 1630 FPDF_CloseDocument(output_doc); | 1603 FPDF_CloseDocument(output_doc); |
| 1631 return buffer; | 1604 return buffer; |
| 1632 } | 1605 } |
| 1633 | 1606 |
| 1634 void PDFiumEngine::FitContentsToPrintableAreaIfRequired( | 1607 void PDFiumEngine::FitContentsToPrintableAreaIfRequired( |
| 1635 const FPDF_DOCUMENT& doc, const PP_PrintSettings_Dev& print_settings) { | 1608 const FPDF_DOCUMENT& doc, |
| 1609 const PP_PrintSettings_Dev& print_settings) { |
| 1636 // Check to see if we need to fit pdf contents to printer paper size. | 1610 // Check to see if we need to fit pdf contents to printer paper size. |
| 1637 if (print_settings.print_scaling_option != | 1611 if (print_settings.print_scaling_option != |
| 1638 PP_PRINTSCALINGOPTION_SOURCE_SIZE) { | 1612 PP_PRINTSCALINGOPTION_SOURCE_SIZE) { |
| 1639 int num_pages = FPDF_GetPageCount(doc); | 1613 int num_pages = FPDF_GetPageCount(doc); |
| 1640 // In-place transformation is more efficient than creating a new | 1614 // In-place transformation is more efficient than creating a new |
| 1641 // transformed document from the source document. Therefore, transform | 1615 // transformed document from the source document. Therefore, transform |
| 1642 // every page to fit the contents in the selected printer paper. | 1616 // every page to fit the contents in the selected printer paper. |
| 1643 for (int i = 0; i < num_pages; ++i) { | 1617 for (int i = 0; i < num_pages; ++i) { |
| 1644 FPDF_PAGE page = FPDF_LoadPage(doc, i); | 1618 FPDF_PAGE page = FPDF_LoadPage(doc, i); |
| 1645 TransformPDFPageForPrinting(page, print_settings); | 1619 TransformPDFPageForPrinting(page, print_settings); |
| 1646 FPDF_ClosePage(page); | 1620 FPDF_ClosePage(page); |
| 1647 } | 1621 } |
| 1648 } | 1622 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 return PDFiumPage::NONSELECTABLE_AREA; | 1660 return PDFiumPage::NONSELECTABLE_AREA; |
| 1687 | 1661 |
| 1688 // If the page hasn't finished rendering, calling into the page sometimes | 1662 // If the page hasn't finished rendering, calling into the page sometimes |
| 1689 // leads to hangs. | 1663 // leads to hangs. |
| 1690 for (const auto& paint : progressive_paints_) { | 1664 for (const auto& paint : progressive_paints_) { |
| 1691 if (paint.page_index == page) | 1665 if (paint.page_index == page) |
| 1692 return PDFiumPage::NONSELECTABLE_AREA; | 1666 return PDFiumPage::NONSELECTABLE_AREA; |
| 1693 } | 1667 } |
| 1694 | 1668 |
| 1695 *page_index = page; | 1669 *page_index = page; |
| 1696 return pages_[page]->GetCharIndex( | 1670 return pages_[page]->GetCharIndex(point_in_page, current_rotation_, |
| 1697 point_in_page, current_rotation_, char_index, form_type, target); | 1671 char_index, form_type, target); |
| 1698 } | 1672 } |
| 1699 | 1673 |
| 1700 bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { | 1674 bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { |
| 1701 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_RIGHT) { | 1675 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_RIGHT) { |
| 1702 if (selection_.empty()) | 1676 if (selection_.empty()) |
| 1703 return false; | 1677 return false; |
| 1704 std::vector<pp::Rect> selection_rect_vector; | 1678 std::vector<pp::Rect> selection_rect_vector; |
| 1705 GetAllScreenRectsUnion(&selection_, GetVisibleRect().point(), | 1679 GetAllScreenRectsUnion(&selection_, GetVisibleRect().point(), |
| 1706 &selection_rect_vector); | 1680 &selection_rect_vector); |
| 1707 pp::Point point = event.GetPosition(); | 1681 pp::Point point = event.GetPosition(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1764 } | 1738 } |
| 1765 } | 1739 } |
| 1766 | 1740 |
| 1767 client_->FormTextFieldFocusChange(false); | 1741 client_->FormTextFieldFocusChange(false); |
| 1768 | 1742 |
| 1769 if (area != PDFiumPage::TEXT_AREA) | 1743 if (area != PDFiumPage::TEXT_AREA) |
| 1770 return true; // Return true so WebKit doesn't do its own highlighting. | 1744 return true; // Return true so WebKit doesn't do its own highlighting. |
| 1771 | 1745 |
| 1772 if (event.GetClickCount() == 1) { | 1746 if (event.GetClickCount() == 1) { |
| 1773 OnSingleClick(page_index, char_index); | 1747 OnSingleClick(page_index, char_index); |
| 1774 } else if (event.GetClickCount() == 2 || | 1748 } else if (event.GetClickCount() == 2 || event.GetClickCount() == 3) { |
| 1775 event.GetClickCount() == 3) { | |
| 1776 OnMultipleClick(event.GetClickCount(), page_index, char_index); | 1749 OnMultipleClick(event.GetClickCount(), page_index, char_index); |
| 1777 } | 1750 } |
| 1778 | 1751 |
| 1779 return true; | 1752 return true; |
| 1780 } | 1753 } |
| 1781 | 1754 |
| 1782 void PDFiumEngine::OnSingleClick(int page_index, int char_index) { | 1755 void PDFiumEngine::OnSingleClick(int page_index, int char_index) { |
| 1783 SetSelecting(true); | 1756 SetSelecting(true); |
| 1784 selection_.push_back(PDFiumRange(pages_[page_index].get(), char_index, 0)); | 1757 selection_.push_back(PDFiumRange(pages_[page_index].get(), char_index, 0)); |
| 1785 } | 1758 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1829 if (mouse_down_state_.Matches(area, target)) { | 1802 if (mouse_down_state_.Matches(area, target)) { |
| 1830 if (area == PDFiumPage::WEBLINK_AREA) { | 1803 if (area == PDFiumPage::WEBLINK_AREA) { |
| 1831 uint32_t modifiers = event.GetModifiers(); | 1804 uint32_t modifiers = event.GetModifiers(); |
| 1832 bool middle_button = | 1805 bool middle_button = |
| 1833 !!(modifiers & PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN); | 1806 !!(modifiers & PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN); |
| 1834 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); | 1807 bool alt_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY); |
| 1835 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); | 1808 bool ctrl_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY); |
| 1836 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); | 1809 bool meta_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_METAKEY); |
| 1837 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); | 1810 bool shift_key = !!(modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY); |
| 1838 | 1811 |
| 1839 WindowOpenDisposition disposition = | 1812 WindowOpenDisposition disposition = ui::DispositionFromClick( |
| 1840 ui::DispositionFromClick(middle_button, alt_key, ctrl_key, meta_key, | 1813 middle_button, alt_key, ctrl_key, meta_key, shift_key); |
| 1841 shift_key); | |
| 1842 | 1814 |
| 1843 client_->NavigateTo(target.url, disposition); | 1815 client_->NavigateTo(target.url, disposition); |
| 1844 client_->FormTextFieldFocusChange(false); | 1816 client_->FormTextFieldFocusChange(false); |
| 1845 return true; | 1817 return true; |
| 1846 } | 1818 } |
| 1847 } | 1819 } |
| 1848 | 1820 |
| 1849 // Prevent middle mouse button from selecting texts. | 1821 // Prevent middle mouse button from selecting texts. |
| 1850 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) | 1822 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) |
| 1851 return false; | 1823 return false; |
| 1852 | 1824 |
| 1853 if (page_index != -1) { | 1825 if (page_index != -1) { |
| 1854 double page_x, page_y; | 1826 double page_x, page_y; |
| 1855 pp::Point point = event.GetPosition(); | 1827 pp::Point point = event.GetPosition(); |
| 1856 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1828 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
| 1857 FORM_OnLButtonUp( | 1829 FORM_OnLButtonUp(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
| 1858 form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | |
| 1859 } | 1830 } |
| 1860 | 1831 |
| 1861 if (!selecting_) | 1832 if (!selecting_) |
| 1862 return false; | 1833 return false; |
| 1863 | 1834 |
| 1864 SetSelecting(false); | 1835 SetSelecting(false); |
| 1865 return true; | 1836 return true; |
| 1866 } | 1837 } |
| 1867 | 1838 |
| 1868 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { | 1839 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1991 PDFiumRange(pages_[page_index].get(), count, count - char_index)); | 1962 PDFiumRange(pages_[page_index].get(), count, count - char_index)); |
| 1992 } | 1963 } |
| 1993 | 1964 |
| 1994 return true; | 1965 return true; |
| 1995 } | 1966 } |
| 1996 | 1967 |
| 1997 bool PDFiumEngine::OnKeyDown(const pp::KeyboardInputEvent& event) { | 1968 bool PDFiumEngine::OnKeyDown(const pp::KeyboardInputEvent& event) { |
| 1998 if (last_page_mouse_down_ == -1) | 1969 if (last_page_mouse_down_ == -1) |
| 1999 return false; | 1970 return false; |
| 2000 | 1971 |
| 2001 bool rv = !!FORM_OnKeyDown( | 1972 bool rv = !!FORM_OnKeyDown(form_, pages_[last_page_mouse_down_]->GetPage(), |
| 2002 form_, pages_[last_page_mouse_down_]->GetPage(), | 1973 event.GetKeyCode(), event.GetModifiers()); |
| 2003 event.GetKeyCode(), event.GetModifiers()); | |
| 2004 | 1974 |
| 2005 if (event.GetKeyCode() == ui::VKEY_BACK || | 1975 if (event.GetKeyCode() == ui::VKEY_BACK || |
| 2006 event.GetKeyCode() == ui::VKEY_ESCAPE) { | 1976 event.GetKeyCode() == ui::VKEY_ESCAPE) { |
| 2007 // Chrome doesn't send char events for backspace or escape keys, see | 1977 // Chrome doesn't send char events for backspace or escape keys, see |
| 2008 // PlatformKeyboardEventBuilder::isCharacterKey() and | 1978 // PlatformKeyboardEventBuilder::isCharacterKey() and |
| 2009 // http://chrome-corpsvn.mtv.corp.google.com/viewvc?view=rev&root=chrome&rev
ision=31805 | 1979 // http://chrome-corpsvn.mtv.corp.google.com/viewvc?view=rev&root=chrome&rev
ision=31805 |
| 2010 // for more information. So just fake one since PDFium uses it. | 1980 // for more information. So just fake one since PDFium uses it. |
| 2011 std::string str; | 1981 std::string str; |
| 2012 str.push_back(event.GetKeyCode()); | 1982 str.push_back(event.GetKeyCode()); |
| 2013 pp::KeyboardInputEvent synthesized(pp::KeyboardInputEvent( | 1983 pp::KeyboardInputEvent synthesized(pp::KeyboardInputEvent( |
| 2014 client_->GetPluginInstance(), | 1984 client_->GetPluginInstance(), PP_INPUTEVENT_TYPE_CHAR, |
| 2015 PP_INPUTEVENT_TYPE_CHAR, | 1985 event.GetTimeStamp(), event.GetModifiers(), event.GetKeyCode(), str)); |
| 2016 event.GetTimeStamp(), | |
| 2017 event.GetModifiers(), | |
| 2018 event.GetKeyCode(), | |
| 2019 str)); | |
| 2020 OnChar(synthesized); | 1986 OnChar(synthesized); |
| 2021 } | 1987 } |
| 2022 | 1988 |
| 2023 return rv; | 1989 return rv; |
| 2024 } | 1990 } |
| 2025 | 1991 |
| 2026 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { | 1992 bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { |
| 2027 if (last_page_mouse_down_ == -1) | 1993 if (last_page_mouse_down_ == -1) |
| 2028 return false; | 1994 return false; |
| 2029 | 1995 |
| 2030 return !!FORM_OnKeyUp( | 1996 return !!FORM_OnKeyUp(form_, pages_[last_page_mouse_down_]->GetPage(), |
| 2031 form_, pages_[last_page_mouse_down_]->GetPage(), | 1997 event.GetKeyCode(), event.GetModifiers()); |
| 2032 event.GetKeyCode(), event.GetModifiers()); | |
| 2033 } | 1998 } |
| 2034 | 1999 |
| 2035 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { | 2000 bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { |
| 2036 if (last_page_mouse_down_ == -1) | 2001 if (last_page_mouse_down_ == -1) |
| 2037 return false; | 2002 return false; |
| 2038 | 2003 |
| 2039 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); | 2004 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); |
| 2040 return !!FORM_OnChar( | 2005 return !!FORM_OnChar(form_, pages_[last_page_mouse_down_]->GetPage(), str[0], |
| 2041 form_, pages_[last_page_mouse_down_]->GetPage(), | 2006 event.GetModifiers()); |
| 2042 str[0], | |
| 2043 event.GetModifiers()); | |
| 2044 } | 2007 } |
| 2045 | 2008 |
| 2046 void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) { | 2009 void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) { |
| 2047 // If the caller asks StartFind() to search for no text, then this is an | 2010 // If the caller asks StartFind() to search for no text, then this is an |
| 2048 // error on the part of the caller. The PPAPI Find_Private interface | 2011 // error on the part of the caller. The PPAPI Find_Private interface |
| 2049 // guarantees it is not empty, so this should never happen. | 2012 // guarantees it is not empty, so this should never happen. |
| 2050 DCHECK(!text.empty()); | 2013 DCHECK(!text.empty()); |
| 2051 | 2014 |
| 2052 // If StartFind() gets called before we have any page information (i.e. | 2015 // If StartFind() gets called before we have any page information (i.e. |
| 2053 // before the first call to LoadDocument has happened). Handle this case. | 2016 // before the first call to LoadDocument has happened). Handle this case. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2075 } | 2038 } |
| 2076 } | 2039 } |
| 2077 | 2040 |
| 2078 int current_page = next_page_to_search_; | 2041 int current_page = next_page_to_search_; |
| 2079 | 2042 |
| 2080 if (pages_[current_page]->available()) { | 2043 if (pages_[current_page]->available()) { |
| 2081 base::string16 str = base::UTF8ToUTF16(text); | 2044 base::string16 str = base::UTF8ToUTF16(text); |
| 2082 // Don't use PDFium to search for now, since it doesn't support unicode | 2045 // Don't use PDFium to search for now, since it doesn't support unicode |
| 2083 // text. Leave the code for now to avoid bit-rot, in case it's fixed later. | 2046 // text. Leave the code for now to avoid bit-rot, in case it's fixed later. |
| 2084 if (0) { | 2047 if (0) { |
| 2085 SearchUsingPDFium( | 2048 SearchUsingPDFium(str, case_sensitive, first_search, |
| 2086 str, case_sensitive, first_search, character_to_start_searching_from, | 2049 character_to_start_searching_from, current_page); |
| 2087 current_page); | |
| 2088 } else { | 2050 } else { |
| 2089 SearchUsingICU( | 2051 SearchUsingICU(str, case_sensitive, first_search, |
| 2090 str, case_sensitive, first_search, character_to_start_searching_from, | 2052 character_to_start_searching_from, current_page); |
| 2091 current_page); | |
| 2092 } | 2053 } |
| 2093 | 2054 |
| 2094 if (!IsPageVisible(current_page)) | 2055 if (!IsPageVisible(current_page)) |
| 2095 pages_[current_page]->Unload(); | 2056 pages_[current_page]->Unload(); |
| 2096 } | 2057 } |
| 2097 | 2058 |
| 2098 if (next_page_to_search_ != last_page_to_search_ || | 2059 if (next_page_to_search_ != last_page_to_search_ || |
| 2099 (first_search && last_character_index_to_search_ != -1)) { | 2060 (first_search && last_character_index_to_search_ != -1)) { |
| 2100 ++next_page_to_search_; | 2061 ++next_page_to_search_; |
| 2101 } | 2062 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2125 // This might happen if the PDF has some dynamically generated text? | 2086 // This might happen if the PDF has some dynamically generated text? |
| 2126 resume_index = 0; | 2087 resume_index = 0; |
| 2127 } | 2088 } |
| 2128 current_find_index_.SetIndex(resume_index); | 2089 current_find_index_.SetIndex(resume_index); |
| 2129 client_->NotifySelectedFindResultChanged(resume_index); | 2090 client_->NotifySelectedFindResultChanged(resume_index); |
| 2130 } | 2091 } |
| 2131 resume_find_index_.Invalidate(); | 2092 resume_find_index_.Invalidate(); |
| 2132 } else { | 2093 } else { |
| 2133 pp::CompletionCallback callback = | 2094 pp::CompletionCallback callback = |
| 2134 find_factory_.NewCallback(&PDFiumEngine::ContinueFind); | 2095 find_factory_.NewCallback(&PDFiumEngine::ContinueFind); |
| 2135 pp::Module::Get()->core()->CallOnMainThread( | 2096 pp::Module::Get()->core()->CallOnMainThread(0, callback, |
| 2136 0, callback, case_sensitive ? 1 : 0); | 2097 case_sensitive ? 1 : 0); |
| 2137 } | 2098 } |
| 2138 } | 2099 } |
| 2139 | 2100 |
| 2140 void PDFiumEngine::SearchUsingPDFium(const base::string16& term, | 2101 void PDFiumEngine::SearchUsingPDFium(const base::string16& term, |
| 2141 bool case_sensitive, | 2102 bool case_sensitive, |
| 2142 bool first_search, | 2103 bool first_search, |
| 2143 int character_to_start_searching_from, | 2104 int character_to_start_searching_from, |
| 2144 int current_page) { | 2105 int current_page) { |
| 2145 // Find all the matches in the current page. | 2106 // Find all the matches in the current page. |
| 2146 unsigned long flags = case_sensitive ? FPDF_MATCHCASE : 0; | 2107 unsigned long flags = case_sensitive ? FPDF_MATCHCASE : 0; |
| 2147 FPDF_SCHHANDLE find = FPDFText_FindStart( | 2108 FPDF_SCHHANDLE find = |
| 2148 pages_[current_page]->GetTextPage(), | 2109 FPDFText_FindStart(pages_[current_page]->GetTextPage(), |
| 2149 reinterpret_cast<const unsigned short*>(term.c_str()), | 2110 reinterpret_cast<const unsigned short*>(term.c_str()), |
| 2150 flags, character_to_start_searching_from); | 2111 flags, character_to_start_searching_from); |
| 2151 | 2112 |
| 2152 // Note: since we search one page at a time, we don't find matches across | 2113 // Note: since we search one page at a time, we don't find matches across |
| 2153 // page boundaries. We could do this manually ourself, but it seems low | 2114 // page boundaries. We could do this manually ourself, but it seems low |
| 2154 // priority since Reader itself doesn't do it. | 2115 // priority since Reader itself doesn't do it. |
| 2155 while (FPDFText_FindNext(find)) { | 2116 while (FPDFText_FindNext(find)) { |
| 2156 PDFiumRange result(pages_[current_page].get(), | 2117 PDFiumRange result(pages_[current_page].get(), |
| 2157 FPDFText_GetSchResultIndex(find), | 2118 FPDFText_GetSchResultIndex(find), |
| 2158 FPDFText_GetSchCount(find)); | 2119 FPDFText_GetSchCount(find)); |
| 2159 | 2120 |
| 2160 if (!first_search && | 2121 if (!first_search && last_character_index_to_search_ != -1 && |
| 2161 last_character_index_to_search_ != -1 && | |
| 2162 result.page_index() == last_page_to_search_ && | 2122 result.page_index() == last_page_to_search_ && |
| 2163 result.char_index() >= last_character_index_to_search_) { | 2123 result.char_index() >= last_character_index_to_search_) { |
| 2164 break; | 2124 break; |
| 2165 } | 2125 } |
| 2166 | 2126 |
| 2167 AddFindResult(result); | 2127 AddFindResult(result); |
| 2168 } | 2128 } |
| 2169 | 2129 |
| 2170 FPDFText_FindClose(find); | 2130 FPDFText_FindClose(find); |
| 2171 } | 2131 } |
| 2172 | 2132 |
| 2173 void PDFiumEngine::SearchUsingICU(const base::string16& term, | 2133 void PDFiumEngine::SearchUsingICU(const base::string16& term, |
| 2174 bool case_sensitive, | 2134 bool case_sensitive, |
| 2175 bool first_search, | 2135 bool first_search, |
| 2176 int character_to_start_searching_from, | 2136 int character_to_start_searching_from, |
| 2177 int current_page) { | 2137 int current_page) { |
| 2178 DCHECK(!term.empty()); | 2138 DCHECK(!term.empty()); |
| 2179 | 2139 |
| 2180 const int original_text_length = pages_[current_page]->GetCharCount(); | 2140 const int original_text_length = pages_[current_page]->GetCharCount(); |
| 2181 int text_length = original_text_length; | 2141 int text_length = original_text_length; |
| 2182 if (character_to_start_searching_from) { | 2142 if (character_to_start_searching_from) { |
| 2183 text_length -= character_to_start_searching_from; | 2143 text_length -= character_to_start_searching_from; |
| 2184 } else if (!first_search && | 2144 } else if (!first_search && last_character_index_to_search_ != -1 && |
| 2185 last_character_index_to_search_ != -1 && | |
| 2186 current_page == last_page_to_search_) { | 2145 current_page == last_page_to_search_) { |
| 2187 text_length = last_character_index_to_search_; | 2146 text_length = last_character_index_to_search_; |
| 2188 } | 2147 } |
| 2189 if (text_length <= 0) | 2148 if (text_length <= 0) |
| 2190 return; | 2149 return; |
| 2191 | 2150 |
| 2192 base::string16 page_text; | 2151 base::string16 page_text; |
| 2193 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter(&page_text, | 2152 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter( |
| 2194 text_length, | 2153 &page_text, text_length, false); |
| 2195 false); | |
| 2196 unsigned short* data = | 2154 unsigned short* data = |
| 2197 reinterpret_cast<unsigned short*>(api_string_adapter.GetData()); | 2155 reinterpret_cast<unsigned short*>(api_string_adapter.GetData()); |
| 2198 int written = FPDFText_GetText(pages_[current_page]->GetTextPage(), | 2156 int written = |
| 2199 character_to_start_searching_from, | 2157 FPDFText_GetText(pages_[current_page]->GetTextPage(), |
| 2200 text_length, | 2158 character_to_start_searching_from, text_length, data); |
| 2201 data); | |
| 2202 api_string_adapter.Close(written); | 2159 api_string_adapter.Close(written); |
| 2203 | 2160 |
| 2204 std::vector<PDFEngine::Client::SearchStringResult> results; | 2161 std::vector<PDFEngine::Client::SearchStringResult> results; |
| 2205 client_->SearchString( | 2162 client_->SearchString(page_text.c_str(), term.c_str(), case_sensitive, |
| 2206 page_text.c_str(), term.c_str(), case_sensitive, &results); | 2163 &results); |
| 2207 for (const auto& result : results) { | 2164 for (const auto& result : results) { |
| 2208 // Need to map the indexes from the page text, which may have generated | 2165 // Need to map the indexes from the page text, which may have generated |
| 2209 // characters like space etc, to character indices from the page. | 2166 // characters like space etc, to character indices from the page. |
| 2210 int temp_start = result.start_index + character_to_start_searching_from; | 2167 int temp_start = result.start_index + character_to_start_searching_from; |
| 2211 int start = FPDFText_GetCharIndexFromTextIndex( | 2168 int start = FPDFText_GetCharIndexFromTextIndex( |
| 2212 pages_[current_page]->GetTextPage(), temp_start); | 2169 pages_[current_page]->GetTextPage(), temp_start); |
| 2213 int end = FPDFText_GetCharIndexFromTextIndex( | 2170 int end = FPDFText_GetCharIndexFromTextIndex( |
| 2214 pages_[current_page]->GetTextPage(), | 2171 pages_[current_page]->GetTextPage(), temp_start + result.length); |
| 2215 temp_start + result.length); | |
| 2216 | 2172 |
| 2217 // If |term| occurs at the end of a page, then |end| will be -1 due to the | 2173 // If |term| occurs at the end of a page, then |end| will be -1 due to the |
| 2218 // index being out of bounds. Compensate for this case so the range | 2174 // index being out of bounds. Compensate for this case so the range |
| 2219 // character count calculation below works out. | 2175 // character count calculation below works out. |
| 2220 if (temp_start + result.length == original_text_length) { | 2176 if (temp_start + result.length == original_text_length) { |
| 2221 DCHECK_EQ(-1, end); | 2177 DCHECK_EQ(-1, end); |
| 2222 end = original_text_length; | 2178 end = original_text_length; |
| 2223 } | 2179 } |
| 2224 DCHECK_LT(start, end); | 2180 DCHECK_LT(start, end); |
| 2225 DCHECK_EQ(term.size(), static_cast<size_t>(end - start)); | 2181 DCHECK_EQ(term.size(), static_cast<size_t>(end - start)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2264 } | 2220 } |
| 2265 | 2221 |
| 2266 SelectionChangeInvalidator selection_invalidator(this); | 2222 SelectionChangeInvalidator selection_invalidator(this); |
| 2267 | 2223 |
| 2268 // Move back/forward through the search locations we previously found. | 2224 // Move back/forward through the search locations we previously found. |
| 2269 size_t new_index; | 2225 size_t new_index; |
| 2270 const size_t last_index = find_results_.size() - 1; | 2226 const size_t last_index = find_results_.size() - 1; |
| 2271 if (current_find_index_.valid()) { | 2227 if (current_find_index_.valid()) { |
| 2272 size_t current_index = current_find_index_.GetIndex(); | 2228 size_t current_index = current_find_index_.GetIndex(); |
| 2273 if (forward) { | 2229 if (forward) { |
| 2274 new_index = (current_index >= last_index) ? 0 : current_index + 1; | 2230 new_index = (current_index >= last_index) ? 0 : current_index + 1; |
| 2275 } else { | 2231 } else { |
| 2276 new_index = (current_find_index_.GetIndex() == 0) ? | 2232 new_index = (current_find_index_.GetIndex() == 0) ? last_index |
| 2277 last_index : current_index - 1; | 2233 : current_index - 1; |
| 2278 } | 2234 } |
| 2279 } else { | 2235 } else { |
| 2280 new_index = forward ? 0 : last_index; | 2236 new_index = forward ? 0 : last_index; |
| 2281 } | 2237 } |
| 2282 current_find_index_.SetIndex(new_index); | 2238 current_find_index_.SetIndex(new_index); |
| 2283 | 2239 |
| 2284 // Update the selection before telling the client to scroll, since it could | 2240 // Update the selection before telling the client to scroll, since it could |
| 2285 // paint then. | 2241 // paint then. |
| 2286 selection_.clear(); | 2242 selection_.clear(); |
| 2287 selection_.push_back(find_results_[current_find_index_.GetIndex()]); | 2243 selection_.push_back(find_results_[current_find_index_.GetIndex()]); |
| 2288 | 2244 |
| 2289 // If the result is not in view, scroll to it. | 2245 // If the result is not in view, scroll to it. |
| 2290 pp::Rect bounding_rect; | 2246 pp::Rect bounding_rect; |
| 2291 pp::Rect visible_rect = GetVisibleRect(); | 2247 pp::Rect visible_rect = GetVisibleRect(); |
| 2292 // Use zoom of 1.0 since visible_rect is without zoom. | 2248 // Use zoom of 1.0 since visible_rect is without zoom. |
| 2293 std::vector<pp::Rect> rects = | 2249 std::vector<pp::Rect> rects = |
| 2294 find_results_[current_find_index_.GetIndex()].GetScreenRects( | 2250 find_results_[current_find_index_.GetIndex()].GetScreenRects( |
| 2295 pp::Point(), 1.0, current_rotation_); | 2251 pp::Point(), 1.0, current_rotation_); |
| 2296 for (const auto& rect : rects) | 2252 for (const auto& rect : rects) |
| 2297 bounding_rect = bounding_rect.Union(rect); | 2253 bounding_rect = bounding_rect.Union(rect); |
| 2298 if (!visible_rect.Contains(bounding_rect)) { | 2254 if (!visible_rect.Contains(bounding_rect)) { |
| 2299 pp::Point center = bounding_rect.CenterPoint(); | 2255 pp::Point center = bounding_rect.CenterPoint(); |
| 2300 // Make the page centered. | 2256 // Make the page centered. |
| 2301 int new_y = static_cast<int>(center.y() * current_zoom_) - | 2257 int new_y = static_cast<int>(center.y() * current_zoom_) - |
| 2302 static_cast<int>(visible_rect.height() * current_zoom_ / 2); | 2258 static_cast<int>(visible_rect.height() * current_zoom_ / 2); |
| 2303 if (new_y < 0) | 2259 if (new_y < 0) |
| 2304 new_y = 0; | 2260 new_y = 0; |
| 2305 client_->ScrollToY(new_y); | 2261 client_->ScrollToY(new_y); |
| 2306 | 2262 |
| 2307 // Only move horizontally if it's not visible. | 2263 // Only move horizontally if it's not visible. |
| 2308 if (center.x() < visible_rect.x() || center.x() > visible_rect.right()) { | 2264 if (center.x() < visible_rect.x() || center.x() > visible_rect.right()) { |
| 2309 int new_x = static_cast<int>(center.x() * current_zoom_) - | 2265 int new_x = static_cast<int>(center.x() * current_zoom_) - |
| 2310 static_cast<int>(visible_rect.width() * current_zoom_ / 2); | 2266 static_cast<int>(visible_rect.width() * current_zoom_ / 2); |
| 2311 if (new_x < 0) | 2267 if (new_x < 0) |
| 2312 new_x = 0; | 2268 new_x = 0; |
| 2313 client_->ScrollToX(new_x); | 2269 client_->ScrollToX(new_x); |
| 2314 } | 2270 } |
| 2315 } | 2271 } |
| 2316 | 2272 |
| 2317 client_->NotifySelectedFindResultChanged(current_find_index_.GetIndex()); | 2273 client_->NotifySelectedFindResultChanged(current_find_index_.GetIndex()); |
| 2318 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true); | 2274 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true); |
| 2319 return true; | 2275 return true; |
| 2320 } | 2276 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2379 client_->Invalidate(pp::Rect(plugin_size_)); | 2335 client_->Invalidate(pp::Rect(plugin_size_)); |
| 2380 } | 2336 } |
| 2381 | 2337 |
| 2382 std::string PDFiumEngine::GetSelectedText() { | 2338 std::string PDFiumEngine::GetSelectedText() { |
| 2383 if (!HasPermission(PDFEngine::PERMISSION_COPY)) | 2339 if (!HasPermission(PDFEngine::PERMISSION_COPY)) |
| 2384 return std::string(); | 2340 return std::string(); |
| 2385 | 2341 |
| 2386 base::string16 result; | 2342 base::string16 result; |
| 2387 base::string16 new_line_char = base::UTF8ToUTF16("\n"); | 2343 base::string16 new_line_char = base::UTF8ToUTF16("\n"); |
| 2388 for (size_t i = 0; i < selection_.size(); ++i) { | 2344 for (size_t i = 0; i < selection_.size(); ++i) { |
| 2389 if (i > 0 && | 2345 if (i > 0 && selection_[i - 1].page_index() > selection_[i].page_index()) { |
| 2390 selection_[i - 1].page_index() > selection_[i].page_index()) { | |
| 2391 result = selection_[i].GetText() + new_line_char + result; | 2346 result = selection_[i].GetText() + new_line_char + result; |
| 2392 } else { | 2347 } else { |
| 2393 if (i > 0) | 2348 if (i > 0) |
| 2394 result.append(new_line_char); | 2349 result.append(new_line_char); |
| 2395 result.append(selection_[i].GetText()); | 2350 result.append(selection_[i].GetText()); |
| 2396 } | 2351 } |
| 2397 } | 2352 } |
| 2398 | 2353 |
| 2399 FormatStringWithHyphens(&result); | 2354 FormatStringWithHyphens(&result); |
| 2400 FormatStringForOS(&result); | 2355 FormatStringForOS(&result); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2490 // to defer the page deletion otherwise we could potentially delete the page | 2445 // to defer the page deletion otherwise we could potentially delete the page |
| 2491 // that originated the calling JS request and destroy the objects that are | 2446 // that originated the calling JS request and destroy the objects that are |
| 2492 // currently being used. | 2447 // currently being used. |
| 2493 base::AutoReset<bool> defer_page_unload_guard(&defer_page_unload_, true); | 2448 base::AutoReset<bool> defer_page_unload_guard(&defer_page_unload_, true); |
| 2494 CalculateVisiblePages(); | 2449 CalculateVisiblePages(); |
| 2495 return most_visible_page_; | 2450 return most_visible_page_; |
| 2496 } | 2451 } |
| 2497 | 2452 |
| 2498 pp::Rect PDFiumEngine::GetPageRect(int index) { | 2453 pp::Rect PDFiumEngine::GetPageRect(int index) { |
| 2499 pp::Rect rc(pages_[index]->rect()); | 2454 pp::Rect rc(pages_[index]->rect()); |
| 2500 rc.Inset(-kPageShadowLeft, -kPageShadowTop, | 2455 rc.Inset(-kPageShadowLeft, -kPageShadowTop, -kPageShadowRight, |
| 2501 -kPageShadowRight, -kPageShadowBottom); | 2456 -kPageShadowBottom); |
| 2502 return rc; | 2457 return rc; |
| 2503 } | 2458 } |
| 2504 | 2459 |
| 2505 pp::Rect PDFiumEngine::GetPageBoundsRect(int index) { | 2460 pp::Rect PDFiumEngine::GetPageBoundsRect(int index) { |
| 2506 return pages_[index]->rect(); | 2461 return pages_[index]->rect(); |
| 2507 } | 2462 } |
| 2508 | 2463 |
| 2509 pp::Rect PDFiumEngine::GetPageContentsRect(int index) { | 2464 pp::Rect PDFiumEngine::GetPageContentsRect(int index) { |
| 2510 return GetScreenRect(pages_[index]->rect()); | 2465 return GetScreenRect(pages_[index]->rect()); |
| 2511 } | 2466 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2612 | 2567 |
| 2613 pp::Rect rect(pp::Point(0, document_size_.height()), page_size); | 2568 pp::Rect rect(pp::Point(0, document_size_.height()), page_size); |
| 2614 page_rects.push_back(rect); | 2569 page_rects.push_back(rect); |
| 2615 | 2570 |
| 2616 document_size_.Enlarge(0, page_size.height()); | 2571 document_size_.Enlarge(0, page_size.height()); |
| 2617 } | 2572 } |
| 2618 | 2573 |
| 2619 // Create blank pages. | 2574 // Create blank pages. |
| 2620 for (int i = 1; i < num_pages; ++i) { | 2575 for (int i = 1; i < num_pages; ++i) { |
| 2621 pp::Rect page_rect(page_rects[i]); | 2576 pp::Rect page_rect(page_rects[i]); |
| 2622 page_rect.Inset(kPageShadowLeft, kPageShadowTop, | 2577 page_rect.Inset(kPageShadowLeft, kPageShadowTop, kPageShadowRight, |
| 2623 kPageShadowRight, kPageShadowBottom); | 2578 kPageShadowBottom); |
| 2624 double width_in_points = ConvertUnitDouble(page_rect.width(), | 2579 double width_in_points = |
| 2625 kPixelsPerInch, | 2580 ConvertUnitDouble(page_rect.width(), kPixelsPerInch, kPointsPerInch); |
| 2626 kPointsPerInch); | 2581 double height_in_points = |
| 2627 double height_in_points = ConvertUnitDouble(page_rect.height(), | 2582 ConvertUnitDouble(page_rect.height(), kPixelsPerInch, kPointsPerInch); |
| 2628 kPixelsPerInch, | |
| 2629 kPointsPerInch); | |
| 2630 FPDFPage_New(doc_, i, width_in_points, height_in_points); | 2583 FPDFPage_New(doc_, i, width_in_points, height_in_points); |
| 2631 pages_.push_back(base::MakeUnique<PDFiumPage>(this, i, page_rect, true)); | 2584 pages_.push_back(base::MakeUnique<PDFiumPage>(this, i, page_rect, true)); |
| 2632 } | 2585 } |
| 2633 | 2586 |
| 2634 CalculateVisiblePages(); | 2587 CalculateVisiblePages(); |
| 2635 if (document_size_ != old_document_size) | 2588 if (document_size_ != old_document_size) |
| 2636 client_->DocumentSizeUpdated(document_size_); | 2589 client_->DocumentSizeUpdated(document_size_); |
| 2637 } | 2590 } |
| 2638 | 2591 |
| 2639 void PDFiumEngine::LoadDocument() { | 2592 void PDFiumEngine::LoadDocument() { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2806 if (size.width() > document_size_.width()) | 2759 if (size.width() > document_size_.width()) |
| 2807 document_size_.set_width(size.width()); | 2760 document_size_.set_width(size.width()); |
| 2808 | 2761 |
| 2809 document_size_.Enlarge(0, size.height()); | 2762 document_size_.Enlarge(0, size.height()); |
| 2810 } | 2763 } |
| 2811 | 2764 |
| 2812 for (int i = 0; i < page_count; ++i) { | 2765 for (int i = 0; i < page_count; ++i) { |
| 2813 // Center pages relative to the entire document. | 2766 // Center pages relative to the entire document. |
| 2814 page_rects[i].set_x((document_size_.width() - page_rects[i].width()) / 2); | 2767 page_rects[i].set_x((document_size_.width() - page_rects[i].width()) / 2); |
| 2815 pp::Rect page_rect(page_rects[i]); | 2768 pp::Rect page_rect(page_rects[i]); |
| 2816 page_rect.Inset(kPageShadowLeft, kPageShadowTop, | 2769 page_rect.Inset(kPageShadowLeft, kPageShadowTop, kPageShadowRight, |
| 2817 kPageShadowRight, kPageShadowBottom); | 2770 kPageShadowBottom); |
| 2818 if (reload) { | 2771 if (reload) { |
| 2819 pages_[i]->set_rect(page_rect); | 2772 pages_[i]->set_rect(page_rect); |
| 2820 } else { | 2773 } else { |
| 2821 // The page is marked as not being available even if |doc_complete| is | 2774 // The page is marked as not being available even if |doc_complete| is |
| 2822 // true because FPDFAvail_IsPageAvail() still has to be called for this | 2775 // true because FPDFAvail_IsPageAvail() still has to be called for this |
| 2823 // page, which will be done in FinishLoadingDocument(). | 2776 // page, which will be done in FinishLoadingDocument(). |
| 2824 pages_.push_back(base::MakeUnique<PDFiumPage>(this, i, page_rect, false)); | 2777 pages_.push_back(base::MakeUnique<PDFiumPage>(this, i, page_rect, false)); |
| 2825 } | 2778 } |
| 2826 } | 2779 } |
| 2827 | 2780 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2912 pages_[index]->set_available(true); | 2865 pages_[index]->set_available(true); |
| 2913 if (default_page_size_.IsEmpty()) | 2866 if (default_page_size_.IsEmpty()) |
| 2914 default_page_size_ = GetPageSize(index); | 2867 default_page_size_ = GetPageSize(index); |
| 2915 return true; | 2868 return true; |
| 2916 } | 2869 } |
| 2917 | 2870 |
| 2918 pp::Size PDFiumEngine::GetPageSize(int index) { | 2871 pp::Size PDFiumEngine::GetPageSize(int index) { |
| 2919 pp::Size size; | 2872 pp::Size size; |
| 2920 double width_in_points = 0; | 2873 double width_in_points = 0; |
| 2921 double height_in_points = 0; | 2874 double height_in_points = 0; |
| 2922 int rv = FPDF_GetPageSizeByIndex( | 2875 int rv = |
| 2923 doc_, index, &width_in_points, &height_in_points); | 2876 FPDF_GetPageSizeByIndex(doc_, index, &width_in_points, &height_in_points); |
| 2924 | 2877 |
| 2925 if (rv) { | 2878 if (rv) { |
| 2926 int width_in_pixels = static_cast<int>( | 2879 int width_in_pixels = static_cast<int>( |
| 2927 ConvertUnitDouble(width_in_points, kPointsPerInch, kPixelsPerInch)); | 2880 ConvertUnitDouble(width_in_points, kPointsPerInch, kPixelsPerInch)); |
| 2928 int height_in_pixels = static_cast<int>( | 2881 int height_in_pixels = static_cast<int>( |
| 2929 ConvertUnitDouble(height_in_points, kPointsPerInch, kPixelsPerInch)); | 2882 ConvertUnitDouble(height_in_points, kPointsPerInch, kPixelsPerInch)); |
| 2930 if (current_rotation_ % 2 == 1) | 2883 if (current_rotation_ % 2 == 1) |
| 2931 std::swap(width_in_pixels, height_in_pixels); | 2884 std::swap(width_in_pixels, height_in_pixels); |
| 2932 size = pp::Size(width_in_pixels, height_in_pixels); | 2885 size = pp::Size(width_in_pixels, height_in_pixels); |
| 2933 } | 2886 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2966 last_progressive_start_time_ = base::Time::Now(); | 2919 last_progressive_start_time_ = base::Time::Now(); |
| 2967 if (bitmap) { | 2920 if (bitmap) { |
| 2968 rv = FPDF_RenderPage_Continue(page, static_cast<IFSDK_PAUSE*>(this)); | 2921 rv = FPDF_RenderPage_Continue(page, static_cast<IFSDK_PAUSE*>(this)); |
| 2969 } else { | 2922 } else { |
| 2970 pp::Rect dirty = progressive_paints_[progressive_index].rect; | 2923 pp::Rect dirty = progressive_paints_[progressive_index].rect; |
| 2971 bitmap = CreateBitmap(dirty, image_data); | 2924 bitmap = CreateBitmap(dirty, image_data); |
| 2972 int start_x, start_y, size_x, size_y; | 2925 int start_x, start_y, size_x, size_y; |
| 2973 GetPDFiumRect(page_index, dirty, &start_x, &start_y, &size_x, &size_y); | 2926 GetPDFiumRect(page_index, dirty, &start_x, &start_y, &size_x, &size_y); |
| 2974 FPDFBitmap_FillRect(bitmap, start_x, start_y, size_x, size_y, 0xFFFFFFFF); | 2927 FPDFBitmap_FillRect(bitmap, start_x, start_y, size_x, size_y, 0xFFFFFFFF); |
| 2975 rv = FPDF_RenderPageBitmap_Start( | 2928 rv = FPDF_RenderPageBitmap_Start( |
| 2976 bitmap, page, start_x, start_y, size_x, size_y, | 2929 bitmap, page, start_x, start_y, size_x, size_y, current_rotation_, |
| 2977 current_rotation_, | |
| 2978 GetRenderingFlags(), static_cast<IFSDK_PAUSE*>(this)); | 2930 GetRenderingFlags(), static_cast<IFSDK_PAUSE*>(this)); |
| 2979 progressive_paints_[progressive_index].bitmap = bitmap; | 2931 progressive_paints_[progressive_index].bitmap = bitmap; |
| 2980 } | 2932 } |
| 2981 return rv != FPDF_RENDER_TOBECOUNTINUED; | 2933 return rv != FPDF_RENDER_TOBECOUNTINUED; |
| 2982 } | 2934 } |
| 2983 | 2935 |
| 2984 void PDFiumEngine::FinishPaint(int progressive_index, | 2936 void PDFiumEngine::FinishPaint(int progressive_index, |
| 2985 pp::ImageData* image_data) { | 2937 pp::ImageData* image_data) { |
| 2986 DCHECK_GE(progressive_index, 0); | 2938 DCHECK_GE(progressive_index, 0); |
| 2987 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); | 2939 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); |
| 2988 DCHECK(image_data); | 2940 DCHECK(image_data); |
| 2989 | 2941 |
| 2990 int page_index = progressive_paints_[progressive_index].page_index; | 2942 int page_index = progressive_paints_[progressive_index].page_index; |
| 2991 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; | 2943 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; |
| 2992 FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap; | 2944 FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap; |
| 2993 int start_x, start_y, size_x, size_y; | 2945 int start_x, start_y, size_x, size_y; |
| 2994 GetPDFiumRect( | 2946 GetPDFiumRect(page_index, dirty_in_screen, &start_x, &start_y, &size_x, |
| 2995 page_index, dirty_in_screen, &start_x, &start_y, &size_x, &size_y); | 2947 &size_y); |
| 2996 | 2948 |
| 2997 // Draw the forms. | 2949 // Draw the forms. |
| 2998 FPDF_FFLDraw( | 2950 FPDF_FFLDraw(form_, bitmap, pages_[page_index]->GetPage(), start_x, start_y, |
| 2999 form_, bitmap, pages_[page_index]->GetPage(), start_x, start_y, size_x, | 2951 size_x, size_y, current_rotation_, GetRenderingFlags()); |
| 3000 size_y, current_rotation_, GetRenderingFlags()); | |
| 3001 | 2952 |
| 3002 FillPageSides(progressive_index); | 2953 FillPageSides(progressive_index); |
| 3003 | 2954 |
| 3004 // Paint the page shadows. | 2955 // Paint the page shadows. |
| 3005 PaintPageShadow(progressive_index, image_data); | 2956 PaintPageShadow(progressive_index, image_data); |
| 3006 | 2957 |
| 3007 DrawSelections(progressive_index, image_data); | 2958 DrawSelections(progressive_index, image_data); |
| 3008 | 2959 |
| 3009 FPDF_RenderPage_Close(pages_[page_index]->GetPage()); | 2960 FPDF_RenderPage_Close(pages_[page_index]->GetPage()); |
| 3010 FPDFBitmap_Destroy(bitmap); | 2961 FPDFBitmap_Destroy(bitmap); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3024 void PDFiumEngine::FillPageSides(int progressive_index) { | 2975 void PDFiumEngine::FillPageSides(int progressive_index) { |
| 3025 DCHECK_GE(progressive_index, 0); | 2976 DCHECK_GE(progressive_index, 0); |
| 3026 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); | 2977 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); |
| 3027 | 2978 |
| 3028 int page_index = progressive_paints_[progressive_index].page_index; | 2979 int page_index = progressive_paints_[progressive_index].page_index; |
| 3029 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; | 2980 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; |
| 3030 FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap; | 2981 FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap; |
| 3031 | 2982 |
| 3032 pp::Rect page_rect = pages_[page_index]->rect(); | 2983 pp::Rect page_rect = pages_[page_index]->rect(); |
| 3033 if (page_rect.x() > 0) { | 2984 if (page_rect.x() > 0) { |
| 3034 pp::Rect left(0, | 2985 pp::Rect left(0, page_rect.y() - kPageShadowTop, |
| 3035 page_rect.y() - kPageShadowTop, | |
| 3036 page_rect.x() - kPageShadowLeft, | 2986 page_rect.x() - kPageShadowLeft, |
| 3037 page_rect.height() + kPageShadowTop + | 2987 page_rect.height() + kPageShadowTop + kPageShadowBottom + |
| 3038 kPageShadowBottom + kPageSeparatorThickness); | 2988 kPageSeparatorThickness); |
| 3039 left = GetScreenRect(left).Intersect(dirty_in_screen); | 2989 left = GetScreenRect(left).Intersect(dirty_in_screen); |
| 3040 | 2990 |
| 3041 FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(), | 2991 FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(), |
| 3042 left.y() - dirty_in_screen.y(), left.width(), | 2992 left.y() - dirty_in_screen.y(), left.width(), |
| 3043 left.height(), client_->GetBackgroundColor()); | 2993 left.height(), client_->GetBackgroundColor()); |
| 3044 } | 2994 } |
| 3045 | 2995 |
| 3046 if (page_rect.right() < document_size_.width()) { | 2996 if (page_rect.right() < document_size_.width()) { |
| 3047 pp::Rect right(page_rect.right() + kPageShadowRight, | 2997 pp::Rect right( |
| 3048 page_rect.y() - kPageShadowTop, | 2998 page_rect.right() + kPageShadowRight, page_rect.y() - kPageShadowTop, |
| 3049 document_size_.width() - page_rect.right() - | 2999 document_size_.width() - page_rect.right() - kPageShadowRight, |
| 3050 kPageShadowRight, | 3000 page_rect.height() + kPageShadowTop + kPageShadowBottom + |
| 3051 page_rect.height() + kPageShadowTop + | 3001 kPageSeparatorThickness); |
| 3052 kPageShadowBottom + kPageSeparatorThickness); | |
| 3053 right = GetScreenRect(right).Intersect(dirty_in_screen); | 3002 right = GetScreenRect(right).Intersect(dirty_in_screen); |
| 3054 | 3003 |
| 3055 FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(), | 3004 FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(), |
| 3056 right.y() - dirty_in_screen.y(), right.width(), | 3005 right.y() - dirty_in_screen.y(), right.width(), |
| 3057 right.height(), client_->GetBackgroundColor()); | 3006 right.height(), client_->GetBackgroundColor()); |
| 3058 } | 3007 } |
| 3059 | 3008 |
| 3060 // Paint separator. | 3009 // Paint separator. |
| 3061 pp::Rect bottom(page_rect.x() - kPageShadowLeft, | 3010 pp::Rect bottom(page_rect.x() - kPageShadowLeft, |
| 3062 page_rect.bottom() + kPageShadowBottom, | 3011 page_rect.bottom() + kPageShadowBottom, |
| 3063 page_rect.width() + kPageShadowLeft + kPageShadowRight, | 3012 page_rect.width() + kPageShadowLeft + kPageShadowRight, |
| 3064 kPageSeparatorThickness); | 3013 kPageSeparatorThickness); |
| 3065 bottom = GetScreenRect(bottom).Intersect(dirty_in_screen); | 3014 bottom = GetScreenRect(bottom).Intersect(dirty_in_screen); |
| 3066 | 3015 |
| 3067 FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(), | 3016 FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(), |
| 3068 bottom.y() - dirty_in_screen.y(), bottom.width(), | 3017 bottom.y() - dirty_in_screen.y(), bottom.width(), |
| 3069 bottom.height(), client_->GetBackgroundColor()); | 3018 bottom.height(), client_->GetBackgroundColor()); |
| 3070 } | 3019 } |
| 3071 | 3020 |
| 3072 void PDFiumEngine::PaintPageShadow(int progressive_index, | 3021 void PDFiumEngine::PaintPageShadow(int progressive_index, |
| 3073 pp::ImageData* image_data) { | 3022 pp::ImageData* image_data) { |
| 3074 DCHECK_GE(progressive_index, 0); | 3023 DCHECK_GE(progressive_index, 0); |
| 3075 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); | 3024 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); |
| 3076 DCHECK(image_data); | 3025 DCHECK(image_data); |
| 3077 | 3026 |
| 3078 int page_index = progressive_paints_[progressive_index].page_index; | 3027 int page_index = progressive_paints_[progressive_index].page_index; |
| 3079 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; | 3028 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; |
| 3080 pp::Rect page_rect = pages_[page_index]->rect(); | 3029 pp::Rect page_rect = pages_[page_index]->rect(); |
| 3081 pp::Rect shadow_rect(page_rect); | 3030 pp::Rect shadow_rect(page_rect); |
| 3082 shadow_rect.Inset(-kPageShadowLeft, -kPageShadowTop, | 3031 shadow_rect.Inset(-kPageShadowLeft, -kPageShadowTop, -kPageShadowRight, |
| 3083 -kPageShadowRight, -kPageShadowBottom); | 3032 -kPageShadowBottom); |
| 3084 | 3033 |
| 3085 // Due to the rounding errors of the GetScreenRect it is possible to get | 3034 // Due to the rounding errors of the GetScreenRect it is possible to get |
| 3086 // different size shadows on the left and right sides even they are defined | 3035 // different size shadows on the left and right sides even they are defined |
| 3087 // the same. To fix this issue let's calculate shadow rect and then shrink | 3036 // the same. To fix this issue let's calculate shadow rect and then shrink |
| 3088 // it by the size of the shadows. | 3037 // it by the size of the shadows. |
| 3089 shadow_rect = GetScreenRect(shadow_rect); | 3038 shadow_rect = GetScreenRect(shadow_rect); |
| 3090 page_rect = shadow_rect; | 3039 page_rect = shadow_rect; |
| 3091 | 3040 |
| 3092 page_rect.Inset(static_cast<int>(ceil(kPageShadowLeft * current_zoom_)), | 3041 page_rect.Inset(static_cast<int>(ceil(kPageShadowLeft * current_zoom_)), |
| 3093 static_cast<int>(ceil(kPageShadowTop * current_zoom_)), | 3042 static_cast<int>(ceil(kPageShadowTop * current_zoom_)), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3116 if (range.page_index() != page_index) | 3065 if (range.page_index() != page_index) |
| 3117 continue; | 3066 continue; |
| 3118 | 3067 |
| 3119 std::vector<pp::Rect> rects = range.GetScreenRects( | 3068 std::vector<pp::Rect> rects = range.GetScreenRects( |
| 3120 visible_rect.point(), current_zoom_, current_rotation_); | 3069 visible_rect.point(), current_zoom_, current_rotation_); |
| 3121 for (const auto& rect : rects) { | 3070 for (const auto& rect : rects) { |
| 3122 pp::Rect visible_selection = rect.Intersect(dirty_in_screen); | 3071 pp::Rect visible_selection = rect.Intersect(dirty_in_screen); |
| 3123 if (visible_selection.IsEmpty()) | 3072 if (visible_selection.IsEmpty()) |
| 3124 continue; | 3073 continue; |
| 3125 | 3074 |
| 3126 visible_selection.Offset( | 3075 visible_selection.Offset(-dirty_in_screen.point().x(), |
| 3127 -dirty_in_screen.point().x(), -dirty_in_screen.point().y()); | 3076 -dirty_in_screen.point().y()); |
| 3128 Highlight(region, stride, visible_selection, &highlighted_rects); | 3077 Highlight(region, stride, visible_selection, &highlighted_rects); |
| 3129 } | 3078 } |
| 3130 } | 3079 } |
| 3131 | 3080 |
| 3132 for (const auto& highlight : form_highlights_) { | 3081 for (const auto& highlight : form_highlights_) { |
| 3133 pp::Rect visible_selection = highlight.Intersect(dirty_in_screen); | 3082 pp::Rect visible_selection = highlight.Intersect(dirty_in_screen); |
| 3134 if (visible_selection.IsEmpty()) | 3083 if (visible_selection.IsEmpty()) |
| 3135 continue; | 3084 continue; |
| 3136 | 3085 |
| 3137 visible_selection.Offset( | 3086 visible_selection.Offset(-dirty_in_screen.point().x(), |
| 3138 -dirty_in_screen.point().x(), -dirty_in_screen.point().y()); | 3087 -dirty_in_screen.point().y()); |
| 3139 Highlight(region, stride, visible_selection, &highlighted_rects); | 3088 Highlight(region, stride, visible_selection, &highlighted_rects); |
| 3140 } | 3089 } |
| 3141 form_highlights_.clear(); | 3090 form_highlights_.clear(); |
| 3142 } | 3091 } |
| 3143 | 3092 |
| 3144 void PDFiumEngine::PaintUnavailablePage(int page_index, | 3093 void PDFiumEngine::PaintUnavailablePage(int page_index, |
| 3145 const pp::Rect& dirty, | 3094 const pp::Rect& dirty, |
| 3146 pp::ImageData* image_data) { | 3095 pp::ImageData* image_data) { |
| 3147 int start_x, start_y, size_x, size_y; | 3096 int start_x, start_y, size_x, size_y; |
| 3148 GetPDFiumRect(page_index, dirty, &start_x, &start_y, &size_x, &size_y); | 3097 GetPDFiumRect(page_index, dirty, &start_x, &start_y, &size_x, &size_y); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3165 return -1; | 3114 return -1; |
| 3166 } | 3115 } |
| 3167 | 3116 |
| 3168 FPDF_BITMAP PDFiumEngine::CreateBitmap(const pp::Rect& rect, | 3117 FPDF_BITMAP PDFiumEngine::CreateBitmap(const pp::Rect& rect, |
| 3169 pp::ImageData* image_data) const { | 3118 pp::ImageData* image_data) const { |
| 3170 void* region; | 3119 void* region; |
| 3171 int stride; | 3120 int stride; |
| 3172 GetRegion(rect.point(), image_data, ®ion, &stride); | 3121 GetRegion(rect.point(), image_data, ®ion, &stride); |
| 3173 if (!region) | 3122 if (!region) |
| 3174 return nullptr; | 3123 return nullptr; |
| 3175 return FPDFBitmap_CreateEx( | 3124 return FPDFBitmap_CreateEx(rect.width(), rect.height(), FPDFBitmap_BGRx, |
| 3176 rect.width(), rect.height(), FPDFBitmap_BGRx, region, stride); | 3125 region, stride); |
| 3177 } | 3126 } |
| 3178 | 3127 |
| 3179 void PDFiumEngine::GetPDFiumRect( | 3128 void PDFiumEngine::GetPDFiumRect(int page_index, |
| 3180 int page_index, const pp::Rect& rect, int* start_x, int* start_y, | 3129 const pp::Rect& rect, |
| 3181 int* size_x, int* size_y) const { | 3130 int* start_x, |
| 3131 int* start_y, |
| 3132 int* size_x, |
| 3133 int* size_y) const { |
| 3182 pp::Rect page_rect = GetScreenRect(pages_[page_index]->rect()); | 3134 pp::Rect page_rect = GetScreenRect(pages_[page_index]->rect()); |
| 3183 page_rect.Offset(-rect.x(), -rect.y()); | 3135 page_rect.Offset(-rect.x(), -rect.y()); |
| 3184 | 3136 |
| 3185 *start_x = page_rect.x(); | 3137 *start_x = page_rect.x(); |
| 3186 *start_y = page_rect.y(); | 3138 *start_y = page_rect.y(); |
| 3187 *size_x = page_rect.width(); | 3139 *size_x = page_rect.width(); |
| 3188 *size_y = page_rect.height(); | 3140 *size_y = page_rect.height(); |
| 3189 } | 3141 } |
| 3190 | 3142 |
| 3191 int PDFiumEngine::GetRenderingFlags() const { | 3143 int PDFiumEngine::GetRenderingFlags() const { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3205 rv.set_y(static_cast<int>(position_.y() / current_zoom_)); | 3157 rv.set_y(static_cast<int>(position_.y() / current_zoom_)); |
| 3206 rv.set_width(static_cast<int>(ceil(plugin_size_.width() / current_zoom_))); | 3158 rv.set_width(static_cast<int>(ceil(plugin_size_.width() / current_zoom_))); |
| 3207 rv.set_height(static_cast<int>(ceil(plugin_size_.height() / current_zoom_))); | 3159 rv.set_height(static_cast<int>(ceil(plugin_size_.height() / current_zoom_))); |
| 3208 return rv; | 3160 return rv; |
| 3209 } | 3161 } |
| 3210 | 3162 |
| 3211 pp::Rect PDFiumEngine::GetPageScreenRect(int page_index) const { | 3163 pp::Rect PDFiumEngine::GetPageScreenRect(int page_index) const { |
| 3212 // Since we use this rect for creating the PDFium bitmap, also include other | 3164 // Since we use this rect for creating the PDFium bitmap, also include other |
| 3213 // areas around the page that we might need to update such as the page | 3165 // areas around the page that we might need to update such as the page |
| 3214 // separator and the sides if the page is narrower than the document. | 3166 // separator and the sides if the page is narrower than the document. |
| 3215 return GetScreenRect(pp::Rect( | 3167 return GetScreenRect( |
| 3216 0, | 3168 pp::Rect(0, pages_[page_index]->rect().y() - kPageShadowTop, |
| 3217 pages_[page_index]->rect().y() - kPageShadowTop, | 3169 document_size_.width(), |
| 3218 document_size_.width(), | 3170 pages_[page_index]->rect().height() + kPageShadowTop + |
| 3219 pages_[page_index]->rect().height() + kPageShadowTop + | 3171 kPageShadowBottom + kPageSeparatorThickness)); |
| 3220 kPageShadowBottom + kPageSeparatorThickness)); | |
| 3221 } | 3172 } |
| 3222 | 3173 |
| 3223 pp::Rect PDFiumEngine::GetScreenRect(const pp::Rect& rect) const { | 3174 pp::Rect PDFiumEngine::GetScreenRect(const pp::Rect& rect) const { |
| 3224 pp::Rect rv; | 3175 pp::Rect rv; |
| 3225 int right = | 3176 int right = |
| 3226 static_cast<int>(ceil(rect.right() * current_zoom_ - position_.x())); | 3177 static_cast<int>(ceil(rect.right() * current_zoom_ - position_.x())); |
| 3227 int bottom = | 3178 int bottom = |
| 3228 static_cast<int>(ceil(rect.bottom() * current_zoom_ - position_.y())); | 3179 static_cast<int>(ceil(rect.bottom() * current_zoom_ - position_.y())); |
| 3229 | 3180 |
| 3230 rv.set_x(static_cast<int>(rect.x() * current_zoom_ - position_.x())); | 3181 rv.set_x(static_cast<int>(rect.x() * current_zoom_ - position_.x())); |
| 3231 rv.set_y(static_cast<int>(rect.y() * current_zoom_ - position_.y())); | 3182 rv.set_y(static_cast<int>(rect.y() * current_zoom_ - position_.y())); |
| 3232 rv.set_width(right - rv.x()); | 3183 rv.set_width(right - rv.x()); |
| 3233 rv.set_height(bottom - rv.y()); | 3184 rv.set_height(bottom - rv.y()); |
| 3234 return rv; | 3185 return rv; |
| 3235 } | 3186 } |
| 3236 | 3187 |
| 3237 void PDFiumEngine::Highlight(void* buffer, | 3188 void PDFiumEngine::Highlight(void* buffer, |
| 3238 int stride, | 3189 int stride, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3256 uint8_t* pixel = static_cast<uint8_t*>(buffer) + y * stride + x * 4; | 3207 uint8_t* pixel = static_cast<uint8_t*>(buffer) + y * stride + x * 4; |
| 3257 // This is our highlight color. | 3208 // This is our highlight color. |
| 3258 pixel[0] = static_cast<uint8_t>(pixel[0] * (kHighlightColorB / 255.0)); | 3209 pixel[0] = static_cast<uint8_t>(pixel[0] * (kHighlightColorB / 255.0)); |
| 3259 pixel[1] = static_cast<uint8_t>(pixel[1] * (kHighlightColorG / 255.0)); | 3210 pixel[1] = static_cast<uint8_t>(pixel[1] * (kHighlightColorG / 255.0)); |
| 3260 pixel[2] = static_cast<uint8_t>(pixel[2] * (kHighlightColorR / 255.0)); | 3211 pixel[2] = static_cast<uint8_t>(pixel[2] * (kHighlightColorR / 255.0)); |
| 3261 } | 3212 } |
| 3262 } | 3213 } |
| 3263 } | 3214 } |
| 3264 | 3215 |
| 3265 PDFiumEngine::SelectionChangeInvalidator::SelectionChangeInvalidator( | 3216 PDFiumEngine::SelectionChangeInvalidator::SelectionChangeInvalidator( |
| 3266 PDFiumEngine* engine) : engine_(engine) { | 3217 PDFiumEngine* engine) |
| 3218 : engine_(engine) { |
| 3267 previous_origin_ = engine_->GetVisibleRect().point(); | 3219 previous_origin_ = engine_->GetVisibleRect().point(); |
| 3268 GetVisibleSelectionsScreenRects(&old_selections_); | 3220 GetVisibleSelectionsScreenRects(&old_selections_); |
| 3269 } | 3221 } |
| 3270 | 3222 |
| 3271 PDFiumEngine::SelectionChangeInvalidator::~SelectionChangeInvalidator() { | 3223 PDFiumEngine::SelectionChangeInvalidator::~SelectionChangeInvalidator() { |
| 3272 // Offset the old selections if the document scrolled since we recorded them. | 3224 // Offset the old selections if the document scrolled since we recorded them. |
| 3273 pp::Point offset = previous_origin_ - engine_->GetVisibleRect().point(); | 3225 pp::Point offset = previous_origin_ - engine_->GetVisibleRect().point(); |
| 3274 for (auto& old_selection : old_selections_) | 3226 for (auto& old_selection : old_selections_) |
| 3275 old_selection.Offset(offset); | 3227 old_selection.Offset(offset); |
| 3276 | 3228 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3300 | 3252 |
| 3301 void PDFiumEngine::SelectionChangeInvalidator::GetVisibleSelectionsScreenRects( | 3253 void PDFiumEngine::SelectionChangeInvalidator::GetVisibleSelectionsScreenRects( |
| 3302 std::vector<pp::Rect>* rects) { | 3254 std::vector<pp::Rect>* rects) { |
| 3303 pp::Rect visible_rect = engine_->GetVisibleRect(); | 3255 pp::Rect visible_rect = engine_->GetVisibleRect(); |
| 3304 for (auto& range : engine_->selection_) { | 3256 for (auto& range : engine_->selection_) { |
| 3305 int page_index = range.page_index(); | 3257 int page_index = range.page_index(); |
| 3306 if (!engine_->IsPageVisible(page_index)) | 3258 if (!engine_->IsPageVisible(page_index)) |
| 3307 continue; // This selection is on a page that's not currently visible. | 3259 continue; // This selection is on a page that's not currently visible. |
| 3308 | 3260 |
| 3309 std::vector<pp::Rect> selection_rects = | 3261 std::vector<pp::Rect> selection_rects = |
| 3310 range.GetScreenRects( | 3262 range.GetScreenRects(visible_rect.point(), engine_->current_zoom_, |
| 3311 visible_rect.point(), | 3263 engine_->current_rotation_); |
| 3312 engine_->current_zoom_, | |
| 3313 engine_->current_rotation_); | |
| 3314 rects->insert(rects->end(), selection_rects.begin(), selection_rects.end()); | 3264 rects->insert(rects->end(), selection_rects.begin(), selection_rects.end()); |
| 3315 } | 3265 } |
| 3316 } | 3266 } |
| 3317 | 3267 |
| 3318 PDFiumEngine::MouseDownState::MouseDownState( | 3268 PDFiumEngine::MouseDownState::MouseDownState( |
| 3319 const PDFiumPage::Area& area, | 3269 const PDFiumPage::Area& area, |
| 3320 const PDFiumPage::LinkTarget& target) | 3270 const PDFiumPage::LinkTarget& target) |
| 3321 : area_(area), target_(target) { | 3271 : area_(area), target_(target) {} |
| 3322 } | |
| 3323 | 3272 |
| 3324 PDFiumEngine::MouseDownState::~MouseDownState() { | 3273 PDFiumEngine::MouseDownState::~MouseDownState() {} |
| 3325 } | |
| 3326 | 3274 |
| 3327 void PDFiumEngine::MouseDownState::Set(const PDFiumPage::Area& area, | 3275 void PDFiumEngine::MouseDownState::Set(const PDFiumPage::Area& area, |
| 3328 const PDFiumPage::LinkTarget& target) { | 3276 const PDFiumPage::LinkTarget& target) { |
| 3329 area_ = area; | 3277 area_ = area; |
| 3330 target_ = target; | 3278 target_ = target; |
| 3331 } | 3279 } |
| 3332 | 3280 |
| 3333 void PDFiumEngine::MouseDownState::Reset() { | 3281 void PDFiumEngine::MouseDownState::Reset() { |
| 3334 area_ = PDFiumPage::NONSELECTABLE_AREA; | 3282 area_ = PDFiumPage::NONSELECTABLE_AREA; |
| 3335 target_ = PDFiumPage::LinkTarget(); | 3283 target_ = PDFiumPage::LinkTarget(); |
| 3336 } | 3284 } |
| 3337 | 3285 |
| 3338 bool PDFiumEngine::MouseDownState::Matches( | 3286 bool PDFiumEngine::MouseDownState::Matches( |
| 3339 const PDFiumPage::Area& area, | 3287 const PDFiumPage::Area& area, |
| 3340 const PDFiumPage::LinkTarget& target) const { | 3288 const PDFiumPage::LinkTarget& target) const { |
| 3341 if (area_ != area) | 3289 if (area_ != area) |
| 3342 return false; | 3290 return false; |
| 3343 | 3291 |
| 3344 if (area == PDFiumPage::WEBLINK_AREA) | 3292 if (area == PDFiumPage::WEBLINK_AREA) |
| 3345 return target_.url == target.url; | 3293 return target_.url == target.url; |
| 3346 | 3294 |
| 3347 if (area == PDFiumPage::DOCLINK_AREA) | 3295 if (area == PDFiumPage::DOCLINK_AREA) |
| 3348 return target_.page == target.page; | 3296 return target_.page == target.page; |
| 3349 | 3297 |
| 3350 return true; | 3298 return true; |
| 3351 } | 3299 } |
| 3352 | 3300 |
| 3353 PDFiumEngine::FindTextIndex::FindTextIndex() | 3301 PDFiumEngine::FindTextIndex::FindTextIndex() : valid_(false), index_(0) {} |
| 3354 : valid_(false), index_(0) { | |
| 3355 } | |
| 3356 | 3302 |
| 3357 PDFiumEngine::FindTextIndex::~FindTextIndex() { | 3303 PDFiumEngine::FindTextIndex::~FindTextIndex() {} |
| 3358 } | |
| 3359 | 3304 |
| 3360 void PDFiumEngine::FindTextIndex::Invalidate() { | 3305 void PDFiumEngine::FindTextIndex::Invalidate() { |
| 3361 valid_ = false; | 3306 valid_ = false; |
| 3362 } | 3307 } |
| 3363 | 3308 |
| 3364 size_t PDFiumEngine::FindTextIndex::GetIndex() const { | 3309 size_t PDFiumEngine::FindTextIndex::GetIndex() const { |
| 3365 DCHECK(valid_); | 3310 DCHECK(valid_); |
| 3366 return index_; | 3311 return index_; |
| 3367 } | 3312 } |
| 3368 | 3313 |
| 3369 void PDFiumEngine::FindTextIndex::SetIndex(size_t index) { | 3314 void PDFiumEngine::FindTextIndex::SetIndex(size_t index) { |
| 3370 valid_ = true; | 3315 valid_ = true; |
| 3371 index_ = index; | 3316 index_ = index; |
| 3372 } | 3317 } |
| 3373 | 3318 |
| 3374 size_t PDFiumEngine::FindTextIndex::IncrementIndex() { | 3319 size_t PDFiumEngine::FindTextIndex::IncrementIndex() { |
| 3375 DCHECK(valid_); | 3320 DCHECK(valid_); |
| 3376 return ++index_; | 3321 return ++index_; |
| 3377 } | 3322 } |
| 3378 | 3323 |
| 3379 void PDFiumEngine::DeviceToPage(int page_index, | 3324 void PDFiumEngine::DeviceToPage(int page_index, |
| 3380 float device_x, | 3325 float device_x, |
| 3381 float device_y, | 3326 float device_y, |
| 3382 double* page_x, | 3327 double* page_x, |
| 3383 double* page_y) { | 3328 double* page_y) { |
| 3384 *page_x = *page_y = 0; | 3329 *page_x = *page_y = 0; |
| 3385 int temp_x = static_cast<int>((device_x + position_.x()) / current_zoom_ - | 3330 int temp_x = static_cast<int>((device_x + position_.x()) / current_zoom_ - |
| 3386 pages_[page_index]->rect().x()); | 3331 pages_[page_index]->rect().x()); |
| 3387 int temp_y = static_cast<int>((device_y + position_.y()) / current_zoom_ - | 3332 int temp_y = static_cast<int>((device_y + position_.y()) / current_zoom_ - |
| 3388 pages_[page_index]->rect().y()); | 3333 pages_[page_index]->rect().y()); |
| 3389 FPDF_DeviceToPage( | 3334 FPDF_DeviceToPage(pages_[page_index]->GetPage(), 0, 0, |
| 3390 pages_[page_index]->GetPage(), 0, 0, | 3335 pages_[page_index]->rect().width(), |
| 3391 pages_[page_index]->rect().width(), pages_[page_index]->rect().height(), | 3336 pages_[page_index]->rect().height(), current_rotation_, |
| 3392 current_rotation_, temp_x, temp_y, page_x, page_y); | 3337 temp_x, temp_y, page_x, page_y); |
| 3393 } | 3338 } |
| 3394 | 3339 |
| 3395 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) { | 3340 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) { |
| 3396 for (int page_index : visible_pages_) { | 3341 for (int page_index : visible_pages_) { |
| 3397 if (pages_[page_index]->GetPage() == page) | 3342 if (pages_[page_index]->GetPage() == page) |
| 3398 return page_index; | 3343 return page_index; |
| 3399 } | 3344 } |
| 3400 return -1; | 3345 return -1; |
| 3401 } | 3346 } |
| 3402 | 3347 |
| 3403 void PDFiumEngine::SetCurrentPage(int index) { | 3348 void PDFiumEngine::SetCurrentPage(int index) { |
| 3404 in_flight_visible_page_.reset(); | 3349 in_flight_visible_page_.reset(); |
| 3405 | 3350 |
| 3406 if (index == most_visible_page_ || !form_) | 3351 if (index == most_visible_page_ || !form_) |
| 3407 return; | 3352 return; |
| 3408 | 3353 |
| 3409 if (most_visible_page_ != -1 && called_do_document_action_) { | 3354 if (most_visible_page_ != -1 && called_do_document_action_) { |
| 3410 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); | 3355 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); |
| 3411 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); | 3356 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); |
| 3412 } | 3357 } |
| 3413 most_visible_page_ = index; | 3358 most_visible_page_ = index; |
| 3414 #if defined(OS_LINUX) | 3359 #if defined(OS_LINUX) |
| 3415 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); | 3360 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); |
| 3416 #endif | 3361 #endif |
| 3417 if (most_visible_page_ != -1 && called_do_document_action_) { | 3362 if (most_visible_page_ != -1 && called_do_document_action_) { |
| 3418 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage(); | 3363 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage(); |
| 3419 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); | 3364 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); |
| 3420 } | 3365 } |
| 3421 } | 3366 } |
| 3422 | 3367 |
| 3423 void PDFiumEngine::TransformPDFPageForPrinting( | 3368 void PDFiumEngine::TransformPDFPageForPrinting( |
| 3424 FPDF_PAGE page, | 3369 FPDF_PAGE page, |
| 3425 const PP_PrintSettings_Dev& print_settings) { | 3370 const PP_PrintSettings_Dev& print_settings) { |
| 3426 // Get the source page width and height in points. | 3371 // Get the source page width and height in points. |
| 3427 const double src_page_width = FPDF_GetPageWidth(page); | 3372 const double src_page_width = FPDF_GetPageWidth(page); |
| 3428 const double src_page_height = FPDF_GetPageHeight(page); | 3373 const double src_page_height = FPDF_GetPageHeight(page); |
| 3429 | 3374 |
| 3430 const int src_page_rotation = FPDFPage_GetRotation(page); | 3375 const int src_page_rotation = FPDFPage_GetRotation(page); |
| 3431 const bool fit_to_page = print_settings.print_scaling_option == | 3376 const bool fit_to_page = print_settings.print_scaling_option == |
| 3432 PP_PRINTSCALINGOPTION_FIT_TO_PRINTABLE_AREA; | 3377 PP_PRINTSCALINGOPTION_FIT_TO_PRINTABLE_AREA; |
| 3433 | 3378 |
| 3434 pp::Size page_size(print_settings.paper_size); | 3379 pp::Size page_size(print_settings.paper_size); |
| 3435 pp::Rect content_rect(print_settings.printable_area); | 3380 pp::Rect content_rect(print_settings.printable_area); |
| 3436 const bool rotated = (src_page_rotation % 2 == 1); | 3381 const bool rotated = (src_page_rotation % 2 == 1); |
| 3437 SetPageSizeAndContentRect(rotated, | 3382 SetPageSizeAndContentRect(rotated, src_page_width > src_page_height, |
| 3438 src_page_width > src_page_height, | 3383 &page_size, &content_rect); |
| 3439 &page_size, | |
| 3440 &content_rect); | |
| 3441 | 3384 |
| 3442 // Compute the screen page width and height in points. | 3385 // Compute the screen page width and height in points. |
| 3443 const int actual_page_width = | 3386 const int actual_page_width = |
| 3444 rotated ? page_size.height() : page_size.width(); | 3387 rotated ? page_size.height() : page_size.width(); |
| 3445 const int actual_page_height = | 3388 const int actual_page_height = |
| 3446 rotated ? page_size.width() : page_size.height(); | 3389 rotated ? page_size.width() : page_size.height(); |
| 3447 | 3390 |
| 3448 const gfx::Rect gfx_content_rect(content_rect.x(), | 3391 const gfx::Rect gfx_content_rect(content_rect.x(), content_rect.y(), |
| 3449 content_rect.y(), | 3392 content_rect.width(), content_rect.height()); |
| 3450 content_rect.width(), | 3393 const double scale_factor = |
| 3451 content_rect.height()); | 3394 fit_to_page |
| 3452 const double scale_factor = fit_to_page ? | 3395 ? printing::CalculateScaleFactor(gfx_content_rect, src_page_width, |
| 3453 printing::CalculateScaleFactor( | 3396 src_page_height, rotated) |
| 3454 gfx_content_rect, src_page_width, src_page_height, rotated) : 1.0; | 3397 : 1.0; |
| 3455 | 3398 |
| 3456 // Calculate positions for the clip box. | 3399 // Calculate positions for the clip box. |
| 3457 printing::PdfRectangle media_box; | 3400 printing::PdfRectangle media_box; |
| 3458 printing::PdfRectangle crop_box; | 3401 printing::PdfRectangle crop_box; |
| 3459 bool has_media_box = !!FPDFPage_GetMediaBox(page, | 3402 bool has_media_box = |
| 3460 &media_box.left, | 3403 !!FPDFPage_GetMediaBox(page, &media_box.left, &media_box.bottom, |
| 3461 &media_box.bottom, | 3404 &media_box.right, &media_box.top); |
| 3462 &media_box.right, | 3405 bool has_crop_box = !!FPDFPage_GetCropBox( |
| 3463 &media_box.top); | 3406 page, &crop_box.left, &crop_box.bottom, &crop_box.right, &crop_box.top); |
| 3464 bool has_crop_box = !!FPDFPage_GetCropBox(page, | 3407 printing::CalculateMediaBoxAndCropBox(rotated, has_media_box, has_crop_box, |
| 3465 &crop_box.left, | 3408 &media_box, &crop_box); |
| 3466 &crop_box.bottom, | |
| 3467 &crop_box.right, | |
| 3468 &crop_box.top); | |
| 3469 printing::CalculateMediaBoxAndCropBox( | |
| 3470 rotated, has_media_box, has_crop_box, &media_box, &crop_box); | |
| 3471 printing::PdfRectangle source_clip_box = | 3409 printing::PdfRectangle source_clip_box = |
| 3472 printing::CalculateClipBoxBoundary(media_box, crop_box); | 3410 printing::CalculateClipBoxBoundary(media_box, crop_box); |
| 3473 printing::ScalePdfRectangle(scale_factor, &source_clip_box); | 3411 printing::ScalePdfRectangle(scale_factor, &source_clip_box); |
| 3474 | 3412 |
| 3475 // Calculate the translation offset values. | 3413 // Calculate the translation offset values. |
| 3476 double offset_x = 0; | 3414 double offset_x = 0; |
| 3477 double offset_y = 0; | 3415 double offset_y = 0; |
| 3478 if (fit_to_page) { | 3416 if (fit_to_page) { |
| 3479 printing::CalculateScaledClipBoxOffset( | 3417 printing::CalculateScaledClipBoxOffset(gfx_content_rect, source_clip_box, |
| 3480 gfx_content_rect, source_clip_box, &offset_x, &offset_y); | 3418 &offset_x, &offset_y); |
| 3481 } else { | 3419 } else { |
| 3482 printing::CalculateNonScaledClipBoxOffset( | 3420 printing::CalculateNonScaledClipBoxOffset( |
| 3483 gfx_content_rect, src_page_rotation, | 3421 gfx_content_rect, src_page_rotation, actual_page_width, |
| 3484 actual_page_width, actual_page_height, | 3422 actual_page_height, source_clip_box, &offset_x, &offset_y); |
| 3485 source_clip_box, &offset_x, &offset_y); | |
| 3486 } | 3423 } |
| 3487 | 3424 |
| 3488 // Reset the media box and crop box. When the page has crop box and media box, | 3425 // Reset the media box and crop box. When the page has crop box and media box, |
| 3489 // the plugin will display the crop box contents and not the entire media box. | 3426 // the plugin will display the crop box contents and not the entire media box. |
| 3490 // If the pages have different crop box values, the plugin will display a | 3427 // If the pages have different crop box values, the plugin will display a |
| 3491 // document of multiple page sizes. To give better user experience, we | 3428 // document of multiple page sizes. To give better user experience, we |
| 3492 // decided to have same crop box and media box values. Hence, the user will | 3429 // decided to have same crop box and media box values. Hence, the user will |
| 3493 // see a list of uniform pages. | 3430 // see a list of uniform pages. |
| 3494 FPDFPage_SetMediaBox(page, 0, 0, page_size.width(), page_size.height()); | 3431 FPDFPage_SetMediaBox(page, 0, 0, page_size.width(), page_size.height()); |
| 3495 FPDFPage_SetCropBox(page, 0, 0, page_size.width(), page_size.height()); | 3432 FPDFPage_SetCropBox(page, 0, 0, page_size.width(), page_size.height()); |
| 3496 | 3433 |
| 3497 // Transformation is not required, return. Do this check only after updating | 3434 // Transformation is not required, return. Do this check only after updating |
| 3498 // the media box and crop box. For more detailed information, please refer to | 3435 // the media box and crop box. For more detailed information, please refer to |
| 3499 // the comment block right before FPDF_SetMediaBox and FPDF_GetMediaBox calls. | 3436 // the comment block right before FPDF_SetMediaBox and FPDF_GetMediaBox calls. |
| 3500 if (scale_factor == 1.0 && offset_x == 0 && offset_y == 0) | 3437 if (scale_factor == 1.0 && offset_x == 0 && offset_y == 0) |
| 3501 return; | 3438 return; |
| 3502 | 3439 |
| 3503 | |
| 3504 // All the positions have been calculated, now manipulate the PDF. | 3440 // All the positions have been calculated, now manipulate the PDF. |
| 3505 FS_MATRIX matrix = {static_cast<float>(scale_factor), | 3441 FS_MATRIX matrix = {static_cast<float>(scale_factor), |
| 3506 0, | 3442 0, |
| 3507 0, | 3443 0, |
| 3508 static_cast<float>(scale_factor), | 3444 static_cast<float>(scale_factor), |
| 3509 static_cast<float>(offset_x), | 3445 static_cast<float>(offset_x), |
| 3510 static_cast<float>(offset_y)}; | 3446 static_cast<float>(offset_y)}; |
| 3511 FS_RECTF cliprect = {static_cast<float>(source_clip_box.left+offset_x), | 3447 FS_RECTF cliprect = {static_cast<float>(source_clip_box.left + offset_x), |
| 3512 static_cast<float>(source_clip_box.top+offset_y), | 3448 static_cast<float>(source_clip_box.top + offset_y), |
| 3513 static_cast<float>(source_clip_box.right+offset_x), | 3449 static_cast<float>(source_clip_box.right + offset_x), |
| 3514 static_cast<float>(source_clip_box.bottom+offset_y)}; | 3450 static_cast<float>(source_clip_box.bottom + offset_y)}; |
| 3515 FPDFPage_TransFormWithClip(page, &matrix, &cliprect); | 3451 FPDFPage_TransFormWithClip(page, &matrix, &cliprect); |
| 3516 FPDFPage_TransformAnnots(page, scale_factor, 0, 0, scale_factor, | 3452 FPDFPage_TransformAnnots(page, scale_factor, 0, 0, scale_factor, offset_x, |
| 3517 offset_x, offset_y); | 3453 offset_y); |
| 3518 } | 3454 } |
| 3519 | 3455 |
| 3520 void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc, | 3456 void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc, |
| 3521 const pp::Rect& shadow_rc, | 3457 const pp::Rect& shadow_rc, |
| 3522 const pp::Rect& clip_rc, | 3458 const pp::Rect& clip_rc, |
| 3523 pp::ImageData* image_data) { | 3459 pp::ImageData* image_data) { |
| 3524 pp::Rect page_rect(page_rc); | 3460 pp::Rect page_rect(page_rc); |
| 3525 page_rect.Offset(page_offset_); | 3461 page_rect.Offset(page_offset_); |
| 3526 | 3462 |
| 3527 pp::Rect shadow_rect(shadow_rc); | 3463 pp::Rect shadow_rect(shadow_rc); |
| 3528 shadow_rect.Offset(page_offset_); | 3464 shadow_rect.Offset(page_offset_); |
| 3529 | 3465 |
| 3530 pp::Rect clip_rect(clip_rc); | 3466 pp::Rect clip_rect(clip_rc); |
| 3531 clip_rect.Offset(page_offset_); | 3467 clip_rect.Offset(page_offset_); |
| 3532 | 3468 |
| 3533 // Page drop shadow parameters. | 3469 // Page drop shadow parameters. |
| 3534 const double factor = 0.5; | 3470 const double factor = 0.5; |
| 3535 uint32_t depth = | 3471 uint32_t depth = |
| 3536 std::max(std::max(page_rect.x() - shadow_rect.x(), | 3472 std::max(std::max(page_rect.x() - shadow_rect.x(), |
| 3537 page_rect.y() - shadow_rect.y()), | 3473 page_rect.y() - shadow_rect.y()), |
| 3538 std::max(shadow_rect.right() - page_rect.right(), | 3474 std::max(shadow_rect.right() - page_rect.right(), |
| 3539 shadow_rect.bottom() - page_rect.bottom())); | 3475 shadow_rect.bottom() - page_rect.bottom())); |
| 3540 depth = static_cast<uint32_t>(depth * 1.5) + 1; | 3476 depth = static_cast<uint32_t>(depth * 1.5) + 1; |
| 3541 | 3477 |
| 3542 // We need to check depth only to verify our copy of shadow matrix is correct. | 3478 // We need to check depth only to verify our copy of shadow matrix is correct. |
| 3543 if (!page_shadow_.get() || page_shadow_->depth() != depth) | 3479 if (!page_shadow_.get() || page_shadow_->depth() != depth) |
| 3544 page_shadow_.reset(new ShadowMatrix(depth, factor, | 3480 page_shadow_.reset( |
| 3545 client_->GetBackgroundColor())); | 3481 new ShadowMatrix(depth, factor, client_->GetBackgroundColor())); |
| 3546 | 3482 |
| 3547 DCHECK(!image_data->is_null()); | 3483 DCHECK(!image_data->is_null()); |
| 3548 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_); | 3484 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_); |
| 3549 } | 3485 } |
| 3550 | 3486 |
| 3551 void PDFiumEngine::GetRegion(const pp::Point& location, | 3487 void PDFiumEngine::GetRegion(const pp::Point& location, |
| 3552 pp::ImageData* image_data, | 3488 pp::ImageData* image_data, |
| 3553 void** region, | 3489 void** region, |
| 3554 int* stride) const { | 3490 int* stride) const { |
| 3555 if (image_data->is_null()) { | 3491 if (image_data->is_null()) { |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3822 } | 3758 } |
| 3823 | 3759 |
| 3824 int PDFiumEngine::Form_Response(IPDF_JSPLATFORM* param, | 3760 int PDFiumEngine::Form_Response(IPDF_JSPLATFORM* param, |
| 3825 FPDF_WIDESTRING question, | 3761 FPDF_WIDESTRING question, |
| 3826 FPDF_WIDESTRING title, | 3762 FPDF_WIDESTRING title, |
| 3827 FPDF_WIDESTRING default_response, | 3763 FPDF_WIDESTRING default_response, |
| 3828 FPDF_WIDESTRING label, | 3764 FPDF_WIDESTRING label, |
| 3829 FPDF_BOOL password, | 3765 FPDF_BOOL password, |
| 3830 void* response, | 3766 void* response, |
| 3831 int length) { | 3767 int length) { |
| 3832 std::string question_str = base::UTF16ToUTF8( | 3768 std::string question_str = |
| 3833 reinterpret_cast<const base::char16*>(question)); | 3769 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(question)); |
| 3834 std::string default_str = base::UTF16ToUTF8( | 3770 std::string default_str = base::UTF16ToUTF8( |
| 3835 reinterpret_cast<const base::char16*>(default_response)); | 3771 reinterpret_cast<const base::char16*>(default_response)); |
| 3836 | 3772 |
| 3837 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3773 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3838 std::string rv = engine->client_->Prompt(question_str, default_str); | 3774 std::string rv = engine->client_->Prompt(question_str, default_str); |
| 3839 base::string16 rv_16 = base::UTF8ToUTF16(rv); | 3775 base::string16 rv_16 = base::UTF8ToUTF16(rv); |
| 3840 int rv_bytes = rv_16.size() * sizeof(base::char16); | 3776 int rv_bytes = rv_16.size() * sizeof(base::char16); |
| 3841 if (response) { | 3777 if (response) { |
| 3842 int bytes_to_copy = rv_bytes < length ? rv_bytes : length; | 3778 int bytes_to_copy = rv_bytes < length ? rv_bytes : length; |
| 3843 memcpy(response, rv_16.c_str(), bytes_to_copy); | 3779 memcpy(response, rv_16.c_str(), bytes_to_copy); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3899 void PDFiumEngine::Form_SubmitForm(IPDF_JSPLATFORM* param, | 3835 void PDFiumEngine::Form_SubmitForm(IPDF_JSPLATFORM* param, |
| 3900 void* form_data, | 3836 void* form_data, |
| 3901 int length, | 3837 int length, |
| 3902 FPDF_WIDESTRING url) { | 3838 FPDF_WIDESTRING url) { |
| 3903 std::string url_str = | 3839 std::string url_str = |
| 3904 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 3840 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); |
| 3905 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3841 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3906 engine->client_->SubmitForm(url_str, form_data, length); | 3842 engine->client_->SubmitForm(url_str, form_data, length); |
| 3907 } | 3843 } |
| 3908 | 3844 |
| 3909 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, | 3845 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, int page_number) { |
| 3910 int page_number) { | |
| 3911 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3846 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3912 engine->ScrollToPage(page_number); | 3847 engine->ScrollToPage(page_number); |
| 3913 } | 3848 } |
| 3914 | 3849 |
| 3915 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, | 3850 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, |
| 3916 void* file_path, | 3851 void* file_path, |
| 3917 int length) { | 3852 int length) { |
| 3918 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3853 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3919 std::string path = engine->client_->ShowFileSelectionDialog(); | 3854 std::string path = engine->client_->ShowFileSelectionDialog(); |
| 3920 if (path.size() + 1 <= static_cast<size_t>(length)) | 3855 if (path.size() + 1 <= static_cast<size_t>(length)) |
| 3921 memcpy(file_path, &path[0], path.size() + 1); | 3856 memcpy(file_path, &path[0], path.size() + 1); |
| 3922 return path.size() + 1; | 3857 return path.size() + 1; |
| 3923 } | 3858 } |
| 3924 | 3859 |
| 3925 FPDF_BOOL PDFiumEngine::Pause_NeedToPauseNow(IFSDK_PAUSE* param) { | 3860 FPDF_BOOL PDFiumEngine::Pause_NeedToPauseNow(IFSDK_PAUSE* param) { |
| 3926 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3861 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3927 return (base::Time::Now() - engine->last_progressive_start_time_). | 3862 return (base::Time::Now() - engine->last_progressive_start_time_) |
| 3928 InMilliseconds() > engine->progressive_paint_timeout_; | 3863 .InMilliseconds() > engine->progressive_paint_timeout_; |
| 3929 } | 3864 } |
| 3930 | 3865 |
| 3931 ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine) | 3866 ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine) |
| 3932 : old_engine_(g_engine_for_unsupported) { | 3867 : old_engine_(g_engine_for_unsupported) { |
| 3933 g_engine_for_unsupported = engine; | 3868 g_engine_for_unsupported = engine; |
| 3934 } | 3869 } |
| 3935 | 3870 |
| 3936 ScopedUnsupportedFeature::~ScopedUnsupportedFeature() { | 3871 ScopedUnsupportedFeature::~ScopedUnsupportedFeature() { |
| 3937 g_engine_for_unsupported = old_engine_; | 3872 g_engine_for_unsupported = old_engine_; |
| 3938 } | 3873 } |
| 3939 | 3874 |
| 3940 ScopedSubstFont::ScopedSubstFont(PDFiumEngine* engine) | 3875 ScopedSubstFont::ScopedSubstFont(PDFiumEngine* engine) |
| 3941 : old_engine_(g_engine_for_fontmapper) { | 3876 : old_engine_(g_engine_for_fontmapper) { |
| 3942 g_engine_for_fontmapper = engine; | 3877 g_engine_for_fontmapper = engine; |
| 3943 } | 3878 } |
| 3944 | 3879 |
| 3945 ScopedSubstFont::~ScopedSubstFont() { | 3880 ScopedSubstFont::~ScopedSubstFont() { |
| 3946 g_engine_for_fontmapper = old_engine_; | 3881 g_engine_for_fontmapper = old_engine_; |
| 3947 } | 3882 } |
| 3948 | 3883 |
| 3949 namespace { | 3884 namespace { |
| 3950 | 3885 |
| 3951 base::LazyInstance<PDFiumEngineExports>::Leaky g_pdf_engine_exports = | 3886 base::LazyInstance<PDFiumEngineExports>::Leaky g_pdf_engine_exports = |
| 3952 LAZY_INSTANCE_INITIALIZER; | 3887 LAZY_INSTANCE_INITIALIZER; |
| 3953 | 3888 |
| 3954 int CalculatePosition(FPDF_PAGE page, | 3889 int CalculatePosition(FPDF_PAGE page, |
| 3955 const PDFiumEngineExports::RenderingSettings& settings, | 3890 const PDFiumEngineExports::RenderingSettings& settings, |
| 3956 pp::Rect* dest) { | 3891 pp::Rect* dest) { |
| 3957 int page_width = static_cast<int>(ConvertUnitDouble(FPDF_GetPageWidth(page), | 3892 int page_width = static_cast<int>(ConvertUnitDouble( |
| 3958 kPointsPerInch, | 3893 FPDF_GetPageWidth(page), kPointsPerInch, settings.dpi_x)); |
| 3959 settings.dpi_x)); | 3894 int page_height = static_cast<int>(ConvertUnitDouble( |
| 3960 int page_height = static_cast<int>(ConvertUnitDouble(FPDF_GetPageHeight(page), | 3895 FPDF_GetPageHeight(page), kPointsPerInch, settings.dpi_y)); |
| 3961 kPointsPerInch, | |
| 3962 settings.dpi_y)); | |
| 3963 | 3896 |
| 3964 // Start by assuming that we will draw exactly to the bounds rect | 3897 // Start by assuming that we will draw exactly to the bounds rect |
| 3965 // specified. | 3898 // specified. |
| 3966 *dest = settings.bounds; | 3899 *dest = settings.bounds; |
| 3967 | 3900 |
| 3968 int rotate = 0; // normal orientation. | 3901 int rotate = 0; // normal orientation. |
| 3969 | 3902 |
| 3970 // Auto-rotate landscape pages to print correctly. | 3903 // Auto-rotate landscape pages to print correctly. |
| 3971 if (settings.autorotate && | 3904 if (settings.autorotate && |
| 3972 (dest->width() > dest->height()) != (page_width > page_height)) { | 3905 (dest->width() > dest->height()) != (page_width > page_height)) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4073 settings.bounds.y() + settings.bounds.height()); | 4006 settings.bounds.y() + settings.bounds.height()); |
| 4074 | 4007 |
| 4075 // A "temporary" hack. Some PDFs seems to render very slowly if | 4008 // A "temporary" hack. Some PDFs seems to render very slowly if |
| 4076 // FPDF_RenderPage() is directly used on a printer DC. I suspect it is | 4009 // FPDF_RenderPage() is directly used on a printer DC. I suspect it is |
| 4077 // because of the code to talk Postscript directly to the printer if | 4010 // because of the code to talk Postscript directly to the printer if |
| 4078 // the printer supports this. Need to discuss this with PDFium. For now, | 4011 // the printer supports this. Need to discuss this with PDFium. For now, |
| 4079 // render to a bitmap and then blit the bitmap to the DC if we have been | 4012 // render to a bitmap and then blit the bitmap to the DC if we have been |
| 4080 // supplied a printer DC. | 4013 // supplied a printer DC. |
| 4081 int device_type = GetDeviceCaps(dc, TECHNOLOGY); | 4014 int device_type = GetDeviceCaps(dc, TECHNOLOGY); |
| 4082 if (device_type == DT_RASPRINTER || device_type == DT_PLOTTER) { | 4015 if (device_type == DT_RASPRINTER || device_type == DT_PLOTTER) { |
| 4083 FPDF_BITMAP bitmap = FPDFBitmap_Create(dest.width(), dest.height(), | 4016 FPDF_BITMAP bitmap = |
| 4084 FPDFBitmap_BGRx); | 4017 FPDFBitmap_Create(dest.width(), dest.height(), FPDFBitmap_BGRx); |
| 4085 // Clear the bitmap | 4018 // Clear the bitmap |
| 4086 FPDFBitmap_FillRect(bitmap, 0, 0, dest.width(), dest.height(), 0xFFFFFFFF); | 4019 FPDFBitmap_FillRect(bitmap, 0, 0, dest.width(), dest.height(), 0xFFFFFFFF); |
| 4087 FPDF_RenderPageBitmap( | 4020 FPDF_RenderPageBitmap(bitmap, page, 0, 0, dest.width(), dest.height(), |
| 4088 bitmap, page, 0, 0, dest.width(), dest.height(), rotate, | 4021 rotate, FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 4089 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); | |
| 4090 int stride = FPDFBitmap_GetStride(bitmap); | 4022 int stride = FPDFBitmap_GetStride(bitmap); |
| 4091 BITMAPINFO bmi; | 4023 BITMAPINFO bmi; |
| 4092 memset(&bmi, 0, sizeof(bmi)); | 4024 memset(&bmi, 0, sizeof(bmi)); |
| 4093 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | 4025 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 4094 bmi.bmiHeader.biWidth = dest.width(); | 4026 bmi.bmiHeader.biWidth = dest.width(); |
| 4095 bmi.bmiHeader.biHeight = -dest.height(); // top-down image | 4027 bmi.bmiHeader.biHeight = -dest.height(); // top-down image |
| 4096 bmi.bmiHeader.biPlanes = 1; | 4028 bmi.bmiHeader.biPlanes = 1; |
| 4097 bmi.bmiHeader.biBitCount = 32; | 4029 bmi.bmiHeader.biBitCount = 32; |
| 4098 bmi.bmiHeader.biCompression = BI_RGB; | 4030 bmi.bmiHeader.biCompression = BI_RGB; |
| 4099 bmi.bmiHeader.biSizeImage = stride * dest.height(); | 4031 bmi.bmiHeader.biSizeImage = stride * dest.height(); |
| 4100 StretchDIBits(dc, dest.x(), dest.y(), dest.width(), dest.height(), | 4032 StretchDIBits(dc, dest.x(), dest.y(), dest.width(), dest.height(), 0, 0, |
| 4101 0, 0, dest.width(), dest.height(), | 4033 dest.width(), dest.height(), FPDFBitmap_GetBuffer(bitmap), |
| 4102 FPDFBitmap_GetBuffer(bitmap), &bmi, DIB_RGB_COLORS, SRCCOPY); | 4034 &bmi, DIB_RGB_COLORS, SRCCOPY); |
| 4103 FPDFBitmap_Destroy(bitmap); | 4035 FPDFBitmap_Destroy(bitmap); |
| 4104 } else { | 4036 } else { |
| 4105 FPDF_RenderPage(dc, page, dest.x(), dest.y(), dest.width(), dest.height(), | 4037 FPDF_RenderPage(dc, page, dest.x(), dest.y(), dest.width(), dest.height(), |
| 4106 rotate, FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); | 4038 rotate, FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 4107 } | 4039 } |
| 4108 RestoreDC(dc, save_state); | 4040 RestoreDC(dc, save_state); |
| 4109 FPDF_ClosePage(page); | 4041 FPDF_ClosePage(page); |
| 4110 FPDF_CloseDocument(doc); | 4042 FPDF_CloseDocument(doc); |
| 4111 return true; | 4043 return true; |
| 4112 } | 4044 } |
| 4113 | 4045 |
| 4114 void PDFiumEngineExports::SetPDFEnsureTypefaceCharactersAccessible( | 4046 void PDFiumEngineExports::SetPDFEnsureTypefaceCharactersAccessible( |
| 4115 PDFEnsureTypefaceCharactersAccessible func) { | 4047 PDFEnsureTypefaceCharactersAccessible func) { |
| 4116 FPDF_SetTypefaceAccessibleFunc( | 4048 FPDF_SetTypefaceAccessibleFunc( |
| 4117 reinterpret_cast<PDFiumEnsureTypefaceCharactersAccessible>(func)); | 4049 reinterpret_cast<PDFiumEnsureTypefaceCharactersAccessible>(func)); |
| 4118 } | 4050 } |
| 4119 | 4051 |
| 4120 void PDFiumEngineExports::SetPDFUseGDIPrinting(bool enable) { | 4052 void PDFiumEngineExports::SetPDFUseGDIPrinting(bool enable) { |
| 4121 FPDF_SetPrintTextWithGDI(enable); | 4053 FPDF_SetPrintTextWithGDI(enable); |
| 4122 } | 4054 } |
| 4123 | 4055 |
| 4124 void PDFiumEngineExports::SetPDFPostscriptPrintingLevel( | 4056 void PDFiumEngineExports::SetPDFPostscriptPrintingLevel(int postscript_level) { |
| 4125 int postscript_level) { | |
| 4126 FPDF_SetPrintPostscriptLevel(postscript_level); | 4057 FPDF_SetPrintPostscriptLevel(postscript_level); |
| 4127 } | 4058 } |
| 4128 | 4059 |
| 4129 #endif // defined(OS_WIN) | 4060 #endif // defined(OS_WIN) |
| 4130 | 4061 |
| 4131 bool PDFiumEngineExports::RenderPDFPageToBitmap( | 4062 bool PDFiumEngineExports::RenderPDFPageToBitmap( |
| 4132 const void* pdf_buffer, | 4063 const void* pdf_buffer, |
| 4133 int pdf_buffer_size, | 4064 int pdf_buffer_size, |
| 4134 int page_number, | 4065 int page_number, |
| 4135 const RenderingSettings& settings, | 4066 const RenderingSettings& settings, |
| 4136 void* bitmap_buffer) { | 4067 void* bitmap_buffer) { |
| 4137 FPDF_DOCUMENT doc = | 4068 FPDF_DOCUMENT doc = |
| 4138 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4069 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 4139 if (!doc) | 4070 if (!doc) |
| 4140 return false; | 4071 return false; |
| 4141 FPDF_PAGE page = FPDF_LoadPage(doc, page_number); | 4072 FPDF_PAGE page = FPDF_LoadPage(doc, page_number); |
| 4142 if (!page) { | 4073 if (!page) { |
| 4143 FPDF_CloseDocument(doc); | 4074 FPDF_CloseDocument(doc); |
| 4144 return false; | 4075 return false; |
| 4145 } | 4076 } |
| 4146 | 4077 |
| 4147 pp::Rect dest; | 4078 pp::Rect dest; |
| 4148 int rotate = CalculatePosition(page, settings, &dest); | 4079 int rotate = CalculatePosition(page, settings, &dest); |
| 4149 | 4080 |
| 4150 FPDF_BITMAP bitmap = | 4081 FPDF_BITMAP bitmap = FPDFBitmap_CreateEx( |
| 4151 FPDFBitmap_CreateEx(settings.bounds.width(), settings.bounds.height(), | 4082 settings.bounds.width(), settings.bounds.height(), FPDFBitmap_BGRA, |
| 4152 FPDFBitmap_BGRA, bitmap_buffer, | 4083 bitmap_buffer, settings.bounds.width() * 4); |
| 4153 settings.bounds.width() * 4); | |
| 4154 // Clear the bitmap | 4084 // Clear the bitmap |
| 4155 FPDFBitmap_FillRect(bitmap, 0, 0, settings.bounds.width(), | 4085 FPDFBitmap_FillRect(bitmap, 0, 0, settings.bounds.width(), |
| 4156 settings.bounds.height(), 0xFFFFFFFF); | 4086 settings.bounds.height(), 0xFFFFFFFF); |
| 4157 // Shift top-left corner of bounds to (0, 0) if it's not there. | 4087 // Shift top-left corner of bounds to (0, 0) if it's not there. |
| 4158 dest.set_point(dest.point() - settings.bounds.point()); | 4088 dest.set_point(dest.point() - settings.bounds.point()); |
| 4159 FPDF_RenderPageBitmap( | 4089 FPDF_RenderPageBitmap(bitmap, page, dest.x(), dest.y(), dest.width(), |
| 4160 bitmap, page, dest.x(), dest.y(), dest.width(), dest.height(), rotate, | 4090 dest.height(), rotate, |
| 4161 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); | 4091 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 4162 FPDFBitmap_Destroy(bitmap); | 4092 FPDFBitmap_Destroy(bitmap); |
| 4163 FPDF_ClosePage(page); | 4093 FPDF_ClosePage(page); |
| 4164 FPDF_CloseDocument(doc); | 4094 FPDF_CloseDocument(doc); |
| 4165 return true; | 4095 return true; |
| 4166 } | 4096 } |
| 4167 | 4097 |
| 4168 bool PDFiumEngineExports::GetPDFDocInfo(const void* pdf_buffer, | 4098 bool PDFiumEngineExports::GetPDFDocInfo(const void* pdf_buffer, |
| 4169 int buffer_size, | 4099 int buffer_size, |
| 4170 int* page_count, | 4100 int* page_count, |
| 4171 double* max_page_width) { | 4101 double* max_page_width) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4199 FPDF_DOCUMENT doc = | 4129 FPDF_DOCUMENT doc = |
| 4200 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4130 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 4201 if (!doc) | 4131 if (!doc) |
| 4202 return false; | 4132 return false; |
| 4203 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4133 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 4204 FPDF_CloseDocument(doc); | 4134 FPDF_CloseDocument(doc); |
| 4205 return success; | 4135 return success; |
| 4206 } | 4136 } |
| 4207 | 4137 |
| 4208 } // namespace chrome_pdf | 4138 } // namespace chrome_pdf |
| OLD | NEW |