8000 Cannot render Apple Color Emoji in plots · Issue #12830 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
10000

Cannot render Apple Color Emoji in plots #12830

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

Open
brienna opened this issue Nov 18, 2018 · 50 comments
Open

Cannot render Apple Color Emoji in plots #12830

brienna opened this issue Nov 18, 2018 · 50 comments
Assignees
Labels
keep Items to be ignored by the “Stale” Github Action topic: text/fonts

Comments

@brienna
Copy link
brienna commented Nov 18, 2018

Bug report

In both Jupyter Notebook and Terminal, I cannot display emojis using the Apple Color Emoji font.

If I attempt to set fontname='Apple Color Emoji' matplotlib won't find the font, and falls back to the default font DejaVu Sans, which renders the image below.

download 2

If I try to load the font using font_manager.FontProperties, it throws an error: RuntimeError: In FT2Font: Could not set the fontsize.

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
import numpy as np

prop = FontProperties(fname='/System/Library/Fonts/Apple Color Emoji.ttc')

freqs = [301, 96, 53, 81, 42]
labels = ['😊', '😱', '😂', '😄', '😛']
plt.figure(figsize=(12,8))
p1 = plt.bar(np.arange(len(labels)), freqs, 0.8, color="lightblue")
new_ylim = plt.ylim()[1]+30
plt.ylim(0, new_ylim)

# Make labels
for rect1, label in zip(p1, labels):
    height = rect1.get_height()
    plt.annotate(
        label,
        (rect1.get_x() + rect1.get_width()/2, height+5),
        ha="center",
        va="bottom",
        #fontsize='30',
        #fontname='Apple Color Emoji'
        fontproperties = prop
    )
    
plt.show()

Matplotlib version

  • Operating system: MacOS Sierra 10.12.6
  • Matplotlib version: 2.2.3
  • Matplotlib backend: MacOSX and module://ipykernel.pylab.backend_inline
  • Python version: Python 3.7.0
  • Jupyter version (if applicable): 5.6.0

Related StackOverflow question.

@ImportanceOfBeingErnest
Copy link
Member

Similar problem: #4492

It seems this somehow worked by coincidence. But as commented on the SO post already, one would start by using the codes that are reported to work in #4492 and see where the difference is.

@ImportanceOfBeingErnest ImportanceOfBeingErnest added the Community support Users in need of help. label Nov 18, 2018
@anntzer
Copy link
Contributor
anntzer commented Nov 18, 2018

Actually that's a limitation of FT2Font.
I couldn't get my hands on Apple Color Emoji.ttc, but at least with Apple Color Emoji.ttf, things work if you use the mplcairo backend (https://github.com/anntzer/mplcairo), and I have no reason to believe that the ttc version would be different.

