-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Comments
Actually that's a limitation of FT2Font. (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...) |
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? |
When running
|
You don't want to run |
Thanks! The installation got a bit further this time, but ends with
I had installed clang via homebrew llvm as instructed in the Build section. |
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. |
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:
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:
Τhen I ran my code again and got So much better! But monochrome? 😩😤 And other colors are off too. |
Not sure what's happening with monochrome but...
Also, can you check your version of |
Installed the wheel so I can import mplcairo systemwide. Ran a standalone script outside the notebook by importing mplcairo (owing to your I'm using cairo 1.18.0. |
That's the pycairo version (I know, it's confusing :/). Still not sure why it's failing for you... |
Likely, indeed. How did you install pycairo? |
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 ( |
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). |
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? |
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. |
What is your |
Also, I guess this is with 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? |
Always happy to help. After all, you caught a bug and a typo in mplcairo :) |
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 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 IOW: My guess is that these are all upstream issues that I can't do anything about :( |
The
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: Maybe @xen must know. He is Python expert and FontForge member.
Modify mplcairo or harfbuzz or both? |
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. |
What does |
It is true. I'll install it. |
Looks like it's already 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? ( |
It seems that
I did and recompiled. But the output is still the same:
And OS details:
|
Thanks. I'm a bit confused why it's not working; try calling |
I am not sure if this output is what you are looking for:
|
Observe that I use a virtual environment of Python in my project. |
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 |
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... |
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. |
Sorry guys, I'm not competent enough to help you here. Possible Dave @davelab6 can help to find right person. |
Sorry for hijacking. Let me know if a new thread is preferred instead!
Hi @anntzer, I just tried this with example code from https://stackoverflow.com/a/55340988 but it doesn't work. An empty plot appears. Am I missing something? Any help appreciated! |
Let's keep track of that on the mplcairo issue you opened. |
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! |
Still a valid request. |
I'm going to try and see if I can get this in with the font shaping work. |
@QuLogic I saw you mentioned in this week's meeting notes that raqm is working "except font fallback". This is very exciting :-) |
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. |
Uh oh!
There was an error while loading. Please reload this page.
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.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
Matplotlib version
Related StackOverflow question.
The text was updated successfully, but these errors were encountered: