prawn
prawn copied to clipboard
Myanmar font is not being rendered correctly
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.
I have attached the font I used. PYIDAUNGSU-2.5_REGULAR.TTF.zip
Let me know what can I help you more.
Regards, Mohan
Note: The result is same with Noto Serif Myanmar fonts. https://www.google.com/get/noto/#serif-mymr
Could you please confirm, that incorrect rendering can be caused by the lack of ligatures?
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.
- ပ => ပ
- ပ + ြ => ပြ
- ပြ + ည => ပြည
- ပြည + ် => ပြည်
Regards, Mohan
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 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.
Even if it's done with ligatures it won't work either. TTFunk strips all ligature glyphs during subsetting.
@pointlessone Really? But how does it do ligatures like 'll' then?
IIRC, TTFunk doesn't touch kerning tables, if you're referring to those. I was speaking of 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.
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.
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.
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
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.
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
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, 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
There was no workaround for me. Combinations like "fi" are just rendered as two separate letters, not the corresponding ligature.
@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.