Skip to content

Font use guide #875

@adsee42

Description

@adsee42

Is your feature request related to a problem? Please describe.
It took me 3 days to figure out how to use a no-latin font. (Japanese)

I know this is not a valid feature request, but for those who struggled too, I would like to share how I managed to make it work.

Describe the solution you'd like
Maybe a README listing all tested working fonts for every kinds of languages.

Describe alternatives you've considered
This is what I did:
tldr:
To render japanese, use Nasu or 源真ゴシック

// Font.register({
//   family: "Nasu",
//   src: `${FONT_PATH}/Nasu-Regular.ttf`,
// });
Font.register({
  family: "源真ゴシック",
  fonts: [
    { src: `${FONT_PATH}/genshingothic/GenShinGothic-P-ExtraLight.ttf`, fontWeight: 200 },
    { src: `${FONT_PATH}/genshingothic/GenShinGothic-P-Light.ttf`, fontWeight: 300 },
    { src: `${FONT_PATH}/genshingothic/GenShinGothic-P-Regular.ttf`, fontWeight: 400 },
    { src: `${FONT_PATH}/genshingothic/GenShinGothic-P-Medium.ttf`, fontWeight: 500 },
    { src: `${FONT_PATH}/genshingothic/GenShinGothic-P-Bold.ttf`, fontWeight: 700 },
    { src: `${FONT_PATH}/genshingothic/GenShinGothic-P-Heavy.ttf`, fontWeight: 900 },
  ],
});

more details:

  1. I would like to have a monospaced latin font and a somewhat nice-looked japanese font.
    Of course the default Roboto did not work. Japanese characters are all garbled.
  2. I searched for issues of this repository, tried all solutions other people mentioned, and none worked for me.
  3. I searched for japanese monospace font, and found this post: https://qiita.com/wheatandcat/items/73b1452bd92f831334e7
    And I tried the Nasu he used in his code, and it worked!
  4. But the numbers were not look like what I wanted, so the searching continued.
  5. After trying Noto Sans, which mentioned in other issues, I also tried Noto Sans CJK JP, Source Han Sans, downloading the default .otf, searching for and downloading .ttf, but none of those worked.
  6. And the search kept going. Then I found 源真ゴシック mentioned above. Did not expect it to work, but it worked like a charm.

By the way, when using Font.register to register custom fonts, you can not have both PDFViewer and BlobProvider in same page.(at least in my environment)

That's all. If you guys know any other working fonts for any other languages, please share it here (or somewhere else that's ok for this kind of content).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions