Allow CPDF_Font to use fallback fonts

Added a vector of pointers to CFX_Fonts in the class CPDF_Font, so that
fallback fonts may be used. In CPDF_CharPosList::Load, the glyphs for each
character are calculated. When m_Font does not support a character, a fallback
font is selected and the character is rendered using that font. This meant
adding an attribute to FXTEXT_CHARPOS so it knows which font renders it.

Also, methods in fpdf_render_text.cpp now may need to call device drawing
methods multiple times because these only support one font at a time. In
CPDF_TextRenderer::DrawNormalText and in CPDF_TextRenderer::DrawTextPath, the
device drawing method is called as few times as possible by grouping contiguous
characters rendered by the same font. In
CPDF_RenderStatus::DrawTextPathWithPattern, drawing was already done one
character at a time, but precalculating CFX_FaceCache. Now, the face cache is
precalculated for all of the fallback fonts.

The list of fallback fonts does not include tha main font. Otherwise the list
would be of raw pointers to avoid double free problems. For now, the font
Arial is used as fallback. This should fix the issue of not seeing Latin
characters displayed when bad fonts are used. However, this should be improved.

Tested manually using the file in the bug, plus a font directory containing a
font that supports Hangul but not Latin. This font is chosen as the substitute
font, but Latin characters are now being rendered.

Design proposal: go/pdfium_fallbackfonts

BUG=pdfium:358

Review-Url: https://codereview.chromium.org/2276653002
4 files changed
tree: fb81a07ad10477d16af26667aa4e4629328b6084
  1. build_gyp/
  2. build_overrides/
  3. core/
  4. docs/
  5. fpdfsdk/
  6. fxjs/
  7. infra/
  8. public/
  9. samples/
  10. skia/
  11. test/
  12. testing/
  13. third_party/
  14. tools/
  15. xfa/
  16. .clang-format
  17. .gitignore
  18. .gn
  19. AUTHORS
  20. BUILD.gn
  21. codereview.settings
  22. DEPS
  23. LICENSE
  24. navbar.md
  25. OWNERS
  26. pdfium.gni
  27. pdfium.gyp
  28. PRESUBMIT.py
  29. README.md
  30. xfa.gyp
README.md

PDFium

News

As of 2016-05-04, GN is used to generate build files replacing GYP. GYP support will remain until it is disabled in Chromium and then will be removed from PDFium.

As of 2016-04-28, the Visual Studio toolchain from depot_tools is used as the default Windows toolchain for Googlers. Please set DEPOT_TOOLS_WIN_TOOLCHAIN=0 if you need to use the system toolchain. See Windows development subsection for details.

Prerequisites

Get the chromium depot tools via the instructions at http://www.chromium.org/developers/how-tos/install-depot-tools (this provides the gclient utility needed below).

Also install Python, Subversion, and Git and make sure they're in your path.

### Windows development

PDFium uses a similar Windows toolchain as Chromium:

Open source contributors

Visual Studio 2015 Update 2 or later is highly recommended.

Run set DEPOT_TOOLS_WIN_TOOLCHAIN=0, or set that variable in your global environment.

Compilation is done through ninja, not Visual Studio.

Google employees

Run: download_from_google_storage --config and follow the authentication instructions. Note that you must authenticate with your @google.com credentials. Enter “0” if asked for a project-id.

Once you've done this, the toolchain will be installed automatically for you in the step below.

The toolchain will be in depot_tools\win_toolchain\vs_files\<hash>, and windbg can be found in depot_tools\win_toolchain\vs_files\<hash>\win_sdk\Debuggers.

If you want the IDE for debugging and editing, you will need to install it separately, but this is optional and not needed for building PDFium.

Get the code

The name of the top-level directory does not matter. In our examples, we use “repo”. This directory must not have been used before by gclient config as each directory can only house a single gclient configuration.

mkdir repo
cd repo
gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
gclient sync
cd pdfium

## Generate the build files

We use GN to generate the build files and Ninja (also included with the depot_tools checkout) to execute the build files.

gn gen <directory>

If you want to set to out/Debug or out/Release you'll need to export GYP_PDFIUM_NO_ACTION=1 to stop gclient sync from executing GYP and overwriting your build files.

### Selecting build configuration

PDFium may be built either with or without JavaScript support, and with or without XFA forms support. Both of these features are enabled by default. Also note that the XFA feature requires JavaScript.

Configuration is done by executing gn args <directory> to configure the build. This will launch an editor in which you can set the following arguments.

use_goma = true  # Googlers only.
is_debug = true  # Enable debugging features.

pdf_use_skia = false  # Set true to enable experimental skia backend.

pdf_enable_xfa = true # Set false to remove XFA support (implies JS support).
pdf_enable_v8 = true  # Set false to remove Javascript support.
pdf_is_standalone = true  # Set for a non-embedded build.

Note, you must set pdf_is_standalone = true if you want the sample applications like pdfium_test to build.

When complete the arguments will be stored in <directory>/args.gn.

Building the code

If you used Ninja, you can build the sample program by: ninja -C <directory>/pdfium_test You can build the entire product (which includes a few unit tests) by: ninja -C <directory>.

Running the sample program

The pdfium_test program supports reading, parsing, and rasterizing the pages of a .pdf file to .ppm or .png output image files (windows supports two other formats). For example: <directory>/pdfium_test --ppm path/to/myfile.pdf. Note that this will write output images to path/to/myfile.pdf.<n>.ppm.

Testing

There are currently several test suites that can be run:

  • pdfium_unittests
  • pdfium_embeddertests
  • testing/tools/run_corpus_tests.py
  • testing/tools/run_javascript_tests.py
  • testing/tools/run_pixel_tests.py

It is possible the tests in the testing directory can fail due to font differences on the various platforms. These tests are reliable on the bots. If you see failures, it can be a good idea to run the tests on the tip-of-tree checkout to see if the same failures appear.

Waterfall

The current health of the source tree can be found at http://build.chromium.org/p/client.pdfium/console

Community

There are several mailing lists that are setup:

Note, the Reviews and Bugs lists are typically read-only.

Bugs

We use this bug tracker, but for security bugs, please use [Chromium's security bug template] (https://code.google.com/p/chromium/issues/entry?template=Security%20Bug) and add the “Cr-Internals-Plugins-PDF” label.

Contributing code

For contributing code, we will follow Chromium's process as much as possible. The main exceptions is:

  1. Code has to conform to the existing style and not Chromium/Google style.