GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Bug]: Font rendering bug for Devanagari text · Issue #23082 · matplotlib/matplotlib

[Bug]: Font rendering bug for Devanagari text #23082

New issue
Copy link
New issue
Copy link
Closed
#30000
Closed
[Bug]: Font rendering bug for Devanagari text#23082
#30000
Copy link
Assignees
QuLogic
Labels
topic: text/fonts
Milestone
v3.11.0

Description

@kach
kach
opened on May 20, 2022
Issue body actions

Bug summary

When rendered as part of a graph's axis label or title, Devanagari text renders incorrectly: the "matras" get affixed to the wrong letters (see the attached image, and note the difference between the string literal in the code and the rendered text in the title of the graph).

Code for reproduction

from matplotlib import pyplot as plt
import matplotlib
matplotlib.rc('font', family='Devanagari Sangam MN')
matplotlib.rc('font', size=18)

plt.title('किसान')

Actual outcome

image

Expected outcome

The rendered word should look the same as in the string literal in the code.

Additional information

No response

Operating system

macOS

Matplotlib Version

3.4.1

Matplotlib Backend

module://ipykernel.pylab.backend_inline

Python version

Python 3.9.12

Jupyter version

6.3.0

Installation

pip

Reacted by Sohang Chopra

Activity

  1. tacaswell commented on May 20, 2022

    @tacaswell
    tacaswell
    on May 20, 2022
    Member
    More actions

    I'm going to start by apologizing that I know nothing more about Devanagari rendering than this issue and a very quick skimming of it's wikipedia entry.

    It looks like the matras is a vowel diacritic that combines with the letter to its left, where as the other vowels appear below or to the right (ref https://en.wikipedia.org/wiki/Devanagari#Vowel_diacritics). Do these render correctly or are all vowels broken?
    It also looks like there are also ligatures between some consonants, do those render correctly?

    I am not sure off the top of my head if we are doing the detailed text layout here or freetype is, but it is clear that the diacritic is not being handled correctly.

    A couple questions:

    • does it work with other fonts? We have seen issues where the fonts have errors in their metadata about the size of the glyphs which results in incorrect layouts
    • does it work if you use https://github.com/matplotlib/mplcairo ? That under the hood uses a different text layout engine which does RTL correctly so it is likely it will also handle this case correctly.
  2. tacaswell commented on May 20, 2022

    @tacaswell
    tacaswell
    on May 20, 2022
    Member
    More actions

    One more detail: we are rendering the text in the order it comes in in the string:

    In [1]: list('किसान')
    Out[1]: ['क', 'ि', 'स', 'ा', 'न']
    
    Reacted by Sohang Chopra
  3. kach commented on May 20, 2022

    @kach
    kach
    on May 20, 2022
    Author
    More actions

    Hi Thomas,

    No apology necessary, thank you for looking into this issue. :)

    Your understanding is correct. All other vowels are fine. 'क' + 'ि' is "special" in the sense that the 'ि' needs to be rendered to the left of the 'क'.

    image

    • The problem persists when I use a different (Devanagari-compatible) font.
    • I don't know how to use mplcairo, but you should be able to run the experiment using the code snippet I shared above. On Macs that font is built-in.

    The consonant-consonant ligatures "work" in the sense that they are not wrong, but not ideal. The Devanagari script has special ligatures for each pair of consonant-ligatures, but there is also a generic way to write them by adding the "halanth" diacritic ([्]) to the first consonant. Matplotlib seems to just use the generic form everywhere. See below (compare to the respective string literals in Python):

    image

  4. tacaswell commented on May 20, 2022

    @tacaswell
    tacaswell
    on May 20, 2022
    Member
    More actions

    Looking at the last example , it looks like the shaping on 'ि' is such that it goes over a the whole ligature?

    Unfortunately, I do not think this is going to be an easy fix (it is possible that we are clipping something to be positive that should be negative to move the diacritic to the left), but I suspect that our text system is not currently up to this.

  5. kach commented on May 20, 2022

    @kach
    kach
    on May 20, 2022
    Author
    More actions

    Hi Thomas,

    You're right, the 'ि' should loop around the entire consonant cluster, though there are exceptions. For example, in मूर्ति the little arc above the त that makes it र्त should be "outside" the matra.

    I do need to produce graphs with (correct) Devanagari labels on them. Do you have recommendations on how to proceed?

  6. anntzer commented on May 20, 2022

    @anntzer
    anntzer
    on May 20, 2022
    Contributor
    More actions

    Unless I am mistaken, this is basically a duplicate of #8765.

  7. tacaswell commented on May 20, 2022

    @tacaswell
    tacaswell
    on May 20, 2022
    Member
    More actions

    The fastest thing is probably to use mplcairo

    so

    import matplotlib
    matplotlib.use('module://mplcairo.qt')
    matplotlib.rc('font', family='Noto Sans Devanagari')  # I already had NoTo installed
    import matplotlib.pyplot as plt
    plt.title('किसान')

    I am not sure how hard it would be to get mplcairo to play nice with inline, but if you need to save the output you are good to go!

    If you definitly need images in a notebook, I think the way to go is module://mplcairo.base and then rely on the repr of a Figure is a png of it it.

  8. oscargus
    added
    topic: text/fonts
    on Jun 4, 2022
  9. QuLogic
    self-assigned this
    on Feb 27, 2025
  10. QuLogic
    added this to Font and text overhaulon Jun 5, 2025
  11. QuLogic
    moved this from Waiting for other PR to In Progress in Font and text overhaulon Jun 5, 2025
  12. github-project-automation
    moved this to Waiting for other PR in Font and text overhaulon Jun 5, 2025
  13. QuLogic
    added this to the v3.11.0 milestone on Jun 5, 2025
  14. QuLogic
    linked a pull request that will close this issueImplement text shaping with libraqm #30000on Aug 8, 2025
  15. QuLogic commented on Apr 10, 2026

    @QuLogic
    QuLogic
    on Apr 10, 2026
    Member
    More actions

    The text-overhaul branch is now merged to main.

  16. QuLogic
    closed this as completedon Apr 10, 2026
  17. github-project-automation
    moved this from In Progress to Done in Font and text overhaulon Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @QuLogic
    QuLogic

Labels

topic: text/fonts

Type

No type

Projects

  • Font and text overhaul
    Status
    Done
    Show more project fields

Milestone

  • v3.11.0

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.