Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

macosx backend doesn't find fonts the same way as other backends #781

Copy link
Copy link
Closed
@zpincus

Description

@zpincus
Issue body actions

All of the other backends appear to use matplotlib.font_manager.findfont() to look up the path for a given font file to use. However, the macosx backend has its own font-lookup mechanism: src/_macosx.m line 2256, setfont().

This mechanism is essentially an odd way to look up the pre-defined PS fonts, and in particular:

  1. looks only at the font-family name, and does not defer to font-family preference lists from rcParams, such as "font.sans-serif" etc.
  2. does not take any properties into account except for a weight that is exactly "bold" or a variant that is exactly "italic".

It is possible to get this font-lookup to find an arbitrary font by passing a PS-style name such as "MyriadPro-Semibold" as the font-family, but this doesn't work for other backends. (findfont() requires the semibold to be passed in as a weight property, not the family name, even though the eventual file returned is named "MyriadPro-Semibold.otf")

There are several possible solutions; I'm not sure which is best:

  1. make findfont() look up fonts by fully-qualified name such as "MyriadPro-Semibold", so that this style could be used for all backends.
  2. make a function to return a compatible name for a given font found by findfont(). Perhaps this would just be the filename (sans extension) from the path returned by findfont?
  3. fix src/_macosx.m:setfont() to load a font from a path passed in. I get the feeling that this isn't exactly the "encouraged" way to deal with fonts on OS X though...

The downside of using findfont(), and why I presume the macosx backend doesn't, is that FreeType2 (and thus findfont()) can't deal with dfont and other font suitcase types, which can be easily loaded by the cocoa font-lookup routines in _macosx.m. But using such fonts results in the case where one can display a plot on OS X, but saving it creates an error.

Any thoughts? Would it be better to funnel things through findfont() for consistency, at the cost of not being able to use some of the basic fonts on OS X (Helvetica, Courier, etc., are all dfonts -- but hence couldn't be used for figure-saving anyway)? That's option 2 or 3. Or better to leave OS X as it is, and just let other backends look up available fonts by filename too? (Option 1)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.