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

Unified Diff: pdf/pdfium/pdfium_engine.cc

Issue 2479313005: Add font substituted metrics for OS other than Linux (Closed)
Patch Set: Override all because struct pointer Created 4 years, 1 month 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
« no previous file with comments | « pdf/out_of_process_instance.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/pdfium/pdfium_engine.cc
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc
index 475d56933053765ad2f460b8ca1d7a89df84a095..5aa7e913a1fe2f016eca3a5b067883eb0dff7235 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -294,6 +294,7 @@ void DeleteFont(struct _FPDF_SYSFONTINFO*, void* font_id) {
pp::Module::Get()->core()->ReleaseResource(res_id);
}
+// Font loading doesn't work in the renderer sandbox in Linux.
FPDF_SYSFONTINFO g_font_info = {
1,
0,
@@ -305,6 +306,90 @@ FPDF_SYSFONTINFO g_font_info = {
0,
DeleteFont
};
+#else
+struct FPDF_SYSFONTINFO_WITHMETRICS : public FPDF_SYSFONTINFO {
+ FPDF_SYSFONTINFO_WITHMETRICS(FPDF_SYSFONTINFO* default_sysfontinfo) {
Lei Zhang 2016/11/08 19:16:10 explicit
+ version = default_sysfontinfo->version;
+ default_sysfontinfo_ = default_sysfontinfo;
+ }
+
+ FPDF_SYSFONTINFO* default_sysfontinfo_;
+};
+
+void* MapFontWithMetrics(struct _FPDF_SYSFONTINFO* sysfontinfo,
Lei Zhang 2016/11/08 19:16:10 Just FPDF_SYSFONTINFO*
npm 2016/11/08 19:54:36 The "_" is used on the Linux overrides in this fil
+ int weight,
+ int italic,
+ int charset,
+ int pitch_family,
+ const char* face,
+ int* exact) {
+ auto* fontinfo_with_metrics =
+ static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo);
+ void* mapped_font = fontinfo_with_metrics->default_sysfontinfo_->MapFont(
+ fontinfo_with_metrics->default_sysfontinfo_, weight, italic, charset,
+ pitch_family, face, exact);
+ if (mapped_font && g_engine_for_fontmapper)
+ g_engine_for_fontmapper->FontSubstituted();
+ return mapped_font;
+}
+
+void DeleteFont(struct _FPDF_SYSFONTINFO* sysfontinfo, void* font_id) {
+ auto* fontinfo_with_metrics =
+ static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo);
+ fontinfo_with_metrics->default_sysfontinfo_->DeleteFont(
+ fontinfo_with_metrics->default_sysfontinfo_, font_id);
+}
+
+void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) {
+ auto* fontinfo_with_metrics =
+ static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo);
+ fontinfo_with_metrics->default_sysfontinfo_->EnumFonts(
+ fontinfo_with_metrics->default_sysfontinfo_, mapper);
+}
+
+unsigned long GetFaceName(struct _FPDF_SYSFONTINFO* sysfontinfo,
+ void* hFont,
+ char* buffer,
+ unsigned long buffer_size) {
+ auto* fontinfo_with_metrics =
+ static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo);
+ return fontinfo_with_metrics->default_sysfontinfo_->GetFaceName(
+ fontinfo_with_metrics->default_sysfontinfo_, hFont, buffer, buffer_size);
+}
+
+void* GetFont(struct _FPDF_SYSFONTINFO* sysfontinfo, const char* face) {
+ auto* fontinfo_with_metrics =
+ static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo);
+ return fontinfo_with_metrics->default_sysfontinfo_->GetFont(
+ fontinfo_with_metrics->default_sysfontinfo_, face);
+}
+
+int GetFontCharset(struct _FPDF_SYSFONTINFO* sysfontinfo, void* hFont) {
+ auto* fontinfo_with_metrics =
+ static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo);
+ return fontinfo_with_metrics->default_sysfontinfo_->GetFontCharset(
+ fontinfo_with_metrics->default_sysfontinfo_, hFont);
+}
+
+unsigned long GetFontData(struct _FPDF_SYSFONTINFO* sysfontinfo,
+ void* hFont,
+ unsigned int table,
+ unsigned char* buffer,
+ unsigned long buf_size) {
+ auto* fontinfo_with_metrics =
+ static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo);
+ return fontinfo_with_metrics->default_sysfontinfo_->GetFontData(
+ fontinfo_with_metrics->default_sysfontinfo_, hFont, table, buffer,
+ buf_size);
+}
+
+void Release(struct _FPDF_SYSFONTINFO* sysfontinfo) {
+ auto* fontinfo_with_metrics =
+ static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo);
+ fontinfo_with_metrics->default_sysfontinfo_->Release(
+ fontinfo_with_metrics->default_sysfontinfo_);
+ delete fontinfo_with_metrics->default_sysfontinfo_;
+}
#endif // defined(OS_LINUX)
PDFiumEngine* g_engine_for_unsupported = nullptr;
@@ -516,13 +601,32 @@ bool InitializeSDK() {
config.m_v8EmbedderSlot = gin::kEmbedderPDFium;
FPDF_InitLibraryWithConfig(&config);
-#if defined(OS_LINUX)
+#if !defined(OS_LINUX)
+ FPDF_SYSFONTINFO_WITHMETRICS* g_font_info =
Lei Zhang 2016/11/08 19:16:10 not a global
npm 2016/11/08 19:54:36 What do you mean? Declare pointer in namespace?
Lei Zhang 2016/11/08 19:58:31 The variable is named g_foo, yet it is a local var
+ new FPDF_SYSFONTINFO_WITHMETRICS(FPDF_GetDefaultSystemFontInfo());
Lei Zhang 2016/11/08 19:16:10 Does this get freed or if it a one time leak?
npm 2016/11/08 19:54:36 We FPDF_SetSystemFontInfo on it, and Release is ca
+ if (g_font_info->default_sysfontinfo_->Release)
+ g_font_info->Release = Release;
+ if (g_font_info->default_sysfontinfo_->EnumFonts)
+ g_font_info->EnumFonts = EnumFonts;
+ // Set new MapFont that calculates metrics
+ if (g_font_info->default_sysfontinfo_->MapFont)
Lei Zhang 2016/11/08 19:16:10 This is the only one you actual care about, right?
npm 2016/11/08 19:54:36 Actually, the default always gets assigned all of
Lei Zhang 2016/11/08 19:58:31 I guess stick with it since we want to follow the
+ g_font_info->MapFont = MapFontWithMetrics;
+ if (g_font_info->default_sysfontinfo_->GetFont)
+ g_font_info->GetFont = GetFont;
+ if (g_font_info->default_sysfontinfo_->GetFaceName)
+ g_font_info->GetFaceName = GetFaceName;
+ if (g_font_info->default_sysfontinfo_->GetFontCharset)
+ g_font_info->GetFontCharset = GetFontCharset;
+ // These are required according to documentation
+ g_font_info->GetFontData = GetFontData;
+ g_font_info->DeleteFont = DeleteFont;
+ FPDF_SetSystemFontInfo(g_font_info);
+#else
// Font loading doesn't work in the renderer sandbox in Linux.
FPDF_SetSystemFontInfo(&g_font_info);
#endif
FSDK_SetUnSpObjProcessHandler(&g_unsupported_info);
-
return true;
}
« no previous file with comments | « pdf/out_of_process_instance.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698