Skip to main content
Participant
April 24, 2009
Question

Detecting/Correcting text overflow

  • April 24, 2009
  • 2 replies
  • 1768 views

Hi folks,

Has anyone here ever been able to successfully determine if a TextItem in PS has overflow in it? Basically I am trying to write a script that replaces text in a document. If this in turn causes text overflow I would like the script to reduce the point size. I have done a few exeriments with both point and paragraph text.

There seems to be no obvious methods or properties for determining that overflow occurs. I thought I could cheat and measure the widths and heights of the text items before I replace the text, then check to see if they are different afterwards and if so, reduce the point size.

However in the case of point text it is not possible to determine the text width so I would have to do something like rasterize it then do the measurement. In the case of paragraph text the height and width of the text box do not change if there is overflow.

Does anyone have any better, more efficient ideas?

cheers

Ben

This topic has been closed for replies.

2 replies

Paul Riggott
Inspiring
April 24, 2009

Here is an example..

#target photoshop
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.documents.add(300, 300, 72.0,  "New Canvas", NewDocumentMode.RGB, DocumentFill.WHITE,1.0);
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT;
newTextLayer.textItem.position = Array(0, 40);
newTextLayer.textItem.font = "Verdana";
newTextLayer.textItem.size = 14;
newTextLayer.textItem.contents = "The quick brown fox jumps over the lazy dogs back"
var Width = activeDocument.width.value;
var LB=activeDocument.activeLayer.bounds;
var textWidth = LB[2].value - LB[0].value;
if(textWidth > Width) alert("Overflow by " + (textWidth-Width) + " pixels");
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;

Ben_J_DAuthor
Participant
April 25, 2009

Many thanks Paul, that method works fine for point text.

As for paragraph text I think I have come up with a solution.

If we convert a paragraph text layer into a point text layer by doing something like:

ArtLayer.textItem.kind = TextType.POINTTEXT;

and overflow has occured, photoshop will clip out the overflowed text.

So after converting the paragraph to point text we need only check that our

text contents matches the text we are trying to replace it with.

These solutions are a both work arounds, it would be nice if there was a proper

method or property to deal with this. Maybe I will make a dear adobe entry.

Participant
March 2, 2023

Hi Ben,

 

Did you ever find a method for doing this?

 

I'd really like to create a script that detects overflowing text for proofing purposes.

Inspiring
April 24, 2009