Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement multi-font embedding for PDF Backend #20804

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

Closed
wants to merge 31 commits into from

Conversation

aitikgupta
Copy link
Contributor

@aitikgupta aitikgupta commented Aug 6, 2021

PR Summary

Adding on to the changes from the original PR: #20740, this PR modifies the layout of FT2Font to allow multiple fonts to work with the PDF backend.

Agg backend is simpler to work with, since things like kerning are set within FT2Font, and all we really needed was a bitmap from it. However, for the PDF backend, we need to extract each glyph from a (possibly) parent FT2Font.

To tackle this, I've implemented a caching layer for the parent object, allowing us to directly get the relevant FT2Font which has a certain glyph. Bits and pieces behind how PDF backend handles fonts is also modified.

With this, we can successfully generate Type 3 and Type 42 subsetted multi-font PDFs:
type3_fallback.pdf
type42_fallback.pdf

image

Test Script:

import matplotlib.pyplot as plt

FONTTYPE = 42    # or 3

plt.rcParams['font.family'] = ['Authentic', 'SimHei']
plt.rcParams['pdf.fonttype'] = FONTTYPE
plt.rcParams['font.size'] = 30
plt.rcParams['pdf.compression'] = 0

plt.figtext(0.18, 0.45, "There are 多个汉字 in between!")
plt.savefig(f"type{FONTTYPE}_fallback.pdf")

Builds on: #20740, Fixes #18883, #15260

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@aitikgupta aitikgupta force-pushed the pdf-fallback branch 3 times, most recently from ac118a7 to d43551f Compare August 7, 2021 08:11
@aitikgupta aitikgupta changed the title Implement Font Fallback for PDF backend Implement multi-font embedding for PDF Backend Aug 13, 2021
@tacaswell
Copy link
Member

I'm going to try and do this one next.

@tacaswell
Copy link
Member

Both this and #20832 have been rebased and it looks like this PR has received some additional fixes so I will start here and then do #20832

@tacaswell
Copy link
Member

Included in #23559

@tacaswell tacaswell closed this Aug 12, 2022
@QuLogic QuLogic added this to the v3.6.0 milestone Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Matplotlib would not try to apply all the font in font list to draw all characters in the given string.
4 participants