Skip to content

Strange Behavior With Chinese Fonts #1027

Open

Description

@Dr-NULL

Bug Report

Description of the problem

PDFKit has a strange behavior when uses a chinese font, and use certain chinese characters.

Details:

  • When inserts the first string ("冷冻去骨牛肉 / Frozen Boneless Beef / Carne Bovina sin Hueso Congelada"), this displays fine.
  • But when inserts some characters (like "产品名"), the texts which inserted next only shows a few characters.
  • Some normal characters such two-dots ":" doesn't rendered by PDFKit.

Code sample

I made a project with a extensive documentation of the problem:
https://github.com/Dr-NULL/Issues-PDFKit

Your environment

  • pdfkit version: 0.10.0
  • Node version: 10.16.3
  • Operating System: Windows 10 x64 bits

Activity

  1. dasoncheng commented on Sep 29, 2019

    @dasoncheng
    dcto.font(join(__dirname, "somewhere/fonts/苹方黑体-准-简.ttf"));

    May be your font load error or do not support Chinese, i tried and it worked

    see Dr-NULL/Issues-PDFKit#1

  2. Dr-NULL commented on Sep 30, 2019

    @Dr-NULL
    Author

    I was testing some fonts, specifically with Google Fonts (.OTF) and two open source fonts (Ping Fang and Founder Type Hei Ti). My observations are as follows:

    • PDFKit has problems with OTF files.
    • PDFKit normally works with TTF fonts.

    I made some changes to the Issues-PDFKit repository. I added more fonts in the "./source" folder and added them to the "./src/global.ts" file. To test the other sources you just need to change the property called on line 14 of the "index.ts" file to another one inside the Global.Path.Fonts module.

    Finally, I attach a preview of how PDFKit renders some of the fonts tested in the attached screenshots:

    Font NotoSansSC OTF:
    NotoSansSC

    Font NotoSerifSC OTF:
    NotoSerifSC

    Font PingFang TTF:
    PingFang

    Font FZHei TTF:
    FZHei

  3. Dr-NULL commented on Sep 30, 2019

    @Dr-NULL
    Author

    Finally that report give me some doubts:

    • ¿Really PDFKit has OTF files support and definitedly this is a bug?¿Or PDFKit hasn't ificial OTF files support?
    • In the case if OTF files aren't officially supported, ¿Do you have contemplated add OTF files full support?
  4. blikblum commented on Sep 30, 2019

    @blikblum
    Member

    Some OTF bugs were fixed recently.

    Please create a self contained example, with font using https://repl.it/@blikblum/minimal-pdfkit so we can look at it

  5. Dr-NULL commented on Oct 1, 2019

    @Dr-NULL
    Author

    The problem still occurs with OTF fonts. The example code is HERE. When you run the project, that create 2 PDF files. One file is created with a OTF Font (fails), and the another PDF is created with a TTF Font (working).

  6. blikblum commented on Oct 2, 2019

    @blikblum
    Member

    I confirm a bug exists but is not necessarily related with OTF format.

    I tested with PingFang otf and ttf formats and both works fine

    Testing with noto sans otf shows the bug. I could not find a noto sans ttf version and the online converters do not properly work with this font.

  7. v-python commented on Oct 3, 2019

    @v-python

    Some Chinese fonts apparently use obscure features. Someone sent me a Chinese TTF font that most font web sites can't successfully manipulate. And some browsers can't display it correctly, seems there are some special flags that some tools & browsers don't handle properly, but that are the basis for sharing strokes among glyphs which can make a Chinese font significantly smaller.

  8. blikblum commented on Oct 3, 2019

    @blikblum
    Member

    This specific font works in other web tools.
    I already identified a bug in fontkit, looking into it

  9. blikblum commented on Oct 5, 2019

    @blikblum
    Member

    Fixed a bug that affect noto sans otf font at foliojs/fontkit#207. Hopefully will fix this.

  10. Dr-NULL commented on Oct 7, 2019

    @Dr-NULL
    Author

    Thanks for all @blikblum , but I can't access to the last changes applied into the lib. I assume that I'll waiting for test these changes to the master branch when the push request will done.

  11. Dr-NULL commented on Oct 14, 2019

    @Dr-NULL
    Author

    The problem continues, I tried with updating PDFKit, the last version that NPM downloads is 0.10.0 and this is the result with NotoSansSC.otf:
    Example OTF

    ...and with PingFang.ttf:
    Example TTF

    The most strange part is if I try to print the pdf with OTF broken font using SumatraPDF (by console), returns the following error:
    Error

  12. blikblum commented on Oct 14, 2019

    @blikblum
    Member

    The fix is not released yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions