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

Unified Diff: pdf/pdfium/pdfium_engine.cc

Issue 2398763002: Add font substitution metric for Linux (Closed)
Patch Set: Restore spacing 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 side-by-side diff with in-line comments
Download patch
Index: pdf/pdfium/pdfium_engine.cc
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc
index 878ee20a7c325e6ac076a520d5db86af9c4b9ba4..959d0f6bc6db12a4b6ebb58ba8f4a86f25411558 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -110,6 +110,8 @@ const int32_t kMaxProgressivePaintTimeMs = 300;
// process.
const int32_t kMaxInitialProgressivePaintTimeMs = 250;
+PDFiumEngine* g_engine_for_fontmapper = nullptr;
+
std::vector<uint32_t> GetPageNumbersFromPrintPageNumberRange(
const PP_PrintPageNumberRange_Dev* page_ranges,
uint32_t page_range_count) {
@@ -259,6 +261,9 @@ void* MapFont(struct _FPDF_SYSFONTINFO*, int weight, int italic,
return nullptr;
}
+ if (g_engine_for_fontmapper)
+ g_engine_for_fontmapper->FontSubstituted();
+
PP_Resource font_resource = pp::PDF::GetFontFileWithFallback(
pp::InstanceHandle(g_last_instance_id),
&description.pp_font_description(),
@@ -1171,6 +1176,10 @@ void PDFiumEngine::UnsupportedFeature(int type) {
client_->DocumentHasUnsupportedFeature(feature);
}
+void PDFiumEngine::FontSubstituted() {
+ client_->FontSubstituted();
+}
+
void PDFiumEngine::ContinueFind(int32_t result) {
StartFind(current_find_text_, result != 0);
}
@@ -1223,6 +1232,7 @@ void PDFiumEngine::PrintBegin() {
pp::Resource PDFiumEngine::PrintPages(
const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count,
const PP_PrintSettings_Dev& print_settings) {
+ ScopedSubstFont scoped_subst_font(this);
if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY))
return PrintPagesAsPDF(page_ranges, page_range_count, print_settings);
else if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY))
@@ -1375,6 +1385,7 @@ pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPDF(
pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) {
pp::Buffer_Dev buffer;
+ ScopedSubstFont scoped_subst_font(this);
int page_count = FPDF_GetPageCount(doc);
for (int i = 0; i < page_count; ++i) {
FPDF_PAGE page = FPDF_LoadPage(doc, i);
@@ -2453,6 +2464,7 @@ void PDFiumEngine::LoadDocument() {
return;
ScopedUnsupportedFeature scoped_unsupported_feature(this);
+ ScopedSubstFont scoped_subst_font(this);
bool needs_password = false;
if (TryLoadingDoc(std::string(), &needs_password)) {
ContinueLoadingDocument(std::string());
@@ -2517,6 +2529,7 @@ void PDFiumEngine::OnGetPasswordComplete(int32_t result,
void PDFiumEngine::ContinueLoadingDocument(const std::string& password) {
ScopedUnsupportedFeature scoped_unsupported_feature(this);
+ ScopedSubstFont scoped_subst_font(this);
bool needs_password = false;
bool loaded = TryLoadingDoc(password, &needs_password);
@@ -3733,6 +3746,15 @@ ScopedUnsupportedFeature::~ScopedUnsupportedFeature() {
g_engine_for_unsupported = old_engine_;
}
+ScopedSubstFont::ScopedSubstFont(PDFiumEngine* engine)
+ : old_engine_(g_engine_for_fontmapper) {
+ g_engine_for_fontmapper = engine;
+}
+
+ScopedSubstFont::~ScopedSubstFont() {
+ g_engine_for_fontmapper = old_engine_;
+}
+
namespace {
base::LazyInstance<PDFiumEngineExports>::Leaky g_pdf_engine_exports =
@@ -3836,6 +3858,7 @@ bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer,
FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, buffer_size, nullptr);
if (!doc)
return false;
+ ScopedSubstFont scoped_subst_font(this);
FPDF_PAGE page = FPDF_LoadPage(doc, page_number);
if (!page) {
FPDF_CloseDocument(doc);

Powered by Google App Engine
This is Rietveld 408576698