FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implement multi-font embedding for PDF Backend by aitikgupta · Pull Request #20804 · matplotlib/matplotlib · GitHub

Repository navigation

Implement multi-font embedding for PDF Backend - #20804

Closed
aitikgupta wants to merge 31 commits into
matplotlib:mainfrom
aitikgupta:pdf-fallback
Closed

aitikgupta wants to merge 31 commits into
matplotlib:mainfrom
aitikgupta:pdf-fallback

Conversation

aitikgupta commented Aug 6, 2021 •
edited
Loading

Copy link
Copy Markdown
Contributor

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

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 mentioned this pull request Aug 7, 2021
3 of 7 tasks
aitikgupta force-pushed the pdf-fallback branch 3 times, most recently from ac118a7 to d43551f Compare August 7, 2021 08:11
aitikgupta changed the title Implement Font Fallback for PDF backend Implement multi-font embedding for PDF Backend Aug 13, 2021

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
Member

Included in #23559

tacaswell closed this Aug 12, 2022
QuLogic added this to the v3.6.0 milestone Aug 12, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL