Issues rendering Burmese/Myanmar in PDFs

Bobby Hagen <[email protected]> Thu, 7 Jan 2021 09:52:50 -0600
Newsgroups gmane.comp.python.reportlab.user
Message-ID <CAO86T9QDYsLyF4=NjgFF9z4r731oRJfGYMxLnED568c_20z2jQ@mail.gmail.com>
Previously posted on the google group, but missing images.  Hopefully those
come through this time. Also clarified a couple steps and wanted to follow
up on this via the list, just in case, as we're still seeing this, even
using the latest reportlab-3.5.59 available via pypi:

We're encountering some problems attempting to build PDFs using Burmese.
The problem doesn't seem restricted to a specific font, as at least
NotoSansMyanmar (https://www.google.com/get/noto/#sans-mymr) and Padauk (
https://fonts.google.com/specimen/Padauk) both have these issues.  Although
independent characters seem to be represented correctly, some of the vowels
and medials (and perhaps other items as well) seem to have some rendering
issues.

The issue we originally ran into was that the  U+103C MYANMAR CONSONANT
SIGN MEDIAL RA was misplaced, seeming to be placed following the consonant
instead of decorating it, as per http://unicode.org/notes/tn11/UTN11_3.pdf.
As a simple example, the string "ကြ" (represented by code points U+1000
U+103c), would appear as two separate characters "က ြ" instead of being
combined. If there was a character following that first "က", " ြ" would
incorrectly decorate the second character instead.

An example snippet, showing this behavior, which should show "ကြေး", but
seems to place the medial and vowel incorrectly:

# coding=utf-8
def main():
    from reportlab.pdfgen.canvas import Canvas
    from reportlab.pdfbase.ttfonts import TTFont
    from reportlab.pdfbase.pdfmetrics import registerFont
    from reportlab.lib.pagesizes import A10

    canv = Canvas('text-on-image.pdf',pagesize=A10)
    registerFont(TTFont('notosans','NotoSansMyanmar-Regular.ttf'))

    canv.setFont('notosans',14)
    canv.setFillColor((1,0,0)) #change the text color
    text = u"\u1000\u103C\u1031\u1038"
    canv.drawString(25,50,text)
    canv.save()

if __name__=='__main__':
    main()

This yields the following:
[image: image.png]

I've used the code points for it in the snippet, but you can see from
http://zawgyi-unicode-test.appspot.com/convertui/ how that should render:
[image: image.png]

And replacing with the actual characters in the code snippet doesn't
fix the issue.
image.png (image/png, 2 KB) - not displayed
image.png (image/png, 2.2 KB) - not displayed