Skip to content
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

Implement multi-font embedding for PDF Backend #20804

Open
wants to merge 29 commits into
base: master
Choose a base branch
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 mentioned this pull request Aug 7, 2021
3 of 7 tasks
@aitikgupta aitikgupta force-pushed the aitikgupta:pdf-fallback branch from 73cb918 to a2876b3 Aug 7, 2021
@aitikgupta aitikgupta force-pushed the aitikgupta:pdf-fallback branch 3 times, most recently from ac118a7 to d43551f Aug 7, 2021
@aitikgupta aitikgupta changed the title Implement Font Fallback for PDF backend Implement multi-font embedding for PDF Backend Aug 13, 2021
@aitikgupta aitikgupta force-pushed the aitikgupta:pdf-fallback branch from d43551f to 742366b Aug 13, 2021
@aitikgupta aitikgupta force-pushed the aitikgupta:pdf-fallback branch from f098e63 to 70b0e18 Aug 13, 2021
@tacaswell tacaswell added this to Medium Priority in v3.5 Milestone Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
v3.5 Milestone
Medium Priority
Linked issues

Successfully merging this pull request may close these issues.

1 participant