Text¶
src.helpers.text.get_font_size(layer: ArtLayer) -> float
¶
Get scale factor adjusted font size of a given text layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
Text layer to get size of. |
required |
src.helpers.text.get_text_key(layer: ArtLayer) -> Any
¶
Get the textKey action reference from a TextLayer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
ArtLayer which must be a TextLayer kind. |
required |
Source code in src\helpers\text.py
src.helpers.text.apply_text_key(text_layer, text_key) -> None
¶
Applies a TextKey action descriptor to a given TextLayer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_layer
|
ArtLayer which must be a TextLayer kind. |
required | |
text_key
|
TextKey extracted from a TextLayer that has been modified. |
required |
Source code in src\helpers\text.py
src.helpers.text.get_line_count(layer: Optional[ArtLayer] = None, docref: Optional[Document] = None) -> int
¶
Get the number of lines in a paragraph text layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer | None
|
Text layer that contains a paragraph TextItem. |
None
|
docref
|
Document | None
|
Reference document, use active if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Number of lines in the TextItem. |
Source code in src\helpers\text.py
src.helpers.text.replace_text(layer: ArtLayer, find: str, replace: str) -> None
¶
Replaces target "find" text with "replace" text in a given TextLayer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
ArtLayer which must be a TextLayer kind. |
required |
find
|
str
|
Text to find in the layer. |
required |
replace
|
str
|
Text to replace the found text with. |
required |
Source code in src\helpers\text.py
src.helpers.text.replace_text_legacy(find: str, replace: str, layer: Optional[ArtLayer] = None, targeted_replace: bool = True) -> None
¶
Replace all instances of replace_this in the specified layer with replace_with, using Photoshop's
built-in search and replace feature. Slower than replace_text, but can handle strings broken into
multiple textStyle ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
find
|
str
|
Text string to search for. |
required |
replace
|
str
|
Text string to replace matches with. |
required |
layer
|
ArtLayer | None
|
Layer object to search through, use active if not provided. |
None
|
targeted_replace
|
bool
|
Disables layer targeting if False, if True may cause a crash on older PS versions. |
True
|
Source code in src\helpers\text.py
src.helpers.text.remove_trailing_text(layer: ArtLayer, idx: int) -> None
¶
Remove text after certain index from a TextLayer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
TextLayer containing the text to modify. |
required |
idx
|
int
|
Index to remove after. |
required |
Source code in src\helpers\text.py
src.helpers.text.remove_leading_text(layer: ArtLayer, idx: int) -> None
¶
Remove text up to a certain index from a TextLayer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
TextLayer containing the text to modify. |
required |
idx
|
int
|
Index to remove up to. |
required |
Source code in src\helpers\text.py
src.helpers.text.get_text_scale_factor(layer: Optional[ArtLayer] = None, axis: Optional[Union[str, list]] = 'yy', text_key=None) -> Union[int, float, list[Union[int, float]]]
¶
Get the scale factor of the document for changing text size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer | None
|
The layer to make active and run the check on. |
None
|
axis
|
str | list | None
|
Scale axis or list of scale axis to check (xx: horizontal, yy: vertical). |
'yy'
|
text_key
|
textKey action descriptor |
None
|
Returns:
| Type | Description |
|---|---|
int | float | list[int | float]
|
Float scale factor |
Source code in src\helpers\text.py
src.helpers.text.align_text(action_list: ActionList, start: int, end: int, alignment: str = 'right') -> ActionList
¶
Align a slice of text in an action using given alignment.
Examples:
Used to align the quote credit of --Name to the right on some classic cards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_list
|
ActionList
|
Action list to add this action to |
required |
start
|
int
|
Starting index of the quote string |
required |
end
|
int
|
Ending index of the quote string |
required |
alignment
|
str
|
left, right, or center |
'right'
|
Returns:
| Type | Description |
|---|---|
ActionList
|
Returns the existing ActionDescriptor with changes applied |
Source code in src\helpers\text.py
src.helpers.text.align_text_right(action_list: ActionList, start: int, end: int) -> None
¶
src.helpers.text.align_text_left(action_list: ActionList, start: int, end: int) -> None
¶
src.helpers.text.align_text_center(action_list: ActionList, start: int, end: int) -> None
¶
Utility shorthand to call align_text with 'center' alignment.
src.helpers.text.set_space_after(space: Union[int, float]) -> None
¶
Manually assign the 'space after' property for a paragraph text layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
int | float
|
The 'space after' value to set. |
required |
Source code in src\helpers\text.py
src.helpers.text.set_text_leading(layer: ArtLayer, leading: Union[float, int]) -> None
¶
Manually assign font leading to a text layer using action descriptors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
Layer containing TextItem to change leading of. |
required |
leading
|
float | int
|
New TextItem font leading. |
required |
Source code in src\helpers\text.py
src.helpers.text.set_text_size(layer: ArtLayer, size: Union[float, int]) -> None
¶
Manually assign font size to a text layer using action descriptors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
Layer containing TextItem to change size of. |
required |
size
|
float | int
|
New TextItem font size. |
required |
Source code in src\helpers\text.py
src.helpers.text.set_text_size_and_leading(layer: ArtLayer, size: Union[int, float], leading: Union[int, float]) -> None
¶
Manually assign font size and leading space to a text layer using action descriptors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
Layer containing TextItem to change size of. |
required |
size
|
int | float
|
New TextItem font size. |
required |
leading
|
int | float
|
New TextItem font leading. |
required |
Source code in src\helpers\text.py
src.helpers.text.set_composer(layer: ArtLayer, every: bool = False) -> None
¶
Set text layer composer to single line or multi line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
Layer containing TextItem to set composer for. |
required |
every
|
bool
|
Set to 'Every-line Composer' if True, otherwise 'Single-line Composer'. By default, set to 'Single-line Composer'. |
False
|
Source code in src\helpers\text.py
src.helpers.text.set_composer_single_line(layer: ArtLayer) -> None
¶
src.helpers.text.set_composer_every_line(layer: ArtLayer) -> None
¶
src.helpers.text.set_font(layer: ArtLayer, font_name: str) -> None
¶
Set the font of a given TextItem layer using a font's ordinary name.
Note
Setting font using the 'postScriptName' is faster. For example: layer.textItem.font = 'Beleren-Bold'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
ArtLayer containing TextItem. |
required |
font_name
|
str
|
Name of the font to set. |
required |
Source code in src\helpers\text.py
src.helpers.text.ensure_visible_reference(reference: ArtLayer) -> Optional[TextItem]
¶
Ensures that a layer used for reference has bounds if it is a text layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
ArtLayer
|
Reference layer that might be a TextLayer. |
required |
Returns:
| Type | Description |
|---|---|
TextItem | None
|
TextItem if reference is an empty text layer, otherwise None. |
Source code in src\helpers\text.py
src.helpers.text.scale_text_right_overlap(layer: ArtLayer, reference: ArtLayer, gap: int = 30) -> None
¶
Scales a text layer down (in 0.2 pt increments) until its right bound has a 30 px~ (based on DPI) clearance from a reference layer's left bound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
The text item layer to scale. |
required |
reference
|
ArtLayer
|
Reference layer we need to avoid. |
required |
gap
|
int
|
Minimum gap to ensure between the layer and reference (DPI adjusted). |
30
|
Source code in src\helpers\text.py
src.helpers.text.scale_text_left_overlap(layer: ArtLayer, reference: ArtLayer, gap: int = 30) -> None
¶
Scales a text layer down (in 0.2 pt increments) until its left bound has a 30 px~ (based on DPI) clearance from a reference layer's right bound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
The text item layer to scale. |
required |
reference
|
ArtLayer
|
Reference layer we need to avoid. |
required |
gap
|
int
|
Minimum gap to ensure between the layer and reference (DPI adjusted). |
30
|
Source code in src\helpers\text.py
src.helpers.text.scale_text_to_width(layer: ArtLayer, width: int, spacing: int = 64, step: float = 0.4, font_size: Optional[float] = None) -> Optional[float]
¶
Resize a given text layer's font size/leading until it fits inside a reference width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
Text layer to scale. |
required |
width
|
int
|
Width the text layer must fit (after spacing added). |
required |
spacing
|
int
|
Amount of DPI adjusted spacing to pad the width. |
64
|
step
|
float
|
Amount to step font size down by in each check. |
0.4
|
font_size
|
float | None
|
The starting font size if pre-calculated. |
None
|
Returns:
| Type | Description |
|---|---|
float | None
|
Font size if font size is calculated during operation, otherwise None. |
Source code in src\helpers\text.py
src.helpers.text.scale_text_to_height(layer: ArtLayer, height: int, spacing: int = 64, step: float = 0.4, font_size: Optional[float] = None) -> Optional[float]
¶
Resize a given text layer's font size/leading until it fits inside a reference width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
Text layer to scale. |
required |
height
|
int
|
Width the text layer must fit (after spacing added). |
required |
spacing
|
int
|
Amount of DPI adjusted spacing to pad the height. |
64
|
step
|
float
|
Amount to step font size down by in each check. |
0.4
|
font_size
|
float | None
|
The starting font size if pre-calculated. |
None
|
Returns:
| Type | Description |
|---|---|
float | None
|
Font size if font size is calculated during operation, otherwise None. |
Source code in src\helpers\text.py
src.helpers.text.scale_text_to_width_textbox(layer: ArtLayer, font_size: Optional[float] = None, step: float = 0.1) -> None
¶
Check if the text in a TextLayer exceeds its bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
ArtLayer with "kind" of TextLayer. |
required |
font_size
|
float | None
|
Starting font size, calculated if not provided (slower execution time). |
None
|
step
|
float
|
Amount of points to step down each iteration. |
0.1
|
Source code in src\helpers\text.py
src.helpers.text.scale_text_layers_to_height(text_layers: list[ArtLayer], ref_height: Union[int, float], font_size: Optional[float] = None, step: float = 0.4) -> Optional[float]
¶
Scale multiple text layers until they all can fit within the same given height dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_layers
|
list[ArtLayer]
|
List of TextLayers to check. |
required |
ref_height
|
int | float
|
Height to fit inside. |
required |
font_size
|
float | None
|
Starting font size of the text layers, calculated if not provided. |
None
|
step
|
float
|
Points to step down the text layers to fit. |
0.4
|