3
votes

We're trying to specify which fonts CasperJS/PhantomJS should use when it finds a generic "sans-serif" css font. We tried to change the ~/.fonts.conf file, but it gets completely ignored.

Is it possible to tell CasperJS/PhantomJS which font to use, also specifying fallback fonts for different character sets (like Chinese, Japanese, Korean etc)?

1
I don't know; it is definitely possible to do this with SlimerJS though (create a custom profile).Darren Cook

1 Answers

-1
votes

You can use any font by linking to it in a CSS file. I use the following for Russian:

@font-face {
    font-family: 'open_sanslight';
    src: url('cyrillic/opensans-light.svg#open_sanslight') format('svg');
    font-weight: normal;
    font-style: normal;
}

You can then set the font as default font for your HTML document or specific areas. Once the font is defined, set it as default font for the whole document like this:

body {
  font-family: open_sanslight;
}

Full example:

<!DOCTYPE html>
<html>

    <head>
    <style>
        @font-face {
            font-family: 'open_sanslight';
            src: url('cyrillic/opensans-light.svg#open_sanslight') format('svg');
            font-weight: normal;
            font-style: normal;
        }

        body {
          font-family: open_sanslight;
        }
    </style>
    </head>

    <body>
      <h1>This is a heading</h1>
      <p>This is a paragraph.</p>
    </body>

</html>

This needs the .svg file in the cyrillic-folder. You can download those files (or others) from Google Fonts.