python - Jak najdu úplnou cestu k písmu z jeho zobrazovaného názvu na počítači Mac?

original title: "python - How can I find the full path to a font from its display name on a Mac?"


I am using the Photoshop's javascript API to find the fonts in a given PSD.

Given a font name returned by the API, I want to find the actual physical font file that font name corresponds to on the disc.

This is all happening in a python program running on OSX so I guess I'm looking for one of:

  • Some Photoshop javascript
  • A Python function
  • An OSX API that I can call from python

Pomocí JavaScriptu API Photoshopu najdu písma v daném PSD. Vzhledem k názvu písma vrácenému API, chci najít skutečný soubor fyzického písma, kterému název písma odpovídá na ...

Toto je shrnutí po překladu. Pokud potřebujete zobrazit celý překlad, klikněte na ikonu „přeložit“

Všechny odpovědi
  • Translate

    Unfortunately the only API that isn't deprecated is located in the ApplicationServices framework, which doesn't have a bridge support file, and thus isn't available in the bridge. If you're wanting to use ctypes, you can use ATSFontGetFileReference after looking up the ATSFontRef.

    Cocoa doesn't have any native support, at least as of 10.5, for getting the location of a font.

  • Translate

    open up a terminal (Applications->Utilities->Terminal) and type this in:

    locate InsertFontHere

    This will spit out every file that has the name you want.

    Warning: there may be alot to wade through.

  • Translate

    There must be a method in Cocoa to get a list of fonts, then you would have to use the PyObjC bindings to call it..

    Depending on what you need them for, you could probably just use something like the following..

    import os
    def get_font_list():
        fonts = []
        for font_path in ["/Library/Fonts", os.path.expanduser("~/Library/Fonts")]:
            if os.path.isdir(font_path):
                    [os.path.join(font_path, cur_font) 
                     for cur_font in os.listdir(font_path)
        return fonts

  • Translate

    I haven't been able to find anything that does this directly. I think you'll have to iterate through the various font folders on the system: /System/Library/Fonts, /Library/Fonts, and there can probably be a user-level directory as well ~/Library/Fonts.