foliojs / fontkit

An advanced font engine for Node and the browser
1.45k stars 213 forks source link

Burmese character signs are not being rendered properly #264

Open ben-dunc opened 2 years ago

ben-dunc commented 2 years ago

Principle Issue

The principle issue here is that Burmese character signs are not being rendered properly.

Background

I'm using pdfmake which uses pdfkit which uses fontkit within an Angular/Ionic application. I'm pretty sure that the issue resides here because it deals with the font, not with the pdf structure. I've experimented with pdfmake to ensure that it is in fact, not the kind of structure that I was using that was causing the problem.

In the application that I'm working through, some English phrases, words and their translations are brought down from a server, parsed through to create the structure, assigned fonts, and then generated client-side via pdfmake for the user to see. However, Burmese is not rendering properly. In case you don't know, Burmese has letters which are normal symbols and signs which modify those letters. Most of these signs are placed around, under, over, or near a symbol. For an example, here is a text with a symbol and a sign: "ကွ". The "က" is the symbol and the smaller circle is a sign that modifies it.

Issue In More Detail

The issue is that these signs are not being placed and rendered properly. Here are some examples. On the right are texts of Burmese being generated by pdfmake and on the right are texts copied from the same source copied too Microsoft word (they are both using the same font: Google Noto Sans Myanmar, an openType ttf font).

Screen Shot 2021-09-17 at 2 43 44 PM

In case you know a bit of pdfMake, here's the code that generated that text:

{
        text: "ဆိုတာကျွန်တော်သိတယ်။",
        font: 'myanmar',
        margin: [0, 5, 0, 0]
},
{
        text: "ကျွန်တော်တို့ဟာသူ့ရဲ့သားသမီးများဖြစ်တယ်။",
        font: 'myanmar',
        margin: [0, 5, 0, 0]
},
{
        text: "အပြစ်ဖြေခြင်းမင်္ဂလာ",
        font: 'myanmar',
        margin: [0, 5, 0, 0]
},
{
        text: "ယုံကြည်တယ်",
        font: 'myanmar',
        margin: [0, 5, 0, 0]
},
{
        text: "စားသောက်ဆိုင်ကြီး",
        font: 'myanmar',
        margin: [0, 5, 0, 0]
},
{
        text: ' ',
        pageBreak: 'after'
}

Note that the font 'myanmar' is defined with the Google Noto Sans Myanmar font. There is a link to the font above.

What I've tried as a fix

  1. Manipulate the pdfmake structure to see if it was the margins or something displacing signs.
  2. Trying different fonts, including those that use Zawgyi encoding rather than Unicode encoding (What is Unicode vs Zawgyi encoding for Myanmar?).
  3. Creating a new blank application and trying there with pdfmake.
  4. Insert character by character letters and signs with their unicodes (i.e.: '\u1000\u103D\u103B').

Requested Fix

Myanmar signs render properly when using pdffont. :)

Thanks!