loonghao / photoshop-python-api

Python API for Photoshop.
https://loonghao.github.io/photoshop-python-api/
MIT License
604 stars 68 forks source link

refactor(TextFonts): Implement __getitem__ to allow lookup by postScriptName #283

Closed Investigamer closed 11 months ago

Investigamer commented 11 months ago

Purpose

Implement a dictionary key lookup for pulling a given font from Photoshop's font list. Similar to my commit adding a dictionary lookup for ArtLayers and LayerSets, I found a massive execution time boost when using this method (about 193% faster than getByName in my testing). Please note: this methodology does require that you provide the postScriptName of the font which is usually different from the name, searching for the name will raise an error.

Example

# Pulling a font with this method (postScriptName)
font = app.fonts['JaceBeleren-Bold']

# Pulling a font the slow way (name)
font = app.fonts.getByName("Jace Beleren Bold")
Investigamer commented 11 months ago

Not sure what's causing the import test fail but I see that its failing in a lot of recent PR's so I'm guessing its something that's been here for a bit