GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Remove ttconv and implement Type-42 embedding using fontTools by jkseppan · Pull Request #20866 · matplotlib/matplotlib

Conversation

@jkseppan

@jkseppan jkseppan commented Aug 20, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

PR Summary

ttconv is now only being used for outputting fonts in Type-42 format in PostScript files, and with fontTools this turns out to be quite doable in pure Python.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] 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).
  • [N/A] 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).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tacaswell reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@jkseppan jkseppan added backend: ps topic: text/fonts labels Aug 20, 2021
@jkseppan
jkseppan force-pushed the remove-ttconv branch from 447fd1b to a826065 Compare August 20, 2021 12:42
@QuLogic QuLogic added this to the v3.6.0 milestone Aug 20, 2021
@jkseppan
jkseppan force-pushed the remove-ttconv branch from 8c44828 to 2535508 Compare August 21, 2021 09:55
@jkseppan

jkseppan commented Aug 21, 2021

Copy link
Copy Markdown
Member Author

Now this works with almost all TrueType fonts on my Mac, with the exception of CFF fonts (#20870) and Apple Color Emoji.ttc and NISC18030.ttf both of which cause a crash in FT2Font (#7305).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jkseppan
jkseppan force-pushed the remove-ttconv branch from de16cf0 to daee4e5 Compare August 21, 2021 15:57
@jkseppan
jkseppan marked this pull request as ready for review August 21, 2021 16:21
@jkseppan
jkseppan force-pushed the remove-ttconv branch 2 times, most recently from 016713a to 7cea2d4 Compare August 22, 2021 14:20
@QuLogic QuLogic added the status: needs rebase label Dec 24, 2021
QuLogic
QuLogic reviewed Dec 24, 2021
View reviewed changes
Comment thread lib/matplotlib/backends/_backend_pdf_ps.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/backends/_backend_pdf_ps.py
if fontfile.endswith('ttc'):
# fix this once we support loading more fonts from a collection
# https://github.com/matplotlib/matplotlib/issues/3135#issuecomment-571085541
options.font_number = 0

@QuLogic QuLogic Dec 24, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we test a ttc in CI already, so it could be used to test this line?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/backends/backend_ps.py Outdated
The Type-42 formatted font
"""
version, breakpoints = _version_and_breakpoints(font.get('loca'), fontdata)
post, name = font['post'], font['name']

@QuLogic QuLogic Dec 24, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these tables guaranteed to exist?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@oscargus oscargus Sep 6, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both post and name are required: https://docs.fileformat.com/font/ttf/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/backends/backend_ps.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/backends/backend_ps.py Outdated
Comment on lines +314 to +322
tuple
((v1, v2), breakpoints) where v1 is the major version number,
v2 is the minor version number and breakpoints is a sorted list
of offsets into fontdata; if loca is not available, just the table
boundaries

@QuLogic QuLogic Dec 24, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For multiple return, you should list the entries separately, like Parameters.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/backends/backend_ps.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/backends/backend_ps.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/backends/backend_ps.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/tests/test_backend_ps.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@tacaswell

tacaswell commented Dec 24, 2021

Copy link
Copy Markdown
Member

Wow, I missed that this came in. 💯 on dropping an extension module!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jklymak jklymak added the status: needs revision label Feb 1, 2022
@jklymak
jklymak marked this pull request as draft February 1, 2022 11:52
@jklymak

jklymak commented Feb 1, 2022

Copy link
Copy Markdown
Member

Dropping to draft until the comments and rebase are addressed. Anyone should feel free to move back to active...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic QuLogic mentioned this pull request Mar 4, 2022
[MNT]: Replace str(n)cpy etc with safe versions (C++) #22603
Closed
@QuLogic

QuLogic commented Mar 15, 2022

Copy link
Copy Markdown
Member

Ping @jkseppan?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oscargus
oscargus reviewed Mar 15, 2022
View reviewed changes
Comment thread lib/matplotlib/backends/_backend_pdf_ps.py

Returns
-------
fontTools.ttLib.ttFont.TTFont

@oscargus oscargus Mar 15, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long term, it could make sense to link to the documentation? (Although fontTools is not in the intersphinx_mapping yet.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Jul 5, 2022
@tacaswell tacaswell modified the milestones: v3.7.0, v3.8.0 Dec 9, 2022
@tacaswell

tacaswell commented Dec 9, 2022

Copy link
Copy Markdown
Member

We want to try and do mpl 3.7 feature freeze around Jan 1 so I think it is unlikely we will have the bandwidth to get this rebased and reviewed by then, pushing to 3.8.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tacaswell
tacaswell force-pushed the remove-ttconv branch from 7cea2d4 to a1b41fe Compare December 9, 2022 20:44
@github-actions github-actions Bot removed the status: needs rebase label Dec 9, 2022
@github-actions github-actions Bot added the status: needs rebase label Jan 21, 2023
@anntzer anntzer mentioned this pull request Feb 20, 2023
Use pybind11 in ttconv module #25253
Merged
@jklymak

jklymak commented Feb 21, 2023

Copy link
Copy Markdown
Member

Do we have someone who can pick this up?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic QuLogic mentioned this pull request Jun 7, 2023
replace ttconv for ps/pdf #12418
Closed
@QuLogic QuLogic modified the milestones: future releases, v3.10.0 Sep 21, 2024
@QuLogic QuLogic removed the status: needs revision label Sep 21, 2024
@QuLogic
QuLogic force-pushed the remove-ttconv branch from 7f2b2a2 to 1393702 Compare September 26, 2024 09:25
@QuLogic

QuLogic commented Oct 9, 2024

Copy link
Copy Markdown
Member

FYI, I think I'm okay with this as it stands, but as I did some followup cleanup work, I'm not sure if I should approve it myself.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oscargus
oscargus approved these changes Oct 10, 2024
View reviewed changes

@oscargus oscargus left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still open to the possibility to add fontTools to the intersphinx-stuff and provide a proper link, but I am also open to do that myself in another PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@oscargus

oscargus commented Oct 10, 2024

Copy link
Copy Markdown
Member

Btw, do we (i.e. someone with a Mac(?)) know if #20866 (comment) still holds?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Oct 10, 2024

Copy link
Copy Markdown
Member

Btw, do we (i.e. someone with a Mac(?)) know if #20866 (comment) still holds?

Maybe @greglucas or @ksunden can have a look at it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@greglucas

greglucas commented Oct 10, 2024

Copy link
Copy Markdown
Contributor

Using the example from the linked issue:

# this needs the patch above

import matplotlib
from pathlib import Path
matplotlib.use('ps')
from matplotlib import pyplot as plt

# the following font is in CFF format on my Mac
font = Path('/System/Library/Fonts/AppleSDGothicNeo.ttc')

fig = plt.figure()
plt.axis((0,10,0,10))
plt.text(3,3,'Glib jocks quiz nymph to vex dwarf.', font=font)

matplotlib.rc('ps', fonttype=42)
plt.savefig('fmt42.ps')

matplotlib.rc('ps', fonttype=3)
plt.savefig('fmt3.ps')

The type42 is completely blank for me (no axes either). The type3 shows up as expected. I don't get an error though 🤷

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tacaswell

tacaswell commented Oct 11, 2024

Copy link
Copy Markdown
Member

That example fails for me on main. Trying to open the fmt42.ps with ghostscript gives me:

@ ghostscript fmt42.ps
GPL Ghostscript 10.04.0 (2024-09-18)
Copyright (C) 2024 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Error: /invalidfont in definefont
Operand stack:
   unknown   --dict:11/15(L)--   Font
Execution stack:
   %interp_exit   .runexec2   --nostringval--   definefont   --nostringval--   2   %stopped_push   --nostringval--   definefont   definefont   false   1   %stopped_push   1949   1   3   %oparray_pop   1948   1   3   %oparray_pop   1933   1   3   %oparray_pop   1803   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   definefont   --nostringval--   2   %stopped_push   --nostringval--   1897   2   4   %oparray_pop
Dictionary stack:
   --dict:745/1123(ro)(G)--   --dict:0/20(G)--   --dict:86/200(L)--   --dict:8/10(L)--
Current allocation mode is local
Current file position is 11715
GPL Ghostscript 10.04.0: Unrecoverable error, exit code 1

and with this branch I get

@ ghostscript fmt42.ps
GPL Ghostscript 10.04.0 (2024-09-18)
Copyright (C) 2024 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Error: /invalidfont in definefont
Operand stack:
   AppleSDGothicNeo-Regular   --dict:12/16(L)--   Font
Execution stack:
   %interp_exit   .runexec2   --nostringval--   definefont   --nostringval--   2   %stopped_push   --nostringval--   definefont   definefont   false   1   %stopped_push   1949   1   3   %oparray_pop   1948   1   3   %oparray_pop   1933   1   3   %oparray_pop   1803   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   definefont   --nostringval--   2   %stopped_push   --nostringval--   1897   2   4   %oparray_pop
Dictionary stack:
   --dict:745/1123(ro)(G)--   --dict:0/20(G)--   --dict:86/200(L)--   --dict:8/10(L)--
Current allocation mode is local
Current file position is 18773
GPL Ghostscript 10.04.0: Unrecoverable error, exit code 1
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ksunden

ksunden commented Oct 11, 2024

Copy link
Copy Markdown
Member

Okay, looks like the answer is that this has not fixed #20866 (comment), however that is broken on main anyway, so I'd lean towards not blocking for merging this if we are otherwise satisfied.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tacaswell

tacaswell commented Oct 11, 2024

Copy link
Copy Markdown
Member

The issue also appears to be font specific, dejavu being embedded as type42 works OK.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jkseppan and others added 10 commits October 16, 2024 04:04
@jkseppan @QuLogic
Type-42 fonts using fontTools
e3bda66
Split _backend_pdf_ps.get_glyphs_subset into two functions:
get_glyphs_subset returns the font object (which needs to be
closed after using) and font_as_file serializes this object
into a BytesIO file-like object.
@jkseppan @QuLogic
Remove ttconv
786f202
Move the test in lib/matplotlib/tests/test_ttconv.py to
lib/matplotlib/tests/test_backend_pdf.py. Actually it has not been
a test of ttconv for a while, since type-3 conversion has not been
using ttconv.
@jkseppan @QuLogic
Add several more droppable tables
566c2a6
Fonttools cannot subset these and drops them; avoid the warning.
@jkseppan @QuLogic
Don't crash if the loca table is missing
485e1b7
Also don't end up in an infinite loop if there is a larger gap
between breakpoints than we would like.
@jkseppan @QuLogic
Don't crash if glyph bounds cannot be found
f4a04c3
@jkseppan @QuLogic
Log the name of unsupported fonts
94698fa
FT2Font throws RuntimeError for some fonts
@jkseppan @QuLogic
Get names from the original font
c6ab62b
Not the subsetted one, since in some cases fontTools.subset
does not produce a good name table.
@jkseppan @QuLogic
Document ttconv removal
19e4679
@QuLogic
Apply fixes from code review
9fa0b2b
@QuLogic
Clean up some ttconv replacements
45a1654
De-wrap a few lines now that we allow longer lines.
@QuLogic
QuLogic force-pushed the remove-ttconv branch from 1393702 to 45a1654 Compare October 16, 2024 08:04
ksunden
ksunden approved these changes Oct 16, 2024
View reviewed changes
@ksunden
ksunden merged commit 5e5ce02 into matplotlib:main Oct 16, 2024
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Nov 7, 2024
@tacaswell
MNT: remove _tconv.pyi
231f595
This was missed in matplotlib#20866
@tacaswell tacaswell mentioned this pull request Nov 7, 2024
MNT: remove _ttconv.pyi #29099
Merged
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Nov 7, 2024
@tacaswell
MNT: remove _ttconv.pyi
f0f1b5c
This was missed in matplotlib#20866
@jkseppan jkseppan mentioned this pull request Jun 12, 2025
Update font-related documentation #30150
Merged
@QuLogic QuLogic mentioned this pull request Jul 1, 2025
Request to support PostScript-flavoured (CFF) OpenType fonts in PDF backend #2869
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@QuLogic QuLogic QuLogic left review comments
@ksunden ksunden ksunden approved these changes
@oscargus oscargus oscargus approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

backend: pdf backend: ps

Projects

None yet

Milestone

v3.10.0

Development

Successfully merging this pull request may close these issues.

replace ttconv for ps/pdf

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@jkseppan @tacaswell @jklymak @QuLogic @oscargus @greglucas @ksunden
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.