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

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

Issue 2398763002: Add font substitution metric for Linux (Closed)
Patch Set: No ScopedSubstFont in PDFiumEngineExports Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | pdf/pdfium/pdfium_page.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "pdf/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // adding too much latency to the display of the final image when the user 103 // adding too much latency to the display of the final image when the user
104 // stops scrolling. 104 // stops scrolling.
105 // Setting a higher value has minimal benefit (scrolling at less than 4 fps will 105 // Setting a higher value has minimal benefit (scrolling at less than 4 fps will
106 // never be a great experience) and there is some cost, since when the user 106 // never be a great experience) and there is some cost, since when the user
107 // stops scrolling the in-progress painting has to complete or timeout before 107 // stops scrolling the in-progress painting has to complete or timeout before
108 // the final painting can start. 108 // the final painting can start.
109 // The scrollbar will always be responsive since it is managed by a separate 109 // The scrollbar will always be responsive since it is managed by a separate
110 // process. 110 // process.
111 const int32_t kMaxInitialProgressivePaintTimeMs = 250; 111 const int32_t kMaxInitialProgressivePaintTimeMs = 250;
112 112
113 PDFiumEngine* g_engine_for_fontmapper = nullptr;
114
113 std::vector<uint32_t> GetPageNumbersFromPrintPageNumberRange( 115 std::vector<uint32_t> GetPageNumbersFromPrintPageNumberRange(
114 const PP_PrintPageNumberRange_Dev* page_ranges, 116 const PP_PrintPageNumberRange_Dev* page_ranges,
115 uint32_t page_range_count) { 117 uint32_t page_range_count) {
116 std::vector<uint32_t> page_numbers; 118 std::vector<uint32_t> page_numbers;
117 for (uint32_t index = 0; index < page_range_count; ++index) { 119 for (uint32_t index = 0; index < page_range_count; ++index) {
118 for (uint32_t page_number = page_ranges[index].first_page_number; 120 for (uint32_t page_number = page_ranges[index].first_page_number;
119 page_number <= page_ranges[index].last_page_number; ++page_number) { 121 page_number <= page_ranges[index].last_page_number; ++page_number) {
120 page_numbers.push_back(page_number); 122 page_numbers.push_back(page_number);
121 } 123 }
122 } 124 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 description.set_face(face_utf8); 254 description.set_face(face_utf8);
253 description.set_weight(WeightToBrowserFontTrustedWeight(weight)); 255 description.set_weight(WeightToBrowserFontTrustedWeight(weight));
254 description.set_italic(italic > 0); 256 description.set_italic(italic > 0);
255 } 257 }
256 258
257 if (!pp::PDF::IsAvailable()) { 259 if (!pp::PDF::IsAvailable()) {
258 NOTREACHED(); 260 NOTREACHED();
259 return nullptr; 261 return nullptr;
260 } 262 }
261 263
264 if (g_engine_for_fontmapper)
265 g_engine_for_fontmapper->FontSubstituted();
266
262 PP_Resource font_resource = pp::PDF::GetFontFileWithFallback( 267 PP_Resource font_resource = pp::PDF::GetFontFileWithFallback(
263 pp::InstanceHandle(g_last_instance_id), 268 pp::InstanceHandle(g_last_instance_id),
264 &description.pp_font_description(), 269 &description.pp_font_description(),
265 static_cast<PP_PrivateFontCharset>(charset)); 270 static_cast<PP_PrivateFontCharset>(charset));
266 long res_id = font_resource; 271 long res_id = font_resource;
267 return reinterpret_cast<void*>(res_id); 272 return reinterpret_cast<void*>(res_id);
268 } 273 }
269 274
270 unsigned long GetFontData(struct _FPDF_SYSFONTINFO*, void* font_id, 275 unsigned long GetFontData(struct _FPDF_SYSFONTINFO*, void* font_id,
271 unsigned int table, unsigned char* buffer, 276 unsigned int table, unsigned char* buffer,
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA: 1169 case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA:
1165 feature = "Screen"; 1170 feature = "Screen";
1166 break; 1171 break;
1167 case FPDF_UNSP_ANNOT_SIG: 1172 case FPDF_UNSP_ANNOT_SIG:
1168 feature = "Digital_Signature"; 1173 feature = "Digital_Signature";
1169 break; 1174 break;
1170 } 1175 }
1171 client_->DocumentHasUnsupportedFeature(feature); 1176 client_->DocumentHasUnsupportedFeature(feature);
1172 } 1177 }
1173 1178
1179 void PDFiumEngine::FontSubstituted() {
1180 client_->FontSubstituted();
1181 }
1182
1174 void PDFiumEngine::ContinueFind(int32_t result) { 1183 void PDFiumEngine::ContinueFind(int32_t result) {
1175 StartFind(current_find_text_, result != 0); 1184 StartFind(current_find_text_, result != 0);
1176 } 1185 }
1177 1186
1178 bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) { 1187 bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) {
1179 DCHECK(!defer_page_unload_); 1188 DCHECK(!defer_page_unload_);
1180 defer_page_unload_ = true; 1189 defer_page_unload_ = true;
1181 bool rv = false; 1190 bool rv = false;
1182 switch (event.GetType()) { 1191 switch (event.GetType()) {
1183 case PP_INPUTEVENT_TYPE_MOUSEDOWN: 1192 case PP_INPUTEVENT_TYPE_MOUSEDOWN:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 return PP_PRINTOUTPUTFORMAT_PDF; 1225 return PP_PRINTOUTPUTFORMAT_PDF;
1217 } 1226 }
1218 1227
1219 void PDFiumEngine::PrintBegin() { 1228 void PDFiumEngine::PrintBegin() {
1220 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WP); 1229 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WP);
1221 } 1230 }
1222 1231
1223 pp::Resource PDFiumEngine::PrintPages( 1232 pp::Resource PDFiumEngine::PrintPages(
1224 const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count, 1233 const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count,
1225 const PP_PrintSettings_Dev& print_settings) { 1234 const PP_PrintSettings_Dev& print_settings) {
1235 ScopedSubstFont scoped_subst_font(this);
1226 if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) 1236 if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY))
1227 return PrintPagesAsPDF(page_ranges, page_range_count, print_settings); 1237 return PrintPagesAsPDF(page_ranges, page_range_count, print_settings);
1228 else if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) 1238 else if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY))
1229 return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings); 1239 return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings);
1230 return pp::Resource(); 1240 return pp::Resource();
1231 } 1241 }
1232 1242
1233 FPDF_DOCUMENT PDFiumEngine::CreateSinglePageRasterPdf( 1243 FPDF_DOCUMENT PDFiumEngine::CreateSinglePageRasterPdf(
1234 double source_page_width, 1244 double source_page_width,
1235 double source_page_height, 1245 double source_page_height,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); 1378 FitContentsToPrintableAreaIfRequired(output_doc, print_settings);
1369 // Now flatten all the output pages. 1379 // Now flatten all the output pages.
1370 buffer = GetFlattenedPrintData(output_doc); 1380 buffer = GetFlattenedPrintData(output_doc);
1371 } 1381 }
1372 FPDF_CloseDocument(output_doc); 1382 FPDF_CloseDocument(output_doc);
1373 return buffer; 1383 return buffer;
1374 } 1384 }
1375 1385
1376 pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) { 1386 pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) {
1377 pp::Buffer_Dev buffer; 1387 pp::Buffer_Dev buffer;
1388 ScopedSubstFont scoped_subst_font(this);
1378 int page_count = FPDF_GetPageCount(doc); 1389 int page_count = FPDF_GetPageCount(doc);
1379 for (int i = 0; i < page_count; ++i) { 1390 for (int i = 0; i < page_count; ++i) {
1380 FPDF_PAGE page = FPDF_LoadPage(doc, i); 1391 FPDF_PAGE page = FPDF_LoadPage(doc, i);
1381 DCHECK(page); 1392 DCHECK(page);
1382 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT); 1393 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT);
1383 FPDF_ClosePage(page); 1394 FPDF_ClosePage(page);
1384 if (flatten_ret == FLATTEN_FAIL) 1395 if (flatten_ret == FLATTEN_FAIL)
1385 return buffer; 1396 return buffer;
1386 } 1397 }
1387 1398
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
2446 !FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_)) { 2457 !FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_)) {
2447 return; 2458 return;
2448 } 2459 }
2449 2460
2450 // If we're in the middle of getting a password, just return. We will retry 2461 // If we're in the middle of getting a password, just return. We will retry
2451 // loading the document after we get the password anyway. 2462 // loading the document after we get the password anyway.
2452 if (getting_password_) 2463 if (getting_password_)
2453 return; 2464 return;
2454 2465
2455 ScopedUnsupportedFeature scoped_unsupported_feature(this); 2466 ScopedUnsupportedFeature scoped_unsupported_feature(this);
2467 ScopedSubstFont scoped_subst_font(this);
2456 bool needs_password = false; 2468 bool needs_password = false;
2457 if (TryLoadingDoc(std::string(), &needs_password)) { 2469 if (TryLoadingDoc(std::string(), &needs_password)) {
2458 ContinueLoadingDocument(std::string()); 2470 ContinueLoadingDocument(std::string());
2459 return; 2471 return;
2460 } 2472 }
2461 if (needs_password) 2473 if (needs_password)
2462 GetPasswordAndLoad(); 2474 GetPasswordAndLoad();
2463 else 2475 else
2464 client_->DocumentLoadFailed(); 2476 client_->DocumentLoadFailed();
2465 } 2477 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2510 getting_password_ = false; 2522 getting_password_ = false;
2511 2523
2512 std::string password_text; 2524 std::string password_text;
2513 if (result == PP_OK && password.is_string()) 2525 if (result == PP_OK && password.is_string())
2514 password_text = password.AsString(); 2526 password_text = password.AsString();
2515 ContinueLoadingDocument(password_text); 2527 ContinueLoadingDocument(password_text);
2516 } 2528 }
2517 2529
2518 void PDFiumEngine::ContinueLoadingDocument(const std::string& password) { 2530 void PDFiumEngine::ContinueLoadingDocument(const std::string& password) {
2519 ScopedUnsupportedFeature scoped_unsupported_feature(this); 2531 ScopedUnsupportedFeature scoped_unsupported_feature(this);
2532 ScopedSubstFont scoped_subst_font(this);
2520 2533
2521 bool needs_password = false; 2534 bool needs_password = false;
2522 bool loaded = TryLoadingDoc(password, &needs_password); 2535 bool loaded = TryLoadingDoc(password, &needs_password);
2523 bool password_incorrect = !loaded && needs_password && !password.empty(); 2536 bool password_incorrect = !loaded && needs_password && !password.empty();
2524 if (password_incorrect && password_tries_remaining_ > 0) { 2537 if (password_incorrect && password_tries_remaining_ > 0) {
2525 GetPasswordAndLoad(); 2538 GetPasswordAndLoad();
2526 return; 2539 return;
2527 } 2540 }
2528 2541
2529 if (!doc_) { 2542 if (!doc_) {
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
3726 3739
3727 ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine) 3740 ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine)
3728 : old_engine_(g_engine_for_unsupported) { 3741 : old_engine_(g_engine_for_unsupported) {
3729 g_engine_for_unsupported = engine; 3742 g_engine_for_unsupported = engine;
3730 } 3743 }
3731 3744
3732 ScopedUnsupportedFeature::~ScopedUnsupportedFeature() { 3745 ScopedUnsupportedFeature::~ScopedUnsupportedFeature() {
3733 g_engine_for_unsupported = old_engine_; 3746 g_engine_for_unsupported = old_engine_;
3734 } 3747 }
3735 3748
3749 ScopedSubstFont::ScopedSubstFont(PDFiumEngine* engine)
3750 : old_engine_(g_engine_for_fontmapper) {
3751 g_engine_for_fontmapper = engine;
3752 }
3753
3754 ScopedSubstFont::~ScopedSubstFont() {
3755 g_engine_for_fontmapper = old_engine_;
3756 }
3757
3736 namespace { 3758 namespace {
3737 3759
3738 base::LazyInstance<PDFiumEngineExports>::Leaky g_pdf_engine_exports = 3760 base::LazyInstance<PDFiumEngineExports>::Leaky g_pdf_engine_exports =
3739 LAZY_INSTANCE_INITIALIZER; 3761 LAZY_INSTANCE_INITIALIZER;
3740 3762
3741 int CalculatePosition(FPDF_PAGE page, 3763 int CalculatePosition(FPDF_PAGE page,
3742 const PDFiumEngineExports::RenderingSettings& settings, 3764 const PDFiumEngineExports::RenderingSettings& settings,
3743 pp::Rect* dest) { 3765 pp::Rect* dest) {
3744 int page_width = static_cast<int>(ConvertUnitDouble(FPDF_GetPageWidth(page), 3766 int page_width = static_cast<int>(ConvertUnitDouble(FPDF_GetPageWidth(page),
3745 kPointsPerInch, 3767 kPointsPerInch,
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
3981 FPDF_DOCUMENT doc = 4003 FPDF_DOCUMENT doc =
3982 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 4004 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3983 if (!doc) 4005 if (!doc)
3984 return false; 4006 return false;
3985 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4007 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3986 FPDF_CloseDocument(doc); 4008 FPDF_CloseDocument(doc);
3987 return success; 4009 return success;
3988 } 4010 }
3989 4011
3990 } // namespace chrome_pdf 4012 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | pdf/pdfium/pdfium_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698