Distrotech / reportlab

Mirror of https://bitbucket.org/rptlab/reportlab
Other
59 stars 42 forks source link

Reportlab won't add some (SMP) characters in truetype fonts to PDF. #8

Open andsmith opened 6 years ago

andsmith commented 6 years ago

I can't add characters from the Supplementary Multilingual Plane (SMP), using TrueType fonts. I downloaded a few fonts for Egyptian hieroglyphs and cuneiform characters to add them to a PDF, however, it doesn't seem to work.

Here's my python (2.7) code using the reportlab package:

from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

if __name__ == "__main__":
    # register fonts
    pdfmetrics.registerFont(TTFont('gardiner', '/usr/share/fonts/truetype/ttf-ancient-scripts/Gardiner313.ttf'))
    pdfmetrics.registerFont(TTFont('aegyptus', '/usr/share/fonts/truetype/ttf-ancient-scripts/Aegyptus313.ttf'))
    pdfmetrics.registerFont(TTFont('noto', 'NotoSansCuneiform-Regular.ttf'))

    # Test with first 20 glphs in each block
    hieroglyph_test_string = " ".join([unichr(0x13000 + x) for x in range(20)])
    cuneiform_test_string = "  ".join([unichr(0x12000 + x) for x in range(20)])

    my_canvas = canvas.Canvas("bmp1_test.pdf", pagesize=letter)

    y_pos, y_decrement = [letter[1] - 50], 50

    def test_font(font_name, chars):
        my_canvas.setFont(font_name, 20)
        my_canvas.drawString(50, y_pos[0], chars)
        y_pos[0] -= y_decrement
        print "\nWrote:  %s\n" % (chars,)

    test_font('gardiner', hieroglyph_test_string)
    test_font('aegyptus', cuneiform_test_string)
    test_font('noto', cuneiform_test_string)

    my_canvas.save()

But it just displays as boxes in the PDF.

I know the fonts are installed, because the chars print on my terminal just fine.

Are there any steps I'm missing here?