镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

How to render stacked Tibetan letters #2572

Closed

Description

@serser

Hello Pillow folks, I've come across this issue with stacked texts in Tibetan (po-ed stackoverflow question here).

from PIL import Image, ImageFont, ImageDraw
import matplotlib.pyplot as plt

test_letters = [u'ཀ', u'ར',u"སྤ",u'རྐ',u'༄',u'ཀྱ',u'ཛྷ']

font = ImageFont.truetype("/Libarary/Fonts/Kokonor.ttf", 20, encoding='unic')

for letter in test_letters:
    img = Image.new("RGBA", (28, 28))
    draw = ImageDraw.Draw(img)
    draw.text((6, 0),letter,(0,0,0),font)
    plt.imshow(img)
    plt.grid()
    plt.show()

One of the output is like this one, displayed apart.
image.

There are some links on Tibetan font rendering, which might of some value.

  1. https://www.microsoft.com/typography/OpenTypeDev/tibetan/intro.htm
  2. http://digitaltibetan.org/index.php/Formatting_rules_for_Tibetan_text
  3. https://collab.its.virginia.edu/wiki/tibetan-script/Using%20Tibetan%20in%20Macintoshes.html

Thanks for any illumination.

Activity

  1. changed the title [-]How to render stacked Tibetan font with ImageFont, and ImageDraw [/-] [+]How to render stacked Tibetan letters with ImageFont, and ImageDraw [/+] on Jun 9, 2017
  2. wiredfool commented on Jun 9, 2017

    @wiredfool
    Member

    I suspect it's the same underlying issue that's fixed in #2284.

  3. serser commented on Jun 10, 2017

    @serser
    Author

    @wiredfool with libraqm compiled and installed, and pip installed Fahad-Alsaidi/Pillow@CTL branch, do I need to alter anything to solve this issue? It seems that the letters still don't stack.

  4. wiredfool commented on Jun 12, 2017

    @wiredfool
    Member

    If that's the case, then there are 3 possibilities:

    • The CTL branch didn't actually compile correctly and the feature isn't available. One issue with that PR is that the feature reporting is incorrect. I've got a fix, and another PR that it relied on is merged, so it's time to get back to that and push it off my machine. It's possible that you have raqm installed, but Pillow couldn't find harfbuzz or fribdi.
    • The CTL branch is supposed to handle this case, and doesn't do it correctly.
    • It's a separate issue. From a quick google, it does appear that harfbuzz is supposed to to Tibetan script, so I'm going to count this as unlikely.
  5. wiredfool commented on Jun 13, 2017

    @wiredfool
    Member

    So, I've got a branch where I'm testing out the complex text layout PR (#2576) and using the following script, I've got something that appears to match what I'm seeing in the browser and libreoffice on Ubuntu 16.04. This is using the font package 'fonts-tibetan-machine', and displaying the whole thing as one string rather than individual glyphs in matplotlib.

    issue_2572

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    from PIL import Image, ImageFont, ImageDraw
    
    test_str = u'ཀ ར སྤ རྐ ༄ ཀྱ ཛྷ'
    
    font = ImageFont.truetype("TibetanMachineUni.ttf", 40, encoding='unic')
    
    img = Image.new("RGBA", (320, 60), 'white')
    draw = ImageDraw.Draw(img)
    draw.text((6, 0),test_str,(0,0,0),font)
    img.save('issue_2572.png')

    To my eye, it looks correct, but I'm not an expert by any means.

    [edit] Now this is strange, it appears to just work without the complex text support as well, on my old 12.04 instance which doesn't have the pre-requisites for raqm. So maybe it's a font thing?

  6. hugovk commented on Jun 14, 2017

    @hugovk
    Member

    I get this on master (Python 2.7.13, macOS, with no RAQM pre-requisites):

    image

    And this on wiredfool/pr_2284:

    image

  7. wiredfool commented on Jun 14, 2017

    @wiredfool
    Member

    Is the top one a cropping issue, or is it a rendering thing?

  8. hugovk commented on Jun 14, 2017

    @hugovk
    Member

    Looks like rendering. With 640px width:

    image


    Highlighting for emphasis:
    image

  9. wiredfool commented on Jun 14, 2017

    @wiredfool
    Member

    That's odd. Wonder if it's a freetype version issue, or if it's a font thing. It looks like you have the same font, so that's not likely to be it.

  10. wiredfool commented on Jun 14, 2017

    @wiredfool
    Member

    Freetype version?

  11. hugovk commented on Jun 14, 2017

    @hugovk
    Member

    Freetype 2.7.1: /usr/local/Cellar/freetype/2.7.1

  12. wiredfool commented on Jun 14, 2017

    @wiredfool
    Member

    12.04:

    (vpy27)erics@builder-1204-x64:~/Pillow$ dpkg -l | grep -i freetype
    ii  libfreetype6                         2.4.8-1ubuntu2.4                    FreeType 2 font engine, shared library files
    

    16.04:

    (vpy27) erics@builder-16:~/Pillow$ dpkg -l | grep freetype
    ii  libfreetype6:amd64                2.6.1-0.1ubuntu2.3                         amd64        FreeType 2 font engine, shared library files
    

    Hmm.

  13. serser commented on Jun 14, 2017

    @serser
    Author

    Thanks @hugovk and @wiredfool It seems that fonts are handled with some preference. To notice although some of them are stacked, they are not rendered properly. Kokonor and Kailasa are default on macOS, and rendered all right when typed as texts.

    image

  14. wiredfool commented on Jun 16, 2017

    @wiredfool
    Member

    I've checked this with the mac fonts on an Ubuntu 16.04 machine, and it's the font, not the freetype version. So there's something different in the fonts.

  15. wiredfool commented on Jun 16, 2017

    @wiredfool
    Member

    @Fahad-Alsaidi Can you take a look at this and see if raqm + harfbuzz is properly parsing this as Tibetan and enabling the appropriate script options? If not, is there a way to override any detected script and pass in Tibetan, either as a feature or otherwise? (i.e., I'm seeing 'TIB ' and 'Tibt' in the harfbuzz source, but neither seem to affect the rendering)

  16. Fahad-Alsaidi commented on Jun 16, 2017

    @Fahad-Alsaidi
    Contributor

    well, have you tried this raqm_set_language (). I think this isn't implemented yet in the original PR.

  17. khaledhosny commented on Jun 16, 2017

    @khaledhosny

    Mac system fonts are likely to be AAT not OpenType fonts, so they will not work on Windows or Linux correctly. On Mac AAT fonts should work if HarfBuzz is compiled with Core Text support.

  18. added
    BugAny unexpected behavior, until confirmed feature.
    on Jun 21, 2017
  19. added this to the Future milestone on Jun 21, 2017
  20. changed the title [-]How to render stacked Tibetan letters with ImageFont, and ImageDraw [/-] [+]How to render stacked Tibetan letters[/+] on Oct 7, 2019
  21. radarhere commented on Oct 7, 2019

    @radarhere
    Member
  22. Attempt-Q commented on Dec 15, 2021

    @Attempt-Q

    Has the problem been solved, can anyone help me?

  23. radarhere commented on Feb 10, 2022

    @radarhere
    Member

    #2576 was merged, which included #2284. Testing with a font downloaded from the web, the raqm support added there resolves this.

    Current Pillow without raqm.
    out_0
    out_1
    out_2
    out_3
    out_4
    out_5
    out_6

    Current Pillow with raqm.
    out_0
    out_1
    out_2
    out_3
    out_4
    out_5
    out_6

    I've also tested this with our CI jobs to confirm that it passes on Linux, macOS and Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugAny unexpected behavior, until confirmed feature.Fonts

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions