-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Characters doesn't display correctly when figure saved as pdf with a custom font #12636
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
Indeed, there is currently no support for subsetting otf fonts, i.e. including only the glyphs that are needed (we do this for ttf; for large fonts such as cjk this can mean megabytes of data). More curious is the bad rendering by certain pdf readers: I get correct rendering with chromium and zathura, and incorrect rendering (with different glyphs) with acroread and okular. I think this specific part qualifies as a bug (subsetting is more of a feature request, desirable but likely to require a bit of work...). As a workaround, you can use the cairo-based backends (either the builtin one -- which suffers from some other issues, e.g. you don't actually have much control over the font used --; or https://github.com/anntzer/mplcairo, which works better) which will properly subset the font (cairo has code for that) and generate pdfs that all readers I've tested render correctly. |
I've tried mplcairo and the builtin cairo. And get 4 kinds of output. Restarted jupyter notebook kernel before each example. 1st example (
|
I realized there's a bug on mplcairo+windows, I'll look into fixing it (some symbol loading not yet implemented...); I only had it working on Linux/OSX so far. |
I uploaded a new wheel for mplcairo (v0.1.post28) at https://github.com/anntzer/mplcairo/releases/tag/nightly which you can download and install with pip. |
@anntzer Thanks for the nightly built wheel, besides the cp36-linux and cp37-win, any chance to upload a cp36-win-64? Sorry for the inconvenience. And another thing, regards the difference of figsize I posted earlier, it seems that give figsize and dpi explicitly like |
Done. |
It works. I can save it to .ps and then convert it to .pdf. Thank you. |
By the way, can you confirm that direct pdf output also fails for you? |
I tried the same code as I opened the
|
Indeed, the issue seems to come from the specific cairo build I'm using (https://preshing.com/20170529/heres-a-standalone-cairo-dll-for-windows/#IDComment1047546463). Happy to get help on that if anyone can look into it... |
Actually I found a (hackish) way to get a better cairo.dll that should render pdf correctly, can you try with the new wheels at https://github.com/anntzer/mplcairo/releases/tag/nightly? |
It works. Thanks very much. Can I use both mplcairo and |
You can set the environment variable |
Problem description:
When using a custom font, saving the figure as pdf format, and then opening the pdf with adobe reader (or many other pdf readers except SumatraPDF), some characters don't display correctly.
I use windows 10 operating system. The font is for the Chinese language, and already install into
C:\windows\fonts
Check the font
Output:
Generate the figure
Code (a minimal and fully example)
There will be a warning message:
And the output in the notebook and the png format both displays correctly:

But when open

figure_with_font.pdf
with "adobe reader", it displays like:When I check the document properties, it seems like the font is already embedded in the pdf:

I've tried some other readers, only Sumatra PDF works.
**I'm using: **
And The output pdf file:
figure_with_font.pdf
Question:
The text was updated successfully, but these errors were encountered: