Chromium Code Reviews| Index: pdf/pdfium/pdfium_engine.cc |
| diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
| index 475d56933053765ad2f460b8ca1d7a89df84a095..80365bf44d1a40e40342938c799bf7cf52b6a472 100644 |
| --- a/pdf/pdfium/pdfium_engine.cc |
| +++ b/pdf/pdfium/pdfium_engine.cc |
| @@ -131,6 +131,7 @@ std::vector<uint32_t> GetPageNumbersFromPrintPageNumberRange( |
| PP_Instance g_last_instance_id; |
| +// TODO(npm): Move font stuff to another file to reduce the size of this one |
| PP_BrowserFont_Trusted_Weight WeightToBrowserFontTrustedWeight(int weight) { |
| static_assert(PP_BROWSERFONT_TRUSTED_WEIGHT_100 == 0, |
| "PP_BrowserFont_Trusted_Weight min"); |
| @@ -147,7 +148,7 @@ PP_BrowserFont_Trusted_Weight WeightToBrowserFontTrustedWeight(int weight) { |
| // This list is for CPWL_FontMap::GetDefaultFontByCharset(). |
| // We pretend to have these font natively and let the browser (or underlying |
| // fontconfig) to pick the proper font on the system. |
| -void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) { |
| +void EnumFonts(FPDF_SYSFONTINFO* sysfontinfo, void* mapper) { |
| FPDF_AddInstalledFont(mapper, "Arial", FXFONT_DEFAULT_CHARSET); |
| const FPDF_CharsetFontMap* font_map = FPDF_GetDefaultTTFMap(); |
| @@ -156,8 +157,13 @@ void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) { |
| } |
| } |
| -void* MapFont(struct _FPDF_SYSFONTINFO*, int weight, int italic, |
| - int charset, int pitch_family, const char* face, int* exact) { |
| +void* MapFont(FPDF_SYSFONTINFO*, |
| + int weight, |
| + int italic, |
| + int charset, |
| + int pitch_family, |
| + const char* face, |
| + int* exact) { |
| // Do not attempt to map fonts if pepper is not initialized (for privet local |
| // printing). |
| // TODO(noamsml): Real font substitution (http://crbug.com/391978) |
| @@ -274,8 +280,10 @@ void* MapFont(struct _FPDF_SYSFONTINFO*, int weight, int italic, |
| return reinterpret_cast<void*>(res_id); |
| } |
| -unsigned long GetFontData(struct _FPDF_SYSFONTINFO*, void* font_id, |
| - unsigned int table, unsigned char* buffer, |
| +unsigned long GetFontData(FPDF_SYSFONTINFO*, |
| + void* font_id, |
| + unsigned int table, |
| + unsigned char* buffer, |
| unsigned long buf_size) { |
| if (!pp::PDF::IsAvailable()) { |
| NOTREACHED(); |
| @@ -289,7 +297,7 @@ unsigned long GetFontData(struct _FPDF_SYSFONTINFO*, void* font_id, |
| return size; |
| } |
| -void DeleteFont(struct _FPDF_SYSFONTINFO*, void* font_id) { |
| +void DeleteFont(FPDF_SYSFONTINFO*, void* font_id) { |
| long res_id = reinterpret_cast<long>(font_id); |
| pp::Module::Get()->core()->ReleaseResource(res_id); |
| } |
| @@ -305,6 +313,93 @@ FPDF_SYSFONTINFO g_font_info = { |
| 0, |
| DeleteFont |
| }; |
| +#else |
| +struct FPDF_SYSFONTINFO_WITHMETRICS : public FPDF_SYSFONTINFO { |
| + explicit FPDF_SYSFONTINFO_WITHMETRICS(FPDF_SYSFONTINFO* default_sysfontinfo) { |
| + version = default_sysfontinfo->version; |
| + default_sysfontinfo_ = default_sysfontinfo; |
| + } |
| + |
| + ~FPDF_SYSFONTINFO_WITHMETRICS() { delete default_sysfontinfo_; } |
|
Tom Sepez
2016/11/08 21:25:52
The public header says:
Application should call F
npm
2016/11/08 21:56:26
The Release() method deletes the extra stuff in FP
|
| + |
| + FPDF_SYSFONTINFO* default_sysfontinfo_; |
| +}; |
| + |
| +FPDF_SYSFONTINFO_WITHMETRICS* g_font_info = nullptr; |
| + |
| +void* MapFontWithMetrics(FPDF_SYSFONTINFO* sysfontinfo, |
| + 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(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(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(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(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(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(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(FPDF_SYSFONTINFO* sysfontinfo) { |
| + auto* fontinfo_with_metrics = |
| + static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo); |
| + fontinfo_with_metrics->default_sysfontinfo_->Release( |
| + fontinfo_with_metrics->default_sysfontinfo_); |
| +} |
| #endif // defined(OS_LINUX) |
| PDFiumEngine* g_engine_for_unsupported = nullptr; |
| @@ -516,7 +611,27 @@ bool InitializeSDK() { |
| config.m_v8EmbedderSlot = gin::kEmbedderPDFium; |
| FPDF_InitLibraryWithConfig(&config); |
| -#if defined(OS_LINUX) |
| +#if !defined(OS_LINUX) |
| + g_font_info = |
| + new FPDF_SYSFONTINFO_WITHMETRICS(FPDF_GetDefaultSystemFontInfo()); |
| + 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) |
| + 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 |
| @@ -527,6 +642,9 @@ bool InitializeSDK() { |
| } |
| void ShutdownSDK() { |
| +#if !defined(OS_LINUX) |
| + delete g_font_info; |
| +#endif |
| FPDF_DestroyLibrary(); |
| TearDownV8(); |
| } |