(The fact that setting the fontname instead of the path doesn't work for ttc files "should" be fixed by #9787, which "just" waits for a second review...)

@anntzer anntzer added topic: text and removed Community support Users in need of help. labels Nov 18, 2018
@brienna
Copy link
Author
brienna commented Nov 18, 2018

According to #3135, ttc font support is limited as well. It would be nice if we have #9787...

@anntzer, I can't seem to build the wheels with mplcairo, using OS X.

@anntzer
Copy link
Contributor
anntzer commented Nov 18, 2018

There are some instructions at https://github.com/anntzer/mplcairo#building. Can you let me know what specific issues you are having with the build?

@brienna
Copy link
Author
brienna commented Nov 19, 2018

When running clang build-osx-wheel.sh:

ld: warning: ignoring file build-osx-wheel.sh, file was built for unsupported file format ( 0x23 0x21 0x2F 0x62 0x69 0x6E 0x2F 0x62 0x61 0x73 0x68 0x0A 0x0A 0x23 0x20 0x42 ) which is not the architecture being linked (x86_64): build-osx-wheel.sh
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

@anntzer
Copy link
Contributor
anntzer commented Nov 19, 2018

You don't want to run clang build-osx-wheel.sh, but just ./build-osx-wheel.sh (or even python setup.py bdist_wheel should be good enough (modulo dependencies) given that you just want to use the wheel locally).

@brienna
Copy link
Author
brienna commented Nov 19, 2018 8000

Thanks! The installation got a bit further this time, but ends with

src/_feature_tests.cpp:3:4: error: "A compiler supporting C++17 is required."
  #error "A compiler supporting C++17 is required."
   ^
1 error generated.
error: command 'x86_64-apple-darwin13.4.0-clang' failed with exit status 1

I had installed clang via homebrew llvm as instructed in the Build section.

@anntzer
Copy link
Contributor
anntzer commented Nov 19, 2018

Well, that's what the error message says: your version of clang is too old. You can install a more recent version with homebrew or conda, then make sure it is active.

@brienna
Copy link
Author
brienna commented Nov 19, 2018

Two things were important: To git clone the repo instead of downloading it, and to make sure that llvm's compiler variables were set correctly before installing:

echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
export CC='/usr/local/opt/llvm/bin/clang'
export CXX='/usr/local/opt/llvm/bin/clang++'
tools/build-osx-wheel.sh

I moved build > lib.macosx-10.9-x86_64-3.7 > mplcairo to my repo where I had my code, and in Jupyter Notebook added:

import mplcairo
matplotlib.use("module://mplcairo.macosx")
print(matplotlib.get_backend())

Τhen I ran my code again and got

screen shot 2018-11-18 at 11 27 57 pm

So much better! But monochrome? 😩😤 And other colors are off too.

@anntzer
Copy link
Contributor
anntzer commented Nov 19, 2018

Not sure what's happening with monochrome but...

  1. You need to install the wheel (that's in the dist directory) with pip install /path/to/mplcairo-etc-etc.whl.
  2. Making things work in the notebook is a bit hackish (does it work better if you run a standalone script outside of the notebook?), however (having installed the wheel as above) things should work in the notebook if you set the MPLCAIRO_PATCH_AGG environment variable to 1 before starting the jupyter server (e.g. MPLCAIRO_PATCH_AGG=1 jupyter notebook), as documented in https://github.com/anntzer/mplcairo#use.

Also, can you check your version of cairo? (mplcairo._mplcairo.__cairo_version__) It needs to be at least 1.15.8 for color emoji support (https://www.phoronix.com/scan.php?page=news_item&px=Cairo-1.15.8-Colored-Emoji). And let's also get the freetype version (mplcairo._mplcairo.__freetype_version__) while we're at it.

@brienna
Copy link
Author
brienna commented Nov 19, 2018

Installed the wheel so I can import mplcairo systemwide.

Ran a standalone script outside the notebook by importing mplcairo (owing to your MPLCAIRO_PATCH_AGG and MacOSX backend incompatibility notes), as well as running in Jupyter using MPLCAIRO_PATCH_AGG=1 jupyter notebook. Both approaches yield the same monochromatic emojis.

I'm using cairo 1.18.0.

@anntzer
Copy link
Contributor
anntzer commented Nov 19, 2018

I'm using cairo 1.18.0.

That's the pycairo version (I know, it's confusing :/).
The cairo version is accessible as import mplcairo._mplcairo; print(mplcairo._mplcairo.__cairo_version__); can you check that, and the freetype version too (as above)?
Also, perhaps try some other color emoji font, e.g. Noto Color Emoji (https://github.com/googlei18n/noto-emoji/tree/master/fonts)?

Still not sure why it's failing for you...

@brienna
Copy link
Author
brienna commented Nov 19, 2018

mplcairo._mplcairo.__cairo_version__ = 1.14.12
mplcairo._mplcairo.__freetype_version__ = 2.9.1

I switched to Noto Color Emoji but it still is monochromatic. Probably because I need to somehow upgrade the in-package cairo version to >= 1.15.8...

screen shot 2018-11-19 at 12 09 44 pm

@anntzer
Copy link
Contributor
anntzer commented Nov 19, 2018

Likely, indeed. How did you install pycairo?
At least homebrew appears to have cairo 1.16 available.

@brienna
Copy link
Author
brienna commented Nov 19, 2018

I had installed pycairo using conda-forge as per the Use instructions.

If I open the python3 environment in Terminal and check pycairo version it says 1.18.0.

I had installed cairo 1.16.0 via brew as well, but can't seem to access it (ModuleNotFoundError: No module named 'cairo'). I'm working on this.

@anntzer
Copy link
Contributor
anntzer commented Nov 19, 2018

I guess best would be to bug conda-forge to update their version of cairo... looks like it just needs to be merged on their side (conda-forge/cairo-feedstock#44).
If you don't want to wait you need to install cairo from homebrew and then pycairo from source (i.e. pip install pycairo after uninstalling the conda-forge version of pycairo).

@brienna
Copy link
Author
brienna commented Nov 19, 2018

Emojis are colored now!

screen shot 2018-11-19 at 1 02 38 pm

Do you have any idea why the colors keep getting rendered so strangely? I'm trying to look through your docs for color specs but cannot seem to find any instructions on this. If I set color="red" for example, it will turn the bars blue.

@anntzer
Copy link
Contributor
anntzer commented Nov 19, 2018

Probably because cairo and agg internally represent the red/green/blue channels in a different order, which should be accounted for but perhaps something's amiss. Does this happen outside of the notebook too?

@brienna
Copy link
Author
brienna commented Nov 19, 2018

Yes, it looks the same outside the notebook. I find it promising that the emojis are no longer monochromatic, though. Now to figure out the color problem.

@anntzer
Copy link
Contributor
anntzer commented Nov 19, 2018

What is your sys.byteorder?

@anntzer
Copy link
Contributor
anntzer commented Nov 19, 2018

Also, I guess this is with module://mplcairo.macosx? Do you have the same problem with module://mplcairo.tk?

Edit: pushed a new commit to the mplcairo repo (you'll need to update your clone), I think this should fix the issue, can you check?

@brienna
Copy link
Author
brienna commented Nov 20, 2018

module://mplcairo.tk works!

Pip uninstalled mplcairo, updated my clone, pip installed mplcairo again, and module://mplcairo.macosx works now as well!

screen shot 2018-11-19 at 11 02 30 pm

Thank you so much for your continued assistance in resolving this.

@anntzer
Copy link
Contributor
anntzer commented Nov 20, 2018

Always happy to help. After all, you caught a bug and a typo in mplcairo :)

@anntzer
Copy link
Contributor
anntzer commented Feb 21, 2021

There's two separate issues at hand here: color and flags (which are really ligatures).

For the DE->flag problem, this arises specifically because emoji fonts rely on ligatures to do the conversion, which can only be done by harfbuzz... but even though harfbuzz supports this, things run into another issue which causes subsequent glyphs to be misplaced (described at harfbuzz/harfbuzz#2428). So I expressly disabled ligature handling for color fonts (you can comment out the chunk of code that sets the &detail::IS_COLOR_FONT_KEY entry in _util.cpp in the mplcairo sources to play with that) so that at least glyphs get positioned more or less reasonably, even though they may not be the ones you want (you have to compromise one way or the other).

For color, my guess is that FreeType or cairo doesn't handle them yet; note that even on chromium (linux) they are not supported:

<html>
<head>
<style>
@font-face {
    font-family: TCE;
    src: url(TwitterColorEmoji-SVGinOT.ttf);
}
.tce{
    font-family: TCE;
}
@font-face {
    font-family: JP;
    src: url(JoyPixels.ttf);
}
.jp{
    font-family: JP;
}
@font-face {
    font-family: NCE;
    src: url(NotoColorEmoji.ttf);
}
.nce{
    font-family: NCE;
}
</style>
</head>
<body>
<div>hello, world</div>
<p>twittercoloremoji<div class="tce">🇩🇪</div></p>
<p>joypixels<div class="jp">🇩🇪</div></p>
<p>notocoloremoji<div class="nce">🇩🇪</div></p>
</body>
</html>

gives
chromium
for me.
(Interestingly, Firefox does handle things fine, though.)
It may be worth trying to write a minimal C example (like the one I wrote for the harfbuzz issue above) to test/repro this; this is left as an exercise to the reader.

IOW: My guess is that these are all upstream issues that I can't do anything about :(

@gusbemacbe
Copy link

So I expressly disabled ligature handling for color fonts (you can comment out the chunk of code that sets the &detail::IS_COLOR_FONT_KEY entry in _util.cpp in the mplcairo sources to play with that)

The mplcairo packages is all in Python, so do I have to clone your repo, modify the _util.cpp file and compile?

For color, my guess is that FreeType or cairo doesn't handle them yet; note that even on chromium (linux) they are not supported:

(Interestingly, Firefox does handle things fine, though.)

You are right that Firefox supports all emoji fonts, inclusive Apple Emoji. Observe that @xem's Twemoji font rendered the emoji colour on Chrome and Edge:

imagem

Maybe @xen must know. He is Python expert and FontForge member.

It may be worth trying to write a minimal C example (like the one I wrote for the harfbuzz issue above) to test/repro this; this is left as an exercise to the reader.

Modify mplcairo or harfbuzz or both?

@gusbemacbe
Copy link

Since it will be complicated, as the only solution is that, I will have to replace the emojis for PNG images, but I am unable to display the images as [x,y]sticklabels. I have already posted on Stack Overflow, but @ImportanceOfBeingErnest no longer appeared since August 2020.

@gusbemacbe
Copy link

I cloned the mplcairo repo, modified the _util.cpp to remove the &detail::IS_COLOR_FONT_KEY and compiled, and reinstalled with force the compiled wheel package, but it did not trigger correctly the flag, maybe I misunderstood your example:

imagem

@anntzer
Copy link
Contributor
anntzer commented Feb 21, 2021

What does mplcairo.get_options() return? If the "raqm" entry is false, try calling mplcairo.set_options(raqm=True); if that raises an exception, that means you'll need to install https://github.com/HOST-Oman/libraqm (which is a small wrapper around harfbuzz).

@gusbemacbe
Copy link

What does mplcairo.get_options() return?

{'cairo_circles': True,
 'float_surface': False,
 'marker_threads': 0,
 'miter_limit': 10.0,
 'raqm': True,
 '_debug': False}

It is true. I'll install it.

@anntzer
Copy link
Contributor
anntzer commented Feb 21, 2021

Looks like it's already True (installed) for you. To be clear, the necessary patch is

diff --git i/src/_util.cpp w/src/_util.cpp
index 66b1b3e..63db0a3 100644
--- i/src/_util.cpp
+++ w/src/_util.cpp
@@ -671,9 +671,9 @@ cairo_font_face_t* font_face_from_path(std::string pathspec)
             || tag == FT_MAKE_TAG('C', 'B', 'L', 'C')
             || tag == FT_MAKE_TAG('s', 'b', 'i', 'x')
             || tag == FT_MAKE_TAG('S', 'V', 'G', ' ')) {
-          CAIRO_CHECK_SET_USER_DATA(
-            cairo_font_face_set_user_data,
-            font_face, &detail::IS_COLOR_FONT_KEY, font_face, nullptr);
+          // CAIRO_CHECK_SET_USER_DATA(
+          //   cairo_font_face_set_user_data,
+          //   font_face, &detail::IS_COLOR_FONT_KEY, font_face, nullptr);
           break;
         }
       }

With this patch, I correctly get the flags (except, as stated above for Twitter Color Emoji). If you don't, perhaps also check the versions of your libs? (mplcairo.get_versions(), although that doesn't report the harfbuzz version so please report that as well)

@gusbemacbe
Copy link
gusbemacbe commented Feb 21, 2021

It seems that libraqm is already installed before.

Looks like it's already True (installed) for you. To be clear, the necessary patch is

I did and recompiled. But the output is still the same:

{'cairo_circles': True,
 'float_surface': False,
 'marker_threads': 0,
 'miter_limit': 10.0,
 'raqm': True,
 '_debug': False}

If you don't, perhaps also check the versions of your libs?

Package             Version
------------------- -------------------
ipykernel           5.5.0
ipyplot             1.1.0
ipython             7.20.0
ipython-genutils    0.2.0
ipywidgets          7.6.3
jupyter-client      6.1.11
jupyter-core        4.7.1
jupyter-server      1.4.0
jupyterlab          3.0.8
jupyterlab-pygments 0.1.2
jupyterlab-server   2.3.0
jupyterlab-widgets  1.0.0
mplcairo            0.3.post71+gd4dc1f5
nbclassic           0.2.6
nbclient            0.5.2
nbconvert           6.0.7
nbformat            5.1.2
networkx            2.5
notebook            6.2.0
numpy               1.20.1
opencv-python       4.5.1.48
pandas              1.2.2
pandocfilters       1.4.3
Pillow              8.1.0
pycairo             1.20.0
PyQt5               5.15.2
PyQt5-sip           12.8.1
qgrid               1.3.1
qt5-applications    5.15.2.2.1
scikit-image        0.18.1
scikit-learn        0.24.1
scipy               1.6.1
seaborn             0.11.1
six                 1.15.0
sklearn-pandas      2.0.4
svgutils            0.3.4
tornado             6.1
traitlets           5.0.5

although that doesn't report the harfbuzz version so please report that as well)

  • harfbuzz: 2.7.4-1
  • cairo: 1.17.4-3
  • freetype2: 2.10.4-1
  • libraqm: 0.7.1-1

And OS details:

  • Distro: Manjaro Linux
  • Kernel: Linux 5.9.16
  • Desktop environment: Sway
  • Display: Wayland

@anntzer
Copy link
Contributor
anntzer commented Feb 21, 2021

Thanks. I'm a bit confused why it's not working; try calling mplcairo.set_options(_debug=True) before everything else and report the output?

@gusbemacbe
Copy link

Thanks. I'm a bit confused why it's not working; try calling mplcairo.set_options(_debug=True) before everything else and report the output?

I am not sure if this output is what you are looking for:

Default backend: module://mplcairo.qt
Backend is now module://mplcairo.qt
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: lp
glyph: 0	x: 0.0	y: 0.0
glyph: 0	x: 37.35378440366973	y: 0.0
string: 🇩🇪 😀
glyph: 208	x: 0.0	y: 0.0
glyph: 209	x: 37.43119266055046	y: 0.0
glyph: 3	x: 74.86238532110092	y: 0.0
glyph: 883	x: 112.21616972477065	y: 0.0
string: 🇩🇪 😀
glyph: 208	x: 0.0	y: 0.0
glyph: 209	x: 37.43119266055046	y: 0.0
glyph: 3	x: 74.86238532110092	y: 0.0
glyph: 883	x: 112.21616972477065	y: 0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 🇩🇪 😀
glyph: 208	x: 0.0	y: 0.0
glyph: 209	x: 37.43119266055046	y: 0.0
glyph: 3	x: 74.86238532110092	y: 0.0
glyph: 883	x: 112.21616972477065	y: 0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: lp
glyph: 79	x: 0.0	y: -0.0
glyph: 83	x: 2.78125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: lp
glyph: 0	x: 0.0	y: 0.0
glyph: 0	x: 37.35378440366973	y: 0.0
string: 🇩🇪 😀
glyph: 208	x: 0.0	y: 0.0
glyph: 209	x: 37.43119266055046	y: 0.0
glyph: 3	x: 74.86238532110092	y: 0.0
glyph: 883	x: 112.21616972477065	y: 0.0
string: 🇩🇪 😀
glyph: 208	x: 0.0	y: 0.0
glyph: 209	x: 37.43119266055046	y: 0.0
glyph: 3	x: 74.86238532110092	y: 0.0
glyph: 883	x: 112.21616972477065	y: 0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.0
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 0.2
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 21	x: 9.53125	y: -0.0
string: 0.4
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 23	x: 9.53125	y: -0.0
string: 0.6
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 25	x: 9.53125	y: -0.0
string: 0.8
glyph: 19	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 27	x: 9.53125	y: -0.0
string: 1.0
glyph: 20	x: 0.0	y: -0.0
glyph: 17	x: 6.359375	y: -0.0
glyph: 19	x: 9.53125	y: -0.0
string: 🇩🇪 😀
glyph: 208	x: 0.0	y: 0.0
glyph: 209	x: 37.43119266055046	y: 0.0
glyph: 3	x: 74.86238532110092	y: 0.0
glyph: 883	x: 112.21616972477065	y: 0.0

@gusbemacbe
10000
Copy link

Observe that I use a virtual environment of Python in my project.

@anntzer
Copy link
Contributor
anntzer commented Feb 21, 2021

Yes, this is what I was looking for. Seems like ligature handling is indeed not being triggered. It's going to require a bit of low-level debugging, but at

GlyphsAndClusters text_to_glyphs_and_clusters(cairo_t* cr, std::string s)
{
  auto const& scaled_font = cairo_get_scaled_font(cr);
  auto gac = GlyphsAndClusters{};
  if (has_raqm()
      && !cairo_font_face_get_user_data(cairo_get_font_face(cr),
                                        &detail::IS_COLOR_FONT_KEY)) {

can you add prints the values of has_raqm() and cairo_font_face_get_user_data(cairo_get_font_face(cr), &detail::IS_COLOR_FONT_KEY)? (I would suggest using plt.figtext() to just draw a single string of text without drawing axes, or using set_xticks([])/set_yticks([]) to suppress axis ticks, to prevent them from mixing with the rest of the output.)

@gusbemacbe
Copy link

Yes, this is what I was looking for. Seems like ligature handling is indeed not being triggered. It's going to require a bit of low-level debugging, but at

I added this to the _util.h. The _util.cpp has already it. I recompiled and reinstalled with force. But it failed:

imagem

@anntzer
Copy link
Contributor
anntzer commented Feb 21, 2021

This is your python source, not the C++ source. If you are not experienced with working with C(++) extensions, this is a rather complex topic for which I unfortunately cannot offer an in-depth tutorial here...

@gusbemacbe
Copy link

Ah, I am very sorry, I confounded Python with C++. But all OK. Then I will use the images instead of emojis, as the only solution.

@xen
Copy link
xen commented Feb 24, 2021

Sorry guys, I'm not competent enough to help you here. Possible Dave @davelab6 can help to find right person.

@jingxuanlim
Copy link
jingxuanlim commented Feb 4, 2023

Sorry for hijacking. Let me know if a new thread is preferred instead!

  1. Making things work in the notebook is a bit hackish (does it work better if you run a standalone script outside of the notebook?), however (having installed the wheel as above) things should work in the notebook if you set the MPLCAIRO_PATCH_AGG environment variable to 1 before starting the jupyter server (e.g. MPLCAIRO_PATCH_AGG=1 jupyter notebook), as documented in https://github.com/anntzer/mplcairo#use.

Hi @anntzer, I just tried this with example code from https://stackoverflow.com/a/55340988 but it doesn't work. An empty plot appears.

image

Am I missing something? Any help appreciated!

@anntzer
Copy link
Contributor
anntzer commented Feb 4, 2023

Let's keep track of that on the mplcairo issue you opened.

Copy link
github-actions bot commented Nov 8, 2024

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Nov 8, 2024
@anntzer
Copy link
Contributor
anntzer commented Nov 8, 2024

Still a valid request.

@story645 story645 added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Nov 8, 2024
@QuLogic QuLogic self-assigned this Feb 27, 2025
@QuLogic
Copy link
Member
QuLogic commented Feb 27, 2025

I'm going to try and see if I can get this in with the font shaping work.

@anntzer
Copy link
Contributor
anntzer commented Feb 27, 2025

@QuLogic I saw you mentioned in this week's meeting notes that raqm is working "except font fallback". This is very exciting :-)
Regarding font fallback, it looks like the "proper" approach (as described by the author of raqm...) is the one described at https://tex.stackexchange.com/questions/520034/fallback-for-harfbuzz-fonts#comment1315285_520048, which I have tried to implement for mplcairo (raqm's API should be enough to implement it, by relying on raqm_set_freetype_face_range) but is actually a bit tedious to do...

@QuLogic
Copy link
Member
QuLogic commented Feb 27, 2025

Yep, that is in fact what I'm following (I think you had the link in mplcairo), but running into some issues with it not actually doing it. I think there may be some cache interfering, so I'm going to try to layout from scratch for every fallback, but that is as you say a bit tedious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action topic: text/fonts
Projects
None yet
Development

No branches or pull requests

8 participants
0