prawn icon indicating copy to clipboard operation
prawn copied to clipboard

Myanmar font is not being rendered correctly

Open pmverma opened this issue 5 years ago • 16 comments

Hi,

I have following text.

require "prawn"

Prawn::Document.generate("hello.pdf") do
  font("PYIDAUNGSU-2.5_REGULAR.TTF") do
    text "ပြည်ထောင်စု သမ္မတ မြန်မာနိုင်ငံတော်‌ - Republic of the Union of Myanmar"
  end
end

Following is the rendered pdf which is not correct.

image

I have attached the font I used. PYIDAUNGSU-2.5_REGULAR.TTF.zip

Let me know what can I help you more.

Regards, Mohan

pmverma avatar Sep 02 '19 08:09 pmverma

Note: The result is same with Noto Serif Myanmar fonts. https://www.google.com/get/noto/#serif-mymr

pmverma avatar Sep 02 '19 09:09 pmverma

Could you please confirm, that incorrect rendering can be caused by the lack of ligatures?

pointlessone avatar Sep 02 '19 10:09 pointlessone

Thanks @pointlessone for your response. Sorry for stupid question, but how can I confirm that ligatures is lacking?

Generally in the text editors or word processors, the combination happens automatically. For eg, from the above example, first letter.

To get ပြည်, there sequence goes like ပ ြ ည ် and the word processors automatically adjusts them.

  1. ပ => ပ
  2. ပ + ြ => ပြ
  3. ပြ + ည => ပြည
  4. ပြည + ် => ပြည်

Regards, Mohan

pmverma avatar Sep 03 '19 03:09 pmverma

Hi @pointlessone , I raised an issue to one of the font developer, however, they think that this might be a problem with library/platform I am using, the library/platform might not be reordering or resolving viramas, etc.

Please see more at https://github.com/silnrsi/font-padauk/issues/30#issuecomment-611847627

I am having this same problem with all Unicode fonts we have for our language. Some fonts have more rendering issue while some have with less. I really need this to be fixed.

I just do not know where to start, and how to further this thing. Can you please help with this?

pmverma avatar Apr 10 '20 05:04 pmverma

@pmverma In the link you referenced is the mention of font shaping. Prawn doesn't do font shaping since that is quite a complex topic. So if the combination is done through font shaping and not through simple ligatures, you won't get correct results in Prawn, for no font.

However, there is ongoing work to bring OTF support to the library "ttfunk" Prawn is using for fonts. Once this has landed it might be easier to implement font shaping in Prawn. But for now this won't work.

gettalong avatar Apr 10 '20 06:04 gettalong

Even if it's done with ligatures it won't work either. TTFunk strips all ligature glyphs during subsetting.

pointlessone avatar Apr 10 '20 07:04 pointlessone

@pointlessone Really? But how does it do ligatures like 'll' then?

gettalong avatar Apr 10 '20 08:04 gettalong

IIRC, TTFunk doesn't touch kerning tables, if you're referring to those. I was speaking of typographic ligatures: Typographic ligatures

These take a few characters and display them with a single glyph. TTFunk doesn't properly handle that (yet?). It only leaves glyphs for individual characters during subsetting. This results in a less fancy typography in western/Cyrillic scripts but is an issue for scripts that heavily rely on ligatures, like Arabic, or Myanmar.

pointlessone avatar Apr 10 '20 08:04 pointlessone

Ah, you are right, I thought about kerning which Prawn supports. The standard 14 PDF fonts partially support ligatures, e.g. Times-Roman supports f i -> fi, and I thought that this was implemented. And similarly for TrueType fonts.

gettalong avatar Apr 10 '20 21:04 gettalong

Standard fonts are just the ones Adobe promised to always have with their software installed. Since they're pre-installed and not processed by TTFunk they might have all sorts of ligatures and not suffer from subsetting issues.

pointlessone avatar Apr 11 '20 11:04 pointlessone

Thanks both @gettalong & @gettalong for your inputs.

Basically I am generating pdf using https://github.com/asciidoctor/asciidoctor-pdf which depends on prawnpdf.

Now I understand I am out of luck here. Is there any plan to add a support for fonts like Myanmar, in prawn? Since you are experts here, what will be your suggestions on this?

Regards, Mohan

pmverma avatar Apr 13 '20 13:04 pmverma

There's a consensus that this feature is desired but no concrete plans for the implementation that I'm aware of. I'll be happy to accept a contribution.

pointlessone avatar Apr 13 '20 14:04 pointlessone

Thanks @pointlessone . I think this will be very broad thing to understand and implement. My current level in this domain is "zero".

However, can you please let me know some resources to understand the issue?

  • basic & essentials things to understand
  • after that where & how to start

Regards, Mohan

pmverma avatar Apr 13 '20 14:04 pmverma

Ended up here using Asciidoctor, too, and realizing the lack of ligatures available in the TTF Font (Vollkorn via Google Fonts) not being used. Just as @pmverma, I'd be happy to help but without a few initial pointers it's gonna be hard for me to actually get started.

odrotbohm avatar Feb 08 '21 16:02 odrotbohm

@odrotbohm, Can you please let me know what was your workaround? Or did you stop using this library?

For me, Here is what I have been doing,

  • Build only the html5 backend then
  • Open it in the browser and save as PDF because they render correctly (Chrome/Edge is better than other browsers).

However, with this approach, I lose all the asciidoctor-pdf features such as generating TOC with link, page number, etc. But I believe, I can automate some of those, header & footers using pdfbox (not tried yet)

Regards, Mohan

pmverma avatar Jun 02 '21 11:06 pmverma

There was no workaround for me. Combinations like "fi" are just rendered as two separate letters, not the corresponding ligature.

odrotbohm avatar Jun 08 '21 15:06 odrotbohm

@odrotbohm, Can you please let me know what was your workaround?

My workaround is to build a new fonte without ligatures… For instance, in this new fonte, let's say "Ligaturae.ttf", I build the "F" glyph with the well-known ligatured "fi". Then, in Prawn:

pdf.update do
  text("<font name="Ligaturae">F</font>", 
          **{inline_format: true})
  # write ligatured "fi" in the pdf document
end

Of course, with a lot of ligatures, it's a lot of work…

FYI, l use the very nice Glyph Mini app to build my fonts.

PhilippePerret avatar Oct 13 '23 09:10 PhilippePerret