Search code examples
extendscriptphotoshop-scriptphotoshop-cs5

Extendscript: How to check whether text content overflows the containing rectangle


I am using Extendscript for Photoshop CS5 to change the text of a text layer. Is there a way of checking whether the text fits e.g. by checking whether it overflows after changing the content?


Solution

  • I haven't found a way to do this directly. But I've used the following technique to determine the height I needed for a textbox (I wanted to keep the width constant) before.

    • expand the textbox's height well beyond what is needed to accommodate the text inside it.
    • duplicate the layer
    • rasterize the duplicate
    • measure the bounds of the rasterized layer.
    • adjust the bounds of the original text layer as needed
    • delete the rasterized duplicate

    Totally roundabout - but it did work.