Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andsmith opened this issue Apr 12, 2018 · 0 comments
Open

Comments

@andsmith
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant