Skip to content

ScaledWidthTextField

src.text_layers.ScaledWidthTextField

Bases: TextField

A TextField which automatically scales down its font size until the width of the layer is within the horizontal bound of a reference layer.

Source code in src\text_layers.py
class ScaledWidthTextField (TextField):
    """A TextField which automatically scales down its font size until the width of the
        layer is within the horizontal bound of a reference layer."""
    FONT = CardFonts.RULES

    @cached_property
    def font(self) -> str:
        """str: Font provided, or fallback on global constant."""
        return self.kw_font or CON.font_rules_text

    @cached_property
    def reference_width(self) -> Union[float, int]:
        """Union[float, int]: Width of the reference layer provided."""
        return get_layer_width(self.reference)

    def execute(self):
        super().execute()

        # Scale down the text layer until it doesn't overlap with a reference layer
        if self.reference:
            scale_text_to_width(self.layer, width=self.reference_width)

Attributes

TI: TextItem

The TextItem object within the ArtLayer.

color: SolidColor

A SolidColor object provided, or fallback on current TextItem color.

doc_selection: Selection

The Selection object from the active document.

docref: Document

The currently active Photoshop document.

font: str

input: str

Raw contents provided to fill the TextItem.

is_text_layer: bool

Checks if the layer provided is a TextLayer.

kw_color: Optional[SolidColor]

Color to apply to the TextItem.

kw_font: Optional[str]

Font to apply to the root TextItem.

kw_font_bold: Optional[str]

Font to apply to any bold text in the TextItem.

kw_font_italic: Optional[str]

Font to apply to any italicized text in the TextItem.

kw_font_mana: Optional[str]

Font to apply to any mana symbols in the TextItem.

kw_symbol_map: dict[str, tuple[str, list[ColorObject]]]

Symbol map to use for formatting mana symbols.

kwargs: dict

Contains optional parameters to modify text formatting behavior.

layer: ArtLayer

ArtLayer containing the TextItem.

reference: Optional[ArtLayer]

A reference layer, typically used for scaling the TextItem.

reference_dims: Optional[type[LayerDimensions]]

Optional[type[LayerDimensions]]: Dimensions of the scaling reference layer.

reference_width: Union[float, int]

Union[float, int]: Width of the reference layer provided.

Functions

validate()

Ensure the Text Layer provided is valid.

Source code in src\text_layers.py
def validate(self):
    """Ensure the Text Layer provided is valid."""
    if self.layer and self.is_text_layer:
        # Layer is valid, select and show it
        select_layer(self.layer, True)
        return True
    with suppress(Exception):
        # Layer provided doesn't exist or isn't a text layer
        name = self.layer.name if self.layer else '[Non-Layer]'
        print(f'Text Field class: {self.__class__.__name__}\n'
              f'Invalid layer provided: {name}')
        self.layer.visible = False
    return False