loonghao / photoshop-python-api

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

fix(TextItem.font): Change font to a read/write string property #322

Closed Investigamer closed 7 months ago

Investigamer commented 7 months ago

Problem

TextItem.font is currently returned as an inoperable TextFont object.

Solution

Return the raw TextItem.app.font which is a string representing the postScriptName of the TextItem's font. This is the normal behavior according to the Photoshop Javascript Reference. Documentation segment attached below.

Note

To set the font of a TextItem using a font existing in Photoshop, you can find the font by name using the Application.fonts collection and pass its postScriptName to TextItem.font, or provide the postScriptName manually if you know it.

# TextFont from fonts collection
arial_bold = app.fonts.getByName('Arial Bold')
text_layer.textItem.font = arial_bold.postScriptName

# Providing a postScriptName manually
text_layer.textItem.font = 'Arial-Bold'

image

Other Changes