Chromium Code Reviews| 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 if (!pp::PDF::GetFontTableForPrivateFontFile(res_id, table, buffer, &size)) | 287 if (!pp::PDF::GetFontTableForPrivateFontFile(res_id, table, buffer, &size)) |
| 288 return 0; | 288 return 0; |
| 289 return size; | 289 return size; |
| 290 } | 290 } |
| 291 | 291 |
| 292 void DeleteFont(struct _FPDF_SYSFONTINFO*, void* font_id) { | 292 void DeleteFont(struct _FPDF_SYSFONTINFO*, void* font_id) { |
| 293 long res_id = reinterpret_cast<long>(font_id); | 293 long res_id = reinterpret_cast<long>(font_id); |
| 294 pp::Module::Get()->core()->ReleaseResource(res_id); | 294 pp::Module::Get()->core()->ReleaseResource(res_id); |
| 295 } | 295 } |
| 296 | 296 |
| 297 // Font loading doesn't work in the renderer sandbox in Linux. | |
| 297 FPDF_SYSFONTINFO g_font_info = { | 298 FPDF_SYSFONTINFO g_font_info = { |
| 298 1, | 299 1, |
| 299 0, | 300 0, |
| 300 EnumFonts, | 301 EnumFonts, |
| 301 MapFont, | 302 MapFont, |
| 302 0, | 303 0, |
| 303 GetFontData, | 304 GetFontData, |
| 304 0, | 305 0, |
| 305 0, | 306 0, |
| 306 DeleteFont | 307 DeleteFont |
| 307 }; | 308 }; |
| 309 #else | |
| 310 struct FPDF_SYSFONTINFO_WITHMETRICS : public FPDF_SYSFONTINFO { | |
| 311 FPDF_SYSFONTINFO_WITHMETRICS(FPDF_SYSFONTINFO* default_sysfontinfo) { | |
|
Lei Zhang
2016/11/08 19:16:10
explicit
| |
| 312 version = default_sysfontinfo->version; | |
| 313 default_sysfontinfo_ = default_sysfontinfo; | |
| 314 } | |
| 315 | |
| 316 FPDF_SYSFONTINFO* default_sysfontinfo_; | |
| 317 }; | |
| 318 | |
| 319 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
| |
| 320 int weight, | |
| 321 int italic, | |
| 322 int charset, | |
| 323 int pitch_family, | |
| 324 const char* face, | |
| 325 int* exact) { | |
| 326 auto* fontinfo_with_metrics = | |
| 327 static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo); | |
| 328 void* mapped_font = fontinfo_with_metrics->default_sysfontinfo_->MapFont( | |
| 329 fontinfo_with_metrics->default_sysfontinfo_, weight, italic, charset, | |
| 330 pitch_family, face, exact); | |
| 331 if (mapped_font && g_engine_for_fontmapper) | |
| 332 g_engine_for_fontmapper->FontSubstituted(); | |
| 333 return mapped_font; | |
| 334 } | |
| 335 | |
| 336 void DeleteFont(struct _FPDF_SYSFONTINFO* sysfontinfo, void* font_id) { | |
| 337 auto* fontinfo_with_metrics = | |
| 338 static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo); | |
| 339 fontinfo_with_metrics->default_sysfontinfo_->DeleteFont( | |
| 340 fontinfo_with_metrics->default_sysfontinfo_, font_id); | |
| 341 } | |
| 342 | |
| 343 void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) { | |
| 344 auto* fontinfo_with_metrics = | |
| 345 static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo); | |
| 346 fontinfo_with_metrics->default_sysfontinfo_->EnumFonts( | |
| 347 fontinfo_with_metrics->default_sysfontinfo_, mapper); | |
| 348 } | |
| 349 | |
| 350 unsigned long GetFaceName(struct _FPDF_SYSFONTINFO* sysfontinfo, | |
| 351 void* hFont, | |
| 352 char* buffer, | |
| 353 unsigned long buffer_size) { | |
| 354 auto* fontinfo_with_metrics = | |
| 355 static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo); | |
| 356 return fontinfo_with_metrics->default_sysfontinfo_->GetFaceName( | |
| 357 fontinfo_with_metrics->default_sysfontinfo_, hFont, buffer, buffer_size); | |
| 358 } | |
| 359 | |
| 360 void* GetFont(struct _FPDF_SYSFONTINFO* sysfontinfo, const char* face) { | |
| 361 auto* fontinfo_with_metrics = | |
| 362 static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo); | |
| 363 return fontinfo_with_metrics->default_sysfontinfo_->GetFont( | |
| 364 fontinfo_with_metrics->default_sysfontinfo_, face); | |
| 365 } | |
| 366 | |
| 367 int GetFontCharset(struct _FPDF_SYSFONTINFO* sysfontinfo, void* hFont) { | |
| 368 auto* fontinfo_with_metrics = | |
| 369 static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo); | |
| 370 return fontinfo_with_metrics->default_sysfontinfo_->GetFontCharset( | |
| 371 fontinfo_with_metrics->default_sysfontinfo_, hFont); | |
| 372 } | |
| 373 | |
| 374 unsigned long GetFontData(struct _FPDF_SYSFONTINFO* sysfontinfo, | |
| 375 void* hFont, | |
| 376 unsigned int table, | |
| 377 unsigned char* buffer, | |
| 378 unsigned long buf_size) { | |
| 379 auto* fontinfo_with_metrics = | |
| 380 static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo); | |
| 381 return fontinfo_with_metrics->default_sysfontinfo_->GetFontData( | |
| 382 fontinfo_with_metrics->default_sysfontinfo_, hFont, table, buffer, | |
| 383 buf_size); | |
| 384 } | |
| 385 | |
| 386 void Release(struct _FPDF_SYSFONTINFO* sysfontinfo) { | |
| 387 auto* fontinfo_with_metrics = | |
| 388 static_cast<FPDF_SYSFONTINFO_WITHMETRICS*>(sysfontinfo); | |
| 389 fontinfo_with_metrics->default_sysfontinfo_->Release( | |
| 390 fontinfo_with_metrics->default_sysfontinfo_); | |
| 391 delete fontinfo_with_metrics->default_sysfontinfo_; | |
| 392 } | |
| 308 #endif // defined(OS_LINUX) | 393 #endif // defined(OS_LINUX) |
| 309 | 394 |
| 310 PDFiumEngine* g_engine_for_unsupported = nullptr; | 395 PDFiumEngine* g_engine_for_unsupported = nullptr; |
| 311 | 396 |
| 312 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { | 397 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { |
| 313 if (!g_engine_for_unsupported) { | 398 if (!g_engine_for_unsupported) { |
| 314 NOTREACHED(); | 399 NOTREACHED(); |
| 315 return; | 400 return; |
| 316 } | 401 } |
| 317 | 402 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 bool InitializeSDK() { | 594 bool InitializeSDK() { |
| 510 SetUpV8(); | 595 SetUpV8(); |
| 511 | 596 |
| 512 FPDF_LIBRARY_CONFIG config; | 597 FPDF_LIBRARY_CONFIG config; |
| 513 config.version = 2; | 598 config.version = 2; |
| 514 config.m_pUserFontPaths = nullptr; | 599 config.m_pUserFontPaths = nullptr; |
| 515 config.m_pIsolate = v8::Isolate::GetCurrent(); | 600 config.m_pIsolate = v8::Isolate::GetCurrent(); |
| 516 config.m_v8EmbedderSlot = gin::kEmbedderPDFium; | 601 config.m_v8EmbedderSlot = gin::kEmbedderPDFium; |
| 517 FPDF_InitLibraryWithConfig(&config); | 602 FPDF_InitLibraryWithConfig(&config); |
| 518 | 603 |
| 519 #if defined(OS_LINUX) | 604 #if !defined(OS_LINUX) |
| 605 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
| |
| 606 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
| |
| 607 if (g_font_info->default_sysfontinfo_->Release) | |
| 608 g_font_info->Release = Release; | |
| 609 if (g_font_info->default_sysfontinfo_->EnumFonts) | |
| 610 g_font_info->EnumFonts = EnumFonts; | |
| 611 // Set new MapFont that calculates metrics | |
| 612 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
| |
| 613 g_font_info->MapFont = MapFontWithMetrics; | |
| 614 if (g_font_info->default_sysfontinfo_->GetFont) | |
| 615 g_font_info->GetFont = GetFont; | |
| 616 if (g_font_info->default_sysfontinfo_->GetFaceName) | |
| 617 g_font_info->GetFaceName = GetFaceName; | |
| 618 if (g_font_info->default_sysfontinfo_->GetFontCharset) | |
| 619 g_font_info->GetFontCharset = GetFontCharset; | |
| 620 // These are required according to documentation | |
| 621 g_font_info->GetFontData = GetFontData; | |
| 622 g_font_info->DeleteFont = DeleteFont; | |
| 623 FPDF_SetSystemFontInfo(g_font_info); | |
| 624 #else | |
| 520 // Font loading doesn't work in the renderer sandbox in Linux. | 625 // Font loading doesn't work in the renderer sandbox in Linux. |
| 521 FPDF_SetSystemFontInfo(&g_font_info); | 626 FPDF_SetSystemFontInfo(&g_font_info); |
| 522 #endif | 627 #endif |
| 523 | 628 |
| 524 FSDK_SetUnSpObjProcessHandler(&g_unsupported_info); | 629 FSDK_SetUnSpObjProcessHandler(&g_unsupported_info); |
| 525 | |
| 526 return true; | 630 return true; |
| 527 } | 631 } |
| 528 | 632 |
| 529 void ShutdownSDK() { | 633 void ShutdownSDK() { |
| 530 FPDF_DestroyLibrary(); | 634 FPDF_DestroyLibrary(); |
| 531 TearDownV8(); | 635 TearDownV8(); |
| 532 } | 636 } |
| 533 | 637 |
| 534 PDFEngine* PDFEngine::Create(PDFEngine::Client* client) { | 638 PDFEngine* PDFEngine::Create(PDFEngine::Client* client) { |
| 535 return new PDFiumEngine(client); | 639 return new PDFiumEngine(client); |
| (...skipping 3489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4025 FPDF_DOCUMENT doc = | 4129 FPDF_DOCUMENT doc = |
| 4026 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4130 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 4027 if (!doc) | 4131 if (!doc) |
| 4028 return false; | 4132 return false; |
| 4029 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4133 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 4030 FPDF_CloseDocument(doc); | 4134 FPDF_CloseDocument(doc); |
| 4031 return success; | 4135 return success; |
| 4032 } | 4136 } |
| 4033 | 4137 |
| 4034 } // namespace chrome_pdf | 4138 } // namespace chrome_pdf |
| OLD | NEW |